def startup(self): # Window class # Main window of the application with title and size self.main_window = toga.MainWindow(title=self.name, size=(300, 150)) style = Pack(padding_top=24) substyle = Pack(padding_right=24, flex=1) # Add the content on the main window self.main_window.content = toga.Box( children=[ toga.Label('Section 1'), toga.Divider(style=style), toga.Label('Section 2', style=style), toga.Divider(style=style), toga.Label('Section 3', style=style), toga.Box( children=[ toga.DetailedList(['List 1'], style=substyle), toga.Divider(direction=toga.Divider.VERTICAL, style=substyle), toga.DetailedList(['List 2'], style=substyle), ], style=Pack(direction=ROW, padding=24, flex=1), ), ], style=Pack(direction=COLUMN, padding=24) ) # Show the main window self.main_window.show()
def startup(self): # Set up main window self.main_window = toga.MainWindow(title=self.name) # Label to show responses. self.label = toga.Label('Ready.') widget = toga.DetailedList( data=[{ 'icon': toga.Icon('resources/brutus.png'), 'title': translation['string'], 'subtitle': translation['country'], } for translation in bee_translations], on_select=self.on_select_handler, # on_delete=self.on_delete_handler, on_refresh=self.on_refresh_handler, style=Pack(flex=1)) # Outermost box outer_box = toga.Box(children=[widget, self.label], 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()
def build(app): box = toga.Box(style=CSS(flex=1, padding=20)) def on_select(widget, selection): print(widget) print(selection) def on_refresh(widget): print('refreshing this shit!') def on_delete(widget, row): print('deleting someting', widget, 'row', row) print(widget) dl = toga.DetailedList(data=['Item 0', 'Item 1', 'Item 2'], on_select=on_select, on_delete=on_delete) btn = toga.Button('My Button') dl.on_refresh = on_refresh dl.data = '1 2 3 4 5 6'.split(' ') box.add(dl) box.add(btn) return dl
def startup(self): # Set up main window self.main_window = toga.MainWindow(title=self.name) self.main_window.app = self self.partner = Eliza() self.chat = toga.DetailedList(data=[{ 'icon': toga.Icon('resources/brutus.png'), 'title': 'Brutus', 'subtitle': 'Hello. How are you feeling today?', }], style=Pack(flex=1)) # Buttons self.text_input = toga.TextInput(style=Pack(flex=1, padding=5)) send_button = toga.Button('Send', on_press=self.handle_input, style=Pack(padding=5)) input_box = toga.Box(children=[self.text_input, send_button], style=Pack(direction=ROW)) # Outermost box outer_box = toga.Box(children=[self.chat, input_box], style=Pack(direction=COLUMN)) # Add the content on the main window self.main_window.content = outer_box # Show the main window self.main_window.show()
def startup(self): self.chat = toga.DetailedList(data=[{ 'icon': toga.Icon(), 'title': 'RisBot', 'subtitle': 'Hello,Wassup?', }], style=Pack(flex=1)) self.text_input = toga.TextInput(style=Pack(flex=1)) send_button = toga.Button('Send', style=Pack(padding_left=5), on_press=self.handle_input) input_box = toga.Box(children=[self.text_input, send_button], style=Pack(direction=ROW, alignment='CENTER', padding=5)) # Create a main window with a name matching the app self.main_window = toga.MainWindow(title=self.name) # Create a main content box main_box = toga.Box() # Add the content on the main window self.main_window.content = toga.Box(children=[self.chat, input_box], style=Pack(direction=COLUMN)) self.partner = eliza.Eliza() # Show the main window self.main_window.show()
def setUp(self): self.factory = MagicMock() self.factory.DetailedList = MagicMock(return_value=MagicMock( spec=toga_dummy.factory.DetailedList)) self.text = 'test text' self.detailed_list = toga.DetailedList(factory=self.factory)
def startup(self): self.main_window = toga.MainWindow(title=self.name) self.box = toga.Box('box1') data1 = ['Item 0', 'Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6', 'Item 7'] self.detailedlist = toga.DetailedList(data=data1, on_select=self.selection_handler, style=Pack(flex=1)) self.box.add(self.detailedlist) self.main_window.content = self.box self.main_window.show()
def setUp(self): super().setUp() self.on_select = None self.on_delete = None self.on_refresh = None self.dlist = toga.DetailedList(factory=toga_dummy.factory, on_select=self.on_select, on_delete=self.on_delete, on_refresh=self.on_refresh)
def setUp(self): super().setUp() self.on_select = None self.on_delete = None self.on_refresh = None self.data = [str(x) for x in range(10)] self.dlist = toga.DetailedList(factory=toga_dummy.factory, data=self.data, on_select=self.on_select, on_delete=self.on_delete, on_refresh=self.on_refresh)
def setUp(self): icon = toga.Icon( os.path.join(os.path.dirname(__file__), '../../../../demo/toga_demo/resources/brutus-32.png')) self.dl = toga.DetailedList([ dict(icon=icon, title='Item %i' % i, subtitle='this is the subtitle for item %i' % i) for i in range(10) ]) # make a shortcut for easy use self.gtk_dl = self.dl._impl self.window = Gtk.Window() self.window.add(self.dl._impl.native)
def build(app): def on_select(widget, row): print('row ', row, 'of widget ', widget, 'was selected.') def on_refresh(widget): print('Pull down to refresh was initialised!') def on_delete(widget, row): print('row ', row, 'of widget ', widget, 'is going to be deleted.') dl = toga.DetailedList(data=[ '{}: {}'.format(x['country'], x['string']) for x in bee_translation ], on_select=on_select, on_delete=on_delete, on_refresh=on_refresh) return dl
def startup(self): #alternative icon embedding #path=os.path.dirname(os.path.abspath(__file__)) #brutus_icon=os.path.join(path,"icons","brutus.icns") #Eliza module self.partner=Eliza() self.chat=toga.DetailedList( data=[ { 'icon':toga.Icon('icons/ubs-logo.png'), 'title': 'Bot', 'subtitle': 'Hello. How are you feeling today?' } ] ,style=Pack(flex=1)) self.text_input=toga.TextInput(style=Pack(flex=1)) send_button=toga.Button('Send',style=Pack(padding_left=5),on_press=self.handle_input) input_box=toga.Box( children=[self.text_input, send_button], style=Pack(direction=ROW, alignment=CENTER, padding=5) ) #alignment='CENTER', # Create a main window with a name matching the app self.main_window = toga.MainWindow(title=self.name) # Create a main content box #main_box = toga.Box() # Add the content on the main window self.main_window.content = toga.Box( children=[self.chat,input_box], style=Pack(direction=COLUMN) ) # Show the main window self.main_window.show()
def startup(self): log.info("We're running on {}".format(host_name)) log.info("Loading settings from {}".format(SETTINGS_FILE)) load_settings(settings) tzinfo = pytz.timezone(settings['tz_name']) log.info("Time zone is {}".format(tzinfo)) if not os.path.isfile(settings['user_id']): pem_cert, pem_key = generate_selfsigned_cert(host_name) with open('ca.crt', 'wb') as f: f.write(pem_cert) with open('ca.key', 'wb') as f: f.write(pem_key) else: pem_cert = open('ca.crt', 'rb').read() cert = x509.load_pem_x509_certificate(pem_cert, default_backend()) log.info("User CN={}".format( cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME)[0].value)) #@dataclass class M(Persistent, object): #created_at: datetime = None created_at = None # #class Meta(M): # pass #class Data(M): # def __init__(self, *args, **kwargs): # self.created_at = tzinfo.localize(datetime.now()) # self.modified_at = self.created_at def open_db(path_to_msf): connection = Connection(FileStorage(path_to_msf)) return connection #log.info('root: {}'.format(root.data)) db = open_db(settings['db_file']) log.info('{}'.format(db)) db_root = db.get_root() #log.info('{}'.format(len(db_root))) if len(db_root) == 0: # empty MSF #about = {} #about = dict({'created_at':tzinfo.localize(datetime.now()).isoformat()}) about = M(tzinfo.localize(datetime.now())) #about.created_at = log.info('{}'.format(about)) #about.update({'created_by_cert' : cert.public_bytes(serialization.Encoding.PEM)}) about.created_by_cert = cert.public_bytes( serialization.Encoding.PEM) #about.update({'uuid' : uuid4()}) about.uuid = uuid4() #about.update({"title" : 'About'}) about.title = 'About' #about.update({"title" : 'About'}) about.body = ''' About this mouse ''' db_root['about'] = about from durus.persistent_list import PersistentList from durus.persistent_dict import PersistentDict acl = PersistentDict() acl['default'] = None db_root['acl'] = acl db.commit() else: acl = db_root['acl'] #log.inf('{}'.format()) log.info('about: {}'.format(db_root['about'])) #start_server() log.info('Startng server . . . ') endpoint = TCP4ServerEndpoint(reactor, 5999) m_factory = MFactory() endpoint.listen(m_factory) def gotProtocol(p): """The callback to start the protocol exchange. We let connecting nodes start the hello handshake""" p.send_hello() point = TCP4ClientEndpoint(reactor, "localhost", 5999) d = connectProtocol(point, m_factory) d.addCallback(gotProtocol) # Create a main window with a name matching the app self.main_window = toga.MainWindow(title=self.name) # Create a main content box #main_box = toga.Box() # Add the content on the main window #self.main_window.content = main_box # Label to show responses. self.label = toga.Label('Ready.', style=Pack(padding_top=20)) self.workspace = toga.DetailedList(data=[{ 'icon': toga.Icon.TIBERIUS_ICON, 'title': "Misbehavin'", 'subtitle': '0' }], style=Pack(flex=1)) # Buttons btn_style = Pack(flex=1) btn_info = toga.Button('Info', on_press=self.action_info_dialog, style=btn_style) btn_question = toga.Button('Question', on_press=self.action_question_dialog, style=btn_style) btn_open = toga.Button('Open File', on_press=self.action_open_file_dialog, style=btn_style) btn_save = toga.Button('Save File', on_press=self.action_save_file_dialog, style=btn_style) btn_select = toga.Button('Select Folder', on_press=self.action_select_folder_dialog, style=btn_style) dialog_btn_box = toga.Box( children=[btn_info, btn_question, btn_open, btn_save, btn_select], style=Pack(direction=ROW)) # Dialog Buttons 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)) # Outermost box outer_box = toga.Box( #children=[btn_box, dialog_btn_box, self.label], children=[self.workspace, self.label], 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()