[PyKDE] PyQt on Windows Mobile
I developed a program for Linux using PyQt which I now have to port to a PDA running Windows Mobile 5. As far as I can tell, Qt is not available for Windows Mobile, so it follows that PyQt is not either. However, I am hoping that someone can confirm this conclusion before I waste a lot of time learning some other GUI library and rewriting my code. Thanks. Gee, while I'm at it I might as well ask whether anyone has any opinions on the next best GUI library (that also runs on Windows Mobile 5). I'm thinking it's either Tkinter or wxPython. -- Jeffrey Barish ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[PyKDE] Tabs in QListBoxText
I have a statement: QListBoxText(clb, '%s:\t%s' % (key, thing[key])) The tab does not appear (it's a space). Do I have to set tab stops, or is there no way to use tabs in listboxes? What I really want is for the keys and things to line up vertically. A QListView could do that with 2 columns, but I don't want the column headers. Any suggestions appreciated. -- Jeffrey Barish ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[PyKDE] Generating dropdown list dynamically
I would like to generate a readonly dropdown list dynamically. I catch the focusInEvent, which gets triggered when I click on the down arrow of the box. At this point, I would generate the contents of the listbox and use QListBoxText to enter it. However, when I select one of the items in the dropdown list, I get another focusInEvent. It's critical that I not get a second focusInEvent after the listbox has been created as I don't want to create the list a second time. I tried setting the focus proxy on the combobox to None, figuring that the second focusInEvent was coming from the listbox. I tried setting the focus policy to NoFocus (on both the the combobox and the listbox). I tried setting the focus policy of the combobox to NoFocus after receiving the first focusInEvent and then turning it on again after the selection of the item. I tried setting the focus policy of the main window to NoFocus. Nothing I do suppresses the second focusInEvent. I'm apparently barking up the wrong tree. Remember that I'm the troglodyte using version 2.3.2 (because that's all that's available for the Zaurus). But at least I found the documentation for this version at Trolltech. import sys from qt import * class MainWindow(QMainWindow): def __init__(self, *args): QMainWindow.__init__(self, *args) self.setFocusPolicy(QWidget.NoFocus) self.cb = MyComboBox(self) for i in range(3): self.cb.insertItem("item %d" % i) QObject.connect(self.cb, SIGNAL('activated(int)'), self.clicked) QObject.connect(self.cb, PYSIGNAL('focusInEvent'), self.focusEvent) def clicked(self, index): print 'Received click on index =', index, 'with text:', self.cb.text(index) self.cb.setFocusPolicy(QWidget.ClickFocus) def focusEvent(self): print 'Received focusInEvent' class MyComboBox(QComboBox): def __init__(self, parent): QComboBox.__init__(self, parent) self.setFocusPolicy(QWidget.ClickFocus) self.setFocusProxy(None) self.lb = self.listBox() self.lb.setFocusPolicy(QWidget.NoFocus) self.lb.setFocusProxy(None) def focusInEvent(self, event): print 'in focusInEvent' self.setFocusPolicy(QWidget.NoFocus) self.emit(PYSIGNAL('focusInEvent'), ()) def main(args): app = QApplication(args) win = MainWindow() app.setMainWidget(win) win.show() app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()")) app.exec_loop() if __name__ == "__main__": main(sys.argv) -- Jeffrey Barish ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[PyKDE] QPEApplication complains about ZCS file
I started using QPEApplication rather than QApplication to integrate my application in Qtopia. The first problem that I had was a complaint that there was no libsl.qmid file. I figured out that this file is related to internationalization. I created a trivial .pro file and ran pylupdate on it to produce an empty .ts. Then I ran lrelease on the .ts to produce a .qm. I renamed it libsl.qmid and put it in the right place. The complaint disappeared. However, in its place, I am now getting the complaint "it seems this file is not ZCS file." This one has me stumped as I can find no reference to ZCS files in the Qt-interest mailing list, this group, or a blanket Google search. Any suggestions? -- Jeffrey Barish ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[PyKDE] Re: Updating GUI from another thread
Giovanni Bajo wrote: > Jeffrey Barish <[EMAIL PROTECTED]> wrote: > >> I tried using >> a custom event. I found that I need a timer in the GUI thread to >> trigger a processEvents call. > > The timer should not be needed at all: the main thread is sitting in > the event loop, so there is no reason why you need to call > processEvents(). > That's what I expected, but without the call to processEvents the GUI doesn't update unless I do something (e.g., scroll the item out of the display or maximize/restore) to trigger an update. My test program displays this behavior too. Just comment out the timer start statement. Clicking on the minimize button is sufficient to get the window to updte even though it doesn't minimize. >> Then I discovered that I don't seem to >> need the custom event: I can simply deselect the item from the task >> thread, although the processEvents call is still necessary. Is the >> issue that something bad could happen if I happen to try selecting >> the item at the same time the task thread is trying to deselect it? > > Yes, you should not be doing this. If you really need this, you must > use app.lock() / app.unlock() in the thread to block the main thread. > > Basically, in Qt 3, the only safe thing you can do is sending a custom > event across threads. In Qt 4 you can connect signals/slots across > threads (across QThreads actually) and Qt will do the right thing. > >> Is the solution with the custom event optimal? > > Yes, without QTimer. You should not need it. > > Giovanni Bajo -- Jeffrey Barish ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[PyKDE] Updating GUI from another thread
This problem seems to come up regularly, but I am wondering whether the solution I found for my situation is safe. I have a program in which I run a time-consuming task in its own thread. Every time the task reaches a milestone, I want it to deselect a listbox item. In the test program below, the GUI thread creates a listbox with 3 items. The user can select one and then push the button. The object is to deselect the selected item from another thread. I tried using a custom event. I found that I need a timer in the GUI thread to trigger a processEvents call. Then I discovered that I don't seem to need the custom event: I can simply deselect the item from the task thread, although the processEvents call is still necessary. Is the issue that something bad could happen if I happen to try selecting the item at the same time the task thread is trying to deselect it? Is the solution with the custom event optimal? The timer seems inelegant. I had hoped to find a solution where the thread could somehow order the GUI thread to deselect and update. # The purpose of this test is to explore the problem of deselecting a # listbox item from another thread. import sys import thread from qt import * class MainWindow(QMainWindow): def __init__(self, *args): QMainWindow.__init__(self, *args) self.mainWidget = QWidget(self) self.setCentralWidget(self.mainWidget) self.lb = QListBox(self.mainWidget) self.button = QPushButton("Clear selections", self.mainWidget) QObject.connect(self.button, SIGNAL('clicked()'), self.clearSelections) for i in range(3): QListBoxText(self.lb, "some text %d" % i) self.vlayout = QVBoxLayout(self.mainWidget) self.vlayout.addWidget(self.lb) self.vlayout.addWidget(self.button) self.timer = QTimer() QObject.connect(self.timer, SIGNAL("timeout()"), self.periodicCall) self.timer.start(500) def periodicCall(self): app.processEvents() def clearSelections(self): thread.start_new_thread(self.do_clearSelections, ()) def customEvent(self, e): if e.type() == 65432: lbi = e.lbi lb = e.lb lb.setSelected(lbi, False) def do_clearSelections(self): lbi = self.lb.firstItem() while lbi: print "lbi.selected() =", lbi.selected() if lbi.selected(): ##e = MyEvent(self.lb, lbi) ##app.postEvent(self, e) self.lb.setSelected(lbi, False) lbi = lbi.next() class MyEvent(QCustomEvent): def __init__(self, lb, lbi): QCustomEvent.__init__(self, 65432) self.lb = lb self.lbi = lbi def lbi(self): return self.lbi app = None def main(args): global app app = QApplication(args) win = MainWindow() app.setMainWidget(win) win.show() app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()")) app.exec_loop() if __name__ == "__main__": main(sys.argv) -- Jeffrey Barish ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[PyKDE] Re: QListBoxItem.isSelected() does not exist
Giovanni Bajo wrote: > Jeffrey Barish <[EMAIL PROTECTED]> wrote: > >> Here's one that I'm pretty sure is a bug. In the following complete >> code sample, the line that is commented out tests whether the >> listboxitem is selected. However, that line produces an >> AttributeError. The line above it works correctly, but according to >> the documentation selected() is obsolete. > > Works for me: > >>>> "isSelected" in dir(QListBoxText) > True >>>> "selected" in dir(QListBoxText) > False > > I also tried a cut-down version of your sample and everything appears > to work as expected: > >>>> a = QApplication([]) >>>> l = QListBox(None) >>>> i = QListBoxText(l, "foo") >>>> i.isSelected > >>>> i.selected > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: selected >>>> l.firstItem() is i > True > > Which version of Qt/PyQt are you using? > > Giovanni Bajo Yes, that could explain it. I am using version 2.3.2, which is what comes with the kopsis package for the Zaurus. Perhaps isSelected became standard in version 3. Is that the version you are running? -- Jeffrey Barish ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[PyKDE] QListBoxItem.isSelected() does not exist
Here's one that I'm pretty sure is a bug. In the following complete code sample, the line that is commented out tests whether the listboxitem is selected. However, that line produces an AttributeError. The line above it works correctly, but according to the documentation selected() is obsolete. import sys from qt import * class MainWindow(QMainWindow): def __init__(self, *args): QMainWindow.__init__(self, *args) self.lb = QListBox(self) self.setCentralWidget(self.lb) QListBoxText(self.lb, "some text") lbi = self.lb.firstItem() print "lbi.selected() = ", lbi.selected() ##print "lbi.isSelected() = ", lbi.isSelected() # AttributeError print QListBoxText.__bases__[0].__dict__.get('isSelected') # the base # is QListBoxItem, and 'isSelected' does not appear in its __dict__ # even though documentation indicates that it is a public member. def main(args): app = QApplication(args) win = MainWindow() app.setMainWidget(win) win.show() app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()")) app.exec_loop() if __name__ == "__main__": main(sys.argv) -- Jeffrey Barish ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[PyKDE] Re: Re: Shading after QListView.setSelected()
Jeffrey Barish wrote: > I should also mention that with this > sample, the selection (after setSelected) is not gray. Trying to get > the shading to blue was what led me to this problem in the first > place. At this point, I don't know what it is in the full program that > changes > the shading to gray. Does the gray shading mean that the item is > disabled? For the record: it was gray because the listview was not the focus. Using self.setFocus() in the constructor for the listview solved the problem. In the sample program, there was only one box, so it automatically got the focus. -- Jeffrey Barish ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[PyKDE] ListBoxItems are invisible
I hope that someone can explain something to me. In the following code sample, I expect to see 3 lines of text in a listbox. When I uncomment the line that is commented out and comment out the 2 lines above it, I get the expected result. With the code as shown, I get a listbox, but no text is visible in it. In both case, however, the print loop confirms that there are 3 lines of text and the text is what was set. So why don't I see anything with the code as shown? Is there a way to make the text visible when I put it in a QListBoxItem? When working with a QListViewItem, it works to create a QListViewItem and then set its text (in fact, one must because unlike QListBox.insertItem, QListView.insertItem does not accept a text argument). Why does it work with views but not boxes? Incidentally, when I first wrote this sample, I had self.insertItem(lbi, -1) after the two lines in question. In that case, I wound up with 6 lines of text, and the last 3 were all "some text 2". What I believe I was supposed to learn is that the constructor for QListBoxItem connects the resulting lbi to the parent specified, so the insertItem was making redundant connections. I'm not clear on why the lines of text were numbered 0, 1, 2, 2, 2, 2 (rather than 0, 0, 1, 1, 2, 2), but what I really want to know is what insertItem(lbi) is properly used for. I suppose it must be for situations in which the lbi being inserted has a different parent, but I can't imagine such a situation. import sys from qt import * class MainWindow(QMainWindow): def __init__(self, *args): QMainWindow.__init__(self, *args) self.mlb = MyListBox(self) self.setCentralWidget(self.mlb) class MyListBox(QListBox): def __init__(self, parent): QListBox.__init__(self, parent) for i in range(3): lbi = QListBoxItem(self) lbi.setText("some text %d" % i) ##self.insertItem("some text %d" % i, -1) for i in range(self.count()): print "text at position", i, self.text(i) def main(args): app = QApplication(args) win = MainWindow() app.setMainWidget(win) win.show() app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()")) app.exec_loop() if __name__ == "__main__": main(sys.argv) -- Jeffrey Barish ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[PyKDE] Re: Re: Shading after QListView.setSelected()
Hans-Peter Jansen wrote: > > Since your sample code isn't complete in this form, it's hard to tell > you _anything_. Do you really expect us to form something runable > from your artifacts to prove you right or wrong? > > Pete Well, yes. I actually thought that my mistake was so basic that it would be obvious even in this fragment. Sorry. Here's a complete sample which I tried to make as short as possible. I even eliminated the subclassing (of QListViewItem), which is what I thought might be producing the problem. When I uncomment the line with the setEnabled call, I get an attribute error. I should also mention that with this sample, the selection (after setSelected) is not gray. Trying to get the shading to blue was what led me to this problem in the first place. At this point, I don't know what it is in the full program that changes the shading to gray. Does the gray shading mean that the item is disabled? import sys from qt import * class MainWindow(QMainWindow): def __init__(self, *args): QMainWindow.__init__(self, *args) self.mainWidget = QWidget(self) self.setCentralWidget(self.mainWidget) self.mlv = MyListView(self.mainWidget) self.vlayout = QVBoxLayout(self.mainWidget) self.vlayout.addWidget(self.mlv) self.mlv.update() class MyListView(QListView): def __init__(self, parent): QListView.__init__(self, parent) self.setAllColumnsShowFocus(True) def update(self): for key in ['one', 'two', 'three']: self.addColumn(key, 80) for thing in [['isaone', 'isatwo', 'isathree'], ['isanotherone', 'isanothertwo', 'isanotherthree'], ['yetanotherone', 'yetanothertwo', 'yetanotherthr']]: lvi = QListViewItem(self) for col in range(3): lvi.setText(col, thing[col]) item = self.firstChild() self.setSelected(item, True) print 'item = ', item # it's a QListViewItem (that's right) ##item.setEnabled(True) # produces AttributeError (that's wrong) def main(args): app = QApplication(args) win = MainWindow() app.setMainWidget(win) win.show() app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()")) app.exec_loop() if __name__ == "__main__": main(sys.argv) -- Jeffrey Barish ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[PyKDE] Re: Shading after QListView.setSelected()
Phil Thompson wrote: >> This question has to be something simple, but I just started >> programming >> PyQt. I fill a listview with lines of text then select the first >> line >> with QListView.setSelected(QListView.firstChild(), True). The >> appropriate item is shaded, but the shading is grey rather than blue. >> I figure that means that the item is not enabled. Right so far? So >> I >> tried QListView.firstChild().setEnabled(True). I get an >> AttributeError. The Qt documentation says that >> QListView.firstChild() returns a QListViewItem and that QListViewItem >> has an attribute >> setEnabled. Is this a bug? Using isEnabled() also produces an >> AttributeError. > > Can you post a small, complete example that demonstrate's the problem > - and the text of the exception? > > Phil I subclassed QListViewItem to provide a place to stash some data. I printed self.firstChild() to confirm that it is a MyListViewItem. I did dir(QListViewItem) to confirm that there really is no attribute setEnabled. Here's the code that calls setEnabled(): class MyListView(QListView): [...] def getSelections(self): [...] for thing in self.things: lvi = MyListViewItem(self, thing['data']) for col, key in zip(range(len(self.keys)), self.keys): lvi.setText(col, thing['text']) self.setSelected(self.firstChild(), True) self.firstChild().setEnabled(True) # produces AttributeError class MyListViewItem(QListViewItem): def __init__(self, parent, data): QListViewItem.__init__(self, parent) self.data = data def getItemData(self): return self.data I am using python 2.4 (the kopsis package). -- Jeffrey Barish ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[PyKDE] Shading after QListView.setSelected()
This question has to be something simple, but I just started programming PyQt. I fill a listview with lines of text then select the first line with QListView.setSelected(QListView.firstChild(), True). The appropriate item is shaded, but the shading is grey rather than blue. I figure that means that the item is not enabled. Right so far? So I tried QListView.firstChild().setEnabled(True). I get an AttributeError. The Qt documentation says that QListView.firstChild() returns a QListViewItem and that QListViewItem has an attribute setEnabled. Is this a bug? Using isEnabled() also produces an AttributeError. -- Jeffrey Barish ___ PyKDE mailing listPyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde