[PyQt] QDialog's widgets do not show up correctly
Phil Thompson
phil at riverbankcomputing.com
Sun Jul 6 16:39:29 BST 2008
On Sun, 6 Jul 2008 17:19:30 +0200, Christoph Schmidt <ch_schmidt at online.de>
wrote:
> Hi,
>
> I'm currently learning programming with PyQt and play around a bit with
> python-apt + PyQt4. My problem is as follows: In order to indicate the
> progress of an apt operation, python-apt offers the possibility to pass
an
>
> instance of a progress class. In this case I subclassed FetchProgress
from
>
> apt.progress:
>
> class GuiUpdateProgress(QDialog, FetchProgress):
> def __init__(self, parent=None):
> QDialog.__init__(self, parent)
> FetchProgress.__init__(self)
> self.items = {}
> self.setModal(True)
> self.fetchIndicator = QProgressBar()
> self.speedIndicator = QLabel("Unknown")
> self.layout = QVBoxLayout()
> self.layout.addWidget(self.fetchIndicator)
> self.layout.addWidget(self.speedIndicator)
> self.setLayout(self.layout)
>
> def start(self):
> self.show()
>
> def stop(self):
> if 2 in self.items.values():
> QMessageBox.warning(self, "Update Error",
> "One or more sources could not be
> updated!")
> self.hide()
>
> def updateStatus(self, uri, descr, shortDescr, status):
> self.items[uri] = status # unimportant
>
> def pulse(self):
> self.percent = ((self.currentBytes + self.currentItems)*100.0) /
> float(self.totalBytes + self.totalItems)
> if self.currentCPS > 0:
> self.eta = (self.totalBytes-self.currentBytes) /
> float(self.currentCPS)
> self.fetchIndicator.setValue(int(self.percent))
> self.speedIndicator.setText(str(self.eta))
> return True
>
> def mediaChange(self, medium, drive):
> pass # unimportant
>
> When I now pass an instance of this class to a python-apt operation, at
> first
> start() is called, then updateStatus() and pulse() are being called
> repeatedly until the operation is done and stop() is called in the end.
>
> I would expect this code to let a QDialog pop up, show its initial state
> when
> start() is called and update whenever pulse() is called. However, it
seems
> to
> only show an empty window before pulse() is called the first time, and
> even
> when pulse() is called, only the QProgressBar updates itself, the QLabel
> stays invisible.
>
> I uploaded the a tstable version of the code at
> http://pastebin.com/f3caddde3
> to show you what I mean (python-apt is required). My PyQt Version is
> (according to Synaptic) 4.3.3.
>
> I hope somebody can tell me what I am doing wrong.
Modal dialogs have their own event loop. You probably need to call the
dialog's exec_() method.
Phil
More information about the PyQt
mailing list