By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,941 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,941 IT Pros & Developers. It's quick & easy.

Using python to extend a python app

P: n/a
I'm writing a python app that works as a replacement for the menu that
comes with most minimalist wms when you right click the root window.
It's prettier and written completely in python.

I'd like to provide hooks or some system so that people can write their
own extensions to the app, for example adding fluxbox options, and then
fluxbox users can choose to use that extension. But I'm not sure how to
implement it.

Right now the best idea I have is to have all desired extensions in a
folder, import each .py file in that folder as a module using
__import__, and then call some predetermined method, say "start", and
pass it the menu as it exists so far so they can add to it, start(menu).
This seems kind of hackish.

I looked at how gdesklets handles this, but its solution looks way more
complex than I'd prefer to have to dive into for this tiny app.

What's the most pythonic way to do this? How do apps that extend
themselves with python usually do this?
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
dataangel <k0*****@kzoo.edu> writes:
I'm writing a python app that works as a replacement for the menu that
comes with most minimalist wms when you right click the root window.
It's prettier and written completely in python.

I'd like to provide hooks or some system so that people can write
their own extensions to the app, for example adding fluxbox options,
and then fluxbox users can choose to use that extension. But I'm not
sure how to implement it.

Right now the best idea I have is to have all desired extensions in a
folder, import each .py file in that folder as a module using
__import__, and then call some predetermined method, say "start", and
pass it the menu as it exists so far so they can add to it,
start(menu). This seems kind of hackish.


That looks pretty reasonable, and easy. There have been some recent
threads (in the past month or so) on plugins, so you might want to
search the archives. Most of it's revolved around not using exec :-)

I just had a look at pyblosxom (one program that I know that uses
plugins), and it uses exactly this approach, with some extra frills:
looking in subdirectories, for instance.

--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.