Exemplo n.º 1
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)
Exemplo n.º 2
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
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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'))
Exemplo n.º 6
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)
Exemplo n.º 7
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])
Exemplo n.º 8
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)
Exemplo n.º 9
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)
Exemplo n.º 10
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
Exemplo n.º 11
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)
Exemplo n.º 12
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()
Exemplo n.º 13
0
def build(app):
    def installHandle(widget):
        import installer
        result_label.value = installer.full_install(package_input.value)

    #Ian Test code
    package_list = [{'Discord', 'Chat for Gamers'},
                    {'Google Chrome', 'Web Browser'},
                    {'Dropbox', 'Upload/Download Files'}]
    left_container = toga.Table(headings=['Package', 'Description'],
                                data=package_list)
    right_content = toga.Box(style=Pack(direction=COLUMN, padding_top=50))

    #Add content to right side
    packageBox = toga.Box()
    text_label = toga.Label('Package:')
    package_input = toga.TextInput()
    submit = toga.Button('Install Package', on_press=installHandle)
    packageBox.add(text_label)
    packageBox.add(package_input)
    packageBox.add(submit)
    resultBox = toga.Box()
    result_label = toga.TextInput(readonly=True)
    result_text = toga.Label('Status:')
    resultBox.add(result_text)
    resultBox.add(result_label)
    right_content.add(packageBox)
    right_content.add(resultBox)

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

    split = toga.SplitContainer()
    split.content = [left_container, right_container]
    things = toga.Group('Things')

    return split
Exemplo n.º 14
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,
            ),
        )
Exemplo n.º 15
0
Arquivo: app.py Projeto: obulat/toga
    def startup(self):
        brutus_icon_256 = "resources/brutus-256"
        cricket_icon_256 = "resources/cricket-256"
        tiberius_icon_256 = "resources/tiberius-256"

        # Set up main window
        self.main_window = toga.MainWindow(title=self.name)

        # Add commands
        print('adding commands')
        # 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(self.action0,
                            label='Action 0',
                            tooltip='Perform action 0',
                            icon=brutus_icon_256,
                            group=things)
        cmd1 = toga.Command(self.action1,
                            label='Action 1',
                            tooltip='Perform action 1',
                            icon=brutus_icon_256,
                            group=things)
        cmd2 = toga.Command(self.action2,
                            label='TB Action 2',
                            tooltip='Perform toolbar action 2',
                            icon=brutus_icon_256,
                            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(self.action3,
                            label='Action 3',
                            tooltip='Perform action 3',
                            shortcut=toga.Key.MOD_1 + 'k',
                            icon=cricket_icon_256,
                            group=toga.Group.COMMANDS,
                            order=4)

        # 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=1)
        cmd5 = toga.Command(
            self.action5,
            label='TB Action 5',
            tooltip='Perform toolbar action 5',
            order=2,
            group=sub_menu
        )  # there is deliberately no icon to show that a toolbar action also works with text
        cmd6 = toga.Command(self.action6,
                            label='Action 6',
                            tooltip='Perform action 6',
                            order=1,
                            icon=cricket_icon_256,
                            group=sub_menu)
        cmd7 = toga.Command(self.action7,
                            label='TB action 7',
                            tooltip='Perform toolbar action 7',
                            order=30,
                            icon=tiberius_icon_256,
                            group=sub_menu)

        def action4(widget):
            print("action 4")
            cmd3.enabled = not cmd3.enabled
            self.textpanel.value += 'action 4\n'

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

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

        # Buttons
        btn_style = Pack(flex=1)
        btn_do_stuff = toga.Button('Do stuff',
                                   on_press=self.do_stuff,
                                   style=btn_style)
        btn_clear = toga.Button('Clear',
                                on_press=self.do_clear,
                                style=btn_style)
        btn_box = toga.Box(children=[btn_do_stuff, btn_clear],
                           style=Pack(direction=ROW))

        self.textpanel = toga.MultilineTextInput(readonly=False,
                                                 style=Pack(flex=1),
                                                 placeholder='Ready.')

        # Outermost box
        outer_box = toga.Box(children=[btn_box, self.textpanel],
                             style=Pack(flex=1, direction=COLUMN, padding=10))

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

        # Show the main window
        self.main_window.show()
Exemplo n.º 16
0
    def startup(self):
        # Window class
        #   Main window of the application with title and size
        self.main_window = toga.MainWindow(self.name, size=(640, 480))
        self.main_window.app = self

        list_data = []
        for i in range(0, 100):
            list_data.append(('root%s' % i, 'value%s' % i))

        left_container = toga.Table(['Hello', 'World'],
                                    data=list_data,
                                    on_select=tableSelected)

        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]

        things = toga.Group('Things')

        cmd0 = toga.Command(action1,
                            label='Action 0',
                            tooltip='Perform action 0',
                            icon=toga.Icon('icons/brutus.icns'),
                            group=things)
        cmd1 = toga.Command(action1,
                            label='Action 1',
                            tooltip='Perform action 1',
                            icon=toga.Icon('icons/brutus.icns'),
                            group=things)
        cmd2 = toga.Command(action2,
                            label='Action 2',
                            tooltip='Perform action 2',
                            icon=toga.Icon.TIBERIUS_ICON,
                            group=things)
        cmd3 = toga.Command(action3,
                            label='Action 3',
                            tooltip='Perform action 3',
                            shortcut='k',
                            icon=toga.Icon('icons/cricket-72.png'))

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

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

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

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

        # Show the main window
        self.main_window.show()
