def test_set_background_color(self): color = '#ffffff' root = TestNode('app', style=Pack(background_color=color)) root.style.reapply() root._impl.set_background_color.assert_called_once_with( rgb(255, 255, 255))
def test_set_visibility_hidden(self): root = TestNode('app', style=Pack(visibility=HIDDEN)) root.style.reapply() root._impl.set_hidden.assert_called_once_with(True)
def test_beeliza(self): root = TestNode('app', style=Pack(direction=COLUMN), children=[ TestNode('detailedlist', style=Pack(flex=1), size=(at_least(100), at_least(100))), TestNode('box', style=Pack(direction=ROW), children=[ TestNode('input', style=Pack(flex=1, padding=5), size=(at_least(100), 15)), TestNode('button', style=Pack(padding=5), size=(at_least(40), 10)), ]), ]) # Minimum size root.style.layout(root, TestViewport(0, 0, dpi=96)) self.assertLayout( root, (160, 125), { 'origin': (0, 0), 'content': (160, 125), 'children': [ { 'origin': (0, 0), 'content': (100, 100) }, { 'origin': (0, 100), 'content': (160, 25), 'children': [ { 'origin': (5, 105), 'content': (100, 15) }, { 'origin': (115, 105), 'content': (40, 10) }, ] }, ] }) # Normal size root.style.layout(root, TestViewport(640, 480, dpi=96)) self.assertLayout( root, (640, 480), { 'origin': (0, 0), 'content': (640, 480), 'children': [ { 'origin': (0, 0), 'content': (640, 455) }, { 'origin': (0, 455), 'content': (640, 25), 'children': [ { 'origin': (5, 460), 'content': (580, 15) }, { 'origin': (595, 460), 'content': (40, 10) }, ] }, ] }) # HiDPI Normal size root.style.layout(root, TestViewport(640, 480, dpi=144)) self.assertLayout( root, (640, 480), { 'origin': (0, 0), 'content': (640, 480), 'children': [ { 'origin': (0, 0), 'content': (640, 451) }, { 'origin': (0, 451), 'content': (640, 29), 'children': [ { 'origin': (7, 458), 'content': (572, 15) }, { 'origin': (593, 458), 'content': (40, 10) }, ] }, ] })
def test_set_center_alignment(self): root = TestNode('app', style=Pack(text_align='center')) root.style.reapply() root._impl.set_alignment.assert_called_once_with(CENTER)
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() split.content = [left_container, right_container] # 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
from toga.style.pack import Pack, COLUMN, ROW padding_10 = Pack(padding=10) padding_bottom_5 = Pack(padding_bottom=5) padding_top_5 = Pack(padding_top=5) column_dir = Pack(direction=COLUMN) flex1 = Pack(flex=1)
def __init__(self, app: toga.App) -> None: # noinspection PyTypeChecker super().__init__( title="Maestral Setup", size=(self.WINDOW_WIDTH, self.WINDOW_HEIGHT), resizeable=False, minimizable=False, app=app, ) # FIXME: remove private API access self._impl.native.titlebarAppearsTransparent = True self._impl.native.titleVisibility = 1 self._impl.native.styleMask |= NSFullSizeContentViewWindowMask self._impl.native.movableByWindowBackground = True self.current_page = 0 # ==== welcome page ============================================================ # noinspection PyTypeChecker self.image0 = toga.ImageView( self.app.icon, style=Pack(width=128, height=128, alignment=CENTER, padding=(40, 0, 40, 0)), ) self.label0 = Label( text="Welcome to Maestral, an open source Dropbox client.", style=Pack(width=self.WINDOW_WIDTH, padding_bottom=40, text_align=CENTER), ) self.btn_start = toga.Button("Link Dropbox Account", style=Pack(width=180)) self.welcome_page = toga.Box( children=[ self.image0, self.label0, self.btn_start, Spacer(COLUMN) ], style=self.page_style, ) # ==== link page =============================================================== # noinspection PyTypeChecker self.image1 = toga.ImageView(self.app.icon, style=Pack(width=64, height=64, padding=(40, 0, 40, 0))) self.label1 = Label( text=( "To link Maestral to your Dropbox account, please retrieve an " "authorization token from Dropbox and enter it below."), linebreak_mode=WORD_WRAP, style=Pack(width=self.CONTENT_WIDTH * 0.9, text_align=CENTER, padding_bottom=10), ) self.btn_auth_token = FollowLinkButton("Retrieve Token", style=Pack(width=125, padding_bottom=35)) self.text_field_auth_token = toga.TextInput( placeholder="Authorization Token", style=Pack( width=self.CONTENT_WIDTH * 0.9, text_align=CENTER, background_color=TRANSPARENT, ), ) self.spinner_link = toga.ActivityIndicator( style=Pack(width=32, height=32)) self.dialog_buttons_link_page = DialogButtons(labels=("Link", "Cancel"), style=self.btn_box_style) self.dialog_buttons_link_page["Link"].enabled = False self.link_page = toga.Box( children=[ self.image1, self.label1, self.btn_auth_token, self.text_field_auth_token, Spacer(COLUMN), self.spinner_link, Spacer(COLUMN), self.dialog_buttons_link_page, ], style=self.page_style, ) # ==== dbx location page ======================================================= # noinspection PyTypeChecker self.image2 = toga.ImageView(self.app.icon, style=Pack(width=64, height=64, padding=(40, 0, 40, 0))) self.dbx_location_label = Label( text= ("Maestral has been successfully linked with your Dropbox account.\n\n" "Please select a local folder for your Dropbox. If the folder is not " "empty, you will be given the option to merge its content with your " "remote Dropbox. Merging will not transfer or duplicate any identical " "files.\n\n" "In the next step, you will be asked to choose which folders to sync." ), linebreak_mode=WORD_WRAP, style=Pack( width=self.CONTENT_WIDTH, height=90, padding_bottom=20, text_align=CENTER, ), ) self.combobox_dbx_location = FileSelectionButton( initial=get_home_dir(), select_files=False, select_folders=True, show_full_path=True, style=Pack(width=self.CONTENT_WIDTH * 0.9, padding_bottom=20), ) self.dialog_buttons_location_page = DialogButtons( labels=("Select", "Cancel & Unlink"), style=self.btn_box_style) self.dbx_location_page = toga.Box( children=[ self.image2, self.dbx_location_label, self.combobox_dbx_location, Spacer(COLUMN), self.dialog_buttons_location_page, ], style=self.page_style, ) # ==== selective sync page ===================================================== self.label3 = Label( text= ("Please select which files and folders to sync below. The initial " "download may take some time, depending on the size of your Dropbox." ), linebreak_mode=WORD_WRAP, style=Pack(width=self.CONTENT_WIDTH, padding=(20, 0, 20, 0)), ) self.dropbox_tree = toga.Tree( headings=["Name", "Included"], accessors=["name", "included"], data=[], style=Pack(width=self.CONTENT_WIDTH, padding_bottom=20, flex=1), multiple_select=True, ) self.dialog_buttons_selective_sync_page = DialogButtons( labels=["Select", "Back"], style=self.btn_box_style, ) self.selective_sync_page = toga.Box( children=[ self.label3, self.dropbox_tree, self.dialog_buttons_selective_sync_page, ], style=self.page_style, ) # ==== done page =============================================================== # noinspection PyTypeChecker self.image4 = toga.ImageView( self.app.icon, style=Pack(width=128, height=128, alignment=CENTER, padding=(40, 0, 40, 0)), ) self.label4 = Label( text= ("You have successfully set up Maestral. Please allow some time for the " "initial indexing and download of your Dropbox before Maestral will " "commence syncing."), linebreak_mode=WORD_WRAP, style=Pack(width=self.CONTENT_WIDTH, text_align=CENTER, padding_bottom=50), ) self.close_button = toga.Button("Close", style=Pack(width=100), on_press=lambda s: self.close()) self.done_page = toga.Box( children=[ self.image4, self.label4, self.close_button, Spacer(COLUMN) ], style=self.page_style, ) self.pages = ( self.welcome_page, self.link_page, self.dbx_location_page, self.selective_sync_page, self.done_page, ) self.content = toga.Box(children=[self.pages[0]])
def test_tutorial_3(self): root = TestNode('app', style=Pack(direction=COLUMN), children=[ TestNode('box', style=Pack(), children=[ TestNode('input', style=Pack(flex=1, padding=5), size=(at_least(100), 15)), TestNode('button', style=Pack(width=50, padding=5), size=(at_least(40), 10)), ]), TestNode('web', style=Pack(flex=1), size=(at_least(100), at_least(100))), ]) # Minimum size root.style.layout(root, Viewport(0, 0, dpi=96)) self.assertLayout( root, (170, 125), { 'origin': (0, 0), 'content': (170, 125), 'children': [{ 'origin': (0, 0), 'content': (170, 25), 'children': [ { 'origin': (5, 5), 'content': (100, 15) }, { 'origin': (115, 5), 'content': (50, 10) }, ] }, { 'origin': (0, 25), 'content': (100, 100) }] }) # Normal size root.style.layout(root, Viewport(640, 480, dpi=96)) self.assertLayout( root, (640, 480), { 'origin': (0, 0), 'content': (640, 480), 'children': [{ 'origin': (0, 0), 'content': (640, 25), 'children': [ { 'origin': (5, 5), 'content': (570, 15) }, { 'origin': (585, 5), 'content': (50, 10) }, ] }, { 'origin': (0, 25), 'content': (640, 455) }] }) # HiDPI Normal size root.style.layout(root, Viewport(640, 480, dpi=144)) self.assertLayout( root, (640, 480), { 'origin': (0, 0), 'content': (640, 480), 'children': [{ 'origin': (0, 0), 'content': (640, 29), 'children': [ { 'origin': (7, 7), 'content': (537, 15) }, { 'origin': (558, 7), 'content': (75, 10) }, ] }, { 'origin': (0, 29), 'content': (640, 451) }] })
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
from maestral.utils.appdirs import get_home_dir # local imports from .private.widgets import ( Label, Spacer, DialogButtons, FollowLinkButton, FileSelectionButton, Window, ) from .private.constants import WORD_WRAP from .private.implementation.cocoa.constants import NSFullSizeContentViewWindowMask # set default font size to 13 pt, as in macOS Pack.validated_property("font_size", choices=FONT_SIZE_CHOICES, initial=13) class SetupDialogGui(Window): WINDOW_WIDTH = 550 WINDOW_HEIGHT = 400 CONTENT_WIDTH = WINDOW_WIDTH - 40 CONTENT_HEIGHT = WINDOW_HEIGHT - 15 - 25 page_style = Pack( width=WINDOW_WIDTH, height=WINDOW_HEIGHT, direction=COLUMN, alignment=CENTER,
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()
def startup(self): main_window = toga.MainWindow(title=self.name, size=(1000, 400)) def buttonStep_handler(widget): global model step = int(step_text.value) while step: model.tick() step -= 1 global avgServiceTime, avgLenQueue, clientDone, clientLeave, money if len(avgServiceTime) == 0: aST = "0" else: aST = str(round(stat.mean(avgServiceTime), 3)) if len(avgLenQueue) == 0: aLQ = "0" else: aLQ = str(round(stat.mean(avgLenQueue), 3)) money = money * int(profit_text.value) / 1000 #прибыль от покупок money = money - int(cashBoxNumber_text.value) * ( (int(salary_text.value) / 24) * (int(step_text.value) / 60)) #зарплаты кассиров money = money - (int(sale_text.value) / 24) * ( int(step_text.value) / 60) #затраты на рекламу table.data = [ ['Среднее время обслуживания', aST, 'мин'], ['Средняя длина очереди касс', aLQ, 'чел'], ['Кол-во обслуженных клиентов', str(clientDone), 'чел'], ['Количество потерянных клиентов', str(clientLeave), 'чел'], ['Общая прибыль', str(round(money, 3)), 'руб'] ] m = int(minute_label.text) + int(step_text.value) if m >= 60: if m - 60 == 0: minute_label.text = "00" else: minute_label.text = str(m - 60) h = int(hour_label.text) + 1 if h >= 24: if h - 24 == 0: hour_label.text = "00" else: hour_label.text = str(h - 24) if day_label.text == "пн": day_label.text = "вт" elif day_label.text == "вт": day_label.text == "ср" elif day_label.text == "ср": day_label.text == "чт" elif day_label.text == "чт": day_label.text == "пт" elif day_label.text == "пт": day_label.text == "сб" elif day_label.text == "сб": day_label.text == "вс" elif day_label.text == "вс": day_label.text == "конец" hour_label.text == "недели" minute_label.text == "" else: hour_label.text = str(h) else: minute_label.text = str(m) def buttonToEnd_handler(widget): print("hello") def buttonStop_handler(widget): print("hello") def buttonExit_handler(window): main_window.close() self.exit() def buttonBegin_handler(widget): global model model = Model(int(cashBoxNumber_text.value), int(maxQueueLen_text.value)) day_label.text = "пн" hour_label.text = "00" minute_label.text = "00" #блокировка полей cashBoxNumber_text.readonly = True maxQueueLen_text.readonly = True advert_text.readonly = True sale_text.readonly = True salary_text.readonly = True minExpense_text.readonly = True maxExpense_text.readonly = True loss_text.readonly = True profit_text.readonly = True step_text.readonly = True buttonBegin.enabled = False button1.enabled = False button2.enabled = False button3.enabled = False button4.enabled = False button5.enabled = False button6.enabled = False button7.enabled = False button8.enabled = False button9.enabled = False button10.enabled = False #обработчики полей для ввода def enter1(widget): print(cashBoxNumber_text.value) def enter2(widget): print(maxQueueLen_text.value) def enter3(widget): print(advert_text.value) def enter4(widget): print(sale_text.value) def enter5(widget): print(salary_text.value) def enter6(widget): print(minExpense_text.value) def enter7(widget): print(maxExpense_text.value) def enter8(widget): print(loss_text.value) def enter9(widget): print(profit_text.value) def enter10(widget): print(step_text.value) # поля для ввода info_box = toga.Box() cashBoxNumber_box = toga.Box(style=Pack(direction=ROW)) cashBoxNumber_text = toga.TextInput(initial="3", style=Pack(flex=2)) button1 = toga.Button("Ввести", style=Pack(flex=3), on_press=enter1) cashBoxNumber_label = toga.Label('Количество касс :', style=Pack(flex=1, text_align=RIGHT, width=210)) cashBoxNumber_box.add(cashBoxNumber_label, cashBoxNumber_text, button1) maxQueueLen_box = toga.Box(style=Pack(direction=ROW)) maxQueueLen_text = toga.TextInput(initial="3", style=Pack(flex=2)) button2 = toga.Button("Ввести", style=Pack(flex=3), on_press=enter2) maxQueueLen_label = toga.Label('Максимальная длина очереди :', style=Pack(flex=1, text_align=RIGHT, width=210)) maxQueueLen_box.add(maxQueueLen_label, maxQueueLen_text, button2) advert_box = toga.Box(style=Pack(direction=ROW)) advert_text = toga.TextInput(initial="7000", style=Pack(flex=2)) button3 = toga.Button("Ввести", style=Pack(flex=3), on_press=enter3) advert_label = toga.Label('Затраты на рекламу :', style=Pack(flex=1, text_align=RIGHT, width=210)) advert_box.add(advert_label, advert_text, button3) sale_box = toga.Box(style=Pack(direction=ROW)) sale_text = toga.TextInput(initial="15", style=Pack(flex=2)) button4 = toga.Button("Ввести", style=Pack(flex=3), on_press=enter4) sale_label = toga.Label('Размер скидки :', style=Pack(flex=1, text_align=RIGHT, width=210)) sale_box.add(sale_label, sale_text, button4) salary_box = toga.Box(style=Pack(direction=ROW)) salary_text = toga.TextInput(initial="1500", style=Pack(flex=2)) button5 = toga.Button("Ввести", style=Pack(flex=3), on_press=enter5) salary_label = toga.Label('Зарплата кассира(в день) :', style=Pack(flex=1, text_align=RIGHT, width=210)) salary_box.add(salary_label, salary_text, button5) minExpense_box = toga.Box(style=Pack(direction=ROW)) minExpense_text = toga.TextInput(initial="100", style=Pack(flex=2)) button6 = toga.Button("Ввести", style=Pack(flex=3), on_press=enter6) minExpense_label = toga.Label('Мин. сумма на покупки :', style=Pack(flex=1, text_align=RIGHT, width=210)) minExpense_box.add(minExpense_label, minExpense_text, button6) maxExpense_box = toga.Box(style=Pack(direction=ROW)) maxExpense_text = toga.TextInput(initial="3000", style=Pack(flex=2)) button7 = toga.Button("Ввести", style=Pack(flex=3), on_press=enter7) maxExpense_label = toga.Label('Макс. сумма на покупки :', style=Pack(flex=1, text_align=RIGHT, width=210)) maxExpense_box.add(maxExpense_label, maxExpense_text, button7) loss_box = toga.Box(style=Pack(direction=ROW)) loss_text = toga.TextInput(initial="0.2", style=Pack(flex=2)) button8 = toga.Button("Ввести", style=Pack(flex=3), on_press=enter8) loss_label_box = MultilineLabel( 'Степень уменьшения клиентов /nпри макс. длине очереди :', box_style=Pack(direction=COLUMN), label_style=Pack(flex=1, text_align=RIGHT, width=210)) loss_box.add(loss_label_box, loss_text, button8) profit_box = toga.Box(style=Pack(direction=ROW)) profit_text = toga.TextInput(initial="100", style=Pack(flex=2)) button9 = toga.Button("Ввести", style=Pack(flex=3), on_press=enter9) profit_label_box = MultilineLabel( 'Прибыль от покупки\nв 1000 рублей :', box_style=Pack(direction=COLUMN), label_style=Pack(flex=1, text_align=RIGHT, width=210)) profit_box.add(profit_label_box, profit_text, button9) step_box = toga.Box(style=Pack(direction=ROW)) step_text = toga.TextInput(initial="15", style=Pack(flex=2)) button10 = toga.Button("Ввести", style=Pack(flex=3), on_press=enter10) step_label = toga.Label('Шаг (10-60 мин.) :', style=Pack(flex=1, text_align=RIGHT, width=210)) step_box.add(step_label, step_text, button10) buttonBegin = toga.Button('Начать', style=Pack(padding_left=80, padding_right=80, padding_top=20), on_press=buttonBegin_handler) curTime_box = toga.Box(style=Pack(direction=ROW, padding_top=20)) curTime_label = toga.Label('Текущее время :', style=Pack(padding_left=60)) day_label = toga.Label('День', style=Pack(padding_left=10)) hour_label = toga.Label('Час') razd_label = toga.Label(' : ') minute_label = toga.Label('Минута') curTime_box.add(curTime_label, day_label, hour_label, razd_label, minute_label) info_box.add(cashBoxNumber_box, maxQueueLen_box, advert_box, sale_box, profit_box, salary_box, loss_box, minExpense_box, maxExpense_box, step_box, curTime_box, buttonBegin) info_box.style.update(direction=COLUMN, padding_top=10, padding_left=10, width=300) # кнопки buttonStep = toga.Button('Шаг', style=Pack(flex=1, padding_right=10, padding_left=10), on_press=buttonStep_handler) buttonStep.style.flex = 1 buttonToEnd = toga.Button('До конца', style=Pack(flex=2, padding_right=10), on_press=buttonToEnd_handler) buttonToEnd.style.flex = 2 buttonStop = toga.Button('Стоп', style=Pack(flex=3, padding_right=10), on_press=buttonStop_handler) buttonStop.style.flex = 3 buttonExit = toga.Button('Выход', style=Pack(flex=4, padding_right=10), on_press=buttonExit_handler) buttonExit.style.flex = 4 button_box = toga.Box() button_box.add(buttonStep, buttonToEnd, buttonStop, buttonExit) button_box.style.update(direction=ROW, padding_top=40, padding_bottom=10, padding_right=10, alignment=CENTER, height=80) # кассы canvas = toga.Canvas() canvas_box = toga.Box() with canvas.fill(color=rgb(250, 119, 73)) as f: #for i in range(cashBoxNumber_box.t) f.rect(50, 100, 30, 20) f.rect(150, 100, 30, 20) f.rect(250, 100, 30, 20) # покупатели with canvas.fill(color=rgb(0, 119, 73)) as f: f.arc(100, 50, 5) f.arc(100, 70, 5) f.arc(100, 90, 5) with canvas.fill(color=rgb(0, 119, 73)) as f: f.arc(200, 90, 5) f.arc(300, 90, 5) canvas_box.add(canvas) canvas_box.style.update(height=170, width=600) # сводная таблица table = toga.Table([' ', 'Значение', 'Ед.измерения']) table.min_width = 600 table.min_height = 500 table.data = [['Среднее время обслуживания', '0', 'мин'], ['Средняя длина очереди касс', '0', 'чел'], ['Кол-во обслуженных клиентов', '0', 'чел'], ['Количество потерянных клиентов', '0', 'чел'], ['Общая прибыль', '0', 'руб']] # моделирование work_box = toga.Box() work_box.add(canvas_box, table, button_box) work_box.style.update(direction=COLUMN, width=600, padding_left=10) # все окно work_box.style.flex = 2 info_box.style.flex = 1 main_box = toga.Box() main_box.add(info_box, work_box) main_box.style.update(direction=ROW) main_window.content = main_box main_window.show()
from toga.style.pack import Pack, COLUMN, ROW full_width = Pack(flex=1) full_column = Pack(flex=1, direction=COLUMN) full_row = Pack(flex=1, direction=ROW) main_box_style = Pack(padding=10, direction=COLUMN, flex=1) grid_row_btn = Pack(direction=ROW, flex=1) generic_style = Pack(padding=10, flex=1) btn_number = Pack(padding=5, flex=1)
def test_tutorial_1(self): root = TestNode('app', style=Pack(direction=COLUMN, padding_top=10), children=[ TestNode('f_box', style=Pack(direction=ROW, padding=5), children=[ TestNode('f_input', style=Pack(flex=1, padding_left=160), size=(at_least(100), 15)), TestNode('f_label', style=Pack(width=100, padding_left=10), size=(at_least(40), 10)), ]), TestNode('c_box', style=Pack(direction=ROW, padding=5), children=[ TestNode('join_label', style=Pack(width=150, padding_right=10), size=(at_least(80), 10)), TestNode('c_input', style=Pack(flex=1), size=(at_least(100), 15)), TestNode('c_label', style=Pack(width=100, padding_left=10), size=(at_least(40), 10)), ]), TestNode('button', style=Pack(flex=1, padding=15), size=(at_least(120), 30)), ]) # Minimum size root.style.layout(root, Viewport(0, 0, dpi=96)) self.assertLayout( root, (380, 120), { 'origin': (0, 10), 'content': (380, 110), 'children': [{ 'origin': (5, 15), 'content': (370, 15), 'children': [ { 'origin': (165, 15), 'content': (100, 15) }, { 'origin': (275, 15), 'content': (100, 10) }, ] }, { 'origin': (5, 40), 'content': (370, 15), 'children': [ { 'origin': (5, 40), 'content': (150, 10) }, { 'origin': (165, 40), 'content': (100, 15) }, { 'origin': (275, 40), 'content': (100, 10) }, ] }, { 'origin': (15, 75), 'content': (120, 30) }] }) # Normal size root.style.layout(root, Viewport(640, 480, dpi=96)) self.assertLayout( root, (640, 120), { 'origin': (0, 10), 'content': (640, 110), 'children': [{ 'origin': (5, 15), 'content': (630, 15), 'children': [ { 'origin': (165, 15), 'content': (360, 15) }, { 'origin': (535, 15), 'content': (100, 10) }, ] }, { 'origin': (5, 40), 'content': (630, 15), 'children': [ { 'origin': (5, 40), 'content': (150, 10) }, { 'origin': (165, 40), 'content': (360, 15) }, { 'origin': (535, 40), 'content': (100, 10) }, ] }, { 'origin': (15, 75), 'content': (610, 30) }] }) # HiDPI Normal size root.style.layout(root, Viewport(640, 480, dpi=144)) self.assertLayout( root, (640, 142), { 'origin': (0, 10), 'content': (640, 132), 'children': [{ 'origin': (7, 15), 'content': (626, 15), 'children': [ { 'origin': (247, 15), 'content': (221, 15) }, { 'origin': (483, 15), 'content': (150, 10) }, ] }, { 'origin': (7, 42), 'content': (626, 15), 'children': [ { 'origin': (7, 42), 'content': (225, 10) }, { 'origin': (247, 42), 'content': (221, 15) }, { 'origin': (483, 42), 'content': (150, 10) }, ] }, { 'origin': (22, 79), 'content': (596, 30) }] })
def __init__(self, **kwargs) -> None: super().__init__( title="Maestral Settings", resizeable=False, minimizable=False, release_on_close=False, **kwargs, ) # ==== account info section ==================================================== self.profile_pic_view = toga.ImageView( self.faceholder, style=Pack( width=SettingsGui.IMAGE_WIDTH, height=SettingsGui.IMAGE_WIDTH, background_color=TRANSPARENT, ), ) apply_round_clipping(self.profile_pic_view) self.profile_pic_view_spacer = toga.Box(style=Pack( width=SettingsGui.COLUMN_WIDTH_LEFT - SettingsGui.IMAGE_WIDTH, direction=ROW, background_color=TRANSPARENT, )) self.label_name = Label( "Account Name (Company Name)", style=Pack( font_size=17, padding_bottom=SettingsGui.ELEMENT_PADDING - 4, width=SettingsGui.COLUMN_WIDTH_RIGHT, ), ) self.label_email = Label( "[email protected], Business", style=Pack( padding_bottom=SettingsGui.SUBELEMENT_PADDING, width=SettingsGui.COLUMN_WIDTH_RIGHT, font_size=12, ), ) self.label_usage = Label( "10.5 % from 1,005 TB used", style=Pack( padding_bottom=SettingsGui.ELEMENT_PADDING, width=SettingsGui.COLUMN_WIDTH_RIGHT, font_size=12, ), ) self.btn_unlink = toga.Button( "Unlink this Dropbox...", style=Pack(width=SettingsGui.BUTTON_WIDTH)) account_info_box = toga.Box( children=[ self.profile_pic_view_spacer, self.profile_pic_view, toga.Box( children=[ self.label_name, self.label_email, self.label_usage, self.btn_unlink, ], style=Pack(direction=COLUMN, padding_left=SettingsGui.COLUMN_PADDING), ), ], style=Pack(direction=ROW), ) # ==== sync settings section =================================================== self._label_select_folders = Label( "Selective sync:", style=Pack(text_align=RIGHT, width=SettingsGui.COLUMN_WIDTH_LEFT), ) self.btn_select_folders = toga.Button( label="Select files and folders...", style=Pack(padding_left=SettingsGui.COLUMN_PADDING, width=SettingsGui.BUTTON_WIDTH), ) self._label_dbx_location = Label( "Local Dropbox folder:", style=Pack(text_align=RIGHT, width=SettingsGui.COLUMN_WIDTH_LEFT), ) self.combobox_dbx_location = FileSelectionButton( initial=get_home_dir(), select_files=False, select_folders=True, style=Pack(padding_left=SettingsGui.COLUMN_PADDING, width=SettingsGui.BUTTON_WIDTH), ) dropbox_settings_box = toga.Box( children=[ toga.Box( children=[ self._label_select_folders, self.btn_select_folders ], style=Pack(alignment=CENTER, padding_bottom=SettingsGui.ELEMENT_PADDING), ), toga.Box( children=[ self._label_dbx_location, self.combobox_dbx_location ], style=Pack(alignment=CENTER), ), ], style=Pack(direction=COLUMN), ) # ==== system settings section ================================================= self._label_update_interval = Label( "Check for updates:", style=Pack(text_align=RIGHT, width=SettingsGui.COLUMN_WIDTH_LEFT), ) self.combobox_update_interval = toga.Selection( items=["Daily", "Weekly", "Monthly", "Never"], style=Pack(padding_left=SettingsGui.COLUMN_PADDING, width=SettingsGui.BUTTON_WIDTH), ) self._label_system_settings = Label( "System settings:", style=Pack(text_align=RIGHT, width=SettingsGui.COLUMN_WIDTH_LEFT), ) self.checkbox_autostart = Switch( label="Start Maestral on login", style=Pack( padding_bottom=SettingsGui.SUBELEMENT_PADDING, width=SettingsGui.COLUMN_WIDTH_RIGHT, ), ) self.checkbox_notifications = Switch( label="Enable notifications on file changes", style=Pack( padding_bottom=SettingsGui.SUBELEMENT_PADDING, width=SettingsGui.COLUMN_WIDTH_RIGHT, ), ) children = [ toga.Box( children=[ self._label_update_interval, self.combobox_update_interval ], style=Pack(alignment=CENTER, padding_bottom=SettingsGui.ELEMENT_PADDING), ), toga.Box(children=[ self._label_system_settings, toga.Box( children=[ self.checkbox_autostart, self.checkbox_notifications, ], style=Pack( alignment=TOP, direction=COLUMN, padding_left=SettingsGui.COLUMN_PADDING, ), ), ], ), ] if FROZEN: # add UI to install command line interface self._label_cli_tool = Label( "Command line tool:", style=Pack(text_align=RIGHT, width=SettingsGui.COLUMN_WIDTH_LEFT), ) self.label_cli_tool_info = Label( "Install the 'maestral' command line tool to /usr/local/bin.", style=Pack( color=GRAY, font_size=12, width=SettingsGui.COLUMN_WIDTH_RIGHT, padding_left=SettingsGui.COLUMN_PADDING, ), ) self.btn_cli_tool = toga.Button( "Install", style=Pack( width=SettingsGui.BUTTON_WIDTH / 2, padding_bottom=SettingsGui.SUBELEMENT_PADDING, padding_left=SettingsGui.COLUMN_PADDING, ), ) children.append( toga.Box( children=[ self._label_cli_tool, self.btn_cli_tool, ], style=Pack(alignment=CENTER, padding_top=SettingsGui.ELEMENT_PADDING), )) children.append( toga.Box( children=[ Label( " ", style=Pack(text_align=RIGHT, width=SettingsGui.COLUMN_WIDTH_LEFT), ), self.label_cli_tool_info, ], style=Pack(alignment=CENTER, padding_top=SettingsGui.SUBELEMENT_PADDING), )) maestral_settings_box = toga.Box( children=children, style=Pack(direction=COLUMN), ) # ==== about section =========================================================== about_box = toga.Box( children=[ Label( "About Maestral:", style=Pack(text_align=RIGHT, width=SettingsGui.COLUMN_WIDTH_LEFT), ), toga.Box( children=[ Label( f"GUI v{__version__}, daemon v{__daemon_version__}", style=Pack( padding_bottom=SettingsGui.SUBELEMENT_PADDING, width=SettingsGui.COLUMN_WIDTH_RIGHT, ), ), LinkLabel( text=__url__, url=__url__, style=Pack( padding_bottom=SettingsGui.SUBELEMENT_PADDING, width=SettingsGui.COLUMN_WIDTH_RIGHT, ), ), Label( f"© 2018 - {year}, {__author__}.", style=Pack(color=GRAY, width=SettingsGui.COLUMN_WIDTH_RIGHT), ), ], style=Pack(direction=COLUMN, padding_left=SettingsGui.COLUMN_PADDING), ), ], style=Pack(direction=ROW), ) main_box = toga.Box( children=[ account_info_box, toga.Divider(style=Pack(padding=SettingsGui.SECTION_PADDING)), dropbox_settings_box, toga.Divider(style=Pack(padding=SettingsGui.SECTION_PADDING)), maestral_settings_box, toga.Divider(style=Pack(padding=SettingsGui.SECTION_PADDING)), about_box, ], style=Pack( direction=COLUMN, padding=30, width=SettingsGui.COLUMN_WIDTH_LEFT + SettingsGui.COLUMN_WIDTH_RIGHT, ), ) self.content = main_box
def test_set_default_right_textalign_when_rtl(self): root = TestNode('app', style=Pack(text_align=None, text_direction=RTL)) root.style.reapply() root._impl.set_alignment.assert_called_once_with(RIGHT)
def __init__(self, direction=ROW, factory=None): style = Pack(flex=1, direction=direction, background_color=TRANSPARENT) super().__init__(style=style, factory=factory)
def test_set_default_left_textalign_when_no_rtl(self): root = TestNode('app', style=Pack(text_align=None)) root.style.reapply() root._impl.set_alignment.assert_called_once_with(LEFT)
def __init__(self, sync_err: SyncErrorEntry) -> None: super().__init__(style=Pack(direction=COLUMN)) self.sync_err = sync_err icon = Icon(for_path=self.sync_err.local_path) # noinspection PyTypeChecker image_view = toga.ImageView( image=icon, style=Pack( width=ICON_SIZE, height=ICON_SIZE, padding=(0, 12, 0, 3), ), ) path_label = Label( sanitize_string(osp.basename(self.sync_err.dbx_path)), style=Pack( padding_bottom=PADDING / 2, ), ) error_label = Label( f"{self.sync_err.title}:\n{self.sync_err.message}", linebreak_mode=WORD_WRAP, style=Pack( font_size=11, width=WINDOW_SIZE[0] - 4 * PADDING - 15 - ICON_SIZE, padding_bottom=PADDING / 2, ), ) link_local = FollowLinkButton( "Show in Finder", url=self.sync_err.local_path, enabled=osp.exists(self.sync_err.local_path), locate=True, style=Pack( padding_right=PADDING, font_size=11, height=12, ), ) quoted_dbx_path = urllib.parse.quote(self.sync_err.dbx_path) dbx_address = f"https://www.dropbox.com/preview{quoted_dbx_path}" link_dbx = FollowLinkButton( "Show Online", url=dbx_address, style=Pack(font_size=11, height=12), ) link_box = toga.Box( children=[link_local, link_dbx], style=Pack(direction=ROW), ) info_box = toga.Box( children=[path_label, error_label, link_box], style=Pack(direction=COLUMN, flex=1), ) content_box = toga.Box( children=[image_view, info_box], style=Pack(direction=ROW), ) hline = toga.Divider(style=Pack(padding=(PADDING, 0, PADDING, 0))) self.add(content_box, hline)