Commit 2f6fbc1e authored by sumpfralle's avatar sumpfralle

register events and gtk widget signals via a global list -> cleaner setup/teardown for modules


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1171 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent d935f820
...@@ -136,14 +136,11 @@ class Bounds(pycam.Plugins.ListPluginBase): ...@@ -136,14 +136,11 @@ class Bounds(pycam.Plugins.ListPluginBase):
self._edit_bounds_name) self._edit_bounds_name)
self.gui.get_object("ModelDescriptionColumn").set_cell_data_func( self.gui.get_object("ModelDescriptionColumn").set_cell_data_func(
self.gui.get_object("ModelNameCell"), self._render_model_name) self.gui.get_object("ModelNameCell"), self._render_model_name)
self.core.register_event("bounds-selection-changed", self._event_handlers = (("bounds-selection-changed", self._switch_bounds),
self._switch_bounds) ("bounds-changed", self._store_bounds_settings),
self.core.register_event("bounds-changed", ("bounds-changed", self._trigger_table_update),
self._store_bounds_settings) ("model-list-changed", self._update_model_list))
self.core.register_event("bounds-changed", self.register_event_handlers(self._event_handlers)
self._trigger_table_update)
self.core.register_event("model-list-changed",
self._update_model_list)
self._trigger_table_update() self._trigger_table_update()
self._switch_bounds() self._switch_bounds()
self._update_model_list() self._update_model_list()
...@@ -155,14 +152,7 @@ class Bounds(pycam.Plugins.ListPluginBase): ...@@ -155,14 +152,7 @@ class Bounds(pycam.Plugins.ListPluginBase):
def teardown(self): def teardown(self):
if self.gui: if self.gui:
self.core.unregister_ui("main", self.gui.get_object("BoundsBox")) self.core.unregister_ui("main", self.gui.get_object("BoundsBox"))
self.core.unregister_event("bounds-selection-changed", self.unregister_event_handlers(self._event_handlers)
self._switch_bounds)
self.core.unregister_event("bounds-changed",
self._store_bounds_settings)
self.core.unregister_event("bounds-changed",
self._trigger_table_update)
self.core.unregister_event("model-list-changed",
self._update_model_list)
self.core.set("bounds", None) self.core.set("bounds", None)
return True return True
......
...@@ -46,38 +46,42 @@ class Clipboard(pycam.Plugins.PluginBase): ...@@ -46,38 +46,42 @@ class Clipboard(pycam.Plugins.PluginBase):
if self.gui: if self.gui:
import gtk import gtk
self._gtk = gtk self._gtk = gtk
self._gtk_handlers = []
self.clipboard = self._gtk.clipboard_get() self.clipboard = self._gtk.clipboard_get()
self.core.set("clipboard-set", self._copy_text_to_clipboard) self.core.set("clipboard-set", self._copy_text_to_clipboard)
self.clipboard.connect("owner-change", self._update_clipboard_widget) self._gtk_handlers.append((self.clipboard, "owner-change",
self.core.register_event("model-selection-changed", self._update_clipboard_widget))
self._update_clipboard_widget)
# menu item and shortcut # menu item and shortcut
self.copy_action = self.gui.get_object("CopyModelToClipboard") self.copy_action = self.gui.get_object("CopyModelToClipboard")
self.copy_action.connect("activate", self.copy_model_to_clipboard) self._gtk_handlers.append((self.copy_action, "activate",
self.copy_model_to_clipboard))
self.register_gtk_accelerator("clipboard", self.copy_action, self.register_gtk_accelerator("clipboard", self.copy_action,
"<Control>c", "CopyModelToClipboard") "<Control>c", "CopyModelToClipboard")
self.core.register_ui("edit_menu", "CopyModelToClipboard", self.core.register_ui("edit_menu", "CopyModelToClipboard",
self.copy_action, 20) self.copy_action, 20)
self.paste_action = self.gui.get_object("PasteModelFromClipboard") self.paste_action = self.gui.get_object("PasteModelFromClipboard")
self.paste_action.connect("activate", self.paste_model_from_clipboard) self._gtk_handlers.append((self.paste_action, "activate",
self.paste_model_from_clipboard))
self.register_gtk_accelerator("clipboard", self.paste_action, self.register_gtk_accelerator("clipboard", self.paste_action,
"<Control>v", "PasteModelFromClipboard") "<Control>v", "PasteModelFromClipboard")
self.core.register_ui("edit_menu", "PasteModelFromClipboard", self.core.register_ui("edit_menu", "PasteModelFromClipboard",
self.paste_action, 25) self.paste_action, 25)
self._event_handlers = (("model-selection-changed",
self._update_clipboard_widget), )
self.register_event_handlers(self._event_handlers)
self.register_gtk_handlers(self._gtk_handlers)
self._update_clipboard_widget() self._update_clipboard_widget()
return True return True
def teardown(self): def teardown(self):
if self.gui: if self.gui:
self.core.unregister_event("model-selection-changed", self.unregister_event_handlers(self._event_handlers)
self._update_clipboard_widget) self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_gtk_accelerator("clipboard", self.copy_action) self.unregister_gtk_accelerator("clipboard", self.copy_action)
self.core.unregister_ui("edit_menu", self.copy_action) self.core.unregister_ui("edit_menu", self.copy_action)
self.unregister_gtk_accelerator("clipboard", self.paste_action) self.unregister_gtk_accelerator("clipboard", self.paste_action)
self.core.unregister_ui("edit_menu", self.paste_action) self.core.unregister_ui("edit_menu", self.paste_action)
self.core.set("clipboard-set", None) self.core.set("clipboard-set", None)
# TODO: check if this disconnects the clipboard-change-handler
self.clipboard = None
def _get_exportable_models(self): def _get_exportable_models(self):
models = self.core.get("models").get_selected() models = self.core.get("models").get_selected()
......
...@@ -38,11 +38,14 @@ class EMCToolExport(pycam.Plugins.PluginBase): ...@@ -38,11 +38,14 @@ class EMCToolExport(pycam.Plugins.PluginBase):
self.export_action = self.gui.get_object("ExportEMCToolDefinition") self.export_action = self.gui.get_object("ExportEMCToolDefinition")
self.register_gtk_accelerator("export", self.export_action, None, self.register_gtk_accelerator("export", self.export_action, None,
"ExportEMCToolDefinition") "ExportEMCToolDefinition")
self.export_action.connect("activate", self.export_emc_tools) self._gtk_handlers = ((self.export_action, "activate",
self.export_emc_tools), )
self.core.register_ui("export_menu", "ExportEMCToolDefinition", self.core.register_ui("export_menu", "ExportEMCToolDefinition",
self.export_action, 80) self.export_action, 80)
self.core.register_event("tool-selection-changed", self._event_handlers = (("tool-selection-changed",
self._update_emc_tool_button) self._update_emc_tool_button), )
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self._update_emc_tool_button() self._update_emc_tool_button()
return True return True
...@@ -50,8 +53,8 @@ class EMCToolExport(pycam.Plugins.PluginBase): ...@@ -50,8 +53,8 @@ class EMCToolExport(pycam.Plugins.PluginBase):
if self.gui: if self.gui:
self.core.unregister_ui("export_menu", self.export_emc_tools) self.core.unregister_ui("export_menu", self.export_emc_tools)
self.unregister_gtk_accelerator("fonts", self.export_emc_tools) self.unregister_gtk_accelerator("fonts", self.export_emc_tools)
self.core.unregister_event("tool-selection-changed", self.unregister_gtk_handlers(self._gtk_handlers)
self._update_emc_tool_button) self.unregister_event_handlers(self._event_handlers)
def _update_emc_tool_button(self, widget=None): def _update_emc_tool_button(self, widget=None):
exportable = len(self.core.get("tools")) > 0 exportable = len(self.core.get("tools")) > 0
......
...@@ -41,48 +41,51 @@ class Fonts(pycam.Plugins.PluginBase): ...@@ -41,48 +41,51 @@ class Fonts(pycam.Plugins.PluginBase):
def setup(self): def setup(self):
self._fonts_cache = pycam.Utils.FontCache.FontCache(get_font_dir(), self._fonts_cache = pycam.Utils.FontCache.FontCache(get_font_dir(),
core=self.core) core=self.core)
self.core.add_item("fonts", lambda: self._fonts_cache) self.core.set("fonts", self._fonts_cache)
# "font dialog" window # "font dialog" window
if self.gui: if self.gui:
import gtk import gtk
self._gtk = gtk self._gtk = gtk
self.font_dialog_window = self.gui.get_object("FontDialog") self.font_dialog_window = self.gui.get_object("FontDialog")
self.font_dialog_window.connect("delete-event", window = self.font_dialog_window
self.toggle_font_dialog_window, False) hide_window = lambda *args: \
self.font_dialog_window.connect("destroy", self.toggle_font_dialog_window(state=False)
self.toggle_font_dialog_window, False) self._gtk_handlers = [(window, "delete-event", hide_window),
self.gui.get_object("FontDialogCancel").connect("clicked", (window, "destroy", hide_window),
self.toggle_font_dialog_window, False) (self.gui.get_object("FontDialogCancel"), "clicked",
self.gui.get_object("FontDialogApply").connect("clicked", hide_window),
self.import_from_font_dialog) (self.gui.get_object("FontDialogApply"), "clicked",
self.gui.get_object("FontDialogSave").connect("clicked", self.import_from_font_dialog),
self.export_from_font_dialog) (self.gui.get_object("FontDialogSave"), "clicked",
self.gui.get_object("FontDialogCopy").connect("clicked", self.export_from_font_dialog),
self.copy_font_dialog_to_clipboard) (self.gui.get_object("FontDialogCopy"), "clicked",
self.gui.get_object("FontDialogInputBuffer").connect("changed", self.copy_font_dialog_to_clipboard),
self.update_font_dialog_preview) (self.gui.get_object("FontDialogInputBuffer"), "changed",
self.gui.get_object("FontDialogPreview").connect("configure_event", self.update_font_dialog_preview),
self.update_font_dialog_preview) (self.gui.get_object("FontDialogPreview"),
self.gui.get_object("FontDialogPreview").connect("expose_event", "configure_event", self.update_font_dialog_preview),
self.update_font_dialog_preview) (self.gui.get_object("FontDialogPreview"), "expose_event",
self.update_font_dialog_preview)]
for objname in ("FontSideSkewValue", "FontCharacterSpacingValue", for objname in ("FontSideSkewValue", "FontCharacterSpacingValue",
"FontLineSpacingValue"): "FontLineSpacingValue"):
obj = self.gui.get_object(objname) obj = self.gui.get_object(objname)
# set default value before connecting the change-handler # set default value before connecting the change-handler
if objname != "FontSideSkewValue": if objname != "FontSideSkewValue":
obj.set_value(1.0) obj.set_value(1.0)
obj.connect("value-changed", self._gtk_handlers.append((obj, "value-changed",
self.update_font_dialog_preview) self.update_font_dialog_preview))
for objname in ("FontTextAlignLeft", "FontTextAlignCenter", for objname in ("FontTextAlignLeft", "FontTextAlignCenter",
"FontTextAlignRight"): "FontTextAlignRight"):
self.gui.get_object(objname).connect("toggled", self._gtk_handlers.append((self.gui.get_object(objname),
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")) 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")
font_action.connect("activate", self.toggle_font_dialog_window) self._gtk_handlers.append((font_action, "activate",
self.toggle_font_dialog_window))
self.core.register_ui("edit_menu", "ShowFontDialogSeparator", self.core.register_ui("edit_menu", "ShowFontDialogSeparator",
None, 55) None, 55)
self.core.register_ui("edit_menu", "ShowFontDialog", font_action, self.core.register_ui("edit_menu", "ShowFontDialog", font_action,
...@@ -91,6 +94,7 @@ class Fonts(pycam.Plugins.PluginBase): ...@@ -91,6 +94,7 @@ class Fonts(pycam.Plugins.PluginBase):
self._font_dialog_window_visible = False self._font_dialog_window_visible = False
self._font_dialog_window_position = None self._font_dialog_window_position = None
self.font_selector = None self.font_selector = None
self.register_gtk_handlers(self._gtk_handlers)
return True return True
def teardown(self): def teardown(self):
...@@ -99,6 +103,7 @@ class Fonts(pycam.Plugins.PluginBase): ...@@ -99,6 +103,7 @@ 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", font_toggle) self.core.unregister_ui("edit_menu", font_toggle)
self.unregister_gtk_accelerator("fonts", font_toggle) self.unregister_gtk_accelerator("fonts", font_toggle)
self.unregister_gtk_handlers(self._gtk_handlers)
def toggle_font_dialog_window(self, widget=None, event=None, state=None): def toggle_font_dialog_window(self, widget=None, event=None, state=None):
# only "delete-event" uses four arguments # only "delete-event" uses four arguments
......
...@@ -39,31 +39,38 @@ class Log(pycam.Plugins.PluginBase): ...@@ -39,31 +39,38 @@ class Log(pycam.Plugins.PluginBase):
self._gtk = gtk self._gtk = gtk
# menu item and shortcut # menu item and shortcut
log_action = self.gui.get_object("ToggleLogWindow") log_action = self.gui.get_object("ToggleLogWindow")
log_action.connect("toggled", self.toggle_log_window) self._gtk_handlers = []
self._gtk_handlers.append((log_action, "toggled",
self.toggle_log_window))
self.register_gtk_accelerator("log", log_action, self.register_gtk_accelerator("log", log_action,
"<Control>l", "ToggleLogWindow") "<Control>l", "ToggleLogWindow")
self.core.register_ui("view_menu", "ToggleLogWindow", log_action, 100) self.core.register_ui("view_menu", "ToggleLogWindow", log_action,
100)
# status bar # status bar
self.status_bar = self.gui.get_object("StatusBar") self.status_bar = self.gui.get_object("StatusBar")
self.gui.get_object("StatusBarEventBox").connect(
"button-press-event", self.toggle_log_window)
event_bar = self.gui.get_object("StatusBarEventBox") event_bar = self.gui.get_object("StatusBarEventBox")
self._gtk_handlers.append((event_bar, "button-press-event",
self.toggle_log_window))
event_bar.unparent() event_bar.unparent()
self.core.register_ui("main_window", "Status", event_bar, 100) self.core.register_ui("main_window", "Status", event_bar, 100)
# "log" window # "log" window
self.log_window = self.gui.get_object("LogWindow") self.log_window = self.gui.get_object("LogWindow")
self.log_window.set_default_size(500, 400) self.log_window.set_default_size(500, 400)
self.log_window.connect("delete-event", self.toggle_log_window, False) hide_window = lambda *args: self.toggle_log_window(state=False)
self.log_window.connect("destroy", self.toggle_log_window, False) self._gtk_handlers.extend([
self.gui.get_object("LogWindowClose").connect("clicked", self.toggle_log_window, False) (self.log_window, "delete-event", hide_window),
self.gui.get_object("LogWindowClear").connect("clicked", self.clear_log_window) (self.log_window, "destroy", hide_window),
self.gui.get_object("LogWindowCopyToClipboard").connect("clicked", (self.gui.get_object("LogWindowClose"), "clicked", hide_window),
self.copy_log_to_clipboard) (self.gui.get_object("LogWindowClear"), "clicked",
self.clear_log_window),
(self.gui.get_object("LogWindowCopyToClipboard"), "clicked",
self.copy_log_to_clipboard)])
self.log_model = self.gui.get_object("LogWindowList") self.log_model = self.gui.get_object("LogWindowList")
# window state # window state
self._log_window_position = None self._log_window_position = None
# register a callback for the log window # register a callback for the log window
pycam.Utils.log.add_hook(self.add_log_message) pycam.Utils.log.add_hook(self.add_log_message)
self.register_gtk_handlers(self._gtk_handlers)
return True return True
def teardown(self): def teardown(self):
...@@ -76,6 +83,7 @@ class Log(pycam.Plugins.PluginBase): ...@@ -76,6 +83,7 @@ class Log(pycam.Plugins.PluginBase):
self.gui.get_object("StatusBarEventBox")) self.gui.get_object("StatusBarEventBox"))
self.core.unregister_ui("view_menu", self.core.unregister_ui("view_menu",
self.gui.get_object("ToggleLogWindow")) self.gui.get_object("ToggleLogWindow"))
self.unregister_gtk_handlers(self._gtk_handlers)
# TODO: disconnect the log handler # TODO: disconnect the log handler
def add_log_message(self, title, message, record=None): def add_log_message(self, title, message, record=None):
......
...@@ -44,14 +44,13 @@ class ModelExtrusion(pycam.Plugins.PluginBase): ...@@ -44,14 +44,13 @@ class ModelExtrusion(pycam.Plugins.PluginBase):
if self.gui: if self.gui:
extrusion_frame = self.gui.get_object("ModelExtrusionFrame") extrusion_frame = self.gui.get_object("ModelExtrusionFrame")
extrusion_frame.unparent() extrusion_frame.unparent()
self.core.register_event("model-change-after", self._gtk_handlers = ((self.gui.get_object("ExtrudeButton"),
self._update_extrude_widgets) "clicked", self._extrude_model), )
self.core.register_event("model-selection-changed", self._event_handlers = (
self._update_extrude_widgets) ("model-change-after", self._update_extrude_widgets),
("model-selection-changed", self._update_extrude_widgets))
self.core.register_ui("model_handling", "Extrusion", self.core.register_ui("model_handling", "Extrusion",
extrusion_frame, 5) extrusion_frame, 5)
self.gui.get_object("ExtrudeButton").connect("clicked",
self._extrude_model)
self.gui.get_object("ExtrusionHeight").set_value(1) self.gui.get_object("ExtrusionHeight").set_value(1)
self.gui.get_object("ExtrusionWidth").set_value(1) self.gui.get_object("ExtrusionWidth").set_value(1)
self.gui.get_object("ExtrusionGrid").set_value(0.5) self.gui.get_object("ExtrusionGrid").set_value(0.5)
...@@ -60,6 +59,8 @@ class ModelExtrusion(pycam.Plugins.PluginBase): ...@@ -60,6 +59,8 @@ class ModelExtrusion(pycam.Plugins.PluginBase):
extrusion_model.append((row[0], row[1], extrusion_model.append((row[0], row[1],
self.gui.get_object(row[2]).get_pixbuf())) self.gui.get_object(row[2]).get_pixbuf()))
self.gui.get_object("ExtrusionTypeSelector").set_active(0) self.gui.get_object("ExtrusionTypeSelector").set_active(0)
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self._update_extrude_widgets() self._update_extrude_widgets()
return True return True
...@@ -67,10 +68,8 @@ class ModelExtrusion(pycam.Plugins.PluginBase): ...@@ -67,10 +68,8 @@ class ModelExtrusion(pycam.Plugins.PluginBase):
if self.gui: if self.gui:
self.core.unregister_ui("model_handling", self.core.unregister_ui("model_handling",
self.gui.get_object("ModelExtrusionFrame")) self.gui.get_object("ModelExtrusionFrame"))
self.core.unregister_event("model-change-after", self.unregister_gtk_handlers(self._gtk_handlers)
self._update_extrude_widgets) self.unregister_event_handlers(self._event_handlers)
self.core.unregister_event("model-selection-changed",
self._update_extrude_widgets)
def _get_extrudable_models(self): def _get_extrudable_models(self):
models = self.core.get("models").get_selected() models = self.core.get("models").get_selected()
......
...@@ -35,19 +35,19 @@ class ModelPlaneMirror(pycam.Plugins.PluginBase): ...@@ -35,19 +35,19 @@ class ModelPlaneMirror(pycam.Plugins.PluginBase):
mirror_box = self.gui.get_object("ModelMirrorBox") mirror_box = self.gui.get_object("ModelMirrorBox")
mirror_box.unparent() mirror_box.unparent()
self.core.register_ui("model_handling", "Mirror", mirror_box, 0) self.core.register_ui("model_handling", "Mirror", mirror_box, 0)
self.gui.get_object("PlaneMirrorButton").connect("clicked", self._gtk_handlers = ((self.gui.get_object("PlaneMirrorButton"),
self._plane_mirror) "clicked", self._plane_mirror), )
self.core.register_event("model-selection-changed", self._event_handlers = (("model-selection-changed",
self._update_plane_widgets) self._update_plane_widgets), )
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self._update_plane_widgets() self._update_plane_widgets()
return True return True
def teardown(self): def teardown(self):
if self.gui: if self.gui:
self.core.unregister_ui("model_handling", self.unregister_gtk_handlers(self._gtk_handlers)
self.gui.get_object("ModelMirrorBox")) self.unregister_event_handlers(self._event_handlers)
self.core.unregister_event("model-selection-changed",
self._update_plane_widgets)
def _update_plane_widgets(self): def _update_plane_widgets(self):
plane_widget = self.gui.get_object("ModelMirrorBox") plane_widget = self.gui.get_object("ModelMirrorBox")
......
...@@ -35,14 +35,16 @@ class ModelPolygons(pycam.Plugins.PluginBase): ...@@ -35,14 +35,16 @@ class ModelPolygons(pycam.Plugins.PluginBase):
polygon_frame = self.gui.get_object("ModelPolygonFrame") polygon_frame = self.gui.get_object("ModelPolygonFrame")
polygon_frame.unparent() polygon_frame.unparent()
self.core.register_ui("model_handling", "Polygons", polygon_frame, 0) self.core.register_ui("model_handling", "Polygons", polygon_frame, 0)
self.core.register_event("model-change-after", self._gtk_handlers = (
self._update_polygon_controls) (self.gui.get_object("ToggleModelDirectionButton"), "clicked",
self.gui.get_object("ToggleModelDirectionButton").connect("clicked", self._toggle_direction),
self._toggle_direction) (self.gui.get_object("DirectionsGuessButton"), "clicked",
self.gui.get_object("DirectionsGuessButton").connect("clicked", self._revise_directions))
self._revise_directions) self._event_handlers = (
self.core.register_event("model-selection-changed", ("model-change-after", self._update_polygon_controls),
self._update_polygon_controls) ("model-selection-changed", self._update_polygon_controls))
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self._update_polygon_controls() self._update_polygon_controls()
return True return True
...@@ -50,10 +52,8 @@ class ModelPolygons(pycam.Plugins.PluginBase): ...@@ -50,10 +52,8 @@ class ModelPolygons(pycam.Plugins.PluginBase):
if self.gui: if self.gui:
self.core.unregister_ui("model_handling", self.core.unregister_ui("model_handling",
self.gui.get_object("ModelPolygonFrame")) self.gui.get_object("ModelPolygonFrame"))
self.core.unregister_event("model-change-after", self.unregister_gtk_handlers(self._gtk_handlers)
self._update_polygon_controls) self.unregister_event_handlers(self._event_handlers)
self.core.unregister_event("model-selection-changed",
self._update_polygon_controls)
def _get_polygon_models(self): def _get_polygon_models(self):
models = [] models = []
......
...@@ -34,28 +34,36 @@ class ModelPosition(pycam.Plugins.PluginBase): ...@@ -34,28 +34,36 @@ class ModelPosition(pycam.Plugins.PluginBase):
if self.gui: if self.gui:
position_box = self.gui.get_object("ModelPositionBox") position_box = self.gui.get_object("ModelPositionBox")
position_box.unparent() position_box.unparent()
self.core.register_ui("model_handling", "Position", position_box, -20) self._gtk_handlers = []
shift_model_button = self.gui.get_object("ShiftModelButton") self.core.register_ui("model_handling", "Position", position_box,
shift_model_button.connect("clicked", self._shift_model) -20)
align_model_button = self.gui.get_object("AlignPositionButton") shift_button = self.gui.get_object("ShiftModelButton")
align_model_button.connect("clicked", self._align_model) self._gtk_handlers.append((shift_button, "clicked",
self._shift_model))
align_button = self.gui.get_object("AlignPositionButton")
self._gtk_handlers.append((align_button, "clicked",
self._align_model))
# grab default button for shift/align controls # grab default button for shift/align controls
for axis in "XYZ": for axis in "XYZ":
obj = self.gui.get_object("ShiftPosition%s" % axis) obj = self.gui.get_object("ShiftPosition%s" % axis)
obj.connect("focus-in-event", lambda widget, data: \ self._gtk_handlers.extend((
shift_model_button.grab_default()) (obj, "focus-in-event", lambda widget, data: \
obj.connect("focus-out-event", lambda widget, data: \ shift_button.grab_default()),
shift_model_button.get_toplevel().set_default(None)) (obj, "focus-out-event", lambda widget, data: \
shift_button.get_toplevel().set_default(None))))
for axis in "XYZ": for axis in "XYZ":
for name_template in ("AlignPosition%s", "AlignPosition%sMin", for name_template in ("AlignPosition%s", "AlignPosition%sMin",
"AlignPosition%sCenter", "AlignPosition%sMax"): "AlignPosition%sCenter", "AlignPosition%sMax"):
obj = self.gui.get_object("AlignPosition%s" % axis) obj = self.gui.get_object("AlignPosition%s" % axis)
obj.connect("focus-in-event", lambda widget, data: \ self._gtk_handlers.extend((
align_model_button.grab_default()) (obj, "focus-in-event", lambda widget, data: \
obj.connect("focus-out-event", lambda widget, data: \ align_button.grab_default()),
align_model_button.get_toplevel().set_default(None)) (obj, "focus-out-event", lambda widget, data: \
self.core.register_event("model-selection-changed", align_button.get_toplevel().set_default(None))))
self._update_position_widgets) self._event_handlers = (("model-selection-changed",
self._update_position_widgets), )
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self._update_position_widgets() self._update_position_widgets()
return True return True
...@@ -63,8 +71,8 @@ class ModelPosition(pycam.Plugins.PluginBase): ...@@ -63,8 +71,8 @@ class ModelPosition(pycam.Plugins.PluginBase):
if self.gui: if self.gui:
self.core.unregister_ui("model_handling", self.core.unregister_ui("model_handling",
self.gui.get_object("ModelPositionBox")) self.gui.get_object("ModelPositionBox"))
self.core.unregister_event("model-selection-changed", self.unregister_gtk_handlers(self._gtk_handlers)
self._update_position_widgets) self.unregister_event_handlers(self._event_handlers)
def _update_position_widgets(self): def _update_position_widgets(self):
widget = self.gui.get_object("ModelPositionBox") widget = self.gui.get_object("ModelPositionBox")
......
...@@ -38,12 +38,13 @@ class ModelProjection(pycam.Plugins.PluginBase): ...@@ -38,12 +38,13 @@ class ModelProjection(pycam.Plugins.PluginBase):
projection_frame.unparent() projection_frame.unparent()
self.core.register_ui("model_handling", "Projection", self.core.register_ui("model_handling", "Projection",
projection_frame, 10) projection_frame, 10)
self.core.register_event("model-change-after", self._gtk_handlers = ((self.gui.get_object("ProjectionButton"),
self._update_controls) "clicked", self._projection), )
self.gui.get_object("ProjectionButton").connect("clicked", self._event_handlers = (
self._projection) ("model-change-after", self._update_controls),
self.core.register_event("model-selection-changed", ("model-selection-changed", self._update_controls))
self._update_controls) self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self._update_controls() self._update_controls()
return True return True
...@@ -51,10 +52,8 @@ class ModelProjection(pycam.Plugins.PluginBase): ...@@ -51,10 +52,8 @@ class ModelProjection(pycam.Plugins.PluginBase):
if self.gui: if self.gui:
self.core.unregister_ui("model_handling", self.core.unregister_ui("model_handling",
self.gui.get_object("ModelProjectionFrame")) self.gui.get_object("ModelProjectionFrame"))
self.core.unregister_event("model-selection-changed", self.unregister_gtk_handlers(self._gtk_handlers)
self._update_controls) self.unregister_event_handlers(self._event_handlers)
self.core.unregister_event("model-change-after",
self._update_controls)
def _get_projectable_models(self): def _get_projectable_models(self):
models = self.core.get("models").get_selected() models = self.core.get("models").get_selected()
......
...@@ -37,10 +37,12 @@ class ModelRotation(pycam.Plugins.PluginBase): ...@@ -37,10 +37,12 @@ class ModelRotation(pycam.Plugins.PluginBase):
rotation_box.unparent() rotation_box.unparent()
self.core.register_ui("model_handling", "Rotation", rotation_box, self.core.register_ui("model_handling", "Rotation", rotation_box,
-10) -10)
self.gui.get_object("RotateModelButton").connect("clicked", self._gtk_handlers = ((self.gui.get_object("RotateModelButton"),
self._rotate_model) "clicked", self._rotate_model), )
self.core.register_event("model-selection-changed", self._event_handlers = (("model-selection-changed",
self._update_controls) self._update_controls), )
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self._update_controls() self._update_controls()
return True return True
...@@ -48,8 +50,8 @@ class ModelRotation(pycam.Plugins.PluginBase): ...@@ -48,8 +50,8 @@ class ModelRotation(pycam.Plugins.PluginBase):
if self.gui: if self.gui:
self.core.unregister_ui("model_handling", self.core.unregister_ui("model_handling",
self.gui.get_object("ModelRotationBox")) self.gui.get_object("ModelRotationBox"))
self.core.unregister_event("model-selection-changed", self.unregister_gtk_handlers(self._gtk_handlers)
self._update_controls) self.unregister_event_handlers(self._event_handlers)
def _update_controls(self): def _update_controls(self):
widget = self.gui.get_object("ModelRotationBox") widget = self.gui.get_object("ModelRotationBox")
......
...@@ -35,38 +35,29 @@ class ModelScaling(pycam.Plugins.PluginBase): ...@@ -35,38 +35,29 @@ class ModelScaling(pycam.Plugins.PluginBase):
scale_box = self.gui.get_object("ModelScaleBox") scale_box = self.gui.get_object("ModelScaleBox")
scale_box.unparent() scale_box.unparent()
self.core.register_ui("model_handling", "Scale", scale_box, -5) self.core.register_ui("model_handling", "Scale", scale_box, -5)
self.core.register_event("model-change-after",
self._update_scale_controls)
scale_percent = self.gui.get_object("ScalePercent") scale_percent = self.gui.get_object("ScalePercent")
scale_button = self.gui.get_object("ScaleModelButton") scale_button = self.gui.get_object("ScaleModelButton")
scale_percent.set_value(100) scale_percent.set_value(100)
scale_percent.connect("focus-in-event",
lambda widget, data: scale_button.grab_default())
scale_percent.connect("focus-out-event", lambda widget, data: \
scale_box.get_toplevel().set_default(None))
scale_button.connect("clicked", self._scale_model)
# scale model to an axis dimension
self.gui.get_object("ScaleDimensionAxis").connect("changed",
lambda widget=None: self.core.emit_event(
"model-change-after"))
scale_dimension_button = self.gui.get_object("ScaleAllAxesButton") scale_dimension_button = self.gui.get_object("ScaleAllAxesButton")
scale_dimension_control = self.gui.get_object( scale_dimension_control = self.gui.get_object(
"ScaleDimensionControl") "ScaleDimensionControl")
scale_dimension_control.connect("focus-in-event", self._gtk_handlers = []
lambda widget, data: scale_dimension_button.grab_default()) self._gtk_handlers.extend((
scale_dimension_control.connect("focus-out-event", (scale_percent, "focus-in-event", lambda widget, data: scale_button.grab_default()),
lambda widget, data: \ (scale_percent, "focus-out-event", lambda widget, data: scale_box.get_toplevel().set_default(None)),
scale_box.get_toplevel().set_default(None)) (scale_button, "clicked", self._scale_model),
scale_dimension_button.connect("clicked", (self.gui.get_object("ScaleDimensionAxis"), "changed", lambda widget=None: self.core.emit_event( "model-change-after")),
self._scale_model_axis_fit, True) (scale_dimension_control, "focus-in-event", lambda widget, data: scale_dimension_button.grab_default()),
self.gui.get_object("ScaleSelectedAxisButton").connect("clicked", (scale_dimension_control, "focus-out-event", lambda widget, data: scale_box.get_toplevel().set_default(None)),
self._scale_model_axis_fit, False) (scale_dimension_button, "clicked", lambda widget: self._scale_model_axis_fit(proportionally=True)),
self.gui.get_object("ScaleInchMM").connect("clicked", (self.gui.get_object("ScaleSelectedAxisButton"), "clicked", lambda widget: self._scale_model_axis_fit(proportionally=False)),
self._scale_model, 100 * 25.4) (self.gui.get_object("ScaleInchMM"), "clicked", lambda widget: self._scale_model(percent=(100 * 25.4))),
self.gui.get_object("ScaleMMInch").connect("clicked", (self.gui.get_object("ScaleMMInch"), "clicked", lambda widget: self._scale_model(percent=(100 / 25.4)))))
self._scale_model, 100 / 25.4) self._event_handlers = (
self.core.register_event("model-selection-changed", ("model-selection-changed", self._update_scale_controls),
self._update_scale_controls) ("model-change-after", self._update_scale_controls))
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self._update_scale_controls() self._update_scale_controls()
return True return True
...@@ -74,10 +65,8 @@ class ModelScaling(pycam.Plugins.PluginBase): ...@@ -74,10 +65,8 @@ class ModelScaling(pycam.Plugins.PluginBase):
if self.gui: if self.gui:
self.core.unregister_ui("model_handling", self.core.unregister_ui("model_handling",
self.gui.get_object("ModelScaleBox")) self.gui.get_object("ModelScaleBox"))
self.core.unregister_event("model-change-after", self.unregister_gtk_handlers(self._gtk_handlers)
self._update_scale_controls) self.unregister_event_handlers(self._event_handlers)
self.core.unregister_event("model-selection-changed",
self._update_scale_controls)
def _update_scale_controls(self): def _update_scale_controls(self):
models = self.core.get("models").get_selected() models = self.core.get("models").get_selected()
......
...@@ -36,18 +36,11 @@ class ModelSupport(pycam.Plugins.PluginBase): ...@@ -36,18 +36,11 @@ class ModelSupport(pycam.Plugins.PluginBase):
self._support_frame.unparent() self._support_frame.unparent()
self.core.register_ui("model_handling", "Support", self.core.register_ui("model_handling", "Support",
self._support_frame, 0) self._support_frame, 0)
self.core.register_event("model-change-after",
self._support_model_changed)
self.core.register_event("bounds-changed",
self._support_model_changed)
self.core.register_event("model-selection-changed",
self._update_widgets)
self.core.register_event("support-model-changed",
self.update_support_model)
support_model_type_selector = self.gui.get_object( support_model_type_selector = self.gui.get_object(
"SupportGridTypesControl") "SupportGridTypesControl")
support_model_type_selector.connect("changed", self._gtk_handlers = []
self._support_model_changed) self._gtk_handlers.append((support_model_type_selector, "changed",
self._support_model_changed))
def add_support_type(obj, name): def add_support_type(obj, name):
types_model = support_model_type_selector.get_model() types_model = support_model_type_selector.get_model()
types_model.append((obj, name)) types_model.append((obj, name))
...@@ -87,20 +80,30 @@ class ModelSupport(pycam.Plugins.PluginBase): ...@@ -87,20 +80,30 @@ class ModelSupport(pycam.Plugins.PluginBase):
get_support_model_type, get_support_model_type,
set_support_model_type) set_support_model_type)
grid_thickness = self.gui.get_object("SupportGridThickness") grid_thickness = self.gui.get_object("SupportGridThickness")
grid_thickness.connect("value-changed", self._support_model_changed) self._gtk_handlers.append((grid_thickness, "value-changed",
self._support_model_changed))
self.core.add_item("support_grid_thickness", self.core.add_item("support_grid_thickness",
grid_thickness.get_value, grid_thickness.set_value) grid_thickness.get_value, grid_thickness.set_value)
grid_height = self.gui.get_object("SupportGridHeight") grid_height = self.gui.get_object("SupportGridHeight")
grid_height.connect("value-changed", self._support_model_changed) self._gtk_handlers.append((grid_height, "value-changed",
self._support_model_changed))
self.core.add_item("support_grid_height", self.core.add_item("support_grid_height",
grid_height.get_value, grid_height.set_value) grid_height.get_value, grid_height.set_value)
self._gtk_handlers.append((
self.gui.get_object("CreateSupportModel"), "clicked",
self._add_support_model))
# support grid defaults # support grid defaults
self.core.set("support_grid_thickness", 0.5) self.core.set("support_grid_thickness", 0.5)
self.core.set("support_grid_height", 0.5) self.core.set("support_grid_height", 0.5)
self.core.set("support_grid_type", "none") self.core.set("support_grid_type", "none")
# prepare GUI # handlers
self.gui.get_object("CreateSupportModel").connect("clicked", self._event_handlers = (
self._add_support_model) ("model-change-after", self._support_model_changed),
("bounds-changed", self._support_model_changed),
("model-selection-changed", self._update_widgets),
("support-model-changed", self.update_support_model))
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self._update_widgets() self._update_widgets()
return True return True
...@@ -109,14 +112,8 @@ class ModelSupport(pycam.Plugins.PluginBase): ...@@ -109,14 +112,8 @@ class ModelSupport(pycam.Plugins.PluginBase):
self.core.unregister_ui("model_handling", self.core.unregister_ui("model_handling",
self.gui.get_object("ModelExtensionsFrame")) self.gui.get_object("ModelExtensionsFrame"))
self.core.unregister_ui("support_model_type_selector", "none") self.core.unregister_ui("support_model_type_selector", "none")
self.core.unregister_event("model-change-after", self.unregister_gtk_handlers(self._gtk_handlers)
self._support_model_changed) self.unregister_event_handlers(self._event_handlers)
self.core.unregister_event("bounds-changed",
self._support_model_changed)
self.core.unregister_event("model-selection-changed",
self._update_widgets)
self.core.unregister_event("support-model-changed",
self.update_support_model)
def _update_widgets(self): def _update_widgets(self):
if self.core.get("models").get_selected(): if self.core.get("models").get_selected():
......
...@@ -34,36 +34,44 @@ class ModelSupportDistributed(pycam.Plugins.PluginBase): ...@@ -34,36 +34,44 @@ class ModelSupportDistributed(pycam.Plugins.PluginBase):
if self.gui: if self.gui:
support_expander = self.gui.get_object("DistributedSupportExpander") support_expander = self.gui.get_object("DistributedSupportExpander")
support_expander.unparent() support_expander.unparent()
self._gtk_handlers = []
self.core.register_ui("support_model_type_selector", self.core.register_ui("support_model_type_selector",
"Distributed (edges)", "distributed_edges", weight=0) "Distributed (edges)", "distributed_edges", weight=0)
self.core.register_ui("support_model_type_selector", self.core.register_ui("support_model_type_selector",
"Distributed (corners)", "distributed_corners", weight=10) "Distributed (corners)", "distributed_corners", weight=10)
self.core.register_ui("support_model_settings", "Grid settings", self.core.register_ui("support_model_settings", "Grid settings",
support_expander) support_expander)
self.core.register_event("support-model-changed",
self.update_support_controls)
self.core.register_event("support-model-changed",
self.update_support_model)
grid_length = self.gui.get_object("SupportGridLength") grid_length = self.gui.get_object("SupportGridLength")
grid_length.connect("value-changed", self.update_support_model) self._gtk_handlers.append((grid_length, "value-changed",
self.update_support_model))
self.core.add_item("support_grid_length", self.core.add_item("support_grid_length",
grid_length.get_value, grid_length.set_value) grid_length.get_value, grid_length.set_value)
average_distance = self.gui.get_object("GridAverageDistance") average_distance = self.gui.get_object("GridAverageDistance")
average_distance.connect("value-changed", self.update_support_model) self._gtk_handlers.append((average_distance, "value-changed",
self.update_support_model))
self.core.add_item("support_grid_average_distance", self.core.add_item("support_grid_average_distance",
average_distance.get_value, average_distance.set_value) average_distance.get_value, average_distance.set_value)
minimum_bridges = self.gui.get_object("GridMinBridgesPerPolygon") minimum_bridges = self.gui.get_object("GridMinBridgesPerPolygon")
minimum_bridges.connect("value-changed", self.update_support_model) self._gtk_handlers.append((minimum_bridges, "value-changed",
self.update_support_model))
self.core.add_item("support_grid_minimum_bridges", self.core.add_item("support_grid_minimum_bridges",
minimum_bridges.get_value, minimum_bridges.set_value) minimum_bridges.get_value, minimum_bridges.set_value)
# TODO: remove these public settings # TODO: remove these public settings
self.core.set("support_grid_average_distance", 30) self.core.set("support_grid_average_distance", 30)
self.core.set("support_grid_minimum_bridges", 2) self.core.set("support_grid_minimum_bridges", 2)
self.core.set("support_grid_length", 5) self.core.set("support_grid_length", 5)
# register handlers
self._event_handlers = (
("support-model-changed", self.update_support_controls),
("support-model-changed", self.update_support_model))
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
return True return True
def teardown(self): def teardown(self):
if self.gui: if self.gui:
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
self.core.unregister_ui("support_model_type_selector", self.core.unregister_ui("support_model_type_selector",
"distributed_edges") "distributed_edges")
self.core.unregister_ui("support_model_type_selector", self.core.unregister_ui("support_model_type_selector",
......
...@@ -42,23 +42,25 @@ class ModelSupportGrid(pycam.Plugins.PluginBase): ...@@ -42,23 +42,25 @@ class ModelSupportGrid(pycam.Plugins.PluginBase):
"grid", weight=-10) "grid", weight=-10)
self.core.register_ui("support_model_settings", "Grid settings", self.core.register_ui("support_model_settings", "Grid settings",
grid_box) grid_box)
self.core.register_event("support-model-changed",
self.update_support_model)
support_model_changed = lambda widget=None: self.core.emit_event( support_model_changed = lambda widget=None: self.core.emit_event(
"support-model-changed") "support-model-changed")
self._gtk_handlers = []
# support grid # support grid
self.grid_adjustments_x = [] self.grid_adjustments_x = []
self.grid_adjustments_y = [] self.grid_adjustments_y = []
self.grid_adjustment_axis_x_last = True self.grid_adjustment_axis_x_last = True
self._block_manual_adjust_update = False self._block_manual_adjust_update = False
grid_distance_x = self.gui.get_object("SupportGridDistanceX") grid_distance_x = self.gui.get_object("SupportGridDistanceX")
grid_distance_x.connect("value-changed", support_model_changed) self._gtk_handlers.append((grid_distance_x, "value-changed",
support_model_changed))
self.core.add_item("support_grid_distance_x", self.core.add_item("support_grid_distance_x",
grid_distance_x.get_value, grid_distance_x.set_value) grid_distance_x.get_value, grid_distance_x.set_value)
grid_distance_square = self.gui.get_object("SupportGridDistanceSquare") grid_distance_square = self.gui.get_object("SupportGridDistanceSquare")
grid_distance_square.connect("clicked", self.update_support_controls) self._gtk_handlers.append((grid_distance_square, "clicked",
self.update_support_controls))
grid_distance_y = self.gui.get_object("SupportGridDistanceY") grid_distance_y = self.gui.get_object("SupportGridDistanceY")
grid_distance_y.connect("value-changed", support_model_changed) self._gtk_handlers.append((grid_distance_y, "value-changed",
support_model_changed))
def get_support_grid_distance_y(): def get_support_grid_distance_y():
if grid_distance_square.get_active(): if grid_distance_square.get_active():
return self.core.get("support_grid_distance_x") return self.core.get("support_grid_distance_x")
...@@ -67,39 +69,46 @@ class ModelSupportGrid(pycam.Plugins.PluginBase): ...@@ -67,39 +69,46 @@ class ModelSupportGrid(pycam.Plugins.PluginBase):
self.core.add_item("support_grid_distance_y", self.core.add_item("support_grid_distance_y",
get_support_grid_distance_y, grid_distance_y.set_value) get_support_grid_distance_y, grid_distance_y.set_value)
grid_offset_x = self.gui.get_object("SupportGridOffsetX") grid_offset_x = self.gui.get_object("SupportGridOffsetX")
grid_offset_x.connect("value-changed", support_model_changed) self._gtk_handlers.append((grid_offset_x, "value-changed",
support_model_changed))
self.core.add_item("support_grid_offset_x", self.core.add_item("support_grid_offset_x",
grid_offset_x.get_value, grid_offset_x.set_value) grid_offset_x.get_value, grid_offset_x.set_value)
grid_offset_y = self.gui.get_object("SupportGridOffsetY") grid_offset_y = self.gui.get_object("SupportGridOffsetY")
grid_offset_y.connect("value-changed", support_model_changed) self._gtk_handlers.append((grid_offset_y, "value-changed",
support_model_changed))
self.core.add_item("support_grid_offset_y", self.core.add_item("support_grid_offset_y",
grid_offset_y.get_value, grid_offset_y.set_value) grid_offset_y.get_value, grid_offset_y.set_value)
# manual grid adjustments # manual grid adjustments
self.grid_adjustment_axis_x = self.gui.get_object("SupportGridPositionManualAxisX") self.grid_adjustment_axis_x = self.gui.get_object(
self.grid_adjustment_axis_x.connect("toggled", "SupportGridPositionManualAxisX")
self.switch_support_grid_manual_selector) self._gtk_handlers.extend((
self.gui.get_object("SupportGridPositionManualResetOne").connect( (self.grid_adjustment_axis_x, "toggled",
"clicked", self.reset_support_grid_manual, False) self.switch_support_grid_manual_selector),
self.gui.get_object("SupportGridPositionManualResetAll").connect( (self.gui.get_object("SupportGridPositionManualResetOne"),
"clicked", self.reset_support_grid_manual, True) "clicked", lambda *args: \
self.reset_support_grid_manual(reset_all=False)),
(self.gui.get_object("SupportGridPositionManualResetAll"),
"clicked", lambda *args: \
self.reset_support_grid_manual(True))))
self.grid_adjustment_model = self.gui.get_object( self.grid_adjustment_model = self.gui.get_object(
"SupportGridPositionManualList") "SupportGridPositionManualList")
self.grid_adjustment_selector = self.gui.get_object( self.grid_adjustment_selector = self.gui.get_object(
"SupportGridPositionManualSelector") "SupportGridPositionManualSelector")
self.grid_adjustment_selector.connect("changed", self._gtk_handlers.append((self.grid_adjustment_selector,
self.switch_support_grid_manual_selector) "changed", self.switch_support_grid_manual_selector))
self.grid_adjustment_value = self.gui.get_object( self.grid_adjustment_value = self.gui.get_object(
"SupportGridPositionManualAdjustment") "SupportGridPositionManualAdjustment")
self.grid_adjustment_value_control = self.gui.get_object( self.grid_adjustment_value_control = self.gui.get_object(
"SupportGridPositionManualShiftControl") "SupportGridPositionManualShiftControl")
self.grid_adjustment_value_control.set_update_policy( self.grid_adjustment_value_control.set_update_policy(
gtk.UPDATE_DISCONTINUOUS) gtk.UPDATE_DISCONTINUOUS)
self.grid_adjustment_value_control.connect("move-slider", self._gtk_handlers.extend((
self.update_support_grid_manual_adjust) (self.grid_adjustment_value_control, "move-slider",
self.grid_adjustment_value_control.connect("value-changed", self.update_support_grid_manual_adjust),
self.update_support_grid_manual_adjust) (self.grid_adjustment_value_control, "value-changed",
self.gui.get_object("SupportGridPositionManualShiftControl2").connect( self.update_support_grid_manual_adjust),
"value-changed", self.update_support_grid_manual_adjust) (self.gui.get_object("SupportGridPositionManualShiftControl2"),
"value-changed", self.update_support_grid_manual_adjust)))
def get_set_grid_adjustment_value(value=None): def get_set_grid_adjustment_value(value=None):
if self.grid_adjustment_axis_x.get_active(): if self.grid_adjustment_axis_x.get_active():
adjustments = self.grid_adjustments_x adjustments = self.grid_adjustments_x
...@@ -118,10 +127,14 @@ class ModelSupportGrid(pycam.Plugins.PluginBase): ...@@ -118,10 +127,14 @@ class ModelSupportGrid(pycam.Plugins.PluginBase):
# TODO: remove these public settings # TODO: remove these public settings
self.core.add_item("support_grid_adjustment_value", self.core.add_item("support_grid_adjustment_value",
get_set_grid_adjustment_value, get_set_grid_adjustment_value) get_set_grid_adjustment_value, get_set_grid_adjustment_value)
self.core.register_event("support-model-changed",
self.update_support_controls)
grid_distance_square.set_active(True) grid_distance_square.set_active(True)
self.core.set("support_grid_distance_x", 10.0) self.core.set("support_grid_distance_x", 10.0)
# handlers
self._event_handlers = ((
("support-model-changed", self.update_support_controls),
("support-model-changed", self.update_support_model)))
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
return True return True
def teardown(self): def teardown(self):
...@@ -129,8 +142,8 @@ class ModelSupportGrid(pycam.Plugins.PluginBase): ...@@ -129,8 +142,8 @@ class ModelSupportGrid(pycam.Plugins.PluginBase):
self.core.unregister_ui("support_model_type_selector", "grid") self.core.unregister_ui("support_model_type_selector", "grid")
self.core.unregister_ui("support_model_settings", self.core.unregister_ui("support_model_settings",
self.gui.get_object("SupportModelGridBox")) self.gui.get_object("SupportModelGridBox"))
self.core.unregister_event("support-model-changed", self.unregister_gtk_handlers(self._gtk_handlers)
self.update_support_model) self.unregister_event_handlers(self._event_handlers)
def update_support_model(self, widget=None): def update_support_model(self, widget=None):
grid_type = self.core.get("support_model_type") grid_type = self.core.get("support_model_type")
......
...@@ -35,10 +35,12 @@ class ModelSwapAxes(pycam.Plugins.PluginBase): ...@@ -35,10 +35,12 @@ class ModelSwapAxes(pycam.Plugins.PluginBase):
swap_box = self.gui.get_object("ModelSwapBox") swap_box = self.gui.get_object("ModelSwapBox")
swap_box.unparent() swap_box.unparent()
self.core.register_ui("model_handling", "Swap axes", swap_box, 0) self.core.register_ui("model_handling", "Swap axes", swap_box, 0)
self.gui.get_object("SwapAxesButton").connect("clicked", self._gtk_handlers = ((self.gui.get_object("SwapAxesButton"),
self._swap_axes) "clicked", self._swap_axes), )
self.core.register_event("model-selection-changed", self._event_handlers = (("model-selection-changed",
self._update_controls) self._update_controls), )
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self._update_controls() self._update_controls()
return True return True
...@@ -46,8 +48,8 @@ class ModelSwapAxes(pycam.Plugins.PluginBase): ...@@ -46,8 +48,8 @@ class ModelSwapAxes(pycam.Plugins.PluginBase):
if self.gui: if self.gui:
self.core.unregister_ui("model_handling", self.core.unregister_ui("model_handling",
self.gui.get_object("ModelSwapBox")) self.gui.get_object("ModelSwapBox"))
self.core.unregister_event("model-selection-changed", self.unregister_gtk_handlers(self._gtk_handlers)
self._update_controls) self.unregister_event_handlers(self._event_handlers)
def _update_controls(self): def _update_controls(self):
box = self.gui.get_object("ModelSwapBox") box = self.gui.get_object("ModelSwapBox")
......
...@@ -61,17 +61,18 @@ class Models(pycam.Plugins.ListPluginBase): ...@@ -61,17 +61,18 @@ class Models(pycam.Plugins.ListPluginBase):
(self.ACTION_CLEAR, "ModelDeleteAll")): (self.ACTION_CLEAR, "ModelDeleteAll")):
self.register_list_action_button(action, self._modelview, self.register_list_action_button(action, self._modelview,
self.gui.get_object(obj_name)) self.gui.get_object(obj_name))
self.gui.get_object("ModelColorButton").connect("color-set", self._gtk_handlers = []
self._set_colors_of_selected_models) self._gtk_handlers.extend((
self.core.register_event("model-selection-changed", (self.gui.get_object("ModelColorButton"), "color-set",
self._get_colors_of_selected_models) self._set_colors_of_selected_models),
self._modelview.connect("row-activated", (self._modelview, "row-activated", lambda *args:
self._list_action_toggle_custom, self.COLUMN_VISIBLE) self._list_action_toggle_custom(
*(args + [self.COLUMN_VISIBLE]))),
(self.gui.get_object("ModelNameColumn"), "edited",
self._edit_model_name)))
self.gui.get_object("ModelVisibleColumn").set_cell_data_func( self.gui.get_object("ModelVisibleColumn").set_cell_data_func(
self.gui.get_object("ModelVisibleSymbol"), self.gui.get_object("ModelVisibleSymbol"),
self._visualize_visible_state) self._visualize_visible_state)
self.gui.get_object("ModelNameColumn").connect("edited",
self._edit_model_name)
self._treemodel = self.gui.get_object("ModelList") self._treemodel = self.gui.get_object("ModelList")
self._treemodel.clear() self._treemodel.clear()
def update_model(): def update_model():
...@@ -93,9 +94,12 @@ class Models(pycam.Plugins.ListPluginBase): ...@@ -93,9 +94,12 @@ class Models(pycam.Plugins.ListPluginBase):
self.core.emit_event("model-list-changed") self.core.emit_event("model-list-changed")
selection = self._modelview.get_selection() selection = self._modelview.get_selection()
selection.set_mode(self._gtk.SELECTION_MULTIPLE) selection.set_mode(self._gtk.SELECTION_MULTIPLE)
selection.connect("changed", self._gtk_handlers.append((selection, "changed",
lambda widget, event: self.core.emit_event(event), "model-selection-changed"))
"model-selection-changed") self._event_handlers = (("model-selection-changed",
self._get_colors_of_selected_models), )
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self._get_colors_of_selected_models() self._get_colors_of_selected_models()
self.register_model_update(update_model) self.register_model_update(update_model)
# update the model list # update the model list
...@@ -105,10 +109,10 @@ class Models(pycam.Plugins.ListPluginBase): ...@@ -105,10 +109,10 @@ class Models(pycam.Plugins.ListPluginBase):
def teardown(self): def teardown(self):
if self.gui: if self.gui:
self.core.unregister_event("model-selection-changed",
self._get_colors_of_selected_models)
self.core.unregister_ui_section("model_handling") self.core.unregister_ui_section("model_handling")
self.core.unregister_ui("main", self.gui.get_object("ModelBox")) self.core.unregister_ui("main", self.gui.get_object("ModelBox"))
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
self.core.set("models", None) self.core.set("models", None)
return True return True
......
...@@ -37,17 +37,16 @@ class OpenGLViewModel(pycam.Plugins.PluginBase): ...@@ -37,17 +37,16 @@ class OpenGLViewModel(pycam.Plugins.PluginBase):
import OpenGL.GL import OpenGL.GL
self._gtk = gtk self._gtk = gtk
self._GL = OpenGL.GL self._GL = OpenGL.GL
self.core.register_event("visualize-items", self.draw_model) self._event_handlers = (("visualize-items", self.draw_model),
self.core.register_event("model-changed", ("model-changed","visual-item-updated"),
lambda: self.core.emit_event("visual-item-updated")) ("model-list-changed","visual-item-updated"))
self.core.register_event("model-list-changed", self.register_event_handlers(self._event_handlers)
lambda: self.core.emit_event("visual-item-updated"))
self.core.emit_event("visual-item-updated") self.core.emit_event("visual-item-updated")
self._cache = {} self._cache = {}
return True return True
def teardown(self): def teardown(self):
self.core.unregister_event("visualize-items", self.draw_model) self.unregister_event_handlers(self._event_handlers)
self.core.emit_event("visual-item-updated") self.core.emit_event("visual-item-updated")
def _get_cache_key(self, model, *args, **kwargs): def _get_cache_key(self, model, *args, **kwargs):
......
...@@ -38,8 +38,10 @@ class ProgressBar(pycam.Plugins.PluginBase): ...@@ -38,8 +38,10 @@ class ProgressBar(pycam.Plugins.PluginBase):
box = self.gui.get_object("ProgressBox") box = self.gui.get_object("ProgressBox")
box.unparent() box.unparent()
self.core.register_ui("main_window", "Progress", box, 50) self.core.register_ui("main_window", "Progress", box, 50)
self.core.add_item("progress", lambda: ProgressGTK(self.core, self.gui)) self.core.add_item("progress", lambda: ProgressGTK(self.core,
show_progress_button = self.gui.get_object("ShowToolpathProgressButton") self.gui, self.log))
show_progress_button = self.gui.get_object(
"ShowToolpathProgressButton")
# TODO: move this setting somewhere else or rename it # TODO: move this setting somewhere else or rename it
self.core.add_item("show_drill_progress", self.core.add_item("show_drill_progress",
show_progress_button.get_active, show_progress_button.get_active,
...@@ -57,12 +59,13 @@ class ProgressGTK(object): ...@@ -57,12 +59,13 @@ class ProgressGTK(object):
_PROGRESS_STACK = [] _PROGRESS_STACK = []
def __init__(self, core, gui): def __init__(self, core, gui, log):
ProgressGTK._PROGRESS_STACK.append(self) ProgressGTK._PROGRESS_STACK.append(self)
import gtk import gtk
self._finished = False self._finished = False
self._gtk = gtk self._gtk = gtk
self._gui = gui self._gui = gui
self.log = log
self.core = core self.core = core
self._cancel_requested = False self._cancel_requested = False
self._start_time = 0 self._start_time = 0
...@@ -75,7 +78,8 @@ class ProgressGTK(object): ...@@ -75,7 +78,8 @@ class ProgressGTK(object):
self._cancel_button = self._gui.get_object("ProgressCancelButton") self._cancel_button = self._gui.get_object("ProgressCancelButton")
self._cancel_button.connect("clicked", self.cancel) self._cancel_button.connect("clicked", self.cancel)
self._progress_bar = self._gui.get_object("ProgressBar") self._progress_bar = self._gui.get_object("ProgressBar")
self._progress_button = self._gui.get_object("ShowToolpathProgressButton") self._progress_button = self._gui.get_object(
"ShowToolpathProgressButton")
self._start_time = time.time() self._start_time = time.time()
self._progress_button.show() self._progress_button.show()
self._last_text = None self._last_text = None
...@@ -117,8 +121,8 @@ class ProgressGTK(object): ...@@ -117,8 +121,8 @@ class ProgressGTK(object):
else: else:
text = "%d/%d" % (self._multi_counter, self._multi_maximum) text = "%d/%d" % (self._multi_counter, self._multi_maximum)
self._multi_widget.set_text(text) self._multi_widget.set_text(text)
self._multi_widget.set_fraction( self._multi_widget.set_fraction(min(1.0,
float(self._multi_counter) / self._multi_maximum) float(self._multi_counter) / self._multi_maximum))
def disable_cancel(self): def disable_cancel(self):
self._cancel_button.set_sensitive(False) self._cancel_button.set_sensitive(False)
...@@ -152,7 +156,8 @@ class ProgressGTK(object): ...@@ -152,7 +156,8 @@ class ProgressGTK(object):
self._finished = True self._finished = True
def __del__(self): def __del__(self):
self.finish() if not self._finished:
self.finish()
def update(self, text=None, percent=None): def update(self, text=None, percent=None):
if text: if text:
...@@ -178,6 +183,7 @@ class ProgressGTK(object): ...@@ -178,6 +183,7 @@ class ProgressGTK(object):
time_estimation_suffix = " remaining ..." time_estimation_suffix = " remaining ..."
if self._progress_bar.get_fraction() > 0: if self._progress_bar.get_fraction() > 0:
total_fraction = (self._progress_bar.get_fraction() + self._multi_counter) / max(1, self._multi_maximum) total_fraction = (self._progress_bar.get_fraction() + self._multi_counter) / max(1, self._multi_maximum)
total_fraction = max(0.0, min(total_fraction, 1.0))
eta_full = (time.time() - self._start_time) / total_fraction eta_full = (time.time() - self._start_time) / total_fraction
if eta_full > 0: if eta_full > 0:
eta_delta = eta_full - (time.time() - self._start_time) eta_delta = eta_full - (time.time() - self._start_time)
......
...@@ -73,8 +73,34 @@ class PluginBase(object): ...@@ -73,8 +73,34 @@ class PluginBase(object):
else: else:
self.log.debug("Failed to locate icon: %s" % self.ICONS[key]) self.log.debug("Failed to locate icon: %s" % self.ICONS[key])
self.ICONS[key] = None self.ICONS[key] = None
self._lambda_handlers = {}
self.enabled = True self.enabled = True
def __get_handler_func(self, func):
if isinstance(func, basestring):
if not func in self._lambda_handlers:
self._lambda_handlers[func] = lambda *args: \
self.core.emit_event(func)
return self._lambda_handlers[func]
else:
return func
def register_event_handlers(self, event_handlers):
for name, func in event_handlers:
self.core.register_event(name, self.__get_handler_func(func))
def register_gtk_handlers(self, gtk_widget_handlers):
for obj, signal, func in gtk_widget_handlers:
obj.connect(signal, self.__get_handler_func(func))
def unregister_event_handlers(self, event_handlers):
for name, func in event_handlers:
self.core.unregister_event(name, self.__get_handler_func(func))
def unregister_gtk_handlers(self, gtk_widget_handlers):
for obj, signal, func in gtk_widget_handlers:
obj.connect(signal, self.__get_handler_func(func))
def setup(self): def setup(self):
raise NotImplementedError(("Module %s (%s) does not implement " + \ raise NotImplementedError(("Module %s (%s) does not implement " + \
"'setup'") % (self.name, __file__)) "'setup'") % (self.name, __file__))
......
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