James,
Here's the shell for you. The main plugin class starts and stops the thread that holds the COM interface to iTunes. It turns out that the iTunes COM will emit events when a song starts and stops, which I attached to in order to generate a TrackChanged event in EG. Waiting for COM events is certainly something you want to do in a new thread.
The first problem I encountered is that since EnsureDispatch will start iTunes, iTunes would start as soon as EventGhost, which isn't what I wanted (I assume you don't either?). So I added a Start action, which will run iTunes if it isn't already started. Right now, if you run an action (Play) and iTunes isn't running, it won't start it, it will say "iTunes isn't running". I prefer this. If you want "Play" to start iTunes, just use the same code I used for Start() in the other eg.ActionClass classes. Or, better yet, make it an option in the plugin settings.
Rather than make an ActionClass for Play, Pause, etc, I created StdCall(). When the ACTIONS list (end of the file) is passed to AddActionsFromList,
Code: Select all
ACTIONS = (
(StdCall, 'Play', 'Play', 'Play', 'Play'),
)
will create an instance of the StdCall class, with self.value set to "Play".
The line
will do the following:
getattr(iTunes,"Play") will evaluate to iTunes.Play, which is then called by the parentheses at the end.
So now all I have to do is add
Code: Select all
ACTIONS = (
(StdCall, 'Play', 'Play', 'Play', 'Play'),
(StdCall, 'Pause', 'Pause', 'Pause', 'Pause'),
)
and I have both a play and a pause action.
There are also ActionClass's for StartApp, ToggleAction and SetVolume (the last mostly because it needed a Configure method). Hopefully those make sense based on the explanation above. The only other trick is that the eg.ActionClass classes call self.plugin.workerThread.CallWait, which makes the actions run in the thread created for the COM object.
One last thing. In ACTIONS, the 2nd parameter is the class name. There should be no spaces for the class name. Also, where it makes sense, if you could use the any of the button names from the MCE remote, then those buttons would automatically work in my EventGhost Beta version. Here's the list of MCE Buttons
Code: Select all
Ok, Back, Left, Right, Up, Down, VolumeUp, VolumeDown, ChannelUp, ChannelDown, Mute, Start, Num0, Num1, Num2, Num3, Num4, Num5, Num6, Num7, Num8, Num9, Teletext, Red, Green, Yellow, Blue, Escape, Enter, Power, Play, Record, Pause, Stop, Skip, Replay, Guide, Recorded_TV, Details, LiveTV, DVDMenu, Forward, Rewind, TV, Music, Pictures, Videos, Star, Pound, Radio, Aspect, Audio, Subtitle
Good luck,
Brett