|
@ -2,8 +2,10 @@ from threading import Thread |
|
|
from wx.lib.softwareupdate import SoftwareUpdate |
|
|
from wx.lib.softwareupdate import SoftwareUpdate |
|
|
import os |
|
|
import os |
|
|
import sys |
|
|
import sys |
|
|
|
|
|
import time |
|
|
import webbrowser |
|
|
import webbrowser |
|
|
import wx |
|
|
import wx |
|
|
|
|
|
import subprocess |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Include proper dirs |
|
|
# Include proper dirs |
|
@ -24,9 +26,12 @@ class TaskBarIcon(wx.TaskBarIcon): |
|
|
|
|
|
|
|
|
TBMENU_OPEN = wx.NewId() |
|
|
TBMENU_OPEN = wx.NewId() |
|
|
TBMENU_SETTINGS = wx.NewId() |
|
|
TBMENU_SETTINGS = wx.NewId() |
|
|
TBMENU_ABOUT = wx.ID_ABOUT |
|
|
|
|
|
TBMENU_EXIT = wx.ID_EXIT |
|
|
TBMENU_EXIT = wx.ID_EXIT |
|
|
|
|
|
|
|
|
|
|
|
closed = False |
|
|
|
|
|
menu = False |
|
|
|
|
|
enabled = False |
|
|
|
|
|
|
|
|
def __init__(self, frame): |
|
|
def __init__(self, frame): |
|
|
wx.TaskBarIcon.__init__(self) |
|
|
wx.TaskBarIcon.__init__(self) |
|
|
self.frame = frame |
|
|
self.frame = frame |
|
@ -34,21 +39,42 @@ class TaskBarIcon(wx.TaskBarIcon): |
|
|
icon = wx.Icon('icon.png', wx.BITMAP_TYPE_PNG) |
|
|
icon = wx.Icon('icon.png', wx.BITMAP_TYPE_PNG) |
|
|
self.SetIcon(icon) |
|
|
self.SetIcon(icon) |
|
|
|
|
|
|
|
|
self.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.onTaskBarActivate) |
|
|
self.Bind(wx.EVT_TASKBAR_LEFT_UP, self.OnTaskBarClick) |
|
|
|
|
|
self.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.OnTaskBarClick) |
|
|
|
|
|
|
|
|
self.Bind(wx.EVT_MENU, self.onOpen, id = self.TBMENU_OPEN) |
|
|
self.Bind(wx.EVT_MENU, self.onOpen, id = self.TBMENU_OPEN) |
|
|
self.Bind(wx.EVT_MENU, self.onSettings, id = self.TBMENU_SETTINGS) |
|
|
self.Bind(wx.EVT_MENU, self.onSettings, id = self.TBMENU_SETTINGS) |
|
|
self.Bind(wx.EVT_MENU, self.onAbout, id = self.TBMENU_ABOUT) |
|
|
|
|
|
self.Bind(wx.EVT_MENU, self.onTaskBarClose, id = self.TBMENU_EXIT) |
|
|
self.Bind(wx.EVT_MENU, self.onTaskBarClose, id = self.TBMENU_EXIT) |
|
|
|
|
|
|
|
|
|
|
|
def OnTaskBarClick(self, evt): |
|
|
|
|
|
menu = self.CreatePopupMenu() |
|
|
|
|
|
self.PopupMenu(menu) |
|
|
|
|
|
menu.Destroy() |
|
|
|
|
|
|
|
|
|
|
|
def enable(self): |
|
|
|
|
|
self.enabled = True |
|
|
|
|
|
|
|
|
|
|
|
if self.menu: |
|
|
|
|
|
self.open_menu.Enable(True) |
|
|
|
|
|
self.setting_menu.Enable(True) |
|
|
|
|
|
|
|
|
|
|
|
self.open_menu.SetText('Open') |
|
|
|
|
|
|
|
|
def CreatePopupMenu(self): |
|
|
def CreatePopupMenu(self): |
|
|
menu = wx.Menu() |
|
|
|
|
|
menu.Append(self.TBMENU_OPEN, "Open") |
|
|
if not self.menu: |
|
|
menu.Append(self.TBMENU_SETTINGS, "Settings") |
|
|
self.menu = wx.Menu() |
|
|
menu.Append(self.TBMENU_ABOUT, "About") |
|
|
self.open_menu = self.menu.Append(self.TBMENU_OPEN, 'Open') |
|
|
menu.Append(self.TBMENU_EXIT, "Close") |
|
|
self.setting_menu = self.menu.Append(self.TBMENU_SETTINGS, 'About') |
|
|
return menu |
|
|
self.exit_menu = self.menu.Append(self.TBMENU_EXIT, 'Quit') |
|
|
|
|
|
|
|
|
|
|
|
if not self.enabled: |
|
|
|
|
|
self.open_menu.Enable(False) |
|
|
|
|
|
self.setting_menu.Enable(False) |
|
|
|
|
|
|
|
|
|
|
|
self.open_menu.SetText('Loading...') |
|
|
|
|
|
|
|
|
|
|
|
return self.menu |
|
|
|
|
|
|
|
|
def onOpen(self, event): |
|
|
def onOpen(self, event): |
|
|
url = self.frame.parent.getSetting('base_url') |
|
|
url = self.frame.parent.getSetting('base_url') |
|
@ -58,17 +84,16 @@ class TaskBarIcon(wx.TaskBarIcon): |
|
|
url = self.frame.parent.getSetting('base_url') + '/settings/' |
|
|
url = self.frame.parent.getSetting('base_url') + '/settings/' |
|
|
webbrowser.open(url) |
|
|
webbrowser.open(url) |
|
|
|
|
|
|
|
|
def onAbout(self, event): |
|
|
def onTaskBarClose(self, evt): |
|
|
print 'onAbout' |
|
|
if self.closed: |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
def onTaskBarActivate(self, evt): |
|
|
self.closed = True |
|
|
if not self.frame.IsShown(): |
|
|
|
|
|
self.frame.Show(True) |
|
|
|
|
|
self.frame.Raise() |
|
|
|
|
|
|
|
|
|
|
|
def onTaskBarClose(self, evt): |
|
|
self.RemoveIcon() |
|
|
wx.CallAfter(self.frame.Close) |
|
|
wx.CallAfter(self.frame.Close) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def makeIcon(self, img): |
|
|
def makeIcon(self, img): |
|
|
if "wxMSW" in wx.PlatformInfo: |
|
|
if "wxMSW" in wx.PlatformInfo: |
|
|
img = img.Scale(16, 16) |
|
|
img = img.Scale(16, 16) |
|
@ -82,7 +107,7 @@ class TaskBarIcon(wx.TaskBarIcon): |
|
|
class MainFrame(wx.Frame): |
|
|
class MainFrame(wx.Frame): |
|
|
|
|
|
|
|
|
def __init__(self, parent): |
|
|
def __init__(self, parent): |
|
|
wx.Frame.__init__(self, None) |
|
|
wx.Frame.__init__(self, None, style = wx.FRAME_NO_TASKBAR) |
|
|
|
|
|
|
|
|
self.parent = parent |
|
|
self.parent = parent |
|
|
self.tbicon = TaskBarIcon(self) |
|
|
self.tbicon = TaskBarIcon(self) |
|
@ -136,6 +161,7 @@ class CouchPotatoApp(wx.App, SoftwareUpdate): |
|
|
settings = {} |
|
|
settings = {} |
|
|
events = {} |
|
|
events = {} |
|
|
restart = False |
|
|
restart = False |
|
|
|
|
|
closing = False |
|
|
|
|
|
|
|
|
def OnInit(self): |
|
|
def OnInit(self): |
|
|
|
|
|
|
|
@ -152,6 +178,9 @@ class CouchPotatoApp(wx.App, SoftwareUpdate): |
|
|
|
|
|
|
|
|
return True |
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
def onAppLoad(self): |
|
|
|
|
|
self.frame.tbicon.enable() |
|
|
|
|
|
|
|
|
def setSettings(self, settings = {}): |
|
|
def setSettings(self, settings = {}): |
|
|
self.settings = settings |
|
|
self.settings = settings |
|
|
|
|
|
|
|
@ -164,24 +193,26 @@ class CouchPotatoApp(wx.App, SoftwareUpdate): |
|
|
|
|
|
|
|
|
def onClose(self, event): |
|
|
def onClose(self, event): |
|
|
|
|
|
|
|
|
onClose = self.events.get('onClose') |
|
|
if not self.closing: |
|
|
if self.events.get('onClose'): |
|
|
self.closing = True |
|
|
|
|
|
self.frame.tbicon.onTaskBarClose(event) |
|
|
|
|
|
|
|
|
|
|
|
onClose = self.events.get('onClose') |
|
|
onClose(event) |
|
|
onClose(event) |
|
|
else: |
|
|
|
|
|
self.afterShutdown() |
|
|
|
|
|
|
|
|
|
|
|
def afterShutdown(self, restart = False): |
|
|
def afterShutdown(self, restart = False): |
|
|
self.frame.Destroy() |
|
|
self.frame.Destroy() |
|
|
self.restart = restart |
|
|
self.restart = restart |
|
|
|
|
|
|
|
|
self.ExitMainLoop() |
|
|
self.ExitMainLoop() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
if __name__ == '__main__': |
|
|
|
|
|
|
|
|
app = CouchPotatoApp(redirect = False) |
|
|
app = CouchPotatoApp(redirect = False) |
|
|
app.MainLoop() |
|
|
app.MainLoop() |
|
|
|
|
|
|
|
|
path = os.path.join(sys.path[0].decode(sys.getfilesystemencoding()), sys.argv[0]) |
|
|
time.sleep(1) |
|
|
|
|
|
|
|
|
if app.restart: |
|
|
if app.restart: |
|
|
pass |
|
|
args = [sys.executable] + [os.path.join(base_path, 'Desktop.py')] + sys.argv[1:] |
|
|
#wx.Process.Open(path) |
|
|
subprocess.Popen(args) |
|
|