Put your plug-ins in a plug-in folder. Each plugin is a .py file and you
should just
think of it as a module. Make it a convention that each plugin has a
standard
PlugInPanel that all the stuff is on.
2. When the user wants to select a plug-in, use a wxFileDialog aimed
at that folder (or if you want it to be neater, a wxChoice with the plug-in
names generated from looking at that folder)
plugin_name =3D filedialog.GetFilename()
3. You need to import that plugin’s namespace.
Something like:
plug_in =3D import(plugin_name)
( import allows you to import using a string)
4. Add the panel in it to the notebook:
page =3D plug_in.PlugInPanel(self.notebook, -1)
self.notebook.AddPage(page, plugin_name)
HTH,
Che
Thanks Che,
You completed what I was still missing!
I didn’t know how to import a module dynamically using a string. So the import function was a critical function that I was still missing.
Hi, Tom. Here's some thoughts....(not tested)
1. Put your plug-ins in a plug-in folder. Each plugin is a .py file and
you
should just
think of it as a module. Make it a convention that each plugin has a
standard
PlugInPanel that all the stuff is on.
2. When the user wants to select a plug-in, use a wxFileDialog aimed
at that folder (or if you want it to be neater, a wxChoice with the
plug-in
names generated from looking at that folder)
plugin_name =3D filedialog.GetFilename()
3. You need to import that plugin's namespace.
Something like:
plug_in =3D __import__(plugin_name)
( __import__ allows you to import using a string)
4. Add the panel in it to the notebook:
page =3D plug_in.PlugInPanel(self.notebook, -1)
self.notebook.AddPage(page, plugin_name)
HTH,
Che
Thanks Che,
You completed what I was still missing!
I didn't know how to import a module dynamically using a string. So the
__import__ function was a critical function that I was still missing.
If you use eggs you could define entry points. I tend to not make my
plugins direct wx subclasses. Instead I will have a plugin that will
have methods like get_notebook_page_class, get_preference_page, and
get_menu that will return the related wx things. Makes things easier
to separate in the module.
Also, if you make all of your plugins subclass a base plugins class,
you can get them really easy:
class a(object):
... pass
...
class b(a):
... pass
...
class c(a):
... pass
...
a.__subclasses__()
[<class '__main__.b'>, <class '__main__.c'>]
Regards,
Nate
···
On Fri, Apr 24, 2009 at 06:00, Tom Clerckx <tclerckx@gmail.com> wrote:
I am sticking to 2.5 for some time while other things catch up to it (and it works
fine for me), but in case you try 2.6 at some point, keep that in mind. Not sure
what the new way to import using a string will be/is in > 2.6. (As with the print
statement becoming a print function, not sure if this is such a good thing, but
what do I know).
Put your plug-ins in a plug-in folder. Each plugin is a .py file and you
should just
think of it as a module. Make it a convention that each plugin has a
standard
PlugInPanel that all the stuff is on.
2. When the user wants to select a plug-in, use a wxFileDialog aimed
at that folder (or if you want it to be neater, a wxChoice with the plug-in
names generated from looking at that folder)
plugin_name =3D filedialog.GetFilename()
You need to import that plugin’s namespace.
Something like:
plug_in =3D import(plugin_name)
( import allows you to import using a string)
4. Add the panel in it to the notebook:
page =3D plug_in.PlugInPanel(self.notebook, -1)
self.notebook.AddPage(page, plugin_name)
HTH,
Che
Thanks Che,
You completed what I was still missing!
I didn’t know how to import a module dynamically using a string. So the import function was a critical function that I was still missing.
I am sticking to 2.5 for some time while other things catch
up to it (and it works
fine for me), but in case you try 2.6 at some point, keep
that in mind. Not sure
what the new way to import using a string will be/is in >
2.6. (As with the print
statement becoming a print function, not sure if this is such
a good thing, but
what do I know).
I use the 'imp' module, and that still works in 2.6. It finds and imports a
module using the module name and the path name as strings.
C M wrote in
news:cc8074370904252120q3bbec24bj4442b29198e8063b@mail.gmail.com in
gmane.comp.python.wxpython:
You completed what I was still missing!
I didn't know how to import a module dynamically using a string. So
the __import__ function was a critical function that I was still
missing.
Python 2.6 (r26:66721, Oct 2 2008, 11:06:43) [MSC v.1500 64 bit (AMD64)]
on win
32
Type "help", "copyright", "credits" or "license" for more information.
Thanks, Rob, I should have checked their docs. Good to know it lives
on as an option. I wonder why the posters in the thread I cited were
saying it is gone?
Che
···
On Sun, Apr 26, 2009 at 9:01 AM, Rob Williscroft rtw@freenet.co.uk wrote:
Sorry--completely my mistake. What the poster had said was, "It seems
in 2.6 you are no longer able to use the __import__ function with
different paths."
The "with different paths" part was the key. Please disregard my
previous confusion.
-Che
···
On Sun, Apr 26, 2009 at 5:40 PM, C M <cmpython@gmail.com> wrote:
On Sun, Apr 26, 2009 at 9:01 AM, Rob Williscroft <rtw@freenet.co.uk> wrote:
C M wrote in
news:cc8074370904252120q3bbec24bj4442b29198e8063b@mail.gmail.com in
gmane.comp.python.wxpython:
>> You completed what I was still missing!
>> I didn't know how to import a module dynamically using a string. So
>> the __import__ function was a critical function that I was still
>> missing.
>>
>
> Tom, just so you know, I just saw that __import__ has been removed in
> Python 2.6
> apparently:
> http://groups.google.com/group/comp.lang.python/browse_thread/thread/1b
> eda7d8ee474b64#
>
Python 2.6 (r26:66721, Oct 2 2008, 11:06:43) [MSC v.1500 64 bit (AMD64)]
on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> __import__
<built-in function __import__>
>>>
Thanks, Rob, I should have checked their docs. Good to know it lives
on as an option. I wonder why the posters in the thread I cited were
saying it is gone?