Exemple #1
0
def build(app):
    brutus_icon = "icons/brutus"
    cricket_icon = "icons/cricket-72.png"

    data = [('root%s' % i, 'value %s' % i) for i in range(1, 100)]

    left_container = toga.Table(headings=['Hello', 'World'], data=data)

    right_content = toga.Box(style=Pack(direction=COLUMN, padding_top=50))

    for b in range(0, 10):
        right_content.add(
            toga.Button('Hello world %s' % b,
                        on_press=button_handler,
                        style=Pack(width=200, padding=20)))

    right_container = toga.ScrollContainer(horizontal=False)

    right_container.content = right_content

    split = toga.SplitContainer()

    split.content = [left_container, right_container]

    things = toga.Group('Things')

    cmd0 = toga.Command(action0,
                        label='Action 0',
                        tooltip='Perform action 0',
                        icon=brutus_icon,
                        group=things)
    cmd1 = toga.Command(action1,
                        label='Action 1',
                        tooltip='Perform action 1',
                        icon=brutus_icon,
                        group=things)
    cmd2 = toga.Command(action2,
                        label='Action 2',
                        tooltip='Perform action 2',
                        icon=toga.Icon.TOGA_ICON,
                        group=things)
    cmd3 = toga.Command(action3,
                        label='Action 3',
                        tooltip='Perform action 3',
                        shortcut=toga.Key.MOD_1 + 'k',
                        icon=cricket_icon)

    def action4(widget):
        print("CALLING Action 4")
        cmd3.enabled = not cmd3.enabled

    cmd4 = toga.Command(action4,
                        label='Action 4',
                        tooltip='Perform action 4',
                        icon=brutus_icon)

    app.commands.add(cmd1, cmd3, cmd4, cmd0)
    app.main_window.toolbar.add(cmd1, cmd2, cmd3, cmd4)

    return split
Exemple #2
0
    def create(self):
        self.native = WinForms.Application

        if win_version >= 6:
            user32.SetProcessDPIAware(True)
        self.native.EnableVisualStyles()
        self.native.SetCompatibleTextRenderingDefault(False)

        self.interface.commands.add(
            toga.Command(None,
                         'About ' + self.interface.name,
                         group=toga.Group.HELP),
            toga.Command(None, 'Preferences', group=toga.Group.FILE),
            # Quit should always be the last item, in a section on it's own
            toga.Command(lambda s: self.exit(),
                         'Exit ' + self.interface.name,
                         shortcut='q',
                         group=toga.Group.FILE,
                         section=sys.maxsize),
            toga.Command(None, 'Visit homepage', group=toga.Group.HELP))
        self._create_app_commands()

        # Call user code to populate the main window
        self.interface.startup()
        self._menu_items = {}
        self.create_menus()
        self.interface.main_window._impl.native.Icon = \
            self.interface.icon.bind(self.interface.factory).native
Exemple #3
0
    def create(self):
        self.native = NSApplication.sharedApplication()
        self.native.setActivationPolicy_(NSApplicationActivationPolicyRegular)

        self.native.setApplicationIconImage_(self.interface.icon._impl.native)

        self.resource_path = os.path.dirname(
            os.path.dirname(NSBundle.mainBundle.bundlePath))

        appDelegate = AppDelegate.alloc().init()
        appDelegate.interface = self
        self.native.setDelegate_(appDelegate)

        app_name = self.interface.name

        self.interface.commands.add(
            toga.Command(None, 'About ' + app_name, group=toga.Group.APP),
            toga.Command(None, 'Preferences', group=toga.Group.APP),
            # Quit should always be the last item, in a section on it's own
            toga.Command(lambda s: self.exit(),
                         'Quit ' + app_name,
                         shortcut='q',
                         group=toga.Group.APP,
                         section=sys.maxsize),
            toga.Command(None, 'Visit homepage', group=toga.Group.HELP))

        # Call user code to populate the main window
        self.interface.startup()

        # Create the lookup table of menu items,
        # then force the creation of the menus.
        self._menu_items = {}
        self.create_menus()
