class TrayIco: def __init__(self): self.menu_options = (("Open window", None, restore), ) self.tray_instance = SysTrayIcon(resource_path("ghost.ico"), "Ready!", self.menu_options, on_quit=ask_quit) def init_icon_tray(self): self.tray_instance.start() def kill_icon_tray(self): self.tray_instance.shutdown() def tip_info(self, text='Example', coords=(0, 0)): self.text = text self.tip = Toplevel(root) if coords == (0, 0): x1, y1 = work_area[2] - 310, work_area[3] - 20 coords = (x1, y1) self.tip.wm_overrideredirect(1) self.tip.wm_geometry("+%d+%d" % coords) label = Label(self.tip, text=self.text, justify=LEFT, foreground="white", background=theme_color, relief=SOLID, borderwidth=2, font=("tahoma", "9", "normal")) label.pack(ipadx=1) self.tip.after(1200, self.tip_kill) def tip_kill(self): self.tip.after(1400, lambda: self.tip.wm_attributes('-alpha', 0.6)) self.tip.after(1600, lambda: self.tip.wm_attributes('-alpha', 0.5)) self.tip.after(1800, lambda: self.tip.wm_attributes('-alpha', 0.3)) self.tip.after(2000, lambda: self.tip.wm_attributes('-alpha', 0.2)) self.tip.after(2200, lambda: self.tip.wm_attributes('-alpha', 0.1)) self.tip.after(2400, self.tip.destroy)
class WindowsSystemTray(object): def __init__(self): self.image_dir = os.path.join(plexpy.PROG_DIR, 'data/interfaces/', plexpy.CONFIG.INTERFACE, 'images') if plexpy.UPDATE_AVAILABLE: self.icon = os.path.join(self.image_dir, 'logo-circle-update.ico') self.hover_text = common.PRODUCT + ' - Update Available!' else: self.icon = os.path.join(self.image_dir, 'logo-circle.ico') self.hover_text = common.PRODUCT if plexpy.CONFIG.LAUNCH_STARTUP: launch_start_icon = os.path.join(self.image_dir, 'check-solid.ico') else: launch_start_icon = None if plexpy.CONFIG.LAUNCH_BROWSER: launch_browser_icon = os.path.join(self.image_dir, 'check-solid.ico') else: launch_browser_icon = None self.menu = [['Open Tautulli', None, self.tray_open, 'default'], ['', None, 'separator', None], [ 'Start Tautulli at Login', launch_start_icon, self.tray_startup, None ], [ 'Open Browser when Tautulli Starts', launch_browser_icon, self.tray_browser, None ], ['', None, 'separator', None], ['Check for Updates', None, self.tray_check_update, None], ['Restart', None, self.tray_restart, None]] if not plexpy.FROZEN: self.menu.insert(6, ['Update', None, self.tray_update, None]) self.tray_icon = SysTrayIcon(self.icon, self.hover_text, self.menu, on_quit=self.tray_quit) def start(self): logger.info("Launching Windows system tray icon.") try: self.tray_icon.start() except Exception as e: logger.error("Unable to launch system tray icon: %s." % e) def shutdown(self): self.tray_icon.shutdown() def update(self, **kwargs): self.tray_icon.update(**kwargs) def tray_open(self, tray_icon): plexpy.launch_browser(plexpy.CONFIG.HTTP_HOST, plexpy.HTTP_PORT, plexpy.HTTP_ROOT) def tray_startup(self, tray_icon): plexpy.CONFIG.LAUNCH_STARTUP = not plexpy.CONFIG.LAUNCH_STARTUP set_startup() def tray_browser(self, tray_icon): plexpy.CONFIG.LAUNCH_BROWSER = not plexpy.CONFIG.LAUNCH_BROWSER set_startup() def tray_check_update(self, tray_icon): versioncheck.check_update() def tray_update(self, tray_icon): if plexpy.UPDATE_AVAILABLE: plexpy.SIGNAL = 'update' else: hover_text = common.PRODUCT + ' - No Update Available' self.update(hover_text=hover_text) def tray_restart(self, tray_icon): plexpy.SIGNAL = 'restart' def tray_quit(self, tray_icon): plexpy.SIGNAL = 'shutdown' def change_tray_update_icon(self): if plexpy.UPDATE_AVAILABLE: self.icon = os.path.join(self.image_dir, 'logo-circle-update.ico') self.hover_text = common.PRODUCT + ' - Update Available!' else: self.icon = os.path.join(self.image_dir, 'logo-circle.ico') self.hover_text = common.PRODUCT + ' - No Update Available' self.update(icon=self.icon, hover_text=self.hover_text) def change_tray_icons(self): if plexpy.CONFIG.LAUNCH_STARTUP: launch_start_icon = os.path.join(self.image_dir, 'check-solid.ico') else: launch_start_icon = None if plexpy.CONFIG.LAUNCH_BROWSER: launch_browser_icon = os.path.join(self.image_dir, 'check-solid.ico') else: launch_browser_icon = None self.menu[2][1] = launch_start_icon self.menu[3][1] = launch_browser_icon self.update(menu_options=self.menu)