2 # Purpose: XRC editor, Panel class and related
3 # Author: Roman Rolinsky <rolinsky@mema.ucl.ac.be>
7 from xxx
import * # xxx imports globals and params
9 from wxPython
.html
import wxHtmlWindow
11 # Properties panel containing notebook
12 class Panel(wxNotebook
):
13 def __init__(self
, parent
, id = -1):
14 if wxPlatform
!= '__WXMAC__': # some problems with this style on macs
15 wxNotebook
.__init
__(self
, parent
, id, style
=wxNB_BOTTOM
)
17 wxNotebook
.__init
__(self
, parent
, id)
19 g
.panel
= panel
= self
22 # Set common button size for parameter buttons
23 bTmp
= wxButton(self
, -1, '')
25 params
.buttonSize
= (self
.DLG_SZE(buttonSize
)[0], bTmp
.GetSize()[1])
29 # List of child windows
31 # Create scrolled windows for pages
32 self
.page1
= wxScrolledWindow(self
, -1)
34 sizer
.Add(wxBoxSizer()) # dummy sizer
35 self
.page1
.SetAutoLayout(True)
36 self
.page1
.SetSizer(sizer
)
37 self
.AddPage(self
.page1
, 'Properties')
39 self
.page2
= wxScrolledWindow(self
, -1)
41 sizer
.Add(wxBoxSizer()) # dummy sizer
42 self
.page2
.SetAutoLayout(True)
43 self
.page2
.SetSizer(sizer
)
45 # Delete child windows and recreate page sizer
46 def ResetPage(self
, page
):
47 topSizer
= page
.GetSizer()
48 sizer
= topSizer
.GetChildren()[0].GetSizer()
49 for w
in page
.GetChildren():
52 topSizer
.Remove(sizer
)
54 sizer
= wxBoxSizer(wxVERTICAL
)
55 # Special case - resize html window
57 topSizer
.Add(sizer
, 1, wxEXPAND
)
59 topSizer
.Add(sizer
, 0, wxALL
, 5)
62 def SetData(self
, xxx
):
65 # Remove current objects and sizer
66 sizer
= self
.ResetPage(self
.page1
)
67 if not xxx
or (not xxx
.allParams
and not xxx
.hasName
):
69 sizer
.Add(wxStaticText(self
.page1
, -1, 'This item has no properties.'))
70 else: # nothing selected
71 # If first time, show some help
73 html
= wxHtmlWindow(self
.page1
, -1, wxDefaultPosition
,
74 wxDefaultSize
, wxSUNKEN_BORDER
)
75 html
.SetPage(g
.helpText
)
76 sizer
.Add(html
, 1, wxEXPAND
)
79 sizer
.Add(wxStaticText(self
.page1
, -1, 'Select a tree item.'))
81 g
.currentXXX
= xxx
.treeObject()
82 # Normal or SizerItem page
83 isGBSizerItem
= isinstance(xxx
.parent
, xxxGridBagSizer
)
84 page
= PropPage(self
.page1
, xxx
.panelName(), xxx
)
86 self
.pages
.append(page
)
87 sizer
.Add(page
, 1, wxEXPAND
)
89 # Special label for child objects - they may have different GUI
90 page
= PropPage(self
.page1
, xxx
.child
.panelName(), xxx
.child
)
91 page
.SetValues(xxx
.child
)
92 self
.pages
.append(page
)
93 sizer
.Add(page
, 0, wxEXPAND | wxTOP
, 5)
95 size
= self
.page1
.GetSizer().GetMinSize()
96 self
.page1
.SetScrollbars(1, 1, size
.width
, size
.height
, 0, 0, True)
99 # Create if does not exist
100 if xxx
and xxx
.treeObject().hasStyle
:
101 xxx
= xxx
.treeObject()
102 # Simplest case: set data if class is the same
103 sizer
= self
.ResetPage(self
.page2
)
104 page
= StylePage(self
.page2
, xxx
.className
+ ' style', xxx
)
106 self
.pages
.append(page
)
107 sizer
.Add(page
, 0, wxEXPAND
)
108 # Add page if not exists
109 if not self
.GetPageCount() == 2:
110 self
.AddPage(self
.page2
, 'Style')
112 size
= self
.page2
.GetSizer().GetMinSize()
113 self
.page2
.SetScrollbars(1, 1, size
.width
, size
.height
, 0, 0, True)
115 # Remove page if exists
116 if self
.GetPageCount() == 2:
120 self
.modified
= False
123 self
.modified
= False
124 # If some parameter has changed
125 def IsModified(self
):
127 def SetModified(self
, value
):
128 # Register undo object when modifying first time
129 if not self
.modified
and value
:
130 g
.undoMan
.RegisterUndo(UndoEdit())
131 self
.modified
= value
133 for p
in self
.pages
: p
.Apply()
135 ################################################################################
137 # General class for notebook pages
138 class ParamPage(wxPanel
):
139 def __init__(self
, parent
, xxx
):
140 wxPanel
.__init
__(self
, parent
, -1)
141 self
.SetBackgroundColour(parent
.GetBackgroundColour())
142 self
.SetForegroundColour(parent
.GetForegroundColour())
144 # Register event handlers
145 for id in paramIDs
.values():
146 EVT_CHECKBOX(self
, id, self
.OnCheckParams
)
148 self
.controls
= {} # save python objects
149 self
.controlName
= None
151 def OnCheckParams(self
, evt
):
153 param
= evt
.GetEventObject().GetName()
154 w
= self
.controls
[param
]
156 objElem
= xxx
.element
158 # Ad new text node in order of allParams
159 w
.SetValue('') # set empty (default) value
160 w
.SetModified() # mark as changed
161 elem
= g
.tree
.dom
.createElement(param
)
162 # Some classes are special
164 xxx
.params
[param
] = xxxParamFont(xxx
.element
, elem
)
165 elif param
in xxxObject
.bitmapTags
:
166 xxx
.params
[param
] = xxxParamBitmap(elem
)
168 xxx
.params
[param
] = xxxParam(elem
)
169 # Find place to put new element: first present element after param
171 paramStyles
= xxx
.allParams
+ xxx
.styles
172 for p
in paramStyles
[paramStyles
.index(param
) + 1:]:
173 # Content params don't have same type
174 if xxx
.params
.has_key(p
) and p
!= 'content':
178 nextTextElem
= xxx
.params
[p
].node
179 objElem
.insertBefore(elem
, nextTextElem
)
181 objElem
.appendChild(elem
)
184 xxx
.params
[param
].remove()
185 del xxx
.params
[param
]
187 w
.modified
= False # mark as not changed
189 # Set modified flag (provokes undo storing is necessary)
190 panel
.SetModified(True)
194 name
= self
.controlName
.GetValue()
197 xxx
.element
.setAttribute('name', name
)
198 for param
, w
in self
.controls
.items():
200 paramObj
= xxx
.params
[param
]
202 if param
in xxx
.specials
:
203 xxx
.setSpecial(param
, value
)
205 paramObj
.update(value
)
208 self
.origChecks
= map(lambda i
: (i
[0], i
[1].GetValue()), self
.checks
.items())
209 self
.origControls
= map(lambda i
: (i
[0], i
[1].GetValue(), i
[1].IsEnabled()),
210 self
.controls
.items())
212 self
.origName
= self
.controlName
.GetValue()
213 # Return original values
216 return (self
.origChecks
, self
.origControls
, self
.origName
)
218 return (self
.origChecks
, self
.origControls
)
219 # Set values from undo data
220 def SetState(self
, state
):
222 self
.checks
[k
].SetValue(v
)
223 for k
,v
,e
in state
[1]:
224 self
.controls
[k
].SetValue(v
)
225 self
.controls
[k
].Enable(e
)
226 if e
: self
.controls
[k
].modified
= True
228 self
.controlName
.SetValue(state
[2])
230 ################################################################################
234 # Panel for displaying properties
235 class PropPage(ParamPage
):
236 def __init__(self
, parent
, label
, xxx
):
237 ParamPage
.__init
__(self
, parent
, xxx
)
238 self
.box
= wxStaticBox(self
, -1, label
)
239 self
.box
.SetFont(g
.labelFont())
240 topSizer
= wxStaticBoxSizer(self
.box
, wxVERTICAL
)
241 sizer
= wxFlexGridSizer(len(xxx
.allParams
), 2, 1, 1)
242 sizer
.AddGrowableCol(1)
244 label
= wxStaticText(self
, -1, 'XML ID:', size
=(LABEL_WIDTH
,-1))
245 control
= ParamText(self
, 'XML_name', 200)
246 sizer
.AddMany([ (label
, 0, wxALIGN_CENTER_VERTICAL
),
247 (control
, 0, wxALIGN_CENTER_VERTICAL | wxBOTTOM | wxGROW
, 5) ])
248 self
.controlName
= control
249 for param
in xxx
.allParams
:
250 present
= xxx
.params
.has_key(param
)
251 if param
in xxx
.required
:
252 label
= wxStaticText(self
, paramIDs
[param
], param
+ ':',
253 size
= (LABEL_WIDTH
,-1), name
= param
)
255 # Notebook has one very loooooong parameter
256 if param
== 'usenotebooksizer': sParam
= 'usesizer:'
257 else: sParam
= param
+ ':'
258 label
= wxCheckBox(self
, paramIDs
[param
], sParam
,
259 size
= (LABEL_WIDTH
,-1), name
= param
)
260 self
.checks
[param
] = label
262 typeClass
= xxx
.paramDict
[param
]
266 typeClass
= paramDict
[param
]
269 typeClass
= ParamText
270 control
= typeClass(self
, param
)
271 control
.Enable(present
)
272 sizer
.AddMany([ (label
, 0, wxALIGN_CENTER_VERTICAL
),
273 (control
, 0, wxALIGN_CENTER_VERTICAL | wxGROW
) ])
274 self
.controls
[param
] = control
275 topSizer
.Add(sizer
, 1, wxALL | wxEXPAND
, 3)
276 self
.SetAutoLayout(True)
277 self
.SetSizer(topSizer
)
279 def SetValues(self
, xxx
):
282 self
.origControls
= []
283 # Set values, checkboxes to False, disable defaults
285 self
.controlName
.SetValue(xxx
.name
)
286 self
.origName
= xxx
.name
287 for param
in xxx
.allParams
:
288 w
= self
.controls
[param
]
291 value
= xxx
.params
[param
].value()
294 if not param
in xxx
.required
:
295 self
.checks
[param
].SetValue(True)
296 self
.origChecks
.append((param
, True))
297 self
.origControls
.append((param
, value
, True))
299 self
.checks
[param
].SetValue(False)
302 self
.origChecks
.append((param
, False))
303 self
.origControls
.append((param
, '', False))
305 ################################################################################
307 # Style notebook page
308 class StylePage(ParamPage
):
309 def __init__(self
, parent
, label
, xxx
):
310 ParamPage
.__init
__(self
, parent
, xxx
)
311 box
= wxStaticBox(self
, -1, label
)
312 box
.SetFont(g
.labelFont())
313 topSizer
= wxStaticBoxSizer(box
, wxVERTICAL
)
314 sizer
= wxFlexGridSizer(len(xxx
.styles
), 2, 1, 1)
315 sizer
.AddGrowableCol(1)
316 for param
in xxx
.styles
:
317 present
= xxx
.params
.has_key(param
)
318 check
= wxCheckBox(self
, paramIDs
[param
],
319 param
+ ':', size
= (LABEL_WIDTH
,-1), name
= param
)
320 check
.SetValue(present
)
321 control
= paramDict
[param
](self
, name
= param
)
322 control
.Enable(present
)
323 sizer
.AddMany([ (check
, 0, wxALIGN_CENTER_VERTICAL
),
324 (control
, 0, wxALIGN_CENTER_VERTICAL | wxGROW
) ])
325 self
.checks
[param
] = check
326 self
.controls
[param
] = control
327 topSizer
.Add(sizer
, 1, wxALL | wxEXPAND
, 3)
328 self
.SetAutoLayout(True)
329 self
.SetSizer(topSizer
)
331 # Set data for a cahced page
332 def SetValues(self
, xxx
):
335 self
.origControls
= []
336 for param
in xxx
.styles
:
337 present
= xxx
.params
.has_key(param
)
338 check
= self
.checks
[param
]
339 check
.SetValue(present
)
340 w
= self
.controls
[param
]
343 value
= xxx
.params
[param
].value()
348 self
.origChecks
.append((param
, present
))
349 self
.origControls
.append((param
, value
, present
))