Subject: Re: Subject: Re: [PATCH] Support for arbitrary main script names in Python plasmoids
-- Messaggio inoltrato -- From: Richard Dale richard.j.d...@gmail.com To: plasma-devel@kde.org Date: Fri, 12 Feb 2010 23:59:06 + Subject: Re: Subject: Re: [PATCH] Support for arbitrary main script names in Python plasmoids On Fri, Feb 12, 2010 at 10:17 AM, Richard Dale richard.j.d...@gmail.com wrote: On Thu, Feb 11, 2010 at 11:34 PM, Diego Casella ([Po]lentino) polentino...@gmail.com wrote: -- Messaggio inoltrato -- From: Richard Dale richard.j.d...@gmail.com To: plasma-devel@kde.org Date: Thu, 11 Feb 2010 18:37:55 + Subject: Re: [PATCH] Support for arbitrary main script names in Python plasmoids On Thu, Feb 11, 2010 at 6:02 PM, Luca Beltrame ei...@heavensinferno.net wrote: 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). Well currently in Plasmate there is not way to specifiy the main script (or main class). Actually, the main script and main class names are taken from the project name; if you create a RubyClock project, Plasmate will create a rubyclock.rb file, with a MainRubyClock class inside it :) The Ruby plasmoid implementation doesn't use the Ruby equivalent of __dict__, but simply derives the main class name from the main script name. So I wasn't sure is you should specifiy a main *class* name in Plasmate like FooBar which would give a main script name of foo_bar.rb. Or whether you should give a main script name of foo_bar.rb the Plasmate form from which the class 'FooBar' is then derived. Currently in Plasmate the name of the applet is used to derive both the module (like a namespace), and the name of the class, which I think is wrong. For example, if you call your applet FooBar you get: module FooBar class FooBar PlasmaScripting::Applet ... I would rather the class was called 'Main' if you don't specifiy a main script. I'm sorry, but this is wrong: I've taken care of avoiding it since the beginning (I also reverted, a couple of days ago, a commit[1] that did exactly what you just described ). Ah OK - I was testing what the 'The_User' had just commited, which you have reverted. I think the name of the main script was wrong for MainForBar - it should be code/main_foo_bar.rb, and fixing that was why he made the change. Personally if a main script isn't specified I would prefer a class name of 'Main' and main script of 'main.rb' for Ruby. I've just commited some changes to the Ruby folder and main script name generation in Ruby so that it now works correctly. If you name you project FooBar it will be put in a folder called 'foo_bar' and the main script will be called 'main_foo_bar.rb'. If you don't follow this convention the correct module and class name will not be generated when the Ruby script engine tries to load the applet. I also enabled creating Ruby Data Engines, as the Ruby api works file. -- Richard That's great, thanks :) ___ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel ___ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel
Re: Subject: Re: [PATCH] Support for arbitrary main script names in Python plasmoids
On Thu, Feb 11, 2010 at 11:34 PM, Diego Casella ([Po]lentino) polentino...@gmail.com wrote: -- Messaggio inoltrato -- From: Richard Dale richard.j.d...@gmail.com To: plasma-de...@kde.org Date: Thu, 11 Feb 2010 18:37:55 + Subject: Re: [PATCH] Support for arbitrary main script names in Python plasmoids On Thu, Feb 11, 2010 at 6:02 PM, Luca Beltrame ei...@heavensinferno.net wrote: 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). Well currently in Plasmate there is not way to specifiy the main script (or main class). Actually, the main script and main class names are taken from the project name; if you create a RubyClock project, Plasmate will create a rubyclock.rb file, with a MainRubyClock class inside it :) The Ruby plasmoid implementation doesn't use the Ruby equivalent of __dict__, but simply derives the main class name from the main script name. So I wasn't sure is you should specifiy a main *class* name in Plasmate like FooBar which would give a main script name of foo_bar.rb. Or whether you should give a main script name of foo_bar.rb the Plasmate form from which the class 'FooBar' is then derived. Currently in Plasmate the name of the applet is used to derive both the module (like a namespace), and the name of the class, which I think is wrong. For example, if you call your applet FooBar you get: module FooBar class FooBar PlasmaScripting::Applet ... I would rather the class was called 'Main' if you don't specifiy a main script. I'm sorry, but this is wrong: I've taken care of avoiding it since the beginning (I also reverted, a couple of days ago, a commit[1] that did exactly what you just described ). Ah OK - I was testing what the 'The_User' had just commited, which you have reverted. I think the name of the main script was wrong for MainForBar - it should be code/main_foo_bar.rb, and fixing that was why he made the change. Personally if a main script isn't specified I would prefer a class name of 'Main' and main script of 'main.rb' for Ruby. Plasmate creates by default a MainProjectName class for ruby and python plasmoids. -- Richard ___ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel
Re: Subject: Re: [PATCH] Support for arbitrary main script names in Python plasmoids
On Fri, Feb 12, 2010 at 10:17 AM, Richard Dale richard.j.d...@gmail.com wrote: On Thu, Feb 11, 2010 at 11:34 PM, Diego Casella ([Po]lentino) polentino...@gmail.com wrote: -- Messaggio inoltrato -- From: Richard Dale richard.j.d...@gmail.com To: plasma-de...@kde.org Date: Thu, 11 Feb 2010 18:37:55 + Subject: Re: [PATCH] Support for arbitrary main script names in Python plasmoids On Thu, Feb 11, 2010 at 6:02 PM, Luca Beltrame ei...@heavensinferno.net wrote: 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). Well currently in Plasmate there is not way to specifiy the main script (or main class). Actually, the main script and main class names are taken from the project name; if you create a RubyClock project, Plasmate will create a rubyclock.rb file, with a MainRubyClock class inside it :) The Ruby plasmoid implementation doesn't use the Ruby equivalent of __dict__, but simply derives the main class name from the main script name. So I wasn't sure is you should specifiy a main *class* name in Plasmate like FooBar which would give a main script name of foo_bar.rb. Or whether you should give a main script name of foo_bar.rb the Plasmate form from which the class 'FooBar' is then derived. Currently in Plasmate the name of the applet is used to derive both the module (like a namespace), and the name of the class, which I think is wrong. For example, if you call your applet FooBar you get: module FooBar class FooBar PlasmaScripting::Applet ... I would rather the class was called 'Main' if you don't specifiy a main script. I'm sorry, but this is wrong: I've taken care of avoiding it since the beginning (I also reverted, a couple of days ago, a commit[1] that did exactly what you just described ). Ah OK - I was testing what the 'The_User' had just commited, which you have reverted. I think the name of the main script was wrong for MainForBar - it should be code/main_foo_bar.rb, and fixing that was why he made the change. Personally if a main script isn't specified I would prefer a class name of 'Main' and main script of 'main.rb' for Ruby. I've just commited some changes to the Ruby folder and main script name generation in Ruby so that it now works correctly. If you name you project FooBar it will be put in a folder called 'foo_bar' and the main script will be called 'main_foo_bar.rb'. If you don't follow this convention the correct module and class name will not be generated when the Ruby script engine tries to load the applet. I also enabled creating Ruby Data Engines, as the Ruby api works file. -- Richard ___ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel
Re: [PATCH] Support for arbitrary main script names in Python plasmoids
On February 11, 2010, Luca Beltrame wrote: 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. i can't comment on the use of __dict__ (my python-fu is non-existent :) but using mainScript() is obviously correct from a libplasma API usage perspective and if this fixes things then yes it should be backported. -- Aaron J. Seigo humru othro a kohnu se GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA EE75 D6B7 2EB1 A7F1 DB43 KDE core developer sponsored by Qt Development Frameworks ___ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel
Re: [PATCH] Support for arbitrary main script names in Python plasmoids
In data giovedì 11 febbraio 2010 19:16:53, Aaron J. Seigo ha scritto: i can't comment on the use of __dict__ (my python-fu is non-existent :) but using mainScript() is obviously correct from a libplasma API usage perspective and if this fixes things then yes it should be backported. Just tested this in Plasmate, which I know uses custom main scripts (after working around a bug there), and it works perfectly. My old scripts, which use main.py, also work OK. I'll commit to trunk and backport soon. 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
Re: [PATCH] Support for arbitrary main script names in Python plasmoids
On Thu, Feb 11, 2010 at 6:02 PM, Luca Beltrame ei...@heavensinferno.net wrote: 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). Well currently in Plasmate there is not way to specifiy the main script (or main class). The Ruby plasmoid implementation doesn't use the Ruby equivalent of __dict__, but simply derives the main class name from the main script name. So I wasn't sure is you should specifiy a main *class* name in Plasmate like FooBar which would give a main script name of foo_bar.rb. Or whether you should give a main script name of foo_bar.rb the Plasmate form from which the class 'FooBar' is then derived. Currently in Plasmate the name of the applet is used to derive both the module (like a namespace), and the name of the class, which I think is wrong. For example, if you call your applet FooBar you get: module FooBar class FooBar PlasmaScripting::Applet ... I would rather the class was called 'Main' if you don't specifiy a main script. For Python, what if there are several classes in the the python main script file - how do you tell which one is for the applet you want to instantiate? 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? ___ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel ___ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel
Re: [PATCH] Support for arbitrary main script names in Python plasmoids
In data giovedì 11 febbraio 2010 19:37:55, Richard Dale ha scritto: __dict__, but simply derives the main class name from the main script name. So I wasn't sure is you should specifiy a main *class* name in This is what is done with my change, at the moment (I used __dict__ because I thought it was the best solution - suggestions welcome in case as I'm not that experienced). Earlier, the main script name was forced to be called main or it would cause errors. For Python, what if there are several classes in the the python main script file - how do you tell which one is for the applet you want to instantiate? You use the one that's called by CreateApplet, which needs to be put in the main script file: class FooApplet(plasmascript.Applet): ... def CreateApplet(parent): return FooApplet(parent) and the relevant bit is then called in the initialization: self.pyapplet = self.module.__dict__[basename].CreateApplet(None) so CreateApplet should *always* return the right applet and must be in the main script file. 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
Subject: Re: [PATCH] Support for arbitrary main script names in Python plasmoids
-- Messaggio inoltrato -- From: Richard Dale richard.j.d...@gmail.com To: plasma-devel@kde.org Date: Thu, 11 Feb 2010 18:37:55 + Subject: Re: [PATCH] Support for arbitrary main script names in Python plasmoids On Thu, Feb 11, 2010 at 6:02 PM, Luca Beltrame ei...@heavensinferno.net wrote: 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). Well currently in Plasmate there is not way to specifiy the main script (or main class). Actually, the main script and main class names are taken from the project name; if you create a RubyClock project, Plasmate will create a rubyclock.rb file, with a MainRubyClock class inside it :) The Ruby plasmoid implementation doesn't use the Ruby equivalent of __dict__, but simply derives the main class name from the main script name. So I wasn't sure is you should specifiy a main *class* name in Plasmate like FooBar which would give a main script name of foo_bar.rb. Or whether you should give a main script name of foo_bar.rb the Plasmate form from which the class 'FooBar' is then derived. Currently in Plasmate the name of the applet is used to derive both the module (like a namespace), and the name of the class, which I think is wrong. For example, if you call your applet FooBar you get: module FooBar class FooBar PlasmaScripting::Applet ... I would rather the class was called 'Main' if you don't specifiy a main script. I'm sorry, but this is wrong: I've taken care of avoiding it since the beginning (I also reverted, a couple of days ago, a commit[1] that did exactly what you just described ). Plasmate creates by default a MainProjectName class for ruby and python plasmoids. So we don't have naming collision :) For Python, what if there are several classes in the the python main script file - how do you tell which one is for the applet you want to instantiate? 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? ___ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel [1] http://websvn.kde.org/trunk/playground/base/plasma/plasmate/templates/mainPlasmoid.rb ___ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel
Subject: Re: [PATCH] Support for arbitrary main script names in Python plasmoids
-- Messaggio inoltrato -- From: Luca Beltrame ei...@heavensinferno.net To: plasma-devel@kde.org Date: Thu, 11 Feb 2010 19:32:13 +0100 Subject: Re: [PATCH] Support for arbitrary main script names in Python plasmoids In data giovedì 11 febbraio 2010 19:16:53, Aaron J. Seigo ha scritto: i can't comment on the use of __dict__ (my python-fu is non-existent :) but using mainScript() is obviously correct from a libplasma API usage perspective and if this fixes things then yes it should be backported. Just tested this in Plasmate, which I know uses custom main scripts (after working around a bug there), and it works perfectly. My old scripts, which use main.py, also work OK. That's great, thanks =) I'll commit to trunk and backport soon. ___ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel