Commit b23b6c91 authored by sumpfralle's avatar sumpfralle

replaced the model box in the bounds settings with ControlsGTK.InputTable...

replaced the model box in the bounds settings with ControlsGTK.InputTable (fixes some minor glitches)
initialize the state of all buttons correctly during registration


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1188 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent bb3f2c9a
...@@ -16,12 +16,6 @@ ...@@ -16,12 +16,6 @@
</row> </row>
</data> </data>
</object> </object>
<object class="GtkListStore" id="BoundsModelsList">
<columns>
<!-- column-name ref_model -->
<column type="gulong"/>
</columns>
</object>
<object class="GtkListStore" id="ToolLimitModeList"> <object class="GtkListStore" id="ToolLimitModeList">
<columns> <columns>
<!-- column-name description --> <!-- column-name description -->
...@@ -754,27 +748,12 @@ ...@@ -754,27 +748,12 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<child> <child>
<object class="GtkViewport" id="viewport2"> <object class="GtkViewport" id="ModelsViewPort">
<property name="visible">True</property> <property name="visible">True</property>
<property name="resize_mode">queue</property> <property name="resize_mode">queue</property>
<property name="shadow_type">etched-out</property> <property name="shadow_type">etched-out</property>
<child> <child>
<object class="GtkTreeView" id="BoundsModelsTable"> <placeholder/>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">BoundsModelsList</property>
<property name="headers_visible">False</property>
<property name="headers_clickable">False</property>
<property name="search_column">0</property>
<child>
<object class="GtkTreeViewColumn" id="ModelDescriptionColumn">
<property name="title">Model</property>
<child>
<object class="GtkCellRendererText" id="ModelNameCell"/>
</child>
</object>
</child>
</object>
</child> </child>
</object> </object>
<packing> <packing>
......
...@@ -57,12 +57,7 @@ class Bounds(pycam.Plugins.ListPluginBase): ...@@ -57,12 +57,7 @@ class Bounds(pycam.Plugins.ListPluginBase):
bounds_box.unparent() bounds_box.unparent()
self.core.register_ui("main", "Bounds", bounds_box, 30) self.core.register_ui("main", "Bounds", bounds_box, 30)
self._boundsview = self.gui.get_object("BoundsEditTable") self._boundsview = self.gui.get_object("BoundsEditTable")
self._modelview = self.gui.get_object("BoundsModelsTable")
model_selection = self._modelview.get_selection()
model_selection.set_mode(gtk.SELECTION_MULTIPLE)
self._gtk_handlers = [] self._gtk_handlers = []
self._gtk_handlers.append((model_selection, "changed",
"bounds-changed"))
self._gtk_handlers.append((self._boundsview.get_selection(), self._gtk_handlers.append((self._boundsview.get_selection(),
"changed", "bounds-selection-changed")) "changed", "bounds-selection-changed"))
self._treemodel = self._boundsview.get_model() self._treemodel = self._boundsview.get_model()
...@@ -87,6 +82,11 @@ class Bounds(pycam.Plugins.ListPluginBase): ...@@ -87,6 +82,11 @@ class Bounds(pycam.Plugins.ListPluginBase):
self.gui.get_object(obj_name)) self.gui.get_object(obj_name))
self._gtk_handlers.append((self.gui.get_object("BoundsNew"), self._gtk_handlers.append((self.gui.get_object("BoundsNew"),
"clicked", self._bounds_new)) "clicked", self._bounds_new))
# model selector
self.models_control = pycam.Gui.ControlsGTK.InputTable([],
change_handler=lambda *args: \
self.core.emit_event("bounds-changed"))
self.gui.get_object("ModelsViewPort").add(self.models_control.get_widget())
# quickly adjust the bounds via buttons # quickly adjust the bounds via buttons
for obj_name in ("MarginIncreaseX", "MarginIncreaseY", for obj_name in ("MarginIncreaseX", "MarginIncreaseY",
"MarginIncreaseZ", "MarginDecreaseX", "MarginDecreaseY", "MarginIncreaseZ", "MarginDecreaseX", "MarginDecreaseY",
...@@ -132,8 +132,6 @@ class Bounds(pycam.Plugins.ListPluginBase): ...@@ -132,8 +132,6 @@ class Bounds(pycam.Plugins.ListPluginBase):
continue continue
self._gtk_handlers.append((self.gui.get_object("NameCell"), self._gtk_handlers.append((self.gui.get_object("NameCell"),
"edited", self._edit_bounds_name)) "edited", self._edit_bounds_name))
self.gui.get_object("ModelDescriptionColumn").set_cell_data_func(
self.gui.get_object("ModelNameCell"), self._render_model_name)
self._event_handlers.extend(( self._event_handlers.extend((
("bounds-selection-changed", self._switch_bounds), ("bounds-selection-changed", self._switch_bounds),
("bounds-changed", self._store_bounds_settings), ("bounds-changed", self._store_bounds_settings),
...@@ -168,39 +166,10 @@ class Bounds(pycam.Plugins.ListPluginBase): ...@@ -168,39 +166,10 @@ class Bounds(pycam.Plugins.ListPluginBase):
selection.select_path((index,)) selection.select_path((index,))
def get_selected_models(self, index=False): def get_selected_models(self, index=False):
return self._get_selected(self._modelview, return self.models_control.get_value()
content=self.core.get("models"), index=index,
force_list=True)
def select_models(self, models): def select_models(self, models):
selection = self._modelview.get_selection() self.models_control.set_value(models)
remaining = models[:]
for index, row in enumerate(self._modelview.get_model()):
model_ids = [id(m) for m in remaining]
path = (index, )
if row[0] in model_ids:
remaining.pop(model_ids.index(row[0]))
if not selection.path_is_selected(path):
selection.select_path(path)
else:
if selection.path_is_selected(path):
selection.unselect_path(path)
# remove all models that are not available anymore
for not_found in remaining:
models.remove(not_found)
def _render_model_name(self, column, cell, model, m_iter):
path = model.get_path(m_iter)
all_models = self.core.get("models")
model_id = model[path[0]][0]
model_ids = [id(m) for m in all_models]
if model_id in model_ids:
this_model = all_models[model_ids.index(model_id)]
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): def _render_bounds_size(self, column, cell, model, m_iter):
path = model.get_path(m_iter) path = model.get_path(m_iter)
...@@ -218,28 +187,12 @@ class Bounds(pycam.Plugins.ListPluginBase): ...@@ -218,28 +187,12 @@ class Bounds(pycam.Plugins.ListPluginBase):
self.gui.get_object("SizeCell"), self._render_bounds_size) self.gui.get_object("SizeCell"), self._render_bounds_size)
def _update_model_list(self): def _update_model_list(self):
model_ids = [id(m) for m in self.core.get("models")] models = self.core.get("models")
model_list = self._modelview.get_model() choices = []
for index, model_id in enumerate(model_ids): for model in models:
while (len(model_list) > index) and \ name = models.get_attr(model, "name")
(model_list[index][0] != model_id): choices.append((name, model))
index_iter = model_list.get_iter((index, )) self.models_control.update_choices(choices)
if model_list[index][0] in model_ids:
# move it to the end of the list
model_list.move_before(index_iter, None)
else:
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)
def _store_bounds_settings(self, widget=None): def _store_bounds_settings(self, widget=None):
data = self.get_selected() data = self.get_selected()
......
...@@ -456,6 +456,8 @@ class ListPluginBase(PluginBase, list): ...@@ -456,6 +456,8 @@ class ListPluginBase(PluginBase, list):
model.connect(signal, self._update_list_action_button_state, model.connect(signal, self._update_list_action_button_state,
modelview, action, button) modelview, action, button)
button.connect("clicked", self._list_action, modelview, action) button.connect("clicked", self._list_action, modelview, action)
# initialize the state of the button
self._update_list_action_button_state(modelview, action, button)
def get_attr(self, item, attr, model=None, id_col=None): def get_attr(self, item, attr, model=None, id_col=None):
return self.__get_set_attr(item, attr, write=False, model=model, id_col=id_col) return self.__get_set_attr(item, attr, write=False, model=model, id_col=id_col)
......
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