Exemplo n.º 1
0
    def startup(self):
        # Main window of the application with title and size
        self.main_window = toga.MainWindow(title=self.name, size=(1000, 500))

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

        self.discreteSliderValueLabel = toga.Label("slide me",
                                                   style=label_style)
        self.continuousSliderValueLabel = toga.Label(
            "Default Slider is a continuous range between 0 to 1",
            style=label_style)

        # Add the content on the main window
        self.main_window.content = toga.Box(children=[
            toga.Box(style=box_style,
                     children=[
                         self.continuousSliderValueLabel,
                         toga.Slider(on_slide=self.my_continuous_on_slide,
                                     style=slider_style),
                     ]),
            toga.Box(
                style=box_style,
                children=[
                    toga.Label(
                        "On a scale of 1 to 10, how easy is building a Toga GUI?",
                        style=label_style),
                    toga.Slider(range=(1, 10),
                                default=10,
                                style=Pack(width=150),
                                tick_count=10),
                ]),
            toga.Box(style=box_style,
                     children=[
                         toga.Label("Sliders can be disabled",
                                    style=label_style),
                         toga.Slider(enabled=False, style=slider_style),
                     ]),
            toga.Box(style=box_style,
                     children=[
                         toga.Label("Give a Slider some style!",
                                    style=label_style),
                         toga.Slider(style=slider_style)
                     ]),
            toga.Box(style=box_style,
                     children=[
                         self.discreteSliderValueLabel,
                         toga.Slider(on_slide=self.my_discrete_on_slide,
                                     range=(MIN_VAL, MAX_VAL),
                                     tick_count=MAX_VAL - MIN_VAL + 1,
                                     style=slider_style),
                     ]),
        ],
                                            style=Pack(direction=COLUMN,
                                                       padding=24))

        self.main_window.show()
Exemplo n.º 2
0
    def startup(self):
        # Main window of the application with title and size
        self.main_window = toga.MainWindow(self.name, size=(700, 500))

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

        self.sliderValueLabel = toga.Label("slide me", style=label_style)

        # Add the content on the main window
        self.main_window.content = toga.Box(children=[
            toga.Box(style=box_style,
                     children=[
                         toga.Label("default Slider -- range is 0 to 1",
                                    style=label_style),
                         toga.Slider(style=slider_style),
                     ]),
            toga.Box(
                style=box_style,
                children=[
                    toga.Label(
                        "on a scale of 1 to 10, how easy is GUI with Toga?",
                        style=label_style),
                    toga.Slider(range=(1, 10),
                                default=10,
                                style=Pack(width=150)),
                ]),
            toga.Box(style=box_style,
                     children=[
                         toga.Label("Sliders can be disabled",
                                    style=label_style),
                         toga.Slider(enabled=False, style=slider_style),
                     ]),
            toga.Box(style=box_style,
                     children=[
                         toga.Label("give a Slider some style!",
                                    style=label_style),
                         toga.Slider(style=slider_style)
                     ]),
            toga.Box(style=box_style,
                     children=[
                         self.sliderValueLabel,
                         toga.Slider(on_slide=self.my_on_slide,
                                     range=(-40, 58),
                                     style=slider_style),
                     ]),
        ],
                                            style=Pack(direction=COLUMN,
                                                       padding=24))

        self.main_window.show()
Exemplo n.º 3
0
    def startup(self):
        # Main window of the application with title and size
        self.main_window = toga.MainWindow(self.name, size=(700, 500))
        self.main_window.app = self

        self.sliderValueLabel = toga.Label("slide me")

        # set up common styls
        label_style = CSS(flex=1, padding_right=24)
        box_style = CSS(flex_direction="row", padding=24)

        # Add the content on the main window
        self.main_window.content = toga.Box(children=[
            toga.Box(style=box_style,
                     children=[
                         toga.Label("default Slider -- range is 0 to 1",
                                    style=label_style),
                         toga.Slider(),
                     ]),
            toga.Box(
                style=box_style,
                children=[
                    toga.Label(
                        "on a scale of 1 to 10, how easy is GUI with Toga?",
                        style=label_style),
                    toga.Slider(range=(1, 10), default=10),
                ]),
            toga.Box(style=box_style,
                     children=[
                         toga.Label("Sliders can be disabled",
                                    style=label_style),
                         toga.Slider(enabled=False),
                     ]),
            toga.Box(style=box_style,
                     children=[
                         toga.Label("give a Slider some style!",
                                    style=label_style),
                         toga.Slider(style=CSS(margin=16, width=300))
                     ]),
            toga.Box(
                style=box_style,
                children=[
                    toga.Label(
                        "use the 'on_slide' callback to respond to changes",
                        style=label_style),
                    toga.Slider(on_slide=self.my_on_slide, range=(-40, 58)),
                    self.sliderValueLabel
                ]),
        ],
                                            style=CSS(padding=24))

        self.main_window.show()
Exemplo n.º 4
0
def slider(tag, range):
    box = toga.Box()
    label = toga.Label(tag)
    txt_input = toga.Slider()

    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
Exemplo n.º 5
0
    def setUp(self):
        super().setUp()

        self.default = 50
        self.range = (0, 100)

        def callback(widget):
            pass

        self.on_slide = callback
        self.enabled = True

        self.slider = toga.Slider(default=self.default,
                                  range=self.range,
                                  on_slide=self.on_slide,
                                  enabled=self.enabled,
                                  factory=toga_dummy.factory)
Exemplo n.º 6
0
def build(app):
    label = toga.Label(text='Value: ')

    def on_slide(widget):
        label.text = 'Value: ' + str(widget.value)

    slider = toga.Slider(range=(0, 100), default=30, on_slide=on_slide, style=CSS())

    box = toga.Box(style=CSS(padding=20))
    box.add(slider)
    box.add(label)

    def toggle_enable(widget):
        slider.enabled = not slider.enabled

    box.add(toga.Button('Toggle Enabled', on_press=toggle_enable))
    return box
Exemplo n.º 7
0
    def setUp(self):
        self.factory = MagicMock()
        self.factory.Slider = MagicMock(return_value=MagicMock(
            spec=toga_dummy.factory.Slider))

        self.default = 50
        self.range = (0, 100)

        def callback(widget):
            pass

        self.on_slide = callback
        self.enabled = True

        self.slider = toga.Slider(default=self.default,
                                  range=self.range,
                                  on_slide=self.on_slide,
                                  enabled=self.enabled,
                                  factory=self.factory)
Exemplo n.º 8
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, padding=(25, 25, 25, 25)))
        # scrollable_box = toga.ScrollContainer(vertical = True, horizontal = False, content = main_box)

        #create text input for content
        label_content = toga.Label('Isi Berita :',
                                   style=Pack(padding_bottom=5))
        main_box.add(label_content)
        self.content = toga.MultilineTextInput(style=Pack(flex=1))
        main_box.add(self.content)

        #create slider for rate compression
        label_rate_compression = toga.Label('Tingkat Peringkasan :  ',
                                            style=Pack(padding_top=25))
        main_box.add(label_rate_compression)
        self.rate_compression = toga.Slider(range=(0, 10), tick_count=11)
        main_box.add(self.rate_compression)

        #create button
        button_sum = toga.Button('Ringkas Data',
                                 on_press=self.summarize_data,
                                 style=Pack(padding_bottom=25))
        main_box.add(button_sum)

        #result of summarize
        label_result_content = toga.Label('Hasil Ringkasan: ',
                                          style=Pack(padding_bottom=5))
        main_box.add(label_result_content)
        self.result_content = toga.MultilineTextInput(style=Pack(flex=1))
        main_box.add(self.result_content)

        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = main_box
        self.main_window.show()
Exemplo n.º 9
0
    def setUp(self):
        super().setUp()

        self.default = 50
        self.min_val = 0
        self.max_val = 100
        self.default_tick = 6
        self.range = (self.min_val, self.max_val)
        self.tick_count = 11

        self.on_change = mock.Mock()
        self.enabled = True

        self.slider = toga.Slider(
            default=self.default,
            range=self.range,
            on_change=self.on_change,
            enabled=self.enabled,
            factory=toga_dummy.factory,
            tick_count=self.tick_count,
        )
Exemplo n.º 10
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
Exemplo n.º 11
0
Arquivo: app.py Projeto: teratorn/toga
    def startup(self):
        # Main window of the application with title and size
        self.main_window = toga.MainWindow(title=self.name, size=(1000, 500))

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

        self.discrete_slider_value_label = toga.Label(
            'Slide me or use "ctrl" + "+/-"', style=label_style)
        self.continuous_slider_value_label = toga.Label(
            "Default Slider is a continuous range between 0 to 1",
            style=label_style)

        # Add the content on the main window
        self.discrete_slider = toga.Slider(
            on_change=self.my_discrete_on_change,
            range=(MIN_VAL, MAX_VAL),
            tick_count=MAX_VAL - MIN_VAL + 1,
            style=slider_style)
        self.main_window.content = toga.Box(children=[
            toga.Box(style=box_style,
                     children=[
                         self.continuous_slider_value_label,
                         toga.Slider(on_change=self.my_continuous_on_change,
                                     style=slider_style),
                     ]),
            toga.Box(
                style=box_style,
                children=[
                    toga.Label(
                        "On a scale of 1 to 10, how easy is building a Toga GUI?",
                        style=label_style),
                    toga.Slider(range=(1, 10),
                                default=10,
                                style=Pack(width=150),
                                tick_count=10),
                ]),
            toga.Box(style=box_style,
                     children=[
                         toga.Label("Sliders can be disabled",
                                    style=label_style),
                         toga.Slider(enabled=False, style=slider_style),
                     ]),
            toga.Box(style=box_style,
                     children=[
                         toga.Label("Give a Slider some style!",
                                    style=label_style),
                         toga.Slider(style=slider_style)
                     ]),
            toga.Box(style=box_style,
                     children=[
                         self.discrete_slider_value_label,
                         self.discrete_slider,
                     ]),
        ],
                                            style=Pack(direction=COLUMN,
                                                       padding=24))

        self.commands.add(
            toga.Command(self.increase_discrete_slider,
                         "Increase slider",
                         shortcut=toga.Key.MOD_1 + toga.Key.PLUS,
                         group=toga.Group.COMMANDS),
            toga.Command(self.decrease_discrete_slider,
                         "Decrease slider",
                         shortcut=toga.Key.MOD_1 + toga.Key.MINUS,
                         group=toga.Group.COMMANDS))

        self.main_window.show()
Exemplo n.º 12
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()
Exemplo n.º 13
0
    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()
Exemplo n.º 14
0
 def test_set_on_release(self):
     on_release = mock.Mock()
     slider = toga.Slider(on_release=on_release, factory=toga_dummy.factory)
     self.assertEqual(slider.on_release._raw, on_release)
Exemplo n.º 15
0
 def test_set_on_press(self):
     on_press = mock.Mock()
     slider = toga.Slider(on_press=on_press, factory=toga_dummy.factory)
     self.assertEqual(slider.on_press._raw, on_press)
Exemplo n.º 16
0
    def startup(self):

        # Create main window
        self.main_window = toga.MainWindow(self.name)
        icons = os.path.join(os.path.dirname(__file__), 'icons')

        # dice number window
        self.roll_dice = ''
        self.die_window = toga.Window('die_num', title='How many dice to roll', closeable=False,
                                      minimizable=False)
        self.dice_number = toga.Slider(range=(1,10), window=self.die_window)


        # Character Attributes on the left
        self.left_content = toga.Slider()
        self.left_container = toga.ScrollContainer(content=self.left_content, horizontal=False)

        # Other attributes on the right
        self.right_container = toga.OptionContainer()

        self.right_table = toga.Table(headings=['Throws', 'Values'])
        self.right_tree = toga.Tree(headings=['Spells', 'Equipment'])

        self.right_container.add('Table', self.right_table)
        self.right_container.add('Tree', self.right_tree)


        # Split left and right boxes formed above
        self.split = toga.SplitContainer()
        self.split.content = [self.left_container, self.right_container]

        # Make dice toolbar
        cmd4 = toga.Command(self.dice4,
                            'Roll D4',
                            tooltip='Roll a four sided die',
                            icon=os.path.join(icons, 'd4.png'),
                            order=1)
        cmd6 = toga.Command(self.dice6,
                            'Roll D6',
                            tooltip='Roll a six sided die',
                            icon=os.path.join(icons, 'd6.png'),
                            order=2)
        cmd8 = toga.Command(self.dice8,
                            'Roll D8',
                            tooltip='Roll a eight sided die',
                            icon=os.path.join(icons, 'd8.png'),
                            order=3)
        cmd10 = toga.Command(self.dice10,
                            'Roll D10',
                            tooltip='Roll a 10 sided die',
                            icon=os.path.join(icons, 'd10.png'),
                            order=4)
        cmd12 = toga.Command(self.dice12,
                            'Roll D12',
                            tooltip='Roll a twelve sided die',
                            icon=os.path.join(icons, 'd12.png'),
                            order=5)
        cmd20 = toga.Command(self.dice20,
                            'Roll D20',
                            tooltip='Roll a twenty sided die',
                            icon=os.path.join(icons, 'd20.png'),
                            order=6)

        # Show main window
        self.main_window.toolbar.add(cmd4, cmd6, cmd8, cmd10, cmd12, cmd20)
        self.main_window.toolbar.add(die_slider)
        self.main_window.content = self.split
        self.main_window.show()