From 9bcf07dec6089a68f599a1ec501ccb78de9339b5 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 7 Feb 2016 18:20:56 +0530 Subject: [PATCH] add menu title, disable check not working right now --- trayicon/Open Media Library.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/trayicon/Open Media Library.py b/trayicon/Open Media Library.py index afa1cc7..8e20639 100644 --- a/trayicon/Open Media Library.py +++ b/trayicon/Open Media Library.py @@ -33,6 +33,7 @@ class OMLTrayIcon(object): self.on_quit = quit menu_options = ( + ('Open Media Library', None, None), ('Launch', None, launch), ('Quit', None, self.QUIT) ) @@ -42,7 +43,7 @@ class OMLTrayIcon(object): self.menu_actions_by_id = dict(self.menu_actions_by_id) del self._next_action_id - self.default_menu_index = 0 + self.default_menu_index = 1 self.window_class_name = name message_map = {win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart, @@ -80,7 +81,10 @@ class OMLTrayIcon(object): result = [] for menu_option in menu_options: option_text, option_icon, option_action = menu_option - if callable(option_action) or option_action in self.SPECIAL_ACTIONS: + if option_action is None: + self.menu_actions_by_id.add((self._next_action_id, option_action)) + result.append(menu_option + (self._next_action_id,)) + elif callable(option_action) or option_action in self.SPECIAL_ACTIONS: self.menu_actions_by_id.add((self._next_action_id, option_action)) result.append(menu_option + (self._next_action_id,)) else: @@ -152,9 +156,12 @@ class OMLTrayIcon(object): for option_text, option_icon, option_action, option_id in menu_options[::-1]: if option_icon: option_icon = self.prep_menu_icon(option_icon) - + fstate = win32con.MF_BYCOMMAND if option_id in self.menu_actions_by_id: + if option_action is None: + fstate |= win32con.MF_GRAYED item, extras = win32gui_struct.PackMENUITEMINFO(text=option_text, + fState=fstate, hbmpItem=option_icon, wID=option_id) win32gui.InsertMenuItem(menu, 0, 1, item) @@ -197,7 +204,7 @@ class OMLTrayIcon(object): menu_action = self.menu_actions_by_id[id] if menu_action == self.QUIT: win32gui.DestroyWindow(self.hwnd) - else: + elif menu_action is not None: menu_action(self) def quit(self): @@ -206,16 +213,16 @@ class OMLTrayIcon(object): win32api.PostThreadMessage(self.thread_id, win32con.WM_QUIT, 0, 0) class Check(Thread): - def __init__(self, parent, pid): + def __init__(self, parent, pidfile): self.parent = parent - self.pid = pid + self.pid = pidfile Thread.__init__(self) self.daemon = True self.start() def run(self): time.sleep(60) - while check_pid(self.pid): + while os.path.exists(self.pidfile): time.sleep(60) self.parent.quit() @@ -239,13 +246,13 @@ def launch(sysTrayIcon=None): pid = os.path.join(base, 'data', 'openmedialibrary.pid') if check_pid(pid): webbrowser.open_new_tab(os.path.join(base, 'openmedialibrary', 'static', 'html', 'load.html')) - sysTrayIcon._check = Check(sysTrayIcon, pid) + #sysTrayIcon._check = Check(sysTrayIcon, pid) elif os.path.exists(base): python = os.path.join(base, 'platform_win32', 'pythonw.exe') oml = os.path.join(base, 'openmedialibrary') subprocess.Popen([python, 'oml', 'server', pid], cwd=oml, start_new_session=True) webbrowser.open_new_tab(os.path.join(base, 'openmedialibrary', 'static', 'html', 'load.html')) - sysTrayIcon._check = Check(sysTrayIcon, pid) + #sysTrayIcon._check = Check(sysTrayIcon, pid) else: install.run(base)