eric7/WebBrowser/Download/DownloadItem.py

branch
eric7
changeset 8563
3c6547443fb2
parent 8556
766e1566cb74
child 8856
df77fbfc150f
diff -r 9250a6d5fde2 -r 3c6547443fb2 eric7/WebBrowser/Download/DownloadItem.py
--- a/eric7/WebBrowser/Download/DownloadItem.py	Tue Aug 31 17:31:23 2021 +0200
+++ b/eric7/WebBrowser/Download/DownloadItem.py	Tue Aug 31 17:48:20 2021 +0200
@@ -7,6 +7,7 @@
 Module implementing a widget controlling a download.
 """
 
+import enum
 import os
 
 from PyQt6.QtCore import (
@@ -27,6 +28,15 @@
 import Utilities.MimeTypes
 
 
+class DownloadState(enum.Enum):
+    """
+    Class implementing the various download states.
+    """
+    Downloading = 0
+    Successful = 1
+    Cancelled = 2
+
+
 class DownloadItem(QWidget, Ui_DownloadItem):
     """
     Class implementing a widget controlling a download.
@@ -39,11 +49,6 @@
     downloadFinished = pyqtSignal(bool)
     progress = pyqtSignal(int, int)
     
-    # TODO: convert this to an enum
-    Downloading = 0
-    DownloadSuccessful = 1
-    DownloadCancelled = 2
-    
     def __init__(self, downloadRequest=None, pageUrl=None, parent=None):
         """
         Constructor
@@ -71,7 +76,7 @@
         self.openButton.setEnabled(False)
         self.openButton.setVisible(False)
         
-        self.__state = DownloadItem.Downloading
+        self.__state = DownloadState.Downloading
         
         icon = self.style().standardIcon(QStyle.StandardPixmap.SP_FileIcon)
         self.fileIcon.setPixmap(icon.pixmap(48, 48))
@@ -110,7 +115,8 @@
         
         # attach to the download item object
         self.__url = self.__downloadRequest.url()
-        self.__downloadRequest.receivedBytesChanged.connect(self.__downloadProgress)
+        self.__downloadRequest.receivedBytesChanged.connect(
+            self.__downloadProgress)
         self.__downloadRequest.isFinishedChanged.connect(self.__finished)
         
         # reset info
@@ -307,7 +313,7 @@
         self.pauseButton.setEnabled(False)
         self.pauseButton.setVisible(False)
         self.setUpdatesEnabled(True)
-        self.__state = DownloadItem.DownloadCancelled
+        self.__state = DownloadState.Cancelled
         self.__downloadRequest.cancel()
         self.__setDateTime()
         self.downloadFinished.emit(False)
@@ -463,7 +469,7 @@
         
         @return flag indicating a download is in progress (boolean)
         """
-        return self.__state == DownloadItem.Downloading
+        return self.__state == DownloadState.Downloading
     
     def downloadedSuccessfully(self):
         """
@@ -471,7 +477,7 @@
         
         @return flag indicating a successful download (boolean)
         """
-        return self.__state == DownloadItem.DownloadSuccessful
+        return self.__state == DownloadState.Successful
     
     def downloadCanceled(self):
         """
@@ -479,7 +485,7 @@
         
         @return flag indicating a canceled download (boolean)
         """
-        return self.__state == DownloadItem.DownloadCancelled
+        return self.__state == DownloadState.Cancelled
     
     def __finished(self):
         """
@@ -497,7 +503,7 @@
         self.stopButton.setVisible(False)
         self.openButton.setEnabled(noError)
         self.openButton.setVisible(noError)
-        self.__state = DownloadItem.DownloadSuccessful
+        self.__state = DownloadState.Successful
         self.__updateInfoLabel()
         self.__setDateTime()
         
@@ -588,9 +594,9 @@
         self.openButton.setEnabled(data["Done"])
         self.openButton.setVisible(data["Done"])
         if data["Done"]:
-            self.__state = DownloadItem.DownloadSuccessful
+            self.__state = DownloadState.Successful
         else:
-            self.__state = DownloadItem.DownloadCancelled
+            self.__state = DownloadState.Cancelled
         self.progressBar.setVisible(False)
         
         self.__adjustSize()

eric ide

mercurial