예제 #1
0
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()
예제 #2
0
 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)
예제 #3
0
 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)
예제 #4
0
def main():
    indicator = appindicator.Indicator.new(
        "customtray", "semi-starred-symbolic",
        appindicator.IndicatorCategory.APPLICATION_STATUS)
    indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
    indicator.set_menu(menu())
    gtk.main()
예제 #5
0
    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))
예제 #6
0
    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))
예제 #7
0
 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))
예제 #8
0
 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))
예제 #9
0
 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))
예제 #10
0
    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))
예제 #11
0
    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))
예제 #12
0
 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))))
예제 #13
0
 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))))
예제 #14
0
 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))
예제 #15
0
    def __init__(self, app_name):
        self.app_name = app_name

        self.ALGORITHM_STATE = Config.CURRENT_ALGORITHM

        self.icon = Icon(self.app_name,
                         icon=self.get_icon(),
                         menu=menu(
                             item('Show QR code',
                                  lambda icon: self.onclick_qr()),
                             item('Open Results Dir',
                                  lambda icon: self.onclick_results()),
                             menu.SEPARATOR,
                             item('Matching Algorithm',
                                  lambda icon: None,
                                  enabled=False),
                             item('SURF (Precise)',
                                  self.set_state('SURF'),
                                  checked=self.get_state('SURF'),
                                  radio=True),
                             item('ORB (Fast)',
                                  self.set_state('ORB'),
                                  checked=self.get_state('ORB'),
                                  radio=True), menu.SEPARATOR,
                             item('Quit', lambda icon: self.onclick_quit())))
예제 #16
0
def make_menu(connected):
    mainMenu = []
    for device in connected:
        menuItem = item(
            device['name'],
            menu(
                item(
                    'A2DP', lambda icon, item: switch_profile(
                        device['address'], 'a2dp_sink')),
                item(
                    'HSP/HFP', lambda icon, item: switch_profile(
                        device['address'], 'headset_head_unit'))))

        mainMenu.append(menuItem)

    icon('BT profile manager', get_tray_image_icon(),
         menu=menu(*mainMenu)).run()
예제 #17
0
def IconCreate():
	global vh
	global trayActions
	global icon
	global DisableTray
	if(DisableTray): return
	icon('elvex', Image.open(BytesIO(requests.get("https://avatars3.githubusercontent.com/u/56801454?s=400&u=0ca69763a92ebb07e3bcf1264d17eaed40682467&v=4").content)), menu=menu(
		item('-- Elvex SOCIAL v'+str(version),trayActions.none, enabled=False),
		item('Dashboard', trayActions.dashboardOpen),
		item('Server settings', menu(
			item("Maintenance", menu(
				item('Disabled', lambda: trayActions.switchTechWorks(-1), checked=lambda i: trayActions.GetCheckedMaintenance(-1)),
				item('Maintenance', lambda: trayActions.switchTechWorks(0), checked=lambda i: trayActions.GetCheckedMaintenance(0)),
				item('Update', lambda: trayActions.switchTechWorks(1), checked=lambda i: trayActions.GetCheckedMaintenance(1)),
				item('Not listed', lambda: trayActions.switchTechWorks(2), checked=lambda i: trayActions.GetCheckedMaintenance(2))
			))
		)),
		item('Restart', trayActions.restart),
		item('Exit', trayActions.exit))).run()
예제 #18
0
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)
예제 #19
0
 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)))))
예제 #20
0
 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))))
예제 #21
0
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()
예제 #22
0
    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))
예제 #23
0
    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?')
예제 #24
0
 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)))))
예제 #25
0
    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>?')
예제 #26
0
 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()
예제 #27
0
 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())))
예제 #28
0
 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))))
예제 #29
0
 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()
예제 #30
0
    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))
예제 #31
0
    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>?')
예제 #32
0
파일: 6m.py 프로젝트: JustinHop/6m
def tray(**kwargs):
    """Runs the system tray selector"""
    traydir = os.path.dirname(os.path.realpath(__file__))
    logger.debug("traydir = {}".format(traydir))
    iconf = os.path.join(traydir, "6m.png")
    if os.path.isfile(iconf):
        icon("6m",
             Image.open(iconf),
             menu=menu(lambda: (
                item(
                    str(i),
                    set_state(i),
                    checked=get_state(i),
                    radio=True)
             for i in config['players']))).run()
예제 #33
0
    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?')
