File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33from activity_browser import application
44from activity_browser .actions .base import ABAction , exception_dialogs
55from activity_browser .ui .icons import qicons
6- from activity_browser .ui .widgets . main_window import global_shortcut
6+ from activity_browser .ui .application import global_shortcut
77
88log = getLogger (__name__ )
99
@@ -18,11 +18,6 @@ class MetaDataStoreOpen(ABAction):
1818 @exception_dialogs
1919 def run ():
2020 from activity_browser .layouts import pages
21- print ("Running MetaDataStoreOpen action" )
22-
23- # Create a details page for the activity
2421 page = pages .MetaDataStorePage ()
2522 central = application .main_window .centralWidget ()
26-
27- # Add the details page to the "Activity Details" group in the central widget
2823 central .addToGroup ("DEBUG" , page )
Original file line number Diff line number Diff line change @@ -82,6 +82,11 @@ def main_window(self) -> QtWidgets.QMainWindow:
8282 def main_window (self , widget : QtWidgets .QMainWindow ):
8383 self ._main_window = widget
8484
85+ # connect global keyboard shortcuts to their respective functions
86+ for seq , func in _global_shortcuts .items ():
87+ shortcut = QtWidgets .QShortcut (QtGui .QKeySequence (seq ), widget )
88+ shortcut .activated .connect (func )
89+
8590 def show (self ):
8691 self .main_window .showMaximized ()
8792
@@ -94,6 +99,20 @@ def deleteLater(self):
9499 self .main_window .deleteLater ()
95100
96101
102+ def global_shortcut (key_sequence ):
103+ """
104+ Decorator to register a global keyboard shortcut for the main window. Decorate a function with e.g.
105+ @global_shortcut("Ctrl+S") to register it as a shortcut. Also works on the run method of actions as long as the
106+ parameters of said action are taken care of.
107+ """
108+ def decorator (func ):
109+ _global_shortcuts [key_sequence ] = func
110+ return func
111+ return decorator
112+
113+ _global_shortcuts = {}
114+
115+
97116application = ABApplication ()
98117
99118
Original file line number Diff line number Diff line change @@ -27,7 +27,6 @@ def __init__(self, parent=None):
2727 self .setMenuBar (self .menu_bar )
2828
2929 self .connect_signals ()
30- self .connect_shortcuts ()
3130
3231 def sync (self ):
3332 """
@@ -88,12 +87,6 @@ def connect_signals(self):
8887 # Keyboard shortcuts
8988 signals .project .changed .connect (self .sync )
9089
91- def connect_shortcuts (self ):
92- """Connect global keyboard shortcuts to their respective functions. Only called once during initialization."""
93- for seq , func in _main_window_shortcuts .items ():
94- shortcut = QtWidgets .QShortcut (QtGui .QKeySequence (seq ), self )
95- shortcut .activated .connect (func )
96-
9790 def clearPanes (self ):
9891 for pane in self .panes ():
9992 pane .deleteLater ()
@@ -116,16 +109,3 @@ def dialog_on_exception(self, exception: Exception):
116109 QtWidgets .QMessageBox .Ok ,
117110 )
118111
119-
120- def global_shortcut (key_sequence ):
121- """
122- Decorator to register a global keyboard shortcut for the main window. Decorate a function with e.g.
123- @global_shortcut("Ctrl+S") to register it as a shortcut. Also works on the run method of actions as long as the
124- parameters of said action are taken care of.
125- """
126- def decorator (func ):
127- _main_window_shortcuts [key_sequence ] = func
128- return func
129- return decorator
130-
131- _main_window_shortcuts = {}
You can’t perform that action at this time.
0 commit comments