Exemple #4
0
    def build(app):
        left_container = toga.Table(['Hello', 'World'])

        left_container.insert(None, 'root1', 'value1')
        left_container.insert(None, 'root2', 'value2')
        left_container.insert(None, 'root3', 'value3')
        left_container.insert(1, 'root4', 'value4')

        for i in range(0, 100):
            left_container.insert(None, 'root%s' % (i + 5),
                                  'value%s' % (i + 5))

        right_content = toga.Box(
            style=CSS(flex_direction='column', padding_top=50))

        for b in range(0, 10):
            right_content.add(
                toga.Button('Hello world %s' % b,
                            on_press=button_handler,
                            style=CSS(width=200, margin=20)))

        right_container = toga.ScrollContainer(horizontal=False)

        right_container.content = right_content

        split = toga.SplitContainer()

        split.content = [left_container, right_container]

        cmd1 = toga.Command(action1,
                            'Action 1',
                            tooltip='Perform action 1',
                            icon='icons/brutus.icns')
        cmd2 = toga.Command(action2,
                            'Action 2',
                            tooltip='Perform action 2',
                            icon=toga.TIBERIUS_ICON)
        cmd3 = toga.Command(action3,
                            'Action 3',
                            tooltip='Perform action 3',
                            icon='icons/cricket-72.png')

        def action4(widget):
            print("CALLING Action 4")
            cmd3.enabled = not cmd3.enabled

        cmd4 = toga.Command(action4,
                            'Action 4',
                            tooltip='Perform action 4',
                            icon='icons/brutus.icns')

        app.main_window.toolbar = [
            cmd1, toga.SEPARATOR, cmd2, toga.SPACER, cmd3,
            toga.EXPANDING_SPACER, cmd4
        ]

        return split
Exemple #5
0
    def _setup_commands(self):
        # Custom command groups
        self.control_tests_group = toga.Group('Test')
        self.instruments_group = toga.Group('Instruments')

        self.show_coverage_command = toga.Command(self.cmd_show_coverage,
                                                  'Show coverage...',
                                                  group=self.instruments_group)
        self.show_coverage_command.enabled = False if duvet is None else True

        # Button to stop run the tests
        self.stop_command = toga.Command(self.cmd_stop,
                                         'Stop',
                                         tooltip='Stop running the tests.',
                                         icon=toga.Icon('resources/stop.png'),
                                         shortcut='s',
                                         group=self.control_tests_group)
        self.stop_command.enabled = False

        # Button to run all the tests
        self.run_all_command = toga.Command(
            self.cmd_run_all,
            'Run all',
            tooltip='Run all the tests.',
            icon=toga.Icon('resources/play.png'),
            shortcut='r',
            group=self.control_tests_group)

        # Button to run only the tests selected by the user
        self.run_selected_command = toga.Command(
            self.cmd_run_selected,
            'Run selected',
            tooltip='Run the tests selected.',
            icon=toga.Icon('resources/run_select.png'),
            shortcut='e',
            group=self.control_tests_group)
        self.run_selected_command.enabled = False

        # Re-run all the tests
        self.rerun_command = toga.Command(
            self.cmd_rerun,
            'Re-run',
            tooltip='Re-run the tests.',
            icon=toga.Icon('resources/re_run.png'),
            shortcut='a',
            group=self.control_tests_group)
        self.rerun_command.enabled = False

        # Cricket's menu items
        self.commands.add(
            # Instrument items
            self.show_coverage_command, )

        self.main_window.toolbar.add(self.stop_command, self.run_all_command,
                                     self.run_selected_command,
                                     self.rerun_command)
Exemple #6
0
    def startup(self):
        # Window class
        #   Main window of the application with title and size
        #   Also make the window non-resizable and non-minimizable.
        self.main_window = toga.MainWindow(title=self.name,
                                           size=(800, 500),
                                           resizeable=False,
                                           minimizable=False)

        self.a_button = toga.Button("A", on_press=self.on_button_press)
        self.b_button = toga.Button("B", on_press=self.on_button_press)
        self.c_button = toga.Button("C", on_press=self.on_button_press)
        self.text_input = toga.TextInput(
            placeholder="I get focused on startup.",
            style=Pack(height=25, width=200, font_size=10))
        self.switch = toga.Switch("Switch", on_toggle=self.on_switch_toggle)
        self.info_label = toga.Label(
            "Use keyboard shortcuts to focus on the different widgets",
            style=Pack(font_size=10))
        # Add the content on the main window
        self.main_window.content = toga.Box(
            style=Pack(direction=COLUMN),
            children=[
                toga.Box(
                    children=[self.a_button, self.b_button, self.c_button]),
                toga.Box(children=[self.text_input]),
                toga.Box(children=[self.switch]),
                toga.Box(children=[self.info_label])
            ])

        self.commands.add(
            toga.Command(lambda widget: self.focus_with_label(self.a_button),
                         label="Focus on A",
                         shortcut=toga.Key.MOD_1 + "a",
                         group=WIDGETS_GROUP),
            toga.Command(lambda widget: self.focus_with_label(self.b_button),
                         label="Focus on B",
                         shortcut=toga.Key.MOD_1 + "b",
                         group=WIDGETS_GROUP),
            toga.Command(lambda widget: self.focus_with_label(self.c_button),
                         label="Focus on C",
                         shortcut=toga.Key.MOD_1 + "c",
                         group=WIDGETS_GROUP),
            toga.Command(
                lambda widget: self.focus_on(self.text_input, "TextInput"),
                label="Focus on text input",
                shortcut=toga.Key.MOD_1 + "t",
                group=WIDGETS_GROUP),
            toga.Command(lambda widget: self.focus_with_label(self.switch),
                         label="Focus on switch",
                         shortcut=toga.Key.MOD_1 + "s",
                         group=WIDGETS_GROUP))
        # Show the main window
        self.main_window.show()

        self.text_input.focus()
Exemple #7
0
    def create(self):
        self.native = WinForms.Application
        self.app_context = WinForms.ApplicationContext()

        # Check the version of windows and make sure we are setting the DPI mode
        # with the most up to date API
        # Windows Versioning Check Sources : https://www.lifewire.com/windows-version-numbers-2625171
        # and https://docs.microsoft.com/en-us/windows/release-information/
        if win_version.Major >= 6:  # Checks for Windows Vista or later
            # Represents Windows 8.1 up to Windows 10 before Build 1703 which should use
            # SetProcessDpiAwareness(True)
            if ((win_version.Major == 6 and win_version.Minor == 3) or
                    (win_version.Major == 10 and win_version.Build < 15063)):
                shcore.SetProcessDpiAwareness(True)
            # Represents Windows 10 Build 1703 and beyond which should use
            # SetProcessDpiAwarenessContext(-2)
            elif win_version.Major == 10 and win_version.Build >= 15063:
                user32.SetProcessDpiAwarenessContext(-2)
            # Any other version of windows should use SetProcessDPIAware()
            else:
                user32.SetProcessDPIAware()

        self.native.EnableVisualStyles()
        self.native.SetCompatibleTextRenderingDefault(False)

        self.interface.commands.add(
            toga.Command(
                lambda _: self.interface.about(),
                'About {}'.format(self.interface.name),
                group=toga.Group.HELP
            ),
            toga.Command(None, 'Preferences', group=toga.Group.FILE),
            # Quit should always be the last item, in a section on it's own
            toga.Command(
                lambda _: self.interface.exit(),
                'Exit ' + self.interface.name,
                shortcut=Key.MOD_1 + 'q',
                group=toga.Group.FILE,
                section=sys.maxsize
            ),
            toga.Command(
                lambda _: self.interface.visit_homepage(),
                'Visit homepage',
                enabled=self.interface.home_page is not None,
                group=toga.Group.HELP
            )
        )
        self._create_app_commands()

        # Call user code to populate the main window
        self.interface.startup()
        self._menu_items = {}
        self.create_menus()
        self.interface.icon.bind(self.interface.factory)
        self.interface.main_window._impl.set_app(self)
Exemple #8
0
    def create(self):
        self.interface.startup()

        self.interface.icon.bind(self.interface.factory)
        # self.resource_path = os.path.dirname(os.path.dirname(NSBundle.mainBundle.bundlePath))

        formal_name = self.interface.formal_name
        self.interface.commands.add(
            toga.Command(None, 'About ' + formal_name, group=toga.Group.APP),
            toga.Command(None, 'Preferences', group=toga.Group.APP),
        )
