Re: [PyQt] QMessageBox with unicode text fails
On Wed Oct 24 23:03:20 BST 2007, Tim Welch wrote: > I'm trying to display a unicode string in a QMessageBox using the > information() static method. However it seems to only accept ascii > characters. I'm using qt/pyqt 4.3.0 on Windows. > > Here's a sample app with output: > > # *-* coding: utf-8 *-* > from PyQt4 import QtCore, QtGui > from PyQt4.QtCore import * > from PyQt4.QtGui import * > > if __name__ == "__main__": > qapp = QApplication([]) > QMessageBox.critical(None, "ImportError", unicode("blort español")) > sys.exit(qapp.exec_()) First of all, are you sure that the syntax you've used for the encoding directive is correct? http://docs.python.org/tut/node4.html Otherwise, this looks fine, but there's potentially a nasty surprise lurking in there. Even if I change the comment line to reflect the syntax used in the above document, I still see this error: > > > Traceback (most recent call last): > File "U:\dev\delphos\src\gui\test.py", line 8, in > QMessageBox.critical(None, "ImportError", unicode("blort español")) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 10: > ordinal not in range(128) > > * This error is due to the way Python's unicode() function is asked to handle the string you've given it, and is unrelated to PyQt's string handling. The proper way to deal with this is to ensure that you're using Unicode strings. It turns out that you can just write QMessageBox.critical(None, "ImportError", u"blort español") and everything should work as expected. Experimenting a bit further, and making a few late-night assumptions about the way things work, it seems that the following happens when you use non-Unicode strings in your code: 1. Python reads in the source code, encoded as UTF-8. 2. When run, the unicode() call is asked to decode UTF-8 encoded text but hasn't been told which encoding to use, so it falls back on the default one. 3. The default encoding isn't UTF-8, so it doesn't work. Since it appears that the encoding used isn't set by the presence of the encoding hint, you would need to force the conversion by explicitly passing the encoding to the unicode() method or, alternatively, somehow setting the default encoding to UTF-8. However, I think the proper solution is as I describe above: to write the string as a Unicode string and to let Python decode it when it loads the file. > Removing the ñ creates a working message box. It makes no difference if I > use the static method or create and setup a QMessageBox object myself. Any > help is appreciated, I found no mention of this in any documentation or the > archives. It's a Python thing. I expect that a new person finds out about this the hard way every day. :-) David ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] PyQt book "Rapid GUI Programming with Python and Qt" now available
A shame that I can't buy here in Argentina :( And the cost for me is to much to buy it in Amazon for example (including the international delivery)... 2007/10/23, Mark Summerfield <[EMAIL PROTECTED]>: > > Hi, > > I am delighted to announce that > > "Rapid GUI Programming with Python and Qt: > The Definitive Guide to PyQt Programming" > > has now been published in the US. > > The book is a hardback, 648 pages, ISBN 0132354187. > > The foreword was written by Phil Thompson (creator of PyQt), who was > also one of the book's five technical reviewers. > > For a brief overview of the book and the table of contents, etc., see > > http://www.qtrac.eu/pyqtbook.html > > This web page also has links to places that sell the book, and has the > full source code for the examples (and model answers to almost every > exercise) available for downloading. > > The book covers PyQt4 (it has no coverage of PyQt3), and is best used > with Python 2.5 and PyQt 4.2 or better, on Windows, Mac OS X, or an > X11-based Unix or Linux. No prior knowledge of GUI programming is > assumed, so don't worry if you've only ever done web programming:-) > > Since this is the only book that covers PyQt4 it is automatically the > "best"---but I have not been complacent, and have worked extremely hard > to make the book as accessible, useful, enjoyable, and interesting as > possible. > > (Note for Safari readers: The printed version of the book uses the PDF I > supplied as is, with fonts and typesetting exactly as I wanted them, > whereas the Safari online edition was retypeset by the publisher.) > > -- > Mark Summerfield, Qtrac Ltd., www.qtrac.eu > > ___ > PyQt mailing listPyQt@riverbankcomputing.com > http://www.riverbankcomputing.com/mailman/listinfo/pyqt > -- Gustavo A. Díaz GDNet Projects www.gdnet.com.ar ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] QMessageBox with unicode text fails
Hi folks, I'm trying to display a unicode string in a QMessageBox using the information() static method. However it seems to only accept ascii characters. I'm using qt/pyqt 4.3.0 on Windows. Here's a sample app with output: # *-* coding: utf-8 *-* from PyQt4 import QtCore, QtGui from PyQt4.QtCore import * from PyQt4.QtGui import * if __name__ == "__main__": qapp = QApplication([]) QMessageBox.critical(None, "ImportError", unicode("blort español")) sys.exit(qapp.exec_()) Traceback (most recent call last): File "U:\dev\delphos\src\gui\test.py", line 8, in QMessageBox.critical(None, "ImportError", unicode("blort español")) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128) * Removing the ñ creates a working message box. It makes no difference if I use the static method or create and setup a QMessageBox object myself. Any help is appreciated, I found no mention of this in any documentation or the archives. Tim ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] PyQt book "Rapid GUI Programming with Python and Qt" now available
I had thought about buying the electronic book a good time ago, but I didn't buy, because there was no "get the printed version cheaper if you buy the electronic version beforehand" option. Maybe you could ask your publisher kindly to become a bit more realistic, so people begin to get accomodated to the electronic sales. The sad thing is: -- Rapid GUI Programming with Python and Qt: The Definitive Guide to PyQt Programming - Retail Price: USD $49.99 RCBoth Print Book and Online Access Bundle - USD $67.48 RCOnline Online Access Only - USD $34.99 RCPrint Print Book Only - USD $34.99 - http://safari.informit.com/9780132354189#purchaseroughcuts -- No chance I'd buy both under these conditions. Even though I'd have really liked helping in beta-reading the book (I became accustomed to always doing a bug-search on any book I read - even on fiction :) ). Best wishes, Arne Am Mittwoch, 24 de Oktober de 2007 15:35:50 schrieb Mark Summerfield: > On 2007-10-24, alteo_gange wrote: > > Why electronic book is as expensive as paper book? > > > > http://safari.awprofessional.com/9780132354189 > > I have no idea how the publisher comes up with the prices! But if there > is little or no difference, I hope you buy the paper version because it > uses the PDF I supplied as is, with the fonts and typesetting as I > wanted them, whereas the publisher retypeset the online version. > > > Le mardi 23 octobre 2007, pyprog a écrit : > > > Excuse in advance for my bad english. > > > > I forgive you. ;-) > > Thanks:-) -- Unpolitisch sein Heißt politisch sein Ohne es zu merken. - Arne Babenhauserheide ( http://draketo.de ) -- Weblog: http://blog.draketo.de -- Mein öffentlicher Schlüssel (PGP/GnuPG): http://draketo.de/inhalt/ich/pubkey.txt signature.asc Description: This is a digitally signed message part. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] NotImplementedError
Title: business Shall try if I find the time. Cheers, Heinz Phil Thompson wrote: On Wednesday 24 October 2007, Heinz A. Preisig wrote: Hi, I found a way around it by trial and error It turned out to be the operation len() , where the was a list of graphics items caused the problem when used in mouseReleaseEvent . In this case it was possible to change the code achieving the same result but not using the len() method. Not sure if this helps in finding the problem. Cheers, Heinz Heinz A. Preisig wrote: Hi, I have been expanding my code with new features after which I experience an error NotImplementedError: QGraphicsItem.boundingRect() is abstract and must be overridden when using the rubber band. The procedure has been working before, but obviously I disturbed the devil. Any suggestions on what to change or do to get rid of the problem Cheers, Heinz Can you produce a test case that demonstrates the problem? Phil -- Heinz A Preisig Professor of Process Systems Engineering Private: Øvre Bakklandet 62 B, 7013 Trondheim, Norway Department of Chemical Engineering Norwegian University of Science and Technology N – 7491 Trondheim, Norway Tel direct: +47 735 92807 Tel mob: +47 9754 1334 e-mail: [EMAIL PROTECTED] web: www.chemeng.ntnu.no\~preisig ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] PyQt book "Rapid GUI Programming with Python and Qt" now available
On 2007-10-24, alteo_gange wrote: > Why electronic book is as expensive as paper book? > > http://safari.awprofessional.com/9780132354189 I have no idea how the publisher comes up with the prices! But if there is little or no difference, I hope you buy the paper version because it uses the PDF I supplied as is, with the fonts and typesetting as I wanted them, whereas the publisher retypeset the online version. > Le mardi 23 octobre 2007, pyprog a écrit : > > Excuse in advance for my bad english. > > I forgive you. ;-) Thanks:-) -- Mark Summerfield, Qtrac Ltd., www.qtrac.eu ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] NotImplementedError
Title: business Hi, I found a way around it by trial and error It turned out to be the operation len() , where the was a list of graphics items caused the problem when used in mouseReleaseEvent . In this case it was possible to change the code achieving the same result but not using the len() method. Not sure if this helps in finding the problem. Cheers, Heinz Heinz A. Preisig wrote: Hi, I have been expanding my code with new features after which I experience an error NotImplementedError: QGraphicsItem.boundingRect() is abstract and must be overridden when using the rubber band. The procedure has been working before, but obviously I disturbed the devil. Any suggestions on what to change or do to get rid of the problem Cheers, Heinz -- Heinz A Preisig Professor of Process Systems Engineering Private: Øvre Bakklandet 62 B, 7013 Trondheim, Norway Department of Chemical Engineering Norwegian University of Science and Technology N – 7491 Trondheim, Norway Tel direct: +47 735 92807 Tel mob: +47 9754 1334 e-mail: [EMAIL PROTECTED] web: www.chemeng.ntnu.no\~preisig ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt -- business Heinz A Preisig Professor of Process Systems Engineering Private: Øvre Bakklandet 62 B, 7013 Trondheim, Norway Department of Chemical Engineering Norwegian University of Science and Technology N – 7491 Trondheim, Norway Tel direct: +47 735 92807 Tel mob: +47 9754 1334 e-mail: [EMAIL PROTECTED] web: www.chemeng.ntnu.no\~preisig ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] PyQt book "Rapid GUI Programming with Python and Qt" now available
Why electronic book is as expensive as paper book? http://safari.awprofessional.com/9780132354189 Le mardi 23 octobre 2007, pyprog a écrit : > Excuse in advance for my bad english. I forgive you. ;-) -- alteo_gange ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] identify a QTreeWidgetItem
Le mardi 23 octobre 2007, Jim Bublitz a écrit : > On Tuesday 23 October 2007 02:13, alteo_gange wrote: > > Hi everybody! > > > > I have created several QTreeWidgetItem and connected a signal > > "itemClicked(QTreeWidgetItem *,int)" on the QTreeWidget. > > > > > treeWidget=QtGui.QTreeWidget(widget) > > > ... > > > itemTree1=QtGui.QTreeWidgetItem(treeWidget) > > > ... > > > itemTree2=QtGui.QTreeWidgetItem(treeWidget) > > > ... > > > self.connect(treeWidget,QtCore.SIGNAL("itemClicked(QTreeWidgetItem > > > *,int)"),self.function) > > > ... > > > def function(self, item): > > > print item > > > > 'print item' return: > > . > > > > > > It's very abstract! > > > > I must identify QTreeWidgetItem in order to connect it an action (view a > > widget on the right), but how? With a method of the item reference? > > Which? I don't know. > > Store the items in a dict as you create them: > > self.itemDict = {} > itemTree1=QtGui.QTreeWidgetItem(treeWidget) > self.itemDict [itemTree1] = ?? # could be the associated widget that you > want # to connect to, or a # string identifier > itemTree2=QtGui.QTreeWidgetItem(treeWidget) > self.itemDict [itemTree2] = ?? > > ... > > def function (self, item): > widget = self.itemDict [item] > ... Great! Now, my code is more secure. I can use several times the same text on several QTreeWidgetItem and i can rename QTreeWidgetItem text without problems (the function mustn't be change). Thanks! -- alteo_gange ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] identify a QTreeWidgetItem
Le mardi 23 octobre 2007, Michael Towers a écrit : > alteo_gange wrote: > >>print item.text(0), "\n" > >> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in > >> position 11: ordinal not in range(128) > > I find this one of the most annoying things in PyQt, it confuses me > terribly. I think in this case you can do (for example) > > print unicode(item.text(0)), "\n" > > (the original result from item.text() being a QString) > > But it may be that you need to specify an encoding and use the > encode or decode methods of unicode or string ... Thanks! It works. Generally i write ' u"unicode characters" ', but in this case it was impossible. Moreover i forgot u"" in the next of my function: > if item.text(0) == u"Filtres Vidéos" -- alteo_gange ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt