author | Laurent Bessard |
Wed, 27 Feb 2013 11:23:42 +0100 | |
changeset 948 | 89fead207c35 |
parent 920 | 1499a4d225db |
child 1055 | da483f620668 |
permissions | -rw-r--r-- |
738 | 1 |
|
2 |
import os |
|
3 |
import types |
|
4 |
||
5 |
import wx |
|
6 |
import wx.lib.buttons |
|
7 |
||
814 | 8 |
from EditorPanel import EditorPanel |
9 |
||
10 |
from IDEFrame import TITLE, FILEMENU, PROJECTTREE, PAGETITLES |
|
11 |
||
12 |
from controls import TextCtrlAutoComplete |
|
13 |
from dialogs import BrowseValuesLibraryDialog |
|
14 |
from util.BitmapLibrary import GetBitmap |
|
738 | 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 |
||
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
127 |
wx.lib.statbmp.GenStaticBitmap.__init__(self, parent, ID, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
128 |
GetBitmap(bitmapname), |
738 | 129 |
pos, size, |
130 |
style, |
|
131 |
name) |
|
132 |
||
133 |
def OnPaint(self, event): |
|
134 |
dc = wx.PaintDC(self) |
|
135 |
colour = self.GetParent().GetBackgroundColour() |
|
136 |
dc.SetPen(wx.Pen(colour)) |
|
137 |
dc.SetBrush(wx.Brush(colour )) |
|
138 |
dc.DrawRectangle(0, 0, *dc.GetSizeTuple()) |
|
139 |
if self._bitmap: |
|
140 |
dc.DrawBitmap(self._bitmap, 0, 0, True) |
|
141 |
||
142 |
class ConfTreeNodeEditor(EditorPanel): |
|
143 |
||
775
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
144 |
SHOW_BASE_PARAMS = True |
762
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
145 |
SHOW_PARAMS = True |
920
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
146 |
CONFNODEEDITOR_TABS = [] |
738 | 147 |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
148 |
def _init_Editor(self, parent): |
920
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
149 |
tabs_num = len(self.CONFNODEEDITOR_TABS) |
762
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
150 |
if self.SHOW_PARAMS: |
920
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
151 |
tabs_num += 1 |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
152 |
|
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
153 |
if tabs_num > 1: |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
154 |
self.Editor = wx.Panel(parent, |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
155 |
style=wx.SUNKEN_BORDER|wx.SP_3D) |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
156 |
|
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
157 |
main_sizer = wx.BoxSizer(wx.VERTICAL) |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
158 |
|
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
159 |
self.ConfNodeNoteBook = wx.Notebook(self.Editor) |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
160 |
parent = self.ConfNodeNoteBook |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
161 |
main_sizer.AddWindow(self.ConfNodeNoteBook, 1, flag=wx.GROW) |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
162 |
|
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
163 |
self.Editor.SetSizer(main_sizer) |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
164 |
else: |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
165 |
self.ConfNodeNoteBook = None |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
166 |
self.Editor = None |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
167 |
|
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
168 |
for title, create_func_name in self.CONFNODEEDITOR_TABS: |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
169 |
editor = getattr(self, create_func_name)(parent) |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
170 |
if self.ConfNodeNoteBook is not None: |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
171 |
self.ConfNodeNoteBook.AddPage(editor, title) |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
172 |
else: |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
173 |
self.Editor = editor |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
174 |
|
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
175 |
if self.SHOW_PARAMS: |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
176 |
|
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
177 |
panel_style = wx.TAB_TRAVERSAL|wx.HSCROLL|wx.VSCROLL |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
178 |
if self.ConfNodeNoteBook is None: |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
179 |
panel_style |= wx.SUNKEN_BORDER |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
180 |
self.ParamsEditor = wx.ScrolledWindow(parent, |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
181 |
style=panel_style) |
762
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
182 |
self.ParamsEditor.SetBackgroundColour(WINDOW_COLOUR) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
183 |
self.ParamsEditor.Bind(wx.EVT_SIZE, self.OnWindowResize) |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
184 |
self.ParamsEditor.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel) |
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 |
# 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
|
187 |
self.ScrollingEnabled = True |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
188 |
|
775
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
189 |
if self.SHOW_BASE_PARAMS: |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
190 |
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
|
191 |
self.ParamsEditorSizer.AddGrowableCol(0) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
192 |
self.ParamsEditorSizer.AddGrowableRow(1) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
193 |
|
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
194 |
self.ParamsEditor.SetSizer(self.ParamsEditorSizer) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
195 |
|
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
196 |
baseparamseditor_sizer = wx.BoxSizer(wx.HORIZONTAL) |
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
197 |
self.ParamsEditorSizer.AddSizer(baseparamseditor_sizer, border=5, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
198 |
flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.TOP) |
775
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 |
self.FullIECChannel = wx.StaticText(self.ParamsEditor, -1) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
201 |
self.FullIECChannel.SetFont( |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
202 |
wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
203 |
wx.BOLD, faceName = faces["helv"])) |
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
204 |
baseparamseditor_sizer.AddWindow(self.FullIECChannel, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
205 |
flag=wx.ALIGN_CENTER_VERTICAL) |
775
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
206 |
|
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
207 |
updownsizer = wx.BoxSizer(wx.VERTICAL) |
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
208 |
baseparamseditor_sizer.AddSizer(updownsizer, border=5, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
209 |
flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
210 |
|
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
211 |
self.IECCUpButton = wx.lib.buttons.GenBitmapTextButton(self.ParamsEditor, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
212 |
bitmap=GetBitmap('IECCDown'), size=wx.Size(16, 16), style=wx.NO_BORDER) |
775
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
213 |
self.IECCUpButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(1), |
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
214 |
self.IECCUpButton) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
215 |
updownsizer.AddWindow(self.IECCUpButton, flag=wx.ALIGN_LEFT) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
216 |
|
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
217 |
self.IECCDownButton = wx.lib.buttons.GenBitmapButton(self.ParamsEditor, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
218 |
bitmap=GetBitmap('IECCUp'), size=wx.Size(16, 16), style=wx.NO_BORDER) |
775
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
219 |
self.IECCDownButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(-1), |
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
220 |
self.IECCDownButton) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
221 |
updownsizer.AddWindow(self.IECCDownButton, flag=wx.ALIGN_LEFT) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
222 |
|
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
223 |
self.ConfNodeName = wx.TextCtrl(self.ParamsEditor, |
775
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
224 |
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
|
225 |
self.ConfNodeName.SetFont( |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
226 |
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
|
227 |
wx.BOLD, faceName = faces["helv"])) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
228 |
self.ConfNodeName.Bind(wx.EVT_TEXT, |
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
229 |
self.GetTextCtrlCallBackFunction(self.ConfNodeName, "BaseParams.Name", True), |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
230 |
self.ConfNodeName) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
231 |
baseparamseditor_sizer.AddWindow(self.ConfNodeName, border=5, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
232 |
flag=wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
775
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
233 |
|
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
234 |
buttons_sizer = self.GenerateMethodButtonSizer() |
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
235 |
baseparamseditor_sizer.AddSizer(buttons_sizer, flag=wx.ALIGN_CENTER) |
775
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
236 |
|
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
237 |
else: |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
238 |
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
|
239 |
self.ParamsEditorSizer.AddGrowableCol(0) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
240 |
self.ParamsEditorSizer.AddGrowableRow(0) |
762
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
241 |
|
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
242 |
self.ConfNodeParamsSizer = wx.BoxSizer(wx.VERTICAL) |
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
243 |
self.ParamsEditorSizer.AddSizer(self.ConfNodeParamsSizer, border=5, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
244 |
flag=wx.LEFT|wx.RIGHT|wx.BOTTOM) |
775
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
245 |
|
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
246 |
self.RefreshConfNodeParamsSizer() |
920
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
247 |
|
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
248 |
if self.ConfNodeNoteBook is not None: |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
249 |
self.ConfNodeNoteBook.AddPage(self.ParamsEditor, _("Config")) |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
250 |
else: |
1499a4d225db
Replaced SplitterWindow in ConfTreeNodeEditor by Notebook
Laurent Bessard
parents:
846
diff
changeset
|
251 |
self.Editor = self.ParamsEditor |
762
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
252 |
else: |
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
253 |
self.ParamsEditor = None |
738 | 254 |
|
743 | 255 |
def __init__(self, parent, controler, window, tagname=""): |
738 | 256 |
EditorPanel.__init__(self, parent, tagname, window, controler) |
743 | 257 |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
258 |
icon_name = self.Controler.GetIconName() |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
259 |
if icon_name is not None: |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
260 |
self.SetIcon(GetBitmap(icon_name)) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
261 |
else: |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
262 |
self.SetIcon(GetBitmap("Extension")) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
263 |
|
738 | 264 |
def __del__(self): |
265 |
self.Controler.OnCloseEditor(self) |
|
266 |
||
267 |
def GetTagName(self): |
|
268 |
return self.Controler.CTNFullName() |
|
269 |
||
270 |
def GetTitle(self): |
|
271 |
fullname = self.Controler.CTNFullName() |
|
272 |
if self.Controler.CTNTestModified(): |
|
273 |
return "~%s~" % fullname |
|
274 |
return fullname |
|
275 |
||
276 |
def HasNoModel(self): |
|
277 |
return False |
|
278 |
||
743 | 279 |
def GetBufferState(self): |
280 |
return False, False |
|
281 |
||
282 |
def Undo(self): |
|
283 |
pass |
|
284 |
||
285 |
def Redo(self): |
|
286 |
pass |
|
287 |
||
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
288 |
def RefreshView(self): |
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
289 |
EditorPanel.RefreshView(self) |
762
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
290 |
if self.ParamsEditor is not None: |
775
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
291 |
if self.SHOW_BASE_PARAMS: |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
292 |
self.ConfNodeName.ChangeValue(self.Controler.MandatoryParams[1].getName()) |
172be32a2482
Adding support for hiding node base params controls if needed
laurent
parents:
767
diff
changeset
|
293 |
self.RefreshIECChannelControlsState() |
762
aaacc83aa86b
Modifying canfestival plugin to following the new Beremiz confnode paradigm
laurent
parents:
751
diff
changeset
|
294 |
self.RefreshConfNodeParamsSizer() |
840
980863738cf6
Fix scroll bug in ConfNode params panel when changing tab selection on Windows
Laurent Bessard
parents:
814
diff
changeset
|
295 |
self.RefreshScrollbars() |
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
296 |
|
738 | 297 |
def EnableScrolling(self, enable): |
298 |
self.ScrollingEnabled = enable |
|
299 |
||
300 |
def RefreshIECChannelControlsState(self): |
|
301 |
self.FullIECChannel.SetLabel(self.Controler.GetFullIEC_Channel()) |
|
302 |
self.IECCDownButton.Enable(self.Controler.BaseParams.getIEC_Channel() > 0) |
|
303 |
||
304 |
def RefreshConfNodeParamsSizer(self): |
|
305 |
self.Freeze() |
|
306 |
self.ConfNodeParamsSizer.Clear(True) |
|
307 |
||
308 |
confnode_infos = self.Controler.GetParamsAttributes() |
|
309 |
if len(confnode_infos) > 0: |
|
310 |
self.GenerateSizerElements(self.ConfNodeParamsSizer, confnode_infos, None, False) |
|
311 |
||
312 |
self.ParamsEditorSizer.Layout() |
|
313 |
self.Thaw() |
|
314 |
||
315 |
def GenerateMethodButtonSizer(self): |
|
316 |
normal_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["helv"]) |
|
317 |
mouseover_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, underline=True, faceName = faces["helv"]) |
|
318 |
||
319 |
msizer = wx.BoxSizer(wx.HORIZONTAL) |
|
320 |
||
321 |
for confnode_method in self.Controler.ConfNodeMethods: |
|
322 |
if "method" in confnode_method and confnode_method.get("shown",True): |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
323 |
button = GenBitmapTextButton(self.ParamsEditor, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
324 |
bitmap=GetBitmap(confnode_method.get("bitmap", "Unknown")), |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
325 |
label=confnode_method["name"], style=wx.NO_BORDER) |
738 | 326 |
button.SetFont(normal_bt_font) |
327 |
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
|
328 |
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
|
329 |
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
|
330 |
else: |
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
331 |
button.Bind(wx.EVT_BUTTON, self.GetButtonCallBackFunction(confnode_method["method"]), button) |
738 | 332 |
# a fancy underline on mouseover |
333 |
def setFontStyle(b, s): |
|
334 |
def fn(event): |
|
335 |
b.SetFont(s) |
|
336 |
b.Refresh() |
|
337 |
event.Skip() |
|
338 |
return fn |
|
339 |
button.Bind(wx.EVT_ENTER_WINDOW, setFontStyle(button, mouseover_bt_font)) |
|
340 |
button.Bind(wx.EVT_LEAVE_WINDOW, setFontStyle(button, normal_bt_font)) |
|
341 |
#hack to force size to mini |
|
342 |
if not confnode_method.get("enabled",True): |
|
343 |
button.Disable() |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
344 |
msizer.AddWindow(button, flag=wx.ALIGN_CENTER) |
738 | 345 |
return msizer |
346 |
||
347 |
def GenerateSizerElements(self, sizer, elements, path, clean = True): |
|
348 |
if clean: |
|
349 |
sizer.Clear(True) |
|
350 |
first = True |
|
351 |
for element_infos in elements: |
|
352 |
if path: |
|
353 |
element_path = "%s.%s"%(path, element_infos["name"]) |
|
354 |
else: |
|
355 |
element_path = element_infos["name"] |
|
356 |
if element_infos["type"] == "element": |
|
357 |
label = element_infos["name"] |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
358 |
staticbox = wx.StaticBox(self.ParamsEditor, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
359 |
label=_(label), size=wx.Size(10, 0)) |
738 | 360 |
staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) |
361 |
if first: |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
362 |
sizer.AddSizer(staticboxsizer, border=5, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
363 |
flag=wx.GROW|wx.TOP|wx.BOTTOM) |
738 | 364 |
else: |
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
365 |
sizer.AddSizer(staticboxsizer, border=5, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
366 |
flag=wx.GROW|wx.BOTTOM) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
367 |
self.GenerateSizerElements(staticboxsizer, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
368 |
element_infos["children"], |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
369 |
element_path) |
738 | 370 |
else: |
371 |
boxsizer = wx.FlexGridSizer(cols=3, rows=1) |
|
372 |
boxsizer.AddGrowableCol(1) |
|
373 |
if first: |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
374 |
sizer.AddSizer(boxsizer, border=5, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
375 |
flag=wx.GROW|wx.ALL) |
738 | 376 |
else: |
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
377 |
sizer.AddSizer(boxsizer, border=5, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
378 |
flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
379 |
|
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
380 |
staticbitmap = GenStaticBitmap(ID=-1, bitmapname=element_infos["name"], |
738 | 381 |
name="%s_bitmap"%element_infos["name"], parent=self.ParamsEditor, |
382 |
pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0) |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
383 |
boxsizer.AddWindow(staticbitmap, border=5, flag=wx.RIGHT) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
384 |
|
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
385 |
statictext = wx.StaticText(self.ParamsEditor, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
386 |
label="%s:"%_(element_infos["name"])) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
387 |
boxsizer.AddWindow(statictext, border=5, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
388 |
flag=wx.ALIGN_CENTER_VERTICAL|wx.RIGHT) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
389 |
|
738 | 390 |
if isinstance(element_infos["type"], types.ListType): |
391 |
if isinstance(element_infos["value"], types.TupleType): |
|
392 |
browse_boxsizer = wx.BoxSizer(wx.HORIZONTAL) |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
393 |
boxsizer.AddSizer(browse_boxsizer) |
738 | 394 |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
395 |
textctrl = wx.TextCtrl(self.ParamsEditor, |
846
26836e421e19
Fix ConfTreeNodeEditor parameters controls size on Windows
laurent
parents:
844
diff
changeset
|
396 |
size=wx.Size(275, -1), style=wx.TE_READONLY) |
738 | 397 |
if element_infos["value"] is not None: |
398 |
textctrl.SetValue(element_infos["value"][0]) |
|
399 |
value_infos = element_infos["value"][1] |
|
400 |
else: |
|
401 |
value_infos = None |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
402 |
browse_boxsizer.AddWindow(textctrl) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
403 |
|
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
404 |
button = wx.Button(self.ParamsEditor, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
405 |
label="...", size=wx.Size(25, 25)) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
406 |
browse_boxsizer.AddWindow(button) |
738 | 407 |
button.Bind(wx.EVT_BUTTON, |
408 |
self.GetBrowseCallBackFunction(element_infos["name"], textctrl, element_infos["type"], |
|
409 |
value_infos, element_path), |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
410 |
button) |
738 | 411 |
else: |
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
412 |
combobox = wx.ComboBox(self.ParamsEditor, |
846
26836e421e19
Fix ConfTreeNodeEditor parameters controls size on Windows
laurent
parents:
844
diff
changeset
|
413 |
size=wx.Size(300, -1), style=wx.CB_READONLY) |
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
414 |
boxsizer.AddWindow(combobox) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
415 |
|
738 | 416 |
if element_infos["use"] == "optional": |
417 |
combobox.Append("") |
|
418 |
if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType): |
|
419 |
for choice, xsdclass in element_infos["type"]: |
|
420 |
combobox.Append(choice) |
|
421 |
name = element_infos["name"] |
|
422 |
value = element_infos["value"] |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
423 |
|
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
424 |
staticbox = wx.StaticBox(self.ParamsEditor, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
425 |
label="%s - %s"%(_(name), _(value)), size=wx.Size(10, 0)) |
738 | 426 |
staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL) |
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
427 |
sizer.AddSizer(staticboxsizer, border=5, flag=wx.GROW|wx.BOTTOM) |
738 | 428 |
self.GenerateSizerElements(staticboxsizer, element_infos["children"], element_path) |
429 |
callback = self.GetChoiceContentCallBackFunction(combobox, staticboxsizer, element_path) |
|
430 |
else: |
|
431 |
for choice in element_infos["type"]: |
|
432 |
combobox.Append(choice) |
|
433 |
callback = self.GetChoiceCallBackFunction(combobox, element_path) |
|
434 |
if element_infos["value"] is None: |
|
435 |
combobox.SetStringSelection("") |
|
436 |
else: |
|
437 |
combobox.SetStringSelection(element_infos["value"]) |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
438 |
combobox.Bind(wx.EVT_COMBOBOX, callback, combobox) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
439 |
|
738 | 440 |
elif isinstance(element_infos["type"], types.DictType): |
441 |
scmin = -(2**31) |
|
442 |
scmax = 2**31-1 |
|
443 |
if "min" in element_infos["type"]: |
|
444 |
scmin = element_infos["type"]["min"] |
|
445 |
if "max" in element_infos["type"]: |
|
446 |
scmax = element_infos["type"]["max"] |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
447 |
spinctrl = wx.SpinCtrl(self.ParamsEditor, |
846
26836e421e19
Fix ConfTreeNodeEditor parameters controls size on Windows
laurent
parents:
844
diff
changeset
|
448 |
size=wx.Size(300, -1), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT) |
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
449 |
spinctrl.SetRange(scmin, scmax) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
450 |
boxsizer.AddWindow(spinctrl) |
738 | 451 |
if element_infos["value"] is not None: |
452 |
spinctrl.SetValue(element_infos["value"]) |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
453 |
spinctrl.Bind(wx.EVT_SPINCTRL, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
454 |
self.GetTextCtrlCallBackFunction(spinctrl, element_path), |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
455 |
spinctrl) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
456 |
|
738 | 457 |
else: |
458 |
if element_infos["type"] == "boolean": |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
459 |
checkbox = wx.CheckBox(self.ParamsEditor, size=wx.Size(17, 25)) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
460 |
boxsizer.AddWindow(checkbox) |
738 | 461 |
if element_infos["value"] is not None: |
462 |
checkbox.SetValue(element_infos["value"]) |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
463 |
checkbox.Bind(wx.EVT_CHECKBOX, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
464 |
self.GetCheckBoxCallBackFunction(checkbox, element_path), |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
465 |
checkbox) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
466 |
|
738 | 467 |
elif element_infos["type"] in ["unsignedLong", "long","integer"]: |
468 |
if element_infos["type"].startswith("unsigned"): |
|
469 |
scmin = 0 |
|
470 |
else: |
|
471 |
scmin = -(2**31) |
|
472 |
scmax = 2**31-1 |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
473 |
spinctrl = wx.SpinCtrl(self.ParamsEditor, |
846
26836e421e19
Fix ConfTreeNodeEditor parameters controls size on Windows
laurent
parents:
844
diff
changeset
|
474 |
size=wx.Size(300, -1), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT) |
738 | 475 |
spinctrl.SetRange(scmin, scmax) |
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
476 |
boxsizer.AddWindow(spinctrl) |
738 | 477 |
if element_infos["value"] is not None: |
478 |
spinctrl.SetValue(element_infos["value"]) |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
479 |
spinctrl.Bind(wx.EVT_SPINCTRL, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
480 |
self.GetTextCtrlCallBackFunction(spinctrl, element_path), |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
481 |
spinctrl) |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
482 |
|
738 | 483 |
else: |
484 |
choices = self.ParentWindow.GetConfigEntry(element_path, [""]) |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
485 |
textctrl = TextCtrlAutoComplete(name=element_infos["name"], |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
486 |
parent=self.ParamsEditor, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
487 |
appframe=self, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
488 |
choices=choices, |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
489 |
element_path=element_path, |
846
26836e421e19
Fix ConfTreeNodeEditor parameters controls size on Windows
laurent
parents:
844
diff
changeset
|
490 |
size=wx.Size(300, -1)) |
738 | 491 |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
775
diff
changeset
|
492 |
boxsizer.AddWindow(textctrl) |
738 | 493 |
if element_infos["value"] is not None: |
494 |
textctrl.ChangeValue(str(element_infos["value"])) |
|
495 |
textctrl.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(textctrl, element_path)) |
|
496 |
first = False |
|
497 |
||
498 |
||
499 |
def GetItemChannelChangedFunction(self, dir): |
|
500 |
def OnConfNodeTreeItemChannelChanged(event): |
|
501 |
confnode_IECChannel = self.Controler.BaseParams.getIEC_Channel() |
|
502 |
res = self.SetConfNodeParamsAttribute("BaseParams.IEC_Channel", confnode_IECChannel + dir) |
|
503 |
wx.CallAfter(self.RefreshIECChannelControlsState) |
|
504 |
wx.CallAfter(self.ParentWindow._Refresh, TITLE, FILEMENU, PROJECTTREE) |
|
505 |
wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, self.GetTagName()) |
|
506 |
event.Skip() |
|
507 |
return OnConfNodeTreeItemChannelChanged |
|
508 |
||
509 |
def SetConfNodeParamsAttribute(self, *args, **kwargs): |
|
510 |
res, StructChanged = self.Controler.SetParamsAttribute(*args, **kwargs) |
|
511 |
if StructChanged: |
|
512 |
wx.CallAfter(self.RefreshConfNodeParamsSizer) |
|
513 |
wx.CallAfter(self.ParentWindow._Refresh, TITLE, FILEMENU) |
|
514 |
return res |
|
515 |
||
767
36e823a90d94
Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents:
762
diff
changeset
|
516 |
def GetButtonCallBackFunction(self, method, push=False): |
738 | 517 |
""" Generate the callbackfunc for a given confnode method""" |
518 |
def OnButtonClick(event): |
|
519 |
# Disable button to prevent re-entrant call |
|
520 |
event.GetEventObject().Disable() |
|
521 |
# Call |
|
522 |
getattr(self.Controler,method)() |
|
523 |
# Re-enable button |
|
524 |
event.GetEventObject().Enable() |
|
525 |
||
767
36e823a90d94
Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents:
762
diff
changeset
|
526 |
if not push: |
36e823a90d94
Adding support for push buttons (EVT_LEFT_DOWN is bind instead of EVT_BUTTON)
laurent
parents:
762
diff
changeset
|
527 |
event.Skip() |
738 | 528 |
return OnButtonClick |
529 |
||
530 |
def GetChoiceCallBackFunction(self, choicectrl, path): |
|
531 |
def OnChoiceChanged(event): |
|
532 |
res = self.SetConfNodeParamsAttribute(path, choicectrl.GetStringSelection()) |
|
533 |
choicectrl.SetStringSelection(res) |
|
534 |
event.Skip() |
|
535 |
return OnChoiceChanged |
|
536 |
||
537 |
def GetChoiceContentCallBackFunction(self, choicectrl, staticboxsizer, path): |
|
538 |
def OnChoiceContentChanged(event): |
|
539 |
res = self.SetConfNodeParamsAttribute(path, choicectrl.GetStringSelection()) |
|
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
540 |
wx.CallAfter(self.RefreshConfNodeParamsSizer) |
738 | 541 |
event.Skip() |
542 |
return OnChoiceContentChanged |
|
543 |
||
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
544 |
def GetTextCtrlCallBackFunction(self, textctrl, path, refresh=False): |
738 | 545 |
def OnTextCtrlChanged(event): |
546 |
res = self.SetConfNodeParamsAttribute(path, textctrl.GetValue()) |
|
547 |
if res != textctrl.GetValue(): |
|
844
ec9e6ef49878
Fixing bug when spinctrl new value is changed by ConfTreeNode
laurent
parents:
840
diff
changeset
|
548 |
if isinstance(textctrl, wx.SpinCtrl): |
ec9e6ef49878
Fixing bug when spinctrl new value is changed by ConfTreeNode
laurent
parents:
840
diff
changeset
|
549 |
textctrl.SetValue(res) |
ec9e6ef49878
Fixing bug when spinctrl new value is changed by ConfTreeNode
laurent
parents:
840
diff
changeset
|
550 |
else: |
ec9e6ef49878
Fixing bug when spinctrl new value is changed by ConfTreeNode
laurent
parents:
840
diff
changeset
|
551 |
textctrl.ChangeValue(res) |
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
552 |
if refresh: |
738 | 553 |
wx.CallAfter(self.ParentWindow._Refresh, TITLE, FILEMENU, PROJECTTREE, PAGETITLES) |
554 |
wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, self.GetTagName()) |
|
555 |
event.Skip() |
|
556 |
return OnTextCtrlChanged |
|
557 |
||
558 |
def GetCheckBoxCallBackFunction(self, chkbx, path): |
|
559 |
def OnCheckBoxChanged(event): |
|
560 |
res = self.SetConfNodeParamsAttribute(path, chkbx.IsChecked()) |
|
561 |
chkbx.SetValue(res) |
|
562 |
event.Skip() |
|
563 |
return OnCheckBoxChanged |
|
564 |
||
565 |
def GetBrowseCallBackFunction(self, name, textctrl, library, value_infos, path): |
|
566 |
infos = [value_infos] |
|
567 |
def OnBrowseButton(event): |
|
568 |
dialog = BrowseValuesLibraryDialog(self, name, library, infos[0]) |
|
569 |
if dialog.ShowModal() == wx.ID_OK: |
|
570 |
value, value_infos = self.SetConfNodeParamsAttribute(path, dialog.GetValueInfos()) |
|
571 |
textctrl.ChangeValue(value) |
|
572 |
infos[0] = value_infos |
|
573 |
dialog.Destroy() |
|
574 |
event.Skip() |
|
575 |
return OnBrowseButton |
|
576 |
||
840
980863738cf6
Fix scroll bug in ConfNode params panel when changing tab selection on Windows
Laurent Bessard
parents:
814
diff
changeset
|
577 |
def RefreshScrollbars(self): |
746
2e09777a40d3
Fix refresh of ConfTreeNodeEditors content when values change
laurent
parents:
744
diff
changeset
|
578 |
self.ParamsEditor.GetBestSize() |
738 | 579 |
xstart, ystart = self.ParamsEditor.GetViewStart() |
580 |
window_size = self.ParamsEditor.GetClientSize() |
|
581 |
maxx, maxy = self.ParamsEditorSizer.GetMinSize() |
|
582 |
posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT)) |
|
583 |
posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT)) |
|
584 |
self.ParamsEditor.Scroll(posx, posy) |
|
585 |
self.ParamsEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, |
|
586 |
maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy) |
|
840
980863738cf6
Fix scroll bug in ConfNode params panel when changing tab selection on Windows
Laurent Bessard
parents:
814
diff
changeset
|
587 |
|
980863738cf6
Fix scroll bug in ConfNode params panel when changing tab selection on Windows
Laurent Bessard
parents:
814
diff
changeset
|
588 |
def OnWindowResize(self, event): |
980863738cf6
Fix scroll bug in ConfNode params panel when changing tab selection on Windows
Laurent Bessard
parents:
814
diff
changeset
|
589 |
self.RefreshScrollbars() |
738 | 590 |
event.Skip() |
591 |
||
592 |
def OnMouseWheel(self, event): |
|
593 |
if self.ScrollingEnabled: |
|
594 |
event.Skip() |
|
595 |