Skip to content

[ENH] Adjust MenuAction #114

Description

@genedan

There's some repetitive code here:

FASLR/faslr/menu.py

Lines 58 to 78 in 73799da

self.connection_action = MenuAction(ICONS_PATH + "db.svg", "&Connection", self)
self.connection_action.setShortcut(QKeySequence("Ctrl+Shift+c"))
self.connection_action.setStatusTip("Edit database connection.")
# noinspection PyUnresolvedReferences
self.connection_action.triggered.connect(self.edit_connection)
self.new_action = QAction("&New Project", self)
self.new_action.setShortcut(QKeySequence("Ctrl+n"))
self.new_action.setStatusTip("Create new project.")
# noinspection PyUnresolvedReferences
self.new_action.triggered.connect(self.new_project)
self.import_action = QAction("&Import Project")
self.import_action.setShortcut(QKeySequence("Ctrl+Shift+i"))
self.import_action.setStatusTip("Import a project from another data source.")
self.engine_action = QAction("&Select Engine")
self.engine_action.setShortcut("Ctrl+shift+e")
self.engine_action.setStatusTip("Select a reserving engine.")
self.engine_action.triggered.connect(self.display_engine) # noqa

Since the methods such as setShortcut and setStatusTip are called shortly after object initialization, we can make the code a bit more readable by adding parameters to the new MenuAction class. Thus:

self.new_action = QAction("&New Project", self)
self.new_action.setShortcut(QKeySequence("Ctrl+n"))
self.new_action.setStatusTip("Create new project.")
self.new_action.triggered.connect(self.new_project)

Will become something like:

self.new_action = MenuAction(
    label="&New Project"
    key_sequence="Ctrl+n"
    status_tip="Create new project."
    connect=self.new_project
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Scope

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions