Commits

fak3 committed 7cbe8d0

gui_utils.py - split out general ActionDialog from DownloadDialog

  • Participants
  • Parent commits 8e16dec

Comments (0)

Files changed (1)

File gui_utils.py

     ERROR = 1
     CANCELED = 2
     
-    def __init__(self, parent, *args):
-        QDialog.__init__(self, parent, *args)
+    def __init__(self, *args):
+        QDialog.__init__(self, *args)
         
         self.success.connect(self.on_success)
         self.error.connect(self.on_error)
     def on_cancel(self): self.done(self.CANCELED)
 
 
-class DownloadFileDialog(StatusDialog):
-    def __init__(self, src, dst_path, parent, *args):
-        StatusDialog.__init__(self, parent, *args)
-        
-        filename = os.path.basename(dst_path)
-        self.text = QLabel(u'Скачивается файл %s' % filename, self)
-        
+class ActionDialog(StatusDialog):
+    def __init__(self,  label, action, aargs=(), *args, **kwargs):
+        StatusDialog.__init__(self, *args, **kwargs)
+        self.text = QLabel(label)
         self.bbox = QDialogButtonBox(QDialogButtonBox.Cancel)
         self.bbox.rejected.connect(self.on_cancel)
         layout = VBox(self, [self.text, self.bbox])
         
-        def dl_proc():
+        def action_proc():
             try:
-                utils.download_file(src, dst_path)
+                action(*aargs)
             except:
                 self.error.emit()
                 raise
             self.success.emit()
         
-        self.download_thread = utils.StoppableThread(target = dl_proc)
-        self.download_thread.start()
+        self.action_thread = utils.StoppableThread(target = action_proc)
+        self.action_thread.start()
         
     def on_cancel(self):
-        self.download_thread.stop()
-        self.download_thread.join()
+        self.action_thread.stop()
+        self.action_thread.join()
         self.done(self.CANCELED)
+
+
+class DownloadFileDialog(ActionDialog):
+    def __init__(self, src, dst_path, *args, **kwargs):
+        msg = u'Скачивается файл %s' % os.path.basename(dst_path)
+        ActionDialog.__init__(self, msg, utils.download_file, (src, dst_path), *args, **kwargs)