Plugin Development

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
cameronr
Posts: 7
Joined: Mon Aug 07, 2006 1:37 am

Plugin Development

Post by cameronr » Sat Aug 12, 2006 9:21 am

Hi all,

I have recently changed to EventGhost from Girder and I must say that, for my purposes, EventGhost is far superior and far easier to use than Girder.

I have plans to develop a few plugins for EventGhost. I have not done any python before but have no doubts it will be easy to pickup as I am a Software Engineer by day :)

The plugins I plan to build are:

1) Generic parallel port plugin. I have a parallel port 8 in, 8 out controller box that I want to control.
2) Windows power down notification plugin that receives Standby/Hibernate notifications and forwards them to EventGhost (is this done already?). I want to use this to control power to my amplifiers and automatic projector masking through the parallel port break-out box.
3) M-Audio Revolution sound card controller plugin.

Now, I have a few questions about the python development environment: 4) Is there an IDE available to make my life a little easier (for windows)? I don't mind using gvim but I prefer an IDE.
5) I saw the wiki entry that describes the packages that I need to run EventGhost from source - is there anything else I need?
6) Once I have developed my plugin(s) what is the best way to give them back to the community?
7) Is there a cvs system set up through sourceforge or am I better working with the 0.3.2 source code package and sending someone the plugins that are developed?

That's about it for now. I am sure I will have more questions soon. Thanks for your great program!

Cheers
Cameron

cameronr
Posts: 7
Joined: Mon Aug 07, 2006 1:37 am

Post by cameronr » Sat Aug 12, 2006 9:58 am

8) I just realised I probably don't need to compile EG from source as the plugins are interpreted at runtime.

9) Is there any documentation that prospective plugin developers should read? Information about how events from a plugin are sent to EG, how a plugin handles events from EG, if there is a need for threads while polling things like parallel ports, etc?

Cheers
Cameron

Bartman
Plugin Developer
Posts: 881
Joined: Sun Feb 12, 2006 9:03 am

Post by Bartman » Sat Aug 12, 2006 11:08 am

you can trigger an event directly in your plugin via self.TriggerEvent("name"). A plugin does not handle an event by itself, but the __call__ function is called by EG if the event is linked with the macro.
I pretty sure there is an need for an internal thread, as most of the plugin do have one.
I would recommend looking at one of the existing plugins. Most of them are still pretty small and simple.

User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Post by Bitmonster » Sat Aug 12, 2006 11:27 am

I have renumbered your questions, to make answering easier.

1. There are some Python modules for the parallel port that might help. I haven't looked into these but you find some if you google "python parallel port".
2. This is already done but might need some enhancements. The code is in eg/DeviceChangeNotifier.py
3. There I can't help. But you can also make/use normal DLLs and call them from Python with the "ctypes" module if this helps.
4. There are many. Actually too many. I use drPython, eventhough it has some bugs and there was longtime no update. But you can use any Python IDE as long as it's "wxPython-aware". Pythonwin for example (part of ActiveState-Python package) can't run wxPython programs nicely.
5. If you run from source, that should be it. To make the installer you need some more. But usually you don't need to run EG from source, if you want to write plugins. You actually can also modify the EG-source itself, because the setup.exe includes all sources and (re)compiles them at runtime.
6. As long as they are small, you can simply post them here in the forum as source and I might include them in the normal distribution. This has happened to all plugins that were written by other authors till now, as long as they are not too special.
7. No, there is currently no CVS/Subversion system for EG. Simply wasn't no need till now, since most people concentrate on their plugins and I concentrate more on the core. But if someone want's to make considerable changes to the core code, we can think about it.
8. Right.
9. Well, documentation is lacking. Recommended reading are the source code of the plugins itself. Start with the Winamp plugin, as it has some comments. Next recommendation would be the eg/PluginClass.py and eg/ActionClass.py source, the "Media Player Classic" plugin and some other plugins that have similiar functionallity as you intend.

cameronr
Posts: 7
Joined: Mon Aug 07, 2006 1:37 am

Post by cameronr » Sun Aug 13, 2006 10:24 am

Thanks for the info. I will see how I go working with the existing plugin source code.

Cheers
Cameron

User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Post by Bitmonster » Mon Aug 14, 2006 4:17 pm

I just noticed, that there were not as many documentation strings in eg/PluginClass.py as I thought. I just wrote a bit more and have uploaded a new beta version. There is still much that might be needed to explain, but I hope it will give now some more hints how plugins in EventGhost work.

