Commit e27eba65 authored by sumpfralle's avatar sumpfralle

added a color chooser to the model list


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1109 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent f47cf6a0
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
<object class="GtkCellRendererPixbuf" id="ModelVisibleSymbol"> <object class="GtkCellRendererPixbuf" id="ModelVisibleSymbol">
<property name="stock_size">2</property> <property name="stock_size">2</property>
</object> </object>
<attributes>
<attribute name="cell-background">3</attribute>
</attributes>
</child> </child>
</object> </object>
</child> </child>
...@@ -67,6 +70,7 @@ ...@@ -67,6 +70,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Remove the selected models</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
</object> </object>
<packing> <packing>
...@@ -81,6 +85,7 @@ ...@@ -81,6 +85,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Remove all models</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
</object> </object>
<packing> <packing>
...@@ -89,6 +94,21 @@ ...@@ -89,6 +94,21 @@
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkColorButton" id="ModelColorButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Change the color of the selected models</property>
<property name="use_alpha">True</property>
<property name="color">#000000000000</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
<child> <child>
<object class="GtkButton" id="ModelMoveUp"> <object class="GtkButton" id="ModelMoveUp">
<property name="label">gtk-go-up</property> <property name="label">gtk-go-up</property>
...@@ -100,7 +120,7 @@ ...@@ -100,7 +120,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">2</property> <property name="position">3</property>
</packing> </packing>
</child> </child>
<child> <child>
...@@ -114,7 +134,7 @@ ...@@ -114,7 +134,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">3</property> <property name="position">4</property>
</packing> </packing>
</child> </child>
<child> <child>
...@@ -130,7 +150,7 @@ ...@@ -130,7 +150,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">4</property> <property name="position">5</property>
</packing> </packing>
</child> </child>
</object> </object>
...@@ -167,12 +187,18 @@ ...@@ -167,12 +187,18 @@
<column type="gchararray"/> <column type="gchararray"/>
<!-- column-name state --> <!-- column-name state -->
<column type="gboolean"/> <column type="gboolean"/>
<!-- column-name color -->
<column type="gchararray"/>
<!-- column-name alpha -->
<column type="guint"/>
</columns> </columns>
<data> <data>
<row> <row>
<col id="0">0</col> <col id="0">0</col>
<col id="1" translatable="yes">Model #1</col> <col id="1" translatable="yes">Model #1</col>
<col id="2">False</col> <col id="2">False</col>
<col id="3" translatable="yes">#ffff00000000</col>
<col id="4">0</col>
</row> </row>
</data> </data>
</object> </object>
......
...@@ -25,12 +25,17 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -25,12 +25,17 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
import pycam.Plugins import pycam.Plugins
_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 = range(3) COLUMN_ID, COLUMN_NAME, COLUMN_VISIBLE, COLUMN_COLOR, COLUMN_ALPHA = range(5)
ATTRIBUTE_MAP = {"name": COLUMN_NAME, "visible": COLUMN_VISIBLE,
"color": COLUMN_COLOR, "alpha": COLUMN_ALPHA}
ICONS = {"visible": "visible.svg", "hidden": "visible_off.svg"} ICONS = {"visible": "visible.svg", "hidden": "visible_off.svg"}
DEFAULT_COLOR = (0.5, 0.5, 1.0, 1.0)
def setup(self): def setup(self):
if self.gui: if self.gui:
...@@ -54,6 +59,10 @@ class Models(pycam.Plugins.ListPluginBase): ...@@ -54,6 +59,10 @@ class Models(pycam.Plugins.ListPluginBase):
(self.ACTION_CLEAR, "ModelDeleteAll")): (self.ACTION_CLEAR, "ModelDeleteAll")):
self.register_list_action_button(action, self._modelview, self.register_list_action_button(action, self._modelview,
self.gui.get_object(obj_name)) self.gui.get_object(obj_name))
self.gui.get_object("ModelColorButton").connect("color-set",
self._set_colors_of_selected_models)
self.core.register_event("model-selection-changed",
self._get_colors_of_selected_models)
self._modelview.connect("row-activated", self._modelview.connect("row-activated",
self._list_action_toggle_custom, self.COLUMN_VISIBLE) self._list_action_toggle_custom, self.COLUMN_VISIBLE)
self.gui.get_object("ModelVisibleColumn").set_cell_data_func( self.gui.get_object("ModelVisibleColumn").set_cell_data_func(
...@@ -73,17 +82,65 @@ class Models(pycam.Plugins.ListPluginBase): ...@@ -73,17 +82,65 @@ 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[0]] = list(row) cache[row[self.COLUMN_ID]] = 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:
self._treemodel.append(cache[id(item)]) self._treemodel.append(cache[id(item)])
else: else:
self._treemodel.append((id(item), "Model #%d" % index, True)) color = "#%04x%04x%04x" % tuple([int(col * _GTK_COLOR_MAX)
for col in self.DEFAULT_COLOR[:3]])
self._treemodel.append((id(item), "Model #%d" % index,
True, color,
int(self.DEFAULT_COLOR[3] * _GTK_COLOR_MAX)))
self._get_colors_of_selected_models()
self.register_model_update(update_model) self.register_model_update(update_model)
self.core.add_item("models", lambda: self) self.core.add_item("models", lambda: self)
return True return True
def get_attr(self, model, attr):
return self.__get_set_attr(model, attr, write=False)
def set_attr(self, model, attr, value):
return self.__get_set_attr(model, attr, value=value, write=True)
def __get_set_attr(self, model, attr, value=None, write=True):
if attr in self.ATTRIBUTE_MAP:
col = self.ATTRIBUTE_MAP[attr]
for index in range(len(self)):
if self._treemodel[index][self.COLUMN_ID] == id(model):
if write:
self._treemodel[index][col] = value
return
else:
return self._treemodel[index][col]
raise IndexError("Model not found: %s" % str(model))
else:
raise KeyError("Attribute '%s' is not part of this list: %s" % \
(attr, ", ".join(self.ATTRIBUTE_MAP.keys())))
def _get_colors_of_selected_models(self, widget=None):
color_button = self.gui.get_object("ModelColorButton")
models = self.get_selected()
color_button.set_sensitive(bool(models))
if models:
# use the color of the first model
model = models[0]
color_str = self.get_attr(model, "color")
alpha_val = self.get_attr(model, "alpha")
color_button.set_color(self._gtk.gdk.color_parse(color_str))
color_button.set_alpha(alpha_val)
def _set_colors_of_selected_models(self, widget=None):
color_button = self.gui.get_object("ModelColorButton")
models = self.get_selected()
color_str = color_button.get_color().to_string()
alpha_val = color_button.get_alpha()
for model in models:
self.set_attr(model, "color", color_str)
self.set_attr(model, "alpha", alpha_val)
self.core.emit_event("visual-item-updated")
def _edit_model_name(self, cell, path, new_text): def _edit_model_name(self, cell, path, new_text):
path = int(path) path = int(path)
if new_text != self._treemodel[path][self.COLUMN_NAME]: if new_text != self._treemodel[path][self.COLUMN_NAME]:
......
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