예제 #34
0
    def test_activate(self):
        """Tests that ``on_activate`` is correctly called.
        """
        q = queue.Queue()

        def on_activate(icon):
            q.put(True)

        ico, colors = icon(menu=menu(action(on_activate), ))

        @test(ico)
        def _():
            ico.visible = True

            say('Click the icon')
            q.get(timeout=TIMEOUT)
예제 #35
0
    def test_activate(self):
        """Tests that ``on_activate`` is correctly called.
        """
        q = queue.Queue()

        def on_activate(icon):
            q.put(True)

        ico, colors = icon(menu=menu(
            action(on_activate),))

        @test(ico)
        def _():
            ico.visible = True

            say('Click the icon')
            q.get(timeout=TIMEOUT)
예제 #36
0
    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)
예제 #37
0
 def run(self):
     global window_shown
     Systray.generate_icon()
     systray_image = Image.open(
         Filepath.get_path(
             os.path.join(Filepath.get_appdata_folder(), 'favicon.ico')))
     systray_menu = menu(
         item('show window',
              Systray.tray_window_toggle,
              checked=lambda item: window_shown),
         item('config', Systray.modify_config),
         #item('copy join link', self.copy_join_link),
         item('reload', Systray.restart),
         item('exit', self.exit))
     self.systray = icon("valorant-rpc", systray_image, "valorant-rpc",
                         systray_menu)
     self.systray.run()
예제 #38
0
    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)
예제 #39
0
파일: tray.py 프로젝트: denosawr/pymine
def create_menu(port: int) -> menu:
    NO_ACTION = lambda _: None
    return menu(
        item("pymine server", NO_ACTION, enabled=False),
        item(f"Active on port {port}", NO_ACTION, enabled=False),
        item("", NO_ACTION, enabled=False),
        item("Type the following command into Minecraft:", NO_ACTION, enabled=False),
        item(
            f"/connect localhost:{port}",
            lambda icon: copy_to_clipboard(icon=icon, port=port),
            enabled=True,
            default=True,
        ),
        item("(click above to copy)", NO_ACTION, enabled=False,),
        item("", NO_ACTION, enabled=False),
        item("WS: 19132, HTTP: 19133", NO_ACTION, enabled=False),
        item("Quit", quit_handler, enabled=True),
    )
예제 #40
0
    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)
예제 #41
0
    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)
예제 #42
0
    def test_menu_activate_submenu(self):
        """Tests that an item in a submenu can be activated.
        """
        q = queue.Queue()

        def on_activate():
            q.put(True)

        ico, colors = icon(menu=(
            item('Item 1', None),
            item('Submenu',
                 menu(item('Item 2', None), item('Item 3', on_activate)))))

        @test(ico)
        def _():
            ico.visible = True

            say('Click Item 3 in the submenu')
            q.get(timeout=TIMEOUT)
예제 #43
0
 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())))
예제 #44
0
    def test_menu_activate_submenu(self):
        """Tests that an item in a submenu can be activated.
        """
        q = queue.Queue()

        def on_activate():
            q.put(True)

        ico, colors = icon(menu=(
            item('Item 1', None),
            item('Submenu', menu(
                item('Item 2', None),
                item('Item 3', on_activate)))))

        @test(ico)
        def _():
            ico.visible = True

            say('Click Item 3 in the submenu')
            q.get(timeout=TIMEOUT)
예제 #45
0
def tray():
    global state

    def on_clicked(icon, item):
        global state
        if state == True:
            icon.icon = Image.open('icon_off.ico')
            icon._update_icon()
        else:
            icon.icon = Image.open('icon.ico')
            icon._update_icon()
        state = not item.checked

    icon('Keyboard Sound',
         Image.open('icon.ico'),
         menu=menu(
             item('Active',
                  on_clicked,
                  default=True,
                  visible=True,
                  checked=lambda item: state))).run()
예제 #46
0
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())))
예제 #47
0
from pystray import Icon as icon, Menu as menu, MenuItem as item
from PIL import Image, ImageDraw
from json import loads as json_loads, dumps as json_dumps
import app


def create_image():

    image = Image.open('./icon.png')
    image.thumbnail([64, 64], Image.ANTIALIAS)

    return image


def set_scene(icon, item):
    app.scene(str(item))


icon = icon(
    'test',
    create_image(),
    menu=menu(
        item('on', lambda icon, item: app.on()),
        item('off', lambda icon, item: app.off()),
        item(
            'scenes',
            menu(lambda: (item(scene, set_scene)
                          for scene in app.CONFIGS['scenes'].keys())))))
icon.run()