Exemple #9
0
    def startup(self):
        # Initialization
        self.dfs = Dfs()

        self.main_window = toga.MainWindow(title=self.name, size=(1366, 720))
        self.main_container = toga.SplitContainer(
            style=Pack(flex=1, padding=(0, 5, -62, 5)),
            direction=toga.SplitContainer.HORIZONTAL,
        )
        self.search_results_table = toga.Table(
            headings=["Name", "Size", "Hash"],
            on_select=self.download,
            data=[])
        self.logs_table = toga.Table(headings=["Category", "Detail"], data=[])
        self.search_query_input = toga.TextInput(placeholder="Search Query",
                                                 style=Pack(flex=1))
        box = toga.Box(
            children=[
                toga.Box(
                    children=[
                        self.search_query_input,
                        toga.Button(
                            "Search",
                            on_press=self.search,
                            style=Pack(width=80, padding_left=5),
                        ),
                    ],
                    style=Pack(direction=ROW,
                               alignment=CENTER,
                               padding=(70, 5, 5, 5)),
                ),
                self.main_container,
            ],
            style=Pack(direction=COLUMN),
        )
        self.main_container.content = [
            self.search_results_table, self.logs_table
        ]
        add_file_cmd = toga.Command(
            self.share,
            label="Add File",
            tooltip="Select file to share",
            icon=Path("./res/icons/baseline_add_black_18dp.png").absolute(),
        )
        add_folder_cmd = toga.Command(
            self.share,
            label="Add Folder",
            tooltip="Select folder to share",
            icon=Path("./res/icons/baseline_add_black_18dp.png").absolute(),
        )
        # self.commands.add(add_file_cmd)
        self.main_window.toolbar.add(add_file_cmd, add_folder_cmd)
        self.main_window.content = box
        self.main_window.show()
Exemple #10
0
    def create(self):
        self.native = NSApplication.sharedApplication
        self.native.setActivationPolicy(NSApplicationActivationPolicyRegular)

        icon = self.interface.icon.bind(self.interface.factory)
        self.native.setApplicationIconImage_(icon.native)

        self.resource_path = os.path.dirname(os.path.dirname(NSBundle.mainBundle.bundlePath))

        self.appDelegate = AppDelegate.alloc().init()
        self.appDelegate.impl = self
        self.appDelegate.interface = self.interface
        self.appDelegate.native = self.native
        self.native.setDelegate_(self.appDelegate)

        formal_name = self.interface.formal_name

        self.interface.commands.add(
            toga.Command(
                lambda _: self.interface.about(),
                'About ' + formal_name,
                group=toga.Group.APP
            ),
            toga.Command(None, 'Preferences', group=toga.Group.APP),
            # Quit should always be the last item, in a section on it's own
            toga.Command(
                lambda _: self.interface.exit(),
                'Quit ' + formal_name,
                shortcut=toga.Key.MOD_1 + 'q',
                group=toga.Group.APP,
                section=sys.maxsize
            ),

            toga.Command(
                lambda _: self.interface.visit_homepage(),
                'Visit homepage',
                enabled=self.interface.home_page is not None,
                group=toga.Group.HELP
            )
        )
        self._create_app_commands()

        # Call user code to populate the main window
        self.interface.startup()

        # Create the lookup table of menu items,
        # then force the creation of the menus.
        self._menu_items = {}
        self.create_menus()
Exemple #11
0
    def startup(self):
        box = toga.Box()
        box.style.direction = COLUMN
        box.style.padding = 10
        self.scroller = toga.ScrollContainer(horizontal=self.hscrolling,
                                             vertical=self.vscrolling)
        switch_box = toga.Box(style=Pack(direction=ROW))
        switch_box.add(
            toga.Switch('vertical scrolling',
                        is_on=self.vscrolling,
                        on_toggle=self.handle_vscrolling))
        switch_box.add(
            toga.Switch('horizontal scrolling',
                        is_on=self.hscrolling,
                        on_toggle=self.handle_hscrolling))
        box.add(switch_box)

        for x in range(100):
            label_text = 'Label {}'.format(x)
            box.add(Item(label_text))

        self.scroller.content = box

        self.main_window = toga.MainWindow(self.name, size=(400, 700))
        self.main_window.content = self.scroller
        self.main_window.show()
        self.commands.add(
            toga.Command(self.toggle_up,
                         "Toggle Up",
                         shortcut=toga.Key.MOD_1 + toga.Key.UP,
                         group=toga.Group.VIEW,
                         order=1),
            toga.Command(self.toggle_down,
                         "Toggle Down",
                         shortcut=toga.Key.MOD_1 + toga.Key.DOWN,
                         group=toga.Group.VIEW,
                         order=2),
            toga.Command(self.toggle_left,
                         "Toggle Left",
                         shortcut=toga.Key.MOD_1 + toga.Key.LEFT,
                         group=toga.Group.VIEW,
                         order=3),
            toga.Command(self.toggle_right,
                         "Toggle Right",
                         shortcut=toga.Key.MOD_1 + toga.Key.RIGHT,
                         group=toga.Group.VIEW,
                         order=4),
        )
