예제 #1
0
    def setUp(self):
        super().setUp()

        self.items = ['item_{}'.format(x) for x in range(0, 3)]
        self.selection = toga.Selection(factory=toga_dummy.factory)
        self.selection = toga.Selection(items=self.items,
                                        factory=toga_dummy.factory)
예제 #2
0
파일: app.py 프로젝트: yuntiaoOS/toga
    def startup(self):
        # Main window of the application with title and size
        self.main_window = toga.MainWindow(title=self.name, size=(640, 400))

        # set up common styles
        label_style = Pack(flex=1, padding_right=24)
        box_style = Pack(direction=ROW, padding=10)

        # Add the content on the main window
        self.main_window.content = toga.Box(
            children=[
                toga.Box(style=box_style, children=[
                    toga.Label("Select an element",
                        style=label_style),

                    toga.Selection(items=["Carbon", "Ytterbium", "Thulium"])
                ]),

                toga.Box(style=box_style, children=[
                    toga.Label("use the 'on_select' callback to respond to changes",
                        style=label_style),

                    toga.Selection(
                      on_select=self.my_on_select,
                      items=["Dubnium", "Holmium", "Zirconium"])

                ]),

                toga.Box(style=box_style, children=[
                    toga.Label("Long lists of items should scroll",
                        style=label_style),

                    toga.Selection(items=dir(toga)),
                ]),

                toga.Box(style=box_style, children=[
                    toga.Label("use some style!", style=label_style),

                    toga.Selection(
                        style=Pack(width=200, padding=24),
                        items=["Curium", "Titanium", "Copernicium"])
                ]),

                toga.Box(style=box_style, children=[
                    toga.Label("Selection widgets can be disabled", style=label_style),

                    toga.Selection(
                        items=['Helium', 'Neon', 'Argon', 'Krypton', 'Xenon', 'Radon', 'Oganesson'],
                        enabled=False
                    )
                ]),
            ],
            style=Pack(direction=COLUMN, padding=24)
        )

        self.main_window.show()
예제 #3
0
    def open_create_spell(self, widget):

        spell_creator = toga.Box(style=Pack(direction=COLUMN))
        elements1 = [
            'Water', 'Earth', 'Wind', 'Fire', 'Light', 'Healing', 'Lightning',
            'Illusion', 'Chaos'
        ]
        elements2 = [
            'Water', 'Earth', 'Wind', 'Fire', 'Light', 'Healing', 'Lightning',
            'Illusion', 'Chaos'
        ]
        forms = [
            'point', 'line', 'wall', 'random', 'chain', 'sphere', 'cube',
            'projectile', 'cone', 'ally'
        ]
        effects = [
            'attack', 'buff', 'debuff', 'enchantment', 'restoration',
            'defense', 'area control'
        ]
        self.firstused = 0
        self.secondused = 0
        self.firsteffectused = 0
        self.secondeffectused = 0
        firstelement = toga.Selection(items=elements1,
                                      on_select=self.UpdateFirst)
        secondelement = toga.Selection(items=elements1,
                                       on_select=self.UpdateSecond)
        form = toga.Selection(items=forms, on_select=self.UpdateForm)
        firsteffect = toga.Selection(items=effects,
                                     on_select=self.UpdateFirstEffect)
        secondeffect = toga.Selection(items=effects,
                                      on_select=self.UpdateSecondEffect)
        self.eleratio = toga.TextInput(style=Pack(flex=1))

        spell_box = toga.Box(style=Pack(direction=ROW, padding=5))
        spell_box.add(firstelement)
        spell_box.add(secondelement)
        spell_box.add(form)
        spell_box.add(firsteffect)
        spell_box.add(secondeffect)
        spell_box.add(self.eleratio)

        spell_score_button = toga.Button('Score your spell',
                                         on_press=self.say_hello,
                                         style=Pack(padding=5))

        spell_creator.add(spell_box)
        spell_creator.add(spell_score_button)

        #self.main_box.remove(self.create_spell_button)
        #self.main_box.add(spell_creator)

        self.new_window = toga.Window(title=None)
        self.new_window.content = spell_creator
        self.new_window.show()
예제 #4
0
    def setUp(self):
        self.factory = MagicMock()
        self.factory.Selection = MagicMock(return_value=MagicMock(
            spec=toga_dummy.factory.Selection))

        self.items = ['item_{}'.format(x) for x in range(0, 3)]
        self.selection = toga.Selection(items=self.items, factory=self.factory)
예제 #5
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
예제 #6
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)
    def __init__(self, flex):
        """Initialize box."""
        super(FittingFunctionBox, self).__init__(
            style=Pack(direction=COLUMN, flex=flex)
        )
        fit_function_box = LineBox()
        fit_function_box.add(toga.Label(text="Fitting function:"))
        self.fitting_function_selection = toga.Selection(
            on_select=self.load_select_fit_function_name,
        )
        fit_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),
        )
        fit_function_box.add(self.fitting_function_syntax)
        self.load_module_button = toga.Button(
            label="Load module", on_press=self.load_module
        )
        fit_function_box.add(self.load_module_button)
        self.add(fit_function_box)

        self.parameters_box = LineBox()
        self.parameters_box.add(toga.Label("Parameters:"))
        self.parameter_inputs = toga.TextInput(
            readonly=True,
            style=Pack(width=PARAMETER_WIDTH),
            on_change=lambda widget: self.reset_fit_function(),
        )
        self.parameters_box.add(self.parameter_inputs)
        self.add(self.parameters_box)

        self.update_fitting_function_options()
예제 #8
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()
    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()
예제 #10
0
    def __init__(self, on_fitting_function_load):
        """Initialize box."""
        super().__init__()
        self.__fitting_function = None
        self.on_fitting_function_load = None
        self.__polynomial_is_set = False

        self.add(toga.Label(text="Fitting function:"))
        self.fitting_function_selection = toga.Selection(
            on_select=self.load_select_fitting_function_name,
        )
        self.fitting_function_syntax = toga.TextInput(
            readonly=True,
            style=Pack(flex=1, padding_left=BIG_PADDING, padding_right=BIG_PADDING),
        )
        self.add(self.fitting_function_selection, self.fitting_function_syntax)

        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()
        self.on_fitting_function_load = on_fitting_function_load
예제 #11
0
        def time_select(name):
            box = toga.Box(style=Pack(direction=ROW))
            box.add(toga.Label(f'Üblicher {name} um ',
                               style=small_font_flex), )
            box.add(
                toga.Selection(id=name,
                               items=[''] + [str(time) for time in range(24)],
                               on_select=select_time,
                               style=small_font_flex))
            box.add(toga.Label(' Uhr.', style=small_font_flex))

            return box
예제 #12
0
    def startup(self):
        # Define the main box app
        main_box = toga.Box()

        self.main_window = toga.MainWindow(title=self.name)
        self.main_window.content = main_box
        self.main_window.show()

        # Define a intro label for the user
        # NOTE: should I store this inside a box?
        self.intro_label = toga.Label('Escolha um campi', id='intro_text')

        # Creating a selection of campus for the user
        self.campus_selection = toga.Selection(items=[
            'Araranguá', 'Blumenau', 'Curitibanos', 'Florianópolis',
            'Joinville', 'CCA'
        ])
        # Implement on_press function
        #self.search_menu_button = toga.Button('Ver cardápio', on_press=self.search_menu(self.campus_selection))
        self.search_menu_button = toga.Button('Ver cardápio')

        # Creating some more boxes
        intro_label_box = toga.Box()
        intro_label_box.add(self.intro_label)

        selection_box = toga.Box()
        selection_box.add(self.campus_selection)

        button_box = toga.Box()
        button_box.add(self.search_menu_button)

        # Styling the boxes
        main_box.style.update(direction=COLUMN, padding_top=10)
        intro_label_box.style.update(direction=ROW, padding=5)
        selection_box.style.update(direction=ROW, padding=5)
        button_box.style.update(direction=ROW, padding=5)

        intro_label_box.style.update(flex=1)
        selection_box.style.update(flex=1, padding_left=160)

        intro_label_box.style.update(width=100, padding_left=10)
        selection_box.style.update(width=100, padding_left=10)

        button_box.style.update(padding=15, flex=1)

        main_box.add(intro_label_box)
        main_box.add(selection_box)
        main_box.add(button_box)

        return main_box
예제 #13
0
def selection(tag, items):
    box = toga.Box()
    label = toga.Label(tag, style=Pack(width=80))
    txt_input = toga.Selection(items=items, style=Pack(width=100))

    box.add(label)
    box.add(txt_input)

    box.style.update(direction=ROW,
                     alignment=LEFT,
                     width=300,
                     flex=1,
                     padding=5,
                     text_align=LEFT)

    return box, txt_input
예제 #14
0
    def __add_column_option(self, label, on_select):

        selection = toga.Selection(
            enabled=self.selection_enabled,
            on_select=on_select,
            style=Pack(alignment=LEFT, width=SELECTION_WIDTH),
        )
        line = LineBox(
            alignment=LEFT,
            children=[
                toga.Label(text=label, style=Pack(width=LABEL_WIDTH)),
                selection,
            ],
        )

        self.add(line)
        return selection
예제 #15
0
 def make_shapes_box(self):
     self.shape_select = toga.Selection(
         items=['Cylinder', 'Cone', 'Duble Cone'],
         style=Pack(width=132),
         on_select = self.set_draw_shape,
     )
     self.shape_segments = toga.NumberInput(
         min_value=3, max_value=20,
         style=Pack(width=132),
         on_change = self.set_draw_shape,
     )
     return toga.Box(
         style=Pack(direction=COLUMN),
         children=[
             self.shape_select,
             self.shape_segments,
         ],
     )
예제 #16
0
    def __init__(self, flex):
        """Initialize box."""
        super(InputFileBox,
              self).__init__(style=Pack(direction=COLUMN, flex=flex))
        self.__input_file_path = toga.TextInput(
            readonly=True,
            style=Pack(flex=1,
                       padding_left=BIG_PADDING,
                       padding_right=BIG_PADDING),
        )
        self.__select_file = toga.Button(label="Choose file",
                                         on_press=self.select_file)
        self.add(
            LineBox(children=[
                toga.Label(text="Input file:"),
                self.__input_file_path,
                self.__select_file,
            ]))

        self.__select_sheet = toga.Selection(enabled=False,
                                             on_select=self.select_sheet)
        self.add(
            LineBox(children=[toga.Label(text="Sheet:"), self.__select_sheet]))
예제 #17
0
def build(app):

    container = toga.OptionContainer()

    box1 = toga.Box()

    button = toga.Button('Hello world', on_press=button_handler)
    button.style.padding = 50
    button.style.flex = 1

    label = toga.NumberInput(min_value=10.5,
                             max_value=50.6,
                             on_change=lambda app: print(app.value))
    label.text = 'Hola Mundo'

    selection = toga.Selection(items=['Casella', 'Pedro Infante', 'Camilo'],
                               on_select=lambda app: print(app.value))
    selection.items = ['321', '123', '456', '654', '789', '987']

    box1.add(button)
    box1.add(label)
    box1.add(selection)

    box2 = toga.Box()

    image = toga.Image('../../static/images/tiberius.svg')
    imageview = toga.ImageView(image)

    slider = toga.Slider(range=(30, 50), on_slide=lambda app: print(app.value))

    box2.add(imageview)
    box2.add(slider)

    container.add('Window 1', box1)
    container.add('Window 2', box2)

    return container
예제 #18
0
파일: app.py 프로젝트: pmfrank/gistsgetter
    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))
        top_box = toga.Box(
            style=Pack(direction=ROW, padding=5, alignment='top'))
        middle_box = toga.Box(
            style=Pack(direction=ROW, padding=5, alignment='center', flex=1))
        button_box = toga.Box(style=Pack(padding=5, alignment='right'))
        bottom_box = toga.Box(style=Pack(
            direction=ROW, padding=(5, 5, 20, 5),
            alignment='bottom'))  # Padding - Top, Right, Botom, Left

        select_label = toga.Label('Search By',
                                  style=Pack(padding=5, alignment='center'))
        self.select = toga.Selection(items=['UserID', 'GistID'])
        self.select_input = toga.TextInput(style=Pack(padding=5, flex=1),
                                           placeholder='User or Gist ID')
        # Line preserved for prostarity will be using helper functions to do search with externale functions
        # select_button = toga.Button('Search',style=Pack(padding=5),on_press=partial(search,string = 'x'))
        select_button = toga.Button('Search',
                                    style=Pack(padding=5),
                                    on_press=self.search_by)

        self.results = toga.MultilineTextInput(style=Pack(padding=(0, 5),
                                                          flex=1),
                                               readonly=True)

        copy_button = toga.Button('Copy to Clipboard',
                                  style=Pack(padding=5),
                                  on_press=self.copy_to_clipboard)

        button_box.add(copy_button)

        middle_box.add(self.results)
        middle_box.add(button_box)

        top_box.add(select_label)
        top_box.add(self.select)
        top_box.add(self.select_input)
        top_box.add(select_button)

        login_label = toga.Label('Username',
                                 style=Pack(padding=5, alignment='left'))
        self.login_input = toga.TextInput(
            style=Pack(padding=5, alignment='left', flex=1))
        pw_label = toga.Label('Password',
                              style=Pack(padding=5, alignment='right'))
        self.pw_input = toga.PasswordInput(
            style=Pack(padding=4, alignment='right', flex=1))

        bottom_box.add(login_label)
        bottom_box.add(self.login_input)
        bottom_box.add(pw_label)
        bottom_box.add(self.pw_input)

        main_box.add(top_box)
        main_box.add(middle_box)
        main_box.add(bottom_box)
        self.main_window = toga.MainWindow(title=self.formal_name,
                                           size=(640, 480))
        self.main_window.content = main_box
        self.main_window.show()
