RE: [PyQt] Next Releases of PyQt and SIP
>BTW, the current PyQt snapshot will build against Qt v4.6-beta1. >Phil Wow, that's great! Is Animation framework and state machine supported? Can't wait to test those c00l animations! :) pyqt 4.6.1. on next week will be build against qt 4.6 beta or qt 4.5? I would like to port couple of new animation demos to pyqt! Could I have an exe installer please? --- Igor igor at tyumbit.ru ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
RE: [PyQt] ANN: PyQt v4.6 and SIP v4.9 Released
Can't compile sip 4.9 with mingw on WinXP pyqthon 2.6.2 Qt 2009.03 SDK + mingw version which comes with SDK. Error text - something about undefined reference in 'py_struct' etc... I'm only one with this problem? --- i...@tyumbit.ru ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] QMYSQL + QSqlQueryModel.
I have compiled mysql plugin with mingw it works with standard Qt installation. Sqlbrowser example from Qt demo works with my plugin ok and queries fetches data from database just fine! But I can't include my mingw compiled plugin to pyqt compiled by riverbank. Replacing C:\Python26\Lib\site-packages\PyQt4\plugins\sqldrivers\qsqlmysql4.dll with mingw compiled version didn't working. Even when I clearing Qt plugin cache in registry. QMYSQL just not showing in available drivers. It's because pyqt compiled with microsoft compiler from Visual Studio? How can I replace standard plugin with mingw version? How can i compile mysql plugin with Qt OpenSource SDK (without commercial license) and with Visual studio compiler? Configure.exe wants commercial license when I choose 'c' in his options. --- igor at tyumbit.ru ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] QMYSQL + QSqlQueryModel.
Hello, my previous post didn't have any asnwers, so I'll try once again: now I'm cutting my example to bare minimum (without models) it's still behaves very strange: My info: winxp, msyql 5.0.45, python 2.6.2, latest precompiled pyqt which comes with mysql plugin as dll , qt 2009.3 Here is a script: - from PyQt4 import QtSql, QtGui from PyQt4.QtSql import * import sys app = QtGui.QApplication(sys.argv) db = QSqlDatabase.addDatabase("QMYSQL") db.setHostName('localhost') db.setDatabaseName('mysql') db.setUserName('root') db.setPassword('root') db.setPort(3306) for driver in QSqlDatabase.drivers(): print driver if not db.open(): QMessageBox.warning(None, "Error log", QString("Database Error: %1").arg(db.lastError().text())) sys.exit(1) query = QtSql.QSqlQuery(db) print 'query result is:', query.exec_("select now()") while query.next(): print "got something" if query.lastError().type() !=QtSql.QSqlError.NoError: err = query.lastError() print 'databaseText error:',err.databaseText() print 'text error:',err.text() db.close() - And here is output: QSQLITE QMYSQL3 QMYSQL QODBC3 QODBC QPSQL7 QPSQL query result is: True databaseText error: text error: QMYSQL3: Unable to fetch data Couple of questons: why QMYSQL3 in error? I'm accessing QMYSQL plugin. why no data from mysql? qt opensource compiled with mingw. mysql plugin which comes witch pyqt compiled with MS compiler. Should I recompile mysql plugin with mingw or with MS compiler? Or it doesn't matter? Thanks --- igor at tyumbit.ru ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] QMYSQL + QSqlQueryModel.
Hello, I'm recently upgraded my python setup to python 2.6.2 + Qt 4.5.1 + latest pyqt (on WinXP) I'm trying to work with mysql through qmysql plugin & QtSql.QSqlQueryModel here is code demonstrating my problem: -- from PyQt4 import QtSql, QtGui,QtCore import sys views = [] def initializeModel(model): model.setQuery("select user.user from user") model.setHeaderData(0, QtCore.Qt.Horizontal, QtCore.QVariant(QtCore.QObject.tr(model, "user"))) def createView(title, model): view = QtGui.QTableView() views.append(view) view.setModel(model) view.setWindowTitle(title) view.show() def createConnection(): db = QtSql.QSqlDatabase.addDatabase("QMYSQL") db.setHostName('localhost') db.setDatabaseName("mysql") db.setUserName("root") db.setPassword("root") if not db.open(): QtGui.QMessageBox.critical(None, QtGui.qApp.tr("Cannot open database"), QtGui.qApp.tr("Unable to establish a database connection.\nClick Cancel to exit."), QtGui.QMessageBox.Cancel) return False return True class CustomSqlModel(QtSql.QSqlQueryModel): def data(self, index, role): value = QtSql.QSqlQueryModel.data(self, index, role) if value.isValid() != True: print 'value not valid?' else: print "value ok" return value if __name__ == '__main__': app = QtGui.QApplication(sys.argv) # QtCore.QTextCodec.setCodecForLocale(QtCore.QTextCodec.codecForName("cp1251") ) # QtCore.QTextCodec.setCodecForCStrings(QtCore.QTextCodec.codecForName("cp1251 ")) # QtCore.QTextCodec.setCodecForTr(QtCore.QTextCodec.codecForName("cp1251")) if not createConnection(): sys.exit(1) CustomModel = CustomSqlModel() initializeModel(CustomModel) createView(QtCore.QObject.tr(CustomModel, "Custom Query Model"), CustomModel) app.setQuitOnLastWindowClosed(True) sys.exit(app.exec_()) -- generally it's trying to show all logins available in mysql database. Please see,that it's system database. What I've got on the screen is a table with 4 EMPTY rows (no logins displayed) and output on console: 'value not valid?' many times... c\:mysql -V C:\Program Files\MySQL\MySQL Server 5.0\bin\mysql.EXE Ver 14.12 Distrib 5.0.45, for Win32 (ia32) c:\> mysql -uroot -proot -Dmysql -e"select user.user from user" shows that's there is actually some logins +--+ | user | +--+ | igor | | root | | igor | | root | +--+ Could please someone check my script on his own mysql db? Is something wrong with decoding/encoding my values which I receive from db? or with mysql setup? or with mysql plugin which comes with pyqt installation? --- igor at tyumbit.ru ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
RE: [PyQt] Catching exceptions everywhere
Hello, How about that overriding sys.excepthook ? This code was shamelessly stolen and modified from Eric IDE ( credits goes to author ) import blablabla sys.excepthook = excepthook def excepthook(excType, excValue, tracebackobj): """ Global function to catch unhandled exceptions. @param excType exception type @param excValue exception value @param tracebackobj traceback object """ separator = '-' * 80 logFile = "simple.log" notice = \ """An unhandled exception occurred. Please report the problem\n"""\ """using the error reporting dialog or via email to <%s>.\n"""\ """A log has been written to "%s".\n\nError information:\n""" % \ ("yourm...@server.com", "") versionInfo="0.0.1" timeString = time.strftime("%Y-%m-%d, %H:%M:%S") tbinfofile = cStringIO.StringIO() traceback.print_tb(tracebackobj, None, tbinfofile) tbinfofile.seek(0) tbinfo = tbinfofile.read() errmsg = '%s: \n%s' % (str(excType), str(excValue)) sections = [separator, timeString, separator, errmsg, separator, tbinfo] msg = '\n'.join(sections) try: f = open(logFile, "w") f.write(msg) f.write(versionInfo) f.close() except IOError: pass errorbox = QtGui.QMessageBox() errorbox.setText(str(notice)+str(msg)+str(versionInfo)) errorbox.exec_() Put it somewhere in your main.py and you got nice messagebox when exception occurs anywhere in your code. --- i...@tyumbit.ru -Original Message- From: pyqt-boun...@riverbankcomputing.com [mailto:pyqt-boun...@riverbankcomputing.com] On Behalf Of Lukas Hetzenecker Sent: Thursday, May 07, 2009 9:32 PM To: pyqt@riverbankcomputing.com Cc: Jeremy Sanders Subject: Re: [PyQt] Catching exceptions everywhere Hello, you could redirect the interpreter's standard error output stream: sys.stderr = YourClass(window.edit, sys.__stderr__, QColor(Qt.red)) YourClass in an "file-like" object (it has an write function) window.edit is an instance of Qt's QTextEdit class and is used to display the message. Here is an example: http://series60-remote.svn.sf.net/viewvc/series60- remote/trunk/pc/series60-remote.py?view=markup , line 288 The class QtOutput is defined here: http://series60- remote.svn.sf.net/viewvc/series60- remote/trunk/pc/lib/log.py?revision=257&view=markup , line 36 And the window that actually displays an error message is here: http://series60-remote.svn.sf.net/viewvc/series60- remote/trunk/pc/window/log.py?view=markup A screenshot is here: http://imagebin.ca/view/5rSa--2X.html The Traceback is colored red in the window. Starting with this is should be easy to get a "report bug"-dialog ;-) If you have any questions please just ask. Greetings, Lukas Am Donnerstag 07 Mai 2009 13:17:54 schrieb Jeremy Sanders: > Is there a way to catch Python exceptions in all parts of a PyQt program? > > I have a "report bug" dialog box which gets called if an exception > occurs in the most frequently used parts of my program, but it would > be nice if I could catch every unhandled exception globally. > > The really nice thing about python is that program tends to keep > running despite an exception in a slot, so we don't get immediate data loss. > > Thanks > > Jeremy ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Detecting second copy of program in memory.[SOLVED]
Hello, I have found solution for my problem. So this post only for archiving in email list. Attaching example is a python version of this solution: http://wiki.qtcentre.org/index.php?title=SingleApplication It is possible to detect second instance of application and to send some string to it (sys.argv in my case). Thanks to all who answered my questions in this list! --- [EMAIL PROTECTED] import sys import thread,socket from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtNetwork import * timeout=1000 class SingleApplication(QApplication): def __init__(self, argv, uniqueKey): super(SingleApplication, self).__init__(argv) self._uniqueKey = uniqueKey self.sharedMemory = QSharedMemory(self._uniqueKey) if self.sharedMemory.attach(): self._isRunning = True else: self._isRunning = False if not self.sharedMemory.create(1): print "Unable to create single instance" return self.localServer = QLocalServer(self) self.connect(self.localServer, SIGNAL("newConnection()"), self.receiveMessage) self.localServer.listen(self._uniqueKey) def receiveMessage(self): localSocket = self.localServer.nextPendingConnection() if not localSocket.waitForReadyRead(timeout): print localSocket.errorString().toLatin1() return byteArray = localSocket.readAll() self.emit(SIGNAL("messageAvailable"), byteArray) localSocket.disconnectFromServer() def isRunning(self): return self._isRunning def sendMessage(self, message): if not self._isRunning: return False localSocket = QLocalSocket(self) localSocket.connectToServer(self._uniqueKey, QIODevice.WriteOnly) if not localSocket.waitForConnected(timeout): print localSocket.errorString().toLatin1() return False localSocket.write(message) if not localSocket.waitForBytesWritten(timeout): print localSocket.errorString().toLatin1() return False localSocket.disconnectFromServer() return True def dumpMessage(data): print data if __name__ == '__main__': app = SingleApplication( sys.argv,"key" ) if app.isRunning(): print "second copy detected!" app.sendMessage("message from other instance:"+str(sys.argv)) sys.exit(0) form = QMainWindow(None) QObject.connect(app, SIGNAL("messageAvailable"), dumpMessage) form.show() sys.exit(app.exec_()) ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Detecting second copy of program in memory.
Hello, I'd like to detect if user tries to launch 2 copies of program. First one should rise from minimised state, and second copy should gracefully exit if detecting first one. So user should see that he is already running program. Here is my lame attempt (please see attachment). Generally it works, but problem is: I can not receive events until app.exec_() is called. So second copy is showing QMainWindow object and _only then_ exits... Just run main.py and then run it again not closing first one to see blinking of second copy. Is there a way to make it more clever way (not showing QMainWindow)? --- [EMAIL PROTECTED] import sys import thread,socket from PyQt4 import QtCore,QtGui HOST='localhost' PORT= 50008 class InstanceChecker(QtCore.QThread): ''' class detects second copy of program in memory. ''' def __init__(self, parent=None): super(InstanceChecker, self).__init__(parent) def run(self): self.InstallSocketHandler() def SendData(self): ''' call this method to send data to first running instance ''' s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) s.send('Hello first copy!.This is from second copy!') s.close() def InstallSocketHandler(self): print "creating local socket..." s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.connectionStatus = False try: s.bind((HOST, PORT)) self.connectionStatus=True except socket.error: print "socket error!" # send data through socket to first copy self.SendData() self.emit(QtCore.SIGNAL("status"),'busy') if self.connectionStatus: self.emit(QtCore.SIGNAL("status"),'ok') s.listen(1) while 1: conn, addr = s.accept() data = conn.recv(1024) self.emit(QtCore.SIGNAL("datareceived"),data) if data == 'end': break conn.close() def datareceiver(data): print "receiving data from second copy :",data # raise window from minimized(possibly) state form.showNormal() def signalreceiver(data): print "signal received:",data if data == 'busy': print "First copy detected in memory : exiting now." sys.exit(1) if __name__ == '__main__': app = QtGui.QApplication(sys.argv) app.instanceChecker = InstanceChecker() app.instanceChecker.start() app.connect(app.instanceChecker,QtCore.SIGNAL("status"),signalreceiver) app.connect(app.instanceChecker,QtCore.SIGNAL("datareceived"),datareceiver) global form form = QtGui.QMainWindow(None) form.show() app.exec_() ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
RE: [PyQt] How to get an event after an Enter key is pressed?
I think QAction is the way to go: something like this works for me: delrecords = QtGui.QAction(self) # create action delrecords.setShortcut(QtCore.Qt.Key_Delete) # set shortcut key for that action .addAction(self.delrecords) # assign action to widget self.connect(self.delrecords, QtCore.SIGNAL("triggered()"), deleteRecords) # connect event is pressed in YOUR_WIDGET. --- [EMAIL PROTECTED] _ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of IloChab Sent: Friday, June 06, 2008 12:02 AM To: PyQt@riverbankcomputing.com Subject: [PyQt] How to get an event after an Enter key is pressed? I wrote an application where I display sql data on a QTableView+QSqlQueryModel read only table. The current version allows you to select via mouse a record on that table and then add it to an other one, pressing an add-button. I'd like to give an alternate way to do this: after record line is selected on the table I'd like to be called on the pression of enter's key and react to it just like if the add button was pressed. If is possible to obtain this behaviour I'd like to trap an other button too: I'd like to be called when delete's key is pressed while the record line is selected. Thanks in advance for your help. Ciao Licia ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] problem building PyQt-win-gpl-4.4.3-snapshot-20080601
Trying to build fresh snapshot with mingw compiler on windows. here is my build cmd file (c:\tmp\ is temporary directory where sources is unpacked): set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Qt\4.4.0\bin ;C:\MinGW\bin cd C:\tmp\sip-4.7.7-snapshot-20080530 C:/Python25/python configure.py -p win32-g++ mingw32-make mingw32-make install cd ..\ cd c:\tmp\PyQt-win-gpl-4.4.3-snapshot-20080601 rem rem Next command is failed to complete ok. rem C:/Python25/python configure.py -w mingw32-make mingw32-make install here is error : C:\tmp\PyQt-win-gpl-4.4.3-snapshot-20080601>c:\python25\python configure.py -w Determining the layout of your Qt installation... C:\Qt\4.4.0\bin\qmake.exe -o qtdirs.mk qtdirs.pro trying to compile release\qtdirs.exe mingw32-make -f qtdirs.mk release mingw32-make -f qtdirs.mk.Release mingw32-make[1]: Entering directory `C:/tmp/PyQt-win-gpl-4.4.3-snapshot-20080601' g++ -c -O2 -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\Qt\4.4.0\include\ QtCore" -I"..\..\Qt\4.4.0\include\QtCore" -I"..\..\Qt\4.4.0\include" -I"c:\Qt\4.4.0\include\ActiveQt" -I"release" -I"." -I"..\..\Qt\4.4.0\mkspecs\default" -o release\qtdirs.o qtdir s.cpp g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -mthreads -Wl -Wl,-subsystem,windows /incremental:no -o release\qtdirs.exe release/qtdirs. o -L"c:\Qt\4.4.0\lib" -lmingw32 -lqtmain -lQtCore4 g++: /incremental:no: No such file or directory mingw32-make[1]: *** [release\qtdirs.exe] Error 1 mingw32-make[1]: Leaving directory `C:/tmp/PyQt-win-gpl-4.4.3-snapshot-20080601' mingw32-make: *** [release] Error 2 PROBLEM making: mingw32-make -f qtdirs.mk release Error: Failed to determine the layout of your Qt installation. Try again using the --verbose flag to see more detail about the problem. I have digged into that process and found that " /incremental:no " is wrong directive for my g++.exe if I delete that directive than "qtdirs.exe" is build as .\release\qtdirs.exe ok. Is something wrong with my g++ version or setup? here is g++ version info: "g++ -v" says: C:\tmp\PyQt-win-gpl-4.4.3-snapshot-20080601\release>g++ -v Reading specs from C:/MinGW/bin/../lib/gcc/mingw32/3.4.2/specs Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host= mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable -languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --e nable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-ja va-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchroniz ation --enable-libstdcxx-debug Thread model: win32 gcc version 3.4.2 (mingw-special) --- Прищепов Игорь. [EMAIL PROTECTED] ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Porting new examples.
Hi, I'm testing new pyqt4.4.0 Seems like setting bitmap on the background of widget is not working. Demo example 'colliding mouse' don't display cheese bitmap as background. Can anyone confirm this behaviour? winxp, qt 4.4.0, pyqt 4.4.0. --- Прищепов Игорь. [EMAIL PROTECTED] ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Old problem with overriding QtGui .Qstyle.polish метод.
Hello, experts. Can anyone please explain why my little app is crashing? I'm doing anything wrong here? Please see code below (also as attached file): generally I'm trying to create my own style based on standard styles which comes with qt. == import sys from PyQt4 import QtCore, QtGui # testing abstract style which comes with pyqt # it crashes too. :( class AbstractStyle(QtGui.QStyle): def __init__(self,usecols=False): super(QtGui.QStyle,self).__init__() print "__init__ ok" def polish(self,args): print "polish started..." print "commenting out 'polish' method will prevent crush" print "now we going to crash :(" class WidgetGallery(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) if __name__ == "__main__": app = QtGui.QApplication(sys.argv) QtGui.QApplication.setStyle(AbstractStyle()) gallery = WidgetGallery() gallery.show() sys.exit(app.exec_()) === Info: winxp, pyqt 4.3.3 python 2.5 Can anyone check this script with current pyqt snapshot? May be this problem is fixed and I should rebuild my pyqt up-to-date ? Thanks. --- Igor [EMAIL PROTECTED] import sys from PyQt4 import QtCore, QtGui # testing abstract style which comes with pyqt # it crashes too. :( class AbstractStyle(QtGui.QStyle): def __init__(self,usecols=False): super(QtGui.QStyle,self).__init__() print "__init__ ok" def polish(self,args): print "polish started..." print "commenting out 'polish' method will prevent crush" print "now we going to crash :(" class WidgetGallery(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) if __name__ == "__main__": app = QtGui.QApplication(sys.argv) QtGui.QApplication.setStyle(AbstractStyle()) gallery = WidgetGallery() gallery.show() sys.exit(app.exec_()) ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Wrapping style classes with SIP for styling python application.
Hello, I'm trying to wrap unwrapped classes for styling my application. Well, seems it's not so trivial. I have managed successfully rebuild PyQt from sources with new wrappers for QCommonStyle,QMotifStyle But when I'm trying to overload method QMotifStyle.polish for example my application is crushed with access violation class NorwegianWoodStyle(QMotifStyle): ... ... def polish(self,palette): print "start" print "when finishing this line, app is crushing" def somethingelse(self) ... Actually I'm converting ..\Qt\4.3.3\examples\widgets\styles\norwegianwoodstyle.cpp to python. I'm suspecting that there is error in my hand coded QCommonSytle or QMotifStyle.sip somewhere. May be I didn't specify some SIP annotation for some method somwhere deeep in class hierarchy. I don't have much expierience with SIP files, actually it's only 2 days :). So the question is: Phil, can you generate those SIP files with your MetaSip package which is not available tо wide public and put them somewhere as separate package with note: "use on your own risk, I'm not officially supporting those files, because styles in Qt can be compiled like plugins and I'm not gonna supply them with main PyQt branch because of that, but if you brave enough than go ahead" If that's not possible than can you look at my hand coded files and tell me where I'm wrong? I will attach my files if overall effort have any sense. Because I spend a whole weekend ont this task but with not much success. >From time to time in mailing list I see that peoples are trying to do what I'm trying to do now: 'Made custom skin with python' I know about StyleSheets. And I have read that it's kinda slowww... So I will try to stick with overriding built in style classes and wrapping unwrapped classes. Sorry if I'm asking to much or if you can't (or wouldn't) do that I'm really appreciating you great PyQt package. --- Igor. [EMAIL PROTECTED] ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] QComboBox + custom model, view, completer fails.(with example)
Hello,all! I'm trying to build my own completion in QComboBox. My overall setup with this thing is not working.Apparently I'm doing something wrong here. But what? What I'm trying to do: let's suppose we have this completion list (for simplicity it's small and with one column only, real data have much more columns). So items goes like this: - item1 - item11 - item111 - item if I type '111' in QComboBox I want a popup with 'item111','item' because '111' is only in those items. I'm defined my own TreeView,SourceModel, SourceFilterModel(like proxy for filtering of SourceModel) and bind them to standard QComboBox. Than I did a little trick with passing focus to lineEdit and back to Popup. Well, my whole schema is not working. Python recursively calls 'somethingIsTyped' method in which I'm trying to force popup to be filtered and shown with new data and I got stack overflow catched by python interpreter. Please see attached example with comments. Can anybody enlighten me on what I'm doing wrong? System: Python 2.5, pyqt 4.3.3, qt 4.3.3, winxp. --- [EMAIL PROTECTED] import sys from PyQt4 import QtCore, QtGui, uic from PyQt4.QtCore import * app = QtGui.QApplication(sys.argv) form_class, base_class = uic.loadUiType("mainform.ui") class SourceModel(QtCore.QAbstractItemModel): """ sample model """ def __init__(self, parent=None): QtCore.QAbstractItemModel.__init__(self, parent) self.colLabels = ["column1","column2"] self.items=[ ['item1' , 'item2' ] , ['item11', 'item22'] , ['item111' , 'item222' ] , ['item' , 'item' ] , ['item1' , 'item2' ] , ] def index(self,row,column,parent): return self.createIndex(row,column,str(row)+str(column)) def parent(self, index): if not index.isValid(): return QtCore.QModelIndex() return QtCore.QModelIndex() def rowCount(self, parent): return len(self.items) def columnCount(self, parent): return len(self.colLabels) def data(self, index, role): if not index.isValid(): return QtCore.QVariant() elif role != QtCore.Qt.DisplayRole and role != QtCore.Qt.EditRole: return QtCore.QVariant() row = index.row() col = index.column() return QtCore.QVariant(str(self.items[row][col])) def flags(self, index): if not index.isValid(): return QtCore.Qt.ItemIsEnabled return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable def headerData(self, section, orientation, role): if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole: return QtCore.QVariant(self.colLabels[section]) return QtCore.QVariant() class SourceFilterModel(QtGui.QSortFilterProxyModel): """ used to filter and sort SourceModel. Acts like a proxy """ def __init__(self,parent): QtGui.QSortFilterProxyModel.__init__(self,parent) self.gui = parent def filterAcceptsRow(self,sourceRow,sourceParent): index = self.sourceModel().index(sourceRow,1,sourceParent) # get text from uderlying source model item_text = str(self.sourceModel().data(index,QtCore.Qt.DisplayRole).toString()) # get what user is typed in comboBox typed_text = str(self.gui.autoCombo.lineEdit().text()) # if typed text in item_text - then this item is Ok to show in # resulting filtering model if item_text.find(typed_text) == -1: return False else: return True class myTreeView(QtGui.QTreeView): """ display our model in 2 column plain list with headers """ def __init__(self, parent=None): QtGui.QTreeView.__init__(self, parent) # store MainForm instance for referencing autoCombo later. self.parent = parent def keyPressEvent(self, e): if e.key() in [QtCore.Qt.Key_Escape,QtCore.Qt.Key_Tab,QtCore.Qt.Key_Down,QtCore.Qt.Key_Up]: # escape, tab, Up, Down key events is passed to TreeView so we can # navigate popup list. QtGui.QTreeView.keyPressEvent(self,e) else: # typed chars is passed to autoCombo's lineEdit self.parent.autoCombo.keyPressEvent(e) class MainForm(QtGui.QDialog, form_class): def __init__(self, *args): QtGui.QWidget.__init__(self, *args) self.setupUi(self) self.treeView = QtGui.QTreeView(self) self.treeView.setSelectionMode(QtGui.QAbstractItemView.MultiSelection) self.treeView.setSortingEnabled(True) self.treeView.setAnimated(True) self.treeView.setWordWrap(True) self.treeView.setItemsExpandable(False) self.treeView.setRootIsDecorated(False) self.sourcemodel = SourceModel() self.proxyModel = SourceFilterModel(self
RE: [PyQt] QtGui.QMotifStyle not in PyQt?
Hello, Phil. > > And second question: anyone of you guys use custom themes like > NorwegianWood for example? > Do you build your own or just use embedded in Qt? (plastic, cde, > etc..) > Those sorts of decisions should normally be left to the user, not the developer. Yeah, I'm agreed on that, I just wanted to provide my own custom skin for user to decide which one to use. When creating skin I want to subclass from ready skins.(like Motif for example) C++ code in Qt example which is based on MotifStyle seems not very hard to convert to python. But creating own custom skin from scratch in python is a lot more work. Looks like it's not easy in PyQt to create one. > > Also how can I build QtDesigner package in order to use custom widgets > in design time? > May be there is binary build somewhere? > > My info: > winXP, python 2.5, PyQt 4.3.3, Qt 4.3 Open Source Edition. > You need to build Qt and PyQt yourself as non-static. I found a good and clean wiki page on that. Downloaded sip and pyqt sources. Will try to build one myself :) -- [EMAIL PROTECTED] ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
RE: [PyQt] QtGui.QMotifStyle not in PyQt?
Hello, Ulrich, nice to hear a response again from you :) I know about style sheets. Well, I'm not sure that I have a full control over the widget, when using style sheet. Also I can not find any widely available applications which utilises this feature, and looks cool and stunning. May be someone can provide a link or maybe screenshot? I'm interested in details of this feature. Example of style sheets in qt docs with student registration window is not very impressing. --- [EMAIL PROTECTED] ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] QtGui.QMotifStyle not in PyQt?
Hello,all! I'm looking in styling my pyqt application. There is nice python "styles" example ported from C++. But it's not complete port because NorwegianWood style is missing. In original C++ demo this example shows one more custom style build by user. So I'm digging deeper and find that QMotifStyle on which this NorwegianWood style is build is'n ported to python part. Is it done intentionally or it's just technologically hard to do? Or it's licensing issues? I'd like to build my own style for application. And second question: anyone of you guys use custom themes like NorwegianWood for example? Do you build your own or just use embedded in Qt? (plastic, cde, etc..) Also how can I build QtDesigner package in order to use custom widgets in design time? May be there is binary build somewhere? My info: winXP, python 2.5, PyQt 4.3.3, Qt 4.3 Open Source Edition. Thank you in advance. --- [EMAIL PROTECTED] ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
RE: [PyQt] Locale problem with dateEdit calendar popup (Solved by Ulrich!) :)
Thanks, Ulrich. Your solution is really helps me! Now everything is working as expected! Monday goes first in sample.py Unfortunately my pyqt installations (4.3.3) doesn't have PyQt4.QtDesigner package. I've remember reading somewhere in this list about this package " it's statically linked, you should build it yourself" or something ... Such a pity that I could not install custom plugin in Designer out of the box. But datetimeedit.py gives me good example and possible solution. I think I can proceed with that. Big thanks again! :) --- [EMAIL PROTECTED] ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Locale problem with dateEdit calendar popup
Hi there, I have dateEdit input widget with calendarPopup set to true. Underlying calendar widget shown and first comes Sunday,than Monday,then Tuesday etc.. here in Russia we counts weeks from Monday,Tuesday etc... I've discovered in docs this method: QCalendarWidget.setFirstDayOfWeek(Qt::DayOfWeek dayOfWeek). So this underlying popup calendar is tweakable. Question is: how get this object from dateEdit control? is there something like: mydateEdit = QtGui.dateEdit(bla bla bla) mydateEdit.getQCalendar.setFirstDayOfWeek(Monday) ^^ How can I access underlying Qcalendar popup in dateEdit in order to set his properties? Or may be there is global locale setup for Qt application by default? I have in my code those lines: from PyQt4 import QtCore, QtGui, uic import locale locale.setlocale(locale.LC_ALL,'Russian_Russia.1251') # setup global python locale for regexp etc... QtCore.QTextCodec.setCodecForLocale(QtCore.QTextCodec.codecForName("cp1251") ) QtCore.QTextCodec.setCodecForCStrings(QtCore.QTextCodec.codecForName("cp1251 ")) QtCore.QTextCodec.setCodecForTr(QtCore.QTextCodec.codecForName("cp1251")) Please note that my popup calendar is localized - I mean I see cyrillic letters, everything is ok except this "our Qt week starts from Sunday he-he." problem... :( Can anyone of subscribers of this list from countries where weeks starts from Monday (Europe?) check in designer how this widget is shown? Thank you in advance. My platform: python 2.5 pyqt 4.3.3 gpl, windows xp. --- [EMAIL PROTECTED] ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
RE: [PyQt] Qcompleter,dateEdit popup questions.
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Andreas Pakulat Sent: Wednesday, February 06, 2008 2:40 PM To: pyqt@riverbankcomputing.com Subject: Re: [PyQt] Qcompleter,dateEdit popup questions. On 06.02.08 11:53:14, Igor Prischepoff wrote: > Hello,everybody! > I'm new to PyQt and in process of > converting my application from wxPython to PyQt. > > I'd like to ask couple of question about nice QCompleter class in Qt > and PyQt. > > Question #1: > How can I build my own custom completer which completes on any char in > the item word? > It seems that default Qcompleter completes only if my items starts > with letters that I've started typing. > For example: here is my abstract model data: > > Item10 > Item110 > Item20 > Item220 > > If I type for example 'm10' then completer should provide only 2 > matches Item10 Item110 because 'm10' chars is found only in this two items. > > I've read documentation about QCompleter in Qt docs but can not find a > clue about methods used by Qcompleter when deciding which item from > model is matched to my typed word. Hi, Andreas! First of all, thank you for answering my question. > As far as I can see, what you need to do is to also provide "m10" as an entry in your completion model. Sorry,but my users can type anything and I have not possibilities to predict and add any possible combination of chars into completion list. So seems like Qcompleter is not intended for a job like this... May be I can work around with another widget. Btw, can I add some kind of custom popup widget to TextEdit control for example? --- [EMAIL PROTECTED] ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Qcompleter,dateEdit popup questions.
Hello,everybody! I'm new to PyQt and in process of converting my application from wxPython to PyQt. I'd like to ask couple of question about nice QCompleter class in Qt and PyQt. Question #1: How can I build my own custom completer which completes on any char in the item word? It seems that default Qcompleter completes only if my items starts with letters that I've started typing. For example: here is my abstract model data: Item10 Item110 Item20 Item220 If I type for example 'm10' then completer should provide only 2 matches Item10 Item110 because 'm10' chars is found only in this two items. I've read documentation about QCompleter in Qt docs but can not find a clue about methods used by Qcompleter when deciding which item from model is matched to my typed word. I think I should inherit from QCompleter something like this: class MyCompleter(QCompleter): def __init__(self, parent=None): super(MyCompleter, self).__init__(parent) self.model = MyCompletionModel() self.setModel(self.model) self.setCompletionColumn(0) Now the question is : which method should I override in order to intercept QCompleter decision about which item from model is fit for currently entered text? Is there something like this? : def complete_decison_method(self,item): prefix = self.completionPrefix() # Get typed text which shoud be completed or matched. if str(item).find(prefix) == -1 : # no - this item don't match entered text, don't show it in popup return False else # yes! this item matches somewhere with prefix - it's valid to complete! return True Can someone provide hint or url maybe? I've read http://doc.trolltech.com/4.2/qcompleter.html but don't find enough info to answer my question. Question #2: I have a dateEdit widget with calendarPopup = true. When calendar chooser is shown in popup - week is started from Sunday. Can I have a dateEdit widget with popup where week is started from Monday? My locale is correct I think, so in calendar popup I am seen russian letters, so problem is not in locale setup I think. My platform: Python 2.5, PyQt 4.3.3 GPL , winXP. --- [EMAIL PROTECTED] ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt