def __init__(self): """Create TreeTodoApplication""" Application.__init__(self) self.connect("activate", self.on_activate) self.taskManager = TaskManager()
def run(application: Gtk.Application) -> None: loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) loop.create_task(async_iterator(application, loop)) application.register() application.activate() with contextlib.suppress(KeyboardInterrupt): loop.run_forever()
async def async_iterator(application: Gtk.Application, loop: asyncio.AbstractEventLoop) -> None: while Gtk.events_pending(): Gtk.main_iteration_do(False) await asyncio.sleep(0.01) if application.main_window and application.main_window.get_realized(): loop.create_task(async_iterator(application, loop)) else: application.quit() loop.stop()
def do_startup(self): """ Perform startup operations. Called once, on application startup. """ Application.do_startup(self) # Connect the close button to a callback action = SimpleAction.new('quit', None) action.connect('activate', self.on_quit) self.add_action(action) # Install main menu builder = Builder() builder.add_from_string(MENU) self.set_app_menu(builder.get_object('app-menu')) # Get a (single) view and model. # Because this function is executed only once, # multiple models or views cannot exist. self.view = View(application=self, title=APP_TITLE) self.model = Model() # Pass view all the callbacks, to assign each one to the appropriate GUI object. self.view.setCallbacks( self.Callbacks(self.model, self.view, self.XML(self.model, self.view))) # Initialize the GUI self.view.initGUI() # Connect each view component with its corresponding model. # This is clearly a controller's responsibility. self.view.zones.set_model(self.model.zones) self.view.playlists.set_model(self.model.playlists) for dayIndex in range(7): self.view.schedule[dayIndex].set_model( self.model.schedule[dayIndex]) # Set app title and logo in gnome's top bar self.view.set_wmclass('Flow Dashboard', 'Flow Dashboard') self.view.set_icon_from_file('src/resources/logo.png') # Make the GUI visible self.view.show_all() # Zone Inspector is set initially invisible, until a zone is selected self.view.zoneInspector.hide()
def extract_accel_from_menu_item( model: Gio.MenuModel, item: int, app: Gtk.Application): accel, action, target = None, None, None more, it = True, model.iterate_item_attributes(item) while more: more, key, value = it.get_next() if key == 'action': action = value.get_string() elif key == 'accel': accel = value.get_string() # TODO: Handle targets if accel and action: detailed_action_name = Gio.Action.print_detailed_name(action, target) app.set_accels_for_action(detailed_action_name, [accel])
def register_accels(app: Gtk.Application): view_accels = ( ('app.quit', '<Primary>Q'), ('view.find', '<Primary>F'), ('view.find-next', '<Primary>G'), ('view.find-previous', '<Primary><Shift>G'), ('view.find-replace', '<Primary>H'), ('view.go-to-line', '<Primary>I'), ('view.next-change', ('<Alt>Down', '<Alt>KP_Down', '<Primary>D')), ('view.next-pane', '<Alt>Page_Down'), ('view.previous-change', ('<Alt>Up', '<Alt>KP_Up', '<Primary>E')), ('view.previous-pane', '<Alt>Page_Up'), ('view.redo', '<Primary><Shift>Z'), ('view.refresh', ('<control>R', 'F5')), ('view.save', '<Primary>S'), ('view.save-all', '<Primary><Shift>L'), ('view.save-as', '<Primary><Shift>S'), ('view.undo', '<Primary>Z'), ('win.close', '<Primary>W'), ('win.new-tab', '<Primary>N'), ('win.stop', 'Escape'), # File comparison actions ('view.file-previous-conflict', '<Primary>I'), ('view.file-next-conflict', '<Primary>K'), ('view.file-push-left', '<Alt>Left'), ('view.file-push-right', '<Alt>Right'), ('view.file-pull-left', '<Alt><shift>Right'), ('view.file-pull-right', '<Alt><shift>Left'), ('view.file-copy-left-up', '<Alt>bracketleft'), ('view.file-copy-right-up', '<Alt>bracketright'), ('view.file-copy-left-down', '<Alt>semicolon'), ('view.file-copy-right-down', '<Alt>quoteright'), ('view.file-delete', ('<Alt>Delete', '<Alt>KP_Delete')), ('view.show-overview-map', 'F9'), # Folder comparison actions ('view.folder-compare', 'Return'), ('view.folder-copy-left', '<Alt>Left'), ('view.folder-copy-right', '<Alt>Right'), ('view.folder-delete', 'Delete'), # Version control actions ('view.vc-commit', '<Primary>M'), ('view.vc-console-visible', 'F9'), ) for (name, accel) in view_accels: accel = accel if isinstance(accel, tuple) else (accel, ) app.set_accels_for_action(name, accel)
def register_accels(app: Gtk.Application): view_accels = ( ('app.quit', '<Primary>Q'), ('view.find', '<Primary>F'), ('view.find-next', '<Primary>G'), ('view.find-previous', '<Primary><Shift>G'), ('view.find-replace', '<Primary>H'), ('view.go-to-line', '<Primary>I'), ('view.next-change', ('<Alt>Down', '<Alt>KP_Down', '<Primary>D')), ('view.next-pane', '<Alt>Page_Down'), ('view.previous-change', ('<Alt>Up', '<Alt>KP_Up', '<Primary>E')), ('view.previous-pane', '<Alt>Page_Up'), ('view.redo', '<Primary><Shift>Z'), ('view.refresh', ('<control>R', 'F5')), ('view.save', '<Primary>S'), ('view.save-all', '<Primary><Shift>L'), ('view.save-as', '<Primary><Shift>S'), ('view.undo', '<Primary>Z'), ('win.close', '<Primary>W'), ('win.new-tab', '<Primary>N'), ('win.stop', 'Escape'), # File comparison actions ('view.file-previous-conflict', '<Primary>I'), ('view.file-next-conflict', '<Primary>K'), ('view.file-push-left', '<Alt>Left'), ('view.file-push-right', '<Alt>Right'), ('view.file-pull-left', '<Alt><shift>Right'), ('view.file-pull-right', '<Alt><shift>Left'), ('view.file-copy-left-up', '<Alt>bracketleft'), ('view.file-copy-right-up', '<Alt>bracketright'), ('view.file-copy-left-down', '<Alt>semicolon'), ('view.file-copy-right-down', '<Alt>quoteright'), ('view.file-delete', ('<Alt>Delete', '<Alt>KP_Delete')), ('view.show-overview-map', 'F9'), # Folder comparison actions ('view.folder-compare', 'Return'), ('view.folder-copy-left', '<Alt>Left'), ('view.folder-copy-right', '<Alt>Right'), ('view.folder-delete', 'Delete'), # Version control actions ('view.vc-commit', '<Primary>M'), ('view.vc-console-visible', 'F9'), ) for (name, accel) in view_accels: accel = accel if isinstance(accel, tuple) else (accel,) app.set_accels_for_action(name, accel)
def do_startup(self): Application.do_startup(self) #TODO: Parse args #if "open-entity" in args: # Set app menu action = SimpleAction.new("preferences", None) action.connect("activate", self.on_preferences) #self.set_accels_for_action("app.preferences", ["<Control>,"]) self.add_action(action) action = SimpleAction.new("shortcuts", None) action.connect("activate", self.on_shortcuts) self.set_accels_for_action("app.shortcuts", ["<Control>F1"]) self.add_action(action) # Set app menu action = SimpleAction.new("help", None) action.connect("activate", self.on_help) self.set_accels_for_action("app.help", ["F1"]) self.add_action(action) action = SimpleAction.new("about", None) action.connect("activate", self.on_about) self.add_action(action) action = SimpleAction.new("quit", None) action.connect("activate", self.on_quit) self.set_accels_for_action("app.quit", ["<Control>q"]) self.add_action(action) # Set entity menu action = SimpleAction.new("entity_close", None) action.connect("activate", self.on_entity_close) self.set_accels_for_action("app.entity_close", ["<Control>w"]) self.add_action(action)
def do_startup(self): GtkApplication.do_startup(self) action = SimpleAction.new("new-window", None) action.connect("activate", self.on_new_window) self.add_action(action) action = SimpleAction.new("shortcuts", None) action.connect("activate", self.on_shortcuts) self.add_action(action) action = SimpleAction.new("about", None) action.connect("activate", self.on_about) self.add_action(action) action = SimpleAction.new("traceback", VariantType.new('s')) action.connect("activate", self.on_traceback) self.add_action(action) action = SimpleAction.new("quit", None) action.connect("activate", self.on_quit) self.add_action(action) self.set_app_menu(AppMenu())
def register_accels(app: Gtk.Application): for name, accel in VIEW_ACCELERATORS.items(): accel = accel if isinstance(accel, tuple) else (accel,) app.set_accels_for_action(name, accel)
def do_startup(self): Application.do_startup(self)