def build(app):
    box = toga.Box(style=CSS(width=200, padding=20))

    def callback(widget):
        box.style.width = box.style.width + 100
        print(box.style.width)

    for x in range(24):
        box.add(toga.Button('Button_{}'.format(x), on_press=callback))
    btn = toga.Button('Button_{}'.format(1), on_press=callback)
    # box.add(btn)


    scrollcontainer = toga.ScrollContainer()
    scrollcontainer.horizontal = False
    scrollcontainer.horizontal = False
    scrollcontainer.content = box
    return scrollcontainer
Exemple #2
0
def build(app):
	path=os.path.dirname(os.path.abspath(__file__))
	brutus_icon=os.path.join(path,"icons","brutus.icns")
	cricket_icon=os.path.join(path,"icons","cricket-72.png")


	#List of tuples added as table values
	data=[('root%s' % i, 'value %s' % i) for i in range(1,100)]
	left_container=toga.Table(headings=['Hello','World'], data=data)
	




	right_content=toga.Box(style=Pack(direction=COLUMN, padding_top=50))
#Dynamically add buttons
	for b in range(0,10):
		right_content.add(toga.Button('Hello world %s' % b,on_press=button_handler,style=Pack(width=200,padding=20)))


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

	split=toga.SplitContainer()
	split.content=[left_container,right_container]
	

	things=toga.Group('Things')

	#Command object
	cmd0=toga.Command(action0,label='Action 0',tooltip='Perform action 0',icon=brutus_icon,group=things)
	cmd1=toga.Command(action1,label='Action 1',tooltip='Perform action 1',icon=brutus_icon,group=things)
	cmd2=toga.Command(action2,label='Action 2',tooltip='Perform action 2',icon=cricket_icon,group=things)
	cmd3=toga.Command(action3,label='Action 3',tooltip='Perform action 3',shortcut='k',icon=cricket_icon)
	cmd4=toga.Command(action4, label='Action 4',tooltip='Perform action 4',icon=brutus_icon)
	#Add commands as Menu Items
	app.commands.add(cmd1,cmd3,cmd4,cmd0)
	#Add commands as Icons on Toolbar
	app.main_window.toolbar.add(cmd1,cmd2,cmd3,cmd4)

	return split
Exemple #3
0
    def startup(self):
        self.main_window = toga.MainWindow(title=self.name, size=(720, 580))
        self.ScrollContainer = toga.ScrollContainer()

        plot_box = toga.Box()

        button = toga.Button('Play',
                             on_press=self.playback,
                             style=Pack(width=100))

        GenerateSpectrum(self.filename)
        image_from_path = toga.Image('Figure_temp.png')
        imageview_from_path = toga.ImageView(image_from_path)
        imageview_from_path.style.update(height=480)
        imageview_from_path.style.update(width=640)
        plot_box.add(imageview_from_path)

        self.things = toga.Group('File')

        cmdOpen = toga.Command(self.actionOpenFileDialog,
                               label='Open',
                               tooltip='Open Audio File',
                               group=self.things)

        self.commands.add(cmdOpen)

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

        # Outermost box
        outer_box = toga.Box(children=[self.label, button, plot_box],
                             style=Pack(flex=1,
                                        direction=COLUMN,
                                        alignment=CENTER,
                                        padding=10))

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

        self.main_window.show()
Exemple #4
0
def build(app):
    def installHandle(widget):
        import installer
        result_label.value = installer.full_install(package_input.value)

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

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

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

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

    return split
import toga

content = toga.WebView()
content.url = 'http://www.google.com'
container = toga.ScrollContainer(content=content, horizontal=False)
container.vertical = False


def build(app):
    return container


toga.App('First App', 'org.pybee.helloworld', startup=build).main_loop()
Exemple #6
0
def build(app):
    brutus_icon = "icons/brutus"
    cricket_icon = "icons/cricket-72.png"

    data = [('root%s' % i, 'value %s' % i) for i in range(1, 100)]

    left_container = toga.Table(headings=['Hello', 'World'], data=data)

    right_content = toga.Box(style=Pack(direction=COLUMN, padding_top=50))

    for b in range(0, 10):
        right_content.add(
            toga.Button('Hello world %s' % b,
                        on_press=button_handler,
                        style=Pack(width=200, padding=20)))

    right_container = toga.ScrollContainer(horizontal=False)

    right_container.content = right_content

    split = toga.SplitContainer()

    # The content of the split container can be specified as a simple list:
    #    split.content = [left_container, right_container]
    # but you can also specify "weight" with each content item, which will
    # set an initial size of the columns to make a "heavy" column wider than
    # a narrower one. In this example, the right container will be twice
    # as wide as the left one.
    split.content = [(left_container, 1), (right_container, 2)]

    # Create a "Things" menu group to contain some of the commands.
    # No explicit ordering is provided on the group, so it will appear
    # after application-level menus, but *before* the Command group.
    # Items in the Things group are not explicitly ordered either, so they
    # will default to alphabetical ordering within the group.
    things = toga.Group('Things')
    cmd0 = toga.Command(action0,
                        label='Action 0',
                        tooltip='Perform action 0',
                        icon=brutus_icon,
                        group=things)
    cmd1 = toga.Command(action1,
                        label='Action 1',
                        tooltip='Perform action 1',
                        icon=brutus_icon,
                        group=things)
    cmd2 = toga.Command(action2,
                        label='Action 2',
                        tooltip='Perform action 2',
                        icon=toga.Icon.TOGA_ICON,
                        group=things)

    # Commands without an explicit group end up in the "Commands" group.
    # The items have an explicit ordering that overrides the default
    # alphabetical ordering
    cmd3 = toga.Command(action3,
                        label='Action 3',
                        tooltip='Perform action 3',
                        shortcut=toga.Key.MOD_1 + 'k',
                        icon=cricket_icon,
                        order=3)

    # Define a submenu inside the Commands group.
    # The submenu group has an order that places it in the parent menu.
    # The items have an explicit ordering that overrides the default
    # alphabetical ordering.
    sub_menu = toga.Group("Sub Menu", parent=toga.Group.COMMANDS, order=2)
    cmd5 = toga.Command(action5,
                        label='Action 5',
                        tooltip='Perform action 5',
                        order=2,
                        group=sub_menu)
    cmd6 = toga.Command(action6,
                        label='Action 6',
                        tooltip='Perform action 6',
                        order=1,
                        group=sub_menu)

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

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

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

    return split
Exemple #7
0
    def startup(self):
        # Paths and files
        ospath = os.path.dirname(sys.argv[0])
        self.CONFIG_FILE = ospath + '\\config'

        # Constants
        self.CHECKUP_TIME = 20 * 60
        self.BREAK_TIME = 20

        # Activity box
        activity_box = toga.Box(
            style=Pack(direction=COLUMN, background_color='aqua'))

        self.timer_running = False

        title_label = toga.Label('Eye Help',
                                 style=Pack(padding_left=50,
                                            padding_right=50,
                                            padding_top=20,
                                            font_family='monospace',
                                            font_size=30,
                                            font_weight='bold'))

        instruction = 'Start and stop timer to track your screen use and eye blinks'

        instructions_box = MultilineLabel(instruction,
                                          box_style=Pack(direction=COLUMN,
                                                         padding_left=50,
                                                         padding_top=10),
                                          label_style=Pack(
                                              padding_bottom=10,
                                              font_family='monospace',
                                              font_size=12),
                                          char_line=35)

        self.start_button = toga.Button('Start Timer!',
                                        on_press=self.begin_timer,
                                        style=Pack(padding_left=50,
                                                   padding_right=50,
                                                   padding_top=20,
                                                   background_color='violet',
                                                   height=50,
                                                   font_family='monospace',
                                                   font_size=20))

        self.stop_button = toga.Button('Stop Timer!',
                                       on_press=self.stop_timer,
                                       style=Pack(padding_left=50,
                                                  padding_right=50,
                                                  padding_top=20,
                                                  padding_bottom=10,
                                                  background_color='violet',
                                                  height=50,
                                                  font_family='monospace',
                                                  font_size=20),
                                       enabled=False)

        # https://www.healthline.com/health/how-many-times-do-you-blink-a-day
        blinks_label = MultilineLabel(
            'It is recommended to blink 15 - 20 times in a minute',
            box_style=Pack(direction=COLUMN,
                           padding_bottom=10,
                           background_color='aqua'),
            label_style=Pack(padding_left=50,
                             background_color='aqua',
                             font_family='monospace',
                             font_size=12),
            char_line=35)

        activity_box.add(title_label)
        activity_box.add(self.start_button)
        activity_box.add(self.stop_button)
        activity_box.add(instructions_box)
        activity_box.add(blinks_label)

        # Eye tips box
        # https://www.mayoclinic.org/diseases-conditions/eyestrain/diagnosis-treatment/drc-20372403
        # https://www.health.ny.gov/prevention/tobacco_control/smoking_can_lead_to_vision_loss_or_blindness
        # https://www.health.harvard.edu/blog/will-blue-light-from-electronic-devices-increase-my-risk-of-macular-degeneration-and-blindness-2019040816365
        self.eye_tips = [
            'Try to not to use very bright lighting as the glare can strain your eyes and make the screen harder to look at',
            'Try to put light sources in places that do not directly shine on your eyes',
            'Using non-prescripted eye drops can help relieve dry eyes. Try to get ones recommended by your doctor',
            'Make sure you screens are at least an arms length away from your eyes',
            'Improve the air quality the air by getting a humidifier or adjusting the thermostat',
            'If you smoke, try to stop as it can lead to diseases related to vision loss',
            'Low levels of blue light (emitted froms screens and most lights) do not affect your eyes, but high levels can be hazardous to your eyes',
            'Blue light affects your biological clock (sleep cycle) so try to avoid screens and bright lights before or while you sleep',
            '20-20-20 Every 20 minutes focus at an object 20 feet far for at least 20 seconds',  # done by timer
            '...'
        ]

        eye_tips_box = toga.Box(style=Pack(
            direction=COLUMN, padding_bottom=10, background_color='aqua'))
        for tip in self.eye_tips:
            tip_box = MultilineLabel(tip,
                                     box_style=Pack(direction=COLUMN,
                                                    padding_bottom=10,
                                                    background_color='wheat'),
                                     label_style=Pack(background_color='aqua',
                                                      font_family='monospace',
                                                      font_size=15),
                                     char_line=28)
            eye_tips_box.add(tip_box)

        eye_tips_scroll = toga.ScrollContainer(style=Pack(
            direction=COLUMN, padding=(5, 5), background_color='red'))
        eye_tips_scroll.content = eye_tips_box

        # Calibrate box
        calibrate_box = toga.Box(
            style=Pack(direction=COLUMN, background_color='aqua'))
        calibrate_info = toga.Label('You will be given instructions',
                                    style=Pack(padding_left=10,
                                               padding_top=10,
                                               font_family='monospace',
                                               font_size=15))
        calibrate_button = toga.Button('Calibrate',
                                       style=Pack(padding_left=50,
                                                  padding_right=50,
                                                  padding_top=20,
                                                  padding_bottom=20,
                                                  background_color='violet',
                                                  font_family='monospace',
                                                  font_size=20),
                                       on_press=self.start_calibrate)
        calibrate_when = MultilineLabel(
            'Use this if you feel that blinks are not being counted correctly',
            box_style=Pack(direction=COLUMN,
                           padding_bottom=10,
                           background_color='aqua'),
            label_style=Pack(padding_left=10,
                             font_family='monospace',
                             font_size=15))
        graph_button = toga.Button('Graph Eye Aspect Ratio',
                                   style=Pack(padding_left=50,
                                              padding_right=50,
                                              padding_top=10,
                                              padding_bottom=10,
                                              background_color='violet',
                                              font_family='monospace',
                                              font_size=15),
                                   on_press=self.start_graph)

        EAR_definition = MultilineLabel(
            '*Eye aspect ratio is lower the more your eyes close',
            box_style=Pack(direction=COLUMN,
                           padding_bottom=10,
                           background_color='aqua'),
            label_style=Pack(padding_left=10,
                             font_family='monospace',
                             font_size=13))

        # manual calibration is a work in progress
        manual_label = toga.Label('Manually calibrate (pick EAR) here',
                                  style=Pack(padding_left=10,
                                             padding_top=10,
                                             font_family='monospace',
                                             font_size=15))
        manual_label2 = toga.Label('Pick a value that seems like a blink',
                                   style=Pack(padding_left=10,
                                              padding_top=10,
                                              font_family='monospace',
                                              font_size=15))
        manual_input = toga.NumberInput(min_value=1,
                                        max_value=99,
                                        style=Pack(padding=(10, 50), width=50))

        calibrate_box.add(calibrate_when)
        calibrate_box.add(calibrate_button)
        calibrate_box.add(calibrate_info)
        calibrate_box.add(graph_button)
        calibrate_box.add(EAR_definition)

        # Config box
        config_box = toga.Box(
            style=Pack(direction=COLUMN, background_color='aqua'))
        self.video_switch = toga.Switch('Show Video',
                                        style=Pack(padding_left=50,
                                                   padding_right=50,
                                                   padding_top=20,
                                                   padding_bottom=20,
                                                   font_family='monospace',
                                                   font_size=20),
                                        is_on=self.tobool(
                                            self.read_config()[1]))

        save_button = toga.Button('Save Configuration',
                                  style=Pack(padding_left=50,
                                             padding_right=50,
                                             padding_top=20,
                                             padding_bottom=20,
                                             background_color='violet',
                                             font_family='monospace',
                                             font_size=20),
                                  on_press=self.save_config)

        reset_button = toga.Button('Reset Configuration',
                                   style=Pack(padding_left=50,
                                              padding_right=50,
                                              padding_top=20,
                                              padding_bottom=20,
                                              background_color='red',
                                              font_family='monospace',
                                              font_size=20),
                                   on_press=self.reset_config)

        config_box.add(self.video_switch)
        config_box.add(save_button)
        config_box.add(reset_button)

        # options - toolbar
        options = toga.OptionContainer(style=Pack(direction=ROW,
                                                  background_color='snow',
                                                  font_family='monospace',
                                                  font_size=15))
        options.add('Activity', activity_box)
        options.add('Eye tips', eye_tips_scroll)
        options.add('Calibrate', calibrate_box)
        options.add('Configure', config_box)

        main_box = toga.Box(style=Pack(
            padding=(10, 10), direction=COLUMN, background_color='snow'))
        main_box.add(options)

        # Create and show main window
        self.main_window = toga.MainWindow(title=self.formal_name,
                                           size=(640, 480),
                                           resizeable=False)
        self.main_window.content = main_box
        self.main_window.show()
Exemple #8
0
    def startup(self):
        # Create the main window
        self.main_window = toga.MainWindow(self.name)

        left_container = toga.OptionContainer()

        left_table = toga.Table(headings=['Hello', 'World'],
                                data=[
                                    ('root1', 'value1'),
                                    ('root2', 'value2'),
                                    ('root3', 'value3'),
                                    ('root4', 'value4'),
                                ])

        left_tree = toga.Tree(headings=['Navigate'],
                              data={
                                  ('root1', ): {},
                                  ('root2', ): {
                                      ('root2.1', ):
                                      None,
                                      ('root2.2', ): [
                                          ('root2.2.1', ),
                                          ('root2.2.2', ),
                                          ('root2.2.3', ),
                                      ]
                                  }
                              })

        left_container.add('Table', left_table)
        left_container.add('Tree', left_tree)

        right_content = toga.Box(style=Pack(direction=COLUMN))
        for b in range(0, 10):
            right_content.add(
                toga.Button('Hello world %s' % b,
                            on_press=self.button_handler,
                            style=Pack(padding=20)))

        right_container = toga.ScrollContainer()

        right_container.content = right_content

        split = toga.SplitContainer()

        split.content = [left_container, right_container]

        cmd1 = toga.Command(
            self.action1,
            'Action 1',
            tooltip='Perform action 1',
            icon='resources/brutus',
        )
        cmd2 = toga.Command(self.action2,
                            'Action 2',
                            tooltip='Perform action 2',
                            icon=toga.Icon.TOGA_ICON)

        self.main_window.toolbar.add(cmd1, cmd2)

        self.main_window.content = split

        # Show the main window
        self.main_window.show()
Exemple #9
0
def build(app):
    left_container = toga.Table(['Hello', 'World'])

    left_container.insert(None, 'root1', 'value1')
    left_container.insert(None, 'root2', 'value2')
    left_container.insert(None, 'root3', 'value3')
    left_container.insert(1, 'root4', 'value4')

    for i in range(0, 100):
        left_container.insert(None, 'root%s' % (i+5), 'value%s' % (i+5))

    right_content = toga.Box(
        style=CSS(flex_direction='column', padding_top=50)
    )

    for b in range(0, 10):
        right_content.add(
            toga.Button(
                'Hello world %s' % b,
                on_press=button_handler,
                style=CSS(width=200, margin=20)
            )
        )

    right_container = toga.ScrollContainer(horizontal=False)

    right_container.content = right_content

    split = toga.SplitContainer()

    split.content = [left_container, right_container]

    things = toga.Group('Things')

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

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

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

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

    return split
Exemple #10
0
    def startup(self):
        # Create the main window
        self.main_window = toga.MainWindow(self.name)
        self.main_window.app = self

        left_container = toga.OptionContainer()

        left_table = toga.Table(['Hello', 'World'])

        left_table.insert(None, 'root1', 'value1')
        left_table.insert(None, 'root2', 'value2')
        left_table.insert(None, 'root3', 'value3')
        left_table.insert(1, 'root4', 'value4')

        left_tree = toga.Tree(['Navigate'])

        left_tree.insert(None, None, 'root1')

        root2 = left_tree.insert(None, None, 'root2')

        left_tree.insert(root2, None, 'root2.1')
        root2_2 = left_tree.insert(root2, None, 'root2.2')

        left_tree.insert(root2_2, None, 'root2.2.1')
        left_tree.insert(root2_2, None, 'root2.2.2')
        left_tree.insert(root2_2, None, 'root2.2.3')

        left_container.add('Table', left_table)
        left_container.add('Tree', left_tree)

        right_content = toga.Box()
        for b in range(0, 10):
            right_content.add(
                toga.Button('Hello world %s' % b,
                            on_press=self.button_handler,
                            style=CSS(margin=20)))

        right_container = toga.ScrollContainer()

        right_container.content = right_content

        split = toga.SplitContainer()

        split.content = [left_container, right_container]

        cmd1 = toga.Command(self.action1,
                            'Action 1',
                            tooltip='Perform action 1',
                            icon=os.path.join(os.path.dirname(__file__),
                                              'icons/brutus-32.png'))
        cmd2 = toga.Command(self.action2,
                            'Action 2',
                            tooltip='Perform action 2',
                            icon=toga.TIBERIUS_ICON)

        self.main_window.toolbar = [cmd1, toga.SEPARATOR, cmd2]

        self.main_window.content = split

        # Show the main window
        self.main_window.show()
Exemple #11
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()
Exemple #12
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.
        """
        ## Define all the images for the new buttons,
        ## From a quick search this seems harder than it is worth as a grade
        """
        Linear_Regression_Image="Images/Linear_Regression"
        Logistic_Regression_Image="Images/Logistic_Regression"
        Bayesian_Classification_Image="Images/Bayesian_Classification"
        Decision_Tree_Image="Images/Decision_Tree"
        Random_Forest_Image="Images/Random_Forest"
        Cluster_Analysis_Image="Images/Cluster_Analysis"
        Fuzzy_Data_Matching_Image="Images/Fuzzy_Data_Matching"
        Multi-Layer_Neural_Networks_Image="Images/Multi-Layer_Neural_Networks"
        Optimization_with_Linear_Programming_Image="Images/Optimization_with_Linear_Programming"
        Massively_Parallel_Programming_with_Spark_Image="Images/Massively_Parallel_Programming_with_Spark"
        """

        self.startJupyterNotebook(self)

        main_box = toga.Box()
        scroll_box = toga.Box(children=[],
                              style=Pack(direction=COLUMN,
                                         padding=10,
                                         flex=1,
                                         text_align=CENTER))

        group1Title = toga.Label('Linear Regression')

        def b1callback(button):
            self.openNotebook(self, "Regressions with charts.ipynb")
            pass

        button1 = toga.Button('Regression With Charts',
                              style=Pack(height=20, padding=13),
                              on_press=b1callback)

        def b2callback(button):
            self.openNotebook(self, "Non Linear Regression.ipynb")
            pass

        button2 = toga.Button('Non-Linear Regression',
                              style=Pack(height=20, padding=13),
                              on_press=b2callback)
        scroll_box.add(group1Title, button1, button2)

        group2Title = toga.Label('Classification')

        def b3callback(button):
            self.openNotebook(self, "Logistic Regression.ipynb")
            pass

        button3 = toga.Button('Logistic Regression',
                              style=Pack(height=20, padding=13),
                              on_press=b3callback)

        def b4callback(button):
            self.openNotebook(self, "Decision Tree Random Forest.ipynb")
            pass

        button4 = toga.Button('Decision Tree and Random Forest',
                              style=Pack(height=20, padding=13),
                              on_press=b4callback)

        def b5callback(button):
            self.openNotebook(self, "Naive Bayes.ipynb")
            pass

        button5 = toga.Button('Bayesian Classification',
                              style=Pack(height=20, padding=13),
                              on_press=b5callback)
        scroll_box.add(group2Title, button3, button4, button5)

        group3Title = toga.Label('K-Means Clustering')

        def b6callback(button):
            self.openNotebook(self, "K-Mean-Clustering-Final-WithLib.ipynb")
            pass

        button6 = toga.Button('Cluster Analysis',
                              style=Pack(height=20, padding=13),
                              on_press=b6callback)
        scroll_box.add(group3Title, button6)

        group4Title = toga.Label('Linear Programming Optimization')

        def b7callback(button):
            self.openNotebook(self, "Linear Programming.ipynb")
            pass

        button7 = toga.Button('Optimization with Linear Programming',
                              style=Pack(height=20, padding=13),
                              on_press=b7callback)
        scroll_box.add(group4Title, button7)

        group5Title = toga.Label('Fuzzy Matching of Data')

        def b8callback(button):
            self.openNotebook(self, "Fuzzy Matching of data.ipynb")
            pass

        button8 = toga.Button('Fuzzy Data Matching',
                              style=Pack(height=20, padding=13),
                              on_press=b8callback)
        scroll_box.add(group5Title, button8)

        group6Title = toga.Label('Neural Networking:')

        def b9callback(button):
            self.openNotebook(self, "Neural Network1.ipynb")
            pass

        button9 = toga.Button('Neural Networks 1',
                              style=Pack(height=20, padding=13),
                              on_press=b9callback)

        def b15callback(button):
            self.openNotebook(self, "Neural Network2.ipynb")
            pass

        button15 = toga.Button('Neural Networks 2',
                               style=Pack(height=20, padding=13),
                               on_press=b15callback)

        def b16callback(button):
            self.openNotebook(self, "Neural Network 3.ipynb")
            pass

        button16 = toga.Button('Neural Networks 3',
                               style=Pack(height=20, padding=13),
                               on_press=b16callback)
        scroll_box.add(group6Title, button9, button15, button16)

        group7Title = toga.Label('Spark')

        def b10callback(button):
            self.openNotebook(self, "Using Spark.ipynb")
            pass

        button10 = toga.Button('Massively Parallel Programming with Spark',
                               style=Pack(height=20, padding=13),
                               on_press=b10callback)
        scroll_box.add(group7Title, button10)

        group8Title = toga.Label('Extra')
        openJupyterButton = toga.Button('Turn on Jupyter',
                                        style=Pack(height=20, padding=13),
                                        on_press=self.startJupyterNotebook)
        closeJupyterButton = toga.Button('Close on Jupyter',
                                         style=Pack(height=20, padding=13),
                                         on_press=self.closeJupyterNotebook)
        scroll_box.add(group8Title, openJupyterButton, closeJupyterButton)

        scroll_view = toga.ScrollContainer(content=scroll_box,
                                           style=Pack(padding=10))
        main_box.add(scroll_view)

        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = main_box
        self.main_window.show()
Exemple #13
0
    def startup(self):
        # Window class
        #   Main window of the application with title and size
        self.main_window = toga.MainWindow(self.name, size=(640, 480))
        self.main_window.app = self

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

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

        right_content = toga.Box(
            style=CSS(flex_direction='column', padding_top=50))

        for b in range(0, 10):
            right_content.add(
                toga.Button('Hello world %s' % b,
                            on_press=button_handler,
                            style=CSS(width=200, margin=20)))

        right_container = toga.ScrollContainer(horizontal=False)

        right_container.content = right_content

        split = toga.SplitContainer()

        split.content = [left_container, right_container]

        things = toga.Group('Things')

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

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

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

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

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

        # Show the main window
        self.main_window.show()
Exemple #14
0
def build(app):
    path = os.path.dirname(os.path.abspath(__file__))
    brutus_icon = os.path.join(path, "icons", "brutus.icns")
    cricket_icon = os.path.join(path, "icons", "cricket-72.png")

    data = [
        ('root%s' % i, 'value %s' % i)
        for i in range(1, 100)
    ]

    left_container = toga.Table(headings=['Hello', 'World'], data=data)

    right_content = toga.Box(
        style=Pack(direction=COLUMN, padding_top=50)
    )

    for b in range(0, 10):
        right_content.add(
            toga.Button(
                'Hello world %s' % b,
                on_press=button_handler,
                style=Pack(width=200, padding=20)
            )
        )

    right_container = toga.ScrollContainer(horizontal=False)

    right_container.content = right_content

    split = toga.SplitContainer()

    split.content = [left_container, right_container]

    things = toga.Group('Things')

    cmd0 = toga.Command(
        action0,
        label='Action 0',
        tooltip='Perform action 0',
        icon=brutus_icon,
        group=things
    )
    cmd1 = toga.Command(
        action1,
        label='Action 1',
        tooltip='Perform action 1',
        icon=brutus_icon,
        group=things
    )
    cmd2 = toga.Command(
        action2,
        label='Action 2',
        tooltip='Perform action 2',
        icon=toga.Icon.TIBERIUS_ICON,
        group=things
    )
    cmd3 = toga.Command(
        action3,
        label='Action 3',
        tooltip='Perform action 3',
        icon=cricket_icon
    )

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

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

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

    return split
    def setUp(self):
        super().setUp()

        self.sc = toga.ScrollContainer(style=TestStyle(),
                                       factory=toga_dummy.factory)
Exemple #16
0
    def setUp(self):
        super().setUp()

        self.sc = toga.ScrollContainer(factory=toga_dummy.factory)
Exemple #17
0
def build(app):
    level1_icon = "icons/chicken-level1.png"
    level2_icon = "icons/cat-level2.png"
    level3_icon = "icons/fox-level3.png"
    level4_icon = "icons/lion-level4.png"
    level5_icon = "icons/tiger-level5.png"

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

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

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

    right_container.content = right_content

    split = toga.SplitContainer()

    split.content = [left_container, right_container]

    levels = toga.Group('Levels')

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

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

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

    return split
Exemple #18
0
    def __init__(self, fitting_data: FittingData, font_size: FontSize,
                 app: toga.App):
        """Initialize window."""
        super().__init__(title="Choose Records", size=RECORD_WINDOW_SIZE)
        self.__fitting_data = fitting_data
        main_box = toga.Box(style=Pack(direction=COLUMN))
        data_box = toga.Box()
        statistics_box = toga.Box()
        font_size_value = FontSize.get_font_size(font_size)
        self.__update_on_check = True
        self.__statistics_labels = {
            (column, parameter): toga.Label(
                text=to_relevant_precision_string(
                    getattr(fitting_data.statistics(column), parameter, 0)),
                style=Pack(height=LINE_HEIGHT,
                           width=COLUMN_WIDTH,
                           font_size=font_size_value),
            )
            for column, parameter in itertools.product(
                fitting_data.all_columns, Statistics.parameters())
        }
        self.__checkboxes = [
            toga.Switch(
                label="",
                is_on=fitting_data.is_selected(i),
                on_toggle=self.select_records,
                style=Pack(height=LINE_HEIGHT,
                           width=COLUMN_WIDTH,
                           font_size=font_size_value),
            ) for i in range(1, fitting_data.length + 1)
        ]
        self.__all_checkbox = toga.Switch(
            label="",
            is_on=self.are_all_selected(),
            on_toggle=self.select_all,
            style=Pack(height=TITLES_LINE_HEIGHT, font_size=font_size_value),
        )
        self.__selected_records_label = toga.Label(
            text="",
            style=Pack(font_size=font_size_value,
                       width=COLUMN_WIDTH,
                       height=TITLES_LINE_HEIGHT),
        )
        data_box.add(
            toga.Box(
                style=Pack(
                    flex=1,
                    direction=COLUMN,
                    padding_left=SMALL_PADDING,
                    padding_right=SMALL_PADDING,
                ),
                children=[
                    toga.Box(
                        style=Pack(
                            height=TITLES_LINE_HEIGHT,
                            font_size=font_size_value,
                        ),
                        children=[
                            self.__all_checkbox, self.__selected_records_label
                        ],
                    ),
                    *self.__checkboxes,
                ],
            ))
        for header, column in fitting_data.data.items():
            data_box.add(
                toga.Box(
                    style=Pack(
                        flex=1,
                        direction=COLUMN,
                        padding_left=SMALL_PADDING,
                        padding_right=SMALL_PADDING,
                    ),
                    children=[
                        toga.Label(
                            text=header,
                            style=Pack(
                                height=TITLES_LINE_HEIGHT,
                                width=COLUMN_WIDTH,
                                font_size=font_size_value,
                                font_weight=BOLD,
                            ),
                        ),
                        *[
                            toga.Label(
                                text=to_relevant_precision_string(element),
                                style=Pack(
                                    height=LINE_HEIGHT,
                                    width=COLUMN_WIDTH,
                                    font_size=font_size_value,
                                ),
                            ) for element in column
                        ],
                    ],
                ))
        main_box.add(data_box)
        main_box.add(toga.Divider())
        statistics_box.add(
            toga.Box(
                style=Pack(
                    flex=1,
                    direction=COLUMN,
                    padding_left=SMALL_PADDING,
                    padding_right=SMALL_PADDING,
                ),
                children=[
                    toga.Label(
                        text=parameter.replace("_", " ").title(),
                        style=Pack(
                            height=LINE_HEIGHT,
                            width=COLUMN_WIDTH,
                            font_size=font_size_value,
                            font_weight=BOLD,
                        ),
                    ) for parameter in Statistics.parameters()
                ],
            ))
        for header, column in fitting_data.data.items():
            statistics_box.add(
                toga.Box(
                    style=Pack(
                        flex=1,
                        direction=COLUMN,
                        padding_left=SMALL_PADDING,
                        padding_right=SMALL_PADDING,
                    ),
                    children=[
                        self.__statistics_labels[(header, parameter)]
                        for parameter in Statistics.parameters()
                    ],
                ))
        main_box.add(statistics_box)
        main_box.add(
            LineBox(children=[
                toga.Button(label="Close", on_press=lambda _: self.close())
            ], ))
        scroller = toga.ScrollContainer(content=main_box)
        self.content = scroller
        self.app = app

        self.update()
Exemple #19
0
    def startup(self):

        self.button_hide = toga.Button(
            label='Hide label',
            style=Pack(padding=10, width=120),
            on_press=self.hide_label,
        )

        self.button_add = toga.Button(
            label='Add image',
            style=Pack(padding=10, width=120),
            on_press=self.add_image,
        )

        self.button_remove = toga.Button(
            label='Remove image',
            style=Pack(padding=10, width=120),
            on_press=self.remove_image,
            enabled=False,
        )

        self.button_insert = toga.Button(
            label='Insert image',
            style=Pack(padding=10, width=120),
            on_press=self.insert_image,
        )

        self.button_reparent = toga.Button(
            label='Reparent image',
            style=Pack(padding=10, width=120),
            on_press=self.reparent_image,
            enabled=False,
        )

        self.button_add_to_scroll = toga.Button(
            label='Add new label',
            style=Pack(padding=10, width=120),
            on_press=self.add_label,
        )

        self.scroll_box = toga.Box(children=[],
                                   style=Pack(direction=COLUMN,
                                              padding=10,
                                              flex=1))
        self.scroll_view = toga.ScrollContainer(content=self.scroll_box,
                                                style=Pack(width=120))

        image = toga.Image('resources/tiberius.png')
        self.image_view = toga.ImageView(image,
                                         style=Pack(padding=10,
                                                    width=60,
                                                    height=60))

        # this tests adding children during init, before we have an implementation
        self.button_box = toga.Box(
            children=[
                self.button_hide,
                self.button_add,
                self.button_insert,
                self.button_reparent,
                self.button_remove,
                self.button_add_to_scroll,
            ],
            style=Pack(direction=COLUMN),
        )

        self.box = toga.Box(children=[],
                            style=Pack(direction=ROW,
                                       padding=10,
                                       alignment=CENTER,
                                       flex=1))

        # this tests adding children when we already have an impl but no window or app
        self.box.add(self.button_box)
        self.box.add(self.scroll_view)

        # add a couple of labels to get us started
        self.labels = []
        for i in range(3):
            self.add_label()

        self.main_window = toga.MainWindow()
        self.main_window.content = self.box
        self.main_window.show()
    def setUp(self):
        self.factory = MagicMock()
        self.factory.ScrollContainer = MagicMock(return_value=MagicMock(
            spec=toga_dummy.factory.ScrollContainer))

        self.sc = toga.ScrollContainer(factory=self.factory)
Exemple #21
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()