Exemple #12
0
 def set_menu_bar(self, menu):
     groups = {
         'App': toga.Group.APP,
         'File': toga.Group.FILE,
         'Edit': toga.Group.EDIT,
         'View': toga.Group.VIEW,
         'Commands': toga.Group.COMMANDS,
         'Window': toga.Group.WINDOW,
         'Help': toga.Group.HELP
     }
     for item in menu:
         section = 0
         try:
             group = groups[item['label']]
         except KeyError:
             group = toga.Group(item['label'])
         for child in item['children']:
             if child['type'] == 'menu_separator':
                 section += 1
                 continue
             command = toga.Command(
                 child['callback'],
                 label = child['label'],
                 shortcut = child['shortcut'],
                 section = section,
                 group = group,
             )
             if 'enabled' in child: command.enabled = child['enabled']
             self.commands.add(command)
Exemple #13
0
 def test_command_init_kargs(self):
     grp = toga.Group('Test group', order=10)
     cmd = toga.Command(lambda x: print('Hello World'),
                        label='test',
                        tooltip='test command',
                        shortcut='t',
                        icon='icons/none.png',
                        group=grp,
                        section=1,
                        order=1,
                        factory=toga_dummy.factory
                        )
     self.assertEqual(cmd.label, 'test')
     self.assertEqual(cmd.shortcut, 't')
     self.assertEqual(cmd.tooltip, 'test command')
     self.assertEqual(cmd.icon_id, 'icons/none.png')
     self.assertEqual(cmd.group, grp)
     self.assertEqual(cmd.section, 1)
     self.assertEqual(cmd.order, 1)
     self.assertTrue(cmd._enabled)
     self.assertEqual(cmd._widgets, [])
     self.assertTrue(cmd.enabled)
     cmd.enabled = False
     self.assertFalse(cmd._enabled)
     self.assertFalse(cmd.enabled)
Exemple #14
0
Fichier : app.py Projet : djay/toga
 def _create_app_commands(self):
     self.interface.commands.add(
         toga.Command(lambda _: self.select_file(),
                      label='Open...',
                      shortcut=toga.Key.MOD_1 + 'o',
                      group=toga.Group.FILE,
                      section=0), )
Exemple #15
0
    def timer_loop(self):
        start_time = time.time()
        while True:
            # When user has been on screen for some time (CHECKUP_TIME)
            elapsed_time = time.time() - start_time
            if elapsed_time >= self.CHECKUP_TIME:
                print('[App] Checkup time')

                # calls the notify function
                command = toga.Command(self.notify, 'Command')
                command.action(command)

                # restart timer and blink counter
                start_time = time.time()
                fd.blink_count = 0

            # When user has left screen for more than some time (BREAK_TIME)
            if not fd.has_face:
                start_time = time.time()

            # exit loop / stop timer
            if fd.detect_exit:
                self.timer_running = False
                break

        # make sure button usage is changed (if opencv is force quitted with q key)
        self.start_button.enabled = True
        self.stop_button.enabled = False
Exemple #16
0
 def _create_app_commands(self):
     self.interface.commands.add(
         toga.Command(lambda w: self.open_file,
                      label='Open...',
                      shortcut='o',
                      group=toga.Group.FILE,
                      section=0), )
Exemple #17
0
 def test_command_repr(self):
     self.assertEqual(
         repr(
             toga.Command(None,
                          "A",
                          group=PARENT_GROUP1,
                          order=1,
                          section=4)),
         "<Command label=A group=<Group label=P order=1 parent=None> section=4 order=1>"
     )
Exemple #18
0
 def test_command_init_defaults(self):
     cmd = toga.Command(lambda x: print('Hello World'), 'test', factory=toga_dummy.factory)
     self.assertEqual(cmd.label, 'test')
     self.assertEqual(cmd.shortcut, None)
     self.assertEqual(cmd.tooltip, None)
     self.assertEqual(cmd.icon, None)
     self.assertEqual(cmd.group, toga.Group.COMMANDS)
     self.assertEqual(cmd.section, 0)
     self.assertEqual(cmd.order, 0)
     self.assertTrue(cmd._enabled)
