author | Laurent Bessard |
Fri, 24 May 2013 16:29:57 +0200 | |
changeset 1173 | ad09b4a755ce |
parent 1165 | 99972084890d |
child 1177 | 4cbbc58b91b4 |
permissions | -rw-r--r-- |
814 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This library is free software; you can redistribute it and/or |
|
5 |
#modify it under the terms of the GNU General Public |
|
6 |
#License as published by the Free Software Foundation; either |
|
7 |
#version 2.1 of the License, or (at your option) any later version. |
|
8 |
# |
|
9 |
#This library is distributed in the hope that it will be useful, |
|
10 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12 |
#General Public License for more details. |
|
13 |
# |
|
14 |
#You should have received a copy of the GNU General Public |
|
15 |
#License along with this library; if not, write to the Free Software |
|
16 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 |
||
18 |
import wx |
|
1164
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
19 |
import wx.lib.agw.customtreectrl as CT |
814 | 20 |
|
1164
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
21 |
from util.BitmapLibrary import GetBitmap |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
22 |
|
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
23 |
# Customize CustomTreeItem for adding icon on item left |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
24 |
CT.GenericTreeItem._ExtraImage = None |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
25 |
|
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
26 |
def SetExtraImage(self, image): |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
27 |
self._type = 1 |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
28 |
self._ExtraImage = image |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
29 |
CT.GenericTreeItem.SetExtraImage = SetExtraImage |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
30 |
|
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
31 |
_DefaultGetCurrentCheckedImage = CT.GenericTreeItem.GetCurrentCheckedImage |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
32 |
def GetCurrentCheckedImage(self): |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
33 |
if self._ExtraImage is not None: |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
34 |
return self._ExtraImage |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
35 |
return _DefaultGetCurrentCheckedImage(self) |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
36 |
CT.GenericTreeItem.GetCurrentCheckedImage = GetCurrentCheckedImage |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
37 |
|
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
38 |
class CustomTree(CT.CustomTreeCtrl): |
814 | 39 |
|
40 |
def __init__(self, *args, **kwargs): |
|
1164
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
41 |
CT.CustomTreeCtrl.__init__(self, *args, **kwargs) |
1165
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
42 |
#self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) |
814 | 43 |
|
44 |
self.BackgroundBitmap = None |
|
45 |
self.BackgroundAlign = wx.ALIGN_LEFT|wx.ALIGN_TOP |
|
46 |
||
47 |
self.AddMenu = None |
|
48 |
self.Enabled = False |
|
49 |
||
1164
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
50 |
self.Bind(wx.EVT_SCROLLWIN, self.OnScroll) |
814 | 51 |
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) |
52 |
||
53 |
def SetBackgroundBitmap(self, bitmap, align): |
|
54 |
self.BackgroundBitmap = bitmap |
|
55 |
self.BackgroundAlign = align |
|
56 |
||
1164
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
57 |
def SetImageListCheck(self, sizex, sizey, imglist=None): |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
58 |
CT.CustomTreeCtrl.SetImageListCheck(self, sizex, sizey, imglist=None) |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
59 |
|
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
60 |
self.ExtraImages = {} |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
61 |
for image in ["function", "functionBlock", "program"]: |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
62 |
self.ExtraImages[image] = self._imageListCheck.Add(GetBitmap(image.upper())) |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
63 |
|
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
64 |
def SetItemExtraImage(self, item, bitmap): |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
65 |
image = self.ExtraImages.get(bitmap) |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
66 |
if image is not None: |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
67 |
dc = wx.ClientDC(self) |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
68 |
item.SetExtraImage(image) |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
69 |
self.CalculateSize(item, dc) |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
70 |
self.RefreshLine(item) |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
71 |
|
814 | 72 |
def SetAddMenu(self, add_menu): |
73 |
self.AddMenu = add_menu |
|
74 |
||
75 |
def Enable(self, enabled): |
|
76 |
self.Enabled = enabled |
|
77 |
||
78 |
def GetBitmapRect(self): |
|
79 |
client_size = self.GetClientSize() |
|
80 |
bitmap_size = self.BackgroundBitmap.GetSize() |
|
81 |
||
82 |
if self.BackgroundAlign & wx.ALIGN_RIGHT: |
|
83 |
x = client_size[0] - bitmap_size[0] |
|
84 |
elif self.BackgroundAlign & wx.ALIGN_CENTER_HORIZONTAL: |
|
85 |
x = (client_size[0] - bitmap_size[0]) / 2 |
|
86 |
else: |
|
87 |
x = 0 |
|
88 |
||
89 |
if self.BackgroundAlign & wx.ALIGN_BOTTOM: |
|
90 |
y = client_size[1] - bitmap_size[1] |
|
91 |
elif self.BackgroundAlign & wx.ALIGN_CENTER_VERTICAL: |
|
92 |
y = (client_size[1] - bitmap_size[1]) / 2 |
|
93 |
else: |
|
94 |
y = 0 |
|
95 |
||
96 |
return wx.Rect(x, y, bitmap_size[0], bitmap_size[1]) |
|
97 |
||
98 |
def OnLeftUp(self, event): |
|
99 |
if self.Enabled: |
|
100 |
pos = event.GetPosition() |
|
101 |
item, flags = self.HitTest(pos) |
|
102 |
||
103 |
bitmap_rect = self.GetBitmapRect() |
|
104 |
if (bitmap_rect.InsideXY(pos.x, pos.y) or |
|
105 |
flags & wx.TREE_HITTEST_NOWHERE) and self.AddMenu is not None: |
|
1165
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
106 |
wx.CallAfter(self.PopupMenuXY, self.AddMenu, pos.x, pos.y) |
814 | 107 |
event.Skip() |
1165
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
108 |
|
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
109 |
def OnEraseBackground(self, event): |
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
110 |
dc = event.GetDC() |
814 | 111 |
|
1165
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
112 |
if not dc: |
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
113 |
dc = wx.ClientDC(self) |
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
114 |
rect = self.GetUpdateRegion().GetBox() |
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
115 |
dc.SetClippingRect(rect) |
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
116 |
|
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
117 |
dc.Clear() |
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
118 |
|
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
119 |
bitmap_rect = self.GetBitmapRect() |
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
120 |
dc.DrawBitmap(self.BackgroundBitmap, bitmap_rect.x, bitmap_rect.y) |
99972084890d
Fixed bugs with left panel CustomTreeCtrl on Windows
Laurent Bessard
parents:
1164
diff
changeset
|
121 |
|
814 | 122 |
def OnScroll(self, event): |
1164
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
123 |
wx.CallAfter(self.Refresh) |
814 | 124 |
event.Skip() |
125 |
||
1164
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
126 |
def OnSize(self, event): |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
127 |
CT.CustomTreeCtrl.OnSize(self, event) |
8fd44bc05aae
Added extra icon in left panel tree for indicating Pou type (function, functionBlock, or program) when alone
Laurent Bessard
parents:
814
diff
changeset
|
128 |
self.Refresh() |