Simplify action creation
This commit is contained in:
61
src/main.py
61
src/main.py
@@ -67,28 +67,28 @@ class CartridgesApplication(Adw.Application):
|
|||||||
# Create actions
|
# Create actions
|
||||||
self.create_actions(
|
self.create_actions(
|
||||||
{
|
{
|
||||||
(self, "quit", ("<primary>q",)),
|
("quit", ("<primary>q",)),
|
||||||
(self, "about", None),
|
("about",),
|
||||||
(self, "preferences", ("<primary>comma",)),
|
("preferences", ("<primary>comma",)),
|
||||||
(self, "launch_game", None),
|
("launch_game",),
|
||||||
(self, "hide_game", None),
|
("hide_game",),
|
||||||
(self, "edit_game", None),
|
("edit_game",),
|
||||||
(self, "add_game", ("<primary>n",)),
|
("add_game", ("<primary>n",)),
|
||||||
(self, "import", ("<primary>i",)),
|
("import", ("<primary>i",)),
|
||||||
(self, "remove_game_details_view", ("Delete",)),
|
("remove_game_details_view", ("Delete",)),
|
||||||
(self, "remove_game", None),
|
("remove_game",),
|
||||||
(self, "igdb_search", None),
|
("igdb_search",),
|
||||||
(self, "sgdb_search", None),
|
("sgdb_search",),
|
||||||
(self, "protondb_search", None),
|
("protondb_search",),
|
||||||
(self, "lutris_search", None),
|
("lutris_search",),
|
||||||
(self, "hltb_search", None),
|
("hltb_search",),
|
||||||
(self.win, "show_hidden", ("<primary>h",)),
|
("show_hidden", ("<primary>h",), self.win),
|
||||||
(self.win, "go_back", ("<alt>Left",)),
|
("go_back", ("<alt>Left",), self.win),
|
||||||
(self.win, "go_to_parent", ("<alt>Up",)),
|
("go_to_parent", ("<alt>Up",), self.win),
|
||||||
(self.win, "toggle_search", ("<primary>f",)),
|
("toggle_search", ("<primary>f",), self.win),
|
||||||
(self.win, "escape", ("Escape",)),
|
("escape", ("Escape",), self.win),
|
||||||
(self.win, "undo", ("<primary>z",)),
|
("undo", ("<primary>z",), self.win),
|
||||||
(self.win, "open_menu", ("F10",)),
|
("open_menu", ("F10",), self.win),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -204,17 +204,18 @@ class CartridgesApplication(Adw.Application):
|
|||||||
|
|
||||||
def create_actions(self, actions):
|
def create_actions(self, actions):
|
||||||
for action in actions:
|
for action in actions:
|
||||||
simple_action = Gio.SimpleAction.new(action[1], None)
|
simple_action = Gio.SimpleAction.new(action[0], None)
|
||||||
simple_action.connect(
|
|
||||||
"activate", getattr(action[0], f"on_{action[1]}_action")
|
scope = action[2] if action[2:3] else self
|
||||||
)
|
simple_action.connect("activate", getattr(scope, f"on_{action[0]}_action"))
|
||||||
if action[2]:
|
|
||||||
|
if action[1:2]:
|
||||||
self.set_accels_for_action(
|
self.set_accels_for_action(
|
||||||
f"app.{action[1]}" if action[0] == self else f"win.{action[1]}",
|
f"app.{action[0]}" if scope == self else f"win.{action[0]}",
|
||||||
action[2],
|
action[1],
|
||||||
)
|
)
|
||||||
|
|
||||||
action[0].add_action(simple_action)
|
scope.add_action(simple_action)
|
||||||
|
|
||||||
|
|
||||||
def main(version): # pylint: disable=unused-argument
|
def main(version): # pylint: disable=unused-argument
|
||||||
|
|||||||
Reference in New Issue
Block a user