28 Ağustos 2010 Cumartesi günü (saat 12:41:50) Gökçen Eraslan şunları 
yazmıştı:
> Özet olarak bu sorun için şunlar denenebilir diye düşünüyorum:
> 
> 1- GUI thread'ine gönderilen her PisiEvent'ten sonra
> (yali/gui/runner.py'dekinden farklı olarak) doğrudan
> QApplication.processEvents çağırmak (bkz. ekteki yama),
> 
> 2- yali/gui/ScrInstall.py'daki objectSender'taki postEvent'i sendEvent'e
> çevirerek, event'in queue'ya girmeden çalıştırılmasını sağlamak, (bunu
> denedim ama bir sonuç alamadım, detaylı bakmak lazım)
> 
> 3-    QThread + Event based iletişim yerine Python threading/multiprocessing
> + PisiUI sınıfının notify callback'ini kullanarak iletişim kurmak,
> 
> Şimdilik aklıma gelenler bunlar. Başka fikri olan?

QEvent kullanmak sağlıklı görünmedi bana, o yüzden Pisi QThread'leri ve ana 
thread arası iletişimi SIGNAL'ler ile takip etmemiz gerektiğini düşünerek 
mekanizmayı değiştirdim.

Yama ekte, Mete'ye de gönderdim Cuma günü, bir de bununla deneyecek.
Index: ScrInstall.py
===================================================================
--- ScrInstall.py	(revision 31654)
+++ ScrInstall.py	(working copy)
@@ -100,6 +100,20 @@
         self.cur = 0
         self.hasErrors = False
 
+        # PiSi operation threads
+        self.pkg_installer = PkgInstaller()
+        self.pkg_configurator = PkgConfigurator()
+
+        self.connect(self.pkg_installer, SIGNAL("pisiOperation(int, QString, QString)"), self.slotPisiOperation)
+        self.connect(self.pkg_installer, SIGNAL("pisiProgress(int)"), self.slotPisiProgress)
+        self.connect(self.pkg_installer, SIGNAL("pisiInstallDone()"), self.slotPisiInstallDone)
+        self.connect(self.pkg_installer, SIGNAL("pisiError(QString)"), self.slotPisiError)
+        self.connect(self.pkg_installer, SIGNAL("pisiRetry(QString)"), self.slotPisiRetry)
+
+        self.connect(self.pkg_configurator, SIGNAL("pisiOperation(int, QString, QString)"), self.slotPisiOperation)
+        self.connect(self.pkg_configurator, SIGNAL("pisiError(QString)"), self.slotPisiError)
+        self.connect(self.pkg_configurator, SIGNAL("pisiDone()"), self.slotPisiDone)
+
     def shown(self):
         # Disable mouse handler
         ctx.mainScreen.dontAskCmbAgain = True
@@ -111,7 +125,6 @@
 
         # start installer thread
         ctx.logger.debug("PkgInstaller is creating...")
-        self.pkg_installer = PkgInstaller()
         ctx.logger.debug("Calling PkgInstaller.start...")
         self.pkg_installer.start()
         ctx.yali.info.updateAndShow(_("Installing packages..."))
@@ -122,52 +135,42 @@
         # start 30 seconds
         self.timer.start(1000 * 30)
 
-    def customEvent(self, qevent):
+    def slotPisiOperation(self, operation, package, summary=""):
+        package = unicode(package)
+        summary = unicode(summary)
+        if operation == pisi.ui.installing:
+            self.ui.info.setText(_("Installing <b>%s</b><br>%s") % (package, summary))
+            ctx.logger.debug("Pisi: %s installing" % package)
+            self.cur += 1
+            self.ui.progress.setValue(self.cur)
+        elif operation == pisi.ui.configuring:
+            self.ui.info.setText(_("Configuring <b>%s</b>") % package)
+            ctx.logger.debug("Pisi: %s configuring" % package)
+            self.cur += 1
+            self.ui.progress.setValue(self.cur)
 
-        # EventPisi
-        if qevent.eventType() == EventPisi:
-            p, event = qevent.data()
+    def slotPisiProgress(self, total)
+        self.ui.progress.setMaximum(total)
 
-            if event == pisi.ui.installing:
-                self.ui.info.setText(_("Installing <b>%s</b><br>%s") % (p.name, p.summary))
-                ctx.logger.debug("Pisi: %s installing" % p.name)
-                self.cur += 1
-                self.ui.progress.setValue(self.cur)
-            elif event == pisi.ui.configuring:
-                self.ui.info.setText(_("Configuring <b>%s</b>") % p.name)
-                ctx.logger.debug("Pisi: %s configuring" % p.name)
-                self.cur += 1
-                self.ui.progress.setValue(self.cur)
+    def slotPisiInstallDone(self):
+        self.packageInstallFinished()
 
-        # EventSetProgress
-        elif qevent.eventType() == EventSetProgress:
-            total = qevent.data()
-            self.ui.progress.setMaximum(total)
+    def slotPisiError(self, err)
+        self.installError(err)
 
-        # EventPackageInstallFinished
-        elif qevent.eventType() == EventPackageInstallFinished:
-            self.packageInstallFinished()
+    def slotPisiRetry(self, package):
+        package = unicode(package)
+        self.timer.stop()
+        ctx.yali.retryAnswer = EjectAndRetryDialog(_("Warning"),
+                                                   _("Failed installing <b>%s</b>") % package,
+                                                   _("Do you want to retry?"))
 
-        # EventError
-        elif qevent.eventType() == EventError:
-            err = qevent.data()
-            self.installError(err)
+        self.timer.start(1000 * 30)
+        ctx.yali.waitCondition.wakeAll()
 
-        # EventRetry
-        elif qevent.eventType() == EventRetry:
-            package = qevent.data()
-            self.timer.stop()
-            ctx.yali.retryAnswer = EjectAndRetryDialog(_("Warning"),
-                                                       _("Failed installing <b>%s</b>") % package,
-                                                       _("Do you want to retry?"))
+    def slotPisiDone(self):
+        self.finished()
 
-            self.timer.start(1000 * 30)
-            ctx.yali.waitCondition.wakeAll()
-
-        # EventAllFinished
-        elif qevent.eventType() == EventAllFinished:
-            self.finished()
-
     def slotChangePix(self):
         slide = self.iter_pics.next()
         self.ui.pix.setPixmap(slide["pic"])
@@ -195,7 +198,6 @@
         ctx.yali.info.updateMessage(_("Configuring packages..."))
 
         # start configurator thread
-        self.pkg_configurator = PkgConfigurator()
         self.pkg_configurator.start()
 
     def execute(self):
@@ -264,12 +266,8 @@
 
         # show progress
         total = len(order)
-        ctx.logger.debug("Creating PisiEvent..")
-        qevent = PisiEvent(QEvent.User, EventSetProgress)
-        ctx.logger.debug("Setting data on just created PisiEvent (EventSetProgress)..")
-        qevent.setData(total * 2)
-        ctx.logger.debug("Posting PisiEvent to the widget..")
-        objectSender(qevent)
+        ctx.logger.debug("Emitting progress signal")
+        self.emit(SIGNAL("pisiProgress(int)"), total * 2)
         ctx.logger.debug("Found %d packages in repo.." % total)
         try:
             while True:
@@ -281,13 +279,9 @@
                     # Lock the mutex
                     ctx.yali.mutex.lock()
 
-                    # Send event for asking retry
-                    qevent = PisiEvent(QEvent.User, EventRetry)
+                    # Emit signal for asking retry
+                    self.emit(SIGNAL("pisiRetry(QString)"), QString(os.path.basename(str(e))))
 
-                    # Send failed package name
-                    qevent.setData(os.path.basename(str(e)))
-                    objectSender(qevent)
-
                     # wait for the result
                     ctx.yali.waitCondition.wait(ctx.yali.mutex)
                     ctx.yali.mutex.unlock()
@@ -305,17 +299,14 @@
             ctx.yali.mutex.lock()
 
             # User+10: error
-            qevent = PisiEvent(QEvent.User, EventError)
-            qevent.setData(e)
-            objectSender(qevent)
+            self.emit(SIGNAL("pisiError(QString)"), QString(str(e)))
 
             # wait for the result
             ctx.yali.waitCondition.wait(ctx.yali.mutex)
 
         ctx.logger.debug("Package install finished ...")
         # Package Install finished lets configure them
-        qevent = PisiEvent(QEvent.User, EventPackageInstallFinished)
-        objectSender(qevent)
+        self.emit(SIGNAL("pisiInstallDone()"))
 
 class PkgConfigurator(QThread):
 
@@ -334,9 +325,7 @@
             yali.pisiiface.configurePending()
         except Exception, e:
             # User+10: error
-            qevent = PisiEvent(QEvent.User, EventError)
-            qevent.setData(e)
-            objectSender(qevent)
+            self.emit(SIGNAL("pisiError(QString)"), QString(str(e)))
 
         # Remove cd repository and install add real
         if yali.sysutils.checkYaliParams(param=ctx.consts.dvd_install_param):
@@ -344,8 +333,7 @@
         else:
             yali.pisiiface.switchToPardusRepo(ctx.consts.cd_repo_name)
 
-        qevent = PisiEvent(QEvent.User, EventAllFinished)
-        objectSender(qevent)
+        self.emit(SIGNAL("pisiDone()"))
 
 class PisiUI(QObject, pisi.ui.UI):
 
@@ -356,27 +344,10 @@
 
     def notify(self, event, **keywords):
         if event == pisi.ui.installing or event == pisi.ui.configuring:
-            qevent = PisiEvent(QEvent.User, EventPisi)
-            data = [keywords['package'], event]
+            package = keywords["package"].name
+            summary = keywords["package"].summary
+            self.emit(SIGNAL("pisiOperation(int, QString, QString)"), event, QString(package), QString(summary))
             self.lastPackage = keywords['package'].name
-            qevent.setData(data)
-            objectSender(qevent)
 
     def display_progress(self, operation, percent, info, **keywords):
         pass
-
-class PisiEvent(QEvent):
-
-    def __init__(self, _, event):
-        QEvent.__init__(self, _)
-        self.event = event
-
-    def eventType(self):
-        return self.event
-
-    def setData(self,data):
-        self._data = data
-
-    def data(self):
-        return self._data
-
_______________________________________________
Gelistirici mailing list
[email protected]
http://liste.pardus.org.tr/mailman/listinfo/gelistirici

Cevap