Commit 3276773e authored by sumpfralle's avatar sumpfralle

replaced "register_parameter_section" with a normal ui_section


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1181 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent ed7f47eb
......@@ -20,7 +20,9 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
# gtk and gobject are imported later (to avoid plugin load failures)
import gtk
import gobject
import pycam.Utils.log
......@@ -69,7 +71,6 @@ class InputNumber(InputBaseClass):
def __init__(self, digits=0, start=0, lower=0, upper=100,
increment=1, change_handler=None):
import gtk
adjustment = gtk.Adjustment(value=start, lower=lower, upper=upper,
step_incr=increment)
self.control = gtk.SpinButton(adjustment, digits=digits)
......@@ -89,8 +90,6 @@ class InputNumber(InputBaseClass):
class InputChoice(InputBaseClass):
def __init__(self, choices, change_handler=None):
import gtk
import gobject
self.model = gtk.ListStore(gobject.TYPE_STRING)
self._values = []
for label, value in choices:
......@@ -149,8 +148,6 @@ class InputChoice(InputBaseClass):
class InputTable(InputChoice):
def __init__(self, choices, change_handler=None):
import gtk
import gobject
self.model = gtk.ListStore(gobject.TYPE_STRING)
self._values = []
for label, value in choices:
......@@ -191,7 +188,6 @@ class InputTable(InputChoice):
class InputCheckBox(InputBaseClass):
def __init__(self, start=False, change_handler=None):
import gtk
self.control = gtk.CheckButton()
self.control.set_active(start)
if change_handler:
......@@ -205,3 +201,81 @@ class InputCheckBox(InputBaseClass):
def set_value(self, value):
self.control.set_active(value)
class ParameterSection(object):
def __init__(self):
self._widgets = []
self._table = gtk.Table(rows=1, columns=2)
self._table.set_col_spacings(3)
self._table.set_row_spacings(3)
self.update_widgets()
self._update_widgets_visibility()
self._table.show()
self.widget = self._table
def add_widget(self, widget, label, weight=100):
item = (widget, label, weight, [])
self._widgets.append(item)
for signal in ("hide", "show"):
item[3].append(widget.connect(signal,
self._update_widgets_visibility))
self.update_widgets()
def clear_widgets(self):
while self._widgets:
item = self._widgets.pop()
for signal_handler in item[3]:
item[0].disconnect(signal_handler)
self.update_widgets()
def update_widgets(self):
widgets = list(self._widgets)
widgets.sort(key=lambda item: item[2])
# remove all widgets from the table
for child in self._table.get_children():
self._table.remove(child)
# add the current controls
for index, widget in enumerate(widgets):
if hasattr(widget, "get_label"):
# checkbox
widget.set_label(widget[1])
self._table.attach(widget, 0, 2, index, index + 1,
xoptions=gtk.FILL, yoptions=gtk.FILL)
elif not widget[1]:
self._table.attach(widget[0], 0, 2, index, index + 1,
xoptions=gtk.FILL, yoptions=gtk.FILL)
else:
# spinbutton, combobox, ...
label = gtk.Label("%s:" % widget[1])
label.set_alignment(0.0, 0.5)
self._table.attach(label, 0, 1, index, index + 1,
xoptions=gtk.FILL, yoptions=gtk.FILL)
self._table.attach(widget[0], 1, 2, index, index + 1,
xoptions=gtk.FILL, yoptions=gtk.FILL)
self._update_widgets_visibility()
def _get_table_row_of_widget(self, widget):
for child in self._table.get_children():
if child is widget:
return self._get_child_row(child)
else:
return -1
def _get_child_row(self, widget):
return gtk.Container.child_get_property(self._table, widget,
"top-attach")
def _update_widgets_visibility(self, widget=None):
for widget in self._widgets:
table_row = self._get_table_row_of_widget(widget[0])
is_visible = widget[0].props.visible
for child in self._table.get_children():
if widget == child:
continue
if self._get_child_row(child) == table_row:
if is_visible:
child.show()
else:
child.hide()
......@@ -36,14 +36,11 @@ class ParameterGroupManager(pycam.Plugins.PluginBase):
self.core.set("get_parameter_sets", self.get_parameter_sets)
self.core.set("register_parameter_group", self.register_parameter_group)
self.core.set("register_parameter_set", self.register_parameter_set)
self.core.set("register_parameter_section", self.register_parameter_section)
self.core.set("register_parameter", self.register_parameter)
self.core.set("unregister_parameter_group",
self.unregister_parameter_group)
self.core.set("unregister_parameter_set",
self.unregister_parameter_set)
self.core.set("unregister_parameter_section",
self.unregister_parameter_section)
self.core.set("unregister_parameter",
self.unregister_parameter)
return True
......@@ -51,9 +48,8 @@ class ParameterGroupManager(pycam.Plugins.PluginBase):
def teardown(self):
for name in ("get_parameters", "set_parameter_values",
"get_parameter_values", "get_parameter_sets",
"register_parameter_section", "register_parameter_set",
"register_parameter_group", "register_parameter",
"unregister_parameter_section", "unregister_parameter_set",
"register_parameter_set", "register_parameter_group",
"register_parameter", "unregister_parameter_set",
"unregister_parameter_group", "unregister_parameter"):
self.core.set(name, None)
......@@ -65,7 +61,28 @@ class ParameterGroupManager(pycam.Plugins.PluginBase):
"changed_set_list_event": changed_set_list_event,
"get_current_set_func": get_current_set_func,
"sets": {},
"sections": {}}
"parameters": {}}
if changed_set_event:
self.core.register_event(changed_set_event,
self._update_widgets_visibility, name)
def _update_widgets_visibility(self, group_name):
group = self._groups[group_name]
current_set_func = group["get_current_set_func"]
if not current_set_func:
return
current_set = current_set_func()
if current_set:
active_parameters = current_set["parameters"]
else:
active_parameters = []
for param in group["parameters"].values():
widget = param["control"].get_widget()
# TODO: this is gtk-specific (show/hide)
if param["name"] in active_parameters:
widget.show()
else:
widget.hide()
def register_parameter_set(self, group_name, name, label, func,
parameters=None, weight=100):
......@@ -87,37 +104,15 @@ class ParameterGroupManager(pycam.Plugins.PluginBase):
if event:
self.core.emit_event(event)
def register_parameter_section(self, group_name, name):
def register_parameter(self, group_name, name, control):
if not group_name in self._groups:
self.log.info("Unknown parameter group: %s" % group_name)
return
group = self._groups[group_name]
if name in group["sections"]:
self.log.debug("Registering section '%s' in group '%s' again" % \
(name, group_name))
widget = ParameterSectionGTK(self.core, group["changed_set_event"],
lambda: self.get_parameters(group_name),
group["get_current_set_func"])
group["sections"][name] = {"widget": widget, "parameters": {}}
return widget.widget
def register_parameter(self, group_name, section_name, name, label,
control, weight=100):
if not group_name in self._groups:
self.log.info("Unknown parameter group: %s" % group_name)
return
group = self._groups[group_name]
if not section_name in group["sections"]:
self.log.info("Unknown parameter section: %s->%s" % \
(group_name, section_name))
return
section = group["sections"][section_name]
if name in section["parameters"]:
if name in group["parameters"]:
self.log.debug("Registering parameter '%s' in group '%s' again" % \
(name, group_name))
section["parameters"][name] = {"name": name, "label": label,
"control": control, "weight": weight }
section["widget"].update_widgets()
group["parameters"][name] = {"name": name, "control": control}
def get_parameters(self, group_name):
if not group_name in self._groups:
......@@ -125,9 +120,7 @@ class ParameterGroupManager(pycam.Plugins.PluginBase):
return []
result = {}
group = self._groups[group_name]
for section in group["sections"].values():
result.update(section["parameters"])
return result
return list(group["parameters"].values)
def get_parameter_values(self, group_name):
if not group_name in self._groups:
......@@ -135,9 +128,8 @@ class ParameterGroupManager(pycam.Plugins.PluginBase):
return {}
result = {}
group = self._groups[group_name]
for section in group["sections"].values():
for parameter in section["parameters"].values():
result[parameter["name"]] = parameter["control"].get_value()
for parameter in group["parameters"].values():
result[parameter["name"]] = parameter["control"].get_value()
return result
def set_parameter_values(self, group_name, value_dict):
......@@ -145,11 +137,9 @@ class ParameterGroupManager(pycam.Plugins.PluginBase):
self.log.info("Unknown parameter group: %s" % group_name)
return
group = self._groups[group_name]
for section in group["sections"].values():
for parameter in section["parameters"].values():
if parameter["name"] in value_dict:
parameter["control"].set_value(
value_dict[parameter["name"]])
for parameter in group["parameters"].values():
if parameter["name"] in value_dict:
parameter["control"].set_value(value_dict[parameter["name"]])
def get_parameter_sets(self, group_name):
if not group_name in self._groups:
......@@ -164,41 +154,24 @@ class ParameterGroupManager(pycam.Plugins.PluginBase):
"group: %s" % group_name)
return
group = self._groups[group_name]
if group["sections"]:
self.log.debug(("Unregistering parameter group (%s), but it " + \
"still contains sections") % \
(group_name, ", ".join(group["sections"].keys())))
for section_name in group["sections"]:
self.unregister_parameter_section(group_name, section_name)
if group["parameters"]:
self.log.debug(("Unregistering parameter from group '%s', but " + \
"it still contains parameters") % \
(group_name, ", ".join(group["parameters"].keys())))
for name in group["parameters"]:
self.unregister_parameter(group_name, name)
if group["sets"]:
self.log.debug(("Unregistering parameter group (%s), but it " + \
"still contains sets: %s") % \
(group_name, ", ".join(group["sets"].keys())))
for set_name in group["sets"]:
self.unregister_parameter_set(group_name, set_name)
changed_set_event = group["changed_set_event"]
if changed_set_event:
self.core.register_event(changed_set_event,
self._update_widgets_visibility)
del self._groups[group_name]
def unregister_parameter_section(self, group_name, section_name):
if not group_name in self._groups:
self.log.debug(("Tried to unregister section '%s' from a " + \
"non-existing parameter group: %s") % \
(section_name, group_name))
return
group = self._groups[group_name]
if not section_name in group["sections"]:
self.log.debug("Tried to unregister non-existing parameter " + \
"section '%s' from group '%s'" % (section_name, group_name))
return
section = group["sections"][section_name]
if section["parameters"]:
self.log.debug(("Unregistering parameter section (%s->%s), " + \
"but it still contains parameters") % (group_name,
section_name, ", ".join(group["parameters"].keys())))
for parameter_name in section["parameters"]:
self.unregister_parameter(group_name, section_name,
parameter_name)
del group["sections"][section_name]
def unregister_parameter_set(self, group_name, set_name):
if not group_name in self._groups:
self.log.debug(("Tried to unregister set '%s' from a " + \
......@@ -215,99 +188,15 @@ class ParameterGroupManager(pycam.Plugins.PluginBase):
if event:
self.core.emit_event(event)
def unregister_parameter(self, group_name, section_name, name):
def unregister_parameter(self, group_name, name):
if not group_name in self._groups:
self.log.debug(("Tried to unregister parameter '%s' in " + \
"section '%s' from a non-existing parameter group: %s") % \
(name, section_name, group_name))
return
group = self._groups[group_name]
if not section_name in group["sections"]:
self.log.debug(("Tried to unregister parameter '%s' from a " + \
"non-existing parameter section '%s' in group '%s'") % \
(name, section_name, group_name))
"non-existing parameter group: %s") % (name, group_name))
return
section = group["sections"][section_name]
if name in section["parameters"]:
del section["parameters"][name]
group = self._groups[group_name]
if name in group["parameters"]:
del group["parameters"][name]
else:
self.log.debug("Tried to unregister the non-existing " + \
"parameter '%s' from '%s->%s'" % \
(name, group_name, section_name))
class ParameterSectionGTK(object):
def __init__(self, core, update_visibility_event=None,
get_params_dict_func=None,
get_current_set_func=None):
import gtk
self._gtk = gtk
self.core = core
self._table = gtk.Table(rows=1, columns=2)
self._table.set_col_spacings(3)
self._table.set_row_spacings(3)
if update_visibility_event:
self.core.register_event(update_visibility_event,
self._update_widgets_visibility)
self._get_current_set_func = get_current_set_func
self._get_params_dict_func = get_params_dict_func
self.update_widgets()
self._update_widgets_visibility()
self._table.show()
self.widget = self._table
def update_widgets(self):
gtk = self._gtk
params = self._get_params_dict_func().values()
params.sort(key=lambda item: item["weight"])
# remove all widgets from the table
for child in self._table.get_children():
self._table.remove(child)
# add the current controls
for index, param in enumerate(params):
widget = param["control"].get_widget()
if hasattr(widget, "get_label"):
# checkbox
widget.set_label(param["label"])
self._table.attach(widget, 0, 2, index, index + 1,
xoptions=gtk.FILL, yoptions=gtk.FILL)
elif not param["label"]:
self._table.attach(widget, 0, 2, index, index + 1,
xoptions=gtk.FILL, yoptions=gtk.FILL)
else:
# spinbutton, combobox, ...
label = gtk.Label("%s:" % param["label"])
label.set_alignment(0.0, 0.5)
self._table.attach(label, 0, 1, index, index + 1,
xoptions=gtk.FILL, yoptions=gtk.FILL)
self._table.attach(widget, 1, 2, index, index + 1,
xoptions=gtk.FILL, yoptions=gtk.FILL)
self._update_widgets_visibility()
def _get_table_row_of_widget(self, widget):
for child in self._table.get_children():
if child is widget:
return self._get_child_row(child)
else:
return -1
def _get_child_row(self, widget):
return self._gtk.Container.child_get_property(self._table, widget,
"top-attach")
def _update_widgets_visibility(self):
params = self._get_params_dict_func()
generator = self._get_current_set_func()
if not generator:
return
for param in params.values():
table_row = self._get_table_row_of_widget(
param["control"].get_widget())
for child in self._table.get_children():
if self._get_child_row(child) == table_row:
if param["name"] in generator["parameters"]:
child.show()
else:
child.hide()
"parameter '%s' from group '%s'" % (name, group_name))
......@@ -33,19 +33,21 @@ class PathParamOverlap(pycam.Plugins.PluginBase):
def setup(self):
# configure the input/output converter
widget = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=99, digits=0,
increment=10, change_handler=lambda widget=None: \
self.control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=99,
digits=0, increment=10, change_handler=lambda widget=None: \
self.core.emit_event("process-changed"))
widget.set_conversion(
self.control.set_conversion(
set_conv=lambda float_value: int(float_value * 100.0),
get_conv=lambda percent: percent / 100.0)
self.core.get("register_parameter")("process", "pathgenerator",
"overlap", "Overlap [%]", widget, weight=10)
self.core.get("register_parameter")("process", "overlap",
self.control)
self.core.register_ui("process_path_parameters", "Overlap [%]",
self.control.get_widget(), weight=10)
return True
def teardown(self):
self.core.get("unregister_parameter")("process", "pathgenerator",
"overlap")
self.core.unregister_ui("process_path_parameters", self.control.get_widget())
self.core.get("unregister_parameter")("process", "overlap")
class PathParamStepDown(pycam.Plugins.PluginBase):
......@@ -54,16 +56,19 @@ class PathParamStepDown(pycam.Plugins.PluginBase):
CATEGORIES = ["Process", "Parameter"]
def setup(self):
widget = pycam.Gui.ControlsGTK.InputNumber(lower=0.01, upper=1000,
digits=2, start=1, change_handler=lambda widget=None: \
self.control = pycam.Gui.ControlsGTK.InputNumber(lower=0.01,
upper=1000, digits=2, start=1,
change_handler=lambda widget=None: \
self.core.emit_event("process-changed"))
self.core.get("register_parameter")("process", "pathgenerator",
"step_down", "Step down", widget, weight=20)
self.core.get("register_parameter")("process", "step_down",
self.control)
self.core.register_ui("process_path_parameters", "Step down",
self.control.get_widget(), weight=20)
return True
def teardown(self):
self.core.get("unregister_parameter")("process", "pathgenerator",
"step_down")
self.core.unregister_ui("process_path_parameters", self.control.get_widget())
self.core.get("unregister_parameter")("process", "step_down")
class PathParamMaterialAllowance(pycam.Plugins.PluginBase):
......@@ -72,16 +77,18 @@ class PathParamMaterialAllowance(pycam.Plugins.PluginBase):
CATEGORIES = ["Process", "Parameter"]
def setup(self):
widget = pycam.Gui.ControlsGTK.InputNumber(start=0, lower=0, upper=100,
digits=2, change_handler=lambda widget=None: \
self.control = pycam.Gui.ControlsGTK.InputNumber(start=0, lower=0,
upper=100, digits=2, change_handler=lambda widget=None: \
self.core.emit_event("process-changed"))
self.core.get("register_parameter")("process", "pathgenerator",
"material_allowance", "Material allowance", widget, weight=30)
self.core.get("register_parameter")("process", "material_allowance",
self.control)
self.core.register_ui("process_path_parameters", "Material allowance",
self.control.get_widget(), weight=30)
return True
def teardown(self):
self.core.get("unregister_parameter")("process", "pathgenerator",
"material_allowance")
self.core.unregister_ui("process_path_parameters", self.control.get_widget())
self.core.get("unregister_parameter")("process", "material_allowance")
class PathParamMillingStyle(pycam.Plugins.PluginBase):
......@@ -90,19 +97,21 @@ class PathParamMillingStyle(pycam.Plugins.PluginBase):
CATEGORIES = ["Process", "Parameter"]
def setup(self):
input_control = pycam.Gui.ControlsGTK.InputChoice(
self.control = pycam.Gui.ControlsGTK.InputChoice(
(("ignore", pycam.Toolpath.MotionGrid.MILLING_STYLE_IGNORE),
("climb / down", pycam.Toolpath.MotionGrid.MILLING_STYLE_CLIMB),
("conventional / up", pycam.Toolpath.MotionGrid.MILLING_STYLE_CONVENTIONAL)),
change_handler=lambda widget=None: self.core.emit_event(
"process-changed"))
self.core.get("register_parameter")("process", "pathgenerator",
"milling_style", "Milling style", input_control, weight=50)
self.core.get("register_parameter")("process", "milling_style",
self.control)
self.core.register_ui("process_path_parameters", "Milling style",
self.control.get_widget(), weight=50)
return True
def teardown(self):
self.core.get("unregister_parameter")("process", "pathgenerator",
"milling_style")
self.core.unregister_ui("process_path_parameters", self.control.get_widget())
self.core.get("unregister_parameter")("process", "milling_style")
class PathParamGridDirection(pycam.Plugins.PluginBase):
......@@ -111,19 +120,21 @@ class PathParamGridDirection(pycam.Plugins.PluginBase):
CATEGORIES = ["Process", "Parameter"]
def setup(self):
input_control = pycam.Gui.ControlsGTK.InputChoice(
self.control = pycam.Gui.ControlsGTK.InputChoice(
(("x", pycam.Toolpath.MotionGrid.GRID_DIRECTION_X),
("y", pycam.Toolpath.MotionGrid.GRID_DIRECTION_Y),
("xy", pycam.Toolpath.MotionGrid.GRID_DIRECTION_XY)),
change_handler=lambda widget=None: self.core.emit_event(
"process-changed"))
self.core.get("register_parameter")("process", "pathgenerator",
"grid_direction", "Direction", input_control, weight=40)
self.core.get("register_parameter")("process", "grid_direction",
self.control)
self.core.register_ui("process_path_parameters", "Direction",
self.control.get_widget(), weight=40)
return True
def teardown(self):
self.core.get("unregister_parameter")("process", "pathgenerator",
"grid_direction")
self.core.unregister_ui("process_path_parameters", self.control.get_widget())
self.core.get("unregister_parameter")("process", "grid_direction")
class PathParamPattern(pycam.Plugins.PluginBase):
......@@ -132,18 +143,20 @@ class PathParamPattern(pycam.Plugins.PluginBase):
CATEGORIES = ["Process", "Parameter"]
def setup(self):
widget = pycam.Gui.ControlsGTK.InputChoice(
self.control = pycam.Gui.ControlsGTK.InputChoice(
(("grid", pycam.Toolpath.MotionGrid.get_fixed_grid),
("spiral", pycam.Toolpath.MotionGrid.get_spiral)),
change_handler=lambda widget=None: self.core.emit_event(
"process-changed"))
self.core.get("register_parameter")("process", "pathgenerator",
"path_pattern", "Pattern", widget, weight=5)
self.core.get("register_parameter")("process", "path_pattern",
self.control)
self.core.register_ui("process_path_parameters", "Pattern",
self.control.get_widget(), weight=5)
return True
def teardown(self):
self.core.get("unregister_parameter")("process", "pathgenerator",
"path_pattern")
self.core.unregister_ui("process_path_parameters", self.control.get_widget())
self.core.get("unregister_parameter")("process", "path_pattern")
class PathParamRadiusCompensation(pycam.Plugins.PluginBase):
......@@ -152,16 +165,18 @@ class PathParamRadiusCompensation(pycam.Plugins.PluginBase):
CATEGORIES = ["Process", "Parameter"]
def setup(self):
widget = pycam.Gui.ControlsGTK.InputCheckBox(
self.control = pycam.Gui.ControlsGTK.InputCheckBox(
change_handler=lambda widget=None: self.core.emit_event(
"process-changed"))
self.core.get("register_parameter")("process", "pathgenerator",
"radius_compensation", "Radius compensation", widget, weight=80)
self.core.get("register_parameter")("process", "radius_compensation",
self.control)
self.core.register_ui("process_path_parameters", "Radius compensation",
self.control.get_widget(), weight=80)
return True
def teardown(self):
self.core.get("unregister_parameter")("process", "pathgenerator",
"radius_compensation")
self.core.unregister_ui("process_path_parameters", self.control.get_widget())
self.core.get("unregister_parameter")("process", "radius_compensation")
class PathParamTraceModel(pycam.Plugins.PluginBase):
......@@ -170,7 +185,7 @@ class PathParamTraceModel(pycam.Plugins.PluginBase):
CATEGORIES = ["Process", "Parameter"]
def setup(self):
self.input_control = pycam.Gui.ControlsGTK.InputTable([],
self.control = pycam.Gui.ControlsGTK.InputTable([],
change_handler=lambda widget=None: \
self.core.emit_event("process-changed"))
# configure the input/output converter
......@@ -185,23 +200,25 @@ class PathParamTraceModel(pycam.Plugins.PluginBase):
return models
def set_converter(models):
return [id(model) for model in models]
self.input_control.set_conversion(set_conv=set_converter,
self.control.set_conversion(set_conv=set_converter,
get_conv=get_converter)
self.core.get("register_parameter")("process", "pathgenerator",
"trace_models", "Trace models (2D)", self.input_control, weight=5)
self.core.get("register_parameter")("process", "trace_models",
self.control)
self.core.register_ui("process_path_parameters", "Trace models (2D)",
self.control.get_widget(), weight=5)
self.core.register_event("model-list-changed", self._update_models)
return True
def teardown(self):
self.core.get("unregister_parameter")("process", "trace_models")
self.core.unregister_ui("process_path_parameters", self.control.get_widget())
self.core.unregister_event("model-list-changed", self._update_models)
def _update_models(self):
choices = []
models = self.core.get("models")
for model in models:
if hasattr(model, "get_polygons"):
choices.append((models.get_attr(model, "name"), model))
self.input_control.update_choices(choices)
def teardown(self):
self.core.get("unregister_parameter")("process", "pathgenerator",
"trace_models")
self.core.unregister_event("model-list-changed", self._update_models)
self.control.update_choices(choices)
......@@ -70,10 +70,11 @@ 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 = self.core.get("register_parameter_section")(
"process", "pathgenerator")
parameter_widget = pycam.Gui.ControlsGTK.ParameterSection()
self.core.register_ui_section("process_path_parameters",
parameter_widget.add_widget, parameter_widget.clear_widgets)
self.core.register_ui("process_parameters", "Path parameters",
parameter_widget, weight=10)
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"),
......
......@@ -31,19 +31,20 @@ class TaskParamCollisionModels(pycam.Plugins.PluginBase):
CATEGORIES = ["Model", "Task", "Parameter"]
def setup(self):
self.input_control = pycam.Gui.ControlsGTK.InputTable([],
self.control = pycam.Gui.ControlsGTK.InputTable([],
change_handler=lambda widget=None: \
self.core.emit_event("task-changed"))
self.input_control.get_widget().set_size_request(240, -1)
self.core.get("register_parameter")("task", "models",
"collision_models", "", self.input_control,
self.control.get_widget().set_size_request(240, -1)
self.core.get("register_parameter")("task", "collision_models",
self.control)
self.core.register_ui("task_models", "", self.control.get_widget(),
weight=5)
self.core.register_event("model-list-changed", self._update_models)
return True
def teardown(self):
self.core.get("unregister_parameter")("task", "models",
"collision_models")
self.core.get("unregister_parameter")("task", "collision_models")
self.core.unregister_ui("task_models", self.control.get_widget())
self.core.unregister_event("model-list-changed", self._update_models)
def _update_models(self):
......@@ -52,7 +53,7 @@ class TaskParamCollisionModels(pycam.Plugins.PluginBase):
for model in models:
if hasattr(model, "triangles"):
choices.append((models.get_attr(model, "name"), model))
self.input_control.update_choices(choices)
self.control.update_choices(choices)
class TaskParamTool(pycam.Plugins.PluginBase):
......@@ -61,16 +62,18 @@ class TaskParamTool(pycam.Plugins.PluginBase):
CATEGORIES = ["Tool", "Task", "Parameter"]
def setup(self):
self.input_control = pycam.Gui.ControlsGTK.InputChoice([],
self.control = pycam.Gui.ControlsGTK.InputChoice([],
change_handler=lambda widget=None: \
self.core.emit_event("task-changed"))
self.core.get("register_parameter")("task", "components", "tool",
"Tool", self.input_control, weight=10)
self.core.get("register_parameter")("task", "tool", self.control)
self.core.register_ui("task_components", "Tool",
self.control.get_widget(), weight=10)
self.core.register_event("tool-list-changed", self._update_tools)
return True
def teardown(self):
self.core.get("unregister_parameter")("task", "components", "tool")
self.core.get("unregister_parameter")("task", "tool")
self.core.unregister_ui("task_models", self.control.get_widget())
self.core.unregister_event("tool-list-changed", self._update_tools)
def _update_tools(self):
......@@ -78,7 +81,7 @@ class TaskParamTool(pycam.Plugins.PluginBase):
tools = self.core.get("tools")
for tool in tools:
choices.append((tools.get_attr(tool, "name"), tool))
self.input_control.update_choices(choices)
self.control.update_choices(choices)
class TaskParamProcess(pycam.Plugins.PluginBase):
......@@ -87,16 +90,18 @@ class TaskParamProcess(pycam.Plugins.PluginBase):
CATEGORIES = ["Process", "Task", "Parameter"]
def setup(self):
self.input_control = pycam.Gui.ControlsGTK.InputChoice([],
self.control = pycam.Gui.ControlsGTK.InputChoice([],
change_handler=lambda widget=None: \
self.core.emit_event("task-changed"))
self.core.get("register_parameter")("task", "components", "process",
"Process", self.input_control, weight=20)
self.core.get("register_parameter")("task", "process", self.control)
self.core.register_ui("task_components", "Process",
self.control.get_widget(), weight=20)
self.core.register_event("process-list-changed", self._update_processes)
return True
def teardown(self):
self.core.get("unregister_parameter")("task", "components", "process")
self.core.get("unregister_parameter")("task", "process")
self.core.unregister_ui("task_models", self.control.get_widget())
self.core.unregister_event("process-list-changed", self._update_processes)
def _update_processes(self):
......@@ -104,7 +109,7 @@ class TaskParamProcess(pycam.Plugins.PluginBase):
processes = self.core.get("processes")
for process in processes:
choices.append((processes.get_attr(process, "name"), process))
self.input_control.update_choices(choices)
self.control.update_choices(choices)
class TaskParamBounds(pycam.Plugins.PluginBase):
......@@ -113,16 +118,18 @@ class TaskParamBounds(pycam.Plugins.PluginBase):
CATEGORIES = ["Bounds", "Task", "Parameter"]
def setup(self):
self.input_control = pycam.Gui.ControlsGTK.InputChoice([],
self.control = pycam.Gui.ControlsGTK.InputChoice([],
change_handler=lambda widget=None: \
self.core.emit_event("task-changed"))
self.core.get("register_parameter")("task", "components", "bounds",
"Bounds", self.input_control, weight=30)
self.core.get("register_parameter")("task", "bounds", self.control)
self.core.register_ui("task_components", "Bounds",
self.control.get_widget(), weight=30)
self.core.register_event("bounds-list-changed", self._update_bounds)
return True
def teardown(self):
self.core.get("unregister_parameter")("task", "components", "bounds")
self.core.get("unregister_parameter")("task", "bounds")
self.core.unregister_ui("task_models", self.control.get_widget())
self.core.unregister_event("bounds-list-changed", self._update_bounds)
def _update_bounds(self):
......@@ -130,5 +137,5 @@ class TaskParamBounds(pycam.Plugins.PluginBase):
bounds = self.core.get("bounds")
for bound in bounds:
choices.append((bounds.get_attr(bound, "name"), bound))
self.input_control.update_choices(choices)
self.control.update_choices(choices)
......@@ -74,14 +74,18 @@ class Tasks(pycam.Plugins.ListPluginBase):
changed_set_event="task-type-changed",
changed_set_list_event="task-type-list-changed",
get_current_set_func=self._get_type)
self.models_parameter_widget = self.core.get(
"register_parameter_section")("task", "models")
self.models_widget = pycam.Gui.ControlsGTK.ParameterSection()
self.core.register_ui_section("task_models",
self.models_widget.add_widget,
self.models_widget.clear_widgets)
self.core.register_ui("task_parameters", "Collision models",
self.models_parameter_widget, weight=20)
self.components_parameter_widget = self.core.get(
"register_parameter_section")("task", "components")
self.models_widget.widget, weight=20)
self.components_widget = pycam.Gui.ControlsGTK.ParameterSection()
self.core.register_ui_section("task_components",
self.components_widget.add_widget,
self.components_widget.clear_widgets)
self.core.register_ui("task_parameters", "Components",
self.components_parameter_widget, weight=10)
self.components_widget.widget, weight=10)
# table
self._gtk_handlers.append((self.gui.get_object("TaskNameCell"),
"edited", self._edit_task_name))
......@@ -131,9 +135,10 @@ class Tasks(pycam.Plugins.ListPluginBase):
if self.gui:
self.core.unregister_ui("main", self.gui.get_object("TaskBox"))
self.core.unregister_ui("task_parameters",
self.models_parameter_widget)
self.core.unregister_ui("task_parameters",
self.components_parameter_widget)
self.models_widget)
self.core.unregister_ui("task_parameters", self.components_widget)
self.core.unregister_ui_section("task_models")
self.core.unregister_ui_section("task_components")
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
while len(self) > 0:
......
......@@ -31,19 +31,21 @@ class ToolParamRadius(pycam.Plugins.PluginBase):
CATEGORIES = ["Tool", "Parameter"]
def setup(self):
control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=99, digits=0,
change_handler=lambda widget=None: self.core.emit_event(
"tool-changed"))
control.set_conversion(set_conv=lambda value: value * 2.0,
self.control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=99,
digits=0, change_handler=lambda widget=None: \
self.core.emit_event("tool-changed"))
self.control.set_conversion(set_conv=lambda value: value * 2.0,
get_conv=lambda value: value / 2.0)
self.core.get("register_parameter")("tool", "size", "radius",
"Tool diameter", control, weight=10)
self.core.get("register_parameter")("tool", "radius", self.control)
self.core.register_ui("tool_size", "Tool Diameter",
self.control.get_widget(), weight=10)
self.core.register_chain("get_toolpath_information",
self.get_toolpath_information)
return True
def teardown(self):
self.core.get("unregister_parameter")("tool", "size", "radius")
self.core.get("unregister_parameter")("tool", "radius")
self.core.unregister_ui("tool_size", self.control.get_widget())
self.core.unregister_chain("get_toolpath_information",
self.get_toolpath_information)
......@@ -59,14 +61,17 @@ class ToolParamTorusRadius(pycam.Plugins.PluginBase):
CATEGORIES = ["Tool", "Parameter"]
def setup(self):
control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=99, digits=0,
change_handler=lambda widget=None: self.core.emit_event(
"tool-changed"))
self.core.get("register_parameter")("tool", "size", "torus_radius",
"Torus radius", control, weight=20)
self.control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=99,
digits=0, change_handler=lambda widget=None: \
self.core.emit_event( "tool-changed"))
self.core.get("register_parameter")("tool", "torus_radius",
self.control)
self.core.register_ui("tool_size", "Torus Radius",
self.control.get_widget(), weight=50)
return True
def teardown(self):
self.core.unregister_ui("tool_size", self.control.get_widget())
self.core.get("unregister_parameter")("tool", "size", "torus_radius")
......@@ -76,16 +81,18 @@ class ToolParamFeedrate(pycam.Plugins.PluginBase):
CATEGORIES = ["Tool", "Parameter"]
def setup(self):
control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=10000,
self.control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=10000,
digits=0, change_handler=lambda widget=None: \
self.core.emit_event("tool-changed"))
self.core.get("register_parameter")("tool", "speed", "feedrate",
"Feedrate", control, weight=10)
self.core.get("register_parameter")("tool", "feedrate", self.control)
self.core.register_ui("tool_speed", "Feedrate",
self.control.get_widget(), weight=10)
self.core.register_chain("get_toolpath_information",
self.get_toolpath_information)
return True
def teardown(self):
self.core.unregister_ui("tool_speed", self.control.get_widget())
self.core.get("unregister_parameter")("tool", "speed", "feedrate")
self.core.unregister_chain("get_toolpath_information",
self.get_toolpath_information)
......@@ -101,16 +108,19 @@ class ToolParamSpindleSpeed(pycam.Plugins.PluginBase):
CATEGORIES = ["Tool", "Parameter"]
def setup(self):
control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=100000,
self.control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=100000,
digits=0, change_handler=lambda widget=None: \
self.core.emit_event("tool-changed"))
self.core.get("register_parameter")("tool", "speed", "spindle_speed",
"Spindle speed", control, weight=20)
self.core.get("register_parameter")("tool", "spindle_speed",
self.control)
self.core.register_ui("tool_speed", "Spindle Speed",
self.control.get_widget(), weight=50)
self.core.register_chain("get_toolpath_information",
self.get_toolpath_information)
return True
def teardown(self):
self.core.unregister_ui("tool_speed", self.control.get_widget())
self.core.get("unregister_parameter")("tool", "speed", "spindle_speed")
self.core.unregister_chain("get_toolpath_information",
self.get_toolpath_information)
......
......@@ -74,14 +74,16 @@ 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_parameter_widget = self.core.get("register_parameter_section")(
"tool", "size")
size_widget = pycam.Gui.ControlsGTK.ParameterSection()
self.core.register_ui("tool_parameters", "Size",
size_parameter_widget, weight=10)
speed_parameter_widget = self.core.get("register_parameter_section")(
"tool", "speed")
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.core.register_ui("tool_parameters", "Speed",
speed_parameter_widget, weight=20)
speed_widget.widget, weight=20)
self.core.register_ui_section("tool_speed",
speed_widget.add_widget, speed_widget.clear_widgets)
# table updates
cell = self.gui.get_object("ToolTableShapeCell")
self.gui.get_object("ToolTableShapeColumn").set_cell_data_func(
......
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