Adding icons on viewers tabs
authorlbessard
Wed, 16 Apr 2008 09:48:06 +0200
changeset 203 76c407fb33fe
parent 202 e219803fdd11
child 204 5eb48c97f6e5
Adding icons on viewers tabs
PLCOpenEditor.py
--- a/PLCOpenEditor.py	Wed Apr 16 09:47:21 2008 +0200
+++ b/PLCOpenEditor.py	Wed Apr 16 09:48:06 2008 +0200
@@ -160,6 +160,22 @@
     "IL"  : []
 }
 
+def GenerateBitmap(icon1_name, icon2_name = None):
+    if icon2_name is None:
+        return wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%icon1_name))
+    else:
+        icon1 = wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%icon1_name))
+        icon2 = wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%icon2_name))
+        width = icon1.GetWidth() + icon2.GetWidth() - 1
+        height = max(icon1.GetHeight(), icon2.GetHeight())
+        tmp_bitmap = wx.EmptyBitmap(width, height)
+        dc = wx.MemoryDC()
+        dc.SelectObject(tmp_bitmap)
+        dc.Clear()
+        dc.DrawBitmap(icon1, 0, 0)
+        dc.DrawBitmap(icon2, icon1.GetWidth() - 1, 0)
+        return tmp_bitmap
+
 def AppendMenu(parent, help, id, kind, text):
     if wx.VERSION >= (2, 6, 0):
         parent.Append(help=help, id=id, kind=kind, text=text)
@@ -610,6 +626,14 @@
         else:
             return self.TabsOpened.SetPageText(idx, text)
 
+    def SetPageBitmap(self, idx, bitmap):
+        if wx.VERSION >= (2, 8, 0):
+            notebook = self.GetNotebook()
+            if notebook is not None:
+                return notebook.SetPageBitmap(idx, bitmap)
+        else:
+            return self.TabsOpened.SetPageImage(idx, bitmap)
+
     def GetPageText(self, idx):
         if wx.VERSION >= (2, 8, 0):
             notebook = self.GetNotebook()
@@ -1030,6 +1054,22 @@
         for idx in xrange(self.GetPageCount()):
             window = self.GetPage(idx)
             words = window.GetTagName().split("::")
+            if words[0] == "P":
+                pou_type = self.Controler.GetEditedElementType(window.GetTagName())[1].upper()
+                pou_body_type = self.Controler.GetEditedElementBodyType(window.GetTagName())
+                self.SetPageBitmap(idx, GenerateBitmap(pou_type, pou_body_type))
+            elif words[0] == "T":
+                pou_body_type = self.Controler.GetEditedElementBodyType(window.GetTagName())
+                self.SetPageBitmap(idx, GenerateBitmap("TRANSITION", pou_body_type))
+            elif words[0] == "A":
+                pou_body_type = self.Controler.GetEditedElementBodyType(window.GetTagName())
+                self.SetPageBitmap(idx, GenerateBitmap("ACTION", pou_body_type))
+            elif words[0] == "C":
+                self.SetPageBitmap(idx, GenerateBitmap("CONFIGURATION"))
+            elif words[0] == "R":
+                self.SetPageBitmap(idx, GenerateBitmap("RESOURCE"))
+            elif words[0] == "D":
+                self.SetPageBitmap(idx, GenerateBitmap("DATATYPE"))
             self.SetPageText(idx, "-".join(words[1:]))