Hello,

currently if you use Python plasmoids the main script *must* be named 
"main.py" because it is hardcoded into pyappletscripts.py. When using a 
different mainscript in the .desktop file (like Plasmate does) this will 
ensure the plasmoid will not run (you get a NameError exception).

The attached patch fixes this by retrieving the mainscript file, stripping it 
to its name and then using Python introspection (__dict__) to pass the right 
module name to the CreateApplet call. 

After applying, old plasmoids (using main.py) and new ones (using *any name*) 
seem to work correctly.

OK to commit? Should this also be backported?
--- pyappletscript.py.old	2010-02-11 18:57:30.000000000 +0100
+++ pyappletscript.py	2010-02-11 18:54:40.000000000 +0100
@@ -57,7 +57,12 @@
             relpath = relpath[:-3]
         relpath = relpath.replace("/",".")
         self.module = __import__(self.pluginName+'.'+relpath)
-        self.pyapplet = self.module.main.CreateApplet(None)
+
+        # Plasma main scripts not necessarily are named "main"
+        # So we use __dict__ to get the right main script name
+        basename = os.path.basename(str(self.mainScript()))
+        basename = os.path.splitext(basename)[0]
+        self.pyapplet = self.module.__dict__[basename].CreateApplet(None)
         self.pyapplet.setApplet(self.applet())
         self.pyapplet.setAppletScript(self)
         self.connect(self.applet(), SIGNAL('extenderItemRestored(Plasma::ExtenderItem*)'),

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel

Reply via email to