Commit 1e716228 authored by sumpfralle's avatar sumpfralle

renamed events "*-parameter-changed" to "*-changed"

migrated task settings to the new parameter manager


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1144 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent ea4da952
...@@ -187,7 +187,7 @@ ...@@ -187,7 +187,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkAlignment" id="alignment1"> <object class="GtkAlignment" id="ProcessSelectorBox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="xscale">0</property> <property name="xscale">0</property>
<property name="yscale">0</property> <property name="yscale">0</property>
......
This diff is collapsed.
...@@ -222,7 +222,7 @@ ...@@ -222,7 +222,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkAlignment" id="alignment1"> <object class="GtkAlignment" id="ToolSelectorBox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="xscale">0</property> <property name="xscale">0</property>
<property name="yscale">0</property> <property name="yscale">0</property>
...@@ -267,7 +267,7 @@ ...@@ -267,7 +267,7 @@
<child> <child>
<object class="GtkHBox" id="ToolParameterBox"> <object class="GtkHBox" id="ToolParameterBox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="spacing">3</property> <property name="spacing">5</property>
<child> <child>
<placeholder/> <placeholder/>
</child> </child>
......
...@@ -31,7 +31,7 @@ _GTK_COLOR_MAX = 65535.0 ...@@ -31,7 +31,7 @@ _GTK_COLOR_MAX = 65535.0
class Models(pycam.Plugins.ListPluginBase): class Models(pycam.Plugins.ListPluginBase):
UI_FILE = "models.ui" UI_FILE = "models.ui"
COLUMN_ID, COLUMN_NAME, COLUMN_VISIBLE, COLUMN_COLOR, COLUMN_ALPHA = range(5) COLUMN_REF, COLUMN_NAME, COLUMN_VISIBLE, COLUMN_COLOR, COLUMN_ALPHA = range(5)
LIST_ATTRIBUTE_MAP = {"name": COLUMN_NAME, "visible": COLUMN_VISIBLE, LIST_ATTRIBUTE_MAP = {"name": COLUMN_NAME, "visible": COLUMN_VISIBLE,
"color": COLUMN_COLOR, "alpha": COLUMN_ALPHA} "color": COLUMN_COLOR, "alpha": COLUMN_ALPHA}
ICONS = {"visible": "visible.svg", "hidden": "visible_off.svg"} ICONS = {"visible": "visible.svg", "hidden": "visible_off.svg"}
...@@ -78,7 +78,7 @@ class Models(pycam.Plugins.ListPluginBase): ...@@ -78,7 +78,7 @@ class Models(pycam.Plugins.ListPluginBase):
self._model_cache = {} self._model_cache = {}
cache = self._model_cache cache = self._model_cache
for row in self._treemodel: for row in self._treemodel:
cache[row[self.COLUMN_ID]] = list(row) cache[row[self.COLUMN_REF]] = list(row)
self._treemodel.clear() self._treemodel.clear()
for index, item in enumerate(self): for index, item in enumerate(self):
if id(item) in cache: if id(item) in cache:
......
...@@ -267,6 +267,9 @@ class ParameterSectionGTK(object): ...@@ -267,6 +267,9 @@ class ParameterSectionGTK(object):
widget.set_label(param["label"]) widget.set_label(param["label"])
self._table.attach(widget, 0, 2, index, index + 1, self._table.attach(widget, 0, 2, index, index + 1,
xoptions=gtk.FILL, yoptions=gtk.FILL) 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: else:
# spinbutton, combobox, ... # spinbutton, combobox, ...
label = gtk.Label("%s:" % param["label"]) label = gtk.Label("%s:" % param["label"])
......
...@@ -33,7 +33,7 @@ class PathParamOverlap(pycam.Plugins.PluginBase): ...@@ -33,7 +33,7 @@ class PathParamOverlap(pycam.Plugins.PluginBase):
# configure the input/output converter # configure the input/output converter
widget = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=99, digits=0, widget = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=99, digits=0,
increment=10, change_handler=lambda widget=None: \ increment=10, change_handler=lambda widget=None: \
self.core.emit_event("process-parameter-changed")) self.core.emit_event("process-changed"))
widget.set_conversion( widget.set_conversion(
set_conv=lambda float_value: int(float_value * 100.0), set_conv=lambda float_value: int(float_value * 100.0),
get_conv=lambda percent: percent / 100.0) get_conv=lambda percent: percent / 100.0)
...@@ -53,7 +53,7 @@ class PathParamStepDown(pycam.Plugins.PluginBase): ...@@ -53,7 +53,7 @@ class PathParamStepDown(pycam.Plugins.PluginBase):
def setup(self): def setup(self):
widget = pycam.Gui.ControlsGTK.InputNumber(lower=0.01, upper=1000, widget = pycam.Gui.ControlsGTK.InputNumber(lower=0.01, upper=1000,
digits=2, start=1, change_handler=lambda widget=None: \ digits=2, start=1, change_handler=lambda widget=None: \
self.core.emit_event("process-parameter-changed")) self.core.emit_event("process-changed"))
self.core.get("register_parameter")("process", "pathgenerator", self.core.get("register_parameter")("process", "pathgenerator",
"step_down", "Step down", widget, weight=20) "step_down", "Step down", widget, weight=20)
return True return True
...@@ -70,7 +70,7 @@ class PathParamMaterialAllowance(pycam.Plugins.PluginBase): ...@@ -70,7 +70,7 @@ class PathParamMaterialAllowance(pycam.Plugins.PluginBase):
def setup(self): def setup(self):
widget = pycam.Gui.ControlsGTK.InputNumber(start=0, lower=0, upper=100, widget = pycam.Gui.ControlsGTK.InputNumber(start=0, lower=0, upper=100,
digits=2, change_handler=lambda widget=None: \ digits=2, change_handler=lambda widget=None: \
self.core.emit_event("process-parameter-changed")) self.core.emit_event("process-changed"))
self.core.get("register_parameter")("process", "pathgenerator", self.core.get("register_parameter")("process", "pathgenerator",
"material_allowance", "Material allowance", widget, weight=30) "material_allowance", "Material allowance", widget, weight=30)
return True return True
...@@ -90,7 +90,7 @@ class PathParamMillingStyle(pycam.Plugins.PluginBase): ...@@ -90,7 +90,7 @@ class PathParamMillingStyle(pycam.Plugins.PluginBase):
("climb / down", "climb"), ("climb / down", "climb"),
("conventional / up", "conventional")), ("conventional / up", "conventional")),
change_handler=lambda widget=None: self.core.emit_event( change_handler=lambda widget=None: self.core.emit_event(
"process-parameter-changed")) "process-changed"))
self.core.get("register_parameter")("process", "pathgenerator", self.core.get("register_parameter")("process", "pathgenerator",
"milling_style", "Milling style", input_control, weight=50) "milling_style", "Milling style", input_control, weight=50)
return True return True
...@@ -108,7 +108,7 @@ class PathParamGridDirection(pycam.Plugins.PluginBase): ...@@ -108,7 +108,7 @@ class PathParamGridDirection(pycam.Plugins.PluginBase):
input_control = pycam.Gui.ControlsGTK.InputChoice( input_control = pycam.Gui.ControlsGTK.InputChoice(
(("x", "x"), ("y", "y"), ("xy", "xy")), (("x", "x"), ("y", "y"), ("xy", "xy")),
change_handler=lambda widget=None: self.core.emit_event( change_handler=lambda widget=None: self.core.emit_event(
"process-parameter-changed")) "process-changed"))
self.core.get("register_parameter")("process", "pathgenerator", self.core.get("register_parameter")("process", "pathgenerator",
"grid_direction", "Direction", input_control, weight=40) "grid_direction", "Direction", input_control, weight=40)
return True return True
...@@ -125,7 +125,7 @@ class PathParamRadiusCompensation(pycam.Plugins.PluginBase): ...@@ -125,7 +125,7 @@ class PathParamRadiusCompensation(pycam.Plugins.PluginBase):
def setup(self): def setup(self):
widget = pycam.Gui.ControlsGTK.InputCheckBox( widget = pycam.Gui.ControlsGTK.InputCheckBox(
change_handler=lambda widget=None: self.core.emit_event( change_handler=lambda widget=None: self.core.emit_event(
"process-parameter-changed")) "process-changed"))
self.core.get("register_parameter")("process", "pathgenerator", self.core.get("register_parameter")("process", "pathgenerator",
"radius_compensation", "Radius compensation", widget, weight=80) "radius_compensation", "Radius compensation", widget, weight=80)
return True return True
...@@ -140,10 +140,9 @@ class PathParamTraceModel(pycam.Plugins.PluginBase): ...@@ -140,10 +140,9 @@ class PathParamTraceModel(pycam.Plugins.PluginBase):
DEPENDS = ["Processes", "Models"] DEPENDS = ["Processes", "Models"]
def setup(self): def setup(self):
# TODO: check if gtk is in use self.input_control = pycam.Gui.ControlsGTK.InputTable([],
self.input_control = pycam.Gui.ControlsGTK.InputTable([], force_type=long, force_type=long, change_handler=lambda widget=None: \
change_handler=lambda widget=None: self.core.emit_event( self.core.emit_event("process-changed"))
"process-parameter-changed"))
# configure the input/output converter # configure the input/output converter
def get_converter(model_refs): def get_converter(model_refs):
models_dict = {} models_dict = {}
......
...@@ -101,7 +101,7 @@ class Processes(pycam.Plugins.ListPluginBase): ...@@ -101,7 +101,7 @@ class Processes(pycam.Plugins.ListPluginBase):
self.register_model_update(update_model) self.register_model_update(update_model)
self.core.register_event("process-selection-changed", self.core.register_event("process-selection-changed",
self._process_switch) self._process_switch)
self.core.register_event("process-parameter-changed", self.core.register_event("process-changed",
self._store_process_settings) self._store_process_settings)
self.core.register_event("process-strategy-changed", self.core.register_event("process-strategy-changed",
self._store_process_settings) self._store_process_settings)
...@@ -166,6 +166,11 @@ class Processes(pycam.Plugins.ListPluginBase): ...@@ -166,6 +166,11 @@ class Processes(pycam.Plugins.ListPluginBase):
self.pop(index) self.pop(index)
# show "new" only if a strategy is available # show "new" only if a strategy is available
self.gui.get_object("ProcessNew").set_sensitive(len(model) > 0) self.gui.get_object("ProcessNew").set_sensitive(len(model) > 0)
selector_box = self.gui.get_object("ProcessSelectorBox")
if len(model) < 2:
selector_box.hide()
else:
selector_box.show()
def _get_strategy(self, name=None): def _get_strategy(self, name=None):
strategies = self.core.get("get_parameter_sets")("process") strategies = self.core.get("get_parameter_sets")("process")
...@@ -212,7 +217,7 @@ class Processes(pycam.Plugins.ListPluginBase): ...@@ -212,7 +217,7 @@ class Processes(pycam.Plugins.ListPluginBase):
if not process: if not process:
control_box.hide() control_box.hide()
else: else:
self.core.block_event("process-parameter-changed") self.core.block_event("process-changed")
self.core.block_event("process-strategy-changed") self.core.block_event("process-strategy-changed")
strategy_name = process["strategy"] strategy_name = process["strategy"]
self.select_strategy(strategy_name) self.select_strategy(strategy_name)
...@@ -220,7 +225,7 @@ class Processes(pycam.Plugins.ListPluginBase): ...@@ -220,7 +225,7 @@ class Processes(pycam.Plugins.ListPluginBase):
self.core.get("set_parameter_values")("process", process["parameters"]) self.core.get("set_parameter_values")("process", process["parameters"])
control_box.show() control_box.show()
self.core.unblock_event("process-strategy-changed") self.core.unblock_event("process-strategy-changed")
self.core.unblock_event("process-parameter-changed") self.core.unblock_event("process-changed")
self.core.emit_event("process-strategy-changed") self.core.emit_event("process-strategy-changed")
def _process_new(self, *args): def _process_new(self, *args):
......
# -*- coding: utf-8 -*-
"""
$Id$
Copyright 2011 Lars Kruse <devel@sumpfralle.de>
This file is part of PyCAM.
PyCAM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PyCAM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import pycam.Plugins
import pycam.Gui.ControlsGTK
class TaskParamCollisionModels(pycam.Plugins.PluginBase):
DEPENDS = ["Models", "Tasks"]
def setup(self):
self.input_control = pycam.Gui.ControlsGTK.InputTable([],
force_type=long, change_handler=lambda widget=None: \
self.core.emit_event("task-changed"))
# configure the input/output converter
def get_converter(model_refs):
models_dict = {}
for model in self.core.get("models"):
models_dict[id(model)] = model
models = []
for model_ref in model_refs:
models.append(models_dict[model_ref])
return models
def set_converter(models):
return [id(model) for model in models]
self.input_control.set_conversion(set_conv=set_converter,
get_conv=get_converter)
self.input_control.get_widget().set_size_request(240, -1)
self.core.get("register_parameter")("task", "models",
"collision_models", "", self.input_control,
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")
def _update_models(self):
choices = []
models = self.core.get("models")
for model in models:
if hasattr(model, "triangles"):
choices.append((models.get_attr(model, "name"), id(model)))
self.input_control.update_choices(choices)
class TaskParamTool(pycam.Plugins.PluginBase):
DEPENDS = ["Tools", "Tasks"]
def setup(self):
self.input_control = pycam.Gui.ControlsGTK.InputChoice([],
force_type=long, 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.register_event("tool-list-changed", self._update_tools)
return True
def teardown(self):
self.core.get("unregister_parameter")("task", "components", "tool")
def _update_tools(self):
choices = []
tools = self.core.get("tools")
for tool in tools:
choices.append((tools.get_attr(tool, "name"), id(tool)))
self.input_control.update_choices(choices)
class TaskParamProcess(pycam.Plugins.PluginBase):
DEPENDS = ["Processes", "Tasks"]
def setup(self):
self.input_control = pycam.Gui.ControlsGTK.InputChoice([],
force_type=long, 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.register_event("process-list-changed", self._update_processes)
return True
def teardown(self):
self.core.get("unregister_parameter")("task", "components", "process")
def _update_processes(self):
choices = []
processes = self.core.get("processes")
for process in processes:
choices.append((processes.get_attr(process, "name"), id(process)))
self.input_control.update_choices(choices)
class TaskParamBounds(pycam.Plugins.PluginBase):
DEPENDS = ["Bounds", "Tasks"]
def setup(self):
self.input_control = pycam.Gui.ControlsGTK.InputChoice([],
force_type=long, 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.register_event("bounds-list-changed", self._update_bounds)
return True
def teardown(self):
self.core.get("unregister_parameter")("task", "components", "bounds")
def _update_bounds(self):
choices = []
bounds = self.core.get("bounds")
for bound in bounds:
choices.append((bounds.get_attr(bound, "name"), id(bound)))
self.input_control.update_choices(choices)
# -*- coding: utf-8 -*-
"""
$Id$
Copyright 2011 Lars Kruse <devel@sumpfralle.de>
This file is part of PyCAM.
PyCAM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PyCAM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import pycam.Plugins
class TaskTypeMilling(pycam.Plugins.PluginBase):
DEPENDS = ["Tasks", "TaskParamCollisionModels", "TaskParamTool",
"TaskParamProcess", "TaskParamBounds"]
def setup(self):
parameters = {"collision_models": [],
"tool": None,
"process": None,
"bounds": None,
}
self.core.get("register_parameter_set")("task", "milling",
"Milling", self.run_task, parameters=parameters,
weight=10)
return True
def teardown(self):
self.core.get("unregister_parameter_set")("task", "milling")
def run_task(self):
pass
This diff is collapsed.
...@@ -32,7 +32,7 @@ class ToolParamRadius(pycam.Plugins.PluginBase): ...@@ -32,7 +32,7 @@ class ToolParamRadius(pycam.Plugins.PluginBase):
def setup(self): def setup(self):
control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=99, digits=0, control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=99, digits=0,
change_handler=lambda widget=None: self.core.emit_event( change_handler=lambda widget=None: self.core.emit_event(
"tool-parameter-changed")) "tool-changed"))
control.set_conversion(set_conv=lambda value: value * 2.0, control.set_conversion(set_conv=lambda value: value * 2.0,
get_conv=lambda value: value / 2.0) get_conv=lambda value: value / 2.0)
self.core.get("register_parameter")("tool", "size", "radius", self.core.get("register_parameter")("tool", "size", "radius",
...@@ -50,7 +50,7 @@ class ToolParamTorusRadius(pycam.Plugins.PluginBase): ...@@ -50,7 +50,7 @@ class ToolParamTorusRadius(pycam.Plugins.PluginBase):
def setup(self): def setup(self):
control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=99, digits=0, control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=99, digits=0,
change_handler=lambda widget=None: self.core.emit_event( change_handler=lambda widget=None: self.core.emit_event(
"tool-parameter-changed")) "tool-changed"))
self.core.get("register_parameter")("tool", "size", "torus_radius", self.core.get("register_parameter")("tool", "size", "torus_radius",
"Torus radius", control, weight=20) "Torus radius", control, weight=20)
return True return True
...@@ -66,7 +66,7 @@ class ToolParamFeedrate(pycam.Plugins.PluginBase): ...@@ -66,7 +66,7 @@ class ToolParamFeedrate(pycam.Plugins.PluginBase):
def setup(self): def setup(self):
control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=10000, control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=10000,
digits=0, change_handler=lambda widget=None: \ digits=0, change_handler=lambda widget=None: \
self.core.emit_event("tool-parameter-changed")) self.core.emit_event("tool-changed"))
self.core.get("register_parameter")("tool", "speed", "feedrate", self.core.get("register_parameter")("tool", "speed", "feedrate",
"Feedrate", control, weight=10) "Feedrate", control, weight=10)
return True return True
...@@ -82,7 +82,7 @@ class ToolParamSpindleSpeed(pycam.Plugins.PluginBase): ...@@ -82,7 +82,7 @@ class ToolParamSpindleSpeed(pycam.Plugins.PluginBase):
def setup(self): def setup(self):
control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=100000, control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=100000,
digits=0, change_handler=lambda widget=None: \ digits=0, change_handler=lambda widget=None: \
self.core.emit_event("tool-parameter-changed")) self.core.emit_event("tool-changed"))
self.core.get("register_parameter")("tool", "speed", "spindle_speed", self.core.get("register_parameter")("tool", "speed", "spindle_speed",
"Spindle speed", control, weight=20) "Spindle speed", control, weight=20)
return True return True
......
...@@ -51,10 +51,7 @@ class Tools(pycam.Plugins.ListPluginBase): ...@@ -51,10 +51,7 @@ class Tools(pycam.Plugins.ListPluginBase):
parameters_box.foreach( parameters_box.foreach(
lambda widget: parameters_box.remove(widget)) lambda widget: parameters_box.remove(widget))
def add_parameter_widget(item, name): def add_parameter_widget(item, name):
# create a frame with an align and the item inside # create a frame within an alignment and the item inside
if len(parameters_box.get_children()) > 0:
# add a separator between two content blocks
parameters_box.pack_start(gtk.VSeparator())
frame_label = gtk.Label() frame_label = gtk.Label()
frame_label.set_markup("<b>%s</b>" % name) frame_label.set_markup("<b>%s</b>" % name)
frame = gtk.Frame() frame = gtk.Frame()
...@@ -67,7 +64,6 @@ class Tools(pycam.Plugins.ListPluginBase): ...@@ -67,7 +64,6 @@ class Tools(pycam.Plugins.ListPluginBase):
parameters_box.pack_start(frame, expand=True) parameters_box.pack_start(frame, expand=True)
self.core.register_ui_section("tool_parameters", self.core.register_ui_section("tool_parameters",
add_parameter_widget, clear_parameter_widgets) add_parameter_widget, clear_parameter_widgets)
selector = self.gui.get_object("ToolShapeSelector")
self.core.get("register_parameter_group")("tool", self.core.get("register_parameter_group")("tool",
changed_set_event="tool-shape-changed", changed_set_event="tool-shape-changed",
changed_set_list_event="tool-shape-list-changed", changed_set_list_event="tool-shape-list-changed",
...@@ -80,6 +76,7 @@ class Tools(pycam.Plugins.ListPluginBase): ...@@ -80,6 +76,7 @@ class Tools(pycam.Plugins.ListPluginBase):
"tool", "speed") "tool", "speed")
self.core.register_ui("tool_parameters", "Speed", self.core.register_ui("tool_parameters", "Speed",
speed_parameter_widget, weight=20) speed_parameter_widget, weight=20)
# table updates
cell = self.gui.get_object("ToolTableShapeCell") cell = self.gui.get_object("ToolTableShapeCell")
self.gui.get_object("ToolTableShapeColumn").set_cell_data_func( self.gui.get_object("ToolTableShapeColumn").set_cell_data_func(
cell, self._render_tool_shape) cell, self._render_tool_shape)
...@@ -107,20 +104,21 @@ class Tools(pycam.Plugins.ListPluginBase): ...@@ -107,20 +104,21 @@ class Tools(pycam.Plugins.ListPluginBase):
selection.connect("changed", selection.connect("changed",
lambda widget, event: self.core.emit_event(event), lambda widget, event: self.core.emit_event(event),
"tool-selection-changed") "tool-selection-changed")
# shape selector
shape_selector = self.gui.get_object("ToolShapeSelector") shape_selector = self.gui.get_object("ToolShapeSelector")
shape_selector.connect("changed", lambda widget: \ shape_selector.connect("changed", lambda widget: \
self.core.emit_event("tool-shape-changed")) self.core.emit_event("tool-shape-changed"))
self.core.register_event("tool-shape-list-changed", self.core.register_event("tool-shape-list-changed",
self._update_widgets) self._update_widgets)
self.register_model_update(update_model)
self.core.register_event("tool-selection-changed", self.core.register_event("tool-selection-changed",
self._tool_change) self._tool_switch)
self.core.register_event("tool-parameter-changed", self.core.register_event("tool-changed",
self._store_tool_settings) self._store_tool_settings)
self.core.register_event("tool-shape-changed", self.core.register_event("tool-shape-changed",
self._store_tool_settings) self._store_tool_settings)
self.register_model_update(update_model)
self._update_widgets() self._update_widgets()
self._tool_change() self._tool_switch()
self.core.set("tools", self) self.core.set("tools", self)
return True return True
...@@ -128,7 +126,7 @@ class Tools(pycam.Plugins.ListPluginBase): ...@@ -128,7 +126,7 @@ class Tools(pycam.Plugins.ListPluginBase):
if self.gui: if self.gui:
self.core.unregister_ui("main", self.gui.get_object("ToolBox")) self.core.unregister_ui("main", self.gui.get_object("ToolBox"))
self.core.unregister_event("tool-selection-changed", self.core.unregister_event("tool-selection-changed",
self._tool_change) self._tool_switch)
self.core.set("tools", None) self.core.set("tools", None)
return True return True
...@@ -201,10 +199,9 @@ class Tools(pycam.Plugins.ListPluginBase): ...@@ -201,10 +199,9 @@ class Tools(pycam.Plugins.ListPluginBase):
cell.set_cell_data_func(renderer, self._render_tool_shape) cell.set_cell_data_func(renderer, self._render_tool_shape)
def _update_widgets(self): def _update_widgets(self):
# TODO: keep the current selection
model = self.gui.get_object("ToolShapeList") model = self.gui.get_object("ToolShapeList")
model.clear() model.clear()
shapes = list(self.core.get("get_parameter_sets")("tool").values()) shapes = self.core.get("get_parameter_sets")("tool").values()
shapes.sort(key=lambda item: item["weight"]) shapes.sort(key=lambda item: item["weight"])
for shape in shapes: for shape in shapes:
model.append((shape["label"], shape["name"])) model.append((shape["label"], shape["name"]))
...@@ -219,6 +216,11 @@ class Tools(pycam.Plugins.ListPluginBase): ...@@ -219,6 +216,11 @@ class Tools(pycam.Plugins.ListPluginBase):
self.pop(index) self.pop(index)
# show "new" only if a strategy is available # show "new" only if a strategy is available
self.gui.get_object("ToolNew").set_sensitive(len(model) > 0) self.gui.get_object("ToolNew").set_sensitive(len(model) > 0)
selector_box = self.gui.get_object("ToolSelectorBox")
if len(model) < 2:
selector_box.hide()
else:
selector_box.show()
def _store_tool_settings(self): def _store_tool_settings(self):
tool = self.get_selected() tool = self.get_selected()
...@@ -233,13 +235,13 @@ class Tools(pycam.Plugins.ListPluginBase): ...@@ -233,13 +235,13 @@ class Tools(pycam.Plugins.ListPluginBase):
control_box.show() control_box.show()
self._trigger_table_update() self._trigger_table_update()
def _tool_change(self, widget=None, data=None): def _tool_switch(self, widget=None, data=None):
tool = self.get_selected() tool = self.get_selected()
control_box = self.gui.get_object("ToolSettingsControlsBox") control_box = self.gui.get_object("ToolSettingsControlsBox")
if not tool: if not tool:
control_box.hide() control_box.hide()
else: else:
self.core.block_event("tool-parameter-changed") self.core.block_event("tool-changed")
self.core.block_event("tool-shape-changed") self.core.block_event("tool-shape-changed")
shape_name = tool["shape"] shape_name = tool["shape"]
self.select_shape(shape_name) self.select_shape(shape_name)
...@@ -247,7 +249,7 @@ class Tools(pycam.Plugins.ListPluginBase): ...@@ -247,7 +249,7 @@ class Tools(pycam.Plugins.ListPluginBase):
self.core.get("set_parameter_values")("tool", tool["parameters"]) self.core.get("set_parameter_values")("tool", tool["parameters"])
control_box.show() control_box.show()
self.core.unblock_event("tool-shape-changed") self.core.unblock_event("tool-shape-changed")
self.core.unblock_event("tool-parameter-changed") self.core.unblock_event("tool-changed")
# trigger a widget update # trigger a widget update
self.core.emit_event("tool-shape-changed") self.core.emit_event("tool-shape-changed")
...@@ -260,3 +262,4 @@ class Tools(pycam.Plugins.ListPluginBase): ...@@ -260,3 +262,4 @@ class Tools(pycam.Plugins.ListPluginBase):
} }
self.append(new_tool) self.append(new_tool)
self.select(new_tool) self.select(new_tool)
...@@ -405,7 +405,7 @@ class ListPluginBase(PluginBase, list): ...@@ -405,7 +405,7 @@ class ListPluginBase(PluginBase, list):
# TODO: "self.treemodel" should not be used here # TODO: "self.treemodel" should not be used here
model = self._treemodel model = self._treemodel
if id_col is None: if id_col is None:
id_col = self.COLUMN_ID id_col = self.COLUMN_REF
if attr in self.LIST_ATTRIBUTE_MAP: if attr in self.LIST_ATTRIBUTE_MAP:
col = self.LIST_ATTRIBUTE_MAP[attr] col = self.LIST_ATTRIBUTE_MAP[attr]
for index in range(len(model)): for index in range(len(model)):
......
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