def tool(channels): def startMidiThread(midiDeviceName): global midi if (midi): midi.stop() midi = MidiInterface(midiDeviceName, channels) midi.start() return midi def on_exit_clicked(icon, item): midi.stop() trayIcon.stop() def on_log_clicked(icon, item): programName = "notepad.exe" fileName = os.getcwd() + "\MidiVolumeMixer.log" sp.Popen([programName, fileName]) def set_state(v): def inner(icon, item): startMidiThread(v) config.set("midi_input", v) return inner def get_state(v): def inner(item): return midi.midiDeviceName == v return inner def get_menu_items(): items = [ item('None', set_state("None"), checked=get_state("None"), radio=True) ] for port, name in midi.getMidiPorts(): items.append( item(name, set_state(name), checked=get_state(name), radio=True)) return items deviceName = config.get("midi_input") startMidiThread(deviceName) trayIcon = icon('MidiVolumeMixer', get_icon_image(), menu=menu(item('Open log', on_log_clicked), item('MIDI Input', menu(get_menu_items)), item('Exit', on_exit_clicked))) trayIcon.run()
def test_menu_dynamic(self): """Tests that a dynamic menu works. """ q = queue.Queue() q.ticks = 0 def on_activate(): q.put(True) q.ticks += 1 ico, colors = icon(menu=menu( item('Item 1', on_activate), item('Item 2', None), item(lambda _:'Item ' + str(q.ticks + 3), None))) @test(ico) def _(): ico.visible = True say('Click Item 1') q.get(timeout=TIMEOUT) say('Expand the popup menu') confirm( self, 'Was it\n%s?' % str(ico.menu))
def test_menu_dynamic_show_hide(self): """Tests that a dynamic menu that is hidden works as expected. """ q = queue.Queue() q.ticks = 0 def on_activate(): q.put(True) q.ticks += 1 def visible(menu_item): return q.ticks % 2 == 0 ico, colors = icon(menu=menu( item('Default', on_activate, default=True, visible=visible), item('Item 2', None, visible=visible))) @test(ico) def _(): ico.visible = True say('Click the icon or select the default menu item') q.get(timeout=TIMEOUT) say('Ensure that the menu does not show and then click the icon') q.get(timeout=TIMEOUT) say('Expand the popup menu') confirm( self, 'Was it\n%s?' % str(ico.menu))
def test_menu_radio_checkable(self): """Tests that providing a value for ``checked`` for checkable items works. """ self.assertFalse(item('Test', None, checked=true).radio) self.assertTrue(item('Test', None, checked=true, radio=True).radio) self.assertTrue(item('Test', None, checked=true, radio=true).radio)
def test_menu_default_none(self): """Tests that an invalid number of default menu items fails. """ self.assertIsNone( menu( item('one', true, default=False), item('two', true, default=False))(None))
def withdraw_window(self): self.root.withdraw() image = Image.open(self.resource_path("mirror_assets/logo.png")) menu = pystray.Menu(item('Quit', self.quit_window), item('Show', self.show_window, default=True)) icon = pystray.Icon("Mirror", image, "Mirror", menu) icon.run()
def withdraw_window(): window.withdraw() image = Image.open("earth.png") menu = (item('Quit', quit_window), item('Show', show_window)) icon = pystray.Icon("name", image, "title", menu) icon.HAS_DEFAULT_ACTION = False icon.run()
def main(): image = Image.open("icon.png") menu = pystray.Menu( item('Clipboard Scrubber', scrub, default=True, enabled=False), pystray.Menu.SEPARATOR, item('Exit', exit)) icon = pystray.Icon('clipboardscrubber', image, 'Clipboard Scrubber', menu) icon.run()
def __init__(self, key): self.key = key self.image = Image.open("img.jpg") self.menu = (item('get', lambda: self.getData()), item('update', lambda: self.updateData()), item('quit', lambda: self.quit())) self.icon = pystray.Icon("name", self.image, "syncboard", self.menu) self.icon.run()
def test_item_call(self): """Tests that calling a menu item works as expected. """ data = [] item('', lambda: data.append(True))(None) self.assertEqual( [True], data)
def icon_start(idk): global icon image = Image.open("icon.ico") menu = (item('Enter Credentials', open_file, default=True), item('Stop Assistant', stop_working)) icon = pystray.Icon("LNM Login Assistant", image, "LNM Login Assistant", menu) icon.run()
def StartRed(): """Changes systray icon to red to indicate no upgrade available.""" global proxied global icon global quit menu = (item('Help', action), item('Quit', exit_prg)) image = Image.open("red.png") icon = pystray.Icon("", image, "Vimes", menu) icon.run()
def update_icon(u_icon): global MENU while u_icon.visible: ip_address, hostname = get_ip_hostname() print(ip_address, hostname) MENU = menu(item(ip_address, action=None), item(hostname, action=None), item('Exit', action=terminate)) u_icon.menu = MENU u_icon.update_menu() sleep(10)
def test_menu_radio_checkable(self): """Tests that providing a value for ``checked`` for checkable items works. """ self.assertFalse( item('Test', None, checked=true).radio) self.assertTrue( item('Test', None, checked=true, radio=True).radio) self.assertTrue( item('Test', None, checked=true, radio=true).radio)
def StartYellow(): """Changes systray icon to yellow to indicate proxy available but not enabled.""" global proxied global icon global quit menu = (item('Help', action), item('Proxy Traffic', ProxyTraffic), item('Quit', exit_prg)) image = Image.open("yellow.png") icon = pystray.Icon("", image, "Vimes", menu) icon.run()
def StartGreen(): """Chagnes systray icon to green to indicate proxied status.""" global proxied global icon global quit menu = (item('Help', action), item('Stop Proxying Traffic', StopProxyTraffic), item('Quit', exit_prg)) image = Image.open("green.png") icon = pystray.Icon("", image, "Vimes", menu) icon.run()
def main(): pyri = Pyri() main_thread = Thread(target=use_pyri, args=[pyri]) secondary_thread = Thread(target=check_reminders, args=[pyri]) main_thread.daemon = True secondary_thread.daemon = True main_thread.start() secondary_thread.start() image = Image.open('./assets/image/icon.png') menu = (item('Empezar', close), item('Salir', close)) icon = pystray.Icon('Pyri', image, 'Pyri', menu) icon.run()
def test_menu_enabled(self): """Tests that menu items can be disabled. """ ico, colors = icon(menu=menu(item('Item 1', None, enabled=true), item('Item 2', None, enabled=False))) @test(ico) def _(): ico.visible = True say('Expand the popup menu') confirm(self, 'Was <Item 1> enabled and <Item 2> disabled?')
def test_menu_construct(self): """Tests that the menu is constructed. """ ico, colors = icon( menu=menu(item('Item 1', None), item('Item 2', None))) @test(ico) def _(): ico.visible = True say('Expand the popup menu') confirm(self, 'Was it\n%s?' % str(ico.menu))
def run_icon_tray(): global icon_tray icon_tray = icon(name='name', icon=Image.open(absolute_path(r'resources\icon.png')), title='Hotkey Manager', menu=menu( item('Active', on_clicked, default=True, checked=lambda item: state), item('Exit', menu_exit))) icon_tray.run()
def test_menu_construct(self): """Tests menu construction. """ self.assertEqual( ''' Test entry one Test entry two Test entry three Test entry four''', '\n' + str( menu(item('Test entry one', None), item( 'Test entry two', None), item('Test entry three', None), item('Test entry four', None))))
def test_menu_radio(self): """Tests that mutually exclusive items are displayed separately. """ ico, colors = icon( menu=menu(item('Item 1', None, checked=true), item('Item 2', None, checked=true, radio=True))) @test(ico) def _(): ico.visible = True say('Expand the popup menu') confirm(self, 'Was <Item 2> displayed differently from <Item 1>?')
def test_menu_separator(self): """Tests menu construction with separators. """ # Separators at the head and tail are ignored self.assertEqual( ''' Test entry one - - - - Test entry two''', '\n' + str( menu(separator(), separator(), item('Test entry one', None), separator(), item('Test entry hidden', None, visible=False), separator(), item('Test entry two', None), separator(), separator())))
def run_systray(): global systray, window_shown systray_menu = menu( item('VALORANT-RPC by restrafes', tray_window_toggle, enabled=False), item('Show Debug Window', tray_window_toggle, checked=lambda item: window_shown), item('Quit', exit_program)) systray = pystray.Icon("VALORANT RPC", Image.open("resources/favicon.ico"), "VALORANT RPC", systray_menu) systray.run()
def test_menu_construct(self): """Tests menu construction. """ self.assertEqual( ''' Test entry one Test entry two Test entry three Test entry four''', '\n' + str(menu( item('Test entry one', None), item('Test entry two', None), item('Test entry three', None), item('Test entry four', None))))
def start_icon(self): global state global defend image = Image.open("resources\icon.png") self.icon = pystray.Icon('RDEF', image, 'RDEF notifications', menu=menu( item('Notifications', self.on_clicked_notifications, checked=lambda item: state), item('Defend', self.on_clicked_defend, checked=lambda item: defend))) self.icon.run()
def test_menu_enabled(self): """Tests that menu items can be disabled. """ ico, colors = icon(menu=menu( item('Item 1', None, enabled=true), item('Item 2', None, enabled=False))) @test(ico) def _(): ico.visible = True say('Expand the popup menu') confirm( self, 'Was <Item 1> enabled and <Item 2> disabled?')
def test_item_call_various_args(self): """Tests that calling a menu item works as expected. """ item('', lambda: None)(None) item('', lambda a: a)(None) item('', lambda a, b: (a, b))(None) with self.assertRaises(ValueError): item('', lambda a, b, c: (a, b, ))
def test_menu_construct(self): """Tests that the menu is constructed. """ ico, colors = icon(menu=menu( item('Item 1', None), item('Item 2', None))) @test(ico) def _(): ico.visible = True say('Expand the popup menu') confirm( self, 'Was it\n%s?' % str(ico.menu))
def test_menu_radio(self): """Tests that mutually exclusive items are displayed separately. """ ico, colors = icon(menu=menu( item('Item 1', None, checked=true), item('Item 2', None, checked=true, radio=True))) @test(ico) def _(): ico.visible = True say('Expand the popup menu') confirm( self, 'Was <Item 2> displayed differently from <Item 1>?')
def traymenu(): global RUN try: image = Image.open("icon.png") menu = ( item('Run', on_clicked, checked=lambda item:RUN), item("Settings", settingsmenu), item("About", about), item('Quit', quit) ) icon = pystray.Icon("name", image,"title",menu) icon.run() except: error_message("traymenu failed")
def test_menu_default_callable(self): """Tests that the default menu item is activated when calling the menu. """ self.assertEqual( 'test result', menu( item('one', lambda: 'test result', default=True))(None))
def test_menu_construct_with_submenu(self): """Tests menu construction. """ self.assertEqual( ''' Test entry 1 Test entry 2 => Test entry 3 Test entry 4 Test entry 5''', '\n' + str(menu( item('Test entry 1', None), item('Test entry 2', menu( item('Test entry 3', None), item('Test entry 4', None))), item('Test entry 5', None))))
def get_menu_items(): items = [ item('None', set_state("None"), checked=get_state("None"), radio=True) ] for port, name in midi.getMidiPorts(): items.append( item(name, set_state(name), checked=get_state(name), radio=True)) return items
def create_systray(self): ypos = cef_config['ypos'] cef_config['typos'] = ypos + 40 # 显示系统托盘 image = get_icon() # 这里如果用相对路径default.ico,那么用bat调用时报错。 self.menu = pystray.Menu(item('打开', self.show_window, default=True), item('退出', self.quit_window)) # 这里menu应该用pystray.Menu(),如果直接使用tuple,那么左键单击报错,其他功能正常。 # 鼠标左键点击托盘图标运行default=True的Menuitem,如果default均为False,则无动作。 self.icon = pystray.Icon("djangomdict", icon=image, title='django-mdict', menu=self.menu) if self.huaci.master is None: self.huaci.set_master(self) self.icon.run()
def test_menu_activate(self): """Tests that the menu can be activated. """ q = queue.Queue() def on_activate(): q.put(True) ico, colors = icon(menu=( item('Item 1', on_activate), item('Item 2', None))) @test(ico) def _(): ico.visible = True say('Click Item 1') q.get(timeout=TIMEOUT)
def test_menu_invisble(self): """Tests that a menu consisting of only empty items does not show. """ q = queue.Queue() def on_activate(): q.put(True) ico, colors = icon(menu=menu( item('Item1', None, visible=False), item('Item2', on_activate, default=True, visible=False))) @test(ico) def _(): ico.visible = True say('Ensure that the menu does not show and then click the icon') q.get(timeout=TIMEOUT)
def test_activate_with_default(self): """Tests that the default menu item is activated when activating icon. """ q = queue.Queue() def on_activate(icon): q.put(True) ico, colors = icon(menu=menu( item('Item 1', None), item('Default', on_activate, default=True))) @test(ico) def _(): ico.visible = True say('Click the icon or select the default menu item') q.get(timeout=TIMEOUT)
def test_menu_separator(self): """Tests menu construction with separators. """ # Separators at the head and tail are ignored self.assertEqual( ''' Test entry one - - - - Test entry two''', '\n' + str(menu( separator(), separator(), item('Test entry one', None), separator(), item('Test entry hidden', None, visible=False), separator(), item('Test entry two', None), separator(), separator())))
def test_menu_construct_from_generator(self): """Tests menu construction. """ self.assertEqual( ''' Test entry 1 Test entry 2 Test entry 3 Test entry 4''', '\n' + str(menu(lambda: ( item('Test entry %d' % (i + 1), None) for i in range(4)))))
def create(configuration): """Creates the system tray icon. """ def href(path): def inner(*args, **kwargs): webbrowser.open(urllib.parse.urljoin( configuration.SERVER_URL, path)) return inner def access_token_toggle(*args): configuration.ACCESS_TOKEN = ( None if configuration.ACCESS_TOKEN is not None else generate_access_token()) return pystray.Icon( __name__, title='Virtual Touchpad - {}'.format( configuration.SERVER_URL), icon=PIL.Image.open( resource.open_stream( { 'darwin': 'icon-dark.png', 'linux': 'icon-light.png', 'win32': 'icon-light.png'}[sys.platform])), menu=menu( item( _('Connect mobile device...'), href('qr')), item( _('Require access code to connect'), access_token_toggle, checked=lambda i: bool(configuration.ACCESS_TOKEN)), menu.SEPARATOR, item( _('Help'), href('help')), menu.SEPARATOR, item( _('Exit'), lambda icon: icon.server.stop())))
def test_menu_visible_submenu(self): """Tests that ``visible`` is correctly set when a submenu is set. """ self.assertTrue( item('Test', menu( item('Item', None)), visible=True).visible) self.assertFalse( item('Test', menu( item('Item', None)), visible=False).visible) self.assertFalse( item('Test', menu( item('Item', None, visible=False)), visible=True).visible)
def test_menu_enabled_callable(self): """Tests that the enabled state can be set. """ self.assertFalse( item( 'one', lambda: 'test result', enabled=False).enabled)
def test_menu_enabled_default(self): """Tests that a menu item is enabled by default. """ self.assertTrue( item( 'one', lambda: 'test result').enabled)
def test_menu_checked_none(self): """Tests that not providing a value for ``default`` works. """ self.assertFalse( item('Test', None).checked)
def test_menu_checked_non_callable(self): """Tests that not passing a callable as checked fails. """ with self.assertRaises(ValueError): item('Test', None, checked=False)
def test_menu_checked_non_callable(self): """Tests that not providing a value for ``default`` works. """ self.assertTrue( item('Test', None, checked=true).checked)
def test_item_name(self): """Tests that the text is set correctly. """ self.assertEqual( 'Test entry', item('Test entry', None).text)
def action(on_activate): """A convenience function to create a hidden default menu item. :param callable on_activate: The activation callback. """ return item('Default', on_activate, default=True, visible=False)