import qutie as ui from qutie.qutie import Qt app = ui.Application() exclusive_group = ui.GroupBox(title="Exclusive", cursor='forbidden', layout=ui.Column( ui.Button("A", checkable=True), ui.PushButton("B", checkable=True, icon='red'), ui.ToolButton("C", checkable=True, arrow_type='no'), ui.ToolButton("D", checkable=True, arrow_type='left'))) g = ui.ButtonGroup(*list(exclusive_group.layout)) print(len(g)) print(list(g)) nonexlusive_group = ui.GroupBox(title="Exclusive", layout=ui.Column( ui.Button("A", checkable=True), ui.PushButton("B", checkable=True, icon='blue'), ui.ToolButton("C", checkable=True, arrow_type='up'),
def main(): app = ui.Application("demo", version="1.0a", organization="acme") app.display_name=f"Demo {app.version}" app.icon = 'orange' tree = ui.Tree( header=("Key", "Value") ) item = tree.append(["Color", "#33cc33"]) item[0].color = "#33cc33" item[0].background = "yellow" item[0].icon = "#33cc33" item.append(["red", 51])[0].icon = 'red' item.append(["green", 204])[0].icon = 'green' item.append(["blue", 51])[0].icon = 'blue' # Install blinking item background usign a timer colors = itertools.cycle(["yellow", "orange"]) def toggle_color(): tree[0][0].background = next(colors) timer = ui.Timer(interval=0.5, timeout=toggle_color) timer.start() item = tree.append(["checked=0"]) item[0].checked = False item[0].icon = '#123456' item = tree.append(["checked=1"]) item[0].checked = True item[0].icon = '#341256' item = tree.append(["checkable=0"]) item.checkable = False item[0].icon = 'yellow' item[0].icon = None item = tree.append(["checkable=1"]) item.checkable = True item[0].icon = ui.Icon.from_theme('document-open') item = tree.append(["checkable=0", "checked=0"]) item.checkable = False item[0].checked = False item = tree.append(["checkable=1", "checked=0"]) item.checkable = True item[0].checked = False item = tree.append(["checkable=0", "checked=1"]) item.checkable = False item[0].checked = True item = tree.append(["checkable=1", "checked=1"]) item.checkable = True item[0].checked = True tree.current = tree[3] tree.fit() tree.clicked = lambda column, data: print(f"tree clicked, column={column}, data={data}") tree.double_clicked = lambda column, data: print(f"tree double clicked, column={column}, data={data}") table = ui.Table( header=("Key", "Value") ) item = table.append(["green", "spam"]) item[0].color = "green" item[0].background = "yellow" item[0].icon = 'blue' item = table.append(["checked=0"]) item[0].checked = False item = table.append(["checked=1"]) item[0].checked = True item = table.append(["checkable=0"]) item[0].checkable = False item = table.append(["checkable=1"]) item[0].checkable = True item = table.append(["checkable=0", "checked=0"]) item[0].checkable = False item[0].checked = False item = table.append(["checkable=1", "checked=0"]) item[0].checkable = True item[0].checked = False item = table.append(["checkable=0", "checked=1"]) item[0].checkable = False item[0].checked = True item = table.append(["checkable=1", "checked=1"]) item[0].checkable = True item[0].checked = True table.current = table[3][0] table.fit() list_ = ui.List( items=("red",) ) list_[0].color = "red" item = list_.append("green") item.color = "green" item.background = "yellow" item.icon = ui.Icon.from_color('blue') item = list_.append("checked=0") item.checked = False item = list_.append("checked=1") item.checked = True item = list_.append("checkable=0") item.checkable = False item = list_.append("checkable=1") item.checkable = True item = list_.append("checkable=0, checked=0") item.checkable = False item.checked = False item = list_.append("checkable=1, checked=0") item.checkable = True item.checked = False item = list_.append("checkable=0, checked=1") item.checkable = False item.checked = True item = list_.append("checkable=1, checked=1") item.checkable = True item.checked = True list_.clicked = lambda row, data: print(f"list clicked, row={row}, data={data}") list_.double_clicked = lambda row, data: print(f"list double clicked, row={row}, data={data}") tabs = ui.Tabs( ui.Tab( title="Tree", layout=tree ), ui.Tab( title="Table", layout=table ), ) splitter = ui.Splitter( list_, ui.Label("Aside") ) splitter.sizes = [3, 2] splitter.handle_width = 1 tabs.append(ui.Tab( title="List", layout=splitter )) tabs.append(NumbersTab(title="Numbers")) tabs.insert(-1, TextTab(title="Text")) tabs.append(SelectTab(title="Select")) tabs.append(ExclusiveTab(title="Exclusive")) tabs.insert(-1, StackTab(title="Stack")) def on_tab_changed(index): window.progress.value = index + 1 tabs.changed = on_tab_changed def on_quit(): app.quit() def on_open(): ui.filename_open(parent=window) def on_preferences(): defaults = ["Apples", "Pears", "Nuts"] def on_click(button): if button == 'restore_defaults': item_list.clear() item_list.extend(defaults) ui.show_info("Reset to defaults.") def on_help(): ui.show_info("Helpful information.") def on_add(): item = ui.get_item(defaults) if item: item_list.append(item) def on_remove(): item = item_list.current if item: item_list.remove(item) def on_edit(index, item): value = ui.get_text(item.value, title="Item", label="Edit item") if value is not None: item.value = value dialog = ui.Dialog(title="Preferences") item_list = ui.List() item_list.double_clicked = on_edit add_button = ui.Button("&Add", clicked=on_add) remove_button = ui.Button("&Del", clicked=on_remove) dialog.layout = ui.Column( ui.Row( item_list, ui.Column( add_button, remove_button, ui.Spacer() ), stretch=(1,0) ), ui.Row( ui.DialogButtonBox( buttons=('restore_defaults', 'close', 'help'), accepted=dialog.close, rejected=dialog.close, clicked=on_click, help_requested=on_help, ) ) ) # Load settings with ui.Settings() as settings: item_list.clear() item_list.extend(settings.setdefault("items", defaults)) dialog.run() # Store settings with ui.Settings() as settings: settings["items"] = [item.value for item in item_list] window = ui.MainWindow( layout=tabs ) edit_menu = window.menubar.append("&Edit") edit_menu.append(ui.Action( text="&Preferences", triggered=on_preferences )) abc_menu = edit_menu.append(ui.Menu( ui.Action("ABC", separator=True), ui.Action("B", icon='red'), ui.Action(separator=True), ui.Action("C", icon='blue'), text="&More..." )) file_menu = window.menubar.insert(window.menubar.index(edit_menu), "&File") window.menubar.remove(file_menu) window.menubar.insert(window.menubar.index(edit_menu), file_menu) quit_action = file_menu.append(ui.Action( text="&Quit", status_tip="Quit application", shortcut="Ctrl+Q", triggered=on_quit )) quit_action = file_menu.insert(0, ui.Action( text="&Open...", status_tip="Open file", shortcut="Ctrl+O", triggered=on_open )) window.menubar.clear() window.menubar.insert(3, edit_menu) window.menubar.insert(0, file_menu) window.menubar.append(abc_menu[1]) window.progress2 = ui.ProgressBar(0, minimum=0, maximum=100) window.statusbar.append(window.progress2) window.progress = ui.ProgressBar(0, minimum=0, maximum=len(tabs)) window.statusbar.insert(0, window.progress) window.message = ui.Label() window.statusbar.append(window.message) window.statusbar.remove(window.message) window.statusbar.insert(0, window.message) window.statusbar.remove(window.message) window.statusbar.insert(-1, window.message) window.message.show() window.statusbar.show_message("Ready!", timeout=5.0) main_toolbar = ui.ToolBar("foo", "bar", "baz", quit_action, edit_menu[0], orientation='vertical') window.toolbars.add(main_toolbar) window.toolbars.add("foo") assert len(window.toolbars) == 2 assert main_toolbar.index(main_toolbar[1]) == 1 window.toolbars.clear() assert len(window.toolbars) == 0 window.toolbars.add(main_toolbar).show() assert main_toolbar.orientation == "horizontal" main_toolbar.orientation = "vertical" assert main_toolbar.orientation == "vertical" main_toolbar.orientation = "horizontal" assert main_toolbar.orientation == "horizontal" assert len(window.toolbars) == 1 main_toolbar.title = "Main Toolbar" main_toolbar.clear() main_toolbar.append(edit_menu[0]) main_toolbar.insert(main_toolbar.index(edit_menu[0]), quit_action) main_toolbar.append(abc_menu) main_toolbar.tool_button_style = 'text_beside_icon' window.show() def on_run(worker): value = 0.0 logging.info("worker:started") while not worker.stopping: worker.emit('progress', value) worker.emit('message', f"about {value:.1f} %") worker.set('reading', value) worker.emit('reading_available') value += random.random() time.sleep(random.random()) if value >= 100.0: value = 0.0 logging.info("worker:finished") def on_finished(): print("DONE") ui.show_info("Worker finished.") def on_failed(e): ui.show_exception(e) worker = ui.Worker(target=on_run, finished=on_finished, failed=on_failed) def on_progress(value): window.progress2.value = value worker.progress = on_progress def on_message(text): window.message.text = text worker.message = on_message def on_reading_available(): value = worker.get('reading') print("reading:", value) worker.reading_available = on_reading_available worker.start() def on_window_close(): result = ui.show_question("Quit application?") if result: worker.stop() worker.join() return result window.close_event = on_window_close with ui.Settings() as settings: settings.setdefault('window/size', (640, 480)) window.resize(*settings.get('window/size')) position = settings.setdefault('window/position', None) if position: window.move(*position) window.maximized = settings.setdefault('window/maximized', False) tabs.current = tabs[settings.get('window/tab', 0)] w = ui.Widget(title="Window") def show_alert(message): ui.show_warning(text=message, title="Alert") w.alert = show_alert w.layout = ui.Button("Trigger Alert", clicked=lambda: w.emit('alert', random.choice(["Alert!", "This is not an exercise!"]))) w.modal = True # workaround to keep window in front w.show() app.run() worker.stop() with ui.Settings() as settings: if not window.maximized: settings['window/size'] = window.size settings['window/position'] = window.position settings['window/maximized'] = window.maximized settings['window/tab'] = tabs.index(tabs.current) worker.join()