add menu title, disable check not working right now

This commit is contained in:
j 2016-02-07 18:20:56 +05:30
parent ad38f4698b
commit 9bcf07dec6

View file

@ -33,6 +33,7 @@ class OMLTrayIcon(object):
self.on_quit = quit self.on_quit = quit
menu_options = ( menu_options = (
('Open Media Library', None, None),
('Launch', None, launch), ('Launch', None, launch),
('Quit', None, self.QUIT) ('Quit', None, self.QUIT)
) )
@ -42,7 +43,7 @@ class OMLTrayIcon(object):
self.menu_actions_by_id = dict(self.menu_actions_by_id) self.menu_actions_by_id = dict(self.menu_actions_by_id)
del self._next_action_id del self._next_action_id
self.default_menu_index = 0 self.default_menu_index = 1
self.window_class_name = name self.window_class_name = name
message_map = {win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart, message_map = {win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart,
@ -80,7 +81,10 @@ class OMLTrayIcon(object):
result = [] result = []
for menu_option in menu_options: for menu_option in menu_options:
option_text, option_icon, option_action = menu_option 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)) self.menu_actions_by_id.add((self._next_action_id, option_action))
result.append(menu_option + (self._next_action_id,)) result.append(menu_option + (self._next_action_id,))
else: else:
@ -152,9 +156,12 @@ class OMLTrayIcon(object):
for option_text, option_icon, option_action, option_id in menu_options[::-1]: for option_text, option_icon, option_action, option_id in menu_options[::-1]:
if option_icon: if option_icon:
option_icon = self.prep_menu_icon(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_id in self.menu_actions_by_id:
if option_action is None:
fstate |= win32con.MF_GRAYED
item, extras = win32gui_struct.PackMENUITEMINFO(text=option_text, item, extras = win32gui_struct.PackMENUITEMINFO(text=option_text,
fState=fstate,
hbmpItem=option_icon, hbmpItem=option_icon,
wID=option_id) wID=option_id)
win32gui.InsertMenuItem(menu, 0, 1, item) win32gui.InsertMenuItem(menu, 0, 1, item)
@ -197,7 +204,7 @@ class OMLTrayIcon(object):
menu_action = self.menu_actions_by_id[id] menu_action = self.menu_actions_by_id[id]
if menu_action == self.QUIT: if menu_action == self.QUIT:
win32gui.DestroyWindow(self.hwnd) win32gui.DestroyWindow(self.hwnd)
else: elif menu_action is not None:
menu_action(self) menu_action(self)
def quit(self): def quit(self):
@ -206,16 +213,16 @@ class OMLTrayIcon(object):
win32api.PostThreadMessage(self.thread_id, win32con.WM_QUIT, 0, 0) win32api.PostThreadMessage(self.thread_id, win32con.WM_QUIT, 0, 0)
class Check(Thread): class Check(Thread):
def __init__(self, parent, pid): def __init__(self, parent, pidfile):
self.parent = parent self.parent = parent
self.pid = pid self.pid = pidfile
Thread.__init__(self) Thread.__init__(self)
self.daemon = True self.daemon = True
self.start() self.start()
def run(self): def run(self):
time.sleep(60) time.sleep(60)
while check_pid(self.pid): while os.path.exists(self.pidfile):
time.sleep(60) time.sleep(60)
self.parent.quit() self.parent.quit()
@ -239,13 +246,13 @@ def launch(sysTrayIcon=None):
pid = os.path.join(base, 'data', 'openmedialibrary.pid') pid = os.path.join(base, 'data', 'openmedialibrary.pid')
if check_pid(pid): if check_pid(pid):
webbrowser.open_new_tab(os.path.join(base, 'openmedialibrary', 'static', 'html', 'load.html')) 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): elif os.path.exists(base):
python = os.path.join(base, 'platform_win32', 'pythonw.exe') python = os.path.join(base, 'platform_win32', 'pythonw.exe')
oml = os.path.join(base, 'openmedialibrary') oml = os.path.join(base, 'openmedialibrary')
subprocess.Popen([python, 'oml', 'server', pid], cwd=oml, start_new_session=True) 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')) webbrowser.open_new_tab(os.path.join(base, 'openmedialibrary', 'static', 'html', 'load.html'))
sysTrayIcon._check = Check(sysTrayIcon, pid) #sysTrayIcon._check = Check(sysTrayIcon, pid)
else: else:
install.run(base) install.run(base)