Re: [PyQt] QtDBus: Calling a method with an Array of Strings signature with Python 3
On Sun, 04 Dec 2011 20:17:52 +, Chris Mayo wrote: > With Python 2 I can do (where /dev/sr0 is a cdrom): > > bus = QtDBus.QDBusConnection.systemBus() > device_iface = QtDBus.QDBusInterface('org.freedesktop.UDisks', > '/org/freedesktop/UDisks/devices/sr0', 'org.freedesktop.UDisks.Device', > bus) > reply = device_iface.call("DriveEject", QStringList()) > > > But with Python 3 this won't work because of QStringList. If I modify it > with: > > reply = device_iface.call("DriveEject", ["", ]) > print(reply.errorMessage()) > > I get: > > Method "DriveEject" with signature "av" on interface > "org.freedesktop.UDisks.Device" doesn't exist > > Chris > > PyQt-x11-gpl-snapshot-4.9-65564eb2fcf4 Try this... arg = QDBusArgument() arg.beginArray(QMetaType.QString) arg.add("") arg.endArray() ...and pass arg to call(). If that works I'll change QDBusArgument so that you can do... call("DeviceEject", QDBusArgument([""], QMetaType.QStringList)) Phil ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Refresh a treeWidget but not it's expand/collapse
On 12/4/2011 12:42 PM, Christopher Evans wrote: What's the best way to refresh/rebuild a treeWidget without blowing away the user's depth traversal and framing? Anyone have a small fn for this? I guess you query the state of all leaves/branches of the treeWidget then reapply it? In qtalchemy, I save selection and expansion state in the "modelAboutToBeReset" signal and restore the state in "modelReset". I save a list of the expanded nodes. You can see the source for yourself at https://bitbucket.org/jbmohler/qtalchemy/src/2a6a6c014c1f/qtalchemy/widgets/tree.py -- the main logic is in the saveRowState and loadRowState at line 115 and 129 respectively. The state is saved in the RowState class at the bottom of that source file. It's very short & basic, but works for my applications. I suppose it's also crucial to understand that I store the object id (obtained by objectConverter which takes an object and returns the primary key) which is most commonly a table primary key. I imagine it might sometimes make sense to store the model index which would be the integer index, but then you'd need to deal with the fact that you might be inserting more records and therefore your integer indices change on reload. Obviously, I'm thinking fairly strictly in terms of a database driven application here. If you have cells other than column zero expanded it will fail (I hard-code 0 in the columnIndices helper function), but I haven't yet been able to fully grok a sensible usage for the Qt hierarchical model notions beyond expanding only on column 0. More exotic hierarchies seem discouraged anyhow. Joel ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Subclass of QGraphicsObject does not have the correct class name listed in QGraphicsScene.items()
Howdy Phil, I'm running into this issue where QGraphicsScene.items() does not return the correct python objects if the items are subclassed from QGraphicsObject. Your response to this issue several months ago was: On Fri, May 20, 2011 at 11:46, Phil Thompson wrote: > It's because QGraphicsObject inherits both QObject and QGraphicsItem. > items() returns a list of QGraphicsItems which, for a QGraphicsObject, has > a different C++ address than the original QGraphicsObject. PyQt doesn't > recognise that the QGraphicsItem is a cast of the QGraphicsObject. I don't > think there is anything I can (sensibly) do about this. The workaround I am using for this bug is to maintain a dictionary that maps from the QtGui::QGraphicsItem memory address back to the original python object. Looks something like: cache[ sip.unwrapinstance(sip.cast(item, QtGui.QGraphicsItem)) ] = item This works, but it's rather messy since every instance of QGraphicsObject and QGraphicsWidget needs to register itself with this cache. I presume PyQt already maintains a similar dictionary so that it can translate between Qt's internal memory addresses and PyQt's wrapper objects. Would it not be straightforward to implement my workaround from within PyQt? Luke ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] QtDBus: Calling a method with an Array of Strings signature with Python 3
Try this... arg = QDBusArgument() arg.beginArray(QMetaType.QString) arg.add("") arg.endArray() and pass arg to call(). Doesn't seem to work: device_iface = QtDBus.QDBusInterface('org.freedesktop.UDisks', '/org/freedesktop/UDisks/devices/sr0', 'org.freedesktop.UDisks.Device', bus) arg = QtDBus.QDBusArgument() arg.beginArray(QMetaType.QString) arg.add("") arg.endArray() reply = device_iface.call("DriveEject", arg) print(reply.errorMessage()) Returns: Unknown option PyQt-x11-gpl-snapshot-4.9-512e7813ed74 Chris ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] QtDBus: Calling a method with an Array of Strings signature with Python 3
On Mon, 05 Dec 2011 19:12:33 +, Chris Mayo wrote: >> >> Try this... >> >> arg = QDBusArgument() >> arg.beginArray(QMetaType.QString) >> arg.add("") >> arg.endArray() >> >> and pass arg to call(). > > Doesn't seem to work: > > device_iface = QtDBus.QDBusInterface('org.freedesktop.UDisks', > '/org/freedesktop/UDisks/devices/sr0', 'org.freedesktop.UDisks.Device', > bus) > > arg = QtDBus.QDBusArgument() > arg.beginArray(QMetaType.QString) > arg.add("") > arg.endArray() > > reply = device_iface.call("DriveEject", arg) > print(reply.errorMessage()) > > > Returns: > > Unknown option ...because "" is not a valid option? According to... http://hal.freedesktop.org/docs/udisks/Device.html#Device.DriveEject ..."unmount" is the only valid option. Phil ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Subclass of QGraphicsObject does not have the correct class name listed in QGraphicsScene.items()
On Mon, 5 Dec 2011 12:24:57 -0500, Luke Campagnola wrote: > Howdy Phil, > I'm running into this issue where QGraphicsScene.items() does not > return the correct python objects if the items are subclassed from > QGraphicsObject. Your response to this issue several months ago was: > > On Fri, May 20, 2011 at 11:46, Phil Thompson > wrote: >> It's because QGraphicsObject inherits both QObject and QGraphicsItem. >> items() returns a list of QGraphicsItems which, for a QGraphicsObject, >> has >> a different C++ address than the original QGraphicsObject. PyQt doesn't >> recognise that the QGraphicsItem is a cast of the QGraphicsObject. I >> don't >> think there is anything I can (sensibly) do about this. > > The workaround I am using for this bug is to maintain a dictionary > that maps from the QtGui::QGraphicsItem memory address back to the > original python object. Looks something like: > cache[ sip.unwrapinstance(sip.cast(item, QtGui.QGraphicsItem)) ] = item > > This works, but it's rather messy since every instance of > QGraphicsObject and QGraphicsWidget needs to register itself with this > cache. I presume PyQt already maintains a similar dictionary so that > it can translate between Qt's internal memory addresses and PyQt's > wrapper objects. Would it not be straightforward to implement my > workaround from within PyQt? Not straightforward, but certainly worth thinking about. Do you have something small I can use as a test case? Phil ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Subclass of QGraphicsObject does not have the correct class name listed in QGraphicsScene.items()
How about this: from PyQt4 import QtCore, QtGui import sip class GObject(QtGui.QGraphicsObject): def boundingRect(self): return QtCore.QRectF(0, 0, 10, 10) def paint(self, p, *args): p.drawRect(self.boundingRect()) app = QtGui.QApplication([]) scene = QtGui.QGraphicsScene() obj = GObject() scene.addItem(obj) items = scene.items(QtCore.QPointF(0,0)) objAddr = sip.unwrapinstance(sip.cast(obj, QtGui.QGraphicsItem)) itemAddr = sip.unwrapinstance(sip.cast(items[0], QtGui.QGraphicsItem)) print "Adresses match:", objAddr == itemAddr print "QGraphicsObject matches:", obj is items[0] On Mon, Dec 5, 2011 at 16:33, Phil Thompson wrote: > On Mon, 5 Dec 2011 12:24:57 -0500, Luke Campagnola > > wrote: >> Howdy Phil, >> I'm running into this issue where QGraphicsScene.items() does not >> return the correct python objects if the items are subclassed from >> QGraphicsObject. Your response to this issue several months ago was: >> >> On Fri, May 20, 2011 at 11:46, Phil Thompson >> wrote: >>> It's because QGraphicsObject inherits both QObject and QGraphicsItem. >>> items() returns a list of QGraphicsItems which, for a QGraphicsObject, >>> has >>> a different C++ address than the original QGraphicsObject. PyQt doesn't >>> recognise that the QGraphicsItem is a cast of the QGraphicsObject. I >>> don't >>> think there is anything I can (sensibly) do about this. >> >> The workaround I am using for this bug is to maintain a dictionary >> that maps from the QtGui::QGraphicsItem memory address back to the >> original python object. Looks something like: >> cache[ sip.unwrapinstance(sip.cast(item, QtGui.QGraphicsItem)) ] = > item >> >> This works, but it's rather messy since every instance of >> QGraphicsObject and QGraphicsWidget needs to register itself with this >> cache. I presume PyQt already maintains a similar dictionary so that >> it can translate between Qt's internal memory addresses and PyQt's >> wrapper objects. Would it not be straightforward to implement my >> workaround from within PyQt? > > Not straightforward, but certainly worth thinking about. > > Do you have something small I can use as a test case? > > Phil ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt