Added color icons
authorDmitriy Morozov <dmitriy@mrzv.org>
Sat, 05 Mar 2011 23:06:27 -0800
changeset 6 6ce97bd3e70f
parent 5 b7757ccad2f4
child 7 cbb51ef4dd6d
Added color icons
ViewerItem.py
triangles.py
--- a/ViewerItem.py	Sat Mar 05 22:52:03 2011 -0800
+++ b/ViewerItem.py	Sat Mar 05 23:06:27 2011 -0800
@@ -5,7 +5,7 @@
         super(ViewerItem, self).__init__(name, parent, QtGui.QListWidgetItem.UserType)
 
         r,g,b = color if color else (0,0,0)
-        self.color = QtGui.QColor(r,g,b)
+        self.set_color(QtGui.QColor(r,g,b))
         self.visible = True
         self.setChecked()
 
@@ -22,6 +22,7 @@
     def createMenu(self):
         menu = QtGui.QMenu()
         colorAction = menu.addAction("Color")
+        colorAction.setIcon(self.color_icon())
         colorAction.command = lambda: self.colorCommand()
         return menu
 
@@ -32,6 +33,14 @@
 
     def colorCommand(self):
         color = QtGui.QColorDialog.getColor(self.color)
+        self.set_color(color)
+
+    def color_icon(self):
+        color_pixmap = QtGui.QPixmap(10,10)
+        color_pixmap.fill(self.color)
+        return QtGui.QIcon(color_pixmap)
+
+    def set_color(self, color):
         if color.isValid():
             self.color = color
-
+        self.setIcon(self.color_icon())
--- a/triangles.py	Sat Mar 05 22:52:03 2011 -0800
+++ b/triangles.py	Sat Mar 05 23:06:27 2011 -0800
@@ -9,7 +9,7 @@
 
 class Triangles(ViewerItem):
     def __init__(self, filename, parent = None):
-        super(Triangles, self).__init__(basename(filename), parent, color = (200,0,200))
+        super(Triangles, self).__init__(basename(filename), parent, color = (200,200,200))
 
         self.triangles = []
         lines = []
@@ -31,6 +31,8 @@
     def createMenu(self):
         menu = super(Triangles, self).createMenu()
         wireframeAction = menu.addAction("Wireframe")
+        wireframeAction.setCheckable(True)
+        wireframeAction.setChecked(self.wireframe)
         wireframeAction.command = lambda: self.wireframeCommand()
         return menu