示例#1
0
    def _installed_section(self) -> toga.Widget:
        desc = "Choose directories for installed games lookup. The lookup is based on child directory names."
        description = toga.Label(desc,
                                 style=Pack(font_size=self.TEXT_SIZE_BIG,
                                            padding_bottom=12))
        if IS_MAC:
            desc_os = "If nothing selected, '/Applications' will be used."
        if IS_WINDOWS:
            desc_os = "e.g. 'C:/Humble' to detect 'C:/Humble/Torchlight/torch.exe' ('Torchlight' matches game name)."
        description_os = toga.Label(desc_os,
                                    style=Pack(font_size=self.TEXT_SIZE_BIG,
                                               padding_bottom=12))

        self._paths_table = OneColumnTable(
            'Path', data=[str(p) for p in self._cfg.installed.search_dirs])

        select_btn = toga.Button('Add path', on_press=self._add_path)
        select_btn.style.flex = 1
        select_btn.style.padding_bottom = 4
        self._remove_btn = toga.Button('Remove path',
                                       on_press=self._remove_paths,
                                       enabled=self._paths_table.not_empty)
        self._remove_btn.style.flex = 1
        config_panel = toga.Box(children=[select_btn, self._remove_btn])
        config_panel.style.direction = 'row'
        config_panel.style.padding_top = 15

        paths_container = toga.Box(children=[
            description, description_os, self._paths_table, config_panel
        ])
        paths_container.style.direction = 'column'
        return paths_container
示例#2
0
    def __init__(self, **kwargs):
        """Initialize box."""
        super().__init__(**kwargs, style=Pack(direction=COLUMN))

        self.fitting_function_box = FittingFunctionBox(
            on_fitting_function_load=(
                lambda widget: self.window.update_parameters_options_boxes(self)
            )
        )
        self.add(self.fitting_function_box)

        self.parameters_boxes = EddingtonBox(
            children=[self.build_parameters_box()],
            style=Pack(direction=COLUMN, padding_left=TAB_PADDING),
        )
        self.add(self.parameters_boxes)

        self.add_parameters_button = toga.Button(
            "+", on_press=lambda widget: self.add_parameters(), enabled=False
        )
        self.remove_parameters_button = toga.Button(
            "-", on_press=lambda widget: self.remove_parameters(), enabled=False
        )
        self.add(
            EddingtonBox(
                children=[self.add_parameters_button, self.remove_parameters_button],
                style=Pack(padding_left=TAB_PADDING),
            )
        )
示例#3
0
    def startup(self):
        # Create Launcher
        self.__launcher = Launcher(self.__airflow_home_default)

        # Create a main window with a name matching the app
        self.main_window = toga.MainWindow(title=self.name, size=(250, 100))

        # Create a main content box
        main_box = toga.Box()
        main_box.style.update(direction=ROW, padding=20)

        # Add load button
        load_button = toga.Button("Load", on_press=self.load)
        load_button.style.padding = 25
        main_box.add(load_button)

        # Add unload button
        unload_button = toga.Button("Unload", on_press=self.unload)
        unload_button.style.padding = 25
        main_box.add(unload_button)

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

        # Show the main window
        self.main_window.show()
示例#4
0
    def startup(self):
        '''Main menu box'''
        self.commands = toga.CommandSet(None)
        self.main_box = toga.Box(style=Pack(direction=ROW, padding=5))
        self.create_spell_button = toga.Button('Create a spell',
                                               on_press=self.open_create_spell,
                                               style=Pack(padding=5))

        self.advance_day = toga.Button('End day',
                                       on_press=self.end_day,
                                       style=Pack(padding=5))

        self.money_available = 10000

        self.money_display = toga.Label('money available: $' +
                                        str(self.money_available))
        '''End main menu box'''
        '''Spell creator box'''
        '''End spell creator box'''

        self.main_box.add(self.create_spell_button)
        self.main_box.add(self.advance_day)
        self.main_box.add(self.money_display)

        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = self.main_box
        self.main_window.show()
示例#5
0
    def startup(self):

        main_box = toga.Box(style=Pack(direction=COLUMN))

        name_label = toga.Label("Your name: ", style=Pack(padding=(0, 5)))
        self.name_input = toga.TextInput(style=Pack(flex=1))
        self.display_score = toga.TextInput(style=Pack(flex=1), readonly=True)

        name_box = toga.Box(style=Pack(direction=ROW, padding=5))
        name_box.add(name_label)
        name_box.add(self.name_input)

        button_1 = toga.Button("Team A",
                               on_press=self.score_for_team_a,
                               style=Pack(padding=5))

        button_2 = toga.Button("Team B",
                               on_press=self.score_for_team_b,
                               style=Pack(padding=5))
        button_3 = toga.Button("Create Match",
                               on_press=self.create_match,
                               style=Pack(padding=5))

        main_box.add(name_box)
        main_box.add(button_1)
        main_box.add(button_2)
        main_box.add(button_3)
        main_box.add(self.display_score)

        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = main_box
        self.main_window.show()
示例#6
0
    def startup(self):
        self.main_window = toga.MainWindow(title=self.name)

        self.multiline_input = toga.MultilineTextInput(
            placeholder='Enter text here...',
            initial='Initial value',
            style=Pack(flex=1))

        button_toggle_enabled = toga.Button(
            'Toggle enabled',
            on_press=self.enable_toggle_pressed,
            style=Pack(flex=1))
        button_toggle_readonly = toga.Button(
            'Toggle readonly',
            on_press=self.readonly_toggle_pressed,
            style=Pack(flex=1))
        button_clear = toga.Button('Clear',
                                   on_press=self.clear_pressed,
                                   style=Pack(flex=1))
        btn_box = toga.Box(children=[
            button_toggle_enabled, button_toggle_readonly, button_clear
        ],
                           style=Pack(direction=ROW, padding=10))

        outer_box = toga.Box(children=[btn_box, self.multiline_input],
                             style=Pack(direction=COLUMN, padding=10))

        self.main_window.content = outer_box
        self.main_window.show()
示例#7
0
    def startup(self):
        # Create Launcher
        self.__launcher = Launcher(os.environ.get("AIRFLOW_HOME"))
        self.__launcher.configure_macos_app()

        # Create a main window with a name matching the app
        self.main_window = toga.MainWindow(title=self.name, size=(250, 100))

        # Create a main content box
        main_box = toga.Box()
        main_box.style.update(direction=ROW, padding=20)

        # Add load button
        load_button = toga.Button("Load", on_press=self.load)
        load_button.style.padding = 25
        main_box.add(load_button)

        # Add unload button
        unload_button = toga.Button("Unload", on_press=self.unload)
        unload_button.style.padding = 25
        main_box.add(unload_button)

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

        # Show the main window
        self.main_window.show()
示例#8
0
文件: app.py 项目: ztangaj/toga
    def startup(self):
        self.main_window = toga.MainWindow(title=self.name)
        self.top_label = toga.Label('www is loading |',
                                    style=Pack(flex=1, padding_left=10))
        self.math_button = toga.Button("2 + 2? ", on_press=self.do_math_in_js)
        self.mutate_page_button = toga.Button("mutate page!",
                                              on_press=self.mutate_page)
        self.set_content_button = toga.Button("set content!",
                                              on_press=self.set_content)
        self.set_agent_button = toga.Button("set agent!",
                                            on_press=self.set_agent)
        self.top_box = toga.Box(children=[
            self.math_button,
            self.mutate_page_button,
            self.set_content_button,
            self.set_agent_button,
            self.top_label,
        ],
                                style=Pack(flex=0, direction=ROW))
        self.webview = toga.WebView(url='https://beeware.org/',
                                    on_key_down=self.on_webview_button_press,
                                    on_webview_load=self.on_webview_load,
                                    style=Pack(flex=1))

        box = toga.Box(children=[
            self.top_box,
            self.webview,
        ],
                       style=Pack(flex=1, direction=COLUMN))

        self.main_window.content = box
        self.main_window.show()
