Commit a699b5ab authored by sumpfralle's avatar sumpfralle

cleaned up some teardown functions


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1184 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 8749bd22
......@@ -117,7 +117,8 @@ class InputChoice(InputBaseClass):
if value in self._values:
self.control.set_active(self._values.index(value))
else:
_log.debug("Unknown value: %s" % str(value))
# this may occour, if plugins were removed
_log.debug2("Unknown value: %s" % str(value))
def update_choices(self, choices):
selected = self.get_value()
......@@ -128,7 +129,6 @@ class InputChoice(InputBaseClass):
self._values.insert(choice_index, value)
continue
index = self._values.index(value)
row = self.model[index]
# the current choice is preceded by some obsolete items
while index > choice_index:
m_iter = self.model.get_iter((index,))
......@@ -136,6 +136,7 @@ class InputChoice(InputBaseClass):
self._values.pop(index)
index -= 1
# update the label column
row = self.model[index]
row[0] = label
# check if there are obsolete items after the last one
while len(self.model) > len(choices):
......
......@@ -246,6 +246,12 @@ class EventCore(pycam.Gui.Settings.Settings):
assert WIDGET_OBJ_INDEX == 1
assert WIDGET_WEIGHT_INDEX == 2
assert WIDGET_ARGS_INDEX == 3
current_widgets = [item[1]
for item in self.ui_sections[section][UI_WIDGET_INDEX]]
if (not widget is None) and (widget in current_widgets):
log.debug("Tried to register widget twice: %s -> %s" % \
(section, name))
return
self.ui_sections[section][UI_WIDGET_INDEX].append((name, widget,
weight, args_dict))
self._rebuild_ui_section(section)
......@@ -426,8 +432,8 @@ class ProjectGui(object):
# preferences tab
preferences_book = self.gui.get_object("PreferencesNotebook")
def clear_preferences():
for index in range(preferences_book.get_n_pages()):
preferences_book.remove_page(0)
for child in preferences_book.get_children():
preferences_book.remove(child)
def add_preferences_item(item, name):
preferences_book.append_page(item, gtk.Label(name))
self.settings.register_ui_section("preferences",
......
......@@ -75,12 +75,12 @@ class Clipboard(pycam.Plugins.PluginBase):
def teardown(self):
if self.gui:
self.unregister_event_handlers(self._event_handlers)
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_gtk_accelerator("clipboard", self.copy_action)
self.core.unregister_ui("edit_menu", self.copy_action)
self.unregister_gtk_accelerator("clipboard", self.paste_action)
self.core.unregister_ui("edit_menu", self.paste_action)
self.unregister_event_handlers(self._event_handlers)
self.unregister_gtk_handlers(self._gtk_handlers)
self.core.set("clipboard-set", None)
def _get_exportable_models(self):
......
......@@ -51,8 +51,8 @@ class EMCToolExport(pycam.Plugins.PluginBase):
def teardown(self):
if self.gui:
self.core.unregister_ui("export_menu", self.export_emc_tools)
self.unregister_gtk_accelerator("fonts", self.export_action)
self.core.unregister_ui("export_menu", self.export_action)
self.unregister_gtk_accelerator("export", self.export_action)
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
......
......@@ -101,7 +101,10 @@ class Fonts(pycam.Plugins.PluginBase):
self.core.add_item("fonts", None)
if self.gui:
font_toggle = self.gui.get_object("ShowFontDialog")
self.core.unregister_ui("edit_menu", None)
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_handlers(self._gtk_handlers)
......
......@@ -56,7 +56,7 @@ class Log(pycam.Plugins.PluginBase):
# "log" window
self.log_window = self.gui.get_object("LogWindow")
self.log_window.set_default_size(500, 400)
hide_window = lambda *args: self.toggle_log_window(state=False)
hide_window = lambda *args: self.toggle_log_window(value=False)
self._gtk_handlers.extend([
(self.log_window, "delete-event", hide_window),
(self.log_window, "destroy", hide_window),
......
......@@ -43,9 +43,9 @@ class Models(pycam.Plugins.ListPluginBase):
if self.gui:
import gtk
self._gtk = gtk
model_frame = self.gui.get_object("ModelBox")
model_frame.unparent()
self.core.register_ui("main", "Models", model_frame, weight=-50)
self.model_frame = self.gui.get_object("ModelBox")
self.model_frame.unparent()
self.core.register_ui("main", "Models", self.model_frame, weight=-50)
model_handling_obj = self.gui.get_object("ModelHandlingNotebook")
def clear_model_handling_obj():
for index in range(model_handling_obj.get_n_pages()):
......@@ -110,6 +110,7 @@ class Models(pycam.Plugins.ListPluginBase):
if self.gui:
self.core.unregister_ui_section("model_handling")
self.core.unregister_ui("main", self.gui.get_object("ModelBox"))
self.core.unregister_ui("main", self.model_frame)
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
self.core.set("models", None)
......
......@@ -85,9 +85,7 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
if self.gui:
self.window = self.gui.get_object("OpenGLWindow")
self.core.get("configure-drag-drop-func")(self.window)
accel_group = self.core.get("gtk-accel-group")
if not accel_group is None:
self.window.add_accel_group(accel_group)
self.window.add_accel_group(self.core.get("gtk-accel-group"))
self.initialized = False
self.busy = False
self.is_visible = False
......@@ -272,6 +270,8 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
def teardown(self):
if self.gui:
self.core.unregister_ui("preferences",
self.gui.get_object("OpenGLPrefTab"))
toggle_3d = self.gui.get_object("Toggle3DView")
# hide the window
toggle_3d.set_active(False)
......@@ -284,6 +284,7 @@ class OpenGLWindow(pycam.Plugins.PluginBase):
for name in ("show_support_grid", "show_dimensions", "show_drill",
"show_directions"):
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_event_handlers(self._event_handlers)
# the area will be created during setup again
......
......@@ -49,7 +49,8 @@ class ParallelProcessing(pycam.Plugins.PluginBase):
self.toggle_process_pool_window, False),
(self.process_pool_window, "destroy",
self.toggle_process_pool_window, False)))
self.process_pool_window.add_accel_group(self.core.get("gtk-accel-group"))
self.process_pool_window.add_accel_group(
self.core.get("gtk-accel-group"))
self._gtk_handlers.append((
self.gui.get_object("ProcessPoolWindowClose"), "clicked",
self.toggle_process_pool_window, False))
......@@ -109,6 +110,8 @@ class ParallelProcessing(pycam.Plugins.PluginBase):
self.gui.get_object("MultiprocessingFrame"))
toggle_button = self.gui.get_object("ToggleProcessPoolWindow")
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_handlers(self._gtk_handlers)
......
......@@ -187,7 +187,12 @@ class PathParamPattern(pycam.Plugins.PluginBase):
def _get_value_converter(self, value):
if value:
parameter_keys = self.core.get("get_parameter_sets")("path_pattern")[value]["parameters"].keys()
pattern_sets = self.core.get("get_parameter_sets")("path_pattern")
try:
current_pattern_set = pattern_sets[value]
except KeyError:
return None
parameter_keys = current_pattern_set["parameters"].keys()
all_parameters = self.core.get("get_parameter_values")("path_pattern")
result = {"name": value, "parameters": {}}
for parameter_key in parameter_keys:
......
......@@ -80,6 +80,8 @@ class PluginSelector(pycam.Plugins.PluginBase):
self.core.register_ui("view_menu", action)
self.core.unregister_event("plugin-list-changed",
self._update_plugin_model)
self.plugin_window.remove_accel_group(
self.core.get("gtk-accel-group"))
self.unregister_gtk_handlers(self._gtk_handlers)
def toggle_plugin_window(self, widget=None, value=None, action=None):
......
......@@ -70,11 +70,12 @@ class Processes(pycam.Plugins.ListPluginBase):
changed_set_event="process-strategy-changed",
changed_set_list_event="process-strategy-list-changed",
get_current_set_func=self._get_strategy)
parameter_widget = pycam.Gui.ControlsGTK.ParameterSection()
self.parameter_widget = pycam.Gui.ControlsGTK.ParameterSection()
self.core.register_ui_section("process_path_parameters",
parameter_widget.add_widget, parameter_widget.clear_widgets)
self.parameter_widget.add_widget,
self.parameter_widget.clear_widgets)
self.core.register_ui("process_parameters", "Path parameters",
parameter_widget.widget, weight=10)
self.parameter_widget.widget, weight=10)
self._gtk_handlers.append((self._modelview.get_selection(),
"changed", "process-selection-changed"))
self._gtk_handlers.append((self.gui.get_object("NameCell"),
......@@ -109,6 +110,10 @@ class Processes(pycam.Plugins.ListPluginBase):
def teardown(self):
if self.gui:
self.core.unregister_ui("main", self.gui.get_object("ProcessBox"))
self.core.unregister_ui_section("process_path_parameters")
self.core.unregister_ui("process_parameters",
self.parameter_widget.widget)
self.core.unregister_ui_section("process_parameters")
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
self.core.set("processes", None)
......
......@@ -139,6 +139,7 @@ class Tasks(pycam.Plugins.ListPluginBase):
self.core.unregister_ui("task_parameters", self.components_widget)
self.core.unregister_ui_section("task_models")
self.core.unregister_ui_section("task_components")
self.core.unregister_ui_section("task_parameters")
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
while len(self) > 0:
......
......@@ -72,7 +72,7 @@ class ToolParamTorusRadius(pycam.Plugins.PluginBase):
def teardown(self):
self.core.unregister_ui("tool_size", self.control.get_widget())
self.core.get("unregister_parameter")("tool", "size", "torus_radius")
self.core.get("unregister_parameter")("tool", "torus_radius")
class ToolParamFeedrate(pycam.Plugins.PluginBase):
......@@ -93,7 +93,7 @@ class ToolParamFeedrate(pycam.Plugins.PluginBase):
def teardown(self):
self.core.unregister_ui("tool_speed", self.control.get_widget())
self.core.get("unregister_parameter")("tool", "speed", "feedrate")
self.core.get("unregister_parameter")("tool", "feedrate")
self.core.unregister_chain("get_toolpath_information",
self.get_toolpath_information)
......@@ -121,7 +121,7 @@ class ToolParamSpindleSpeed(pycam.Plugins.PluginBase):
def teardown(self):
self.core.unregister_ui("tool_speed", self.control.get_widget())
self.core.get("unregister_parameter")("tool", "speed", "spindle_speed")
self.core.get("unregister_parameter")("tool", "spindle_speed")
self.core.unregister_chain("get_toolpath_information",
self.get_toolpath_information)
......
......@@ -74,16 +74,18 @@ class Tools(pycam.Plugins.ListPluginBase):
changed_set_event="tool-shape-changed",
changed_set_list_event="tool-shape-list-changed",
get_current_set_func=self._get_shape)
size_widget = pycam.Gui.ControlsGTK.ParameterSection()
self.size_widget = pycam.Gui.ControlsGTK.ParameterSection()
self.core.register_ui("tool_parameters", "Size",
size_widget.widget, weight=10)
self.size_widget.widget, weight=10)
self.core.register_ui_section("tool_size",
size_widget.add_widget, size_widget.clear_widgets)
speed_widget = pycam.Gui.ControlsGTK.ParameterSection()
self.size_widget.add_widget,
self.size_widget.clear_widgets)
self.speed_widget = pycam.Gui.ControlsGTK.ParameterSection()
self.core.register_ui("tool_parameters", "Speed",
speed_widget.widget, weight=20)
self.speed_widget.widget, weight=20)
self.core.register_ui_section("tool_speed",
speed_widget.add_widget, speed_widget.clear_widgets)
self.speed_widget.add_widget,
self.speed_widget.clear_widgets)
# table updates
cell = self.gui.get_object("ToolTableShapeCell")
self.gui.get_object("ToolTableShapeColumn").set_cell_data_func(
......@@ -130,6 +132,11 @@ class Tools(pycam.Plugins.ListPluginBase):
def teardown(self):
if self.gui:
self.core.unregister_ui("main", self.gui.get_object("ToolBox"))
self.core.unregister_ui_section("tool_speed")
self.core.unregister_ui_section("tool_size")
self.core.unregister_ui("tool_parameters", self.size_widget.widget)
self.core.unregister_ui("tool_parameters", self.speed_widget.widget)
self.core.unregister_ui_section("tool_parameters")
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
self.core.unregister_chain("get_toolpath_information",
......
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