Exemplo n.º 17
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
Exemplo n.º 18
0
import toga

PARENT_GROUP1 = toga.Group("P", 1)
CHILD_GROUP1 = toga.Group("C", order=2, parent=PARENT_GROUP1)
CHILD_GROUP2 = toga.Group("B", order=4, parent=PARENT_GROUP1)
PARENT_GROUP2 = toga.Group("O", 2)
CHILD_GROUP3 = toga.Group("A", 2, parent=PARENT_GROUP2)

A = toga.Command(None, "A", group=PARENT_GROUP2, order=1)
S = toga.Command(None, "S", group=PARENT_GROUP1, order=5)
T = toga.Command(None, "T", group=CHILD_GROUP2, order=2)
U = toga.Command(None, "U", group=CHILD_GROUP2, order=1)
V = toga.Command(None, "V", group=PARENT_GROUP1, order=3)
B = toga.Command(None, "B", group=CHILD_GROUP1, section=2, order=1)
W = toga.Command(None, "W", group=CHILD_GROUP1, order=4)
X = toga.Command(None, "X", group=CHILD_GROUP1, order=2)
Y = toga.Command(None, "Y", group=CHILD_GROUP1, order=1)
Z = toga.Command(None, "Z", group=PARENT_GROUP1, order=1)

COMMANDS_IN_ORDER = [Z, Y, X, W, B, V, U, T, S, A]
COMMANDS_IN_SET = [
    Z, toga.GROUP_BREAK,
    Y, X, W, toga.SECTION_BREAK, B, toga.GROUP_BREAK,
    V, toga.GROUP_BREAK,
    U, T, toga.GROUP_BREAK,
    S, toga.GROUP_BREAK,
    A,
]
Exemplo n.º 19
0
 def test_group_init_no_order(self):
     grp = toga.Group('label')
     self.assertEqual(grp.label, 'label')
     self.assertEqual(grp.order, 0)
Exemplo n.º 20
0
 def test_group_lt(self):
     grp1, grp2 = toga.Group('A'), toga.Group('B')
     self.assertTrue(toga.Group('A', 1) < toga.Group('A', 2))
     self.assertTrue(toga.Group('A') < toga.Group('B'))
Exemplo n.º 21
0
 def test_group_eq(self):
     self.assertEqual(toga.Group('A'), toga.Group('A'))
     self.assertEqual(toga.Group('A', 1), toga.Group('A', 1))
     self.assertNotEqual(toga.Group('A'), toga.Group('B'))
     self.assertNotEqual(toga.Group('A', 1), toga.Group('A', 2))
     self.assertNotEqual(toga.Group('A', 1), toga.Group('B', 1))
Exemplo n.º 22
0
def build(app):
    level1_icon = "icons/chicken-level1.png"
    level2_icon = "icons/cat-level2.png"
    level3_icon = "icons/fox-level3.png"
    level4_icon = "icons/lion-level4.png"
    level5_icon = "icons/tiger-level5.png"

    data = [(
        'Question1', 'Points Receive: 3 ',
        'Which 100-mile long waterway links the Mediterranean and the Red Sea?'
    ), ('Question2', 'Points Receive: 5', 'What is the capital of Kenya?'),
            ('Question3', 'Points Receive: 7',
             'The average of first 50 natural numbers is?'),
            ('Question4', 'Points Receive: 9',
             'The number of 3-digit numbers divisible by 6?'),
            ('Question5', 'Points Receive: 11',
             'Which is the second longest river in Africa?')]

    left_container = toga.Table(
        headings=['Questions', 'Points Per Question', 'Contents'], data=data)

    right_content = toga.Box(style=Pack(direction=COLUMN, padding_top=50))
    for b in range(1, 6):
        right_content.add(
            toga.Button('Answer %s' % b,
                        on_press=button_handler,
                        style=Pack(width=200, padding=20)))
        print("Answer number", b, "is :")
    right_container = toga.ScrollContainer(horizontal=False)

    right_container.content = right_content

    split = toga.SplitContainer()

    split.content = [left_container, right_container]

    levels = toga.Group('Levels')

    cmd0 = toga.Command(level1,
                        label='Level 1',
                        tooltip='Perform level 0',
                        icon=level1_icon,
                        group=levels)
    cmd1 = toga.Command(level2,
                        label='Level 2',
                        tooltip='Perform level 1',
                        icon=level2_icon,
                        group=levels)
    cmd2 = toga.Command(level3,
                        label='Level 3',
                        tooltip='Perform level 2',
                        icon=level3_icon,
                        group=levels)
    cmd3 = toga.Command(level4,
                        label='Level 4',
                        tooltip='Perform level 3',
                        shortcut=toga.Key.MOD_1 + 'k',
                        icon=level4_icon)

    cmd4 = toga.Command(level5,
                        label='Level 5',
                        tooltip='Perform level 4',
                        icon=level5_icon)

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

    return split
Exemplo n.º 23
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]

    things = toga.Group('Things')

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

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

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

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

    return split
Exemplo n.º 24
0
from travertino.constants import COLUMN

import toga
from toga.style import Pack

WIDGETS_GROUP = toga.Group("Widgets", order=2)


class ExampleFocusApp(toga.App):
    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),
Exemplo n.º 25
0
    def set_commands(self):
        """Add several Toga Command instances to the Toga CommandSet in
        ``self.commands``.

        This produces DativeTop's menu items (sometimes with keyboard
        shortcuts) and maps them to methods on this class.
        """
        self.commands = toga.CommandSet(self.factory)

        about_cmd = toga.Command(
            self.about_cmd,
            label='About DativeTop',
            group=toga.Group.APP,
            section=0)

        cut_cmd = toga.Command(
            self.cut_cmd,
            label='Cut',
            shortcut=toga.Key.MOD_1 + 'x',
            group=toga.Group.EDIT,
            section=0)

        copy_cmd = toga.Command(
            self.copy_cmd,
            label='Copy',
            shortcut=toga.Key.MOD_1 + 'c',
            group=toga.Group.EDIT,
            section=0)

        paste_cmd = toga.Command(
            self.paste_cmd,
            label='Paste',
            shortcut=toga.Key.MOD_1 + 'v',
            group=toga.Group.EDIT,
            section=0)

        select_all_cmd = toga.Command(
            self.select_all_cmd,
            label='Select All',
            shortcut=toga.Key.MOD_1 + 'a',
            group=toga.Group.EDIT,
            section=0)

        quit_cmd = toga.Command(
            self.quit_cmd,
            'Quit DativeTop',
            shortcut=toga.Key.MOD_1 + 'q',
            group=toga.Group.APP,
            section=sys.maxsize)

        visit_dative_in_browser_cmd = toga.Command(
            self.visit_dative_in_browser_cmd,
            label='Visit Dative in Browser',
            group=toga.Group.HELP,
            order=0)

        visit_old_in_browser_cmd = toga.Command(
            self.visit_old_in_browser_cmd,
            label='Visit OLD in Browser',
            group=toga.Group.HELP,
            order=1)

        visit_old_web_site_cmd = toga.Command(
            self.visit_old_web_site_cmd,
            label='Visit OLD Web Site',
            group=toga.Group.HELP,
            order=3)

        visit_dative_web_site_cmd = toga.Command(
            self.visit_dative_web_site_cmd,
            label='Visit Dative Web Site',
            group=toga.Group.HELP,
            order=2)

        reload_cmd = toga.Command(
            self.reload_cmd,
            label='Reload DativeTop',
            shortcut=toga.Key.MOD_1 + 'r',
            group=toga.Group.VIEW)

        reset_cmd = toga.Command(
            self.reset_dative_app_settings_cmd,
            label='Reset Dative',
            shortcut=toga.Key.MOD_1 + 'k',
            group=toga.Group.VIEW)

        view_dativetop_gui_cmd = toga.Command(
            self.view_dativetop_gui_cmd,
            label='DativeTop',
            shortcut=toga.Key.MOD_1 + 't',
            group=toga.Group.VIEW,
            order=2)

        view_dative_gui_cmd = toga.Command(
            self.view_dative_gui_cmd,
            label='Dative',
            shortcut=toga.Key.MOD_1 + 'd',
            group=toga.Group.VIEW,
            order=3)

        history_group = toga.Group('History', order=70)

        back_cmd = toga.Command(
            self.back_cmd,
            label='Back',
            shortcut=toga.Key.MOD_1 + '[',
            group=history_group)

        forward_cmd = toga.Command(
            self.forward_cmd,
            label='Forward',
            shortcut=toga.Key.MOD_1 + ']',
            group=history_group)

        self.commands.add(
            # DativeTop
            about_cmd,
            quit_cmd,
            # Edit
            cut_cmd,
            copy_cmd,
            paste_cmd,
            select_all_cmd,
            # View
            reload_cmd,
            reset_cmd,
            view_dativetop_gui_cmd,
            view_dative_gui_cmd,
            # History
            back_cmd,
            forward_cmd,
            # Help
            visit_dative_in_browser_cmd,
            visit_old_in_browser_cmd,
            visit_old_web_site_cmd,
            visit_dative_web_site_cmd,
        )
Exemplo n.º 26
0
from eddington_gui.boxes.parameters_box import ParametersBox
from eddington_gui.boxes.plot_configuration_box import PlotConfigurationBox
from eddington_gui.buttons.plot_button import PlotButton
from eddington_gui.buttons.save_figure_button import SaveFigureButton
from eddington_gui.consts import (
    FIGURE_WINDOW_SIZE,
    GITHUB_USER_NAME,
    MAIN_WINDOW_SIZE,
    NO_VALUE,
    SMALL_PADDING,
    FontSize,
)
from eddington_gui.window.explore_window import ExploreWindow
from eddington_gui.window.records_choice_window import RecordsChoiceWindow

PLOT_GROUP = toga.Group("Plot", order=2)


class EddingtonGUI(toga.App):  # pylint: disable=R0902,R0904
    """Main app instance."""

    input_file_box: InputFileBox
    fitting_function_box: FittingFunctionBox
    initial_guess_box: ParametersBox
    data_columns_box: DataColumnsBox
    plot_options_container: toga.OptionContainer
    output_box: OutputBox

    main_window: toga.Window
    plot_boxes: Dict[str, PlotConfigurationBox]
    can_plot_map: Dict[str, Callable[[], bool]]