示例#9
0
    def __init__(self, on_choose_record):
        """Initialize box."""
        super().__init__()
        self.__sheet_selection_enabled = False
        self.on_input_file_change = None
        self.on_csv_read = None
        self.on_excel_read = None
        self.on_select_excel_file = None

        self.__input_file_path = toga.TextInput(readonly=True,
                                                style=Pack(flex=1))
        self.__select_file_button = toga.Button(
            label="Choose file",
            on_press=self.select_file,
            style=Pack(padding_left=SMALL_PADDING),
        )
        self.add(
            toga.Label(text="Input file:"),
            self.__input_file_path,
            self.__select_file_button,
            toga.Button(
                label="Choose records",
                on_press=on_choose_record,
                style=Pack(padding_left=SMALL_PADDING),
            ),
        )

        self.__sheet_label = toga.Label(text="Sheet:")
        self.__sheet_selection = toga.Selection(on_select=self.select_sheet)
示例#10
0
    def startup(self):
        self.word_input = toga.PasswordInput(style=Pack(flex=1, padding=5))
        self.new_game = toga.Button('New Game',
                                    on_press=self.new_game_handler,
                                    style=Pack(width=100, padding=5))
        self.give_up = toga.Button('Give Up',
                                   on_press=self.give_up_handler,
                                   style=Pack(width=100, padding=5))
        self.start = toga.Button('Start',
                                 on_press=self.start_game_handler,
                                 style=Pack(width=50, padding=5))
        self.buttons_box = toga.Box(children=[
            self.new_game, self.give_up, self.word_input, self.start
        ])
        self.buttons_box.remove(self.word_input)
        print(self.buttons_box.children)

        self.tree_image = toga.ImageView(toga.Image(IMAGES[0]))
        self.tree_image.style.update(height=400)
        self.tree_image.style.update(width=400)

        start_box = toga.Box(children=[self.tree_image, self.buttons_box])
        # start_box.add(tree_image)
        # start_box.add(buttons_box)
        start_box.style.update(direction=COLUMN)
        start_box.style.update(alignment=CENTER)

        self.main_window = toga.MainWindow(title=self.name)

        self.main_window.content = start_box
        self.main_window.show()
示例#11
0
    def startup(self):
        self.main_window = toga.MainWindow(title=self.name)  #, ))
        self.outer_box = toga.Box(style=Pack(flex=1))
        self.outer_box.style.update(direction=COLUMN, alignment=RIGHT)

        self.choose_button = toga.Button('Random Game',
                                         on_press=self.decide_game,
                                         style=Pack(alignment=CENTER,
                                                    flex=1,
                                                    padding=10))
        self.attack_button = toga.Button('Attack Game',
                                         on_press=self.decide_attack_game,
                                         style=Pack(alignment=CENTER,
                                                    flex=1,
                                                    padding=10))
        self.balanced_button = toga.Button('Balanced Game',
                                           on_press=self.decide_balanced_game,
                                           style=Pack(alignment=CENTER,
                                                      flex=1,
                                                      padding=10))
        self.outer_box.add(self.choose_button)
        self.outer_box.add(self.attack_button)
        self.outer_box.add(self.balanced_button)
        # initializing the space
        self.scroller = toga.ScrollContainer(content=self.outer_box)
        self.init_games()
        self.split = toga.SplitContainer()
        self.split.content = [self.scroller, self.game_dashboard]

        # image from local path
        # We set the style width/height parameters for this one
        self.main_window.content = self.split
        self.main_window.show()
示例#12
0
def build(app):
    def on_load(widget):
        print('Finished loading!')
        print(widget.dom)

    def on_key(event, flag):
        print('Key down: ', event, ' Flag: ', flag)

    webview = toga.WebView(on_key_down=on_key,
                           on_webview_load=on_load,
                           style=CSS(flex=1))
    url_input = toga.TextInput(initial='https://github.com/',
                               style=CSS(flex=1, margin=5))

    def load_page(widget):
        print('loading: ', url_input.value)
        webview.url = url_input.value

    def print_dom(widget):
        print(webview.dom)

    box = toga.Box(children=[
        toga.Box(children=[
            url_input,
            toga.Button('Go', on_press=load_page, style=CSS(width=50)),
        ],
                 style=CSS(flex_direction='row', padding_top=25)), webview,
        toga.Box(children=[toga.Button('Print DOM', on_press=print_dom)])
    ],
                   style=CSS(flex_direction='column'))

    webview.url = url_input.value

    # Show the main window
    return box
示例#13
0
    def startup(self):

        main_box = toga.Box(style=Pack(direction=COLUMN))

        name_label = toga.Label('Test Packet: ', style=Pack(padding=(0, 5)))
        self.test_packet = toga.TextInput(style=Pack(flex=1))

        name_box = toga.Box(style=Pack(direction=ROW, padding=5))
        name_box.add(name_label)
        name_box.add(self.test_packet)

        button = toga.Button('Send Test Packet',
                             on_press=self.send_packet,
                             style=Pack(padding=5))
        button1 = toga.Button('Toggle GPIO C0',
                              on_press=self.toggle_gpio,
                              style=Pack(padding=5))

        main_box.add(name_box)
        main_box.add(button)
        main_box.add(button1)

        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = main_box
        self.main_window.show()
示例#14
0
    def startup(self):
        self.terms = []
        main_box = toga.Box(style=Pack(direction=COLUMN))

        term_label = toga.Label('Enter term(s): ', style=Pack(padding=(0, 5)))
        self.term_input = toga.TextInput(style=Pack(flex=1))

        term_box = toga.Box(style=Pack(direction=ROW, padding=5))
        term_box.add(term_label)
        term_box.add(self.term_input)

        term_button = toga.Button('Add term',
                                  on_press=self.term_list,
                                  style=Pack(padding=5))

        fetch_button = toga.Button('Fetch transcripts',
                                   on_press=self.hydra_fetch,
                                   style=Pack(padding=5))

        main_box.add(term_box)
        main_box.add(term_button)
        main_box.add(fetch_button)

        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = main_box
        self.main_window.show()
示例#15
0
    def startup(self):
        # Main window of the application with title and size
        self.main_window = toga.MainWindow(title=self.name, size=(500, 500))

        # the user may change the value with +/- buttons
        self.progress_adder = toga.ProgressBar()

        # the user may switch between "running" mode and a set value
        self.progress_runner = toga.ProgressBar(max=None)

        # set up common styles
        label_style = Pack(flex=1, padding_right=24)
        row_box_style = Pack(direction=ROW, padding=24)
        col_box_style = Pack(direction=COLUMN, padding=24)

        # Add the content on the main window
        self.main_window.content = toga.Box(style=col_box_style, children=[
            toga.Box(style=col_box_style, children=[
                toga.Label("Use the +/- buttons to change the progress",
                           style=label_style),

                self.progress_adder,

                toga.Box(children=[
                    toga.Button("+", on_press=self.increase_progress,
                                style=Pack(flex=1)),
                    toga.Button("-", on_press=self.decrease_progress,
                                style=Pack(flex=1)),
                ]),

                toga.Switch("Toggle running mode", on_toggle=self.toggle_running)
            ]),

            toga.Box(style=row_box_style, children=[
                toga.Label("default ProgressBar", style=label_style),
                toga.ProgressBar(),
            ]),

            toga.Box(style=row_box_style, children=[
                toga.Label("disabled ProgressBar", style=label_style),
                toga.ProgressBar(max=None,  running=False),
            ]),

            toga.Box(style=row_box_style, children=[
                toga.Label("indeterminate ProgressBar", style=label_style),
                toga.ProgressBar(max=None,  running=True),
            ]),

            toga.Box(style=row_box_style, children=[
                toga.Label("determinate ProgressBar", style=label_style),
                toga.ProgressBar(max=1, running=False, value=0.5),
            ]),

            toga.Box(style=row_box_style, children=[
                toga.Label("running determinate ProgressBar", style=label_style),
                toga.ProgressBar(max=1, running=True, value=0.5),
            ]),
        ])

        self.main_window.show()
示例#16
0
    def results_pane(self):
        results_pane = toga.OptionContainer(style=Pack(width=280, padding_left=20))

        self.qr_image = toga.ImageView(id='qr', image=None, style=Pack(width=250, height=250, padding_bottom=10))
        
        self.save_qr_button = toga.Button('Save QR', on_press=self.save_qr ,style=Pack(alignment=CENTER, width=250))

        self.qr_box = toga.Box(
            children=[self.qr_image, self.save_qr_button],
            style=Pack(direction=COLUMN, padding=10, width=270)
            )
        results_pane.add('QR Code', self.qr_box)

        self.xmp_text = toga.MultilineTextInput(
            style=Pack(width=270, height=350, padding=5)
            )
        self.xmp_button = toga.Button(
            'Save XMP',
            on_press=self.save_xmp,
            style=Pack(width=250, alignment=CENTER)
            )
        self.xmp_box = toga.Box(
            children=[self.xmp_text, self.xmp_button],
            style=Pack(direction=COLUMN)
        )
        results_pane.add('XMP', self.xmp_box)
        return results_pane
示例#17
0
def build(app):
    data = []
    for x in range(5):
        data.append([str(x) for x in range(5)])

    label = toga.Label('No row selected.')

    def selection_handler(widget, row):
        label.text = 'You selected row: {}'.format(row) if row is not None else 'No row selected'

    table = toga.Table(headings=['heading_{}'.format(x) for x in range(5)],
                       data=data,
                       style=CSS(flex=1),
                       on_select=selection_handler)

    def insert_handler(widget):
        table.data.insert(0, [str(round(random() * 100)) for _ in range(5)])
        table._impl.refresh()
        print('Rows', len(table.data.data))

    def delete_handler(widget):
        if len(table.data.data) > 0:
            table.data.remove(table.data.data[0])
            table._impl.refresh()
        else:
            print('Table is empty!')

    btn_style = CSS(flex=1)
    btn_insert = toga.Button('Insert Row', on_press=insert_handler, style=btn_style)
    btn_delete = toga.Button('Delete Row', on_press=delete_handler, style=btn_style)
    btn_box = toga.Box(children=[btn_insert, btn_delete], style=CSS(flex_direction='row'))

    box = toga.Box(children=[table, btn_box, label], style=CSS(flex=1, flex_direction='column', padding=10))
    return box
示例#18
0
def build(app):
    item_set_1 = [
        'other selection 1', 'other selection 2', 'other selection 3',
        'new item 4'
    ]
    item_set_2 = ['selection 1', 'selection 2', 'selection 3']
    selection = toga.Selection(
        items=['selection 1', 'selection 2', 'selection 3'],
        style=CSS(margin=20))

    def swap_selection(widget):
        selection.items = item_set_2 if selection.items == item_set_1 else item_set_1

    def get_selection(widget):
        print(selection.value)

    def set_selection(widget):
        selection.value = 'selection 1'

    box = toga.Box(style=CSS(padding=20))
    box.add(selection)
    box.add(
        toga.Box(children=[
            toga.Button('Swap Items', on_press=swap_selection),
            toga.Button('Get Selected Item', on_press=get_selection),
            toga.Button('Set Selected Item', on_press=set_selection)
        ]))
    return box
示例#19
0
    def startup(self):
        self.db = {}
        self.root = None
        main_box = toga.Box(style=Pack(direction=COLUMN))

        self.pdf_tree = toga.Table(headings=['File'],
                                   data=[],
                                   on_double_click=self.rm_row,
                                   style=Pack(padding=5, width=250,
                                              height=600))

        self.select_btn = toga.Button('browse',
                                      on_press=self.select_cb,
                                      style=Pack(padding=5, width=120))

        self.merge_btn = toga.Button('merge',
                                     on_press=self.merge_cb,
                                     style=Pack(padding=5, width=120))

        info_panel = toga.Box(style=Pack(direction=ROW))
        info_panel.add(self.pdf_tree)

        button_panel = toga.Box(style=Pack(direction=ROW))
        button_panel.add(self.select_btn)
        button_panel.add(self.merge_btn)

        main_box.add(info_panel)
        main_box.add(button_panel)
        self.main_window = toga.MainWindow(title=self.formal_name,
                                           size=(250, 600))
        self.main_window.content = main_box
        self.main_window.show()
示例#20
0
    def openConfigWindow(self, widget):
        try:
            # self.inputsConfig = dict()
            self.config_box = toga.Box(style=Pack(direction=COLUMN))
            for i in packages.get_config_param():
                lbl = toga.Label('{}: {}'.format(i[1].capitalize(), i[3]))
                ti = toga.TextInput(style=Pack(flex=1))
                ti.value = i[2]
                self.config_box.add(lbl)
                self.config_box.add(ti)
                self.inputsConfig[i[0]] = ti

            config_box_btn = toga.Box(style=Pack(direction=ROW))
            returMainWindow = toga.Button('Return',
                                          on_press=self.openMainWindow,
                                          style=Pack(
                                              background_color='#FF6363',
                                              flex=1,
                                              height=36))
            defaultbtn = toga.Button('Default parameters',
                                     on_press=self.defaultConfig,
                                     style=Pack(background_color='#52de97',
                                                flex=1,
                                                height=36))
            logbtn = toga.Button('Registry',
                                 on_press=self.logReport,
                                 style=Pack(background_color='#52de97',
                                            flex=1,
                                            height=36))
            savebtn = toga.Button('Save',
                                  on_press=self.saveConfig,
                                  style=Pack(background_color='#52de97',
                                             flex=1,
                                             height=36))

            config_box_btn.add(returMainWindow)
            config_box_btn.add(logbtn)
            config_box_btn.add(defaultbtn)
            config_box_btn.add(savebtn)

            self.config_box.add(config_box_btn)

            self.main_box.remove(self.first_box)
            self.main_box.remove(self.web)
            self.main_box.remove(self.second_box)
            self.main_box.remove(self.downloadBtn)
            self.main_box.remove(self.openfolder)
            self.main_box.remove(self.donate)

            self.main_box.add(self.config_box)
            self.main_window.content = self.main_box

            self.main_window.show()
            # self.config_window = toga.Window(title='Config parameters', size=(900, 500))
            # self.config_window.content = config_box
            # self.config_window.show()
        except Exception as e:
            pass
