[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    [PyQt] [Python plugin] menu items: actions binding with cycle
From:       Anne Ghisla <a.ghisla () studenti ! uninsubria ! it>
Date:       2008-07-30 9:15:09
Message-ID: 1217409309.6458.27.camel () galadriel
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


Hello all,

I'm developing a plugin for QGIS using:
- PyQt 4.3.3-2ubuntu4.1 
- Python 2.5.2
- Qt4

I'm populating a submenu with 4 items:

[code]
# create action for MCP submenu
self.actionmcp = QAction(QIcon(""), "MCP", self.iface.getMainWindow())
self.actionmcp.setWhatsThis("None")
QObject.connect(self.actionmcp, SIGNAL("activated()"), lambda
method="mcp": self.showInterface(method))  

# create action for kernel href submenu
self.actionhref = QAction(QIcon(""), "Kernel
href",self.iface.getMainWindow())
self.actionhref.setWhatsThis("None")
QObject.connect(self.actionhref, SIGNAL("activated()"),  lambda
method="href": self.showInterface(method))
[/code]

...and so on.

The code is clearly self-similar. 
I tried to write a cycle to populate the menu, but it doesn't work.

[code]
mth = {"mcp":"MCP", "href":"Kernel h ref", "lscv":"Kernel h LSCV",
"hadj":"Kernel with adjusted h"}
[declaration of self.action* outside cycle]
for k, v in self.mth.iteritems():
 a = getattr(self,  "action" + k)
 a = QAction(QIcon(""), v , self.iface.getMainWindow())
 a.setWhatsThis("None")
 QObject.connect(a, SIGNAL("activated()"), lambda method=k:
self.showInterface(method))
[/code]

I get no errors when running QGIS from a shell, but no submenu is
displayed.
I've also tried to assign QAction(QIcon(""), v ,
self.iface.getMainWindow()) directly on getattr(), but Python didn't
allow to assign to a function.

Any suggestions? 

regards,

Anne Ghisla

["signature.asc" (application/pgp-signature)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic