Created
August 31, 2011 19:39
-
-
Save nathggns/1184491 to your computer and use it in GitHub Desktop.
Keyboard Music Controller for iTunes (Windows)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from wmi import WMI | |
| from win32com.client.gencache import EnsureDispatch | |
| import pygtk; pygtk.require('2.0'); import gtk | |
| import traceback, win32con, threading, wx | |
| class Logic: | |
| class iTunes: | |
| def __init__(self): pass | |
| def __init__(self): | |
| #processes = WMI().InstancesOf('Win32_Process') | |
| #if not 'iTunes.exe' in [process.Properties_('Name').Value for process in processes]: | |
| # self.api = False | |
| #else: | |
| self.api = EnsureDispatch("iTunes.application") | |
| def toggle(self, *args): self.api.PlayPause() | |
| def next(self, *args): self.api.NextTrack() | |
| def last(self, *args): self.api.PreviousTrack() | |
| class App(): | |
| def __init__(self): | |
| icon = gtk.StatusIcon() | |
| icon.set_tooltip('Media Controller') | |
| icon.set_from_file('icon.ico') | |
| self.logic = Logic() | |
| self.itunes = self.logic.iTunes() | |
| self.a = wx.App() | |
| self.w = wx.Frame(None) | |
| hotkeys = [ | |
| ([win32con.MOD_CONTROL, win32con.VK_RIGHT], 101, Logic().iTunes().next), | |
| ( | |
| [win32con.MOD_CONTROL, win32con.VK_LEFT], | |
| 102, | |
| Logic().iTunes().last | |
| ), | |
| ( | |
| [win32con.MOD_CONTROL, win32con.VK_SPACE], | |
| 103, | |
| Logic().iTunes().toggle | |
| ) | |
| ] | |
| for i in hotkeys: | |
| self.bind_hotkey(i[1], i[0], i[-1]) | |
| self.a.MainLoop() | |
| def bind_hotkey(self, id, key, callback): | |
| self.w.RegisterHotKey( | |
| id, | |
| key[0], | |
| key[1] | |
| ) | |
| self.w.Bind(wx.EVT_HOTKEY, callback, id=id) | |
| App() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment