-
Notifications
You must be signed in to change notification settings - Fork 8
/
Inspector.py
1472 lines (1213 loc) · 54.7 KB
/
Inspector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#----------------------------------------------------------------------
# Name: Inspector.py
# Purpose:
#
# Author: Riaan Booysen
#
# Created: 1999
# RCS-ID: $Id$
# Copyright: (c) 1999 - 2007 Riaan Booysen
# Licence: GPL
#----------------------------------------------------------------------
#Boa:Frame:InspectorFrame
""" Inspects and edits design-time components, manages property editors
and interacts with the designer and companions
"""
print 'importing Inspector'
# XXX Disable clipboards buttons when non Designer item is selected !!
import os
from types import *
import wx
import wx.lib.stattext
from wxCompat import wxNO_3D
import PaletteMapping, PaletteStore, Preferences, Help
from PropEdit import PropertyEditors
from Companions import EventCollections
import Preferences, RTTI, Utils
from Preferences import IS, oiLineHeight, inspPageNames, flatTools
from Preferences import keyDefs
from Utils import _
scrollBarWidth = 0
IECWidthFudge = 3
[wxID_ENTER, wxID_UNDOEDIT, wxID_CRSUP, wxID_CRSDOWN, wxID_CONTEXTHELP,
wxID_SWITCHDESIGNER, wxID_SWITCHEDITOR, wxID_OPENITEM, wxID_CLOSEITEM,
wxID_INDEXHELP,
] = Utils.wxNewIds(10)
[wxID_INSPECTORFRAME, wxID_INSPECTORFRAMECONSTR, wxID_INSPECTORFRAMEEVENTS,
wxID_INSPECTORFRAMEPAGES, wxID_INSPECTORFRAMEPROPS,
wxID_INSPECTORFRAMESTATUSBAR, wxID_INSPECTORFRAMETOOLBAR,
] = [wx.NewId() for _init_ctrls in range(7)]
[wxID_INSPECTORFRAMETOOLBARTOOLS0] = [wx.NewId() for _init_coll_toolBar_Tools in range(1)]
class InspectorFrame(wx.Frame, Utils.FrameRestorerMixin):
""" Main Inspector frame, mainly does frame initialisation and handles
events from the toolbar """
_custom_classes = {'wx.Notebook': ['InspectorNotebook'],
'wx.SplitterWindow': ['EventsWindow'],
'wx.ScrolledWindow': ['InspectorPropScrollWin',
'InspectorConstrScrollWin'],}
def _init_coll_pages_Pages(self, parent):
# generated method, don't edit
parent.AddPage(imageId=-1, page=self.constr, select=True,
text=self.constr_name)
parent.AddPage(imageId=-1, page=self.props, select=False,
text=self.props_name)
parent.AddPage(imageId=-1, page=self.events, select=False,
text=self.events_name)
def _init_coll_toolBar_Tools(self, parent):
# generated method, don't edit
parent.AddTool(bitmap=self.up_bmp, id=wxID_INSPECTORFRAMETOOLBARTOOLS0,
isToggle=False, longHelpString='', pushedBitmap=wx.NullBitmap,
shortHelpString=_('Select parent'))
self.Bind(wx.EVT_TOOL, self.OnUp, id=wxID_INSPECTORFRAMETOOLBARTOOLS0)
parent.Realize()
def _init_coll_statusBar_Fields(self, parent):
# generated method, don't edit
parent.SetFieldsCount(2)
parent.SetStatusText(_('Nothing selected'), 0)
parent.SetStatusText('', 1)
parent.SetStatusWidths([-1, -1])
def _init_utils(self):
# generated method, don't edit
self.paletteImages = wx.ImageList(height=24, width=24)
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_INSPECTORFRAME, name='', parent=prnt,
pos=wx.Point(363, 272), size=wx.Size(290, 505),
style=wx.DEFAULT_FRAME_STYLE| Preferences.childFrameStyle,
title=_('Inspector'))
self._init_utils()
self.SetClientSize(wx.Size(282, 478))
self.Bind(wx.EVT_SIZE, self.OnSizing)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
self.toolBar = wx.ToolBar(id=wxID_INSPECTORFRAMETOOLBAR, name='toolBar',
parent=self, pos=wx.Point(0, 0), size=wx.Size(282, 24),
style=wx.TB_HORIZONTAL | wx.NO_BORDER | Preferences.flatTools | wx.CLIP_CHILDREN)
self.SetToolBar(self.toolBar)
self.statusBar = wx.StatusBar(id=wxID_INSPECTORFRAMESTATUSBAR,
name='statusBar', parent=self, style=wx.ST_SIZEGRIP)
self.statusBar.SetFont(wx.Font(Preferences.inspStatBarFontSize,
wx.DEFAULT, wx.NORMAL, wx.BOLD, False, ''))
self._init_coll_statusBar_Fields(self.statusBar)
self.SetStatusBar(self.statusBar)
self.pages = InspectorNotebook(id=wxID_INSPECTORFRAMEPAGES,
name='pages', parent=self, pos=wx.Point(0, 24), size=wx.Size(282,
434), style=0)
self.constr = InspectorConstrScrollWin(id=wxID_INSPECTORFRAMECONSTR,
name='constr', parent=self.pages, pos=wx.Point(0, 0),
size=wx.Size(274, 408), style=wx.SUNKEN_BORDER)
self.props = InspectorPropScrollWin(id=wxID_INSPECTORFRAMEPROPS,
name='props', parent=self.pages, pos=wx.Point(0, 0),
size=wx.Size(274, 408), style=wx.SUNKEN_BORDER)
self.events = EventsWindow(id=wxID_INSPECTORFRAMEEVENTS, name='events',
parent=self.pages, pos=wx.Point(0, 0), size=wx.Size(274, 404),
style=wx.SP_3D)
self._init_coll_toolBar_Tools(self.toolBar)
self._init_coll_pages_Pages(self.pages)
def __init__(self, parent):
self.constr_name = Preferences.inspPageNames['Constr']
self.props_name = Preferences.inspPageNames['Props']
self.events_name = Preferences.inspPageNames['Evts']
self.up_bmp = IS.load('Images/Inspector/Up.png')
self._init_ctrls(parent)
del self.up_bmp
# Inspector is created before the Editor so this must be set after
# creating the Editor
self.editor = None
self.winConfOption = 'inspector'
self.loadDims()
self.propertyRegistry = PropertyEditors.PropertyRegistry()
PropertyEditors.registerEditors(self.propertyRegistry)
self.destroying = False
for cmpInf in PaletteStore.compInfo.values():
filename ='Images/Palette/'+ cmpInf[0]+'.png'
try:
cmpInf.append(self.paletteImages.Add(IS.load(filename)))
except IS.Error:
cmpInf.append(self.paletteImages.Add(IS.load('Images/Palette/Component.png')))
self.SetIcon(IS.load('Images/Icons/Inspector.ico'))
self.vetoSelect = False
self.selObj = None
self.selCmp = None
self.selDesgn = None
self.prevDesigner = (None, None)
self.prevCollDesgn = None
self.sessionHandler = None
self.toolBar.AddSeparator()
Utils.AddToolButtonBmpIS(self, self.toolBar,
'Images/Shared/Delete.png', _('Delete selection'), self.OnDelete)
Utils.AddToolButtonBmpIS(self, self.toolBar,
'Images/Shared/Cut.png', _('Cut selection'), self.OnCut)
Utils.AddToolButtonBmpIS(self, self.toolBar,
'Images/Shared/Copy.png', _('Copy selection'), self.OnCopy)
Utils.AddToolButtonBmpIS(self, self.toolBar,
'Images/Shared/Paste.png', _('Paste selection'), self.OnPaste)
Utils.AddToolButtonBmpIS(self, self.toolBar,
'Images/Editor/Refresh.png', _('Recreate selection'), self.OnRecreateSelection)
self.toolBar.AddSeparator()
self.wxID_POST = Utils.AddToolButtonBmpIS(self, self.toolBar,
'Images/Inspector/Post.png', _('Post the session'), self.OnPost)
self.wxID_CANCEL = Utils.AddToolButtonBmpIS(self, self.toolBar,
'Images/Inspector/Cancel.png', _('Cancel the session'), self.OnCancel)
self.toolBar.AddSeparator()
## Utils.AddToolButtonBmpIS(self, self.toolBar, 'Images/Shared/RevertItem.png',
## 'Revert item', self.OnRevertItem)
self.wxID_ADDITEM = Utils.AddToolButtonBmpIS(self, self.toolBar,
'Images/Shared/NewItem.png', _('New item'), self.OnNewItem)
self.wxID_DELITEM = Utils.AddToolButtonBmpIS(self, self.toolBar,
'Images/Shared/DeleteItem.png', _('Delete item'), self.OnDelItem)
self.toolBar.AddSeparator()
Utils.AddToolButtonBmpIS(self, self.toolBar,
'Images/Shared/Help.png', _('Show help'), self.OnHelp)
self.toolBar.Realize()
self.constr.setInspector(self)
self.props.setInspector(self)
self.events.setInspector(self)
if wx.Platform == '__WXGTK__':
prxy, self.containment = Utils.wxProxyPanel(self.pages, ParentTree)
else:
prxy = self.containment = ParentTree(self.pages)
self.containment.SetImageList(self.paletteImages)
self.pages.AddPage(prxy, inspPageNames['Objs'])
self.selection = None
self.Bind(wx.EVT_MENU, self.OnSwitchEditor, id=wxID_SWITCHEDITOR)
self.Bind(wx.EVT_MENU, self.OnSwitchDesigner, id=wxID_SWITCHDESIGNER)
self.Bind(wx.EVT_MENU, self.OnIndexHelp, id=wxID_INDEXHELP)
self.SetAcceleratorTable(wx.AcceleratorTable([\
(keyDefs['Designer'][0], keyDefs['Designer'][1], wxID_SWITCHEDITOR),
(keyDefs['Inspector'][0], keyDefs['Inspector'][1], wxID_SWITCHDESIGNER),
(keyDefs['HelpFind'][0], keyDefs['HelpFind'][1], wxID_INDEXHELP)]
))
self.updateToolBarState()
def OnSwitchEditor(self, event):
if self.editor:
self.editor.restore()
def OnSwitchDesigner(self, event):
if self.selDesgn:
self.selDesgn.restore()
def setDefaultDimensions(self):
self.SetDimensions(Preferences.screenX, Preferences.underPalette + Preferences.screenY,
Preferences.inspWidth, Preferences.bottomHeight)
#---Object selection------------------------------------------------------------
def selectObject(self, compn, selectInContainment=True, collDesgn=None,
focusPage=None, restore=False, sessionHandler=None):
""" Select an object in the inspector by populating the property
pages. This method is called from the InspectableObjectView
derived classes """
if restore:
self.restore()
if self.sessionHandler:
self.sessionHandler.promptPostOrCancel(self)
if focusPage is not None:
if self.pages.GetSelection() != focusPage:
self.pages.SetSelection(focusPage)
if self.selCmp == compn or self.vetoSelect:
return
# Clear inspector selection
self.constr.cleanup()
self.props.cleanup()
self.events.cleanup()
if self.prevDesigner[0] and compn.designer and not collDesgn and \
(compn.designer != self.prevDesigner[0] or not collDesgn and self.prevDesigner[1]):
if compn.designer.supportsParentView:
compn.designer.refreshContainment()
# deselect last selection if in different designer
if self.prevDesigner[0] and self.prevDesigner != (compn.designer, collDesgn):
if self.prevDesigner[1]:
self.prevDesigner[1].selectNone()
else:
self.prevDesigner[0].selectNone()
self.prevDesigner = (compn.designer, collDesgn)
self.selCmp = compn
self.selDesgn = compn.designer
self.selObj = compn.control
self.sessionHandler = sessionHandler
self.statusBar.SetStatusText(compn.name)
self.statusBar.SetStatusText(compn.GetClass(), 1)
# Update progress inbetween building of property pages
# Is this convoluted or what :)
if self.selDesgn:
sb = self.selDesgn.model.editor.statusBar.progress
else: sb = None
if sb: sb.SetValue(10)
try:
c_p = compn.getPropList()
if sb: sb.SetValue(30)
self.constr.readObject(c_p['constructor'])
if sb: sb.SetValue(50)
self.props.readObject(c_p['properties'])
if sb: sb.SetValue(70)
self.events.readObject()
if sb: sb.SetValue(90)
if selectInContainment and self.containment.valid:
# XXX Ugly must change
try:
treeId = self.containment.treeItems[compn.name]
except:
treeId = self.containment.treeItems['']
self.containment.valid = False
self.containment.SelectItem(treeId)
self.containment.valid = True
self.containment.EnsureVisible(treeId)
finally:
if sb: sb.SetValue(0)
# set add item state
self.updateToolBarState()
def multiSelectObject(self, compn, designer):
self.selCmp = compn
self.selDesgn = designer
self.selObj = None
# These methods update property pages.
# Call when changes in the selected control is detected
def pageUpdate(self, page, name):
nv = page.getNameValue(name)
if nv:
page.initFromComponent(name)
def propertyUpdate(self, name):
self.pageUpdate(self.props, name)
def constructorUpdate(self, name):
self.pageUpdate(self.constr, name)
def eventUpdate(self, name, delete=False):
if delete:
self.events.definitions.removeEvent(name)
else:
self.pageUpdate(self.events, name)
# Direct companion source update of position and size when multiselected
# While multiple components are selected the inspector does not persist
# selected control value changes
def directPositionUpdate(self, comp):
comp.persistProp('Position', 'SetPosition', `comp.control.GetPosition()`)
def directSizeUpdate(self, comp):
comp.persistProp('Size', 'SetSize', `comp.control.GetSize()`)
## def selectedCtrlHelpFile(self):
## """ Return the help file/link associated with the selected control """
## if self.selCmp: return self.selCmp.wxDocs
## else: return ''
def cleanup(self):
## if self.sessionHandler is not None:
## self.sessionHandler.promptPostOrCancel()
self.selCmp = None
self.selObj = None
self.selDesgn = None
self.sessionHandler = None
self.constr.cleanup()
self.props.cleanup()
self.events.cleanup()
self.statusBar.SetStatusText('')
self.statusBar.SetStatusText('', 1)
self.updateToolBarState()
def initSashes(self):
self.constr.initSash()
self.props.initSash()
self.events.initSash()
def updateToolBarState(self):
canAddDel = self.selCmp is not None and \
hasattr(self.selCmp, 'propItems') and \
hasattr(self.selCmp, 'updateZopeProps')
self.toolBar.EnableTool(self.wxID_ADDITEM, canAddDel)
self.toolBar.EnableTool(self.wxID_DELITEM, canAddDel)
hasSessionHandler = self.sessionHandler is not None
self.toolBar.EnableTool(self.wxID_POST, hasSessionHandler)
self.toolBar.EnableTool(self.wxID_CANCEL, hasSessionHandler)
def OnSizing(self, event):
event.Skip()
def OnDelete(self, event):
if self.selDesgn:
self.selDesgn.OnControlDelete(event)
def OnUp(self, event):
if self.sessionHandler:
self.sessionHandler.doUp(self)
else:
self.cleanup()
def OnCut(self, event):
if self.selDesgn:
self.selDesgn.OnCutSelected(event)
def OnCopy(self, event):
if self.selDesgn:
self.selDesgn.OnCopySelected(event)
def OnPaste(self, event):
if self.selDesgn:
self.selDesgn.OnPasteSelected(event)
def OnRecreateSelection(self, event):
if self.selDesgn:
self.selDesgn.OnRecreateSelected(event)
def OnPost(self, event):
if self.sessionHandler:
self.sessionHandler.doPost(self)
def OnCancel(self, event):
if self.sessionHandler:
self.sessionHandler.doCancel(self)
def OnHelp(self, event):
Help.showHelp('Inspector.html')
def OnIndexHelp(self, event):
self.editor.OnHelpFindIndex(event)
def OnRevertItem(self, event):
if self.selCmp and self.props.prevSel and self.props.prevSel.propEditor:
propEdit = self.props.prevSel.propEditor
propEdit.companion.propRevertToDefault(propEdit.name,
propEdit.propWrapper.getSetterName())
self.props.prevSel.showPropNameModified()
def refreshZopeProps(self):
cmpn = self.selCmp
cmpn.updateZopeProps()
self.selCmp = None
self.selectObject(cmpn)
def OnNewItem(self, event):
if self.selCmp and hasattr(self.selCmp, 'propItems'):
from ZopeLib import PropDlg
dlg = PropDlg.create(self)
try:
if dlg.ShowModal() == wx.ID_OK:
self.selCmp.addProperty(dlg.tcPropName.GetValue(),
dlg.tcValue.GetValue(), dlg.chType.GetStringSelection())
self.refreshZopeProps()
finally:
dlg.Destroy()
def OnDelItem(self, event):
if self.selCmp and self.props.prevSel and hasattr(self.selCmp, 'propItems'):
self.selCmp.delProperty(self.props.prevSel.propName)
self.refreshZopeProps()
def OnCloseWindow(self, event):
self.Show(False)
if self.destroying or __name__ == '__main__':
self.paletteImages = None
self.cleanup()
self.pages.destroy()
self.constr.destroy()
self.props.destroy()
self.events.destroy()
self.Destroy()
event.Skip()
elif Preferences.expandEditorOnCloseInspector:
self.editor.expandOnInspectorClose()
def restore(self):
Utils.FrameRestorerMixin.restore(self)
if Preferences.expandEditorOnCloseInspector:
self.editor.restoreOnInspectorRestore()
wxID_PARENTTREE = wx.NewId()
wxID_PARENTTREESELECTED = wx.NewId()
class ParentTree(wx.TreeCtrl):
""" Specialised tree ctrl that displays parent child relationship of
controls on the frame """
# XXX Rather associate data with tree item than going only on the name
def __init__(self, parent):
wx.TreeCtrl.__init__(self, parent, wxID_PARENTTREE, style=wx.TR_HAS_BUTTONS | wx.CLIP_CHILDREN | wx.SUNKEN_BORDER)
self.cleanup()
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelect, id=wxID_PARENTTREE)
def cleanup(self):
self.designer = None
self.valid = False
self.treeItems = {}
self.DeleteAllItems()
self.root = None
def addChildren(self, parent, dict, designer):
""" Recursive method to construct parent/child relationships in a tree """
for par in designer.objectOrder:
if dict.has_key(par):
img = PaletteStore.compInfo[designer.objects[par][1].__class__][2]
itm = self.AppendItem(parent, par, img)
self.treeItems[par] = itm
if len(dict[par]):
self.addChildren(itm, dict[par], designer)
self.Expand(parent)
def refreshCtrl(self, root, relDict, designer):
self.cleanup()
self.designer = designer
self.root = self.AddRoot(root,
PaletteStore.compInfo[designer.objects[''][1].__class__.__bases__[0]][2])
self.treeItems[''] = self.root
self.addChildren(self.root, relDict[''], designer)
self.valid = True
def selectName(self, name):
tii = wx.TreeItemId()
self.SelectItem(self.treeItems.get(name, tii))
def selectedName(self):
return self.GetItemText(self.GetSelection())
def selectItemGUIOnly(self, name):
tii = wx.TreeItemId()
self.SelectItem(self.treeItems.get(name, tii))
def extendHelpUrl(self, wxClass, url):
return wxClass, url
def OnSelect(self, event=None):
""" Event triggered when the selection changes in the tree """
if self.valid:
idx = self.GetSelection()
if self.designer:
## if idx == self.root:
## if self.GetRootItem() == idx:
# Ugly but nothing else works
try:
ctrlInfo = self.designer.objects[self.GetItemText(idx)]
except KeyError:
ctrlInfo = self.designer.objects['']
if hasattr(self.designer, 'selection') and self.designer.selection:
self.designer.selection.selectCtrl(ctrlInfo[1], ctrlInfo[0])
class NameValue:
""" Base class for all name value pairs that appear in the Inspector """
def __init__(self, inspector, nameParent, valueParent, companion,
rootCompanion, name, propWrapper, idx, indent,
editor=None, options=None, names=None, ownerPropEdit=None):
self.destr = False
self.lastSizeN = 0
self.lastSizeV = 0
self.indent = indent
self.inspector = inspector
self.propName = name
self.editing = False
self.nameParent = nameParent
self.valueParent = valueParent
self.idx = idx
self.nameBevelTop = None
self.nameBevelBottom = None
self.valueBevelTop = None
self.valueBevelBottom = None
lockEditor, attrName, self.isCat = self.checkLockedProperty(name,
propWrapper.getSetterName(), companion)
if lockEditor:
editor = lockEditor
self.locked = True
else:
self.locked = False
if editor:
self.propEditor = editor(name, valueParent, companion, rootCompanion,
propWrapper, idx, valueParent.GetSize().x+IECWidthFudge, options,
names)
else:
self.propEditor = self.inspector.inspector.propertyRegistry.factory(name,
valueParent, companion, rootCompanion, propWrapper, idx,
valueParent.GetSize().x + IECWidthFudge)
# Hardwire locked properties to return frame attributes
if lockEditor:
self.propEditor.value = attrName
self.expander = None
if self.propEditor:
self.propEditor.ownerPropEdit = ownerPropEdit
self.updatePropValue()
displayVal = self.propEditor.getDisplayValue()
# check if it's expandable
if PropertyEditors.esExpandable in self.propEditor.getStyle():
mID = wx.NewId()
self.expander = wx.CheckBox(nameParent, mID, '',
wx.Point(8 * self.indent, self.idx * oiLineHeight +2),
wx.Size(13, 14))
self.expander.SetValue(True)
self.expander.Bind(wx.EVT_CHECKBOX, self.OnExpand, id=mID)
else:
self.propValue = ''
displayVal = ''
# Create name and value controls and separators
self.nameCtrl = wx.lib.stattext.GenStaticText(nameParent, -1, name,
wx.Point(8 * self.indent + 16, idx * oiLineHeight +2),
wx.Size(inspector.panelNames.GetSize().x, oiLineHeight -3),
style=wx.ST_NO_AUTORESIZE | wx.NO_BORDER) #wxCLIP_CHILDREN |
self.nameCtrl.SetToolTipString(companion.getPropertyHelp(name))
self.nameCtrl.Bind(wx.EVT_LEFT_DOWN, self.OnSelect)
self.showPropNameModified(self.isCat)
self.value = wx.lib.stattext.GenStaticText(valueParent, -1, displayVal,
wx.Point(2, idx * oiLineHeight +2), wx.Size(inspector.getValueWidth(),
oiLineHeight -3), style=wx.ST_NO_AUTORESIZE) #wxCLIP_CHILDREN |
self.value.SetForegroundColour(Preferences.propValueColour)
self.value.SetToolTipString(displayVal)
self.value.Bind(wx.EVT_LEFT_DOWN, self.OnSelect)
if lockEditor and not self.isCat:
self.enboldenCtrl(self.value)
sepCol = wx.Colour(160, 160, 160)
self.separatorN = wx.Window(nameParent, -1, wx.Point(0,
(idx +1) * oiLineHeight), wx.Size(inspector.panelNames.GetSize().x, 1))#,
#style=wx.CLIP_CHILDREN)
self.separatorN.SetBackgroundColour(sepCol)
self.separatorN.Refresh()
self.separatorV = wx.Window(valueParent, -1, wx.Point(0,
(idx +1) * oiLineHeight), wx.Size(inspector.getValueWidth(), 1))#,
#style=wx.CLIP_CHILDREN)
self.separatorV.SetBackgroundColour(sepCol)
self.separatorV.Refresh()
def checkLockedProperty(self, name, setterName, companion):
""" Determine if the property is locked """
# XXX refactor, this is currently ugly
try:
srcVal = companion.persistedPropVal(name, setterName)
except KeyError:
pass
else:
if srcVal is not None:
if srcVal == 'PROP_CATEGORY':
return PropertyEditors.LockedPropEdit, '', True
if type(srcVal) is type([]):
if len(srcVal):
srcVal = srcVal[0]
else:
srcVal = ''
if srcVal.startswith('self.') and \
hasattr(companion.designer.model.specialAttrs['self'], srcVal[5:]):
return PropertyEditors.LockedPropEdit, srcVal, False
return None, '', False
def destroy(self, cancel = False):
self.hideEditor(cancel, noUpdate=True)
self.destr = True
self.nameCtrl.Destroy()
self.value.Destroy()
self.separatorN.Destroy()
self.separatorV.Destroy()
if self.expander:
self.expander.Destroy()
def createHelpUrl(self):
if self.propEditor:
pw = self.propEditor.propWrapper
# custom help
if pw.routeType == 'CompnRoute':
return '', ''
# wxWin help
if pw.routeType == 'CtrlRoute':
mthName = pw.getSetterName()
mthObj = getattr(self.propEditor.companion.control, mthName)
cls = mthObj.im_class.__name__
if cls[-3:] == 'Ptr': cls = cls[:-3]
return cls, cls + mthName
return '', ''
def updatePropValue(self):
self.propValue = self.propEditor.getValue()
def showPropNameModified(self, displayAsCat=False):
if self.propEditor and Preferences.showModifiedProps:
propEdit = self.propEditor
propSetter = propEdit.propWrapper.getSetterName()
mod = not propEdit.companion.propIsDefault(propEdit.name, propSetter)
self.enboldenCtrl(self.nameCtrl, mod or displayAsCat)
if displayAsCat:
self.nameCtrl.SetForegroundColour(Preferences.propValueColour)
def enboldenCtrl(self, ctrl, bold = True):
fnt = ctrl.GetFont()
ctrl.SetFont(wx.Font(fnt.GetPointSize(),
fnt.GetFamily(), fnt.GetStyle(), bold and wx.BOLD or wx.NORMAL,
fnt.GetUnderlined(), fnt.GetFaceName()))
def updateDisplayValue(self):
dispVal = self.propEditor.getDisplayValue()
currVal = self.value.GetLabel()
if currVal != dispVal:
self.value.SetLabel(dispVal)
self.value.SetToolTipString(dispVal)
self.showPropNameModified(self.isCat)
def setPos(self, idx):
self.idx = idx
if self.expander:
self.expander.SetPosition(wx.Point(8 * self.indent,
self.idx * oiLineHeight + 2))
self.nameCtrl.SetPosition(wx.Point(8 * self.indent + 16, idx * oiLineHeight +2))
self.value.SetPosition(wx.Point(2, idx * oiLineHeight +2))
self.separatorN.SetPosition(wx.Point(0, (idx +1) * oiLineHeight))
self.separatorV.SetPosition(wx.Point(0, (idx +1) * oiLineHeight))
if self.nameBevelTop:
self.nameBevelTop.SetPosition(wx.Point(0, idx*oiLineHeight -1))
self.nameBevelBottom.SetPosition(wx.Point(0, (idx + 1)*oiLineHeight -1))
if self.propEditor:
self.propEditor.setIdx(idx)
elif self.valueBevelTop:
self.valueBevelTop.SetPosition(wx.Point(0, idx*oiLineHeight -1))
self.valueBevelBottom.SetPosition(wx.Point(0, (idx + 1)*oiLineHeight -1))
def resize(self, nameWidth, valueWidth):
if nameWidth <> self.lastSizeN:
if self.nameBevelTop:
self.nameBevelTop.SetSize(wx.Size(nameWidth, 1))
self.nameBevelBottom.SetSize(wx.Size(nameWidth, 1))
if nameWidth > 100:
self.nameCtrl.SetSize(wx.Size(nameWidth, self.nameCtrl.GetSize().y))
else:
self.nameCtrl.SetSize(wx.Size(100, self.nameCtrl.GetSize().y))
self.separatorN.SetSize(wx.Size(nameWidth, 1))
if valueWidth <> self.lastSizeV:
if self.valueBevelTop:
self.valueBevelTop.SetSize(wx.Size(valueWidth, 1))
self.valueBevelBottom.SetSize(wx.Size(valueWidth, 1))
self.value.SetSize(wx.Size(valueWidth, self.value.GetSize().y))
self.separatorV.SetSize(wx.Size(valueWidth, 1))
if self.propEditor:
self.propEditor.setWidth(valueWidth)
self.lastSizeN = nameWidth
self.lastSizeV = valueWidth
def showEdit(self):
self.nameBevelTop = wx.Window(self.nameParent, -1,
wx.Point(0, max(self.idx*oiLineHeight -1, 0)),
wx.Size(self.inspector.panelNames.GetSize().x, 1))
self.nameBevelTop.SetBackgroundColour(wx.BLACK)
self.nameBevelBottom = wx.Window(self.nameParent, -1,
wx.Point(0, (self.idx + 1)*oiLineHeight -1),
wx.Size(self.inspector.panelNames.GetSize().x, 1))
self.nameBevelBottom.SetBackgroundColour(wx.WHITE)
if not self.locked and self.propEditor:
self.value.SetLabel('')
self.value.SetToolTipString('')
self.value.SetSize((0, 0))
self.propEditor.inspectorEdit()
else:
self.valueBevelTop = wx.Window(self.valueParent, -1,
wx.Point(0, max(self.idx*oiLineHeight -1, 0)),
wx.Size(self.inspector.getValueWidth(), 1))
self.valueBevelTop.SetBackgroundColour(wx.BLACK)
self.valueBevelBottom =wx.Window(self.valueParent, -1,
wx.Point(0, (self.idx + 1)*oiLineHeight -1),
wx.Size(self.inspector.getValueWidth(), 1))
self.valueBevelBottom.SetBackgroundColour(wx.WHITE)
self.editing = True
self.nameBevelTop.Refresh()
self.nameBevelBottom.Refresh()
if self.valueBevelTop: self.valueBevelTop.Refresh()
if self.valueBevelBottom: self.valueBevelBottom.Refresh()
def hideEditor(self, cancel=False, noUpdate=False):
if self.propEditor:# and (not self.destr):
if cancel:
self.propEditor.inspectorCancel()
else:
if noUpdate:
# swallow exceptions as autoposted values can not be canceled
try:
self.propEditor.inspectorPost()
except Exception, err:
wx.LogError(_('Could not post %s because: %s: %s')%(
self.propName, err.__class__.__name__, str(err)))
else:
self.propEditor.inspectorPost()
self.updateDisplayValue()
self.value.SetSize(wx.Size(self.separatorV.GetSize().x,
oiLineHeight-3))
if self.nameBevelTop:
self.nameBevelTop.Destroy()
self.nameBevelTop = None
self.nameBevelBottom.Destroy()
self.nameBevelBottom = None
if self.valueBevelTop:
self.valueBevelTop.Destroy()
self.valueBevelTop = None
self.valueBevelBottom.Destroy()
self.valueBevelBottom = None
self.editing = False
def OnSelect(self, event=None):
self.inspector.propertySelected(self)
def OnExpand(self, event):
if event.IsChecked(): self.inspector.collapse(self)
else: self.inspector.expand(self)
class PropNameValue(NameValue):
""" Name value for properties, usually Get/Set methods, but can also be
routed to Companion methods """
def initFromComponent(self):
""" Update Inspector after possible change to underlying control """
if self.propEditor:
self.propEditor.initFromComponent()
if not self.propEditor.editorCtrl:
self.updateDisplayValue()
self.propEditor.persistValue(self.propEditor.valueAsExpr())
class ConstrNameValue(NameValue):
""" Name value for constructor parameters """
def initFromComponent(self):
""" Update Inspector after possible change to underlying control """
if self.propEditor:
self.propEditor.initFromComponent()
if not self.propEditor.editorCtrl:
self.updateDisplayValue()
def showPropNameModified(self, isCat=False):
pass
class EventNameValue(NameValue):
""" Name value for event definitions """
def initFromComponent(self):
if self.propEditor:
self.propEditor.initFromComponent()
if not self.propEditor.editorCtrl:
self.updateDisplayValue()
class ZopePropNameValue(NameValue):
""" Name value for properties, usually Get/Set methods, but can also be
routed to Companion methods """
def initFromComponent(self):
pass
wxID_EVTCATS = wx.NewId()
wxID_EVTMACS = wx.NewId()
class EventsWindow(wx.SplitterWindow):
""" Window that hosts event name values and event category selection """
def __init__(self, *_args, **_kwargs):
wx.SplitterWindow.__init__(self, _kwargs['parent'], _kwargs['id'],
style = Preferences.splitterStyle)
self.categories = wx.SplitterWindow(self, -1,
style=wxNO_3D | wx.SP_3D | wx.SP_LIVE_UPDATE)
self.definitions = InspectorEventScrollWin(self, -1,
style=wx.SUNKEN_BORDER | wx.TAB_TRAVERSAL)
self.SetMinimumPaneSize(20)
self.SplitHorizontally(self.categories, self.definitions)
self.SetSashPosition(100)
self.categoryClasses = wx.ListCtrl(self.categories, wxID_EVTCATS, style=wx.LC_LIST)
self.selCatClass = -1
self.categoryClasses.Bind(wx.EVT_LIST_ITEM_SELECTED,
self.OnCatClassSelect, id=wxID_EVTCATS)
self.categoryClasses.Bind(wx.EVT_LIST_ITEM_DESELECTED,
self.OnCatClassDeselect, id=wxID_EVTCATS)
self.categoryMacros = wx.ListCtrl(self.categories, wxID_EVTMACS, style=wx.LC_LIST)
self.categoryMacros.Bind(wx.EVT_LIST_ITEM_SELECTED,
self.OnMacClassSelect, id=wxID_EVTMACS)
self.categoryMacros.Bind(wx.EVT_LIST_ITEM_DESELECTED,
self.OnMacClassDeselect, id=wxID_EVTMACS)
self.categoryMacros.Bind(wx.EVT_LEFT_DCLICK, self.OnMacroSelect)
self.selMacClass = -1
self.categories.SetMinimumPaneSize(20)
self.categories.SplitVertically(self.categoryClasses, self.categoryMacros)
self.categories.SetSashPosition(80)
def setInspector(self, inspector):
self.inspector = inspector
self.definitions.setInspector(inspector)
def readObject(self):
#clean up all previous items
self.cleanup()
# List available categories
for catCls in self.inspector.selCmp.events():
self.categoryClasses.InsertStringItem(0, catCls)
self.definitions.readObject()
self.definitions.refreshSplitter()
def cleanup(self):
self.definitions.cleanup()
self.categoryClasses.DeleteAllItems()
self.categoryMacros.DeleteAllItems()
def destroy(self):
self.definitions.destroy()
self.inspector = None
def findMacro(self, name):
for macro in EventCollections.EventCategories[\
self.categoryClasses.GetItemText(self.selCatClass)]:
if macro == name: return macro
raise Exception, _('Macro: %s not found.')%name
def addEvent(self, name, value, wid = None):
self.inspector.selCmp.persistEvt(name, value, wid)
self.inspector.selCmp.evtSetter(name, value)
self.definitions.addEvent(name)
self.definitions.refreshSplitter()
def getEvent(self, name):
return self.definitions.getNameValue(name)
def macroNameToEvtName(self, macName):
flds = macName.split('_')
del flds[0] #remove 'EVT'
cmpName = self.inspector.selCmp.evtName()
evtName = 'On'+cmpName[0].upper()+cmpName[1:]
for fld in flds:
evtName = evtName + fld.capitalize()
return evtName
def extendHelpUrl(self, wxClass, url):
return wxClass, url
def initSash(self):
self.definitions.initSash()
self.categories.SetSashPosition(80)
self.SetSashPosition(Preferences.oiEventSelectionHeight)
def OnCatClassSelect(self, event):
self.selCatClass = event.m_itemIndex
catClass = EventCollections.EventCategories[\
self.categoryClasses.GetItemText(self.selCatClass)]
for catMac in catClass:
self.categoryMacros.InsertStringItem(0, catMac)
def OnCatClassDeselect(self, event):
self.selCatClass = -1
self.selMacClass = -1
self.categoryMacros.DeleteAllItems()
def OnMacClassSelect(self, event):
self.selMacClass = event.m_itemIndex
def OnMacClassDeselect(self, event):
self.selMacClass = -1
def doAddEvent(self, catClassName, macName):
companion = self.inspector.selCmp
methName = self.macroNameToEvtName(macName)
frameName = companion.designer.GetName()
if catClassName in EventCollections.commandCategories:
wid = companion.getWinId()
else:
wid = None
nv = self.getEvent(macName)
if nv:
self.addEvent(macName, methName, wid)
nv.initFromComponent()
nv.OnSelect()
else: self.addEvent(macName, methName, wid)
def OnMacroSelect(self, event):
if self.selMacClass > -1:
catClassName = self.categoryClasses.GetItemText(self.selCatClass)
macName = self.categoryMacros.GetItemText(self.selMacClass)