Re: [PyQt] Plugins not loading. Library paths dependent on order of code with QApplication.
On Fri, 12 Feb 2010 18:27:28 -0600, Matthew Sorenson verai...@veraiste.com wrote: Hi, The database plugins fail to load for me in certain situations. I believe I have narrowed the problem down to the differences between the examples at the end. Working with the databases before instantiating a QApplication seems to change the library paths. This doesn't appear to be the case when using C++ and Qt4. This could be the correct behavior, but I'm not sure. I discovered it trying to load the Assistant Eric Plugin in eric4. The plugin works for Detlev on various Linux, Win XP, and Win 7. The PluginAssistantEric.py script has the following check: drivers = QSqlDatabase.drivers() if drivers.contains(QSQLITE): return True else: error = self.trUtf8(The SQLite database driver is not available.) return False At this point, there are no drivers loaded and it returns false. Placing QtGui.QApplication.addLibraryPath(C:\Python26\Lib\site-packages\PyQt4\plugins) above this snippet will load the drivers. I am using PyQt 4.7 on Python 2.6.4 and eric 4.4.1. I'm not sure if this is expected behavior, a configuration error on my part, or an error within PyQt. I would appreciate any help. Thanks, Matthew Sorenson Assuming you are using the GPL binary installer, the path to the plugins directory isn't correct until the qt.conf file has been processed. This happens during the QCoreApplication ctor call. You might expect that it would also be done in QSqlDatabase.drivers() (as it might be influenced by the contents of the plugins directory) but that doesn't seem to be the case. Phil Examples: Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on hermes, Standard import sys from PyQt4 import QtGui, QtSql app = QtGui.QApplication(sys.argv) QtSql.QSqlDatabase.drivers().count() 7 db = QtSql.QSqlDatabase.addDatabase(QSQLITE) QtGui.QApplication.libraryPaths().count() 2 print QtGui.QApplication.libraryPaths()[0] C:/Python26/Lib/site-packages/PyQt4/plugins print QtGui.QApplication.libraryPaths()[1] C:/python26 - Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on hermes, Standard import sys from PyQt4 import QtGui, QtSql QtSql.QSqlDatabase.drivers().count() 0 app = QtGui.QApplication(sys.argv) QtSql.QSqlDatabase.drivers().count() 0 db = QtSql.QSqlDatabase.addDatabase(QSQLITE) StdErr: QSqlDatabase: QSQLITE driver not loaded QSqlDatabase: available drivers: QtGui.QApplication.libraryPaths().count() 1 print QtGui.QApplication.libraryPaths()[0] C:/python26 QtGui.QApplication.addLibraryPath(C:\Python26\Lib\site-packages\PyQt4\plugins) QtGui.QApplication.libraryPaths().count() 2 QtSql.QSqlDatabase.drivers().count() 7 db = QtSql.QSqlDatabase.addDatabase(QSQLITE) StdErr: QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work. QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] double free issue with OUT-argument
Hi, wrapping happily away a 3D-engine, I encounter the following problem: import irrlicht core = irrlicht.irr.core q = core.quaternion() q.toEuler() python(3701) malloc: *** error for object 0x474b70: double free *** set a breakpoint in malloc_error_break to debug (0.0, -0.0, 0.0) This is the declaration of toEuler in .sip: void toEuler(irr::core::vector3df euler /Out/) const; As you can see, it's supposed to modify a passed vector in place. However, I declared vectors to be converted from to tuples, by this code mapping: %MappedType irr::core::vector3df { %TypeHeaderCode #include vector3d.h %End %ConvertFromTypeCode if (!sipCpp) return PyTuple_New(0); irr::core::vector3df *v = (irr::core::vector3df *)sipCpp; return PyTuple_Pack(3, PyFloat_FromDouble(v-X),PyFloat_FromDouble(v-Y),PyFloat_FromDouble(v-Z)); %End %ConvertToTypeCode if (sipIsErr == NULL) { if(PySequence_Check(sipPy) PySequence_Length(sipPy) == 3) { for(int j = 0; j 3; j++) { PyObject *v = PySequence_GetItem(sipPy, j); if(!PyFloat_Check(v) !PyInt_Check(v)) { return false; } } return true; } return false; } if (sipPy == Py_None) { *sipCppPtr = NULL; return 0; } irr::core::vector3df *v = new irr::core::vector3df(); PyErr_Clear(); irr::core::vector3df t = *v; if(PyArg_ParseTuple(sipPy, fff, t.X, t.Y, t.Z)) { *sipCppPtr = v; return 1; } else { delete v; *sipIsErr = 1; return 0; } %End }; Looking at the generated code, it seems to me it is perfectly fine - it creates a new vector instance, passes that in, converts it to a tuple, and deletes it. extern C {static PyObject *meth_irr_core_quaternion_toEuler(PyObject *, PyObject *);} static PyObject *meth_irr_core_quaternion_toEuler(PyObject *sipSelf, PyObject *sipArgs) { int sipArgsParsed = 0; { irr::core::vector3df * a0; irr::core::quaternion *sipCpp; if (sipParseArgs(sipArgsParsed,sipArgs,B,sipSelf,sipType_irr_core_quaternion,sipCpp)) { PyObject *sipResult; a0 = new irr::core::vector3df(); sipCpp-toEuler(*a0); sipResult = sipConvertFromNewType(a0,sipType_irr_core_vector3df,NULL); delete a0; return sipResult; } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipArgsParsed,sipName_quaternion,sipName_toEuler); return NULL; } I don't understand the behavior - anything I miss? Regards, Diez ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] File Dialog Opens Twice
David, Detlev, OK, I am gonna guess that this line in setupUi is what you are both referring to: QtCore.QMetaObject.connectSlotsByName(Notepad) Here is what I was thinking: QtCore.QObject.connect(self.pushButton_2, QtCore.SIGNAL(clicked()), Notepad.close) QtCore.QMetaObject.connectSlotsByName(Notepad) I thought the first line took care of my close button, so I would have to take care of the open button in my file. The following archive makes it even more confusing for me: http://msemac.redwoods.edu/~darnold/junk/Archive.zip In test.py (generated from edytor.ui with pyuic4 edytor.uitest.py) I have the same connections in setupUi: self.retranslateUi(Notepad) QtCore.QObject.connect(self.pushButton_2, QtCore.SIGNAL(clicked()), Notepad.close) QtCore.QMetaObject.connectSlotsByName(Notepad) Yet in my test_start.py, I write: # here we connect signals with our slots QtCore.QObject.connect(self.ui.button_open,QtCore.SIGNAL(clicked()),self.file_dialog) def file_dialog(self): fd = QtGui.QFileDialog(self) plik = open(fd.getOpenFileName()).read() self.ui.editor_window.setText(plik) And I don't get the double open problem when I run test_start.py. I don't understand the difference. Can you explain? David. On Feb 12, 2010, at 8:13 PM, David Boddie wrote: On Sat Feb 13 02:07:44 GMT 2010, David Arnold wrote: [...] class Notepad(QMainWindow, Ui_Notepad): def __init__(self, parent = None): QMainWindow.__init__(self, parent) self.setupUi(self) ^^^ Connection 1 (behind the scenes) self.connect(self.button_open, SIGNAL(clicked()), self.on_button_open_clicked) ^^^ Connection 2 @pyqtSignature() def on_button_open_clicked(self): fd=QFileDialog(self) plik=open(fd.getOpenFileName()).read() self.editor_window.setText(plik) However, when I run the project and click on the Open button, the file dialog opens, I select start.py in the SimpleTextEditor folder, press OK and it opens fine in the QTextEdit window. However, then the QFileDialog opens a second time. Weird. Can anyone explain what I am doing wrong? You called setupUi(self) which connects all the signals to specially-named slots like the one you defined (on_button_open_clicked) and decorated with @pyqtSignature. Then you explicitly connected the push button's signal to the slot again. So, when the button is pressed, the slot will be invoked twice and the dialog will be opened twice. David ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Fonts on Macbook
All, I am trying a zetcode tutorial file: import sys from PyQt4 import QtGui from PyQt4 import QtCore class Tooltip(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.setGeometry(300, 300, 250, 150) self.setWindowTitle('Tooltip') self.setToolTip('This is a bQWidget/b widget') QtGui.QToolTip.setFont(QtGui.QFont('Arial', 20)) app=QtGui.QApplication(sys.argv) tp=Tooltip() tp.show() sys.exit(app.exec_()) No matter what changes I make to this line: QtGui.QToolTip.setFont(QtGui.QFont('Arial', 20)) The results are always the same. Are there any Mac users out there who can actually change fonts and fontsize in this script? David ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] since SIP 4.10: closures loosing outer variables!
On Sat, 13 Feb 2010 22:47:35 +0100, Wilbert Berendsen wbs...@xs4all.nl wrote: Hi, since my system upgraded SIP to 4.10 (and KDE to 4.4) my own PyKDE4 app Frescobaldi has strange garbage collection issues all over the place, with error messages like: NameError: free variable 'docGroup' referenced before assignment in enclosing scope It seems that when I connect a local or lambda function to a Qt signal, the function remains alive but it looses the references its outer variables! The objects those outer variables point to are still there (they work as usual), but they just become unreachable from local or lambda functions. I can circumvent the problem by passing in those outer variables as default arguments, but that is kind of clumsy. How come the outer variables are garbage collected but the function containing them not? Is this a bug in SIP or PyQt or should I adapt a different coding style? (i.e. without anonymous or local functions) ? ... Do you have a test case? Phil ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Fonts on Macbook
On 13 Feb 2010, at 20:17, David Arnold wrote: No matter what changes I make to this line: QtGui.QToolTip.setFont(QtGui.QFont('Arial', 20)) The results are always the same. Are there any Mac users out there who can actually change fonts and fontsize in this script? I confirm that this does not seem to have any effect on Mac. However, you can change the appearance of tooltips by using a stylesheet: import sys from PyQt4 import QtGui from PyQt4 import QtCore class Tooltip(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.setGeometry(300, 300, 250, 150) self.setWindowTitle('Tooltip') tip_style = QToolTip { border: 2px solid green; border-radius: 4px; padding: 2px; font-family: Arial; font-size: 20pt; } self.setStyleSheet(tip_style) self.setToolTip('This is a bQWidget/b widget') app=QtGui.QApplication(sys.argv) tp=Tooltip() tp.show() sys.exit(app.exec_()) If you want all tooltips to have the same non-default appearance then I think that you could use QApplication's setStyleSheet method instead of QWidget's one. -- CMcP ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] addAction to menubar
Hi, I'm trying some of the zetcode tutorials. How come no menu item shows up on my Macbook when I execute the following? # menubar.py import sys from PyQt4 import QtGui, QtCore class MainWindow(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) self.resize(250, 150) self.setWindowTitle('menubar') exit = QtGui.QAction(QtGui.QIcon('icons/exit.png'), 'Exit', self) exit.setShortcut('Ctrl+Q') exit.setStatusTip('Exit application') self.connect(exit, QtCore.SIGNAL('triggered()'), QtCore.SLOT('close()')) self.statusBar() menubar = self.menuBar() file = menubar.addMenu('File') file.addAction(exit) app = QtGui.QApplication(sys.argv) main = MainWindow() main.show() sys.exit(app.exec_()) ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt