Commit f769b18b authored by sumpfralle's avatar sumpfralle

various cleanups of different plugins


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1213 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent ed791695
...@@ -33,6 +33,7 @@ CONFIG_DIR = "pycam" ...@@ -33,6 +33,7 @@ CONFIG_DIR = "pycam"
log = pycam.Utils.log.get_logger() log = pycam.Utils.log.get_logger()
def get_config_dirname(): def get_config_dirname():
try: try:
from win32com.shell import shellcon, shell from win32com.shell import shellcon, shell
...@@ -76,6 +77,11 @@ class Settings(object): ...@@ -76,6 +77,11 @@ class Settings(object):
self.define_set_func(key, set_func) self.define_set_func(key, set_func)
self.items[key][self.VALUE_INDEX] = None self.items[key][self.VALUE_INDEX] = None
def remove_item(self, key):
if not self.items.has_key(key):
return
del self.items[key]
def define_get_func(self, key, get_func=None): def define_get_func(self, key, get_func=None):
if not self.items.has_key(key): if not self.items.has_key(key):
return return
......
...@@ -99,7 +99,7 @@ class Fonts(pycam.Plugins.PluginBase): ...@@ -99,7 +99,7 @@ class Fonts(pycam.Plugins.PluginBase):
return True return True
def teardown(self): def teardown(self):
self.core.add_item("fonts", None) self.core.remove_item("fonts")
if self.gui: if self.gui:
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)
......
...@@ -43,7 +43,14 @@ class GCodePreferences(pycam.Plugins.PluginBase): ...@@ -43,7 +43,14 @@ class GCodePreferences(pycam.Plugins.PluginBase):
while not child in self._pref_items: while not child in self._pref_items:
parent.remove(child) parent.remove(child)
parent = child parent = child
try:
child = child.get_children()[0] child = child.get_children()[0]
except (AttributeError, IndexError):
# We encountered an invalid item (e.g. a label
# without children) or an empty item.
break
else:
# we found a valid child -> remove it
parent.remove(child) parent.remove(child)
def add_preferences_item(item, name): def add_preferences_item(item, name):
if not item in self._pref_items: if not item in self._pref_items:
...@@ -116,8 +123,7 @@ class GCodeSafetyHeight(pycam.Plugins.PluginBase): ...@@ -116,8 +123,7 @@ class GCodeSafetyHeight(pycam.Plugins.PluginBase):
def teardown(self): def teardown(self):
self.clear_state_items() self.clear_state_items()
self.core.add_item("gcode_safety_height", lambda value: None, self.core.remove_item("gcode_safety_height")
lambda: None)
self.safety_height.destroy() self.safety_height.destroy()
...@@ -140,8 +146,7 @@ class GCodeFilenameExtension(pycam.Plugins.PluginBase): ...@@ -140,8 +146,7 @@ class GCodeFilenameExtension(pycam.Plugins.PluginBase):
return True return True
def teardown(self): def teardown(self):
self.core.add_item("gcode_filename_extension", lambda value: None, self.core.remove_item("gcode_filename_extension")
lambda: None)
self.filename_extension.destroy() self.filename_extension.destroy()
...@@ -176,8 +181,7 @@ class GCodeStepWidth(pycam.Plugins.PluginBase): ...@@ -176,8 +181,7 @@ class GCodeStepWidth(pycam.Plugins.PluginBase):
while self.controls: while self.controls:
self.core.unregister_ui("gcode_step_width", self.controls.pop()) self.core.unregister_ui("gcode_step_width", self.controls.pop())
for key in "xyz": for key in "xyz":
self.core.add_item("gcode_minimum_step_%s" % key, lambda: None, self.core.remove_item("gcode_minimum_step_%s" % key)
lambda value: None)
class GCodeSpindle(pycam.Plugins.PluginBase): class GCodeSpindle(pycam.Plugins.PluginBase):
...@@ -185,11 +189,11 @@ class GCodeSpindle(pycam.Plugins.PluginBase): ...@@ -185,11 +189,11 @@ class GCodeSpindle(pycam.Plugins.PluginBase):
CATEGORIES = ["GCode"] CATEGORIES = ["GCode"]
def setup(self): def setup(self):
table = pycam.Gui.ControlsGTK.ParameterSection() self._table = pycam.Gui.ControlsGTK.ParameterSection()
self.core.register_ui("gcode_preferences", "Spindle control", self.core.register_ui("gcode_preferences", "Spindle control",
table.widget) self._table.widget)
self.core.register_ui_section("gcode_spindle", self.core.register_ui_section("gcode_spindle",
table.add_widget, table.clear_widgets) self._table.add_widget, self._table.clear_widgets)
self.spindle_delay = pycam.Gui.ControlsGTK.InputNumber(digits=1) self.spindle_delay = pycam.Gui.ControlsGTK.InputNumber(digits=1)
# TODO: this should be done via parameter groups based on postprocessors # TODO: this should be done via parameter groups based on postprocessors
self.spindle_delay.get_widget().show() self.spindle_delay.get_widget().show()
...@@ -207,6 +211,15 @@ class GCodeSpindle(pycam.Plugins.PluginBase): ...@@ -207,6 +211,15 @@ class GCodeSpindle(pycam.Plugins.PluginBase):
self.update_widgets() self.update_widgets()
return True return True
def teardown(self):
self.core.remove_item("gcode_spindle_delay")
self.core.unregister_ui("gcode_spindle",
self.spindle_delay.get_widget())
self.core.unregister_ui("gcode_spindle",
self.spindle_enable.get_widget())
self.core.unregister_ui_section("gcode_spindle")
self.core.unregister_ui("gcode_preferences", self._table.widget)
def update_widgets(self, widget=None): def update_widgets(self, widget=None):
widget = self.spindle_delay.get_widget() widget = self.spindle_delay.get_widget()
widget.set_sensitive(self.spindle_enable.get_value()) widget.set_sensitive(self.spindle_enable.get_value())
...@@ -244,6 +257,15 @@ class GCodeCornerStyle(pycam.Plugins.PluginBase): ...@@ -244,6 +257,15 @@ class GCodeCornerStyle(pycam.Plugins.PluginBase):
self.update_widgets() self.update_widgets()
return True return True
def teardown(self):
self.core.unregister_ui("gcode_corner_style",
self.motion_tolerance.get_widget())
self.core.unregister_ui("gcode_corner_style",
self.naive_tolerance.get_widget())
self.core.unregister_ui("gcode_corner_style",
self.path_mode.get_widget())
self.core.unregister_ui_section("gcode_corner_style")
def update_widgets(self, widget=None): def update_widgets(self, widget=None):
enable_tolerances = (self.path_mode.get_value() == "optimize_speed") enable_tolerances = (self.path_mode.get_value() == "optimize_speed")
controls = (self.motion_tolerance, self.naive_tolerance) controls = (self.motion_tolerance, self.naive_tolerance)
......
...@@ -36,17 +36,28 @@ class GCodeTouchOff(pycam.Plugins.PluginBase): ...@@ -36,17 +36,28 @@ class GCodeTouchOff(pycam.Plugins.PluginBase):
box.unparent() box.unparent()
self.core.register_ui("gcode_preferences", "Touch Off", self.core.register_ui("gcode_preferences", "Touch Off",
box, weight=70) box, weight=70)
self._gtk_handlers = []
for objname, setting in ( for objname, setting in (
("GCodeTouchOffOnStartup", "touch_off_on_startup"), ("GCodeTouchOffOnStartup", "touch_off_on_startup"),
("GCodeTouchOffOnToolChange", "touch_off_on_tool_change")): ("GCodeTouchOffOnToolChange", "touch_off_on_tool_change")):
self.gui.get_object(objname).connect("toggled", obj = self.gui.get_object(objname)
self.update_widgets) self._gtk_handlers.append((obj, "toggled", self.update_widgets))
self.gui.get_object("TouchOffLocationSelector").connect("changed", self.core.add_item(setting, obj.get_active, obj.set_active)
self.update_widgets) selector = self.gui.get_object("TouchOffLocationSelector")
self.gui.get_object("TouchOffLocationSelector").set_active(0) self._gtk_handlers.append((selector, "changed", self.update_widgets))
selector.set_active(0)
self.register_gtk_handlers(self._gtk_handlers)
self.update_widgets() self.update_widgets()
return True return True
def teardown(self):
if self.gui:
self.core.unregister_ui("gcode_preferences",
self.gui.get_object("TouchOffBox"))
self.unregister_gtk_handlers(self._gtk_handlers)
for setting in ("touch_off_on_startup", "touch_off_on_tool_change"):
self.core.remove_item(setting)
def update_widgets(self, widget=None): def update_widgets(self, widget=None):
# tool change controls # tool change controls
pos_control = self.gui.get_object("TouchOffLocationSelector") pos_control = self.gui.get_object("TouchOffLocationSelector")
......
...@@ -69,7 +69,7 @@ class ToolpathSimulation(pycam.Plugins.PluginBase): ...@@ -69,7 +69,7 @@ class ToolpathSimulation(pycam.Plugins.PluginBase):
def teardown(self): def teardown(self):
if self.gui: if self.gui:
for name in ("simulation_speed_factor", "simulation_details_level"): for name in ("simulation_speed_factor", "simulation_details_level"):
self.core.add_item(name, None, lambda value: None) self.core.remove_item(name)
self.unregister_gtk_handlers(self._gtk_handlers) self.unregister_gtk_handlers(self._gtk_handlers)
def finish_toolpath_simulation(self, widget=None, data=None): def finish_toolpath_simulation(self, widget=None, data=None):
......
...@@ -63,7 +63,7 @@ class Units(pycam.Plugins.PluginBase): ...@@ -63,7 +63,7 @@ class Units(pycam.Plugins.PluginBase):
return True return True
def teardown(self): def teardown(self):
self.core.clear_state_items() self.clear_state_items()
if self.gui: if self.gui:
self.core.unregister_ui("preferences_general", self.core.unregister_ui("preferences_general",
self.gui.get_object("UnitPrefBox")) self.gui.get_object("UnitPrefBox"))
......
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