Beispiel #1
0
    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()
Beispiel #2
0
    def startup(self):
        """
        Construct and show the Toga application.

        Usually, you would add your application to a main content box.
        We then create a main window (with a name matching the app), and
        show the main window.
        """
        self.license_data = SelectedLicense()

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

        self.top_container = toga.SplitContainer(
            direction=toga.SplitContainer.VERTICAL,
            style=Pack(height=320)
            )


        self.outer_container = toga.Box(
            children=[self.top_container, self.attribution_pane()],
            style=Pack(direction=COLUMN, padding=20)
            )

        self.top_container.content = [self.details_form(), self.results_pane()]

        self.main_window.content = self.outer_container
        self.main_window.show()
Beispiel #3
0
    def _setup_main_content(self):
        '''
        Sets up the main content area. It is a persistent GUI component
        '''

        # Create the output/viewer area on the right frame
        # Need to create this before the option container in the left
        # frame is created.
        self._setup_right_frame()

        # Create the tree/control area on the left frame
        self._setup_left_frame()

        # Weight the split container so 66% of the screen
        # is the details panel.
        self.split_main_container = toga.SplitContainer(
            content=[
                (self.tree_notebook, 33),
                (self.right_box, 66),
            ],
            style=Pack(flex=1)
        )
        # Main content area
        self.outer_box = toga.Box(
            children=[
                self.split_main_container,
                self.statusbar
            ],
            style=Pack(direction=COLUMN)
        )
        self.content = self.outer_box
Beispiel #4
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
Beispiel #5
0
    def startup(self):
        # Create a main window with a name matching the app
        self.main_window = toga.MainWindow(self.name)

        self.input = toga.TextInput(style=Pack(flex=1))
        self.avatar_type = toga.Selection(items=sorted(AVATAR_TYPES.keys()),
                                          style=Pack(padding_left=10),
                                          on_select=self.generate)
        self.button = toga.Button('Go!',
                                  style=Pack(padding_left=10),
                                  on_press=self.generate)

        input_box = toga.Box(
            children=[self.input, self.avatar_type, self.button],
            style=Pack(direction=ROW, padding=10, alignment=CENTER))

        self.avatar = toga.ImageView()

        # Create a main content box
        main_box = toga.Box(children=[input_box, self.avatar],
                            style=Pack(direction=COLUMN))

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

        # Show the main window
        self.main_window.show()
Beispiel #6
0
    def startup(self):
        main_box = toga.Box(style=Pack(direction=COLUMN))

        name_label = toga.Label(
            'Your name pls: ',
            style=Pack(padding=(0, 5))
        )
        self.name_input = 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.name_input)

        button = toga.Button(
            'Say Hello!',
            on_press=self.say_hello,
            style=Pack(padding=5)
        )

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

        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = main_box
        self.main_window.show()
Beispiel #7
0
    def __init__(self, **kwargs) -> None:
        super().__init__(title="Folder Selection", **kwargs)

        self.tree = toga.Tree(
            headings=["Name", "Included"],
            accessors=["name", "included"],
            style=Pack(flex=1),
            multiple_select=True,
        )

        self.dialog_buttons = DialogButtons(
            labels=["Update", "Cancel"],
            style=Pack(padding=(0, 20, 20, 20)),
        )
        self.dialog_buttons["Update"].enabled = False

        # Outermost box
        self.outer_box = toga.Box(
            children=[
                toga.Label(
                    "Please select which files and folders to sync.",
                    style=Pack(padding=20),
                ),
                self.tree,
                self.dialog_buttons,
            ],
            style=Pack(direction=COLUMN, flex=1, alignment=RIGHT),
        )

        # Add the content on the main window
        self.content = self.outer_box
Beispiel #8
0
 def __init__(self):
     """Initialize box."""
     logo_path = Path(__file__).parent.parent / "resources" / "eddington_gui.png"
     logo = toga.Image(str(logo_path))
     super(HeaderBox, self).__init__(
         alignment=TOP,
         children=[
             toga.Label(
                 text=f"Version: {__version__}",
                 style=Pack(
                     font_size=SMALL_FONT_SIZE, font_family=HEADER_FONT_FAMILY
                 ),
             ),
             toga.Box(style=Pack(flex=1)),
             toga.ImageView(
                 image=logo, style=Pack(height=LOGO_SIZE, width=LOGO_SIZE)
             ),
             toga.Box(style=Pack(flex=1)),
             toga.Label(
                 text=f"Author: {__author__}",
                 style=Pack(
                     font_size=SMALL_FONT_SIZE, font_family=HEADER_FONT_FAMILY
                 ),
             ),
         ],
     )
    def __init__(self, flex):
        """Initialize box."""
        super().__init__(style=Pack(direction=COLUMN, flex=flex))
        self.fitting_function_box = LineBox()
        self.fitting_function_box.add(toga.Label(text="Fitting function:"))
        self.fitting_function_selection = toga.Selection(
            on_select=self.load_select_fitting_function_name, )
        self.fitting_function_box.add(self.fitting_function_selection)
        self.fitting_function_syntax = toga.TextInput(
            readonly=True,
            style=Pack(flex=1,
                       padding_left=BIG_PADDING,
                       padding_right=BIG_PADDING),
        )
        self.fitting_function_box.add(self.fitting_function_syntax)
        self.load_module_button = toga.Button(label="Load module",
                                              on_press=self.load_module)
        self.fitting_function_box.add(self.load_module_button)
        self.add(self.fitting_function_box)

        self.polynomial_degree_title = toga.Label("Degree:")
        self.polynomial_degree_input = toga.NumberInput(
            min_value=1,
            max_value=5,
            default=1,
            on_change=lambda widget: self.set_polynomial_degree(),
        )

        self.update_fitting_function_options()
Beispiel #10
0
    def startup(self):
        async def hello_world_async():
            print("async hello from hello_world_async()")

        loop = AndroidEventLoop(SelectorMinusSelect())
        asyncio.set_event_loop(loop)
        loop.run_forever_cooperatively()

        asyncio.ensure_future(hello_world_async())

        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))

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

        button = toga.Button("Say Hello!",
                             on_press=self.say_hello,
                             style=Pack(padding=5))

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

        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = main_box
        self.main_window.show()
Beispiel #11
0
    def startup(self):
        # Window class
        #   Main window of the application with title and size
        self.main_window = toga.MainWindow(title=self.name, size=(300, 150))

        style = Pack(padding_top=24)
        substyle = Pack(padding_right=24, flex=1)

        # Add the content on the main window
        self.main_window.content = toga.Box(
            children=[
                toga.Label('Section 1'),
                toga.Divider(style=style),
                toga.Label('Section 2', style=style),
                toga.Divider(style=style),
                toga.Label('Section 3', style=style),
                toga.Box(
                    children=[
                        toga.DetailedList(['List 1'], style=substyle),
                        toga.Divider(direction=toga.Divider.VERTICAL, style=substyle),
                        toga.DetailedList(['List 2'], style=substyle),
                    ],
                    style=Pack(direction=ROW, padding=24, flex=1),
                ),
            ],
            style=Pack(direction=COLUMN, padding=24)
        )

        # Show the main window
        self.main_window.show()
Beispiel #12
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()
Beispiel #13
0
 def make_motion_box(self):
     motions = [
         ('up', '\u25B2', 46),
         ('left', '\u25C0', 45),
         ('stop', '\u25A0', 46),
         ('right', '\u25B6', 45),
         ('down', '\u25BC', 45),
         ('home', 'Home', 132),
     ]
     buttons = [
         toga.Button(
             symbol, on_press=async_partial(self.motion, direction=direction),
             style=Pack(width=width, height=46)
         )
         for direction, symbol, width in motions
     ]
     return toga.Box(
         style=Pack(direction=COLUMN, alignment=CENTER),
         children=[
             buttons[0],
             toga.Box(style=Pack(direction=ROW), children=buttons[1:4]),
             buttons[4],
             buttons[5],
         ]
     )
Beispiel #14
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)
Beispiel #15
0
    def __init__(self, data, app=None, font_size=FontSize.DEFAULT):
        """Initialize window."""
        super().__init__(size=EXPLORE_WINDOW_SIZE)
        self.app = app
        self.data = data
        self.font_size = font_size
        window_width = self.size[0]
        self.parameters_options_boxes = EddingtonBox(
            children=[self.build_parameters_options_box()],
            style=Pack(direction=COLUMN))
        self.plot_configuration_box = PlotConfigurationBox(plot_method=None,
                                                           suffix="Explore")
        self.controls_box = EddingtonBox(
            children=[
                self.parameters_options_boxes,
                toga.Box(style=Pack(flex=1)),
                self.plot_configuration_box,
                EddingtonBox(children=[
                    toga.Button("Refresh",
                                on_press=lambda widget: self.draw()),
                    SaveFigureButton("Save", plot_method=self.plot),
                ]),
            ],
            style=Pack(direction=COLUMN),
        )
        self.figure_box = FigureBox(self.plot, width=int(window_width * 0.5))
        self.content = toga.SplitContainer(
            content=[self.controls_box, self.figure_box])

        self.update_font_size()

        self.draw()
Beispiel #16
0
    def startup(self):
        # Window class
        #   Main window of the application with title and size
        self.main_window = toga.MainWindow(title=self.name, size=(300, 150))

        style = Pack(padding_top=24)
        substyle = Pack(padding_right=12, padding_left=12, flex=1)

        # Add the content on the main window
        self.main_window.content = toga.Box(children=[
            toga.Label('Section 1'),
            toga.Divider(style=style),
            toga.Label('Section 2', style=style),
            toga.Divider(style=style),
            toga.Label('Section 3', style=style),
            toga.Box(
                children=[
                    toga.TextInput(placeholder="First textbox"),
                    toga.Divider(direction=toga.Divider.VERTICAL,
                                 style=substyle),
                    toga.TextInput(placeholder="Second textbox"),
                ],
                style=Pack(direction=ROW, padding=24, flex=1),
            ),
        ],
                                            style=Pack(direction=COLUMN,
                                                       padding=24))

        # Show the main window
        self.main_window.show()
Beispiel #17
0
    def startup(self):
        """
        Construct and show the Toga application.

        Usually, you would add your application to a main content box.
        We then create a main window (with a name matching the app), and
        show the main window.
        """
        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))

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

        button = toga.Button('Say Hello!',
                             on_press=self.say_hello,
                             style=Pack(padding=5))

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

        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = main_box
        self.main_window.show()
Beispiel #18
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()
    def __init__(self, flex):
        """Initialize box."""
        super().__init__(style=Pack(direction=COLUMN, flex=flex))

        self.__title_input = self.__add_column_option("Title:")
        self.__residuals_title_input = self.__add_column_option(
            "Residuals title:")
        self.__xlabel_input = self.__add_column_option("X label:")
        self.__ylabel_input = self.__add_column_option("Y label:")

        self.__grid_switch = toga.Switch(label="Grid")
        self.__legend_switch = toga.Switch(label="Legend")
        self.add(LineBox(children=[self.__grid_switch, self.__legend_switch]))

        self.__x_domain_switch = toga.Switch(
            label="Custom X domain",
            on_toggle=lambda _: self.x_domain_switch_handler())
        self.__x_min_title = toga.Label("X minimum:",
                                        style=Pack(visibility=HIDDEN))
        self.__x_min_input = toga.TextInput(style=Pack(visibility=HIDDEN))
        self.__x_max_title = toga.Label("X maximum:",
                                        style=Pack(visibility=HIDDEN))
        self.__x_max_input = toga.TextInput(style=Pack(visibility=HIDDEN))
        self.add(
            LineBox(children=[
                self.__x_domain_switch,
                self.__x_min_title,
                self.__x_min_input,
                self.__x_max_title,
                self.__x_max_input,
            ]))
Beispiel #20
0
    def __init__(self, main_window): # note: to alter another class, add
        # the object as a parameter
        # This is just the test box items, doesn't do a lot.
        self.main_window = main_window
        self.nothing_label = toga.Label(
            'See what happens:',
            style=Pack(padding=(0, 5))
            )
        self.nothing_input = toga.TextInput(
            initial="Moo?",
            style=Pack(flex=1)
            )
        self.nothing_button = toga.Button(
            'Click me now.',
            on_press=self.say_nothing,
            style=Pack(padding=(0, 5))
            )

        # Nothing box with relevant items
        self.nothing_box = toga.Box(
            children=[
                self.nothing_label,
                self.nothing_input,
                self.nothing_button
                ],
            style=Pack(direction=ROW, alignment=CENTER, padding_top=5)
            )
Beispiel #21
0
    def startup(self):
        # Window class
        #   Main window of the application with title and size
        self.main_window = toga.MainWindow(title=self.name, size=(300, 150))

        switch_style = Pack(padding=24)

        # Add the content on the main window
        self.main_window.content = toga.Box(
            children=[
                # Simple switch with label and callback function called toggled
                toga.Switch('Change Label', on_toggle=self.callbackLabel),

                # Switch with initial state
                toga.Switch('Initial state',
                            is_on=True,
                            style=Pack(padding_top=24)),

                # Switch with label and enable option
                toga.Switch('Disabled',
                            enabled=False,
                            style=Pack(padding_top=24))
            ],
            style=Pack(direction=COLUMN, padding=24))

        # Show the main window
        self.main_window.show()
Beispiel #22
0
    def startup(self):
        # Set up main window
        self.main_window = toga.MainWindow(title=self.name)

        self.fs_source = FileSystemSource(Path.cwd())

        self.tree = toga.Tree(headings=['Name', 'Date Modified'],
                              data=self.fs_source,
                              style=Pack(flex=1),
                              multiple_select=True,
                              on_select=self.selection_handler,
                              on_double_click=self.double_click_handler)
        self.label = toga.Label('A view of the current directory!',
                                style=Pack(padding=10))

        # Outermost box
        outer_box = toga.Box(children=[
            self.label,
            self.tree,
        ],
                             style=Pack(flex=1, direction=COLUMN))

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

        # Show the main window
        self.main_window.show()
