示例#1
0
    def startup(self):
        self.main_window = toga.MainWindow(title=self.name)

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

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

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

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

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

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

        self.xmp_text = toga.MultilineTextInput(
            style=Pack(width=270, height=350, padding=5)
            )
        self.xmp_button = toga.Button(
            'Save XMP',
            on_press=self.save_xmp,
            style=Pack(width=250, alignment=CENTER)
            )
        self.xmp_box = toga.Box(
            children=[self.xmp_text, self.xmp_button],
            style=Pack(direction=COLUMN)
        )
        results_pane.add('XMP', self.xmp_box)
        return results_pane
示例#3
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()
        main_box.style.update(direction=COLUMN, padding_top=10)
        self.poetry_box = toga.MultilineTextInput(
            readonly=True,
            style=Pack(flex=1,
                       padding=(10, 10, 10, 10),
                       font_size=42,
                       font_family="Helvetica"),
        )
        self.poetry_box.value = "Loading..."

        main_box.add(self.poetry_box)

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

        self.add_background_task(self.fetch_poem)
示例#4
0
    def create_export(self, button):
        data = {
            'domains': {},
            'browsers': self.browsers,
            'days': self.days,
            'times': self.times,
            'participant_code': self.pseudonym.value
        }
        i = 0
        history = self.history
        for row in self.unmasked_data:
            if row['domain'] in self.hidden_domains:
                key = f'[verborgen_{i}]'
                history['domain'].replace(to_replace=row['domain'],
                                          value=f'[verborgen_{i}]',
                                          inplace=True)
                i += 1
            elif row['domain'] == '':
                key = 'N/A'
            else:
                key = str(row['domain'])
            data['domains'][key] = row['visits']

        if button.id == "preview":
            try:
                for i in range(len(self.preview.children)):
                    self.preview.remove(self.preview.children[0])
            except IndexError:
                pass
            self.preview.add(
                toga.MultilineTextInput(initial=str(yaml.dump(data)),
                                        readonly=True,
                                        style=small_font_flex))

            self.preview.add(
                toga.MultilineTextInput(initial=history.to_string(
                    index=False, header=['Zeit', 'Domain']),
                                        readonly=True,
                                        style=small_font_flex))
            self.preview.add(
                toga.Label('Nur exakt diese Daten werden erfasst.'))
            self.preview.add(self.export_button())
            # self.preview.refresh()

        self.data = data
示例#5
0
    def setUp(self):
        super().setUp()

        self.initial = 'Super Multiline Text'
        self.on_change = mock.Mock()
        self.multiline = toga.MultilineTextInput(
            initial=self.initial,
            on_change=self.on_change,
            factory=toga_dummy.factory,
        )
示例#6
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()
示例#7
0
文件: app.py 项目: xmonader/toga
    def startup(self):
        self.main_window = toga.MainWindow(title=self.name)

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

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

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

        self.main_window.content = outer_box
        self.main_window.show()
示例#8
0
    def make_codebox():
        code_box = toga.Box(style=CSS(flex=1))
        with open('make_a_window.py') as f:
            code_text = toga.MultilineTextInput(
                initial=f.read(),
                readonly=True,
                style=CSS(flex=1),
            )
        code_box.add(code_text)

        return code_box
示例#9
0
    def attribution_pane(self):
        self.license_text = toga.Label(text="Your selected license", style=Pack(flex=1))
        self.attribution_text = toga.MultilineTextInput(
            initial="No license selected",
            readonly=True,
            style=Pack(height=50, padding_top=10)
            )

        return toga.Box(
            children=[self.license_text, self.attribution_text],
            style=Pack(direction=COLUMN, padding=10)
            )
示例#10
0
    def _library_section(self) -> toga.Widget:
        desc = "Choose HumbleBundle game types to be shown in your GOG Galaxy library."
        source_help = {
            SOURCE.DRM_FREE:
            "Games from www.humblebundle.com/home/library that have direct download for Windows, Mac or Linux",
            SOURCE.TROVE:
            "Games from Humble Trove games (requires to be an active or past subscriber).",
            SOURCE.KEYS:
            "Game keys to be redeemed in foreign services like Steam or Origin."
        }
        show_revealed_help = 'Check to show all game keys as separate games.\n' \
            'Uncheck to show only game keys that are already revealed\n' \
            '(redeemed keys are usually reported by other Galaxy plugins).'

        description = toga.Label(desc,
                                 style=Pack(font_size=self.TEXT_SIZE_BIG,
                                            padding_bottom=12))
        rows = [description]
        self.show_revealed_sw = toga.Switch(
            'show_revealed_keys',
            on_toggle=self._on_revealed_switch,
            is_on=self._cfg.library.show_revealed_keys,
            enabled=SOURCE.KEYS in self._cfg.library.sources,
            style=Pack(padding_left=20, padding_top=2))
        for s in SOURCE:
            sw = toga.Switch(s.value,
                             on_toggle=self._on_source_switch,
                             is_on=(s in self._cfg.library.sources))
            sw.style.padding_bottom = 2
            set_tooltip(sw, source_help[s])
            rows.append(sw)
        set_tooltip(self.show_revealed_sw, show_revealed_help)
        rows.append(self.show_revealed_sw)

        if IS_MAC:  # workaround for not working tooltip
            inp = toga.MultilineTextInput(readonly=True,
                                          style=Pack(padding_top=10))
            inp.MIN_WIDTH = self.SIZE[0] - 50
            for k, v in source_help.items():
                inp.value += f'{k.value}: {v}\n'
            inp.value += f'show_revealed_help: {show_revealed_help}'
            rows.append(inp)

        lib_box = toga.Box(children=rows)
        lib_box.style.direction = 'column'
        lib_box.style.padding_bottom = 15
        return lib_box
示例#11
0
    def _news_section(self) -> toga.Widget:
        margin = 15
        box = toga.Box()
        box.style.padding_bottom = margin

        try:
            with open(self._changelog_path, 'r') as f:
                changelog = f.read()
        except FileNotFoundError as e:
            changelog = str(e)
        text_box = toga.MultilineTextInput(readonly=True)
        text_box.MIN_WIDTH = self.SIZE[0] - (2 * margin)
        text_box.MIN_HEIGHT = self.SIZE[1] - (2 * margin)
        text_box.value = changelog

        box.add(text_box)
        return box
示例#12
0
    def startup(self):
        self.main_window = toga.MainWindow(title=self.name)

        self.box = toga.Box('box1')
        # self.textinput = toga.MultilineTextInput('input1', style=Pack(flex=1))
        self.textinput = toga.MultilineTextInput('input1', style=None)

        # load file here
        # Need to deal with the file path later
        with open('notebook1.txt', 'r') as f:
            self.textinput.value = f.read()

        self.box.add(self.textinput)

        self.on_exit = self.save_file

        self.main_window.content = self.box
        self.main_window.show()
示例#13
0
文件: app.py 项目: cr2d20/AGU_POC
    def enter_cust_details(self, widget):
        name_label = toga.Label('Customer name: ', style=Pack(padding=(10, 2)))
        self.name_input = toga.TextInput(style=Pack(flex=1))

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

        # Phone number
        phone_label = toga.Label('Phone Number: ', style=Pack(padding=(10, 5)))
        self.phone_input = toga.TextInput(style=Pack(flex=1))

        phone_box = toga.Box(style=Pack(direction=ROW, padding=5))
        phone_box.add(phone_label)
        phone_box.add(self.phone_input)

        # Email
        email_label = toga.Label('Email: ', style=Pack(padding=(10, 5)))
        self.email_input = toga.TextInput(style=Pack(flex=1))

        email_box = toga.Box(style=Pack(direction=ROW, padding=5))
        email_box.add(email_label)
        email_box.add(self.email_input)

        # City
        city_label = toga.Label('City: ', style=Pack(padding=(10, 5)))
        self.city_input = toga.TextInput(style=Pack(flex=1))

        # Country
        country_label = toga.Label('Country: ', style=Pack(padding=(10, 5)))
        self.country_input = toga.TextInput(style=Pack(flex=1))

        country_box = toga.Box(style=Pack(direction=ROW, padding=5))
        country_box.add(city_label)
        country_box.add(self.city_input)
        country_box.add(country_label)
        country_box.add(self.country_input)

        # Adress
        address_label = toga.Label('Address: ', style=Pack(padding=(10, 5)))
        self.add_input = toga.MultilineTextInput(style=Pack(flex=1))

        add_box = toga.Box(style=Pack(direction=ROW, padding=5))
        add_box.add(address_label)
        add_box.add(self.add_input)

        # Requirement
        req_label = toga.Label('Requirement: ', style=Pack(padding=(10, 5)))
        self.req_input = toga.MultilineTextInput(style=Pack(flex=1))

        req_box = toga.Box(style=Pack(direction=ROW, padding=5))
        req_box.add(req_label)
        req_box.add(self.req_input)

        # Nature of Business
        nob_label = toga.Label('Nature of Business: ',
                               style=Pack(padding=(10, 5)))
        self.nob_input = toga.MultilineTextInput(style=Pack(flex=1))

        nob_box = toga.Box(style=Pack(direction=ROW, padding=5))
        nob_box.add(nob_label)
        nob_box.add(self.nob_input)

        # Notes
        note_label = toga.Label('Notes: ', style=Pack(padding=(10, 5)))
        self.note_input = toga.MultilineTextInput(style=Pack(flex=1))

        note_box = toga.Box(style=Pack(direction=ROW, padding=5))
        note_box.add(note_label)
        note_box.add(self.note_input)

        # Follow Up
        followup_label = toga.Label('Follow Up: ', style=Pack(padding=(10, 5)))
        self.followup_input = toga.TextInput(style=Pack(flex=1))

        followup_box = toga.Box(style=Pack(direction=ROW, padding=5))
        followup_box.add(followup_label)
        followup_box.add(self.followup_input)

        button = toga.Button('Save',
                             on_press=self.save,
                             style=Pack(padding_top=25,
                                        width=100,
                                        alignment=CENTER))

        main_box = toga.Box(
            children=[
                name_box, phone_box, email_box, add_box, country_box, req_box,
                nob_box, note_box, button
            ],
            style=Pack(padding=50,
                       padding_top=50,
                       direction=COLUMN,
                       alignment=CENTER),
        )

        self.secondary_window = toga.Window(title="New Customer details")
        self.secondary_window.content = main_box
        self.secondary_window.show()
    def setUp(self):
        super().setUp()

        self.initial = 'Super Multiline Text'
        self.multiline = toga.MultilineTextInput(initial=self.initial,
                                                 factory=toga_dummy.factory)
示例#15
0
    def startup(self):
        """
        Construct and show the Toga application.
        """
        main_box = toga.Box(style=Pack(direction=COLUMN))

        input_box = toga.Box(style=Pack(direction=ROW))
        input_folder = toga.TextInput(readonly=True)
        input_folder.style.update(flex=1)

        output_box = toga.Box(style=Pack(direction=ROW))
        output_folder = toga.TextInput(readonly=True)
        output_folder.style.update(flex=1)

        console_box = toga.Box(style=Pack(direction=ROW))
        direc = str(os.getcwd())
        console = toga.MultilineTextInput(readonly=True, initial=f"Now in {direc}")
        console.style.update(flex=1)

        def update_console(text):
            console.value += "\n" + text

        self.main_window = toga.MainWindow(title=self.formal_name, size=(300, 300))

        def get_input_folder(widget):
            self.in_folder = self.main_window.select_folder_dialog('select folder to sort', initial_directory=os.getcwd())
            self.in_folder = Path(self.in_folder[0])
            input_folder.value = self.in_folder
            update_console(f"Input folder set to {self.in_folder}")

        def get_output_folder(widget):
            self.out_folder = self.main_window.select_folder_dialog('select output location', initial_directory=os.getcwd())
            self.out_folder = Path(self.out_folder[0])
            output_folder.value = self.out_folder
            update_console(f"Output folder set to {self.out_folder}")

        def classify_and_move(widget):            
            try:
                create_folders(self.out_folder)
            except:
                update_console("Problem creating the output location -- did you pick a destination folder?")
                return
            
            try:
                pictures = get_files(self.in_folder, extensions=image_extensions, recurse=True)
            except Exception as e:
                update_console(f"{e}")
                return
            
            try:
                classify(pictures, self.out_folder)
                update_console("Done!")
            except Exception as e:
                update_console("There was a problem :(")
                update_console(f"{e}")
            
            


        select_input_folder_button = toga.Button(
            'Select folder to sort',
            on_press=get_input_folder,
            style=Pack(padding=(0, 10))
        )

        select_output_folder_button = toga.Button(
            'Select destination folder',
            on_press=get_output_folder,
            style=Pack(padding=(0, 10))
        )
       
        classify_button = toga.Button(
            'Classify',
            on_press=classify_and_move,
            style=Pack(padding=(10, 200))
        )
        
        input_box.add(select_input_folder_button)
        input_box.add(input_folder)
        input_box.style.update(padding=(10, 20))

        output_box.add(select_output_folder_button)
        output_box.add(output_folder)
        output_box.style.update(padding=(10, 20))

        console_box.add(console)
        console_box.style.update(padding=(10, 20))
        
        main_box.add(input_box)
        main_box.add(output_box)
        main_box.add(classify_button)
        main_box.add(console_box)


        self.main_window.content = main_box
        self.main_window.show()
示例#16
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))
        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()
示例#17
0
文件: app.py 项目: xmonader/toga
    def startup(self):

        # ==== Set up main window ======================================================

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

        # Label for user instructions
        label = toga.Label(
            "Please select an example to run",
            style=Pack(padding_bottom=10),
        )

        # ==== Table with examples =====================================================

        self.examples = []

        # search for all folders that contain modules
        for root, dirs, files in os.walk(examples_dir):
            # skip hidden folders
            dirs[:] = [d for d in dirs if not d.startswith(".")]
            if any(name == "__main__.py" for name in files):
                path = Path(root)
                self.examples.append(dict(name=path.name, path=path.parent))

        self.examples.sort(key=lambda e: e["path"])

        self.table = toga.Table(
            headings=["Name", "Path"],
            data=self.examples,
            on_double_click=self.run,
            on_select=self.on_example_selected,
            style=Pack(padding_bottom=10, flex=1),
        )

        # Buttons
        self.btn_run = toga.Button(
            "Run Example", on_press=self.run, style=Pack(flex=1, padding_right=5)
        )
        self.btn_open = toga.Button(
            "Open folder", on_press=self.open, style=Pack(flex=1, padding_left=5)
        )

        button_box = toga.Box(children=[self.btn_run, self.btn_open])

        # ==== View of example README ==================================================

        self.info_view = toga.MultilineTextInput(
            placeholder="Please select example", readonly=True, style=Pack(padding=1)
        )

        # ==== Assemble layout =========================================================

        left_box = toga.Box(
            children=[self.table, button_box],
            style=Pack(
                direction=COLUMN,
                padding=1,
                flex=1,
            ),
        )

        split_container = toga.SplitContainer(content=[left_box, self.info_view])

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

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

        # Show the main window
        self.main_window.show()
示例#18
0
    def on_update(self):
        global __VERSION__
        latest = updater.getLatestRelease()
        if latest['version'] <= __VERSION__:
            self.main_window.info_dialog(title="Information", message="No update available.")
            return
        self.update_window = toga.Window(title="Update", size=(400,100))

        textbox = toga.MultilineTextInput(readonly=True, style=Pack(flex=1))
        textbox.value = latest['notes']

        progress_bar = toga.ProgressBar(max=latest['size'], value=0)

        btn_update_now = None

        def on_btn_click_later(e):
            self.update_window._impl.close()

        def on_btn_click_now(e):
            btn_update_now.enabled = False
            def addBarValue(v):
                progress_bar.value += v
            def thread_update_task():
                bundlePath = updater.getBundlePath()
                response = requests.get(latest['url'], verify=False, stream=True)
                progress_value = 0
                tempFolder = tempfile.TemporaryDirectory()
                with open(tempFolder.name + "/patch.zip", "wb") as f:
                    for chunk in response.iter_content(chunk_size=1024):
                        if chunk:
                            f.write(chunk)
                            PyObjCTools.AppHelper.callAfter(addBarValue, 1024)

                zip_ref = updater.MyZipFile(tempFolder.name + "/patch.zip", 'r')
                zip_ref.extractall(tempFolder.name + "/patches/")
                zip_ref.close()
                shutil.rmtree(bundlePath)
                shutil.copytree(tempFolder.name + "/patches/LeagueFriend.app", bundlePath)
                tempFolder.cleanup()
                os.system('open -n "{}"'.format(bundlePath))
                self.exit()
            t = threading.Thread(target=thread_update_task)
            t.start()
            




        btn_update_now = toga.Button(label="Update Now", on_press=on_btn_click_now, style=Pack(padding_left="50"))
        btn_update_later = toga.Button(label="Later", on_press=on_btn_click_later, style=Pack(padding_left="10"))

        self.update_window.content = toga.Box(children=[
                toga.Box(children=[
                        toga.Label(text="New update available.", style=Pack(padding_bottom="20", padding_left="5")),
                        btn_update_now,
                        btn_update_later
                    ], style=Pack(direction=ROW, flex=1)),
                toga.Label(text="Release Notes:", style=Pack(padding_bottom="5", padding_left="5")),
                textbox,
                progress_bar
            ], style=Pack(direction=COLUMN, flex=1, padding="10"))

        self.update_window.show()