예제 #19
0
    def build_settings(self):
        self.exp_duration = toga.Selection(
            items=[str(i) for i in range(7, 32)])
        self.cnt_department = toga.Selection(
            items=[str(i) for i in range(5, 10)])
        self.exp_step = toga.Selection(
            items=[str(i) + " час" for i in range(1, 10)])

        self.select_event_day = toga.Selection(
            items=[str(i) for i in range(0, 32)])
        self.select_event_hour = toga.Selection(
            items=[str(i) for i in range(5, 10)])

        self.btn_start_experiment = toga.Button('Начать моделирование',
                                                on_press=self.start_experiment,
                                                style=Pack(flex=1,
                                                           width=250,
                                                           alignment='right'))

        self.btn_step = toga.Button('Выполнить шаг моделирования',
                                    on_press=self.step,
                                    style=Pack(flex=1, width=300, height=38))

        self.btn_add_event = toga.Button('Добавить событие',
                                         on_press=self.add_event,
                                         style=Pack(flex=1,
                                                    width=300,
                                                    height=38))

        self.add_event_day = toga.Selection(items=[str(i) for i in range(32)])
        self.add_event_time = toga.Selection(items=[str(i) for i in range(24)])
        self.add_event_duration = toga.Selection(
            items=[str(i) for i in range(24)])
        self.add_event_room = toga.Selection(
            items=[str(1 + i) for i in range(5)])
        self.add_event_name = toga.TextInput(placeholder='Название события')

        self.add_event_participants_list = toga.Table(['Имя работника'],
                                                      multiple_select=True,
                                                      style=table_style)
        self.add_event_participants = toga.TextInput(
            placeholder='Участники через запятую', style=Pack(width=200))

        self.btn_delete_event = toga.Button('Удалить событие',
                                            on_press=self.delete_event,
                                            style=Pack(flex=1,
                                                       width=300,
                                                       height=38))
        self.delete_event_id = toga.Selection(
            items=[str(i) for i in range(100)])

        self.label_curtime = toga.Label("Текущее время: 0 день 0.00",
                                        style=main_label_style)

        self.label_warning = toga.Label("", style=main_label_style)

        progress = toga.ProgressBar(max=100,
                                    value=1,
                                    style=Pack(padding_top=15))

        self.settings_box = toga.Box(children=[
            toga.Box(style=box_style,
                     children=[
                         toga.Label("Период моделирования", style=label_style),
                         self.exp_duration
                     ]),
            toga.Box(style=box_style,
                     children=[
                         toga.Label("Количество отделов", style=label_style),
                         self.cnt_department
                     ]),
            self.btn_start_experiment,
            progress,
            self.label_warning,
        ],
                                     style=Pack(direction=COLUMN, padding=24))

        self.step_box = toga.Box(children=[
            toga.Box(children=[
                self.label_curtime,
            ]),
            toga.Box(children=[
                toga.Label("Шаг моделирования", style=label_style),
                self.exp_step, self.btn_step
            ],
                     style=Pack(direction=ROW, padding=14))
        ],
                                 style=Pack(direction=COLUMN, padding=24))

        self.add_event_box = toga.Box(children=[
            toga.Box(style=box_style,
                     children=[
                         toga.Label("День", style=label_style),
                         self.add_event_day
                     ]),
            toga.Box(style=box_style,
                     children=[
                         toga.Label("Время", style=label_style),
                         self.add_event_time
                     ]),
            toga.Box(style=box_style,
                     children=[
                         toga.Label("Длительность", style=label_style),
                         self.add_event_duration
                     ]),
            toga.Box(style=box_style,
                     children=[
                         toga.Label("Комната", style=label_style),
                         self.add_event_room
                     ]),
            toga.Box(style=box_style,
                     children=[
                         toga.Label("Название", style=label_style),
                         self.add_event_name
                     ]),
            toga.Box(style=box_style,
                     children=[
                         toga.Label("Участники", style=label_style),
                         self.add_event_participants_list,
                         self.add_event_participants
                     ]),
            self.btn_add_event,
        ],
                                      style=Pack(direction=COLUMN, padding=24))

        self.delete_event_box = toga.Box(children=[
            toga.Box(style=box_style,
                     children=[
                         toga.Label("Номер события", style=label_style),
                         self.delete_event_id
                     ]),
            self.btn_delete_event,
        ],
                                         style=Pack(direction=COLUMN,
                                                    padding=24))

        self.content_box = toga.Box(children=[
            self.settings_box, self.step_box, self.add_event_box,
            self.delete_event_box
        ],
                                    style=Pack(direction=COLUMN))

        return self.content_box
예제 #20
0
    def startup(self):
        # Set up main window
        self.main_window = toga.MainWindow(title=self.name)

        # styles
        style_flex = Pack(flex=1, padding=5)
        style_row = Pack(direction=ROW, flex=1)
        style_select = Pack(direction=ROW, flex=1, padding_right=10)
        style_col = Pack(direction=COLUMN, flex=1)

        # select
        label_select = toga.Label('Select an Option position:',
                                  style=style_flex)
        self.select_option = toga.Selection(style=style_flex)
        # buttons
        btn_remove = toga.Button('Remove',
                                 on_press=self.on_remove_option,
                                 style=style_flex)
        btn_enabled = toga.Button('Toggle enabled',
                                  on_press=self.on_enable_option,
                                  style=style_flex)
        # change label
        self.input_change_title = toga.TextInput(style=style_flex)
        btn_change_title = toga.Button('Change title',
                                       on_press=self.on_change_option_title,
                                       style=style_flex)

        box_select = toga.Box(style=style_select,
                              children=[label_select, self.select_option])
        box_actions_col1 = toga.Box(style=style_row,
                                    children=[btn_remove, btn_enabled])
        box_actions_col2 = toga.Box(
            style=style_row,
            children=[self.input_change_title, btn_change_title])
        box_actions = toga.Box(style=style_col,
                               children=[box_actions_col1, box_actions_col2])
        box_container_actions = toga.Box(style=style_row,
                                         children=[box_select, box_actions])

        self.optioncontainer = toga.OptionContainer(style=Pack(
            padding_bottom=20))
        self._create_options()

        btn_add = toga.Button('Add Option', on_press=self.on_add_option)
        box_general_actions = toga.Box(style=Pack(padding_bottom=10),
                                       children=[btn_add])

        # Outermost box
        outer_box = toga.Box(children=[
            box_general_actions, box_container_actions, self.optioncontainer
        ],
                             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()
예제 #21
0
    def startup(self):
        # choose a default publisher
        self.publisher = 'TOI'

        # Load App configuration from default location
        self.app_config = AppConfig()

        # setup logging
        logging.basicConfig(
            filename=self.app_config.config['App']['log_file'],
            filemode='w',
            format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
            level=logging.DEBUG)

        # Scraper
        self.scraper = Scraper(publisher=self.publisher,
                               app_config=self.app_config)

        # Data object instances
        self.epaper = EPaper(publisher=self.publisher,
                             app_config=self.app_config)

        # GUI
        self._menu_items = {}
        self.document_types = ['.jpg', '.png', '.pdf']
        self.main_window = toga.MainWindow(self.name)

        # Get publications
        doc = self.scraper.fetch(self.scraper.site_archive_url)
        if doc:
            self.epaper.publications = self.scraper.parse_publication_codes(
                doc)

        # Get previously selected publication from config or None
        val = self.app_config.config[self.publisher].get(
            'selected_pub_code', '')
        if val:
            self.epaper.selected_publication = [
                p for p in self.epaper.publications.items() if p[1] == val
            ][0]

        # Publication Selection widget
        self.publication_selection = toga.Selection(
            items=self.epaper.publications.keys(),
            style=Pack(flex=1, padding_left=5, padding_right=5))

        # Get editions
        doc = self.scraper.fetch(
            self.scraper.site_archive_edition_url.format(
                pub_code=self.epaper.selected_publication[1]))
        if doc:
            self.epaper.editions = self.scraper.parse_edition_codes(doc)

        # Get previously selected edition from config or None
        val = self.app_config.config[self.publisher].get(
            'selected_edition_code', '')
        if val:
            self.epaper.selected_edition = [
                e for e in self.epaper.editions.items() if e[1] == val
            ][0]

        self.edition_selection = toga.Selection(
            items=self.epaper.editions.keys(),
            style=Pack(flex=1, padding_left=5, padding_right=5))

        self.date_selection = toga.Selection(items=self.epaper.available_dates,
                                             style=Pack(flex=1,
                                                        padding_left=5,
                                                        padding_right=5))

        # Thumbnail View Commands
        thumbnail_commands = []
        for i in range(self.epaper.num_pages):
            thumbnail_commands.append(
                toga.Command(self.display_page(None, i),
                             label='Display Page',
                             tooltip='Display Page {}'.format(i),
                             group=toga.Group.VIEW,
                             section=0))

        thumbnail_buttons = [
            toga.Button('Page {}'.format(i),
                        on_press=self.display_page(None, i),
                        style=Pack(width=100, padding=2))
            for i in range(self.epaper.num_pages)
        ]

        # left view of SplitContainer below
        self.thumbnail_view = toga.ScrollContainer(content=toga.Box(
            children=thumbnail_buttons, style=Pack(direction=COLUMN)))

        # right view of SplitContainer below
        self.page_view = toga.ScrollContainer(content=toga.ImageView(
            id='page-view',
            image=self.epaper.get_page_image_from_disk(
                self.epaper.selected_page),
        ))

        # MainWindow view
        box = toga.Box(children=[
            toga.Box(children=[
                self.publication_selection, self.edition_selection,
                self.date_selection
            ],
                     style=Pack(direction=ROW, padding=5)),
            toga.SplitContainer(content=(self.thumbnail_view, self.page_view),
                                style=Pack(direction=ROW, padding=5))
        ],
                       style=Pack(direction=COLUMN))

        self.main_window.content = box
        self.main_window.show()
예제 #22
0
파일: app.py 프로젝트: ignaciocabeza/toga
    def startup(self):
        # Set up main window
        self.main_window = toga.MainWindow(title=self.name, size=(250, 250))

        self.canvas = toga.Canvas(style=Pack(flex=1),
                                  on_resize=self.refresh_canvas)
        self.context_selection = toga.Selection(items=[STROKE, FILL],
                                                on_select=self.refresh_canvas)
        self.drawing_shape_instructions = {
            TRIANGLE: self.draw_triangle,
            TRIANGLES: self.draw_triangles,
            RECTANGLE: self.draw_rectangle,
            ELLIPSE: self.draw_ellipse,
            HALF_ELLIPSE: self.draw_half_ellipse,
            ICE_CREAM: self.draw_ice_cream,
            SMILE: self.draw_smile,
            SEA: self.draw_sea,
            STAR: self.draw_star,
            TEXT: self.draw_text
        }
        self.dash_patterns = {
            CONTINUOUS: None,
            DASH_1_1: [1, 1],
            DASH_1_2: [1, 2],
            DASH_2_3_1: [2, 3, 1]
        }
        self.shape_selection = toga.Selection(items=list(
            self.drawing_shape_instructions.keys()),
                                              on_select=self.refresh_canvas)
        self.color_selection = toga.Selection(
            items=[BLACK, BLUE, GREEN, RED, YELLOW],
            on_select=self.refresh_canvas)
        self.fill_rule_selection = toga.Selection(
            items=[value.name.lower() for value in FillRule],
            on_select=self.refresh_canvas)
        self.line_width_slider = toga.Slider(range=(1, 10),
                                             default=1,
                                             on_slide=self.refresh_canvas)
        self.dash_pattern_selection = toga.Selection(
            items=list(self.dash_patterns.keys()),
            on_select=self.refresh_canvas)
        box = toga.Box(style=Pack(direction=COLUMN),
                       children=[
                           toga.Box(style=Pack(direction=ROW),
                                    children=[
                                        self.context_selection,
                                        self.shape_selection,
                                        self.color_selection,
                                        self.fill_rule_selection
                                    ]),
                           toga.Box(style=Pack(direction=ROW),
                                    children=[
                                        toga.Label("Line Width:"),
                                        self.line_width_slider,
                                        self.dash_pattern_selection
                                    ]), self.canvas
                       ])

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

        self.render_drawing(self.canvas, *self.main_window.size)

        # Show the main window
        self.main_window.show()
예제 #23
0
    def startup(self):
        
        main_box = t.Box(style=Pack(direction= COLUMN))

        url = "https://danepubliczne.imgw.pl/api/data/synop"

        CITIES = []

        try: 
            response_pogoda = request.urlopen(url).read()
        except ConnectionError:
            err_msg = "There was a connection error."
            error_lbl = t.Label(err_msg)
            error_lbl.style.update(padding = 30)
            main_box.add(error_lbl)
        except Exception as e:    
            err_msg = f"An error occured. Error type: {type(e)}"
            error_lbl = t.Label(err_msg)
            error_lbl.style.update(padding = 30)
            main_box.add(error_lbl)
        else:

            response_pogoda = response_pogoda.decode()

            response_pogoda = loads(response_pogoda)

            #FUNCS

            def wlbl_fill(data_pomiaru, godzina_pomiaru, suma_opadu, predkosc_wiatru, temperatura):

                wlbl_001.text = f"\U0001F30C POGODA \U0001F30C"
                brk_003.text = '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
                wlbl_002.text =f"{data_pomiaru}    {godzina_pomiaru}:00"  
                
                wlbl_101.text = f"\U0001F327"
                wlbl_102.text = f"Opady"
                wlbl_103.text = f"{suma_opadu}"
                wlbl_104.text = f"mm"

                wlbl_201.text = f"\U0001F32A"
                wlbl_202.text = f"Wiatr"
                wlbl_203.text = f"{predkosc_wiatru}"
                wlbl_204.text = f"km/h"

                wlbl_301.text = f"\U0001F321"
                wlbl_302.text = f"Temperatura"
                wlbl_303.text = f"{temperatura}"
                wlbl_304.text = f"C"


            def wlbl_data(city_name, rsp = response_pogoda):
                for row in rsp:
                    if row["stacja"] == city_name:
                        response = row
                        break
                data_pomiaru = response['data_pomiaru']
                godzina_pomiaru = response['godzina_pomiaru']

                suma_opadu = float(response['suma_opadu'])
                predkosc_wiatru = float(response['predkosc_wiatru'])

                temperatura = float(response['temperatura'])
                wlbl_fill(data_pomiaru, godzina_pomiaru, suma_opadu, predkosc_wiatru, temperatura)
                 

            def get_selection(widget=None, city=None):
                if widget:
                    wlbl_data(widget.value)
                if city:
                    wlbl_data(city)

            #------------------------------------------------------------------------------------------------
            #DATA
            
            for row in response_pogoda:
                CITIES.append(row['stacja'])

 
            #------------------------------------------------------------------------------------------------
            #BOXES
            weather_box = t.Box(style=Pack(direction= COLUMN, padding = 10))

               
                #WEATHER BOX
                    #City Selector
            csb  = t.Box(style=Pack(direction= ROW, padding_bottom = 20))
                    #Title
            wb01 = t.Box(style=Pack(direction= ROW, padding_bottom = 10))
            brk3 = t.Box(style=Pack(direction= ROW, padding_bottom = 10))
            wb02 = t.Box(style=Pack(direction= ROW, padding_bottom = 10))
                    #Opady, Wiatr, Temperatura
            wb10 = t.Box(style=Pack(direction= ROW, padding_bottom = 20))
            wb20 = t.Box(style=Pack(direction= ROW, padding_bottom = 20))
            wb30 = t.Box(style=Pack(direction= ROW, padding_bottom = 20))

            #------------------------------------------------------------------------------------------------
            #ELEMENTS
                
                #WEATHER BOX
            city_select = t.Selection(items=CITIES, on_select=get_selection)
                    #Title
            wlbl_001 = t.Label('',     style=Pack(width = 400, font_size = 15, font_weight = 'bold', text_align = 'left'))
            brk_003  = t.Label('',     style=Pack(width = 400, font_size = 12, text_align = 'left'))
            wlbl_002 = t.Label('',     style=Pack(width = 300, font_size = 15, font_weight = 'bold', text_align = 'left'))
                    
                    #Opady
            wlbl_101 = t.Label('',     style=Pack(width = 25,  font_size = 12, text_align = 'left'))
            wlbl_102 = t.Label('',     style=Pack(width = 125, font_size = 12, text_align = 'left'))
            wlbl_103 = t.Label('',     style=Pack(width = 100, font_size = 12, text_align = 'right'))
            wlbl_104 = t.Label('',     style=Pack(width = 50,  font_size = 12, text_align = 'right'))
                    
                    #Wiatr
            wlbl_201 = t.Label('',     style=Pack(width = 25,  font_size = 12, text_align = 'left'))
            wlbl_202 = t.Label('',     style=Pack(width = 125, font_size = 12, text_align = 'left'))
            wlbl_203 = t.Label('',     style=Pack(width = 100, font_size = 12, text_align = 'right'))
            wlbl_204 = t.Label('',     style=Pack(width = 50,  font_size = 12, text_align = 'right'))
                    
                    #Temperatura
            wlbl_301 = t.Label('',     style=Pack(width = 25,  font_size = 12, text_align = 'left'))
            wlbl_302 = t.Label('',     style=Pack(width = 125, font_size = 12, text_align = 'left'))
            wlbl_303 = t.Label('',     style=Pack(width = 100, font_size = 12, text_align = 'right'))
            wlbl_304 = t.Label('',     style=Pack(width = 50,  font_size = 12, text_align = 'right'))
                    
                    
      
        #------------------------------------------------------------------------------------------------
        # INSERTING ELEMENTS

            # Elements to boxes
                
                #Weather Box
                    # City Selector
        csb.add(city_select)
                    # Title
        wb01.add(wlbl_001)
        wb02.add(wlbl_002)
        brk3.add(brk_003)
                    # Opady
        wb10.add(wlbl_101)
        wb10.add(wlbl_102)
        wb10.add(wlbl_103)
        wb10.add(wlbl_104)
                    # Wiatr
        wb20.add(wlbl_201)
        wb20.add(wlbl_202)
        wb20.add(wlbl_203)
        wb20.add(wlbl_204)
                    # Temperatura
        wb30.add(wlbl_301)
        wb30.add(wlbl_302)
        wb30.add(wlbl_303)
        wb30.add(wlbl_304)


            # Boxes to boxes
        

        weather_box.add(csb)
        weather_box.add(wb01)
        weather_box.add(wb02)
        weather_box.add(brk3)
        weather_box.add(wb10)
        weather_box.add(wb20)
        weather_box.add(wb30)

            # Boxes to main
        main_box.add(weather_box)

        #------------------------------------------------------------------------------------------------
        get_selection(city = 'Białystok')
        self.main_window = t.MainWindow(title='PogodaInfo')
        self.main_window.size = (400, 350)
        self.main_window.content = main_box
        self.main_window.show()
예제 #24
0
    def startup(self):

        self.main_window = toga.MainWindow(title=self.name, size=(640, 400))

        label_style = Pack(flex=1, padding_right=24)
        box_style_horiz = Pack(direction=ROW, padding=15)
        box_style_verti = Pack(direction=COLUMN, padding=15)

        #selections
        self.portselect = toga.Selection(items=serial_ports())
        self.chipselect = toga.Selection(items=["ESP8266", "ESP32"],
                                         on_select=self.update_selections)
        self.verselect = toga.Selection(items=[
            "v1.8.7", "v1.9.0", "v1.9.1", "v1.9.2", "v1.9.3", "v1.9.4",
            "v1.10.0"
        ])

        #puerto
        self.port = None
        self.port_open = False

        #switchs
        self.switchdio = toga.Switch('DIO',
                                     is_on=False,
                                     style=Pack(padding_left=10,
                                                padding_top=5))

        #textinputs
        self.textfile = toga.TextInput(style=Pack(flex=1, width=200))
        self.commandesp = toga.TextInput(style=Pack(flex=1, width=450))

        #intento de terminal
        self.textterminal = toga.MultilineTextInput(id='terminal')

        #textoutputs
        self.textoutputs = toga.MultilineTextInput(id='output')

        self.filelabel = toga.Label("No ha seleccionado ningun archivo",
                                    style=Pack(padding=2))
        self.fname = None
        # definir los hijos del main box afuera del main box
        left_box = toga.Box(style=box_style_verti)
        left_box.add(
            toga.Box(style=Pack(direction=ROW, padding_left=25),
                     children=[
                         self.portselect, self.chipselect, self.verselect,
                         self.switchdio
                     ]))
        left_box.add(
            toga.Box(style=Pack(direction=COLUMN, padding_top=7),
                     children=[
                         toga.Button("Ver archivos en ESP",
                                     on_press=self.read_files,
                                     style=Pack(padding_top=15,
                                                padding_left=2)),
                         toga.Button("Seleccionar archivo",
                                     on_press=self.action_open_file_dialog,
                                     style=Pack(padding=2)), self.filelabel,
                         toga.Button("Ejecutar archivo en ESP",
                                     on_press=self.run_in_esp,
                                     style=Pack(padding=2)),
                         toga.Button("Grabar archivo en ESP",
                                     on_press=self.save_to_esp,
                                     style=Pack(padding=2)), self.textfile,
                         toga.Button("Borrar archivo de ESP",
                                     on_press=self.erase_from_esp,
                                     style=Pack(padding=2)),
                         toga.Button("Obtener archivo de ESP",
                                     on_press=self.get_file_esp,
                                     style=Pack(padding=2)), self.textoutputs
                     ]))

        # Cambio en la estructura de los boxes para que funcione el rendering de los hijos en Windows, el bug es propio de toga al momento de presentar los boxes
        # Agregar hijos de right_box
        # right_box = toga.Box(style=box_style_verti)
        # right_box.add(toga.Button("Flashear",on_press=self.flash, style=Pack(padding=2)))
        # right_box.add(toga.Button("Borrar flash/firmware",on_press=self.eraseflash, style=Pack(padding=2)))
        # right_box.add(toga.Button("Actualizar puertos",on_press=self.update_ports, style=Pack(padding=2)))
        # right_box.add(toga.Button("Abrir puerto", on_press=self.open_port, style=Pack(padding=2)))
        # right_box.add(self.textterminal)
        # right_box.add(toga.Box(style=Pack(direction=ROW,padding_top=7), children=[
        # 				self.commandesp,
        # 				toga.Button("Enviar comando", on_press=self.send_command, style=Pack(padding=2))
        # 				])
        # 			)

        left_box.add(
            toga.Button("Flashear", on_press=self.flash,
                        style=Pack(padding=2)))
        left_box.add(
            toga.Button("Borrar flash/firmware",
                        on_press=self.eraseflash,
                        style=Pack(padding=2)))
        left_box.add(
            toga.Button("Actualizar puertos",
                        on_press=self.update_ports,
                        style=Pack(padding=2)))
        left_box.add(
            toga.Button("Abrir puerto",
                        on_press=self.open_port,
                        style=Pack(padding=2)))
        left_box.add(self.textterminal)
        left_box.add(
            toga.Box(style=Pack(direction=ROW, padding_top=7),
                     children=[
                         self.commandesp,
                         toga.Button("Enviar comando",
                                     on_press=self.send_command,
                                     style=Pack(padding=2))
                     ]))

        container = toga.Box()
        container.add(left_box)
        # container.add(right_box)

        self.main_window.content = container

        self.main_window.show()
예제 #25
0
    def startup(self):
        # Main window of the application with title and size
        self.main_window = toga.MainWindow(title=self.name, size=(640, 400))

        # set up common styles
        label_style = Pack(flex=1, padding_right=24)
        box_style = Pack(direction=ROW, padding=10)

        # Add the content on the main window
        self.selection = toga.Selection(items=self.OPTIONS)

        self.main_window.content = toga.Box(
            children=[
                toga.Box(
                    style=box_style,
                    children=[
                        toga.Label("Select an element", style=label_style),
                        self.selection,
                    ],
                ),
                toga.Box(
                    style=box_style,
                    children=[
                        toga.Label(
                            "Selection value can be set by property setter",
                            style=label_style,
                        ),
                        toga.Button(label="Set Carbon",
                                    on_press=self.set_carbon),
                        toga.Button(label="Set Ytterbium",
                                    on_press=self.set_ytterbium),
                        toga.Button(label="Set THULIUM",
                                    on_press=self.set_thulium),
                    ],
                ),
                toga.Box(
                    style=box_style,
                    children=[
                        toga.Label(
                            "use the 'on_select' callback to respond to changes",
                            style=label_style,
                        ),
                        toga.Selection(
                            on_select=self.my_on_select,
                            items=["Dubnium", "Holmium", "Zirconium"],
                        ),
                    ],
                ),
                toga.Box(
                    style=box_style,
                    children=[
                        toga.Label("Long lists of items should scroll",
                                   style=label_style),
                        toga.Selection(items=dir(toga)),
                    ],
                ),
                toga.Box(
                    style=box_style,
                    children=[
                        toga.Label("use some style!", style=label_style),
                        toga.Selection(
                            style=Pack(width=200, padding=24),
                            items=["Curium", "Titanium", "Copernicium"],
                        ),
                    ],
                ),
                toga.Box(
                    style=box_style,
                    children=[
                        toga.Label("Selection widgets can be disabled",
                                   style=label_style),
                        toga.Selection(
                            items=[
                                "Helium",
                                "Neon",
                                "Argon",
                                "Krypton",
                                "Xenon",
                                "Radon",
                                "Oganesson",
                            ],
                            enabled=False,
                        ),
                    ],
                ),
            ],
            style=Pack(direction=COLUMN, padding=24),
        )

        self.main_window.show()
예제 #26
0
    def startup(self):
        # Set up main window
        self.main_window = toga.MainWindow(title=self.name, size=(750, 500))

        self.canvas = toga.Canvas(
            style=Pack(flex=1),
            on_resize=self.refresh_canvas,
            on_press=self.on_press,
            on_drag=self.on_drag,
            on_release=self.on_release,
            on_alt_press=self.on_alt_press,
            on_alt_drag=self.on_alt_drag,
            on_alt_release=self.on_alt_release
        )
        self.context_selection = toga.Selection(items=[STROKE, FILL], on_select=self.refresh_canvas)
        self.drawing_shape_instructions = {
            INSTRUCTIONS: self.draw_instructions,
            TRIANGLE: self.draw_triangle,
            TRIANGLES: self.draw_triangles,
            RECTANGLE: self.draw_rectangle,
            ELLIPSE: self.draw_ellipse,
            HALF_ELLIPSE: self.draw_half_ellipse,
            ICE_CREAM: self.draw_ice_cream,
            SMILE: self.draw_smile,
            SEA: self.draw_sea,
            STAR: self.draw_star,
        }
        self.dash_patterns = {
            CONTINUOUS: None,
            DASH_1_1: [1, 1],
            DASH_1_2: [1, 2],
            DASH_2_3_1: [2, 3, 1]
        }
        self.shape_selection = toga.Selection(
            items=list(self.drawing_shape_instructions.keys()),
            on_select=self.on_shape_change
        )
        self.color_selection = toga.Selection(
            items=[BLACK, BLUE, GREEN, RED, YELLOW],
            on_select=self.refresh_canvas
        )
        self.fill_rule_selection = toga.Selection(
            items=[value.name.lower() for value in FillRule],
            on_select=self.refresh_canvas
        )
        self.line_width_slider = toga.Slider(
            range=(1, 10),
            default=1,
            on_slide=self.refresh_canvas
        )
        self.dash_pattern_selection = toga.Selection(
            items=list(self.dash_patterns.keys()),
            on_select=self.refresh_canvas
        )
        self.clicked_point = None
        self.translation = None
        self.rotation = 0
        self.scale_x_slider = toga.Slider(
            range=(0, 2),
            default=1,
            tick_count=10,
            on_slide=self.refresh_canvas
        )
        self.scale_y_slider = toga.Slider(
            range=(0, 2),
            default=1,
            tick_count=10,
            on_slide=self.refresh_canvas
        )
        self.font_selection = toga.Selection(
            items=[
                SYSTEM,
                MESSAGE,
                SERIF,
                SANS_SERIF,
                CURSIVE,
                FANTASY,
                MONOSPACE
            ],
            on_select=self.refresh_canvas
        )
        self.font_size = toga.NumberInput(
            min_value=10,
            max_value=72,
            default=20,
            on_change=self.refresh_canvas
        )
        self.italic_switch = toga.Switch(
            label="italic",
            on_toggle=self.refresh_canvas
        )
        self.bold_switch = toga.Switch(
            label="bold",
            on_toggle=self.refresh_canvas
        )
        label_style = Pack(font_size=10, padding_left=5)

        # Add the content on the main window
        box = toga.Box(
            style=Pack(direction=COLUMN),
            children=[
                toga.Box(
                    style=Pack(direction=ROW, padding=5),
                    children=[
                        self.context_selection,
                        self.shape_selection,
                        self.color_selection,
                        self.fill_rule_selection
                    ]
                ),
                toga.Box(
                    style=Pack(direction=ROW, padding=5),
                    children=[
                        toga.Label("Line Width:", style=label_style),
                        self.line_width_slider,
                        self.dash_pattern_selection
                    ]
                ),
                toga.Box(
                    style=Pack(direction=ROW, padding=5),
                    children=[
                        toga.Label("X Scale:", style=label_style),
                        self.scale_x_slider,
                        toga.Label("Y Scale:", style=label_style),
                        self.scale_y_slider,
                        toga.Button(
                            label="Reset transform",
                            on_press=self.reset_transform
                        )
                    ]
                ),
                toga.Box(
                    style=Pack(direction=ROW, padding=5),
                    children=[
                        toga.Label("Font Family:", style=label_style),
                        self.font_selection,
                        toga.Label("Font Size:", style=label_style),
                        self.font_size,
                        self.bold_switch,
                        self.italic_switch
                    ]
                ),
                self.canvas
            ]
        )
        self.main_window.content = box

        self.change_shape()
        self.render_drawing()

        # Show the main window
        self.main_window.show()
예제 #27
0
파일: app.py 프로젝트: FunPythonEC/uPy_IDE
    def startup(self):

        self.main_window = toga.MainWindow(title=self.name, size=(640, 400))

        label_style = Pack(flex=1, padding_right=24)
        box_style_horiz = Pack(direction=ROW, padding=15)
        box_style_verti = Pack(direction=COLUMN, padding=15)

        #selections
        self.portselect = toga.Selection(items=serial_ports())
        self.chipselect = toga.Selection(items=["ESP8266", "ESP32"],
                                         on_select=self.update_selections)
        self.verselect = toga.Selection(items=[
            "v1.8.7", "v1.9.0", "v1.9.1", "v1.9.2", "v1.9.3", "v1.9.4",
            "v1.10.0"
        ])

        #puerto
        self.port = None
        self.port_open = False

        #switchs
        self.switchdio = toga.Switch('DIO',
                                     is_on=False,
                                     style=Pack(padding_left=10,
                                                padding_top=5))

        #textinputs
        self.textfile = toga.TextInput(style=Pack(flex=1, width=200))
        self.commandesp = toga.TextInput(style=Pack(flex=1, width=450))

        #intento de terminal
        self.textterminal = toga.MultilineTextInput(readonly=False,
                                                    style=Pack(flex=1,
                                                               width=600,
                                                               height=600))

        #textoutputs
        self.textoutputs = toga.MultilineTextInput(readonly=True,
                                                   style=Pack(flex=1,
                                                              width=200,
                                                              height=200))

        #botones
        self.btnport = toga.Button("Abrir puerto",
                                   on_press=self.open_port,
                                   style=Pack(padding=2))

        self.filelabel = toga.Label("No ha seleccionado ningun archivo",
                                    style=Pack(padding=2))
        self.fname = None
        self.main_window.content = toga.Box(children=[
            toga.Box(
                style=box_style_verti,
                children=[
                    toga.Box(style=Pack(direction=ROW, padding_left=25),
                             children=[
                                 self.portselect, self.chipselect,
                                 self.verselect, self.switchdio
                             ]),
                    toga.Box(
                        style=Pack(direction=COLUMN, padding_top=7),
                        children=[
                            toga.Button("Ver archivos en ESP",
                                        on_press=self.read_files,
                                        style=Pack(padding_top=15,
                                                   padding_left=2)),
                            toga.Button("Seleccionar archivo",
                                        on_press=self.action_open_file_dialog,
                                        style=Pack(padding=2)), self.filelabel,
                            toga.Button("Ejecutar archivo en ESP",
                                        on_press=self.run_in_esp,
                                        style=Pack(padding=2)),
                            toga.Button("Grabar archivo en ESP",
                                        on_press=self.save_to_esp,
                                        style=Pack(padding=2)), self.textfile,
                            toga.Button("Borrar archivo de ESP",
                                        on_press=self.erase_from_esp,
                                        style=Pack(padding=2)),
                            toga.Button("Obtener archivo de ESP",
                                        on_press=self.get_file_esp,
                                        style=Pack(
                                            padding=2)), self.textoutputs
                        ])
                ]),
            toga.Box(style=box_style_verti,
                     children=[
                         toga.Button("Flashear", on_press=self.flash),
                         toga.Button("Borrar flash/firmware",
                                     on_press=self.eraseflash),
                         toga.Button("Actualizar puertos",
                                     on_press=self.update_ports), self.btnport,
                         self.textterminal,
                         toga.Box(style=Pack(direction=ROW, padding_top=7),
                                  children=[
                                      self.commandesp,
                                      toga.Button("Enviar comando",
                                                  on_press=self.send_command,
                                                  style=Pack(padding=2))
                                  ])
                     ])
        ])

        self.main_window.show()
예제 #28
0
    def startup(self):
        # Set up main window
        self.main_window = toga.MainWindow(title=self.name)

        # styles
        style_flex = Pack(flex=1, padding=5)
        style_row = Pack(direction=ROW, flex=1)
        style_select = Pack(direction=ROW, flex=1, padding_right=10)
        style_col = Pack(direction=COLUMN, flex=1)

        # select
        label_select = toga.Label('Select an Option position:',
                                  style=style_flex)
        self.select_option = toga.Selection(style=style_flex)
        # buttons
        btn_remove = toga.Button('Remove',
                                 on_press=self.on_remove_option,
                                 style=style_flex)
        btn_enabled = toga.Button('Toggle enabled',
                                  on_press=self.on_enable_option,
                                  style=style_flex)
        # change label
        self.input_change_title = toga.TextInput(style=style_flex)
        btn_change_title = toga.Button('Change title',
                                       on_press=self.on_change_option_title,
                                       style=style_flex)

        box_select = toga.Box(style=style_select,
                              children=[label_select, self.select_option])
        box_actions_col1 = toga.Box(style=style_row,
                                    children=[btn_remove, btn_enabled])
        box_actions_col2 = toga.Box(
            style=style_row,
            children=[self.input_change_title, btn_change_title])
        box_actions = toga.Box(style=style_col,
                               children=[box_actions_col1, box_actions_col2])
        box_container_actions = toga.Box(style=style_row,
                                         children=[box_select, box_actions])

        self.selected_label = toga.Label("")
        self.optioncontainer = toga.OptionContainer(
            on_select=self.on_select_tab, style=Pack(padding_bottom=20))
        self._create_options()

        btn_add = toga.Button('Add Option', on_press=self.on_add_option)
        box_general_actions = toga.Box(style=Pack(padding_bottom=10),
                                       children=[btn_add])

        # Outermost box
        outer_box = toga.Box(children=[
            box_general_actions,
            box_container_actions,
            self.selected_label,
            self.optioncontainer,
        ],
                             style=Pack(
                                 flex=1,
                                 direction=COLUMN,
                                 padding=10,
                             ))

        self.commands.add(
            toga.Command(self.set_next_tab,
                         "Next tab",
                         shortcut=toga.Key.MOD_1 + toga.Key.RIGHT,
                         group=toga.Group.COMMANDS,
                         order=1),
            toga.Command(self.set_previous_tab,
                         "Previous tab",
                         shortcut=toga.Key.MOD_1 + toga.Key.LEFT,
                         group=toga.Group.COMMANDS,
                         order=1))

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

        # Show the main window
        self.main_window.show()
예제 #29
0
    def startup(self):
        self.main_window = toga.MainWindow(title=self.formal_name,
                                           size=(320, 568))

        box = toga.Box(style=Pack(direction=COLUMN, padding=5))

        local_box = toga.Box(
            style=Pack(padding=(20, 0, 5, 0), alignment=CENTER))
        local_box.add(
            toga.Label('Local Currency:',
                       style=Pack(
                           width=120,
                           padding_right=5,
                           font_family='Helvetica',
                           font_size=16,
                           font_weight=BOLD,
                           text_align=RIGHT,
                       )))

        self.local_currency = toga.Selection(
            items=[str(c) for c in CURRENCIES],
            on_select=self.on_select,
            style=Pack(flex=1))
        local_box.add(self.local_currency)

        box.add(local_box)

        self.amount = toga.NumberInput(on_change=self.on_change,
                                       min_value=0,
                                       step='0.01',
                                       style=Pack(font_family='Helvetica',
                                                  font_size=48,
                                                  text_align=RIGHT))
        box.add(self.amount)

        tip_box = toga.Box(style=Pack(padding_top=10))

        self.tip_rate = toga.Selection(items=["20%", "15%", "10%"],
                                       on_select=self.on_select,
                                       style=Pack(flex=1))
        tip_box.add(self.tip_rate)

        self.tip = toga.TextInput(readonly=True,
                                  style=Pack(flex=1,
                                             padding_left=5,
                                             text_align=RIGHT))
        tip_box.add(self.tip)

        self.tip_total = toga.TextInput(readonly=True,
                                        style=Pack(flex=1, text_align=RIGHT))
        tip_box.add(self.tip_total)

        box.add(tip_box)

        my_box = toga.Box(style=Pack(padding=(10, 0, 5, 0), alignment=CENTER))
        my_box.add(
            toga.Label('My Currency:',
                       style=Pack(width=120,
                                  padding_right=5,
                                  font_family='Helvetica',
                                  font_size=16,
                                  font_weight=BOLD,
                                  text_align=RIGHT)))

        self.my_currency = toga.Selection(items=[str(c) for c in CURRENCIES],
                                          on_select=self.on_select,
                                          style=Pack(flex=1))
        my_box.add(self.my_currency)

        box.add(my_box)

        self.my_amount = toga.TextInput(readonly=True,
                                        style=Pack(font_family='Helvetica',
                                                   font_size=48,
                                                   text_align=RIGHT))
        box.add(self.my_amount)

        my_tip_box = toga.Box(style=Pack(padding_top=10))

        self.my_tip_label = toga.Label('20%',
                                       style=Pack(flex=1,
                                                  padding_left=5,
                                                  text_align=RIGHT))
        my_tip_box.add(self.my_tip_label)

        self.my_tip = toga.TextInput(readonly=True,
                                     style=Pack(flex=1,
                                                padding_left=5,
                                                text_align=RIGHT))
        my_tip_box.add(self.my_tip)

        self.my_tip_total = toga.TextInput(readonly=True,
                                           style=Pack(flex=1,
                                                      text_align=RIGHT))
        my_tip_box.add(self.my_tip_total)

        box.add(my_tip_box)

        self.main_window.content = box
        self.main_window.show()
예제 #30
0
    def __init__(self, **kwargs) -> None:
        super().__init__(
            title="Maestral Settings",
            resizeable=False,
            minimizable=False,
            release_on_close=False,
            **kwargs,
        )

        # ==== account info section ====================================================

        self.profile_pic_view = toga.ImageView(
            self.faceholder,
            style=Pack(
                width=SettingsGui.IMAGE_WIDTH,
                height=SettingsGui.IMAGE_WIDTH,
                background_color=TRANSPARENT,
            ),
        )
        apply_round_clipping(self.profile_pic_view)

        self.profile_pic_view_spacer = toga.Box(style=Pack(
            width=SettingsGui.COLUMN_WIDTH_LEFT - SettingsGui.IMAGE_WIDTH,
            direction=ROW,
            background_color=TRANSPARENT,
        ))

        self.label_name = Label(
            "Account Name (Company Name)",
            style=Pack(
                font_size=17,
                padding_bottom=SettingsGui.ELEMENT_PADDING - 4,
                width=SettingsGui.COLUMN_WIDTH_RIGHT,
            ),
        )
        self.label_email = Label(
            "[email protected], Business",
            style=Pack(
                padding_bottom=SettingsGui.SUBELEMENT_PADDING,
                width=SettingsGui.COLUMN_WIDTH_RIGHT,
                font_size=12,
            ),
        )
        self.label_usage = Label(
            "10.5 % from 1,005 TB used",
            style=Pack(
                padding_bottom=SettingsGui.ELEMENT_PADDING,
                width=SettingsGui.COLUMN_WIDTH_RIGHT,
                font_size=12,
            ),
        )
        self.btn_unlink = toga.Button(
            "Unlink this Dropbox...",
            style=Pack(width=SettingsGui.BUTTON_WIDTH))

        account_info_box = toga.Box(
            children=[
                self.profile_pic_view_spacer,
                self.profile_pic_view,
                toga.Box(
                    children=[
                        self.label_name,
                        self.label_email,
                        self.label_usage,
                        self.btn_unlink,
                    ],
                    style=Pack(direction=COLUMN,
                               padding_left=SettingsGui.COLUMN_PADDING),
                ),
            ],
            style=Pack(direction=ROW),
        )

        # ==== sync settings section ===================================================

        self._label_select_folders = Label(
            "Selective sync:",
            style=Pack(text_align=RIGHT, width=SettingsGui.COLUMN_WIDTH_LEFT),
        )
        self.btn_select_folders = toga.Button(
            label="Select files and folders...",
            style=Pack(padding_left=SettingsGui.COLUMN_PADDING,
                       width=SettingsGui.BUTTON_WIDTH),
        )

        self._label_dbx_location = Label(
            "Local Dropbox folder:",
            style=Pack(text_align=RIGHT, width=SettingsGui.COLUMN_WIDTH_LEFT),
        )
        self.combobox_dbx_location = FileSelectionButton(
            initial=get_home_dir(),
            select_files=False,
            select_folders=True,
            style=Pack(padding_left=SettingsGui.COLUMN_PADDING,
                       width=SettingsGui.BUTTON_WIDTH),
        )

        dropbox_settings_box = toga.Box(
            children=[
                toga.Box(
                    children=[
                        self._label_select_folders, self.btn_select_folders
                    ],
                    style=Pack(alignment=CENTER,
                               padding_bottom=SettingsGui.ELEMENT_PADDING),
                ),
                toga.Box(
                    children=[
                        self._label_dbx_location, self.combobox_dbx_location
                    ],
                    style=Pack(alignment=CENTER),
                ),
            ],
            style=Pack(direction=COLUMN),
        )

        # ==== system settings section =================================================

        self._label_update_interval = Label(
            "Check for updates:",
            style=Pack(text_align=RIGHT, width=SettingsGui.COLUMN_WIDTH_LEFT),
        )
        self.combobox_update_interval = toga.Selection(
            items=["Daily", "Weekly", "Monthly", "Never"],
            style=Pack(padding_left=SettingsGui.COLUMN_PADDING,
                       width=SettingsGui.BUTTON_WIDTH),
        )

        self._label_system_settings = Label(
            "System settings:",
            style=Pack(text_align=RIGHT, width=SettingsGui.COLUMN_WIDTH_LEFT),
        )
        self.checkbox_autostart = Switch(
            label="Start Maestral on login",
            style=Pack(
                padding_bottom=SettingsGui.SUBELEMENT_PADDING,
                width=SettingsGui.COLUMN_WIDTH_RIGHT,
            ),
        )
        self.checkbox_notifications = Switch(
            label="Enable notifications on file changes",
            style=Pack(
                padding_bottom=SettingsGui.SUBELEMENT_PADDING,
                width=SettingsGui.COLUMN_WIDTH_RIGHT,
            ),
        )

        children = [
            toga.Box(
                children=[
                    self._label_update_interval, self.combobox_update_interval
                ],
                style=Pack(alignment=CENTER,
                           padding_bottom=SettingsGui.ELEMENT_PADDING),
            ),
            toga.Box(children=[
                self._label_system_settings,
                toga.Box(
                    children=[
                        self.checkbox_autostart,
                        self.checkbox_notifications,
                    ],
                    style=Pack(
                        alignment=TOP,
                        direction=COLUMN,
                        padding_left=SettingsGui.COLUMN_PADDING,
                    ),
                ),
            ], ),
        ]

        if FROZEN:
            # add UI to install command line interface
            self._label_cli_tool = Label(
                "Command line tool:",
                style=Pack(text_align=RIGHT,
                           width=SettingsGui.COLUMN_WIDTH_LEFT),
            )

            self.label_cli_tool_info = Label(
                "Install the 'maestral' command line tool to /usr/local/bin.",
                style=Pack(
                    color=GRAY,
                    font_size=12,
                    width=SettingsGui.COLUMN_WIDTH_RIGHT,
                    padding_left=SettingsGui.COLUMN_PADDING,
                ),
            )

            self.btn_cli_tool = toga.Button(
                "Install",
                style=Pack(
                    width=SettingsGui.BUTTON_WIDTH / 2,
                    padding_bottom=SettingsGui.SUBELEMENT_PADDING,
                    padding_left=SettingsGui.COLUMN_PADDING,
                ),
            )

            children.append(
                toga.Box(
                    children=[
                        self._label_cli_tool,
                        self.btn_cli_tool,
                    ],
                    style=Pack(alignment=CENTER,
                               padding_top=SettingsGui.ELEMENT_PADDING),
                ))
            children.append(
                toga.Box(
                    children=[
                        Label(
                            " ",
                            style=Pack(text_align=RIGHT,
                                       width=SettingsGui.COLUMN_WIDTH_LEFT),
                        ),
                        self.label_cli_tool_info,
                    ],
                    style=Pack(alignment=CENTER,
                               padding_top=SettingsGui.SUBELEMENT_PADDING),
                ))

        maestral_settings_box = toga.Box(
            children=children,
            style=Pack(direction=COLUMN),
        )

        # ==== about section ===========================================================

        about_box = toga.Box(
            children=[
                Label(
                    "About Maestral:",
                    style=Pack(text_align=RIGHT,
                               width=SettingsGui.COLUMN_WIDTH_LEFT),
                ),
                toga.Box(
                    children=[
                        Label(
                            f"GUI v{__version__}, daemon v{__daemon_version__}",
                            style=Pack(
                                padding_bottom=SettingsGui.SUBELEMENT_PADDING,
                                width=SettingsGui.COLUMN_WIDTH_RIGHT,
                            ),
                        ),
                        LinkLabel(
                            text=__url__,
                            url=__url__,
                            style=Pack(
                                padding_bottom=SettingsGui.SUBELEMENT_PADDING,
                                width=SettingsGui.COLUMN_WIDTH_RIGHT,
                            ),
                        ),
                        Label(
                            f"© 2018 - {year}, {__author__}.",
                            style=Pack(color=GRAY,
                                       width=SettingsGui.COLUMN_WIDTH_RIGHT),
                        ),
                    ],
                    style=Pack(direction=COLUMN,
                               padding_left=SettingsGui.COLUMN_PADDING),
                ),
            ],
            style=Pack(direction=ROW),
        )

        main_box = toga.Box(
            children=[
                account_info_box,
                toga.Divider(style=Pack(padding=SettingsGui.SECTION_PADDING)),
                dropbox_settings_box,
                toga.Divider(style=Pack(padding=SettingsGui.SECTION_PADDING)),
                maestral_settings_box,
                toga.Divider(style=Pack(padding=SettingsGui.SECTION_PADDING)),
                about_box,
            ],
            style=Pack(
                direction=COLUMN,
                padding=30,
                width=SettingsGui.COLUMN_WIDTH_LEFT +
                SettingsGui.COLUMN_WIDTH_RIGHT,
            ),
        )

        self.content = main_box