Exemple #19
0
def build(app):
	path=os.path.dirname(os.path.abspath(__file__))
	brutus_icon=os.path.join(path,"icons","brutus.icns")
	cricket_icon=os.path.join(path,"icons","cricket-72.png")


	#List of tuples added as table values
	data=[('root%s' % i, 'value %s' % i) for i in range(1,100)]
	left_container=toga.Table(headings=['Hello','World'], data=data)
	




	right_content=toga.Box(style=Pack(direction=COLUMN, padding_top=50))
#Dynamically add buttons
	for b in range(0,10):
		right_content.add(toga.Button('Hello world %s' % b,on_press=button_handler,style=Pack(width=200,padding=20)))


	right_container=toga.ScrollContainer(horizontal=False)
	right_container.content=right_content

	split=toga.SplitContainer()
	split.content=[left_container,right_container]
	

	things=toga.Group('Things')

	#Command object
	cmd0=toga.Command(action0,label='Action 0',tooltip='Perform action 0',icon=brutus_icon,group=things)
	cmd1=toga.Command(action1,label='Action 1',tooltip='Perform action 1',icon=brutus_icon,group=things)
	cmd2=toga.Command(action2,label='Action 2',tooltip='Perform action 2',icon=cricket_icon,group=things)
	cmd3=toga.Command(action3,label='Action 3',tooltip='Perform action 3',shortcut='k',icon=cricket_icon)
	cmd4=toga.Command(action4, label='Action 4',tooltip='Perform action 4',icon=brutus_icon)
	#Add commands as Menu Items
	app.commands.add(cmd1,cmd3,cmd4,cmd0)
	#Add commands as Icons on Toolbar
	app.main_window.toolbar.add(cmd1,cmd2,cmd3,cmd4)

	return split
Exemple #20
0
 def test_cmd_sort_key(self):
     grp = toga.Group('Test group', order=10)
     cmd = toga.Command(lambda x: print('Hello World'),
                        label='test',
                        tooltip='test command',
                        shortcut='t',
                        icon='icons/none.png',
                        group=grp,
                        section=1,
                        order=1,
                        factory=toga_dummy.factory)
     self.assertEqual(toga.cmd_sort_key(cmd), (grp, 1, 1, 'test'))
Exemple #21
0
    def create(self):
        self.native = WinForms.Application

        self.interface.commands.add(
            toga.Command(None,
                         'About ' + self.interface.name,
                         group=toga.Group.HELP),
            toga.Command(None, 'Preferences', group=toga.Group.FILE),
            # Quit should always be the last item, in a section on it's own
            toga.Command(lambda s: self.exit(),
                         'Exit ' + self.interface.name,
                         shortcut='q',
                         group=toga.Group.FILE,
                         section=sys.maxsize),
            toga.Command(None, 'Visit homepage', group=toga.Group.HELP))

        # Call user code to populate the main window
        self.interface.startup()
        self._menu_items = {}
        self.create_menus()
        self.interface.main_window._impl.native.Icon = \
            self.interface.icon.bind(self.interface.factory).native
Exemple #22
0
 def test_command_bind(self):
     grp = toga.Group('Test group', order=10)
     cmd = toga.Command(lambda x: print('Hello World'),
                        label='test',
                        tooltip='test command',
                        shortcut='t',
                        icon='icons/none.png',
                        group=grp,
                        section=1,
                        order=1,
                        factory=toga_dummy.factory)
     retur_val = cmd.bind(factory=toga_dummy.factory)
     self.assertEqual(retur_val, cmd._impl)
Exemple #23
0
 def test_cmdset_iter(self):
     test_widget = toga.Widget(factory=toga_dummy.factory)
     cs = toga.CommandSet(test_widget)
     grp = toga.Group('Test group', order=10)
     cmd = toga.Command(lambda x: print('Hello World'),
                        label='test',
                        tooltip='test command',
                        shortcut='t',
                        icon='icons/none.png',
                        group=grp,
                        section=1,
                        order=1,
                        factory=toga_dummy.factory)
     cs.add(cmd)
     self.assertEqual(list(cs), [cmd])
