diff options
author | Seth Hitefield <sdhitefield@gmail.com> | 2017-05-11 15:31:50 -0400 |
---|---|---|
committer | Johnathan Corgan <johnathan@corganlabs.com> | 2017-05-11 12:52:11 -0700 |
commit | ef139ce3f10e181edfafafcc08ae26cec54221ed (patch) | |
tree | 3401606c180e8a4431eb791d865eb4fb41fd2099 /grc | |
parent | 69172b07723872df00ac1ab821acebd2b0a56e6a (diff) |
grc: gtk3: Small fixes for PR 1299
Diffstat (limited to 'grc')
-rw-r--r-- | grc/gui/DrawingArea.py | 53 | ||||
-rw-r--r-- | grc/gui/MainWindow.py | 5 | ||||
-rw-r--r-- | grc/gui/Notebook.py | 9 | ||||
-rwxr-xr-x | grc/main.py | 1 |
4 files changed, 39 insertions, 29 deletions
diff --git a/grc/gui/DrawingArea.py b/grc/gui/DrawingArea.py index 2403fa2844..648f1df849 100644 --- a/grc/gui/DrawingArea.py +++ b/grc/gui/DrawingArea.py @@ -92,6 +92,29 @@ class DrawingArea(Gtk.DrawingArea): # self.set_flags(Gtk.CAN_FOCUS) # self.set_can_focus(True) # self.connect('focus-out-event', self._handle_focus_lost_event) + # Setup a map of the accelerator keys to the action to trigger + self.accels = { + Gtk.accelerator_parse('d'): Actions.BLOCK_DISABLE, + Gtk.accelerator_parse('e'): Actions.BLOCK_ENABLE, + Gtk.accelerator_parse('b'): Actions.BLOCK_BYPASS, + Gtk.accelerator_parse('c'): Actions.BLOCK_CREATE_HIER, + Gtk.accelerator_parse('Up'): Actions.BLOCK_DEC_TYPE, + Gtk.accelerator_parse('Down'): Actions.BLOCK_INC_TYPE, + Gtk.accelerator_parse('Left'): Actions.BLOCK_ROTATE_CCW, + Gtk.accelerator_parse('Right'): Actions.BLOCK_ROTATE_CW, + Gtk.accelerator_parse('minus'): Actions.PORT_CONTROLLER_DEC, + Gtk.accelerator_parse('plus'): Actions.PORT_CONTROLLER_INC, + Gtk.accelerator_parse('Add'): Actions.PORT_CONTROLLER_INC, + Gtk.accelerator_parse('Subtract'): Actions.PORT_CONTROLLER_DEC, + Gtk.accelerator_parse('Return'): Actions.BLOCK_PARAM_MODIFY, + Gtk.accelerator_parse('<Shift>t'): Actions.BLOCK_VALIGN_TOP, + Gtk.accelerator_parse('<Shift>m'): Actions.BLOCK_VALIGN_MIDDLE, + Gtk.accelerator_parse('<Shift>b'): Actions.BLOCK_VALIGN_BOTTOM, + Gtk.accelerator_parse('<Shift>l'): Actions.BLOCK_HALIGN_LEFT, + Gtk.accelerator_parse('<Shift>c'): Actions.BLOCK_HALIGN_CENTER, + Gtk.accelerator_parse('<Shift>r'): Actions.BLOCK_HALIGN_RIGHT, + } + ########################################################################## # Handlers @@ -172,32 +195,12 @@ class DrawingArea(Gtk.DrawingArea): key = event.keyval mod = event.state - # Setup a map of the accelerator keys to the action to trigger - accels = { - Gtk.accelerator_parse('d'): Actions.BLOCK_DISABLE, - Gtk.accelerator_parse('e'): Actions.BLOCK_ENABLE, - Gtk.accelerator_parse('b'): Actions.BLOCK_BYPASS, - Gtk.accelerator_parse('c'): Actions.BLOCK_CREATE_HIER, - Gtk.accelerator_parse('Up'): Actions.BLOCK_DEC_TYPE, - Gtk.accelerator_parse('Down'): Actions.BLOCK_INC_TYPE, - Gtk.accelerator_parse('Left'): Actions.BLOCK_ROTATE_CCW, - Gtk.accelerator_parse('Right'): Actions.BLOCK_ROTATE_CW, - Gtk.accelerator_parse('minus'): Actions.PORT_CONTROLLER_DEC, - Gtk.accelerator_parse('plus'): Actions.PORT_CONTROLLER_INC, - Gtk.accelerator_parse('Add'): Actions.PORT_CONTROLLER_INC, - Gtk.accelerator_parse('Subtract'): Actions.PORT_CONTROLLER_DEC, - Gtk.accelerator_parse('Return'): Actions.BLOCK_PARAM_MODIFY, - Gtk.accelerator_parse('<Shift>t'): Actions.BLOCK_VALIGN_TOP, - Gtk.accelerator_parse('<Shift>m'): Actions.BLOCK_VALIGN_MIDDLE, - Gtk.accelerator_parse('<Shift>b'): Actions.BLOCK_VALIGN_BOTTOM, - Gtk.accelerator_parse('<Shift>l'): Actions.BLOCK_HALIGN_LEFT, - Gtk.accelerator_parse('<Shift>c'): Actions.BLOCK_HALIGN_CENTER, - Gtk.accelerator_parse('<Shift>r'): Actions.BLOCK_HALIGN_RIGHT, - } - # Not sold on this. - if (key, mod) in accels: - accels[(key, mod)]() + try: + action = self.accels[(key, mod)] + action() return True + except KeyError: + return False def _update_size(self): w, h = self._flow_graph.get_extents()[2:] diff --git a/grc/gui/MainWindow.py b/grc/gui/MainWindow.py index 38fd9a71a1..f913d63966 100644 --- a/grc/gui/MainWindow.py +++ b/grc/gui/MainWindow.py @@ -63,8 +63,9 @@ class MainWindow(Gtk.ApplicationWindow): self.config = platform.config # Add all "win" actions to the local - win_actions = filter(lambda x: x.startswith("win."), Actions.get_actions()) - map(lambda x: self.add_action(Actions.actions[x]), win_actions) + for x in Actions.get_actions(): + if x.startswith("win."): + self.add_action(Actions.actions[x]) # Setup window vbox = Gtk.VBox() diff --git a/grc/gui/Notebook.py b/grc/gui/Notebook.py index ef08961036..21db913c0e 100644 --- a/grc/gui/Notebook.py +++ b/grc/gui/Notebook.py @@ -129,12 +129,19 @@ class Page(Gtk.HBox): self.scrolled_window = Gtk.ScrolledWindow() self.scrolled_window.set_size_request(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT) self.scrolled_window.set_policy(Gtk.PolicyType.ALWAYS, Gtk.PolicyType.ALWAYS) + self.scrolled_window.connect('key-press-event', self._handle_scroll_window_key_press) self.scrolled_window.add(self.drawing_area) self.pack_start(self.scrolled_window, True, True, 0) self.show_all() - + def _handle_scroll_window_key_press(self, widget, event): + is_ctrl_pg = ( + event.state & Gdk.ModifierType.CONTROL_MASK and + event.keyval in (Gdk.KEY_Page_Up, Gdk.KEY_Page_Down) + ) + if is_ctrl_pg: + return self.get_parent().event(event) def get_generator(self): """ diff --git a/grc/main.py b/grc/main.py index 224a9b11e8..4d04608269 100755 --- a/grc/main.py +++ b/grc/main.py @@ -74,7 +74,6 @@ def main(): log.debug("Running main") # Delay importing until the logging is setup - # Otherwise, the decorators could not use logging. from .gui.Platform import Platform from .gui.Application import Application |