Commit 2fe7f67e authored by sumpfralle's avatar sumpfralle

added visualization for visible/invisible models in list

* icons based on http://www.openclipart.org/detail/67411/occhio-01 by emilie.rollandin (Public Domain)


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1106 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 5fd1649b
...@@ -25,14 +25,13 @@ ...@@ -25,14 +25,13 @@
<property name="model">ModelList</property> <property name="model">ModelList</property>
<property name="headers_visible">False</property> <property name="headers_visible">False</property>
<child> <child>
<object class="GtkTreeViewColumn" id="treeviewcolumn1"> <object class="GtkTreeViewColumn" id="ModelVisibleColumn">
<property name="title">column</property> <property name="title">column</property>
<property name="clickable">True</property> <property name="clickable">True</property>
<child> <child>
<object class="GtkCellRendererToggle" id="ModelVisibleToggle"/> <object class="GtkCellRendererPixbuf" id="ModelVisibleSymbol">
<attributes> <property name="stock_size">2</property>
<attribute name="active">2</attribute> </object>
</attributes>
</child> </child>
</object> </object>
</child> </child>
...@@ -40,7 +39,9 @@ ...@@ -40,7 +39,9 @@
<object class="GtkTreeViewColumn" id="treeviewcolumn2"> <object class="GtkTreeViewColumn" id="treeviewcolumn2">
<property name="title">column</property> <property name="title">column</property>
<child> <child>
<object class="GtkCellRendererText" id="cellrenderertext1"/> <object class="GtkCellRendererText" id="ModelNameColumn">
<property name="editable">True</property>
</object>
<attributes> <attributes>
<attribute name="text">1</attribute> <attribute name="text">1</attribute>
</attributes> </attributes>
......
This diff is collapsed.
This diff is collapsed.
...@@ -29,11 +29,13 @@ import pycam.Plugins ...@@ -29,11 +29,13 @@ import pycam.Plugins
class Models(pycam.Plugins.ListPluginBase): class Models(pycam.Plugins.ListPluginBase):
UI_FILE = "models.ui" UI_FILE = "models.ui"
COLUMN_VISIBLE = 2 COLUMN_ID, COLUMN_NAME, COLUMN_VISIBLE = range(3)
ICONS = {"visible": "visible.svg", "hidden": "visible_off.svg"}
def setup(self): def setup(self):
if self.gui: if self.gui:
import gtk import gtk
self._gtk = gtk
model_frame = self.gui.get_object("ModelBox") model_frame = self.gui.get_object("ModelBox")
model_frame.unparent() model_frame.unparent()
self.core.register_ui("main", "Models", model_frame, -50) self.core.register_ui("main", "Models", model_frame, -50)
...@@ -42,7 +44,7 @@ class Models(pycam.Plugins.ListPluginBase): ...@@ -42,7 +44,7 @@ class Models(pycam.Plugins.ListPluginBase):
for index in range(model_handling_obj.get_n_pages()): for index in range(model_handling_obj.get_n_pages()):
model_handling_obj.remove_page(0) model_handling_obj.remove_page(0)
def add_model_handling_item(item, name): def add_model_handling_item(item, name):
model_handling_obj.append_page(item, gtk.Label(name)) model_handling_obj.append_page(item, self._gtk.Label(name))
self.core.register_ui_section("model_handling", self.core.register_ui_section("model_handling",
add_model_handling_item, clear_model_handling_obj) add_model_handling_item, clear_model_handling_obj)
self._modelview = self.gui.get_object("ModelView") self._modelview = self.gui.get_object("ModelView")
...@@ -52,8 +54,13 @@ class Models(pycam.Plugins.ListPluginBase): ...@@ -52,8 +54,13 @@ 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("ModelVisibleToggle").connect("toggled", self._modelview.connect("row-activated",
self._list_action_toggle, self.COLUMN_VISIBLE) self._list_action_toggle_custom, self.COLUMN_VISIBLE)
self.gui.get_object("ModelVisibleColumn").set_cell_data_func(
self.gui.get_object("ModelVisibleSymbol"),
self._visualize_visible_state)
self.gui.get_object("ModelNameColumn").connect("edited",
self._edit_model_name)
self._treemodel = self.gui.get_object("ModelList") self._treemodel = self.gui.get_object("ModelList")
self._treemodel.clear() self._treemodel.clear()
def update_model(): def update_model():
...@@ -72,6 +79,26 @@ class Models(pycam.Plugins.ListPluginBase): ...@@ -72,6 +79,26 @@ class Models(pycam.Plugins.ListPluginBase):
self.core.add_item("models", lambda: self) self.core.add_item("models", lambda: self)
return True return True
def _edit_model_name(self, cell, path, new_text):
path = int(path)
if new_text != self._treemodel[path][self.COLUMN_NAME]:
self._treemodel[path][self.COLUMN_NAME] = new_text
def _visualize_visible_state(self, column, cell, model, m_iter):
visible = model.get_value(m_iter, self.COLUMN_VISIBLE)
if visible:
cell.set_property("pixbuf", self.ICONS["visible"])
else:
cell.set_property("pixbuf", self.ICONS["hidden"])
def _list_action_toggle_custom(self, treeview, path, clicked_column,
force_column=None):
if force_column is None:
column = self._modelview.get_columns().index(clicked_column)
else:
column = force_column
self._list_action_toggle(clicked_column, str(path[0]), column)
def _list_action_toggle(self, widget, path, column): def _list_action_toggle(self, widget, path, column):
path = int(path) path = int(path)
model = self._treemodel model = self._treemodel
......
...@@ -23,7 +23,9 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -23,7 +23,9 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
import os import os
import imp import imp
import inspect import inspect
# TODO: load these modules only on demand
import gtk import gtk
import gobject
import pycam.Utils.log import pycam.Utils.log
import pycam.Utils.locations import pycam.Utils.locations
...@@ -36,6 +38,8 @@ class PluginBase(object): ...@@ -36,6 +38,8 @@ class PluginBase(object):
UI_FILE = None UI_FILE = None
DEPENDS = [] DEPENDS = []
ICONS = {}
ICON_SIZE = 23
def __init__(self, core, name): def __init__(self, core, name):
self.enabled = True self.enabled = True
...@@ -52,6 +56,20 @@ class PluginBase(object): ...@@ -52,6 +56,20 @@ class PluginBase(object):
self.gui.add_from_file(gtk_build_file) self.gui.add_from_file(gtk_build_file)
except RuntimeError: except RuntimeError:
self.gui = None self.gui = None
for key in self.ICONS:
icon_location = pycam.Utils.locations.get_ui_file_location(
self.ICONS[key])
if icon_location:
try:
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(
icon_location, self.ICON_SIZE, self.ICON_SIZE)
except gobject.GError:
self.ICONS[key] = None
else:
self.ICONS[key] = pixbuf
else:
self.log.debug("Failed to locate icon: %s" % self.ICONS[key])
self.ICONS[key] = None
def setup(self): def setup(self):
raise NotImplementedError(("Module %s (%s) does not implement " + \ raise NotImplementedError(("Module %s (%s) does not implement " + \
......
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