author | laurent |
Sun, 10 Jun 2012 20:20:09 +0200 | |
changeset 765 | ef221ba41dec |
parent 762 | aaacc83aa86b |
child 767 | 36e823a90d94 |
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 |
||
148 |
HAS_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 |
|
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
170 |
self.ParamsEditorSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
171 |
self.ParamsEditorSizer.AddGrowableCol(0) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
172 |
self.ParamsEditorSizer.AddGrowableRow(1) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
173 |
|
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
174 |
self.ParamsEditor.SetSizer(self.ParamsEditorSizer) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
175 |
|
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
176 |
baseparamseditor_sizer = wx.BoxSizer(wx.HORIZONTAL) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
177 |
self.ParamsEditorSizer.AddSizer(baseparamseditor_sizer, 0, border=5, |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
178 |
flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.TOP) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
179 |
|
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
180 |
self.FullIECChannel = wx.StaticText(self.ParamsEditor, -1) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
181 |
self.FullIECChannel.SetFont( |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
182 |
wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
183 |
wx.BOLD, faceName = faces["helv"])) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
184 |
baseparamseditor_sizer.AddWindow(self.FullIECChannel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
185 |
|
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
186 |
updownsizer = wx.BoxSizer(wx.VERTICAL) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
187 |
baseparamseditor_sizer.AddSizer(updownsizer, 0, border=5, |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
188 |
flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
189 |
|
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
190 |
ieccupbutton_id = wx.NewId() |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
191 |
self.IECCUpButton = wx.lib.buttons.GenBitmapTextButton( |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
192 |
id=ieccupbutton_id, bitmap=wx.Bitmap(opjimg('IECCDown')), |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
193 |
name='IECUpButton', parent=self.ParamsEditor, pos=wx.Point(0, 0), |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
194 |
size=wx.Size(16, 16), style=wx.NO_BORDER) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
195 |
self.IECCUpButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(1), |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
196 |
id=ieccupbutton_id) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
197 |
updownsizer.AddWindow(self.IECCUpButton, 0, border=0, flag=wx.ALIGN_LEFT) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
198 |
|
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
199 |
ieccdownbutton_id = wx.NewId() |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
200 |
self.IECCDownButton = wx.lib.buttons.GenBitmapButton( |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
201 |
id=ieccdownbutton_id, bitmap=wx.Bitmap(opjimg('IECCUp')), |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
202 |
name='IECDownButton', parent=self.ParamsEditor, pos=wx.Point(0, 0), |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
203 |
size=wx.Size(16, 16), style=wx.NO_BORDER) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
204 |
self.IECCDownButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(-1), |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
205 |
id=ieccdownbutton_id) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
206 |
updownsizer.AddWindow(self.IECCDownButton, 0, border=0, flag=wx.ALIGN_LEFT) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
207 |
|
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
208 |
confnodename_id = wx.NewId() |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
209 |
self.ConfNodeName = wx.TextCtrl( |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
210 |
self.ParamsEditor, confnodename_id, |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
211 |
size=wx.Size(150, 25), style=wx.NO_BORDER) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
212 |
self.ConfNodeName.SetFont( |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
213 |
wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
214 |
wx.BOLD, faceName = faces["helv"])) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
215 |
self.ConfNodeName.Bind(wx.EVT_TEXT, |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
216 |
self.GetTextCtrlCallBackFunction(self.ConfNodeName, "BaseParams.Name", True), |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
217 |
id=confnodename_id) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
218 |
baseparamseditor_sizer.AddWindow(self.ConfNodeName, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
219 |
|
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
220 |
buttons_sizer = self.GenerateMethodButtonSizer() |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
221 |
baseparamseditor_sizer.AddSizer(buttons_sizer, 0, border=0, flag=wx.ALIGN_CENTER) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
222 |
|
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
223 |
self.ConfNodeParamsSizer = wx.BoxSizer(wx.VERTICAL) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
224 |
self.ParamsEditorSizer.AddSizer(self.ConfNodeParamsSizer, 0, border=5, |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
225 |
flag=wx.LEFT|wx.RIGHT|wx.BOTTOM) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
226 |
else: |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
227 |
self.ParamsEditor = None |
738 | 228 |
|
229 |
self._init_ConfNodeEditor(self.Editor) |
|
230 |
||
231 |
if self.ConfNodeEditor is not None: |
|
762
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
232 |
if self.ParamsEditor is not None: |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
233 |
min_size = self.ParamsEditorSizer.GetMinSize() |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
234 |
self.Editor.SplitHorizontally(self.ParamsEditor, |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
235 |
self.ConfNodeEditor, |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
236 |
min(min_size.height, 200)) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
237 |
else: |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
238 |
self.Editor.Initialize(self.ConfNodeEditor) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
239 |
elif self.ParamsEditor is not None: |
738 | 240 |
self.Editor.Initialize(self.ParamsEditor) |
241 |
||
743 | 242 |
def __init__(self, parent, controler, window, tagname=""): |
738 | 243 |
EditorPanel.__init__(self, parent, tagname, window, controler) |
743 | 244 |
|
245 |
icon_path = self.Controler.GetIconPath() |
|
246 |
if icon_path is None: |
|
247 |
icon_path = opjimg("Extension") |
|
248 |
self.SetIcon(wx.Bitmap(icon_path, wx.BITMAP_TYPE_PNG)) |
|
738 | 249 |
|
250 |
def __del__(self): |
|
251 |
self.Controler.OnCloseEditor(self) |
|
252 |
||
253 |
def GetTagName(self): |
|
254 |
return self.Controler.CTNFullName() |
|
255 |
||
256 |
def GetTitle(self): |
|
257 |
fullname = self.Controler.CTNFullName() |
|
258 |
if self.Controler.CTNTestModified(): |
|
259 |
return "~%s~" % fullname |
|
260 |
return fullname |
|
261 |
||
262 |
def HasNoModel(self): |
|
263 |
return False |
|
264 |
||
743 | 265 |
def GetBufferState(self): |
266 |
return False, False |
|
267 |
||
268 |
def Undo(self): |
|
269 |
pass |
|
270 |
||
271 |
def Redo(self): |
|
272 |
pass |
|
273 |
||
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
274 |
def RefreshView(self): |
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
275 |
EditorPanel.RefreshView(self) |
762
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
276 |
if self.ParamsEditor is not None: |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
277 |
self.ConfNodeName.ChangeValue(self.Controler.MandatoryParams[1].getName()) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
278 |
self.RefreshIECChannelControlsState() |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
279 |
self.RefreshConfNodeParamsSizer() |
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
280 |
|
738 | 281 |
def EnableScrolling(self, enable): |
282 |
self.ScrollingEnabled = enable |
|
283 |
||
284 |
def RefreshIECChannelControlsState(self): |
|
285 |
self.FullIECChannel.SetLabel(self.Controler.GetFullIEC_Channel()) |
|
286 |
self.IECCDownButton.Enable(self.Controler.BaseParams.getIEC_Channel() > 0) |
|
287 |
||
288 |
def RefreshConfNodeParamsSizer(self): |
|
289 |
self.Freeze() |
|
290 |
self.ConfNodeParamsSizer.Clear(True) |
|
291 |
||
292 |
confnode_infos = self.Controler.GetParamsAttributes() |
|
293 |
if len(confnode_infos) > 0: |
|
294 |
self.GenerateSizerElements(self.ConfNodeParamsSizer, confnode_infos, None, False) |
|
295 |
||
296 |
self.ParamsEditorSizer.Layout() |
|
297 |
self.Thaw() |
|
298 |
||
299 |
def GenerateMethodButtonSizer(self): |
|
300 |
normal_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["helv"]) |
|
301 |
mouseover_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, underline=True, faceName = faces["helv"]) |
|
302 |
||
303 |
msizer = wx.BoxSizer(wx.HORIZONTAL) |
|
304 |
||
305 |
for confnode_method in self.Controler.ConfNodeMethods: |
|
306 |
if "method" in confnode_method and confnode_method.get("shown",True): |
|
307 |
id = wx.NewId() |
|
308 |
label = confnode_method["name"] |
|
309 |
button = GenBitmapTextButton(id=id, parent=self.ParamsEditor, |
|
310 |
bitmap=wx.Bitmap(Bpath("images", "%s.png"%confnode_method.get("bitmap", "Unknown"))), label=label, |
|
311 |
name=label, pos=wx.DefaultPosition, style=wx.NO_BORDER) |
|
312 |
button.SetFont(normal_bt_font) |
|
313 |
button.SetToolTipString(confnode_method["tooltip"]) |
|
314 |
button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(confnode_method["method"]), id=id) |
|
315 |
# a fancy underline on mouseover |
|
316 |
def setFontStyle(b, s): |
|
317 |
def fn(event): |
|
318 |
b.SetFont(s) |
|
319 |
b.Refresh() |
|
320 |
event.Skip() |
|
321 |
return fn |
|
322 |
button.Bind(wx.EVT_ENTER_WINDOW, setFontStyle(button, mouseover_bt_font)) |
|
323 |
button.Bind(wx.EVT_LEAVE_WINDOW, setFontStyle(button, normal_bt_font)) |
|
324 |
#hack to force size to mini |
|
325 |
if not confnode_method.get("enabled",True): |
|
326 |
button.Disable() |
|
327 |
msizer.AddWindow(button, 0, border=0, flag=wx.ALIGN_CENTER) |
|
328 |
return msizer |
|
329 |
||
330 |
def GenerateSizerElements(self, sizer, elements, path, clean = True): |
|
331 |
if clean: |
|
332 |
sizer.Clear(True) |
|
333 |
first = True |
|
334 |
for element_infos in elements: |
|
335 |
if path: |
|
336 |
element_path = "%s.%s"%(path, element_infos["name"]) |
|
337 |
else: |
|
338 |
element_path = element_infos["name"] |
|
339 |
if element_infos["type"] == "element": |
|
340 |
label = element_infos["name"] |
|
341 |
staticbox = wx.StaticBox(id=-1, label=_(label), |
|
342 |
name='%s_staticbox'%element_infos["name"], parent=self.ParamsEditor, |
|
343 |
pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0) |
|
344 |
staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) |
|
345 |
if first: |
|
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
346 |
sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.TOP|wx.BOTTOM) |
738 | 347 |
else: |
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
348 |
sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.BOTTOM) |
738 | 349 |
self.GenerateSizerElements(staticboxsizer, element_infos["children"], element_path) |
350 |
else: |
|
351 |
boxsizer = wx.FlexGridSizer(cols=3, rows=1) |
|
352 |
boxsizer.AddGrowableCol(1) |
|
353 |
if first: |
|
354 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.ALL) |
|
355 |
else: |
|
356 |
sizer.AddSizer(boxsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM) |
|
357 |
staticbitmap = GenStaticBitmap(ID=-1, bitmapname="%s.png"%element_infos["name"], |
|
358 |
name="%s_bitmap"%element_infos["name"], parent=self.ParamsEditor, |
|
359 |
pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
|
360 |
boxsizer.AddWindow(staticbitmap, 0, border=5, flag=wx.RIGHT) |
|
361 |
label = element_infos["name"] |
|
362 |
statictext = wx.StaticText(id=-1, label="%s:"%_(label), |
|
363 |
name="%s_label"%element_infos["name"], parent=self.ParamsEditor, |
|
364 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
|
365 |
boxsizer.AddWindow(statictext, 0, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.RIGHT) |
|
366 |
id = wx.NewId() |
|
367 |
if isinstance(element_infos["type"], types.ListType): |
|
368 |
if isinstance(element_infos["value"], types.TupleType): |
|
369 |
browse_boxsizer = wx.BoxSizer(wx.HORIZONTAL) |
|
370 |
boxsizer.AddSizer(browse_boxsizer, 0, border=0, flag=0) |
|
371 |
||
372 |
textctrl = wx.TextCtrl(id=id, name=element_infos["name"], parent=self.ParamsEditor, |
|
373 |
pos=wx.Point(0, 0), size=wx.Size(275, 25), style=wx.TE_READONLY) |
|
374 |
if element_infos["value"] is not None: |
|
375 |
textctrl.SetValue(element_infos["value"][0]) |
|
376 |
value_infos = element_infos["value"][1] |
|
377 |
else: |
|
378 |
value_infos = None |
|
379 |
browse_boxsizer.AddWindow(textctrl, 0, border=0, flag=0) |
|
380 |
button_id = wx.NewId() |
|
381 |
button = wx.Button(id=button_id, name="browse_%s" % element_infos["name"], parent=self.ParamsEditor, |
|
382 |
label="...", pos=wx.Point(0, 0), size=wx.Size(25, 25)) |
|
383 |
browse_boxsizer.AddWindow(button, 0, border=0, flag=0) |
|
384 |
button.Bind(wx.EVT_BUTTON, |
|
385 |
self.GetBrowseCallBackFunction(element_infos["name"], textctrl, element_infos["type"], |
|
386 |
value_infos, element_path), |
|
387 |
id=button_id) |
|
388 |
else: |
|
389 |
combobox = wx.ComboBox(id=id, name=element_infos["name"], parent=self.ParamsEditor, |
|
390 |
pos=wx.Point(0, 0), size=wx.Size(300, 28), style=wx.CB_READONLY) |
|
391 |
boxsizer.AddWindow(combobox, 0, border=0, flag=0) |
|
392 |
if element_infos["use"] == "optional": |
|
393 |
combobox.Append("") |
|
394 |
if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType): |
|
395 |
for choice, xsdclass in element_infos["type"]: |
|
396 |
combobox.Append(choice) |
|
397 |
name = element_infos["name"] |
|
398 |
value = element_infos["value"] |
|
399 |
staticbox = wx.StaticBox(id=-1, label="%s - %s"%(_(name), _(value)), |
|
400 |
name='%s_staticbox'%element_infos["name"], parent=self.ParamsEditor, |
|
401 |
pos=wx.Point(0, 0), size=wx.Size(10, 0), style=0) |
|
402 |
staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) |
|
403 |
sizer.AddSizer(staticboxsizer, 0, border=5, flag=wx.GROW|wx.BOTTOM) |
|
404 |
self.GenerateSizerElements(staticboxsizer, element_infos["children"], element_path) |
|
405 |
callback = self.GetChoiceContentCallBackFunction(combobox, staticboxsizer, element_path) |
|
406 |
else: |
|
407 |
for choice in element_infos["type"]: |
|
408 |
combobox.Append(choice) |
|
409 |
callback = self.GetChoiceCallBackFunction(combobox, element_path) |
|
410 |
if element_infos["value"] is None: |
|
411 |
combobox.SetStringSelection("") |
|
412 |
else: |
|
413 |
combobox.SetStringSelection(element_infos["value"]) |
|
414 |
combobox.Bind(wx.EVT_COMBOBOX, callback, id=id) |
|
415 |
elif isinstance(element_infos["type"], types.DictType): |
|
416 |
scmin = -(2**31) |
|
417 |
scmax = 2**31-1 |
|
418 |
if "min" in element_infos["type"]: |
|
419 |
scmin = element_infos["type"]["min"] |
|
420 |
if "max" in element_infos["type"]: |
|
421 |
scmax = element_infos["type"]["max"] |
|
422 |
spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=self.ParamsEditor, |
|
423 |
pos=wx.Point(0, 0), size=wx.Size(300, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT) |
|
424 |
spinctrl.SetRange(scmin,scmax) |
|
425 |
boxsizer.AddWindow(spinctrl, 0, border=0, flag=0) |
|
426 |
if element_infos["value"] is not None: |
|
427 |
spinctrl.SetValue(element_infos["value"]) |
|
428 |
spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path), id=id) |
|
429 |
else: |
|
430 |
if element_infos["type"] == "boolean": |
|
431 |
checkbox = wx.CheckBox(id=id, name=element_infos["name"], parent=self.ParamsEditor, |
|
432 |
pos=wx.Point(0, 0), size=wx.Size(17, 25), style=0) |
|
433 |
boxsizer.AddWindow(checkbox, 0, border=0, flag=0) |
|
434 |
if element_infos["value"] is not None: |
|
435 |
checkbox.SetValue(element_infos["value"]) |
|
436 |
checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, element_path), id=id) |
|
437 |
elif element_infos["type"] in ["unsignedLong", "long","integer"]: |
|
438 |
if element_infos["type"].startswith("unsigned"): |
|
439 |
scmin = 0 |
|
440 |
else: |
|
441 |
scmin = -(2**31) |
|
442 |
scmax = 2**31-1 |
|
443 |
spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=self.ParamsEditor, |
|
444 |
pos=wx.Point(0, 0), size=wx.Size(300, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT) |
|
445 |
spinctrl.SetRange(scmin, scmax) |
|
446 |
boxsizer.AddWindow(spinctrl, 0, border=0, flag=0) |
|
447 |
if element_infos["value"] is not None: |
|
448 |
spinctrl.SetValue(element_infos["value"]) |
|
449 |
spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path), id=id) |
|
450 |
else: |
|
451 |
choices = self.ParentWindow.GetConfigEntry(element_path, [""]) |
|
452 |
textctrl = TextCtrlAutoComplete(id=id, |
|
453 |
name=element_infos["name"], |
|
454 |
parent=self.ParamsEditor, |
|
455 |
appframe=self, |
|
456 |
choices=choices, |
|
457 |
element_path=element_path, |
|
458 |
pos=wx.Point(0, 0), |
|
459 |
size=wx.Size(300, 25), |
|
460 |
style=0) |
|
461 |
||
462 |
boxsizer.AddWindow(textctrl, 0, border=0, flag=0) |
|
463 |
if element_infos["value"] is not None: |
|
464 |
textctrl.ChangeValue(str(element_infos["value"])) |
|
465 |
textctrl.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(textctrl, element_path)) |
|
466 |
first = False |
|
467 |
||
468 |
||
469 |
def GetItemChannelChangedFunction(self, dir): |
|
470 |
def OnConfNodeTreeItemChannelChanged(event): |
|
471 |
confnode_IECChannel = self.Controler.BaseParams.getIEC_Channel() |
|
472 |
res = self.SetConfNodeParamsAttribute("BaseParams.IEC_Channel", confnode_IECChannel + dir) |
|
473 |
wx.CallAfter(self.RefreshIECChannelControlsState) |
|
474 |
wx.CallAfter(self.ParentWindow._Refresh, TITLE, FILEMENU, PROJECTTREE) |
|
475 |
wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, self.GetTagName()) |
|
476 |
event.Skip() |
|
477 |
return OnConfNodeTreeItemChannelChanged |
|
478 |
||
479 |
def SetConfNodeParamsAttribute(self, *args, **kwargs): |
|
480 |
res, StructChanged = self.Controler.SetParamsAttribute(*args, **kwargs) |
|
481 |
if StructChanged: |
|
482 |
wx.CallAfter(self.RefreshConfNodeParamsSizer) |
|
483 |
wx.CallAfter(self.ParentWindow._Refresh, TITLE, FILEMENU) |
|
484 |
return res |
|
485 |
||
486 |
def GetButtonCallBackFunction(self, method): |
|
487 |
""" Generate the callbackfunc for a given confnode method""" |
|
488 |
def OnButtonClick(event): |
|
489 |
# Disable button to prevent re-entrant call |
|
490 |
event.GetEventObject().Disable() |
|
491 |
# Call |
|
492 |
getattr(self.Controler,method)() |
|
493 |
# Re-enable button |
|
494 |
event.GetEventObject().Enable() |
|
495 |
||
496 |
event.Skip() |
|
497 |
return OnButtonClick |
|
498 |
||
499 |
def GetChoiceCallBackFunction(self, choicectrl, path): |
|
500 |
def OnChoiceChanged(event): |
|
501 |
res = self.SetConfNodeParamsAttribute(path, choicectrl.GetStringSelection()) |
|
502 |
choicectrl.SetStringSelection(res) |
|
503 |
event.Skip() |
|
504 |
return OnChoiceChanged |
|
505 |
||
506 |
def GetChoiceContentCallBackFunction(self, choicectrl, staticboxsizer, path): |
|
507 |
def OnChoiceContentChanged(event): |
|
508 |
res = self.SetConfNodeParamsAttribute(path, choicectrl.GetStringSelection()) |
|
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
509 |
wx.CallAfter(self.RefreshConfNodeParamsSizer) |
738 | 510 |
event.Skip() |
511 |
return OnChoiceContentChanged |
|
512 |
||
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
513 |
def GetTextCtrlCallBackFunction(self, textctrl, path, refresh=False): |
738 | 514 |
def OnTextCtrlChanged(event): |
515 |
res = self.SetConfNodeParamsAttribute(path, textctrl.GetValue()) |
|
516 |
if res != textctrl.GetValue(): |
|
517 |
textctrl.ChangeValue(res) |
|
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
518 |
if refresh: |
738 | 519 |
wx.CallAfter(self.ParentWindow._Refresh, TITLE, FILEMENU, PROJECTTREE, PAGETITLES) |
520 |
wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, self.GetTagName()) |
|
521 |
event.Skip() |
|
522 |
return OnTextCtrlChanged |
|
523 |
||
524 |
def GetCheckBoxCallBackFunction(self, chkbx, path): |
|
525 |
def OnCheckBoxChanged(event): |
|
526 |
res = self.SetConfNodeParamsAttribute(path, chkbx.IsChecked()) |
|
527 |
chkbx.SetValue(res) |
|
528 |
event.Skip() |
|
529 |
return OnCheckBoxChanged |
|
530 |
||
531 |
def GetBrowseCallBackFunction(self, name, textctrl, library, value_infos, path): |
|
532 |
infos = [value_infos] |
|
533 |
def OnBrowseButton(event): |
|
534 |
dialog = BrowseValuesLibraryDialog(self, name, library, infos[0]) |
|
535 |
if dialog.ShowModal() == wx.ID_OK: |
|
536 |
value, value_infos = self.SetConfNodeParamsAttribute(path, dialog.GetValueInfos()) |
|
537 |
textctrl.ChangeValue(value) |
|
538 |
infos[0] = value_infos |
|
539 |
dialog.Destroy() |
|
540 |
event.Skip() |
|
541 |
return OnBrowseButton |
|
542 |
||
543 |
def OnWindowResize(self, event): |
|
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
544 |
self.ParamsEditor.GetBestSize() |
738 | 545 |
xstart, ystart = self.ParamsEditor.GetViewStart() |
546 |
window_size = self.ParamsEditor.GetClientSize() |
|
547 |
maxx, maxy = self.ParamsEditorSizer.GetMinSize() |
|
548 |
posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT)) |
|
549 |
posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT)) |
|
550 |
self.ParamsEditor.Scroll(posx, posy) |
|
551 |
self.ParamsEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, |
|
552 |
maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy) |
|
553 |
event.Skip() |
|
554 |
||
555 |
def OnMouseWheel(self, event): |
|
556 |
if self.ScrollingEnabled: |
|
557 |
event.Skip() |
|
558 |