Commit ea576566 authored by sumpfralle's avatar sumpfralle

unified the GTK accel group for all windows

enabled "CTRL-w" as an accelerator for "close window"


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1260 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 4572bdfb
...@@ -453,6 +453,7 @@ class ProjectGui(object): ...@@ -453,6 +453,7 @@ class ProjectGui(object):
self.settings.get("configure-drag-drop-func")(self.window) self.settings.get("configure-drag-drop-func")(self.window)
# other events # other events
self.window.connect("destroy", self.destroy) self.window.connect("destroy", self.destroy)
self.window.connect("delete-event", self.destroy)
# the settings window # the settings window
self.gui.get_object("CloseSettingsWindow").connect("clicked", self.toggle_preferences_window, False) self.gui.get_object("CloseSettingsWindow").connect("clicked", self.toggle_preferences_window, False)
self.gui.get_object("ResetPreferencesButton").connect("clicked", self.reset_preferences) self.gui.get_object("ResetPreferencesButton").connect("clicked", self.reset_preferences)
...@@ -472,9 +473,15 @@ class ProjectGui(object): ...@@ -472,9 +473,15 @@ class ProjectGui(object):
uimanager = gtk.UIManager() uimanager = gtk.UIManager()
self.settings.set("gtk-uimanager", uimanager) self.settings.set("gtk-uimanager", uimanager)
self._accel_group = uimanager.get_accel_group() self._accel_group = uimanager.get_accel_group()
# send a "delete" event on "CTRL-w" for every window
def handle_window_close(accel_group, window, *args):
window.emit("delete-event", gtk.gdk.Event(gtk.gdk.DELETE))
self._accel_group.connect_group(ord('w'), gtk.gdk.CONTROL_MASK,
gtk.ACCEL_LOCKED, handle_window_close)
self.settings.add_item("gtk-accel-group", lambda: self._accel_group) self.settings.add_item("gtk-accel-group", lambda: self._accel_group)
for window in (self.window, self.about_window, self.preferences_window): for obj in self.gui.get_objects():
window.add_accel_group(self._accel_group) if isinstance(obj, gtk.Window):
obj.add_accel_group(self._accel_group)
# preferences tab # preferences tab
preferences_book = self.gui.get_object("PreferencesNotebook") preferences_book = self.gui.get_object("PreferencesNotebook")
def clear_preferences(): def clear_preferences():
......
...@@ -80,8 +80,6 @@ class Fonts(pycam.Plugins.PluginBase): ...@@ -80,8 +80,6 @@ class Fonts(pycam.Plugins.PluginBase):
self._gtk_handlers.append((self.gui.get_object(objname), self._gtk_handlers.append((self.gui.get_object(objname),
"toggled", self.update_font_dialog_preview)) "toggled", self.update_font_dialog_preview))
# use global key accel map # use global key accel map
self.font_dialog_window.add_accel_group(
self.core.get("gtk-accel-group"))
font_action = self.gui.get_object("ShowFontDialog") font_action = self.gui.get_object("ShowFontDialog")
self.register_gtk_accelerator("fonts", font_action, self.register_gtk_accelerator("fonts", font_action,
"<Control><Shift>t", "ShowFontDialog") "<Control><Shift>t", "ShowFontDialog")
...@@ -104,8 +102,6 @@ class Fonts(pycam.Plugins.PluginBase): ...@@ -104,8 +102,6 @@ class Fonts(pycam.Plugins.PluginBase):
font_toggle = self.gui.get_object("ShowFontDialog") font_toggle = self.gui.get_object("ShowFontDialog")
self.core.unregister_ui("edit_menu", None) self.core.unregister_ui("edit_menu", None)
self.core.unregister_ui("edit_menu", font_toggle) self.core.unregister_ui("edit_menu", font_toggle)
self.font_dialog_window.remove_accel_group(
self.core.get("gtk-accel-group"))
self.unregister_gtk_accelerator("fonts", font_toggle) self.unregister_gtk_accelerator("fonts", font_toggle)
self.unregister_gtk_handlers(self._gtk_handlers) self.unregister_gtk_handlers(self._gtk_handlers)
......
...@@ -83,7 +83,6 @@ class OpenGLWindow(pycam.Plugins.PluginBase): ...@@ -83,7 +83,6 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
self.context_menu = gtk.Menu() self.context_menu = gtk.Menu()
self.window = self.gui.get_object("OpenGLWindow") self.window = self.gui.get_object("OpenGLWindow")
self.core.get("configure-drag-drop-func")(self.window) self.core.get("configure-drag-drop-func")(self.window)
self.window.add_accel_group(self.core.get("gtk-accel-group"))
self.initialized = False self.initialized = False
self.busy = False self.busy = False
self.is_visible = False self.is_visible = False
...@@ -237,7 +236,6 @@ class OpenGLWindow(pycam.Plugins.PluginBase): ...@@ -237,7 +236,6 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
self.core.get("unregister_color")(name) self.core.get("unregister_color")(name)
for name in ("show_drill", "show_directions"): for name in ("show_drill", "show_directions"):
self.core.get("unregister_display_item")(name) self.core.get("unregister_display_item")(name)
self.window.remove_accel_group(self.core.get("gtk-accel-group"))
self.unregister_gtk_handlers(self._gtk_handlers) self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers) self.unregister_event_handlers(self._event_handlers)
# the area will be created during setup again # the area will be created during setup again
......
...@@ -49,8 +49,6 @@ class ParallelProcessing(pycam.Plugins.PluginBase): ...@@ -49,8 +49,6 @@ class ParallelProcessing(pycam.Plugins.PluginBase):
self.toggle_process_pool_window, False), self.toggle_process_pool_window, False),
(self.process_pool_window, "destroy", (self.process_pool_window, "destroy",
self.toggle_process_pool_window, False))) self.toggle_process_pool_window, False)))
self.process_pool_window.add_accel_group(
self.core.get("gtk-accel-group"))
self._gtk_handlers.append(( self._gtk_handlers.append((
self.gui.get_object("ProcessPoolWindowClose"), "clicked", self.gui.get_object("ProcessPoolWindowClose"), "clicked",
self.toggle_process_pool_window, False)) self.toggle_process_pool_window, False))
...@@ -111,8 +109,6 @@ class ParallelProcessing(pycam.Plugins.PluginBase): ...@@ -111,8 +109,6 @@ class ParallelProcessing(pycam.Plugins.PluginBase):
self.gui.get_object("MultiprocessingFrame")) self.gui.get_object("MultiprocessingFrame"))
toggle_button = self.gui.get_object("ToggleProcessPoolWindow") toggle_button = self.gui.get_object("ToggleProcessPoolWindow")
self.core.unregister_ui("view_menu", toggle_button) self.core.unregister_ui("view_menu", toggle_button)
self.process_pool_window.remove_accel_group(
self.core.get("gtk-accel-group"))
self.unregister_gtk_accelerator("processes", toggle_button) self.unregister_gtk_accelerator("processes", toggle_button)
self.unregister_gtk_handlers(self._gtk_handlers) self.unregister_gtk_handlers(self._gtk_handlers)
......
...@@ -44,8 +44,6 @@ class PluginSelector(pycam.Plugins.PluginBase): ...@@ -44,8 +44,6 @@ class PluginSelector(pycam.Plugins.PluginBase):
self.toggle_plugin_window, False), self.toggle_plugin_window, False),
(self.plugin_window, "destroy", (self.plugin_window, "destroy",
self.toggle_plugin_window, False))) self.toggle_plugin_window, False)))
self.plugin_window.add_accel_group(
self.core.get("gtk-accel-group"))
self._gtk_handlers.append(( self._gtk_handlers.append((
self.gui.get_object("ClosePluginManager"), "clicked", self.gui.get_object("ClosePluginManager"), "clicked",
self.toggle_plugin_window, False)) self.toggle_plugin_window, False))
...@@ -80,8 +78,6 @@ class PluginSelector(pycam.Plugins.PluginBase): ...@@ -80,8 +78,6 @@ class PluginSelector(pycam.Plugins.PluginBase):
self.core.register_ui("view_menu", action) self.core.register_ui("view_menu", action)
self.core.unregister_event("plugin-list-changed", self.core.unregister_event("plugin-list-changed",
self._update_plugin_model) self._update_plugin_model)
self.plugin_window.remove_accel_group(
self.core.get("gtk-accel-group"))
self.unregister_gtk_handlers(self._gtk_handlers) self.unregister_gtk_handlers(self._gtk_handlers)
def toggle_plugin_window(self, widget=None, value=None, action=None): def toggle_plugin_window(self, widget=None, value=None, action=None):
......
...@@ -60,6 +60,15 @@ class PluginBase(object): ...@@ -60,6 +60,15 @@ class PluginBase(object):
self.log.info("Failed to import UI file (%s): %s" % \ self.log.info("Failed to import UI file (%s): %s" % \
(gtk_build_file, err_msg)) (gtk_build_file, err_msg))
self.gui = None self.gui = None
else:
# All windows should share the same accel group (for
# keyboard shortcuts).
common_accel_group = self.core["gtk-accel-group"]
if common_accel_group:
for obj in self.gui.get_objects():
if isinstance(obj, gtk.Window):
obj.add_accel_group(common_accel_group)
for key in self.ICONS: for key in self.ICONS:
icon_location = pycam.Utils.locations.get_ui_file_location( icon_location = pycam.Utils.locations.get_ui_file_location(
self.ICONS[key]) self.ICONS[key])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment