def run(self): def get_wrapper(command): def wrapper(): self.r_queue.put((command, None)) return wrapper def die(): self.icon_stop() menu_items = [ MenuItem("Show Console", get_wrapper("show_console")), MenuItem("Application Menu", get_wrapper("open_player_menu")), MenuItem("Open Config Folder", get_wrapper("open_config_brs")), MenuItem("Quit", die) ] icon = Icon(APP_NAME, menu=Menu(*menu_items)) icon.icon = Image.open(icon_file) self.icon_stop = icon.stop def setup(icon: Icon): icon.visible = True icon.run(setup=setup) self.r_queue.put(("die", None))
def __init__(self, config): self.config = config self.proxySettings = config.proxySettings self.proxySettings.onChangedMode(self._changedProxyMode) self.iconNoProxy = Image.open( os.path.abspath(self.config.path + '/icons/no_proxy.png')) self.iconProxyMan = Image.open( os.path.abspath(self.config.path + '/icons/proxy_man.png')) self.iconProxyAuto = Image.open( os.path.abspath(self.config.path + '/icons/proxy_auto.png')) self.menu = Menu(lambda: ( MenuItem(self.modeLabel, None, enabled=False), Menu.SEPARATOR, MenuItem(_('Deactivate Proxy'), self._redirectTo(self._noProxy), enabled=not self.mode.isNone()), MenuItem(_('Activate Manual Proxy'), self._redirectTo(self._proxyMan), enabled=not self.mode.isManual()), MenuItem(_('Activate Automatic Proxy'), self._redirectTo(self._proxyAuto), enabled=not self.mode.isAuto()), Menu.SEPARATOR, MenuItem(_('Proxy Profiles'), Menu(lambda: self.generateProfilesMenu())), Menu. SEPARATOR, MenuItem(_('Exit Tray'), self._redirectTo(self.quit)))) self.profileEditor = ProfileEditor(self.config) self.profileEditor.onSaveCallback(self.update_menu) self.profileEditor.onDeleteCallback(self.update_menu) self.pystray = Icon('ProxyTray', self.iconProxyMan, menu=self.menu) self._refreshProxyMode() self.pystray.run()
def run(self): from pystray import Icon, MenuItem, Menu def get_wrapper(command): def wrapper(): self.r_queue.put((command, None)) return wrapper def die(): # We don't call self.icon_stop() because it crashes on Linux now... if sys.platform == "linux": # This kills the status icon uncleanly. self.r_queue.put(("die", None)) else: self.icon_stop() menu_items = [ MenuItem(_("Configure Servers"), get_wrapper("show_preferences")), MenuItem(_("Show Console"), get_wrapper("show_console")), MenuItem(_("Application Menu"), get_wrapper("open_player_menu")), MenuItem(_("Open Config Folder"), get_wrapper("open_config_brs")), MenuItem(_("Quit"), die) ] icon = Icon(USER_APP_NAME, menu=Menu(*menu_items)) icon.icon = Image.open(get_resource("systray.png")) self.icon_stop = icon.stop def setup(icon): icon.visible = True self.r_queue.put(("ready", None)) icon.run(setup=setup) self.r_queue.put(("die", None))
def main(): tray = pystray.Icon('tray-test') image = Image.open(ICO_PATH) tray.icon = image menu = Menu(*create_commands(COMMANDS)) tray.menu = menu tray.run(show)
def run(self): from pystray import Icon, MenuItem, Menu def get_wrapper(command): def wrapper(): self.r_queue.put((command, None)) return wrapper def die(): self.icon_stop() menu_items = [ MenuItem("Configure Servers", get_wrapper("show_preferences")), MenuItem("Show Console", get_wrapper("show_console")), MenuItem("Application Menu", get_wrapper("open_player_menu")), MenuItem("Open Config Folder", get_wrapper("open_config_brs")), MenuItem("Quit", die) ] icon = Icon(USER_APP_NAME, menu=Menu(*menu_items)) with importlib.resources.path(__package__, 'systray.png') as icon_file: icon.icon = Image.open(icon_file) self.icon_stop = icon.stop def setup(icon): icon.visible = True self.r_queue.put(("ready", None)) icon.run(setup=setup) self.r_queue.put(("die", None))
def init_icon(): icon = pystray.Icon('Status') icon.menu = Menu( MenuItem('Available', lambda: ButtonClickAvail(User)), MenuItem('Webex', lambda: ButtonClickWebex(User)), MenuItem('Logs/ESRS', lambda: ButtonClickLogs(User)), MenuItem('No Bandwidth', lambda: ButtonClickNoBW(User)), MenuItem('Away', lambda: ButtonClickAway(User)), MenuItem('In Call', lambda: ButtonClickIncall(User)), MenuItem('Out of office', lambda: ButtonClickOOO(User)), ) icon.icon = Image.open(resource_path('./images/icon.png')) icon.title = 'Status Update' def setup(icon): icon.visible = True app = IsilonStatus() app.mainloop() # while icon.visible==True: # flags, hcursor, (prevx,prevy) = win32gui.GetCursorInfo() # self.after(1000 * 10, self.inactive(prevx, prevy)) icon.run(setup) return icon
def tray(): global icon, thread icon = None thread = None name = 'ED - Autopilot' icon = Icon(name=name, title=name) logo = Image.open(resource_path('src/logo.png')) icon.icon = logo icon.menu = Menu( MenuItem('Scan Off', set_state(0), checked=get_state(0), radio=True), MenuItem('Scan on Primary Fire', set_state(1), checked=get_state(1), radio=True), MenuItem('Scan on Secondary Fire', set_state(2), checked=get_state(2), radio=True), MenuItem('Exit', lambda: exit_action())) keyboard.add_hotkey('home', start_action) keyboard.add_hotkey('end', stop_action) icon.run(setup)
def run(self): # not supported on mac if config.operating_system == 'Darwin': log('Systray is not supported on mac yet') return options_map = { 'Show': self.show_main_window, 'Minimize to Systray': self.minimize_to_systray, 'Quit': self.quit } # make our own Gtk statusIcon, since pystray failed to run icon properly on Gtk 3.0 from a thread if config.operating_system == 'Linux': try: import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk self.Gtk = Gtk def icon_right_click(icon, button, time): menu = Gtk.Menu() for option, callback in options_map.items(): item = Gtk.MenuItem(label=option) item.connect('activate', callback) menu.append(item) menu.show_all() menu.popup(None, None, None, icon, button, time) icon = Gtk.StatusIcon() icon.set_from_file(self.tray_icon_path) icon.connect("popup-menu", icon_right_click) icon.connect('activate', self.show_main_window) self.active = True Gtk.main() return except: self.active = False # let pystray decide which icon to run try: from pystray import Icon, Menu, MenuItem items = [] for option, callback in options_map.items(): items.append( MenuItem(option, callback, default=True if option == 'Show' else False)) menu = Menu(*items) self.icon = Icon('PyIDM', self.tray_icon, menu=menu) self.active = True self.icon.run() except Exception as e: log('systray: - run() - ', e) self.active = False
def __init__(self, worker: Worker): # save worker reference self._worker = worker # create the icon self._icon = Icon("Mover") # set the image self._icon.icon = MOVER_ICON # set actions # - set source # - set destination # - number of backlogs # - start/stop # - exit self._start_stop = MenuItem("Start", self.on_start_stop, enabled=False) # initial state self._set_source = MenuItem("Set Source", self.on_set_source) self._set_destination = MenuItem("Set Destination", self.on_set_destination) self._number_of_backlogs = MenuItem( "Number of Backlogs", Menu( MenuItem("Immediate", partial(self.on_number_of_backlogs_changed, 0)), MenuItem("5", partial(self.on_number_of_backlogs_changed, 5)), MenuItem("10", partial(self.on_number_of_backlogs_changed, 10)), MenuItem("25", partial(self.on_number_of_backlogs_changed, 25)), ), ) self._timeout = MenuItem( 'Timeout', Menu(MenuItem('Never', partial(self.on_timeout_changed, 0)), MenuItem('30 s', partial(self.on_timeout_changed, 30)))) self._exit = MenuItem("Exit", self.on_exit) self._icon.menu = Menu( self._start_stop, Menu.SEPARATOR, self._set_source, self._set_destination, self._number_of_backlogs, Menu.SEPARATOR, self._exit, )
def __init__(self, options={}): self.__main_gui = None self.__notifier = notify2.Notification('dnfdragora', '', 'dnfdragora') self.__running = True self.__updater = threading.Thread(target=self.__update_loop) self.__scheduler = sched.scheduler(time.time, time.sleep) self.__config = config.AppConfig('dnfdragora') self.__updateInterval = 180 self.__update_count = -1 if self.__config.systemSettings : settings = {} if 'settings' in self.__config.systemSettings.keys() : settings = self.__config.systemSettings['settings'] if 'update_interval' in settings.keys() : self.__updateInterval = int(settings['update_interval']) if self.__config.userPreferences: if 'settings' in self.__config.userPreferences.keys() : settings = self.__config.userPreferences['settings'] if 'interval for checking updates' in settings.keys() : self.__updateInterval = int(settings['interval for checking updates']) # if missing gets the default icon from our folder (same as dnfdragora) icon_path = '/usr/share/dnfdragora/images/' if 'icon-path' in options.keys() : icon_path = options['icon-path'] if icon_path.endswith('/'): icon_path = icon_path + 'dnfdragora.png' else: icon_path = icon_path + '/dnfdragora.png' theme_icon_pathname = self.__get_theme_icon_pathname() or icon_path print("Icon: %s"%(theme_icon_pathname)) #empty icon as last chance self.__icon = Image.Image() try: if theme_icon_pathname.endswith('.svg'): with open(theme_icon_pathname, 'rb') as svg: self.__icon = self.__svg_to_Image(svg.read()) else: self.__icon = Image.open(theme_icon_pathname) except Exception as e: print(e) print("Cannot open theme icon using default one %s"%(icon_path)) self.__icon = Image.open(icon_path) self.__menu = Menu( MenuItem(_('Update'), self.__run_update), MenuItem(_('Open dnfdragora dialog'), self.__run_dnfdragora), MenuItem(_('Check for updates'), self.__get_updates_forced), MenuItem(_('Exit'), self.__shutdown) ) self.__name = 'dnfdragora-updater' self.__tray = Tray(self.__name, self.__icon, self.__name, self.__menu)
def init_icon(): icon = pystray.Icon('mon') icon.menu = Menu( MenuItem('TimeStamp', lambda: timestamp_action(icon)), MenuItem('Exit', lambda: exit_action(icon)), ) icon.icon = Image.open('ICON.png') icon.title = 'ToolsBox' icon.run(setup)
def init_icon(): icon = pystray.Icon('Network downtime detector') icon.menu = Menu(MenuItem('Exit', lambda: exit_action(icon))) icon.icon = create_image(down, "Start", 12, white) icon.title = 'Network downtime detector' icon.run(setup)
def createIcon(self): image = self.b.getNextImage() self.appData.saveImage(image) wall = WindowsWallpaper() wall.setWallpaper(self.appData.getImagePath()) image = Image.open("icon.png") menu = Menu(MenuItem('Next Image', self.nextI), MenuItem('Prev Image', self.prevI), MenuItem('Quit', self.quitI)) self.icon = pystray.Icon("pyBing v0.1", image, "pyBing v0.1", menu)
def create_tray(): global pause_state pause_state = False pause = MenuItem('pause', lambda: option('pause'), checked=lambda state: pause_state) tray = Icon('wisdom on pic', title='Wallpaper Wisdom', icon=image.Image.open(r'files\icon.png'), menu=Menu(MenuItem('new image', change_wallpaper), pause, MenuItem('exit', lambda: option('exit')))) return tray
def on_close(): root.withdraw() global systray, tray_running my_menu = Menu(MenuItem("Open", open_window), MenuItem("Quit", quit_program)) systray = Icon(app_name, Image.open(resource_path('icon.ico')), menu=my_menu) tray_running = True systray.run()
def __init__(self, options={}): self.__main_gui = None self.__notifier = notify2.Notification('dnfdragora', '', 'dnfdragora') self.__running = True self.__updater = threading.Thread(target=self.__update_loop) self.__scheduler = sched.scheduler(time.time, time.sleep) self.__config = config.AppConfig('dnfdragora') self.__updateInterval = 180 self.__update_count = -1 if self.__config.systemSettings: settings = {} if 'settings' in self.__config.systemSettings.keys(): settings = self.__config.systemSettings['settings'] if 'update_interval' in settings.keys(): self.__updateInterval = int(settings['update_interval']) if self.__config.userPreferences: if 'settings' in self.__config.userPreferences.keys(): settings = self.__config.userPreferences['settings'] if 'interval for checking updates' in settings.keys(): self.__updateInterval = int( settings['interval for checking updates']) icon_path = '/usr/share/icons/hicolor/128x128/apps' if 'icon-path' in options.keys(): icon_path = options['icon-path'] if icon_path.endswith('/'): icon_path = icon_path + 'dnfdragora.png' else: icon_path = icon_path + '/dnfdragora.png' issue_82_workaround_icon_path = icon_path try: from gi.repository import Gtk icon_theme = Gtk.IconTheme.get_default() icon_path = icon_theme.lookup_icon("dnfdragora", 128, 0).get_filename() issue_82_workaround_test = Image.open( icon_path ) #Apperantly PIL (or Pillow?) doesn't support svg icons. If the filetype isn't supported an exception will be thrown except: icon_path = issue_82_workaround_icon_path # Use backup icon path. print("icon %s" % (icon_path)) self.__icon = Image.open(icon_path) self.__menu = Menu( MenuItem(_('Update'), self.__run_update), MenuItem(_('Open dnfdragora dialog'), self.__run_dnfdragora), MenuItem(_('Check for updates'), self.__get_updates_forced), MenuItem(_('Exit'), self.__shutdown)) self.__name = 'dnfdragora-updater' self.__tray = Tray(self.__name, self.__icon, self.__name, self.__menu)
def menu(): return Menu( MenuItem( 'Connect', connect), MenuItem( 'Settings', settings), MenuItem( 'Quit', quit) )
def on_closing(): settings = functions.load_settings() icon = pystray.Icon("ThemeSwitch") icon.icon = Image.open(Path(__file__).parent / "../icons/icon.ico") icon.title = "Theme Switch" icon.menu = Menu( MenuItem('Open', lambda: reopen_program(root, icon), default=True), MenuItem('Change mode', lambda: change_mode_tray(settings)), MenuItem('Quit', lambda: exit_tray(root, icon))) root.withdraw() icon.run(setup)
def update_menu(): global icon try: icon.menu = Menu( MenuItem('Messages(s) : '+str(nb_of_msgs_to_read), lambda : display_browser('https://www.koreus.com/modules/mpmanager/msgbox.php')), MenuItem('Notification(s) : '+str(nb_of_notifs), lambda : display_browser('https://www.koreus.com/notifs.php')), MenuItem('Article(s) : '+str(new_art), lambda : display_browser('https://www.koreus.com/modules/news/')), Menu.SEPARATOR, MenuItem('Paramètre', Menu( MenuItem('Paramètres avancés', lambda : threading.Thread(target=parametrer_wnd).start()), Menu.SEPARATOR, MenuItem('%s'%("Ne plus afficher les notifications" if show else "Réafficher les notifications"), able_notif), MenuItem('%s'%("Ne plus afficher les erreurs" if show_wrong else "Réafficher les erreurs"), show_error), Menu.SEPARATOR, MenuItem( 'Activer la connexion Test non-sécurisée %s'%("(En cours)" if parameters[0] else ""), lambda:mod_parameters(1,0,0), enabled=1-parameters[0]), MenuItem( 'Activer la connexion Firefox sécurisée %s'%("(En cours)" if parameters[1] else ""), lambda:mod_parameters(0,1,0), enabled=1-parameters[1]), MenuItem( 'Activer la connexion Chrome sécurisée %s'%("(En cours)" if parameters[2] else ""), lambda:mod_parameters(0,0,1), enabled=1-parameters[2]))), MenuItem('%s'%("Déconnexion" if pwd else "Connexion"), lambda : redeconnexion()), MenuItem('Quitter', lambda : exit_action(icon)), ) except: traceback.print_exc()
def run(self): menu_items = [ MenuItem("Configure Servers", self.show_preferences), MenuItem("Show Console", self.show_console), MenuItem("Application Menu", self.open_player_menu), ] if open_config: menu_items.append(MenuItem("Open Config Folder", open_config)) menu_items.append(MenuItem("Quit", self.stop)) icon = Icon(USER_APP_NAME, menu=Menu(*menu_items)) icon.icon = Image.open(icon_file) self.icon_stop = icon.stop icon.run()
def __init__(self, icon, menu=[], exit=None, schedule=None): self.icon = pystray.Icon("mon") self.icon.title = "Tooltip" self.icon.icon = Image.open(icon) self.schedule = schedule menu.append(("Exit", lambda: self.exit())) menu_items = [] for name, action in menu: menu_items.append(MenuItem(name, action)) self.icon.menu = Menu(*menu_items) if exit: self.exit = exit
def __init__(self, options={}): self.__main_gui = None self.__notifier = sh.Command("/usr/bin/notify-send") self.__running = True self.__updater = threading.Thread(target=self.__update_loop) self.__scheduler = sched.scheduler(time.time, time.sleep) self.__config = config.AppConfig('dnfdragora') self.__updateInterval = 180 self.__update_count = -1 if self.__config.systemSettings: settings = {} if 'settings' in self.__config.systemSettings.keys(): settings = self.__config.systemSettings['settings'] if 'update_interval' in settings.keys(): self.__updateInterval = int(settings['update_interval']) if self.__config.userPreferences: if 'settings' in self.__config.userPreferences.keys(): settings = self.__config.userPreferences['settings'] if 'interval for checking updates' in settings.keys(): self.__updateInterval = int( settings['interval for checking updates']) icon_path = '/usr/share/icons/hicolor/128x128/apps' if 'icon-path' in options.keys(): icon_path = options['icon-path'] if icon_path.endswith('/'): icon_path = icon_path + 'dnfdragora.png' else: icon_path = icon_path + '/dnfdragora.png' try: from gi.repository import Gtk icon_theme = Gtk.IconTheme.get_default() icon_path = icon_theme.lookup_icon("dnfdragora", 128, 0).get_filename() except: pass print("icon %s" % (icon_path)) self.__icon = Image.open(icon_path) self.__menu = Menu( MenuItem(_('Update'), self.__run_update), MenuItem(_('Open dnfdragora dialog'), self.__run_dnfdragora), MenuItem(_('Check for updates'), self.__get_updates_forced), MenuItem(_('Exit'), self.__shutdown)) self.__name = 'dnfdragora-updater' self.__tray = Tray(self.__name, self.__icon, self.__name, self.__menu)
def __init__(self): self.__main_gui = None self.__notifier = sh.Command("/usr/bin/notify-send") self.__running = True self.__updater = threading.Thread(target=self.__update_loop) self.__scheduler = sched.scheduler(time.time, time.sleep) self.__config = config.AppConfig('dnfdragora') self.__updateInterval = 180 if self.__config.systemSettings: settings = {} if 'settings' in self.__config.systemSettings.keys(): settings = self.__config.systemSettings['settings'] if 'update_interval' in settings.keys(): self.__updateInterval = int(settings['update_interval']) if self.__config.userPreferences: if 'settings' in self.__config.userPreferences.keys(): settings = self.__config.userPreferences['settings'] if 'interval for checking updates' in settings.keys(): self.__updateInterval = int( settings['interval for checking updates']) icon_path = '/usr/share/icons/hicolor/128x128/apps/dnfdragora.png' try: self.__backend = dnfdaemon.client.Client() except dnfdaemon.client.DaemonError as error: print(_('Error starting dnfdaemon service: [%s]'), str(error)) sys.exit(1) try: from gi.repository import Gtk icon_theme = Gtk.IconTheme.get_default() icon_path = icon_theme.lookup_icon("dnfdragora", 128, 0).get_filename() except: pass self.__icon = Image.open(icon_path) self.__menu = Menu( MenuItem(_('Update'), self.__run_update), MenuItem(_('Open dnfdragora dialog'), self.__run_dnfdragora), MenuItem(_('Check for updates'), self.__get_updates_forced), MenuItem(_('Exit'), self.__shutdown)) self.__name = 'dnfdragora-updater' self.__tray = Tray(self.__name, self.__icon, self.__name, self.__menu)
def generateProfilesMenu(self): result = [ MenuItem(_('New Profile'), self._redirectTo(self._newProfile)) ] for profile in ProxyTrayConfig.getProfiles(): result.append( MenuItem( profile['name'], Menu(lambda: (MenuItem( _('Apply'), self._redirectTo(self._applyProfile, profile['name'])), MenuItem( _('Edit'), self._redirectTo(self._modifyProfile, profile['name'])))))) return result
def tray(): global icon, thread icon = None thread = None name = 'ED - Autopilot' icon = Icon(name=name, title=name) logo = Image.open(resource_path('src/logo.png')) icon.icon = logo icon.menu = Menu(MenuItem('Exit', lambda: exit_action()), ) keyboard.add_hotkey('home', start_action) keyboard.add_hotkey('end', stop_action) icon.run(setup)
def configure_systray(): def setup(icon): icon.visible = True def exit_action(icon): icon.visible = False icon.stop() os._exit(1) image = Image.open(os.path.join("images", "snappy_systray.png")) icon = Icon("snappy", icon=image, title="snappy") menu = Menu(MenuItem("exit", lambda: exit_action(icon))) icon.menu = menu icon.run(setup)
def menu(): menu = gtk.Menu() command_one = gtk.MenuItem('My Notes') command_one.connect('activate', note) menu.append(command_one) exittray = gtk.MenuItem('Exit Tray') exittray.connect('activate', quit) menu.append(exittray) menu.show_all() return menu
def main(): logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s', level=logging.INFO) logging.info('URL Trimmer boot!') global thread thread = ClipboardThread(WindowsTextClipboard(), DEFAULT_FILTERS) logging.info('Starting clipboard thread') thread.start() image = Image.open('icon.png') icon = Icon('URL Trimmer', icon=image, menu=Menu( MenuItem('Settings', lambda icon, item: None), MenuItem('Exit', close_app) )) logging.info('Starting system tray icon') icon.run()
def start(self): def on_clicked(icon, _): logging.info('[APP] Closing. Source: TrayIcon') states.running = False icon.stop() def clicked_display(_, item): states.displayed = item.checked tray_icon = Icon('chesscord', title='chesscord', icon=Image.open(RESOURCES_DIR / 'logo.png')) tray_icon.menu = Menu( MenuItem('update config', utils.open_webpage), MenuItem('hide', clicked_display, checked=lambda item: not states.displayed), MenuItem('Exit', on_clicked)) tray_icon.run()
def __init__(self): self.cs = CapSwitch() #Run CapSwitch when it is opened self.init_thread(target=self.cs.start_listener) # *** Attributes *** self.icon_path = "icon.png" # *** Setup Menu *** self.menu_items = [ MenuItem(self.check_status, self.toggle), MenuItem("Exit", self.exit), ] self.menu = Menu(*self.menu_items) # *** Create System Tray Icon *** self.icon = Icon("CapSwitch", menu=self.menu) self.icon.icon = Image.open(self.icon_path) self.icon.run()