Commit 7ed99e24 authored by sumpfralle's avatar sumpfralle

finished cleanup of gtk widget signal handling


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1173 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 1193c3dd
......@@ -154,6 +154,8 @@ class Bounds(pycam.Plugins.ListPluginBase):
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
self.core.set("bounds", None)
while len(self) > 0:
self.pop()
def get_selected(self, index=False):
return self._get_selected(self._boundsview, index=index)
......@@ -194,7 +196,11 @@ class Bounds(pycam.Plugins.ListPluginBase):
model_ids = [id(m) for m in all_models]
if model_id in model_ids:
this_model = all_models[model_ids.index(model_id)]
cell.set_property("text", all_models.get_attr(this_model, "name"))
try:
label = all_models.get_attr(this_model, "name")
except IndexError:
label = ""
cell.set_property("text", label)
def _render_bounds_size(self, column, cell, model, m_iter):
path = model.get_path(m_iter)
......@@ -225,6 +231,16 @@ class Bounds(pycam.Plugins.ListPluginBase):
model_list.remove(index_iter)
if len(model_list) <= index:
model_list.append((model_id,))
# remove missing models from all bounds
for bounds in self:
removal_list = []
for index, model in enumerate(bounds["Models"]):
if not model in self.core.get("models"):
removal_list.append(index)
removal_list.reverse()
for index in removal_list:
bounds["Models"].pop(index)
print "Removed model %d" % index
def _store_bounds_settings(self, widget=None):
data = self.get_selected()
......
......@@ -113,6 +113,8 @@ class Models(pycam.Plugins.ListPluginBase):
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
self.core.set("models", None)
while len(self) > 0:
self.pop()
return True
def _get_colors_of_selected_models(self, widget=None):
......
......@@ -43,10 +43,16 @@ class ParallelProcessing(pycam.Plugins.PluginBase):
# "process pool" window
self.process_pool_window = self.gui.get_object("ProcessPoolWindow")
self.process_pool_window.set_default_size(500, 400)
self.process_pool_window.connect("delete-event", self.toggle_process_pool_window, False)
self.process_pool_window.connect("destroy", self.toggle_process_pool_window, False)
self._gtk_handlers = []
self._gtk_handlers.extend((
(self.process_pool_window, "delete-event",
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.gui.get_object("ProcessPoolWindowClose").connect("clicked", self.toggle_process_pool_window, False)
self._gtk_handlers.append((
self.gui.get_object("ProcessPoolWindowClose"), "clicked",
self.toggle_process_pool_window, False))
self.gui.get_object("ProcessPoolRefreshInterval").set_value(3)
self.process_pool_model = self.gui.get_object("ProcessPoolStatisticsModel")
# show/hide controls
......@@ -63,22 +69,23 @@ class ParallelProcessing(pycam.Plugins.PluginBase):
self.gui.get_object("EnableParallelProcesses").hide()
self.enable_parallel_processes.set_active(
pycam.Utils.threading.is_multiprocessing_enabled())
self.enable_parallel_processes.connect("toggled",
self.handle_parallel_processes_settings)
self._gtk_handlers.append((self.enable_parallel_processes,
"toggled", self.handle_parallel_processes_settings))
self.number_of_processes = self.gui.get_object(
"NumberOfProcesses")
self.number_of_processes.set_value(
pycam.Utils.threading.get_number_of_processes())
server_port_local_obj = self.gui.get_object("ServerPortLocal")
server_port_remote_obj = self.gui.get_object("RemoteServerPort")
self.number_of_processes.connect("value-changed",
self.handle_parallel_processes_settings)
self.gui.get_object("EnableServerMode").connect("toggled",
self.initialize_multiprocessing)
self.gui.get_object("ServerPasswordGenerate").connect("clicked",
self.generate_random_server_password)
self.gui.get_object("ServerPasswordShow").connect("toggled",
self.update_parallel_processes_settings)
self._gtk_handlers.extend((
(self.number_of_processes, "value-changed",
self.handle_parallel_processes_settings),
(self.gui.get_object("EnableServerMode"), "toggled",
self.initialize_multiprocessing),
(self.gui.get_object("ServerPasswordGenerate"), "clicked",
self.generate_random_server_password),
(self.gui.get_object("ServerPasswordShow"), "toggled",
self.update_parallel_processes_settings)))
auth_key_obj = self.gui.get_object("ServerPassword")
server_hostname = self.gui.get_object("RemoteServerHostname")
cpu_cores = pycam.Utils.threading.get_number_of_cores()
......@@ -86,11 +93,13 @@ class ParallelProcessing(pycam.Plugins.PluginBase):
cpu_cores = "unknown"
self.gui.get_object("AvailableCores").set_label(str(cpu_cores))
toggle_button = self.gui.get_object("ToggleProcessPoolWindow")
toggle_button.connect("toggled", self.toggle_process_pool_window)
self._gtk_handlers.append((toggle_button, "toggled",
self.toggle_process_pool_window))
self.register_gtk_accelerator("processes", toggle_button,
None, "ToggleProcessPoolWindow")
self.core.register_ui("view_menu", "ToggleProcessPoolWindow",
toggle_button, 40)
self.register_gtk_handlers(self._gtk_handlers)
return True
def teardown(self):
......@@ -101,6 +110,7 @@ class ParallelProcessing(pycam.Plugins.PluginBase):
toggle_button = self.gui.get_object("ToggleProcessPoolWindow")
self.core.unregister_ui("view_menu", toggle_button)
self.unregister_gtk_accelerator("processes", toggle_button)
self.unregister_gtk_handlers(self._gtk_handlers)
def toggle_process_pool_window(self, widget=None, value=None, action=None):
toggle_process_pool_checkbox = self.gui.get_object("ToggleProcessPoolWindow")
......
......@@ -160,7 +160,8 @@ class PathParamTraceModel(pycam.Plugins.PluginBase):
models_dict[id(model)] = model
models = []
for model_ref in model_refs:
models.append(models_dict[model_ref])
if model_ref in models_dict:
models.append(models_dict[model_ref])
return models
def set_converter(models):
return [id(model) for model in models]
......
......@@ -38,32 +38,38 @@ class PluginSelector(pycam.Plugins.PluginBase):
if self.gui:
import gtk
self.plugin_window = self.gui.get_object("PluginManagerWindow")
self.plugin_window.connect("delete-event",
self.toggle_plugin_window, False)
self.plugin_window.connect("destroy",
self.toggle_plugin_window, False)
self._gtk_handlers = []
self._gtk_handlers.extend((
(self.plugin_window, "delete-event",
self.toggle_plugin_window, False),
(self.plugin_window, "destroy",
self.toggle_plugin_window, False)))
self.plugin_window.add_accel_group(
self.core.get("gtk-accel-group"))
self.gui.get_object("ClosePluginManager").connect("clicked",
self.toggle_plugin_window, False)
self._gtk_handlers.append((
self.gui.get_object("ClosePluginManager"), "clicked",
self.toggle_plugin_window, False))
self._treemodel = self.gui.get_object("PluginsModel")
self._treemodel.clear()
action = self.gui.get_object("TogglePluginWindow")
action.connect("toggled", self.toggle_plugin_window)
self._gtk_handlers.append((action, "toggled",
self.toggle_plugin_window))
self.register_gtk_accelerator("plugins", action, None,
"TogglePluginWindow")
self.core.register_ui("view_menu", "TogglePluginWindow", action, 60)
# model filters
model_filter = self.gui.get_object("PluginsModel").filter_new()
for obj_name in ("StatusFilter", "CategoryFilter"):
self.gui.get_object(obj_name).connect("changed",
lambda widget: model_filter.refilter())
self._gtk_handlers.append((self.gui.get_object(obj_name),
"changed", lambda widget: model_filter.refilter()))
self.gui.get_object("PluginsTable").set_model(model_filter)
model_filter.set_visible_func(self._filter_set_visible)
self.gui.get_object("PluginsEnabledCell").connect("toggled",
self.toggle_plugin_state)
self._gtk_handlers.append((
self.gui.get_object("PluginsEnabledCell"), "toggled",
self.toggle_plugin_state))
self.core.register_event("plugin-list-changed",
self._update_plugin_model)
self.register_gtk_handlers(self._gtk_handlers)
self._update_plugin_model()
return True
......@@ -74,6 +80,7 @@ class PluginSelector(pycam.Plugins.PluginBase):
self.core.register_ui("view_menu", action)
self.core.unregister_event("plugin-list-changed",
self._update_plugin_model)
self.unregister_gtk_handlers(self._gtk_handlers)
def toggle_plugin_window(self, widget=None, value=None, action=None):
toggle_plugin_button = self.gui.get_object("TogglePluginWindow")
......
......@@ -37,6 +37,7 @@ class Processes(pycam.Plugins.ListPluginBase):
self._gtk = gtk
process_frame = self.gui.get_object("ProcessBox")
process_frame.unparent()
self._gtk_handlers = []
self.core.register_ui("main", "Processs", process_frame, weight=20)
self._modelview = self.gui.get_object("ProcessEditorTable")
for action, obj_name in ((self.ACTION_UP, "ProcessMoveUp"),
......@@ -44,8 +45,8 @@ class Processes(pycam.Plugins.ListPluginBase):
(self.ACTION_DELETE, "ProcessDelete")):
self.register_list_action_button(action, self._modelview,
self.gui.get_object(obj_name))
self.gui.get_object("ProcessNew").connect("clicked",
self._process_new)
self._gtk_handlers.append((self.gui.get_object("ProcessNew"),
"clicked", self._process_new))
# parameters
parameters_box = self.gui.get_object("ProcessParametersBox")
def clear_parameter_widgets():
......@@ -77,8 +78,8 @@ class Processes(pycam.Plugins.ListPluginBase):
selection.connect("changed",
lambda widget, event: self.core.emit_event(event),
"process-selection-changed")
self.gui.get_object("NameCell").connect("edited",
self._edit_process_name)
self._gtk_handlers.append((self.gui.get_object("NameCell"),
"edited", self._edit_process_name))
self._treemodel = self.gui.get_object("ProcessList")
self._treemodel.clear()
def update_model():
......@@ -93,29 +94,27 @@ class Processes(pycam.Plugins.ListPluginBase):
cache[id(item)] = [id(item), "Process #%d" % index]
self._treemodel.append(cache[id(item)])
self.core.emit_event("process-list-changed")
strategy_selector = self.gui.get_object("StrategySelector")
strategy_selector.connect("changed", lambda widget: \
self.core.emit_event("process-strategy-changed"))
self.core.register_event("process-strategy-list-changed",
self._update_widgets)
self._gtk_handlers.append((self.gui.get_object("StrategySelector"),
"changed", "process-strategy-changed"))
self.register_model_update(update_model)
self.core.register_event("process-selection-changed",
self._process_switch)
self.core.register_event("process-changed",
self._store_process_settings)
self.core.register_event("process-strategy-changed",
self._store_process_settings)
self._event_handlers = (
("process-strategy-list-changed", self._update_widgets),
("process-selection-changed", self._process_switch),
("process-changed", self._store_process_settings),
("process-strategy-changed", self._store_process_settings))
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self.core.set("processes", self)
return True
def teardown(self):
if self.gui:
self.core.unregister_ui("main", self.gui.get_object("ProcessBox"))
self.core.unregister_event("process-selection-changed",
self._process_switch)
self.core.unregister_event("process-changed",
self._store_process_settings)
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
self.core.set("processes", None)
while len(self) > 0:
self.pop()
return True
def get_selected(self, index=False):
......
......@@ -87,6 +87,7 @@ class TaskParamTool(pycam.Plugins.PluginBase):
def teardown(self):
self.core.get("unregister_parameter")("task", "components", "tool")
self.core.unregister_event("tool-list-changed", self._update_tools)
def _update_tools(self):
choices = []
......@@ -115,6 +116,7 @@ class TaskParamProcess(pycam.Plugins.PluginBase):
def teardown(self):
self.core.get("unregister_parameter")("task", "components", "process")
self.core.unregister_event("process-list-changed", self._update_processes)
def _update_processes(self):
choices = []
......@@ -143,6 +145,7 @@ class TaskParamBounds(pycam.Plugins.PluginBase):
def teardown(self):
self.core.get("unregister_parameter")("task", "components", "bounds")
self.core.unregister_event("bounds-list-changed", self._update_bounds)
def _update_bounds(self):
choices = []
......
......@@ -39,6 +39,7 @@ class Tasks(pycam.Plugins.ListPluginBase):
if self.gui:
import gtk
self._gtk = gtk
self._gtk_handlers = []
task_frame = self.gui.get_object("TaskBox")
task_frame.unparent()
self.core.register_ui("main", "Tasks", task_frame, weight=40)
......@@ -48,8 +49,8 @@ class Tasks(pycam.Plugins.ListPluginBase):
(self.ACTION_DELETE, "TaskDelete")):
self.register_list_action_button(action, self._taskview,
self.gui.get_object(obj_name))
self.gui.get_object("TaskNew").connect("clicked",
self._task_new)
self._gtk_handlers.append((self.gui.get_object("TaskNew"),
"clicked", self._task_new))
# parameters
parameters_box = self.gui.get_object("TaskParameterBox")
def clear_parameter_widgets():
......@@ -82,20 +83,20 @@ class Tasks(pycam.Plugins.ListPluginBase):
self.core.register_ui("task_parameters", "Components",
self.components_parameter_widget, weight=10)
# table
self.gui.get_object("TaskNameCell").connect("edited",
self._edit_task_name)
self._gtk_handlers.append((self.gui.get_object("TaskNameCell"),
"edited", self._edit_task_name))
selection = self._taskview.get_selection()
selection.connect("changed",
lambda widget, event: self.core.emit_event(event),
"task-selection-changed")
self._gtk_handlers.append((selection, "changed",
"task-selection-changed"))
selection.set_mode(self._gtk.SELECTION_MULTIPLE)
self._treemodel = self.gui.get_object("TaskList")
self._treemodel.clear()
# generate toolpaths
self.gui.get_object("GenerateToolPathButton").connect("clicked",
self._generate_selected_toolpaths)
self.gui.get_object("GenerateAllToolPathsButton").connect("clicked",
self._generate_all_toolpaths)
self._gtk_handlers.extend((
(self.gui.get_object("GenerateToolPathButton"), "clicked",
self._generate_selected_toolpaths),
(self.gui.get_object("GenerateAllToolPathsButton"), "clicked",
self._generate_all_toolpaths)))
# manage the treemodel
def update_model():
if not hasattr(self, "_model_cache"):
......@@ -111,16 +112,16 @@ class Tasks(pycam.Plugins.ListPluginBase):
self._treemodel.append((id(item), "Task #%d" % index))
self.core.emit_event("task-list-changed")
# shape selector
type_selector = self.gui.get_object("TaskTypeSelector")
type_selector.connect("changed", lambda widget: \
self.core.emit_event("task-type-changed"))
self.core.register_event("task-type-list-changed",
self._update_widgets)
self.core.register_event("task-selection-changed",
self._task_switch)
self.core.register_event("task-changed", self._store_task)
self.core.register_event("task-type-changed", self._store_task)
self._gtk_handlers.append((self.gui.get_object("TaskTypeSelector"),
"changed", "task-type-changed"))
self._event_handlers = (
("task-type-list-changed", self._update_widgets),
("task-selection-changed", self._task_switch),
("task-changed", self._store_task),
("task-type-changed", self._store_task))
self.register_model_update(update_model)
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self._update_widgets()
self._task_switch()
self.core.set("tasks", self)
......@@ -129,16 +130,14 @@ class Tasks(pycam.Plugins.ListPluginBase):
def teardown(self):
if self.gui:
self.core.unregister_ui("main", self.gui.get_object("TaskBox"))
self.core.unregister_event("task-type-list-changed",
self._update_widgets)
self.core.unregister_event("task-selection-changed",
self._task_switch)
self.core.unregister_event("task-changed", self._store_task)
self.core.unregister_event("task-type-changed", self._store_task)
self.core.unregister_ui("task_parameters",
self.models_parameter_widget)
self.core.unregister_ui("task_parameters",
self.components_parameter_widget)
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
while len(self) > 0:
self.pop()
def get_selected(self, index=False):
return self._get_selected(self._taskview, index=index)
......
......@@ -38,12 +38,14 @@ class ToolpathCrop(pycam.Plugins.PluginBase):
self._frame = self.gui.get_object("ToolpathCropFrame")
self.core.register_ui("toolpath_handling", "Crop",
self._frame, 40)
self._gtk_handlers = []
for objname in ("ToolpathCropZSlice", "ToolpathCropMargin"):
obj = self.gui.get_object(objname)
obj.set_value(0)
obj.connect("value-changed", self._update_widgets)
self.gui.get_object("CropButton").connect("clicked",
self.crop_toolpath)
self._gtk_handlers.append((obj, "value-changed",
self._update_widgets))
self._gtk_handlers.append((self.gui.get_object("CropButton"),
"clicked", self.crop_toolpath))
# model selector
self.models_widget = pycam.Gui.ControlsGTK.InputTable([],
force_type=long, change_handler=self._update_widgets)
......@@ -62,10 +64,11 @@ class ToolpathCrop(pycam.Plugins.PluginBase):
get_conv=get_converter)
self.gui.get_object("ModelTableContainer").add(
self.models_widget.get_widget())
self.core.register_event("model-list-changed",
self._update_models_list)
self.core.register_event("toolpath-selection-changed",
self._update_visibility)
self._event_handlers = (
("model-list-changed", self._update_models_list),
("toolpath-selection-changed", self._update_visibility))
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self._update_widgets()
self._update_visibility()
return True
......@@ -75,10 +78,8 @@ class ToolpathCrop(pycam.Plugins.PluginBase):
self.gui.get_object("ModelTableContainer").remove(
self.models_widget.get_widget())
self.core.unregister_ui("toolpath_handling", self._frame)
self.core.unregister_event("model-list-changed",
self._update_models_list)
self.core.unregister_event("toolpath-selection-changed",
self._update_visibility)
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
def _update_models_list(self):
choices = []
......
......@@ -51,20 +51,20 @@ class ToolpathExport(pycam.Plugins.PluginBase):
self._postproc_model = self.gui.get_object("PostprocessorList")
self._postproc_selector = self.gui.get_object(
"PostprocessorSelector")
self.gui.get_object("ExportGCodeAll").connect("clicked",
self.export_all)
self.gui.get_object("ExportGCodeSelected").connect("clicked",
self.export_selected)
self.gui.get_object("ExportGCodeVisible").connect("clicked",
self.export_visible)
self.core.register_event("postprocessors-list-changed",
self._update_postprocessors)
self.core.register_event("toolpath-list-changed",
self._update_widgets)
self.core.register_event("toolpath-selection-changed",
self._update_widgets)
self.core.register_event("toolpath-changed",
self._update_widgets)
self._gtk_handlers = (
(self.gui.get_object("ExportGCodeAll"), "clicked",
self.export_all),
(self.gui.get_object("ExportGCodeSelected"), "clicked",
self.export_selected),
(self.gui.get_object("ExportGCodeVisible"), "clicked",
self.export_visible))
self._event_handlers = (
("postprocessors-list-changed", self._update_postprocessors),
("toolpath-list-changed", self._update_widgets),
("toolpath-selection-changed", self._update_widgets),
("toolpath-changed", self._update_widgets))
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self._update_postprocessors()
self._update_widgets()
return True
......@@ -72,14 +72,8 @@ class ToolpathExport(pycam.Plugins.PluginBase):
def teardown(self):
if self.gui:
self.core.unregister_ui("toolpath_handling", self._frame)
self.core.unregister_event("postprocessors-list-changed",
self._update_postprocessors)
self.core.unregister_event("toolpath-list-changed",
self._update_widgets)
self.core.unregister_event("toolpath-selection-changed",
self._update_widgets)
self.core.unregister_event("toolpath-changed",
self._update_widgets)
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
def register_postprocessor(self, name, label, func):
if name in self._postprocessors:
......
......@@ -33,6 +33,7 @@ class ToolpathGrid(pycam.Plugins.PluginBase):
def setup(self):
if self.gui:
self._gtk_handlers = []
self._frame = self.gui.get_object("ToolpathGridFrame")
self.core.register_ui("toolpath_handling", "Clone grid",
self._frame, 30)
......@@ -40,21 +41,22 @@ class ToolpathGrid(pycam.Plugins.PluginBase):
self.gui.get_object(objname).set_value(1)
for objname in ("GridYCount", "GridXCount", "GridYDistance",
"GridXDistance"):
self.gui.get_object(objname).connect("value-changed",
self._update_widgets)
self.gui.get_object("GridCreate").connect("clicked",
self.create_toolpath_grid)
self._gtk_handlers.append((self.gui.get_object(objname),
"value-changed", self._update_widgets))
self._gtk_handlers.append((self.gui.get_object("GridCreate"),
"clicked", self.create_toolpath_grid))
self.core.register_event("toolpath-selection-changed",
self._update_widgets)
self.register_gtk_handlers(self._gtk_handlers)
self._update_widgets()
return True
def teardown(self):
if self.gui:
self.core.unregister_ui("toolpath_handling", self._frame)
self.unregister_gtk_handlers(self._gtk_handlers)
self.core.unregister_event("toolpath-selection-changed",
self._update_widgets)
pass
def _get_toolpaths_dim(self, toolpaths):
if toolpaths:
......
......@@ -20,6 +20,7 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import math
import pycam.Plugins
# this requires ODE - we import it later, if necessary
......@@ -33,6 +34,7 @@ class ToolpathSimulation(pycam.Plugins.PluginBase):
def setup(self):
if self.gui:
self._gtk_handlers = []
speed_factor_widget = self.gui.get_object("SimulationSpeedFactor")
self.core.add_item("simulation_speed_factor",
lambda: pow(10, speed_factor_widget.get_value()),
......@@ -48,21 +50,27 @@ class ToolpathSimulation(pycam.Plugins.PluginBase):
complete = self.core.get("simulation_complete_distance")
partial = widget.get_value() / 100.0 * complete
self.core.set("simulation_current_distance", partial)
simulation_progress.connect("value-changed", update_simulation_progress)
self._gtk_handlers.append((simulation_progress, "value-changed",
update_simulation_progress))
# update the speed factor label
speed_factor_widget.connect("value-changed", lambda widget: \
self.gui.get_object("SimulationSpeedFactorValueLabel").\
set_label("%.2f" % self.core.get("simulation_speed_factor")))
self._gtk_handlers.append((speed_factor_widget, "value-changed",
lambda widget: self.gui.get_object(
"SimulationSpeedFactorValueLabel").set_label("%.2f" % \
self.core.get("simulation_speed_factor"))))
self.simulation_window = self.gui.get_object("SimulationDialog")
self.simulation_window.connect("delete-event",
self.finish_toolpath_simulation)
self._gtk_handlers.append((self.simulation_window, "delete-event",
self.finish_toolpath_simulation))
sim_detail_obj = self.gui.get_object("SimulationDetailsValue")
self.core.add_item("simulation_details_level",
sim_detail_obj.get_value, sim_detail_obj.set_value)
self.register_gtk_handlers(self._gtk_handlers)
return True
def teardown(self):
pass
if self.gui:
for name in ("simulation_speed_factor", "simulation_details_level"):
self.core.add_item(name, None, lambda value: None)
self.unregister_gtk_handlers(self._gtk_handlers)
def finish_toolpath_simulation(self, widget=None, data=None):
# hide the simulation tab
......
......@@ -38,6 +38,7 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
self.tp_box = self.gui.get_object("ToolpathsBox")
self.tp_box.unparent()
self.core.register_ui("main", "Toolpaths", self.tp_box, weight=50)
self._gtk_handlers = []
self._modelview = self.gui.get_object("ToolpathTable")
self._treemodel = self.gui.get_object("ToolpathListModel")
self._treemodel.clear()
......@@ -58,20 +59,19 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
self.core.register_ui_section("toolpath_handling",
add_toolpath_handling_item, clear_toolpath_handling_obj)
# handle table changes
self._modelview.connect("row-activated",
self._list_action_toggle_custom, self.COLUMN_VISIBLE)
self._modelview.connect("row-activated",
lambda *args: self.core.emit_event("toolpath-changed"))
self._gtk_handlers.extend((
(self._modelview, "row-activated",
self._list_action_toggle_custom, self.COLUMN_VISIBLE),
(self._modelview, "row-activated", "toolpath-changed"),
(self.gui.get_object("ToolpathNameCell"), "edited",
self._edit_toolpath_name)))
self.gui.get_object("ToolpathVisibleColumn").set_cell_data_func(
self.gui.get_object("ToolpathVisibleSymbol"),
self._visualize_visible_state)
self.gui.get_object("ToolpathNameCell").connect("edited",
self._edit_toolpath_name)
# handle selection changes
selection = self._modelview.get_selection()
selection.connect("changed",
lambda widget, event: self.core.emit_event(event),
"toolpath-selection-changed")
self._gtk_handlers.append((selection, "changed",
"toolpath-selection-changed"))
selection.set_mode(gtk.SELECTION_MULTIPLE)
# model handling
def update_model():
......@@ -89,14 +89,13 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
"Toolpath #%d" % index, True))
self.core.emit_event("toolpath-list-changed")
self.register_model_update(update_model)
self.core.register_event("toolpath-changed",
self._update_widgets)
self.core.register_event("toolpath-list-changed",
self._update_widgets)
self.core.register_event("toolpath-changed",
lambda: self.core.emit_event("visual-item-updated"))
self.core.register_event("toolpath-list-changed",
lambda: self.core.emit_event("visual-item-updated"))
self._event_handlers = (
("toolpath-changed", self._update_widgets),
("toolpath-list-changed", self._update_widgets),
("toolpath-changed", "visual-item-updated"),
("toolpath-list-changed", "visual-item-updated"))
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self._trigger_toolpath_time_update()
self._update_widgets()
self.core.set("toolpaths", self)
......@@ -105,10 +104,8 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
def teardown(self):
if self.gui:
self.core.unregister_ui("main", self.gui.get_object("ToolpathsBox"))
self.core.unregister_event("toolpath-changed",
self._update_widgets)
self.core.unregister_event("toolpath-list-changed",
self._update_widgets)
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
self.core.set("toolpaths", None)
def get_selected(self):
......
......@@ -40,6 +40,7 @@ class Tools(pycam.Plugins.ListPluginBase):
tool_frame = self.gui.get_object("ToolBox")
tool_frame.unparent()
self.core.register_ui("main", "Tools", tool_frame, weight=10)
self._gtk_handlers = []
self.core.register_chain("get_toolpath_information",
self.get_toolpath_information)
self._modelview = self.gui.get_object("ToolEditorTable")
......@@ -48,7 +49,8 @@ class Tools(pycam.Plugins.ListPluginBase):
(self.ACTION_DELETE, "ToolDelete")):
self.register_list_action_button(action, self._modelview,
self.gui.get_object(obj_name))
self.gui.get_object("ToolNew").connect("clicked", self._tool_new)
self._gtk_handlers.append((self.gui.get_object("ToolNew"),
"clicked", self._tool_new))
# parameters
parameters_box = self.gui.get_object("ToolParameterBox")
def clear_parameter_widgets():
......@@ -84,10 +86,10 @@ class Tools(pycam.Plugins.ListPluginBase):
cell = self.gui.get_object("ToolTableShapeCell")
self.gui.get_object("ToolTableShapeColumn").set_cell_data_func(
cell, self._render_tool_shape)
self.gui.get_object("ToolTableIDCell").connect("edited",
self._edit_tool_id)
self.gui.get_object("ToolTableNameCell").connect("edited",
self._edit_tool_name)
self._gtk_handlers.append((self.gui.get_object("ToolTableIDCell"),
"edited", self._edit_tool_id))
self._gtk_handlers.append((self.gui.get_object("ToolTableNameCell"),
"edited", self._edit_tool_name))
self._treemodel = self.gui.get_object("ToolList")
self._treemodel.clear()
def update_model():
......@@ -104,23 +106,20 @@ class Tools(pycam.Plugins.ListPluginBase):
self._treemodel.append(cache[id(item)])
self.core.emit_event("tool-list-changed")
# selector
selection = self._modelview.get_selection()
selection.connect("changed",
lambda widget, event: self.core.emit_event(event),
"tool-selection-changed")
self._gtk_handlers.append((self._modelview.get_selection(),
"changed", "tool-selection-changed"))
# shape selector
shape_selector = self.gui.get_object("ToolShapeSelector")
shape_selector.connect("changed", lambda widget: \
self.core.emit_event("tool-shape-changed"))
self.core.register_event("tool-shape-list-changed",
self._update_widgets)
self.core.register_event("tool-selection-changed",
self._tool_switch)
self.core.register_event("tool-changed",
self._store_tool_settings)
self.core.register_event("tool-shape-changed",
self._store_tool_settings)
self._gtk_handlers.append((
self.gui.get_object("ToolShapeSelector"), "changed",
"tool-shape-changed"))
self._event_handlers = (
("tool-shape-list-changed", self._update_widgets),
("tool-selection-changed", self._tool_switch),
("tool-changed", self._store_tool_settings),
("tool-shape-changed", self._store_tool_settings))
self.register_model_update(update_model)
self.register_gtk_handlers(self._gtk_handlers)
self.register_event_handlers(self._event_handlers)
self._update_widgets()
self._tool_switch()
self.core.set("tools", self)
......@@ -129,11 +128,13 @@ class Tools(pycam.Plugins.ListPluginBase):
def teardown(self):
if self.gui:
self.core.unregister_ui("main", self.gui.get_object("ToolBox"))
self.core.unregister_event("tool-selection-changed",
self._tool_switch)
self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers)
self.core.unregister_chain("get_toolpath_information",
self.get_toolpath_information)
self.core.set("tools", None)
while len(self) > 0:
self.pop()
return True
def get_selected(self, index=False):
......
......@@ -30,33 +30,41 @@ class Units(pycam.Plugins.PluginBase):
def setup(self):
if self.gui:
self._gtk_handlers = []
unit_pref_box = self.gui.get_object("UnitPrefBox")
unit_pref_box.unparent()
self.core.register_ui("preferences_general", "Units",
unit_pref_box, 20)
# unit control (mm/inch)
unit_field = self.gui.get_object("unit_control")
unit_field.connect("changed", self.change_unit_init)
self._gtk_handlers.append((unit_field, "changed",
self.change_unit_init))
def set_unit(text):
unit_field.set_active(0 if text == "mm" else 1)
self._last_unit = text
self.core.add_item("unit", unit_field.get_active_text, set_unit)
# other plugins should use "unit_string" for human readable output
self.core.add_item("unit_string", unit_field.get_active_text)
self.gui.get_object("UnitChangeSelectAll").connect("clicked",
self.change_unit_set_selection, True)
self.gui.get_object("UnitChangeSelectNone").connect("clicked",
self.change_unit_set_selection, False)
self._gtk_handlers.extend((
(self.gui.get_object("UnitChangeSelectAll"), "clicked",
self.change_unit_set_selection, True),
(self.gui.get_object("UnitChangeSelectNone"), "clicked",
self.change_unit_set_selection, False)))
# "unit change" window
self.unit_change_window = self.gui.get_object("UnitChangeDialog")
self.gui.get_object("UnitChangeApply").connect("clicked", self.change_unit_apply)
self.unit_change_window.connect("delete_event", self.change_unit_apply, False)
self._gtk_handlers.extend((
(self.gui.get_object("UnitChangeApply"), "clicked",
self.change_unit_apply),
(self.unit_change_window, "delete_event",
self.change_unit_apply, False)))
self.register_gtk_handlers(self._gtk_handlers)
return True
def teardown(self):
if self.gui:
self.core.unregister_ui("preferences_general",
self.gui.get_object("UnitPrefBox"))
self.unregister_gtk_handlers(self._gtk_handlers)
# TODO: reset setting "unit" back to a default value?
def change_unit_init(self, widget=None):
......
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