示例#19
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(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()
示例#20
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()
示例#21
0
    def setUp(self):
        self.factory = MagicMock()
        self.factory.MultilineTextInput = MagicMock(return_value=MagicMock(spec=toga_dummy.widgets.multilinetextinput.MultilineTextInput))

        self.initial = 'Super Multiline Text'
        self.multiline = toga.MultilineTextInput(self.initial, factory=self.factory)
示例#22
0
    def _setup_right_frame(self):
        '''
        The right frame is basically the "output viewer" space
        '''
        # Box to show the detail of a test
        self.right_box = toga.Box(style=Pack(direction=COLUMN, padding=(10, 0)))

        # Initial status for coverage
        self.coverage = False
        # Checkbutton to change the status for coverage
        # self.coverage_checkbox = toga.Switch('Generate coverage', on_toggle=self.on_coverageChange)

        # If coverage is available, enable it by default.
        # Otherwise, disable the widget
        if not coverage:
            self.coverage = False
            # self.coverage_checkbox.enabled = False

        # Label for indicator status of test
        self.status_label = toga.Label(
            '',
            style=Pack(
                text_align=CENTER,
                width=60,
                padding_right=10,
                font_family=SANS_SERIF,
                font_weight=BOLD,
                font_size=40,
            )
        )

        # Box to put the name of the test
        self.name_box = toga.Box(style=Pack(direction=ROW, padding=(5, 10)))
        # Label to indicate that the next input text it will be the name
        self.name_label = toga.Label(
            'Name:', style=Pack(text_align=RIGHT, width=80, padding_right=10)
        )
        # Text input to show the name of the test
        self.name_view = toga.TextInput(readonly=True, style=Pack(flex=1))
        # Insert the name box objects
        self.name_box.add(self.name_label)
        self.name_box.add(self.name_view)

        # Box to put the test duration
        self.duration_box = toga.Box(style=Pack(direction=ROW, padding=(5, 10)))
        # Label to indicate the test duration
        self.duration_label = toga.Label(
            'Duration:', style=Pack(text_align=RIGHT, width=80, padding_right=10)
        )
        # Text input to show the test duration
        self.duration_view = toga.TextInput(readonly=True, style=Pack(flex=1))
        self.duration_box.add(self.duration_label)
        self.duration_box.add(self.duration_view)

        # Group the name and duration into a single "identifier" box
        self.identifier_box = toga.Box(style=Pack(direction=COLUMN, flex=1))
        self.identifier_box.add(self.name_box)
        self.identifier_box.add(self.duration_box)

        # Put the identifiers on the same row as the status label
        self.summary_box = toga.Box(style=Pack(direction=ROW, alignment=CENTER))
        self.summary_box.add(self.identifier_box)
        self.summary_box.add(self.status_label)

        # Box to put the test description
        self.description_box = toga.Box(style=Pack(direction=ROW, padding=(5, 10), flex=1))
        # Label to indicate the test description
        self.description_label = toga.Label(
            'Description:', style=Pack(text_align=RIGHT, width=80, padding_right=10)
        )
        # Text input to show the test description
        self.description_view = toga.MultilineTextInput(style=Pack(flex=1))
        # Insert the test description box objects
        self.description_box.add(self.description_label)
        self.description_box.add(self.description_view)

        # Box to put the test output
        self.output_box = toga.Box(style=Pack(direction=ROW, padding=(5, 10), flex=3))
        # Label to indicate the test output
        self.output_label = toga.Label(
            'Output:', style=Pack(text_align=RIGHT, width=80, padding_right=10)
        )
        # Text input to show the test output
        self.output_view = toga.MultilineTextInput(style=Pack(flex=1))
        # Insert the test output box objects
        self.output_box.add(self.output_label)
        self.output_box.add(self.output_view)

        # Box to put the test error
        self.error_box = toga.Box(style=Pack(direction=ROW, padding=(5, 10), flex=3))
        # Label to indicate the test error
        self.error_label = toga.Label(
            'Error:', style=Pack(text_align=RIGHT, width=80, padding_right=10)
        )
        # Text input to show the test error
        self.error_view = toga.MultilineTextInput(style=Pack(flex=1))
        # Insert the test error box objects
        self.error_box.add(self.error_label)
        self.error_box.add(self.error_view)

        # Insert the right box contents
        # self.right_box.add(self.coverage_checkbox)
        self.right_box.add(self.summary_box)
        self.right_box.add(self.description_box)
        self.right_box.add(self.output_box)
        self.right_box.add(self.error_box)
示例#23
0
文件: app.py 项目: obulat/toga
    def startup(self):
        brutus_icon_256 = "resources/brutus-256"
        cricket_icon_256 = "resources/cricket-256"
        tiberius_icon_256 = "resources/tiberius-256"

        # Set up main window
        self.main_window = toga.MainWindow(title=self.name)

        # Add commands
        print('adding commands')
        # 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(self.action0,
                            label='Action 0',
                            tooltip='Perform action 0',
                            icon=brutus_icon_256,
                            group=things)
        cmd1 = toga.Command(self.action1,
                            label='Action 1',
                            tooltip='Perform action 1',
                            icon=brutus_icon_256,
                            group=things)
        cmd2 = toga.Command(self.action2,
                            label='TB Action 2',
                            tooltip='Perform toolbar action 2',
                            icon=brutus_icon_256,
                            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(self.action3,
                            label='Action 3',
                            tooltip='Perform action 3',
                            shortcut=toga.Key.MOD_1 + 'k',
                            icon=cricket_icon_256,
                            group=toga.Group.COMMANDS,
                            order=4)

        # 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=1)
        cmd5 = toga.Command(
            self.action5,
            label='TB Action 5',
            tooltip='Perform toolbar action 5',
            order=2,
            group=sub_menu
        )  # there is deliberately no icon to show that a toolbar action also works with text
        cmd6 = toga.Command(self.action6,
                            label='Action 6',
                            tooltip='Perform action 6',
                            order=1,
                            icon=cricket_icon_256,
                            group=sub_menu)
        cmd7 = toga.Command(self.action7,
                            label='TB action 7',
                            tooltip='Perform toolbar action 7',
                            order=30,
                            icon=tiberius_icon_256,
                            group=sub_menu)

        def action4(widget):
            print("action 4")
            cmd3.enabled = not cmd3.enabled
            self.textpanel.value += 'action 4\n'

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

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

        # Buttons
        btn_style = Pack(flex=1)
        btn_do_stuff = toga.Button('Do stuff',
                                   on_press=self.do_stuff,
                                   style=btn_style)
        btn_clear = toga.Button('Clear',
                                on_press=self.do_clear,
                                style=btn_style)
        btn_box = toga.Box(children=[btn_do_stuff, btn_clear],
                           style=Pack(direction=ROW))

        self.textpanel = toga.MultilineTextInput(readonly=False,
                                                 style=Pack(flex=1),
                                                 placeholder='Ready.')

        # Outermost box
        outer_box = toga.Box(children=[btn_box, self.textpanel],
                             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()