35 from controls import TextCtrlAutoComplete |
35 from controls import TextCtrlAutoComplete |
36 from dialogs import BrowseValuesLibraryDialog |
36 from dialogs import BrowseValuesLibraryDialog |
37 from util.BitmapLibrary import GetBitmap |
37 from util.BitmapLibrary import GetBitmap |
38 |
38 |
39 if wx.Platform == '__WXMSW__': |
39 if wx.Platform == '__WXMSW__': |
40 faces = { 'times': 'Times New Roman', |
40 faces = { |
41 'mono' : 'Courier New', |
41 'times': 'Times New Roman', |
42 'helv' : 'Arial', |
42 'mono': 'Courier New', |
43 'other': 'Comic Sans MS', |
43 'helv': 'Arial', |
44 'size' : 16, |
44 'other': 'Comic Sans MS', |
45 } |
45 'size': 16, |
|
46 } |
46 else: |
47 else: |
47 faces = { 'times': 'Times', |
48 faces = { |
48 'mono' : 'Courier', |
49 'times': 'Times', |
49 'helv' : 'Helvetica', |
50 'mono': 'Courier', |
50 'other': 'new century schoolbook', |
51 'helv': 'Helvetica', |
51 'size' : 18, |
52 'other': 'new century schoolbook', |
52 } |
53 'size': 18, |
|
54 } |
53 |
55 |
54 SCROLLBAR_UNIT = 10 |
56 SCROLLBAR_UNIT = 10 |
|
57 |
55 |
58 |
56 class GenBitmapTextButton(wx.lib.buttons.GenBitmapTextButton): |
59 class GenBitmapTextButton(wx.lib.buttons.GenBitmapTextButton): |
57 def _GetLabelSize(self): |
60 def _GetLabelSize(self): |
58 """ used internally """ |
61 """ used internally """ |
59 w, h = self.GetTextExtent(self.GetLabel()) |
62 w, h = self.GetTextExtent(self.GetLabel()) |
69 width = w |
72 width = w |
70 return width, height, False |
73 return width, height, False |
71 |
74 |
72 def DrawLabel(self, dc, width, height, dw=0, dy=0): |
75 def DrawLabel(self, dc, width, height, dw=0, dy=0): |
73 bmp = self.bmpLabel |
76 bmp = self.bmpLabel |
74 if bmp != None: # if the bitmap is used |
77 if bmp is not None: # if the bitmap is used |
75 if self.bmpDisabled and not self.IsEnabled(): |
78 if self.bmpDisabled and not self.IsEnabled(): |
76 bmp = self.bmpDisabled |
79 bmp = self.bmpDisabled |
77 if self.bmpFocus and self.hasFocus: |
80 if self.bmpFocus and self.hasFocus: |
78 bmp = self.bmpFocus |
81 bmp = self.bmpFocus |
79 if self.bmpSelected and not self.up: |
82 if self.bmpSelected and not self.up: |
80 bmp = self.bmpSelected |
83 bmp = self.bmpSelected |
81 bw,bh = bmp.GetWidth(), bmp.GetHeight() |
84 bw, bh = bmp.GetWidth(), bmp.GetHeight() |
82 if not self.up: |
85 if not self.up: |
83 dw = dy = self.labelDelta |
86 dw = dy = self.labelDelta |
84 hasMask = bmp.GetMask() != None |
87 hasMask = bmp.GetMask() is not None |
85 else: |
88 else: |
86 bw = bh = 0 # no bitmap -> size is zero |
89 bw = bh = 0 # no bitmap -> size is zero |
87 |
90 |
88 dc.SetFont(self.GetFont()) |
91 dc.SetFont(self.GetFont()) |
89 if self.IsEnabled(): |
92 if self.IsEnabled(): |
96 if not self.up: |
99 if not self.up: |
97 dw = dy = self.labelDelta |
100 dw = dy = self.labelDelta |
98 |
101 |
99 pos_x = (width-bw)/2+dw # adjust for bitmap and text to centre |
102 pos_x = (width-bw)/2+dw # adjust for bitmap and text to centre |
100 pos_y = (height-bh-th)/2+dy |
103 pos_y = (height-bh-th)/2+dy |
101 if bmp !=None: |
104 if bmp is not None: |
102 dc.DrawBitmap(bmp, pos_x, pos_y, hasMask) # draw bitmap if available |
105 dc.DrawBitmap(bmp, pos_x, pos_y, hasMask) # draw bitmap if available |
103 pos_x = (width-tw)/2+dw # adjust for bitmap and text to centre |
106 pos_x = (width-tw)/2+dw # adjust for bitmap and text to centre |
104 pos_y += bh + 2 |
107 pos_y += bh + 2 |
105 |
108 |
106 dc.DrawText(label, pos_x, pos_y) # draw the text |
109 dc.DrawText(label, pos_x, pos_y) # draw the text |
107 |
110 |
108 |
111 |
109 class GenStaticBitmap(wx.StaticBitmap): |
112 class GenStaticBitmap(wx.StaticBitmap): |
110 """ Customized GenStaticBitmap, fix transparency redraw bug on wx2.8/win32, |
113 """ Customized GenStaticBitmap, fix transparency redraw bug on wx2.8/win32, |
111 and accept image name as __init__ parameter, fail silently if file do not exist""" |
114 and accept image name as __init__ parameter, fail silently if file do not exist""" |
112 def __init__(self, parent, ID, bitmapname, |
115 def __init__(self, parent, ID, bitmapname, |
113 pos = wx.DefaultPosition, size = wx.DefaultSize, |
116 pos=wx.DefaultPosition, size=wx.DefaultSize, |
114 style = 0, |
117 style=0, |
115 name = "genstatbmp"): |
118 name="genstatbmp"): |
116 |
119 |
117 bitmap = GetBitmap(bitmapname) |
120 bitmap = GetBitmap(bitmapname) |
118 if bitmap is None: |
121 if bitmap is None: |
119 bitmap = wx.EmptyBitmap(0, 0) |
122 bitmap = wx.EmptyBitmap(0, 0) |
120 |
123 |
121 wx.StaticBitmap.__init__(self, parent, ID, |
124 wx.StaticBitmap.__init__(self, parent, ID, |
122 bitmap, |
125 bitmap, |
123 pos, size, |
126 pos, size, |
124 style, |
127 style, |
125 name) |
128 name) |
|
129 |
126 |
130 |
127 class ConfTreeNodeEditor(EditorPanel): |
131 class ConfTreeNodeEditor(EditorPanel): |
128 |
132 |
129 SHOW_BASE_PARAMS = True |
133 SHOW_BASE_PARAMS = True |
130 SHOW_PARAMS = True |
134 SHOW_PARAMS = True |
135 if self.SHOW_PARAMS and len(self.Controler.GetParamsAttributes()) > 0: |
139 if self.SHOW_PARAMS and len(self.Controler.GetParamsAttributes()) > 0: |
136 tabs_num += 1 |
140 tabs_num += 1 |
137 |
141 |
138 if tabs_num > 1 or self.SHOW_BASE_PARAMS: |
142 if tabs_num > 1 or self.SHOW_BASE_PARAMS: |
139 self.Editor = wx.Panel(parent, |
143 self.Editor = wx.Panel(parent, |
140 style=wx.SUNKEN_BORDER|wx.SP_3D) |
144 style=wx.SUNKEN_BORDER | wx.SP_3D) |
141 |
145 |
142 self.MainSizer = wx.BoxSizer(wx.VERTICAL) |
146 self.MainSizer = wx.BoxSizer(wx.VERTICAL) |
143 |
147 |
144 if self.SHOW_BASE_PARAMS: |
148 if self.SHOW_BASE_PARAMS: |
145 baseparamseditor_sizer = wx.BoxSizer(wx.HORIZONTAL) |
149 baseparamseditor_sizer = wx.BoxSizer(wx.HORIZONTAL) |
146 self.MainSizer.AddSizer(baseparamseditor_sizer, border=5, |
150 self.MainSizer.AddSizer(baseparamseditor_sizer, border=5, |
147 flag=wx.GROW|wx.ALL) |
151 flag=wx.GROW | wx.ALL) |
148 |
152 |
149 self.FullIECChannel = wx.StaticText(self.Editor, -1) |
153 self.FullIECChannel = wx.StaticText(self.Editor, -1) |
150 self.FullIECChannel.SetFont( |
154 self.FullIECChannel.SetFont( |
151 wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, |
155 wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, |
152 wx.BOLD, faceName = faces["helv"])) |
156 wx.BOLD, faceName=faces["helv"])) |
153 baseparamseditor_sizer.AddWindow(self.FullIECChannel, |
157 baseparamseditor_sizer.AddWindow(self.FullIECChannel, |
154 flag=wx.ALIGN_CENTER_VERTICAL) |
158 flag=wx.ALIGN_CENTER_VERTICAL) |
155 |
159 |
156 updownsizer = wx.BoxSizer(wx.VERTICAL) |
160 updownsizer = wx.BoxSizer(wx.VERTICAL) |
157 baseparamseditor_sizer.AddSizer(updownsizer, border=5, |
161 baseparamseditor_sizer.AddSizer(updownsizer, border=5, |
158 flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL) |
162 flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL) |
159 |
163 |
160 self.IECCUpButton = wx.lib.buttons.GenBitmapTextButton(self.Editor, |
164 self.IECCUpButton = wx.lib.buttons.GenBitmapTextButton( |
161 bitmap=GetBitmap('IECCDown'), size=wx.Size(16, 16), style=wx.NO_BORDER) |
165 self.Editor, |
|
166 bitmap=GetBitmap('IECCDown'), |
|
167 size=wx.Size(16, 16), |
|
168 style=wx.NO_BORDER) |
162 self.IECCUpButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(1), |
169 self.IECCUpButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(1), |
163 self.IECCUpButton) |
170 self.IECCUpButton) |
164 updownsizer.AddWindow(self.IECCUpButton, flag=wx.ALIGN_LEFT) |
171 updownsizer.AddWindow(self.IECCUpButton, flag=wx.ALIGN_LEFT) |
165 |
172 |
166 self.IECCDownButton = wx.lib.buttons.GenBitmapButton(self.Editor, |
173 self.IECCDownButton = wx.lib.buttons.GenBitmapButton( |
167 bitmap=GetBitmap('IECCUp'), size=wx.Size(16, 16), style=wx.NO_BORDER) |
174 self.Editor, bitmap=GetBitmap('IECCUp'), |
|
175 size=wx.Size(16, 16), style=wx.NO_BORDER) |
168 self.IECCDownButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(-1), |
176 self.IECCDownButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(-1), |
169 self.IECCDownButton) |
177 self.IECCDownButton) |
170 updownsizer.AddWindow(self.IECCDownButton, flag=wx.ALIGN_LEFT) |
178 updownsizer.AddWindow(self.IECCDownButton, flag=wx.ALIGN_LEFT) |
171 |
179 |
172 self.ConfNodeName = wx.TextCtrl(self.Editor, |
180 self.ConfNodeName = wx.TextCtrl(self.Editor, |
173 size=wx.Size(150, 25)) |
181 size=wx.Size(150, 25)) |
174 self.ConfNodeName.SetFont( |
182 self.ConfNodeName.SetFont( |
175 wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, |
183 wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, |
176 wx.BOLD, faceName = faces["helv"])) |
184 wx.BOLD, faceName=faces["helv"])) |
177 self.ConfNodeName.Bind(wx.EVT_TEXT, |
185 self.ConfNodeName.Bind( |
178 self.GetTextCtrlCallBackFunction(self.ConfNodeName, "BaseParams.Name", True), |
186 wx.EVT_TEXT, |
179 self.ConfNodeName) |
187 self.GetTextCtrlCallBackFunction(self.ConfNodeName, "BaseParams.Name", True), |
180 baseparamseditor_sizer.AddWindow(self.ConfNodeName, border=5, |
188 self.ConfNodeName) |
181 flag=wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
189 baseparamseditor_sizer.AddWindow( |
|
190 self.ConfNodeName, border=5, |
|
191 flag=wx.LEFT | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL) |
182 |
192 |
183 buttons_sizer = self.GenerateMethodButtonSizer() |
193 buttons_sizer = self.GenerateMethodButtonSizer() |
184 baseparamseditor_sizer.AddSizer(buttons_sizer, flag=wx.ALIGN_CENTER) |
194 baseparamseditor_sizer.AddSizer(buttons_sizer, flag=wx.ALIGN_CENTER) |
185 |
195 |
186 if tabs_num > 1: |
196 if tabs_num > 1: |
205 else: |
215 else: |
206 self.Editor = editor |
216 self.Editor = editor |
207 |
217 |
208 if self.SHOW_PARAMS and len(self.Controler.GetParamsAttributes()) > 0: |
218 if self.SHOW_PARAMS and len(self.Controler.GetParamsAttributes()) > 0: |
209 |
219 |
210 panel_style = wx.TAB_TRAVERSAL|wx.HSCROLL|wx.VSCROLL |
220 panel_style = wx.TAB_TRAVERSAL | wx.HSCROLL | wx.VSCROLL |
211 if self.ConfNodeNoteBook is None and parent != self.Editor: |
221 if self.ConfNodeNoteBook is None and parent != self.Editor: |
212 panel_style |= wx.SUNKEN_BORDER |
222 panel_style |= wx.SUNKEN_BORDER |
213 self.ParamsEditor = wx.ScrolledWindow(parent, |
223 self.ParamsEditor = wx.ScrolledWindow(parent, |
214 style=panel_style) |
224 style=panel_style) |
215 self.ParamsEditor.Bind(wx.EVT_SIZE, self.OnParamsEditorResize) |
225 self.ParamsEditor.Bind(wx.EVT_SIZE, self.OnParamsEditorResize) |
216 self.ParamsEditor.Bind(wx.EVT_SCROLLWIN, self.OnParamsEditorScroll) |
226 self.ParamsEditor.Bind(wx.EVT_SCROLLWIN, self.OnParamsEditorScroll) |
217 |
227 |
218 self.ParamsEditorSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=5) |
228 self.ParamsEditorSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=5) |
219 self.ParamsEditorSizer.AddGrowableCol(0) |
229 self.ParamsEditorSizer.AddGrowableCol(0) |
220 self.ParamsEditorSizer.AddGrowableRow(0) |
230 self.ParamsEditorSizer.AddGrowableRow(0) |
221 self.ParamsEditor.SetSizer(self.ParamsEditorSizer) |
231 self.ParamsEditor.SetSizer(self.ParamsEditorSizer) |
222 |
232 |
223 self.ConfNodeParamsSizer = wx.BoxSizer(wx.VERTICAL) |
233 self.ConfNodeParamsSizer = wx.BoxSizer(wx.VERTICAL) |
224 self.ParamsEditorSizer.AddSizer(self.ConfNodeParamsSizer, border=5, |
234 self.ParamsEditorSizer.AddSizer(self.ConfNodeParamsSizer, border=5, |
225 flag=wx.LEFT|wx.RIGHT|wx.BOTTOM) |
235 flag=wx.LEFT | wx.RIGHT | wx.BOTTOM) |
226 |
236 |
227 self.RefreshConfNodeParamsSizer() |
237 self.RefreshConfNodeParamsSizer() |
228 |
238 |
229 if self.ConfNodeNoteBook is not None: |
239 if self.ConfNodeNoteBook is not None: |
230 self.ConfNodeNoteBook.AddPage(self.ParamsEditor, _("Config")) |
240 self.ConfNodeNoteBook.AddPage(self.ParamsEditor, _("Config")) |
292 |
302 |
293 self.ParamsEditorSizer.Layout() |
303 self.ParamsEditorSizer.Layout() |
294 self.Thaw() |
304 self.Thaw() |
295 |
305 |
296 def GenerateMethodButtonSizer(self): |
306 def GenerateMethodButtonSizer(self): |
297 normal_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["helv"]) |
307 normal_bt_font = wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName=faces["helv"]) |
298 mouseover_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, underline=True, faceName = faces["helv"]) |
308 mouseover_bt_font = wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName=faces["helv"], underline=True) |
299 |
309 |
300 msizer = wx.BoxSizer(wx.HORIZONTAL) |
310 msizer = wx.BoxSizer(wx.HORIZONTAL) |
301 |
311 |
302 for confnode_method in self.Controler.ConfNodeMethods: |
312 for confnode_method in self.Controler.ConfNodeMethods: |
303 if "method" in confnode_method and confnode_method.get("shown",True): |
313 if "method" in confnode_method and confnode_method.get("shown", True): |
304 button = GenBitmapTextButton(self.Editor, |
314 button = GenBitmapTextButton(self.Editor, |
305 bitmap=GetBitmap(confnode_method.get("bitmap", "Unknown")), |
315 bitmap=GetBitmap(confnode_method.get("bitmap", "Unknown")), |
306 label=confnode_method["name"], style=wx.NO_BORDER) |
316 label=confnode_method["name"], |
|
317 style=wx.NO_BORDER) |
307 button.SetFont(normal_bt_font) |
318 button.SetFont(normal_bt_font) |
308 button.SetToolTipString(confnode_method["tooltip"]) |
319 button.SetToolTipString(confnode_method["tooltip"]) |
309 if confnode_method.get("push", False): |
320 if confnode_method.get("push", False): |
310 button.Bind(wx.EVT_LEFT_DOWN, self.GetButtonCallBackFunction(confnode_method["method"], True)) |
321 button.Bind(wx.EVT_LEFT_DOWN, self.GetButtonCallBackFunction(confnode_method["method"], True)) |
311 else: |
322 else: |
312 button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(confnode_method["method"]), button) |
323 button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(confnode_method["method"]), button) |
313 # a fancy underline on mouseover |
324 # a fancy underline on mouseover |
|
325 |
314 def setFontStyle(b, s): |
326 def setFontStyle(b, s): |
315 def fn(event): |
327 def fn(event): |
316 b.SetFont(s) |
328 b.SetFont(s) |
317 b.Refresh() |
329 b.Refresh() |
318 event.Skip() |
330 event.Skip() |
319 return fn |
331 return fn |
320 button.Bind(wx.EVT_ENTER_WINDOW, setFontStyle(button, mouseover_bt_font)) |
332 button.Bind(wx.EVT_ENTER_WINDOW, setFontStyle(button, mouseover_bt_font)) |
321 button.Bind(wx.EVT_LEAVE_WINDOW, setFontStyle(button, normal_bt_font)) |
333 button.Bind(wx.EVT_LEAVE_WINDOW, setFontStyle(button, normal_bt_font)) |
322 #hack to force size to mini |
334 # hack to force size to mini |
323 if not confnode_method.get("enabled",True): |
335 if not confnode_method.get("enabled", True): |
324 button.Disable() |
336 button.Disable() |
325 msizer.AddWindow(button, flag=wx.ALIGN_CENTER) |
337 msizer.AddWindow(button, flag=wx.ALIGN_CENTER) |
326 return msizer |
338 return msizer |
327 |
339 |
328 def GenerateSizerElements(self, sizer, elements, path, clean = True): |
340 def GenerateSizerElements(self, sizer, elements, path, clean=True): |
329 if clean: |
341 if clean: |
330 sizer.Clear(True) |
342 sizer.Clear(True) |
331 first = True |
343 first = True |
332 for element_infos in elements: |
344 for element_infos in elements: |
333 if path: |
345 if path: |
334 element_path = "%s.%s"%(path, element_infos["name"]) |
346 element_path = "%s.%s" % (path, element_infos["name"]) |
335 else: |
347 else: |
336 element_path = element_infos["name"] |
348 element_path = element_infos["name"] |
337 if element_infos["type"] == "element": |
349 if element_infos["type"] == "element": |
338 name = element_infos["name"] |
350 name = element_infos["name"] |
339 value = element_infos["value"] |
351 value = element_infos["value"] |
340 label = _(name) |
352 label = _(name) |
341 if value is not None: |
353 if value is not None: |
342 label += " - %s" % _(value) |
354 label += " - %s" % _(value) |
343 staticbox = wx.StaticBox(self.ParamsEditor, |
355 staticbox = wx.StaticBox(self.ParamsEditor, |
344 label=_(label), size=wx.Size(10, 0)) |
356 label=_(label), size=wx.Size(10, 0)) |
345 staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) |
357 staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) |
346 flags = (wx.GROW | wx.BOTTOM | wx.LEFT | wx.RIGHT) |
358 flags = (wx.GROW | wx.BOTTOM | wx.LEFT | wx.RIGHT) |
347 if first: |
359 if first: |
348 flags |= wx.TOP |
360 flags |= wx.TOP |
349 sizer.AddSizer(staticboxsizer, border=5, flag=flags) |
361 sizer.AddSizer(staticboxsizer, border=5, flag=flags) |
355 boxsizer.AddGrowableCol(1) |
367 boxsizer.AddGrowableCol(1) |
356 flags = (wx.GROW | wx.BOTTOM | wx.LEFT | wx.RIGHT) |
368 flags = (wx.GROW | wx.BOTTOM | wx.LEFT | wx.RIGHT) |
357 if first: |
369 if first: |
358 flags |= wx.TOP |
370 flags |= wx.TOP |
359 sizer.AddSizer(boxsizer, border=5, flag=flags) |
371 sizer.AddSizer(boxsizer, border=5, flag=flags) |
360 staticbitmap = GenStaticBitmap(ID=-1, bitmapname=element_infos["name"], |
372 staticbitmap = GenStaticBitmap( |
361 name="%s_bitmap"%element_infos["name"], parent=self.ParamsEditor, |
373 ID=-1, bitmapname=element_infos["name"], |
|
374 name="%s_bitmap" % element_infos["name"], parent=self.ParamsEditor, |
362 pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
375 pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
363 boxsizer.AddWindow(staticbitmap, border=5, flag=wx.RIGHT) |
376 boxsizer.AddWindow(staticbitmap, border=5, flag=wx.RIGHT) |
364 |
377 |
365 statictext = wx.StaticText(self.ParamsEditor, |
378 statictext = wx.StaticText(self.ParamsEditor, |
366 label="%s:"%_(element_infos["name"])) |
379 label="%s:" % _(element_infos["name"])) |
367 boxsizer.AddWindow(statictext, border=5, |
380 boxsizer.AddWindow(statictext, border=5, |
368 flag=wx.ALIGN_CENTER_VERTICAL|wx.RIGHT) |
381 flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT) |
369 |
382 |
370 if isinstance(element_infos["type"], types.ListType): |
383 if isinstance(element_infos["type"], types.ListType): |
371 if isinstance(element_infos["value"], types.TupleType): |
384 if isinstance(element_infos["value"], types.TupleType): |
372 browse_boxsizer = wx.BoxSizer(wx.HORIZONTAL) |
385 browse_boxsizer = wx.BoxSizer(wx.HORIZONTAL) |
373 boxsizer.AddSizer(browse_boxsizer) |
386 boxsizer.AddSizer(browse_boxsizer) |
374 |
387 |
375 textctrl = wx.TextCtrl(self.ParamsEditor, |
388 textctrl = wx.TextCtrl(self.ParamsEditor, |
376 size=wx.Size(275, -1), style=wx.TE_READONLY) |
389 size=wx.Size(275, -1), style=wx.TE_READONLY) |
377 if element_infos["value"] is not None: |
390 if element_infos["value"] is not None: |
378 textctrl.SetValue(element_infos["value"][0]) |
391 textctrl.SetValue(element_infos["value"][0]) |
379 value_infos = element_infos["value"][1] |
392 value_infos = element_infos["value"][1] |
380 else: |
393 else: |
381 value_infos = None |
394 value_infos = None |
387 self.GetBrowseCallBackFunction(element_infos["name"], textctrl, element_infos["type"], |
400 self.GetBrowseCallBackFunction(element_infos["name"], textctrl, element_infos["type"], |
388 value_infos, element_path), |
401 value_infos, element_path), |
389 button) |
402 button) |
390 else: |
403 else: |
391 combobox = wx.ComboBox(self.ParamsEditor, |
404 combobox = wx.ComboBox(self.ParamsEditor, |
392 size=wx.Size(300, -1), style=wx.CB_READONLY) |
405 size=wx.Size(300, -1), style=wx.CB_READONLY) |
393 boxsizer.AddWindow(combobox) |
406 boxsizer.AddWindow(combobox) |
394 |
407 |
395 if element_infos["use"] == "optional": |
408 if element_infos["use"] == "optional": |
396 combobox.Append("") |
409 combobox.Append("") |
397 if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType): |
410 if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType): |
399 combobox.Append(choice) |
412 combobox.Append(choice) |
400 name = element_infos["name"] |
413 name = element_infos["name"] |
401 value = element_infos["value"] |
414 value = element_infos["value"] |
402 |
415 |
403 staticbox = wx.StaticBox(self.ParamsEditor, |
416 staticbox = wx.StaticBox(self.ParamsEditor, |
404 label="%s - %s"%(_(name), _(value)), size=wx.Size(10, 0)) |
417 label="%s - %s" % (_(name), _(value)), |
|
418 size=wx.Size(10, 0)) |
405 staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) |
419 staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) |
406 sizer.AddSizer(staticboxsizer, border=5, flag=wx.GROW | wx.BOTTOM | wx.LEFT | wx.RIGHT) |
420 sizer.AddSizer(staticboxsizer, border=5, flag=wx.GROW | wx.BOTTOM | wx.LEFT | wx.RIGHT) |
407 self.GenerateSizerElements(staticboxsizer, element_infos["children"], element_path) |
421 self.GenerateSizerElements(staticboxsizer, element_infos["children"], element_path) |
408 callback = self.GetChoiceContentCallBackFunction(combobox, staticboxsizer, element_path) |
422 callback = self.GetChoiceContentCallBackFunction(combobox, staticboxsizer, element_path) |
409 else: |
423 else: |
422 if "min" in element_infos["type"]: |
436 if "min" in element_infos["type"]: |
423 scmin = element_infos["type"]["min"] |
437 scmin = element_infos["type"]["min"] |
424 if "max" in element_infos["type"]: |
438 if "max" in element_infos["type"]: |
425 scmax = element_infos["type"]["max"] |
439 scmax = element_infos["type"]["max"] |
426 spinctrl = wx.SpinCtrl(self.ParamsEditor, |
440 spinctrl = wx.SpinCtrl(self.ParamsEditor, |
427 size=wx.Size(300, -1), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT) |
441 size=wx.Size(300, -1), |
|
442 style=wx.SP_ARROW_KEYS | wx.ALIGN_RIGHT) |
428 spinctrl.SetRange(scmin, scmax) |
443 spinctrl.SetRange(scmin, scmax) |
429 boxsizer.AddWindow(spinctrl) |
444 boxsizer.AddWindow(spinctrl) |
430 if element_infos["value"] is not None: |
445 if element_infos["value"] is not None: |
431 spinctrl.SetValue(element_infos["value"]) |
446 spinctrl.SetValue(element_infos["value"]) |
432 spinctrl.Bind(wx.EVT_SPINCTRL, |
447 spinctrl.Bind(wx.EVT_SPINCTRL, |
441 checkbox.SetValue(element_infos["value"]) |
456 checkbox.SetValue(element_infos["value"]) |
442 checkbox.Bind(wx.EVT_CHECKBOX, |
457 checkbox.Bind(wx.EVT_CHECKBOX, |
443 self.GetCheckBoxCallBackFunction(checkbox, element_path), |
458 self.GetCheckBoxCallBackFunction(checkbox, element_path), |
444 checkbox) |
459 checkbox) |
445 |
460 |
446 elif element_infos["type"] in ["unsignedLong", "long","integer"]: |
461 elif element_infos["type"] in ["unsignedLong", "long", "integer"]: |
447 if element_infos["type"].startswith("unsigned"): |
462 if element_infos["type"].startswith("unsigned"): |
448 scmin = 0 |
463 scmin = 0 |
449 else: |
464 else: |
450 scmin = -(2**31) |
465 scmin = -(2**31) |
451 scmax = 2**31-1 |
466 scmax = 2**31-1 |
452 spinctrl = wx.SpinCtrl(self.ParamsEditor, |
467 spinctrl = wx.SpinCtrl(self.ParamsEditor, |
453 size=wx.Size(300, -1), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT) |
468 size=wx.Size(300, -1), |
|
469 style=wx.SP_ARROW_KEYS | wx.ALIGN_RIGHT) |
454 spinctrl.SetRange(scmin, scmax) |
470 spinctrl.SetRange(scmin, scmax) |
455 boxsizer.AddWindow(spinctrl) |
471 boxsizer.AddWindow(spinctrl) |
456 if element_infos["value"] is not None: |
472 if element_infos["value"] is not None: |
457 spinctrl.SetValue(element_infos["value"]) |
473 spinctrl.SetValue(element_infos["value"]) |
458 spinctrl.Bind(wx.EVT_SPINCTRL, |
474 spinctrl.Bind(wx.EVT_SPINCTRL, |
545 event.Skip() |
560 event.Skip() |
546 return OnCheckBoxChanged |
561 return OnCheckBoxChanged |
547 |
562 |
548 def GetBrowseCallBackFunction(self, name, textctrl, library, value_infos, path): |
563 def GetBrowseCallBackFunction(self, name, textctrl, library, value_infos, path): |
549 infos = [value_infos] |
564 infos = [value_infos] |
|
565 |
550 def OnBrowseButton(event): |
566 def OnBrowseButton(event): |
551 dialog = BrowseValuesLibraryDialog(self, name, library, infos[0]) |
567 dialog = BrowseValuesLibraryDialog(self, name, library, infos[0]) |
552 if dialog.ShowModal() == wx.ID_OK: |
568 if dialog.ShowModal() == wx.ID_OK: |
553 value, value_infos = self.SetConfNodeParamsAttribute(path, dialog.GetValueInfos()) |
569 value, value_infos = self.SetConfNodeParamsAttribute(path, dialog.GetValueInfos()) |
554 textctrl.ChangeValue(value) |
570 textctrl.ChangeValue(value) |
564 maxx, maxy = self.ParamsEditorSizer.GetMinSize() |
580 maxx, maxy = self.ParamsEditorSizer.GetMinSize() |
565 posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT)) |
581 posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT)) |
566 posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT)) |
582 posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT)) |
567 self.ParamsEditor.Scroll(posx, posy) |
583 self.ParamsEditor.Scroll(posx, posy) |
568 self.ParamsEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, |
584 self.ParamsEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, |
569 maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy) |
585 maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, |
|
586 posx, posy) |
570 |
587 |
571 def OnParamsEditorResize(self, event): |
588 def OnParamsEditorResize(self, event): |
572 self.RefreshScrollbars() |
589 self.RefreshScrollbars() |
573 event.Skip() |
590 event.Skip() |
574 |
591 |