Beispiel #23
0
    def startup(self):
        # Set up main window
        self.main_window = toga.MainWindow(title=self.name)

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

        self.tree = toga.Tree(headings=['Year', 'Title', 'Rating', 'Genre'],
                              data=DecadeSource(),
                              on_select=self.on_select_handler,
                              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_box = toga.Box(children=[btn_insert], style=Pack(direction=ROW))

        # Outermost box
        outer_box = toga.Box(children=[btn_box, self.tree, 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()
Beispiel #24
0
    def startup(self):
        self.main_window = toga.MainWindow('main', title=self.title, size=self.size)

        self.top_container = toga.Box(children=[self.logo, self.price, self.currency],
            style=Pack(
                direction=COLUMN, alignment=CENTER
        ))

        self.bottom_container = toga.SplitContainer()
        right = toga.Box(
            children=[self.bid, self.bid_val, self.low, self.low_val, self.volume_24, self.volume_24_val],
            style=Pack(
                direction=COLUMN,
                padding_left=40, padding_top=20
            )
        )
        left = toga.Box(
            children=[self.ask, self.ask_val, self.high, self.high_val, self.volume, self.volume_val],
            style=Pack(
                direction=COLUMN,
                padding_left=40, padding_top=20
            )
        )
        self.bottom_container.content = [right, left]

        self.split = toga.SplitContainer(direction=toga.SplitContainer.HORIZONTAL)
        self.split.content = [self.top_container, self.bottom_container]

        self.main_window.content = self.split
        self.main_window.show()
Beispiel #25
0
    def startup(self):
        # Set up main window
        self.main_window = toga.MainWindow(title=self.name)

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

        widget = toga.DetailedList(
            data=[{
                'icon': toga.Icon('resources/brutus.png'),
                'title': translation['string'],
                'subtitle': translation['country'],
            } for translation in bee_translations],
            on_select=self.on_select_handler,
            # on_delete=self.on_delete_handler,
            on_refresh=self.on_refresh_handler,
            style=Pack(flex=1))

        # Outermost box
        outer_box = toga.Box(children=[widget, 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()
Beispiel #26
0
    def startup(self):
        """
        Construct and show the Toga application.

        Usually, you would add your application to a main content box.
        We then create a main window (with a name matching the app), and
        show the main window.
        """
        main_box = toga.Box(
            style=Pack(
                direction=COLUMN
            )
        )

        buttons = dict()
        stuff = ['item1','item2','item3','item4','item5']

        for s in stuff:
            buttons[s] = toga.Button(
                    s,
                    id = s,
                    style=Pack(
                        padding = 5
                    ),
                    on_press = functools.partial(self.button_press, s) # Use partial function evaluation to get different response from each button
                )
                main_box.add(buttons[s])
            )
Beispiel #27
0
    def startup(self):
        # Create a main window with a name matching the app
        self.main_window = toga.MainWindow(title=self.name, size=(360, 280))

        # Create a main content box
        main_box = toga.Box(style=Pack(direction=COLUMN))

        # Add something to the main box
        main_box.add(toga.Label('Hello World!', style=Pack(padding=5)))

        # Create another box and add it to main_box
        grid_box = toga.Box(style=Pack(direction=COLUMN, padding=5))
        main_box.add(grid_box)

        # Add 4 x 5 array of Buttons to the grid box
        count = 1
        for row in range(5):
            row_box = toga.Box(style=Pack(padding=5))
            for col in range(4):
                row_box.add(toga.Button(f'{count}', style=Pack(padding=5)))
                count += 1
            grid_box.add(row_box)

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

        # Show the main window
        self.main_window.show()
Beispiel #28
0
    def startup(self):
        # Set up main window
        self.main_window = toga.MainWindow(title=self.name)
        self.main_window.app = self

        self.partner = Eliza()

        self.chat = toga.DetailedList(data=[{
            'icon':
            toga.Icon('resources/brutus.png'),
            'title':
            'Brutus',
            'subtitle':
            'Hello. How are you feeling today?',
        }],
                                      style=Pack(flex=1))

        # Buttons
        self.text_input = toga.TextInput(style=Pack(flex=1, padding=5))
        send_button = toga.Button('Send',
                                  on_press=self.handle_input,
                                  style=Pack(padding=5))
        input_box = toga.Box(children=[self.text_input, send_button],
                             style=Pack(direction=ROW))

        # Outermost box
        outer_box = toga.Box(children=[self.chat, input_box],
                             style=Pack(direction=COLUMN))

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

        # Show the main window
        self.main_window.show()
Beispiel #29
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),
            )
        )
Beispiel #30
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()