Exemple #24
0
 def test_cmdset_add(self):
     self.changed = False
     test_widget = toga.Widget(factory=toga_dummy.factory)
     cs = toga.CommandSet(test_widget, on_change=self._changed)
     grp = toga.Group('Test group', order=10)
     cmd = toga.Command(lambda x: print('Hello World'),
                        label='test',
                        tooltip='test command',
                        shortcut='t',
                        icon='icons/none.png',
                        group=grp,
                        section=1,
                        order=1,
                        factory=toga_dummy.factory)
     cs.add(cmd)
     self.assertTrue(self.changed)
Exemple #25
0
 def test_command_enabler(self):
     grp = toga.Group('Test group', order=10)
     cmd = toga.Command(
         lambda x: print('Hello World'),
         label='test',
         tooltip='test command',
         shortcut='t',
         icon='icons/none.png',
         group=grp,
         section=1,
         order=1,
         factory=toga_dummy.factory,
     )
     cmd.bind(toga_dummy.factory)
     cmd.enabled = False
     self.assertActionPerformedWith(cmd, 'set enabled', value=False)
     cmd.enabled = True
     self.assertActionPerformedWith(cmd, 'set enabled', value=True)
Exemple #26
0
    def __init__(self):
        resource_dir = os.path.dirname(
            os.path.dirname(os.path.dirname(__file__)))
        super().__init__(
            'Hera',
            document_types={'ipynb': Notebook},
        )
        os.environ['PIP_TARGET'] = str(self.paths.data / 'pkgs')
        sys.path.append(str(self.paths.data / 'pkgs'))
        os.environ['PYTHONPATH'] += ':' + str(self.paths.data / 'pkgs')
        print(os.environ['PYTHONPATH'])

        cmd1 = toga.Command(install_dependencies,
                            label='Install packages',
                            tooltip='Installs some helpful packages',
                            shortcut=toga.Key.MOD_1 + 'i',
                            icon='icons/pretty.png',
                            group=toga.Group.FILE,
                            section=0)

        self.commands.add(cmd1)
Exemple #27
0
    def test_command_enabler(self):
        test_widget = toga.Widget(factory=toga_dummy.factory)
        grp = toga.Group('Test group', order=10)
        cmd = toga.Command(
            lambda x: print('Hello World'),
            label='test',
            tooltip='test command',
            shortcut='t',
            icon='icons/none.png',
            group=grp,
            section=1,
            order=1,
            factory=toga_dummy.factory,
        )
        cmd._widgets.append(test_widget)
        cmd._widgets[0]._impl = Mock()
        cmd.enabled = False
        self.assertEqual(cmd._enabled, False)

        for widget in cmd._widgets:
            self.assertEqual(widget.enabled, False)
Exemple #28
0
    def startup(self):
        self.main_window = toga.MainWindow(title=self.name, size=(720, 580))
        self.ScrollContainer = toga.ScrollContainer()

        plot_box = toga.Box()

        button = toga.Button('Play',
                             on_press=self.playback,
                             style=Pack(width=100))

        GenerateSpectrum(self.filename)
        image_from_path = toga.Image('Figure_temp.png')
        imageview_from_path = toga.ImageView(image_from_path)
        imageview_from_path.style.update(height=480)
        imageview_from_path.style.update(width=640)
        plot_box.add(imageview_from_path)

        self.things = toga.Group('File')

        cmdOpen = toga.Command(self.actionOpenFileDialog,
                               label='Open',
                               tooltip='Open Audio File',
                               group=self.things)

        self.commands.add(cmdOpen)

        # Label to show responses.
        self.label = toga.Label('Ready.')

        # Outermost box
        outer_box = toga.Box(children=[self.label, button, plot_box],
                             style=Pack(flex=1,
                                        direction=COLUMN,
                                        alignment=CENTER,
                                        padding=10))

        # Add the content on the main window
        self.main_window.content = outer_box

        self.main_window.show()