I also changed the "TriggerEventWithoutRelease" method name to "TriggerEnduringEvent". I don't know why I first used such a mistakable name.

User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Post by Bitmonster » Thu Aug 17, 2006 7:49 pm

I started a new wiki page, that should give a small tutorial when it is finished. You find the page here:
http://www.eventghost.org/wiki/Writing_Plugins

cameronr
Posts: 7
Joined: Mon Aug 07, 2006 1:37 am

Post by cameronr » Fri Aug 18, 2006 4:28 am

Thanks for the info and wiki page. I am actually travelling for the next 5 weeks so you won't hear from me for a little while - just wanted to let you know I appreciate your input.

A question to leave you with: Is it possible to dynamically create actions at run-time? A scenario:

If I write a xAP (xAP is a distributed event sending/receiving system primarily designed for home Automation) plugin that queries the network for available xAP devices, (each device has it's own set of actions that can be executed) can I dynamically create Actions to associate with the available devices?

This would allow me to add a new xAP device to my network, open up the xAP plugin in eventGhost (which would find the new device and its associated actions), and select the new actions provide by that new device.

Do you have to sub-class the ActionClass, or can you instantiate them directly and add Actions to your plugin as required?

Hope that makes sense..

Thanks
Cameron

User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Post by Bitmonster » Fri Aug 18, 2006 12:18 pm

The __init__ method of your plugin is called when the plugin is loaded. In this method you add all actions your plugin can handle, through subclasses of eg.ActionClass for every action and calling self.AddAction. The subclassing can be done dynamically in this moment. Examples are the Foobar2000 and MediaPlayerClassic plugins, as they create actions from a list, eventhough this list is hardcoded. So you could dynamically determine what actions you want to add in this moment. But you can't do it later. And you have to make sure, that actions that are already used by the user will also be added again and don't disappear, as otherwise the configuration of the user would break.

Another idea would be to only have a single generic action and let it query your devices in the moment the user configures it (the first configuration has to be done immediately after it was added to the tree). There you could show the user a freshly queried list of possible xAP actions that the network can handle. Then you can let the user choose the one he wants and store all needed information for this xAP action as parameters for the EG action, like the device and the xAP action name.

So instead of dynamically creating actions, you can dynamically configure actions.

Hope you get the point. This is nearly the same as the USB-UIRT for example, that also only has a single "Transmit IR" action, but can be used to transmit any code for any device, since it can learn any IR code in the configuration dialog.

Bartman
Plugin Developer
Posts: 881
Joined: Sun Feb 12, 2006 9:03 am

Post by Bartman » Sat Aug 19, 2006 12:16 pm

I was just wondering about code conventions for EG. I'm quite sure there was something in the wiki but I can't find it anymore.
Are these the same as for Python in general?

How can I prepare my code to support the i18n possibilities of EG?

User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Post by Bitmonster » Sat Aug 19, 2006 1:36 pm

Bartman wrote:I was just wondering about code conventions for EG. I'm quite sure there was something in the wiki but I can't find it anymore.
Are these the same as for Python in general?
No, EventGhost uses wxPython conventions, because it uses more wxPython than Python libs. The Win32-Api also has conventions that are more like wxPython than Python.

The page is here, eventhough not complete:
http://www.eventghost.org/wiki/Coding_Style
Bartman wrote:How can I prepare my code to support the i18n possibilities of EG?
Well, I will have to write a HowTo about that.

User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Post by Bitmonster » Sat Aug 19, 2006 3:46 pm

Bartman wrote:How can I prepare my code to support the i18n possibilities of EG?
Here it is:
http://www.eventghost.org/wiki/Internationalization
Is this understandable?

There was a bug in the current version. I will upload a new beta later today and then it should work as intended.

Bartman
Plugin Developer
Posts: 881
Joined: Sun Feb 12, 2006 9:03 am

Post by Bartman » Sat Aug 19, 2006 5:59 pm

I just updated to 0.3.3_build_688 but the name and description values of the actions are not shown at. EG just states "MessageX".

User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Post by Bitmonster » Sat Aug 19, 2006 6:20 pm

Ok, should now be fixed in 689.

CollinR
Experienced User
Posts: 265
Joined: Tue Sep 05, 2006 7:16 am
Location: Oklahoma
Contact:

Re: Plugin Development

Post by CollinR » Thu Sep 13, 2007 6:37 pm

BTT for xAP

Post Reply