示例#21
0
文件: app.py 项目: yconst/toga
    def startup(self):
        self.main_window = toga.MainWindow(title=self.name)

        # Label to show which row is currently selected.
        self.label = toga.Label('Ready.')

        # Data to populate the table.
        data = []
        for x in range(5):
            data.append(tuple(str(x) for x in range(5)))

        self.table1 = toga.Table(headings=headings,
                                 data=bee_movies[:4],
                                 style=Pack(flex=1),
                                 on_select=self.on_select_handler)

        self.table2 = toga.Table(headings=headings,
                                 data=self.table1.data,
                                 style=Pack(flex=1))

        tablebox = toga.Box(children=[self.table1, self.table2],
                            style=Pack(flex=1))

        # Buttons
        btn_style = Pack(flex=1)
        btn_insert = toga.Button('Insert Row',
                                 on_press=self.insert_handler,
                                 style=btn_style)
        btn_delete = toga.Button('Delete Row',
                                 on_press=self.delete_handler,
                                 style=btn_style)
        btn_clear = toga.Button('Clear Table',
                                on_press=self.clear_handler,
                                style=btn_style)
        btn_reset = toga.Button('Reset Table',
                                on_press=self.reset_handler,
                                style=btn_style)
        btn_toggle = toga.Button('Toggle Column',
                                 on_press=self.toggle_handler,
                                 style=btn_style)
        btn_box = toga.Box(children=[
            btn_insert, btn_delete, btn_clear, btn_reset, btn_toggle
        ],
                           style=Pack(direction=ROW))

        # Most outer box
        outer_box = toga.Box(children=[btn_box, tablebox, self.label],
                             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()
示例#22
0
def start():
    main_box = toga.Box()
    LoginB = toga.Button('Login', on_press=Login)
    SignupB = toga.Button('Signup', on_press=Signup)
    main_box.add(LoginB)
    main_box.add(SignupB)
    main_window = toga.MainWindow(title="formal_name")
    main_window.content = main_box
    main_window.show()
示例#23
0
def build(app):
    content_left = toga.Box(style=CSS(padding=20))
    content_right = toga.Box(style=CSS(padding=20))
    for _ in range(10):
        content_left.add(toga.Button('Button {}'.format(_)))
        content_right.add(toga.Button('Button {}'.format(_)))
    split_container = toga.SplitContainer(
        content=[content_left, content_right])
    return split_container
示例#24
0
 def _update_tab_box(self):
     self.tab_box.remove(*self.tab_box.children)
     for tab in self._tabs:
         select_button = toga.Button(
             tab.title, on_press=lambda _: self._focus_tab(tab))
         close_button = toga.Button("x",
                                    on_press=lambda _: self._close_tab(tab))
         box = toga.Box(children=[select_button, close_button])
         self.tab_box.add(box)
示例#25
0
文件: app.py 项目: ztangaj/toga
    def startup(self):
        # Set up main window
        self.main_window = toga.MainWindow(title=self.name)

        # Label to show responses.
        self.label = toga.Label('Ready.', style=Pack(padding_top=20))

        # Buttons
        btn_style = Pack(flex=1)
        btn_info = toga.Button('Info', on_press=self.action_info_dialog, style=btn_style)
        btn_question = toga.Button('Question', on_press=self.action_question_dialog, style=btn_style)
        btn_confirm = toga.Button('Confirm', on_press=self.action_confirm_dialog, style=btn_style)
        btn_error = toga.Button('Error', on_press=self.action_error_dialog, style=btn_style)
        btn_open = toga.Button('Open File', on_press=self.action_open_file_dialog, style=btn_style)
        btn_open_multi = toga.Button(
            'Open File (Multiple)',
            on_press=self.action_open_file_dialog_multi,
            style=btn_style
        )
        btn_save = toga.Button('Save File', on_press=self.action_save_file_dialog, style=btn_style)
        btn_select = toga.Button('Select Folder', on_press=self.action_select_folder_dialog, style=btn_style)
        btn_select_multi = toga.Button(
            'Select Folders',
            on_press=self.action_select_folder_dialog_multi,
            style=btn_style
        )

        btn_clear = toga.Button('Clear', on_press=self.do_clear, style=btn_style)

        # Outermost box
        box = toga.Box(
            children=[
                btn_info,
                btn_question,
                btn_confirm,
                btn_error,
                btn_open,
                btn_save,
                btn_select,
                btn_select_multi,
                btn_open_multi,
                btn_clear,
                self.label
            ],
            style=Pack(
                flex=1,
                direction=COLUMN,
                padding=10
            )
        )

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

        # Show the main window
        self.main_window.show()
示例#26
0
文件: app.py 项目: vsergeyev/toga
    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()
    def startup(self):
        self.main_window = toga.MainWindow(title=self.name)
        self.button = toga.Button('add_background_task',
                                  on_press=self.button_handler)
        self.button2 = toga.Button('async_handler',
                                   on_press=self.button2_handler)

        main_box = toga.Box(children=[self.button, self.button2])
        self.main_window.content = main_box
        self.main_window.show()
示例#28
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.yellow_button = toga.Button(
            label="Set yellow color",
            on_press=self.set_yellow_color,
            style=Pack(background_color=YELLOW),
        )
        self.inner_box = toga.Box(
            style=Pack(direction=ROW),
            children=[
                toga.Button(
                    label="Set red color",
                    on_press=self.set_red_color,
                    style=Pack(background_color=RED),
                ),
                self.yellow_button,
                toga.Button(
                    label="Set blue color",
                    on_press=self.set_blue_color,
                    style=Pack(background_color=BLUE),
                ),
                toga.Button(
                    label="Set green color",
                    on_press=self.set_green_color,
                    style=Pack(background_color=GREEN),
                ),
                toga.Button(
                    label="Reset color",
                    on_press=self.reset_color,
                    style=Pack(background_color=WHITE),
                ),
            ],
        )
        #  Create the outer box with 2 rows
        self.outer_box = toga.Box(
            style=Pack(direction=COLUMN, flex=1),
            children=[
                self.inner_box,
                toga.Label(text="Hello to my world!", style=Pack(text_align=CENTER)),
                toga.Switch(
                    "Enable yellow", is_on=True, on_toggle=self.toggle_yellow_button
                ),
            ],
        )

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

        # Show the main window
        self.main_window.show()
示例#29
0
文件: app.py 项目: xmonader/toga
    def startup(self):
        self.main_window = toga.MainWindow(title=self.name)

        self.multiline_input = toga.MultilineTextInput(
            placeholder='Enter text here...',
            initial='Initial value',
            style=Pack(flex=1),
            on_change=self.set_label
        )

        button_toggle_enabled = toga.Button(
            'Toggle enabled',
            on_press=self.enable_toggle_pressed,
            style=Pack(flex=1)
        )
        button_toggle_readonly = toga.Button(
            'Toggle readonly',
            on_press=self.readonly_toggle_pressed,
            style=Pack(flex=1)
        )
        button_add_content = toga.Button(
            'Add content',
            on_press=self.add_content_pressed,
            style=Pack(flex=1)
        )
        button_clear = toga.Button(
            'Clear',
            on_press=self.clear_pressed,
            style=Pack(flex=1)
        )
        btn_box = toga.Box(
            children=[
                button_toggle_enabled,
                button_toggle_readonly,
                button_add_content,
                button_clear,
            ],
            style=Pack(
                direction=ROW,
                padding=10
            )
        )
        self.label = toga.Label("Nothing has been written yet")

        outer_box = toga.Box(
            children=[btn_box, self.multiline_input, self.label],
            style=Pack(
                direction=COLUMN,
                padding=10
            )
        )

        self.main_window.content = outer_box
        self.main_window.show()
示例#30
0
    def startup(self):
        self.main_window = toga.MainWindow(self.name)
        self.main_window.app = self

        # Label to show which row is currently selected.
        self.label = toga.Label('Ready.')

        # Create two tables with custom data sources; the data source
        # of the second reads from the first.
        # The headings are also in a different order.
        self.table1 = toga.Table(headings=['Year', 'Title', 'Rating', 'Genre'],
                                 data=MovieSource(),
                                 style=CSS(flex=1),
                                 on_select=self.on_select_handler)

        self.table2 = toga.Table(headings=['Rating', 'Title', 'Year', 'Genre'],
                                 data=GoodMovieSource(self.table1.data),
                                 style=CSS(flex=1))

        # Populate the table
        for entry in bee_movies:
            self.table1.data.add(entry)

        tablebox = toga.Box(children=[self.table1, self.table2],
                            style=CSS(flex=1))

        # Buttons
        btn_style = CSS(flex=1)
        btn_insert = toga.Button('Insert Row',
                                 on_press=self.insert_handler,
                                 style=btn_style)
        btn_delete = toga.Button('Delete Row',
                                 on_press=self.delete_handler,
                                 style=btn_style)
        btn_clear = toga.Button('Clear Table',
                                on_press=self.clear_handler,
                                style=btn_style)
        btn_box = toga.Box(children=[btn_insert, btn_delete, btn_clear],
                           style=CSS(flex_direction='row'))

        # Most outer box
        outer_box = toga.Box(children=[btn_box, tablebox, self.label],
                             style=CSS(flex=1,
                                       flex_direction='column',
                                       padding=10,
                                       min_width=500,
                                       min_height=300))

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

        # Show the main window
        self.main_window.show()