Exemple #29
0
    def startup(self):
        play_group = toga.Group('Play', order=31)
        view_group = toga.Group('View', order=32)

        self.commands.add(
            toga.Command(self.reload,
                         label='Reload slide deck',
                         shortcut=toga.Key.MOD_1 + 'r',
                         group=toga.Group.FILE,
                         section=1), )
        self.commands.add(
            toga.Command(
                self.play,
                label='Play slideshow',
                shortcut=toga.Key.MOD_1 + 'p',
                group=play_group,
                section=0,
                order=0,
            ),
            toga.Command(
                self.reset_timer,
                label='Reset timer',
                shortcut=toga.Key.MOD_1 + 't',
                group=play_group,
                section=0,
                order=1,
            ),
            toga.Command(
                self.next_slide,
                label='Next slide',
                shortcut=toga.Key.RIGHT,
                group=play_group,
                section=1,
                order=0,
            ),
            toga.Command(
                self.previous_slide,
                label='Previous slide',
                shortcut=toga.Key.LEFT,
                group=play_group,
                section=1,
                order=1,
            ),
            toga.Command(
                self.first_slide,
                label='First slide',
                shortcut=toga.Key.HOME,
                group=play_group,
                section=1,
                order=2,
            ),
            toga.Command(
                self.last_slide,
                label='Last slide',
                shortcut=toga.Key.END,
                group=play_group,
                section=1,
                order=3,
            ),
        )
        self.commands.add(
            toga.Command(
                self.switch_screens,
                label='Switch screens',
                shortcut=toga.Key.MOD_1 + toga.Key.TAB,
                group=view_group,
            ),
            toga.Command(
                self.change_aspect_ratio,
                label='Change aspect ratio',
                shortcut=toga.Key.MOD_1 + 'a',
                group=view_group,
            ),
        )
Exemple #30
0
def build(app):
    brutus_icon = "icons/brutus"
    cricket_icon = "icons/cricket-72.png"

    data = [('root%s' % i, 'value %s' % i) for i in range(1, 100)]

    left_container = toga.Table(headings=['Hello', 'World'], data=data)

    right_content = toga.Box(style=Pack(direction=COLUMN, padding_top=50))

    for b in range(0, 10):
        right_content.add(
            toga.Button('Hello world %s' % b,
                        on_press=button_handler,
                        style=Pack(width=200, padding=20)))

    right_container = toga.ScrollContainer(horizontal=False)

    right_container.content = right_content

    split = toga.SplitContainer()

    # The content of the split container can be specified as a simple list:
    #    split.content = [left_container, right_container]
    # but you can also specify "weight" with each content item, which will
    # set an initial size of the columns to make a "heavy" column wider than
    # a narrower one. In this example, the right container will be twice
    # as wide as the left one.
    split.content = [(left_container, 1), (right_container, 2)]

    # Create a "Things" menu group to contain some of the commands.
    # No explicit ordering is provided on the group, so it will appear
    # after application-level menus, but *before* the Command group.
    # Items in the Things group are not explicitly ordered either, so they
    # will default to alphabetical ordering within the group.
    things = toga.Group('Things')
    cmd0 = toga.Command(action0,
                        label='Action 0',
                        tooltip='Perform action 0',
                        icon=brutus_icon,
                        group=things)
    cmd1 = toga.Command(action1,
                        label='Action 1',
                        tooltip='Perform action 1',
                        icon=brutus_icon,
                        group=things)
    cmd2 = toga.Command(action2,
                        label='Action 2',
                        tooltip='Perform action 2',
                        icon=toga.Icon.TOGA_ICON,
                        group=things)

    # Commands without an explicit group end up in the "Commands" group.
    # The items have an explicit ordering that overrides the default
    # alphabetical ordering
    cmd3 = toga.Command(action3,
                        label='Action 3',
                        tooltip='Perform action 3',
                        shortcut=toga.Key.MOD_1 + 'k',
                        icon=cricket_icon,
                        order=3)

    # Define a submenu inside the Commands group.
    # The submenu group has an order that places it in the parent menu.
    # The items have an explicit ordering that overrides the default
    # alphabetical ordering.
    sub_menu = toga.Group("Sub Menu", parent=toga.Group.COMMANDS, order=2)
    cmd5 = toga.Command(action5,
                        label='Action 5',
                        tooltip='Perform action 5',
                        order=2,
                        group=sub_menu)
    cmd6 = toga.Command(action6,
                        label='Action 6',
                        tooltip='Perform action 6',
                        order=1,
                        group=sub_menu)

    def action4(widget):
        print("CALLING Action 4")
        cmd3.enabled = not cmd3.enabled

    cmd4 = toga.Command(action4,
                        label='Action 4',
                        tooltip='Perform action 4',
                        icon=brutus_icon,
                        order=1)

    # The order in which commands are added to the app or the toolbar won't
    # alter anything. Ordering is defined by the command definitions.
    app.commands.add(cmd1, cmd0, cmd6, cmd4, cmd5, cmd3)
    app.main_window.toolbar.add(cmd1, cmd3, cmd2, cmd4)

    return split