author | Edouard Tisserant |
Mon, 18 Jun 2012 02:35:21 +0200 | |
changeset 776 | c81397b665b6 |
parent 775 | 172be32a2482 |
child 781 | cdc6393705ce |
permissions | -rw-r--r-- |
738 | 1 |
|
2 |
import os |
|
3 |
import types |
|
4 |
||
5 |
import wx |
|
6 |
import wx.lib.buttons |
|
7 |
||
8 |
from controls import EditorPanel |
|
9 |
||
10 |
from PLCOpenEditor import TITLE, FILEMENU, PROJECTTREE, PAGETITLES |
|
11 |
||
742
41a4a560406c
Fixed runtime problems with python 2.6 without wx installed
Edouard Tisserant
parents:
738
diff
changeset
|
12 |
from util.misc import opjimg |
738 | 13 |
from util.TextCtrlAutoComplete import TextCtrlAutoComplete |
14 |
from util.BrowseValuesLibraryDialog import BrowseValuesLibraryDialog |
|
15 |
||
16 |
if wx.Platform == '__WXMSW__': |
|
17 |
faces = { 'times': 'Times New Roman', |
|
18 |
'mono' : 'Courier New', |
|
19 |
'helv' : 'Arial', |
|
20 |
'other': 'Comic Sans MS', |
|
21 |
'size' : 16, |
|
22 |
} |
|
23 |
else: |
|
24 |
faces = { 'times': 'Times', |
|
25 |
'mono' : 'Courier', |
|
26 |
'helv' : 'Helvetica', |
|
27 |
'other': 'new century schoolbook', |
|
28 |
'size' : 18, |
|
29 |
} |
|
30 |
||
31 |
SCROLLBAR_UNIT = 10 |
|
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
32 |
WINDOW_COLOUR = wx.Colour(240, 240, 240) |
738 | 33 |
|
34 |
CWD = os.path.split(os.path.realpath(__file__))[0] |
|
35 |
||
36 |
def Bpath(*args): |
|
37 |
return os.path.join(CWD,*args) |
|
38 |
||
39 |
# Some helpers to tweak GenBitmapTextButtons |
|
40 |
# TODO: declare customized classes instead. |
|
41 |
gen_mini_GetBackgroundBrush = lambda obj:lambda dc: wx.Brush(obj.GetParent().GetBackgroundColour(), wx.SOLID) |
|
42 |
gen_textbutton_GetLabelSize = lambda obj:lambda:(wx.lib.buttons.GenButton._GetLabelSize(obj)[:-1] + (False,)) |
|
43 |
||
44 |
def make_genbitmaptogglebutton_flat(button): |
|
45 |
button.GetBackgroundBrush = gen_mini_GetBackgroundBrush(button) |
|
46 |
button.labelDelta = 0 |
|
47 |
button.SetBezelWidth(0) |
|
48 |
button.SetUseFocusIndicator(False) |
|
49 |
||
50 |
# Patch wx.lib.imageutils so that gray is supported on alpha images |
|
51 |
import wx.lib.imageutils |
|
52 |
from wx.lib.imageutils import grayOut as old_grayOut |
|
53 |
def grayOut(anImage): |
|
54 |
if anImage.HasAlpha(): |
|
55 |
AlphaData = anImage.GetAlphaData() |
|
56 |
else : |
|
57 |
AlphaData = None |
|
58 |
||
59 |
old_grayOut(anImage) |
|
60 |
||
61 |
if AlphaData is not None: |
|
62 |
anImage.SetAlphaData(AlphaData) |
|
63 |
||
64 |
wx.lib.imageutils.grayOut = grayOut |
|
65 |
||
66 |
class GenBitmapTextButton(wx.lib.buttons.GenBitmapTextButton): |
|
67 |
def _GetLabelSize(self): |
|
68 |
""" used internally """ |
|
69 |
w, h = self.GetTextExtent(self.GetLabel()) |
|
70 |
if not self.bmpLabel: |
|
71 |
return w, h, False # if there isn't a bitmap use the size of the text |
|
72 |
||
73 |
w_bmp = self.bmpLabel.GetWidth()+2 |
|
74 |
h_bmp = self.bmpLabel.GetHeight()+2 |
|
75 |
height = h + h_bmp |
|
76 |
if w_bmp > w: |
|
77 |
width = w_bmp |
|
78 |
else: |
|
79 |
width = w |
|
80 |
return width, height, False |
|
81 |
||
82 |
def DrawLabel(self, dc, width, height, dw=0, dy=0): |
|
83 |
bmp = self.bmpLabel |
|
84 |
if bmp != None: # if the bitmap is used |
|
85 |
if self.bmpDisabled and not self.IsEnabled(): |
|
86 |
bmp = self.bmpDisabled |
|
87 |
if self.bmpFocus and self.hasFocus: |
|
88 |
bmp = self.bmpFocus |
|
89 |
if self.bmpSelected and not self.up: |
|
90 |
bmp = self.bmpSelected |
|
91 |
bw,bh = bmp.GetWidth(), bmp.GetHeight() |
|
92 |
if not self.up: |
|
93 |
dw = dy = self.labelDelta |
|
94 |
hasMask = bmp.GetMask() != None |
|
95 |
else: |
|
96 |
bw = bh = 0 # no bitmap -> size is zero |
|
97 |
||
98 |
dc.SetFont(self.GetFont()) |
|
99 |
if self.IsEnabled(): |
|
100 |
dc.SetTextForeground(self.GetForegroundColour()) |
|
101 |
else: |
|
102 |
dc.SetTextForeground(wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT)) |
|
103 |
||
104 |
label = self.GetLabel() |
|
105 |
tw, th = dc.GetTextExtent(label) # size of text |
|
106 |
if not self.up: |
|
107 |
dw = dy = self.labelDelta |
|
108 |
||
109 |
pos_x = (width-bw)/2+dw # adjust for bitmap and text to centre |
|
110 |
pos_y = (height-bh-th)/2+dy |
|
111 |
if bmp !=None: |
|
112 |
dc.DrawBitmap(bmp, pos_x, pos_y, hasMask) # draw bitmap if available |
|
113 |
pos_x = (width-tw)/2+dw # adjust for bitmap and text to centre |
|
114 |
pos_y += bh + 2 |
|
115 |
||
116 |
dc.DrawText(label, pos_x, pos_y) # draw the text |
|
117 |
||
118 |
||
119 |
class GenStaticBitmap(wx.lib.statbmp.GenStaticBitmap): |
|
120 |
""" Customized GenStaticBitmap, fix transparency redraw bug on wx2.8/win32, |
|
121 |
and accept image name as __init__ parameter, fail silently if file do not exist""" |
|
122 |
def __init__(self, parent, ID, bitmapname, |
|
123 |
pos = wx.DefaultPosition, size = wx.DefaultSize, |
|
124 |
style = 0, |
|
125 |
name = "genstatbmp"): |
|
126 |
||
127 |
bitmappath = Bpath( "images", bitmapname) |
|
128 |
if os.path.isfile(bitmappath): |
|
129 |
bitmap = wx.Bitmap(bitmappath) |
|
130 |
else: |
|
131 |
bitmap = None |
|
132 |
wx.lib.statbmp.GenStaticBitmap.__init__(self, parent, ID, bitmap, |
|
133 |
pos, size, |
|
134 |
style, |
|
135 |
name) |
|
136 |
||
137 |
def OnPaint(self, event): |
|
138 |
dc = wx.PaintDC(self) |
|
139 |
colour = self.GetParent().GetBackgroundColour() |
|
140 |
dc.SetPen(wx.Pen(colour)) |
|
141 |
dc.SetBrush(wx.Brush(colour )) |
|
142 |
dc.DrawRectangle(0, 0, *dc.GetSizeTuple()) |
|
143 |
if self._bitmap: |
|
144 |
dc.DrawBitmap(self._bitmap, 0, 0, True) |
|
145 |
||
146 |
class ConfTreeNodeEditor(EditorPanel): |
|
147 |
||
775
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
148 |
SHOW_BASE_PARAMS = True |
762
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
149 |
SHOW_PARAMS = True |
738 | 150 |
|
151 |
def _init_ConfNodeEditor(self, prnt): |
|
152 |
self.ConfNodeEditor = None |
|
153 |
||
154 |
def _init_Editor(self, prnt): |
|
155 |
self.Editor = wx.SplitterWindow(id=self.ID, name='EditorSplitter', parent=prnt, |
|
156 |
size=wx.Size(0, 0), style=wx.SUNKEN_BORDER|wx.SP_3D) |
|
157 |
self.SetNeedUpdating(True) |
|
158 |
self.SetMinimumPaneSize(1) |
|
159 |
||
762
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
160 |
if self.SHOW_PARAMS: |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
161 |
self.ParamsEditor = wx.ScrolledWindow(self.Editor, -1, size=wx.Size(-1, -1), |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
162 |
style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
163 |
self.ParamsEditor.SetBackgroundColour(WINDOW_COLOUR) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
164 |
self.ParamsEditor.Bind(wx.EVT_SIZE, self.OnWindowResize) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
165 |
self.ParamsEditor.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
166 |
|
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
167 |
# Variable allowing disabling of ParamsEditor scroll when Popup shown |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
168 |
self.ScrollingEnabled = True |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
169 |
|
775
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
170 |
if self.SHOW_BASE_PARAMS: |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
171 |
self.ParamsEditorSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
172 |
self.ParamsEditorSizer.AddGrowableCol(0) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
173 |
self.ParamsEditorSizer.AddGrowableRow(1) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
174 |
|
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
175 |
self.ParamsEditor.SetSizer(self.ParamsEditorSizer) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
176 |
|
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
177 |
baseparamseditor_sizer = wx.BoxSizer(wx.HORIZONTAL) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
178 |
self.ParamsEditorSizer.AddSizer(baseparamseditor_sizer, 0, border=5, |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
179 |
flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.TOP) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
180 |
|
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
181 |
self.FullIECChannel = wx.StaticText(self.ParamsEditor, -1) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
182 |
self.FullIECChannel.SetFont( |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
183 |
wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
184 |
wx.BOLD, faceName = faces["helv"])) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
185 |
baseparamseditor_sizer.AddWindow(self.FullIECChannel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
186 |
|
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
187 |
updownsizer = wx.BoxSizer(wx.VERTICAL) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
188 |
baseparamseditor_sizer.AddSizer(updownsizer, 0, border=5, |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
189 |
flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
190 |
|
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
191 |
ieccupbutton_id = wx.NewId() |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
192 |
self.IECCUpButton = wx.lib.buttons.GenBitmapTextButton( |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
193 |
id=ieccupbutton_id, bitmap=wx.Bitmap(opjimg('IECCDown')), |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
194 |
name='IECUpButton', parent=self.ParamsEditor, pos=wx.Point(0, 0), |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
195 |
size=wx.Size(16, 16), style=wx.NO_BORDER) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
196 |
self.IECCUpButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(1), |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
197 |
id=ieccupbutton_id) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
198 |
updownsizer.AddWindow(self.IECCUpButton, 0, border=0, flag=wx.ALIGN_LEFT) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
199 |
|
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
200 |
ieccdownbutton_id = wx.NewId() |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
201 |
self.IECCDownButton = wx.lib.buttons.GenBitmapButton( |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
202 |
id=ieccdownbutton_id, bitmap=wx.Bitmap(opjimg('IECCUp')), |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
203 |
name='IECDownButton', parent=self.ParamsEditor, pos=wx.Point(0, 0), |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
204 |
size=wx.Size(16, 16), style=wx.NO_BORDER) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
205 |
self.IECCDownButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(-1), |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
206 |
id=ieccdownbutton_id) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
207 |
updownsizer.AddWindow(self.IECCDownButton, 0, border=0, flag=wx.ALIGN_LEFT) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
208 |
|
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
209 |
confnodename_id = wx.NewId() |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
210 |
self.ConfNodeName = wx.TextCtrl( |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
211 |
self.ParamsEditor, confnodename_id, |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
212 |
size=wx.Size(150, 25), style=wx.NO_BORDER) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
213 |
self.ConfNodeName.SetFont( |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
214 |
wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
215 |
wx.BOLD, faceName = faces["helv"])) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
216 |
self.ConfNodeName.Bind(wx.EVT_TEXT, |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
217 |
self.GetTextCtrlCallBackFunction(self.ConfNodeName, "BaseParams.Name", True), |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
218 |
id=confnodename_id) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
219 |
baseparamseditor_sizer.AddWindow(self.ConfNodeName, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
220 |
|
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
221 |
buttons_sizer = self.GenerateMethodButtonSizer() |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
222 |
baseparamseditor_sizer.AddSizer(buttons_sizer, 0, border=0, flag=wx.ALIGN_CENTER) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
223 |
|
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
224 |
else: |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
225 |
self.ParamsEditorSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=5) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
226 |
self.ParamsEditorSizer.AddGrowableCol(0) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
227 |
self.ParamsEditorSizer.AddGrowableRow(0) |
762
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
228 |
|
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
229 |
self.ConfNodeParamsSizer = wx.BoxSizer(wx.VERTICAL) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
230 |
self.ParamsEditorSizer.AddSizer(self.ConfNodeParamsSizer, 0, border=5, |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
231 |
flag=wx.LEFT|wx.RIGHT|wx.BOTTOM) |
775
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
232 |
|
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
233 |
self.RefreshConfNodeParamsSizer() |
762
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
234 |
else: |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
235 |
self.ParamsEditor = None |
738 | 236 |
|
237 |
self._init_ConfNodeEditor(self.Editor) |
|
238 |
||
239 |
if self.ConfNodeEditor is not None: |
|
762
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
240 |
if self.ParamsEditor is not None: |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
241 |
min_size = self.ParamsEditorSizer.GetMinSize() |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
242 |
self.Editor.SplitHorizontally(self.ParamsEditor, |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
243 |
self.ConfNodeEditor, |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
244 |
min(min_size.height, 200)) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
245 |
else: |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
246 |
self.Editor.Initialize(self.ConfNodeEditor) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
247 |
elif self.ParamsEditor is not None: |
738 | 248 |
self.Editor.Initialize(self.ParamsEditor) |
249 |
||
743 | 250 |
def __init__(self, parent, controler, window, tagname=""): |
738 | 251 |
EditorPanel.__init__(self, parent, tagname, window, controler) |
743 | 252 |
|
253 |
icon_path = self.Controler.GetIconPath() |
|
254 |
if icon_path is None: |
|
255 |
icon_path = opjimg("Extension") |
|
256 |
self.SetIcon(wx.Bitmap(icon_path, wx.BITMAP_TYPE_PNG)) |
|
738 | 257 |
|
258 |
def __del__(self): |
|
259 |
self.Controler.OnCloseEditor(self) |
|
260 |
||
261 |
def GetTagName(self): |
|
262 |
return self.Controler.CTNFullName() |
|
263 |
||
264 |
def GetTitle(self): |
|
265 |
fullname = self.Controler.CTNFullName() |
|
266 |
if self.Controler.CTNTestModified(): |
|
267 |
return "~%s~" % fullname |
|
268 |
return fullname |
|
269 |
||
270 |
def HasNoModel(self): |
|
271 |
return False |
|
272 |
||
743 | 273 |
def GetBufferState(self): |
274 |
return False, False |
|
275 |
||
276 |
def Undo(self): |
|
277 |
pass |
|
278 |
||
279 |
def Redo(self): |
|
280 |
pass |
|
281 |
||
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
282 |
def RefreshView(self): |
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
283 |
EditorPanel.RefreshView(self) |
762
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
284 |
if self.ParamsEditor is not None: |
775
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
285 |
if self.SHOW_BASE_PARAMS: |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
286 |
self.ConfNodeName.ChangeValue(self.Controler.MandatoryParams[1].getName()) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
287 |
self.RefreshIECChannelControlsState() |
762
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
288 |
self.RefreshConfNodeParamsSizer() |
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
289 |
|
738 | 290 |
def EnableScrolling(self, enable): |
291 |
self.ScrollingEnabled = enable |
|
292 |
||
293 |
def RefreshIECChannelControlsState(self): |
|
294 |
self.FullIECChannel.SetLabel(self.Controler.GetFullIEC_Channel()) |
|
295 |
self.IECCDownButton.Enable(self.Controler.BaseParams.getIEC_Channel() > 0) |
|
296 |
||
297 |
def RefreshConfNodeParamsSizer(self): |
|
298 |
self.Freeze() |
|
299 |
self.ConfNodeParamsSizer.Clear(True) |
|
300 |
||
301 |
confnode_infos = self.Controler.GetParamsAttributes() |
|
302 |
if len(confnode_infos) > 0: |
|
303 |
self.GenerateSizerElements(self.ConfNodeParamsSizer, confnode_infos, None, False) |
|
304 |
||
305 |
self.ParamsEditorSizer.Layout() |
|
306 |
self.Thaw() |
|
307 |
||
308 |
def GenerateMethodButtonSizer(self): |
|
309 |
normal_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["helv"]) |
|
310 |
mouseover_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, underline=True, faceName = faces["helv"]) |
|
311 |
||
312 |
msizer = wx.BoxSizer(wx.HORIZONTAL) |
|
313 |
||
314 |
for confnode_method in self.Controler.ConfNodeMethods: |
|
315 |
if "method" in confnode_method and confnode_method.get("shown",True): |
|
316 |
id = wx.NewId() |
|
317 |
label = confnode_method["name"] |
|
767
36e823a90d94
Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents:
762
diff
changeset
|
318 |
bitmap_path = confnode_method.get("bitmap", "Unknown") |
36e823a90d94
Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents:
762
diff
changeset
|
319 |
if os.path.splitext(bitmap_path)[1] == "": |
36e823a90d94
Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents:
762
diff
changeset
|
320 |
bitmap_path = Bpath("images", "%s.png" % bitmap_path) |
738 | 321 |
button = GenBitmapTextButton(id=id, parent=self.ParamsEditor, |
767
36e823a90d94
Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents:
762
diff
changeset
|
322 |
bitmap=wx.Bitmap(bitmap_path), label=label, |
738 | 323 |
name=label, pos=wx.DefaultPosition, style=wx.NO_BORDER) |
324 |
button.SetFont(normal_bt_font) |
|
325 |
button.SetToolTipString(confnode_method["tooltip"]) |
|
767
36e823a90d94
Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents:
762
diff
changeset
|
326 |
if confnode_method.get("push", False): |
36e823a90d94
Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents:
762
diff
changeset
|
327 |
button.Bind(wx.EVT_LEFT_DOWN, self.GetButtonCallBackFunction(confnode_method["method"], True)) |
36e823a90d94
Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents:
762
diff
changeset
|
328 |
else: |
36e823a90d94
Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents:
762
diff
changeset
|
329 |
button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(confnode_method["method"]), id=id) |
738 | 330 |
# a fancy underline on mouseover |
331 |
def setFontStyle(b, s): |
|
332 |
def fn(event): |
|
333 |
b.SetFont(s) |
|
334 |
b.Refresh() |
|
335 |
event.Skip() |
|
336 |
return fn |
|
337 |
button.Bind(wx.EVT_ENTER_WINDOW, setFontStyle(button, mouseover_bt_font)) |
|
338 |
button.Bind(wx.EVT_LEAVE_WINDOW, setFontStyle(button, normal_bt_font)) |
|
339 |
#hack to force size to mini |
|
340 |
if not confnode_method.get("enabled",True): |
|
341 |
button.Disable() |
|
342 |
msizer.AddWindow(button, 0, border=0, flag=wx.ALIGN_CENTER) |
|
343 |
return msizer |
|
344 |
||
345 |
def GenerateSizerElements(self, sizer, elements, path, clean = True): |
|
346 |
if clean: |
|
347 |
sizer.Clear(True) |
|
348 |
first = True |
|
349 |
for element_infos in elements: |
|
350 |
if path: |
|
351 |
element_path = "%s.%s"%(path, element_infos["name"]) |
|
352 |
else: |
|
353 |
element_path = element_infos["name"] |
|
354 |
if element_infos["type"] == "element": |
|
355 |
label = element_infos["name"] |
|
356 |
staticbox = wx.StaticBox(id=-1, label=_(label), |
|
357 |
name='%s_staticbox'%element_infos["name"], parent=self.ParamsEditor, |
|
358 |
pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0) |
|
359 |
staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) |
|
360 |
if first: |
|
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
361 |
sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.TOP|wx.BOTTOM) |
738 | 362 |
else: |
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
363 |
sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.BOTTOM) |
738 | 364 |
self.GenerateSizerElements(staticboxsizer, element_infos["children"], element_path) |
365 |
else: |
|
366 |
boxsizer = wx.FlexGridSizer(cols=3, rows=1) |
|
367 |
boxsizer.AddGrowableCol(1) |
|
368 |
if first: |
|
369 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL) |
|
370 |
else: |
|
371 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM) |
|
372 |
staticbitmap = GenStaticBitmap(ID=-1, bitmapname="%s.png"%element_infos["name"], |
|
373 |
name="%s_bitmap"%element_infos["name"], parent=self.ParamsEditor, |
|
374 |
pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
|
375 |
boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
|
376 |
label = element_infos["name"] |
|
377 |
statictext = wx.StaticText(id=-1, label="%s:"%_(label), |
|
378 |
name="%s_label"%element_infos["name"], parent=self.ParamsEditor, |
|
379 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
|
380 |
boxsizer.AddWindow(statictext, 0, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.RIGHT) |
|
381 |
id = wx.NewId() |
|
382 |
if isinstance(element_infos["type"], types.ListType): |
|
383 |
if isinstance(element_infos["value"], types.TupleType): |
|
384 |
browse_boxsizer = wx.BoxSizer(wx.HORIZONTAL) |
|
385 |
boxsizer.AddSizer(browse_boxsizer, 0, border=0, flag=0) |
|
386 |
||
387 |
textctrl = wx.TextCtrl(id=id, name=element_infos["name"], parent=self.ParamsEditor, |
|
388 |
pos=wx.Point(0, 0), size=wx.Size(275, 25), style=wx.TE_READONLY) |
|
389 |
if element_infos["value"] is not None: |
|
390 |
textctrl.SetValue(element_infos["value"][0]) |
|
391 |
value_infos = element_infos["value"][1] |
|
392 |
else: |
|
393 |
value_infos = None |
|
394 |
browse_boxsizer.AddWindow(textctrl, 0, border=0, flag=0) |
|
395 |
button_id = wx.NewId() |
|
396 |
button = wx.Button(id=button_id, name="browse_%s" % element_infos["name"], parent=self.ParamsEditor, |
|
397 |
label="...", pos=wx.Point(0, 0), size=wx.Size(25, 25)) |
|
398 |
browse_boxsizer.AddWindow(button, 0, border=0, flag=0) |
|
399 |
button.Bind(wx.EVT_BUTTON, |
|
400 |
self.GetBrowseCallBackFunction(element_infos["name"], textctrl, element_infos["type"], |
|
401 |
value_infos, element_path), |
|
402 |
id=button_id) |
|
403 |
else: |
|
404 |
combobox = wx.ComboBox(id=id, name=element_infos["name"], parent=self.ParamsEditor, |
|
405 |
pos=wx.Point(0, 0), size=wx.Size(300, 28), style=wx.CB_READONLY) |
|
406 |
boxsizer.AddWindow(combobox, 0, border=0, flag=0) |
|
407 |
if element_infos["use"] == "optional": |
|
408 |
combobox.Append("") |
|
409 |
if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType): |
|
410 |
for choice, xsdclass in element_infos["type"]: |
|
411 |
combobox.Append(choice) |
|
412 |
name = element_infos["name"] |
|
413 |
value = element_infos["value"] |
|
414 |
staticbox = wx.StaticBox(id=-1, label="%s - %s"%(_(name), _(value)), |
|
415 |
name='%s_staticbox'%element_infos["name"], parent=self.ParamsEditor, |
|
416 |
pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0) |
|
417 |
staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) |
|
418 |
sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.BOTTOM) |
|
419 |
self.GenerateSizerElements(staticboxsizer, element_infos["children"], element_path) |
|
420 |
callback = self.GetChoiceContentCallBackFunction(combobox, staticboxsizer, element_path) |
|
421 |
else: |
|
422 |
for choice in element_infos["type"]: |
|
423 |
combobox.Append(choice) |
|
424 |
callback = self.GetChoiceCallBackFunction(combobox, element_path) |
|
425 |
if element_infos["value"] is None: |
|
426 |
combobox.SetStringSelection("") |
|
427 |
else: |
|
428 |
combobox.SetStringSelection(element_infos["value"]) |
|
429 |
combobox.Bind(wx.EVT_COMBOBOX, callback, id=id) |
|
430 |
elif isinstance(element_infos["type"], types.DictType): |
|
431 |
scmin = -(2**31) |
|
432 |
scmax = 2**31-1 |
|
433 |
if "min" in element_infos["type"]: |
|
434 |
scmin = element_infos["type"]["min"] |
|
435 |
if "max" in element_infos["type"]: |
|
436 |
scmax = element_infos["type"]["max"] |
|
437 |
spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=self.ParamsEditor, |
|
438 |
pos=wx.Point(0, 0), size=wx.Size(300, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT) |
|
439 |
spinctrl.SetRange(scmin,scmax) |
|
440 |
boxsizer.AddWindow(spinctrl, 0, border=0, flag=0) |
|
441 |
if element_infos["value"] is not None: |
|
442 |
spinctrl.SetValue(element_infos["value"]) |
|
443 |
spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path), id=id) |
|
444 |
else: |
|
445 |
if element_infos["type"] == "boolean": |
|
446 |
checkbox = wx.CheckBox(id=id, name=element_infos["name"], parent=self.ParamsEditor, |
|
447 |
pos=wx.Point(0, 0), size=wx.Size(17, 25), style=0) |
|
448 |
boxsizer.AddWindow(checkbox, 0, border=0, flag=0) |
|
449 |
if element_infos["value"] is not None: |
|
450 |
checkbox.SetValue(element_infos["value"]) |
|
451 |
checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, element_path), id=id) |
|
452 |
elif element_infos["type"] in ["unsignedLong", "long","integer"]: |
|
453 |
if element_infos["type"].startswith("unsigned"): |
|
454 |
scmin = 0 |
|
455 |
else: |
|
456 |
scmin = -(2**31) |
|
457 |
scmax = 2**31-1 |
|
458 |
spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=self.ParamsEditor, |
|
459 |
pos=wx.Point(0, 0), size=wx.Size(300, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT) |
|
460 |
spinctrl.SetRange(scmin, scmax) |
|
461 |
boxsizer.AddWindow(spinctrl, 0, border=0, flag=0) |
|
462 |
if element_infos["value"] is not None: |
|
463 |
spinctrl.SetValue(element_infos["value"]) |
|
464 |
spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path), id=id) |
|
465 |
else: |
|
466 |
choices = self.ParentWindow.GetConfigEntry(element_path, [""]) |
|
467 |
textctrl = TextCtrlAutoComplete(id=id, |
|
468 |
name=element_infos["name"], |
|
469 |
parent=self.ParamsEditor, |
|
470 |
appframe=self, |
|
471 |
choices=choices, |
|
472 |
element_path=element_path, |
|
473 |
pos=wx.Point(0, 0), |
|
474 |
size=wx.Size(300, 25), |
|
475 |
style=0) |
|
476 |
||
477 |
boxsizer.AddWindow(textctrl, 0, border=0, flag=0) |
|
478 |
if element_infos["value"] is not None: |
|
479 |
textctrl.ChangeValue(str(element_infos["value"])) |
|
480 |
textctrl.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(textctrl, element_path)) |
|
481 |
first = False |
|
482 |
||
483 |
||
484 |
def GetItemChannelChangedFunction(self, dir): |
|
485 |
def OnConfNodeTreeItemChannelChanged(event): |
|
486 |
confnode_IECChannel = self.Controler.BaseParams.getIEC_Channel() |
|
487 |
res = self.SetConfNodeParamsAttribute("BaseParams.IEC_Channel", confnode_IECChannel + dir) |
|
488 |
wx.CallAfter(self.RefreshIECChannelControlsState) |
|
489 |
wx.CallAfter(self.ParentWindow._Refresh, TITLE, FILEMENU, PROJECTTREE) |
|
490 |
wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, self.GetTagName()) |
|
491 |
event.Skip() |
|
492 |
return OnConfNodeTreeItemChannelChanged |
|
493 |
||
494 |
def SetConfNodeParamsAttribute(self, *args, **kwargs): |
|
495 |
res, StructChanged = self.Controler.SetParamsAttribute(*args, **kwargs) |
|
496 |
if StructChanged: |
|
497 |
wx.CallAfter(self.RefreshConfNodeParamsSizer) |
|
498 |
wx.CallAfter(self.ParentWindow._Refresh, TITLE, FILEMENU) |
|
499 |
return res |
|
500 |
||
767
36e823a90d94
Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents:
762
diff
changeset
|
501 |
def GetButtonCallBackFunction(self, method, push=False): |
738 | 502 |
""" Generate the callbackfunc for a given confnode method""" |
503 |
def OnButtonClick(event): |
|
504 |
# Disable button to prevent re-entrant call |
|
505 |
event.GetEventObject().Disable() |
|
506 |
# Call |
|
507 |
getattr(self.Controler,method)() |
|
508 |
# Re-enable button |
|
509 |
event.GetEventObject().Enable() |
|
510 |
||
767
36e823a90d94
Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents:
762
diff
changeset
|
511 |
if not push: |
36e823a90d94
Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents:
762
diff
changeset
|
512 |
event.Skip() |
738 | 513 |
return OnButtonClick |
514 |
||
515 |
def GetChoiceCallBackFunction(self, choicectrl, path): |
|
516 |
def OnChoiceChanged(event): |
|
517 |
res = self.SetConfNodeParamsAttribute(path, choicectrl.GetStringSelection()) |
|
518 |
choicectrl.SetStringSelection(res) |
|
519 |
event.Skip() |
|
520 |
return OnChoiceChanged |
|
521 |
||
522 |
def GetChoiceContentCallBackFunction(self, choicectrl, staticboxsizer, path): |
|
523 |
def OnChoiceContentChanged(event): |
|
524 |
res = self.SetConfNodeParamsAttribute(path, choicectrl.GetStringSelection()) |
|
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
525 |
wx.CallAfter(self.RefreshConfNodeParamsSizer) |
738 | 526 |
event.Skip() |
527 |
return OnChoiceContentChanged |
|
528 |
||
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
529 |
def GetTextCtrlCallBackFunction(self, textctrl, path, refresh=False): |
738 | 530 |
def OnTextCtrlChanged(event): |
531 |
res = self.SetConfNodeParamsAttribute(path, textctrl.GetValue()) |
|
532 |
if res != textctrl.GetValue(): |
|
533 |
textctrl.ChangeValue(res) |
|
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
534 |
if refresh: |
738 | 535 |
wx.CallAfter(self.ParentWindow._Refresh, TITLE, FILEMENU, PROJECTTREE, PAGETITLES) |
536 |
wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, self.GetTagName()) |
|
537 |
event.Skip() |
|
538 |
return OnTextCtrlChanged |
|
539 |
||
540 |
def GetCheckBoxCallBackFunction(self, chkbx, path): |
|
541 |
def OnCheckBoxChanged(event): |
|
542 |
res = self.SetConfNodeParamsAttribute(path, chkbx.IsChecked()) |
|
543 |
chkbx.SetValue(res) |
|
544 |
event.Skip() |
|
545 |
return OnCheckBoxChanged |
|
546 |
||
547 |
def GetBrowseCallBackFunction(self, name, textctrl, library, value_infos, path): |
|
548 |
infos = [value_infos] |
|
549 |
def OnBrowseButton(event): |
|
550 |
dialog = BrowseValuesLibraryDialog(self, name, library, infos[0]) |
|
551 |
if dialog.ShowModal() == wx.ID_OK: |
|
552 |
value, value_infos = self.SetConfNodeParamsAttribute(path, dialog.GetValueInfos()) |
|
553 |
textctrl.ChangeValue(value) |
|
554 |
infos[0] = value_infos |
|
555 |
dialog.Destroy() |
|
556 |
event.Skip() |
|
557 |
return OnBrowseButton |
|
558 |
||
559 |
def OnWindowResize(self, event): |
|
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
560 |
self.ParamsEditor.GetBestSize() |
738 | 561 |
xstart, ystart = self.ParamsEditor.GetViewStart() |
562 |
window_size = self.ParamsEditor.GetClientSize() |
|
563 |
maxx, maxy = self.ParamsEditorSizer.GetMinSize() |
|
564 |
posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT)) |
|
565 |
posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT)) |
|
566 |
self.ParamsEditor.Scroll(posx, posy) |
|
567 |
self.ParamsEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, |
|
568 |
maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy) |
|
569 |
event.Skip() |
|
570 |
||
571 |
def OnMouseWheel(self, event): |
|
572 |
if self.ScrollingEnabled: |
|
573 |
event.Skip() |
|
574 |