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
|
#----------------------------------------------------------------------
# Name: DataView.py
# Purpose: Designer for Utility (non visual) objects
#
# Author: Riaan Booysen
#
# Created: 1999
# RCS-ID: $Id: DataView.py,v 1.22 2004/08/16 13:35:57 riaan Exp $
# Copyright: (c) 1999 - 2004 Riaan Booysen
# Licence: GPL
#----------------------------------------------------------------------
print 'importing Views.DataView'
import os, copy
from wxPython.wx import *
import Preferences, Utils
import sourceconst
import PaletteMapping, PaletteStore, Help
from InspectableViews import InspectableObjectView, DesignerError
import ObjCollection
class DataView(wxListView, InspectableObjectView):
viewName = 'Data'
collectionMethod = sourceconst.init_utils
postBmp = 'Images/Inspector/Post.png'
cancelBmp = 'Images/Inspector/Cancel.png'
def __init__(self, parent, inspector, model, compPal):
[self.wxID_DATAVIEW] = map(lambda _init_ctrls: wxNewId(), range(1))
wxListView.__init__(self, parent, self.wxID_DATAVIEW, size=(0,0),
style=Preferences.dataViewListStyle | wxSUNKEN_BORDER)
InspectableObjectView.__init__(self, inspector, model, compPal,
(('Default editor', self.OnDefaultEditor, '-', ''),
('Post', self.OnPost, self.postBmp, ''),
('Cancel', self.OnCancel, self.cancelBmp, ''),
('-', None, '-', ''),
('Cut', self.OnCutSelected, '-', ''),
('Copy', self.OnCopySelected, '-', 'Copy'),
('Paste', self.OnPasteSelected, '-', 'Paste'),
('Delete', self.OnControlDelete, '-', 'Delete'),
('-', None, '-', ''),
('Creation/Tab order...', self.OnCreationOrder, '-', ''),
('-', None, '-', ''),
('Context help', self.OnContextHelp, '-', 'ContextHelp'),
), 0)
self.il = wxImageList(24, 24)
self.SetImageList(self.il, wxIMAGE_LIST_SMALL)
EVT_LEFT_DOWN(self, self.OnSelectOrAdd)
EVT_LIST_ITEM_SELECTED(self, self.wxID_DATAVIEW, self.OnObjectSelect)
EVT_LIST_ITEM_DESELECTED(self, self.wxID_DATAVIEW, self.OnObjectDeselect)
self.selection = []
self.vetoSelect = false
self.active = true
def initialize(self):
if self.model.objectCollections.has_key(self.collectionMethod):
objCol = self.model.objectCollections[self.collectionMethod]
objCol.indexOnCtrlName()
else:
objCol = ObjCollection.ObjectCollection()
deps, depLinks = {}, {}
self.initObjectsAndCompanions(objCol.creators, objCol, deps, depLinks)
def initObjectsAndCompanions(self, creators, objColl, dependents, depLinks):
InspectableObjectView.initObjectsAndCompanions(self, creators, objColl, dependents, depLinks)
self.initIdOnlyObjEvts(objColl.events, creators)
def refreshCtrl(self):
self.DeleteAllItems()
if self.model.objectCollections.has_key(self.collectionMethod):
objCol = self.model.objectCollections[self.collectionMethod]
objCol.indexOnCtrlName()
else:
objCol = ObjCollection.ObjectCollection()
creators = {}
for ctrl in objCol.creators:
if ctrl.comp_name:
creators[ctrl.comp_name] = ctrl
for name in self.objectOrder:
idx = -1
ctrl = creators[name]
className = ctrl.class_name
try:
ClassObj = PaletteMapping.evalCtrl(className)
except NameError:
if className in self.model.customClasses:
ClassObj = self.model.customClasses[className]
else:
idx = self.il.Add(PaletteStore.bitmapForComponent(className,
'Component'))
else:
className = ClassObj.__name__
if idx == -1:
idx = self.il.Add(PaletteStore.bitmapForComponent(ClassObj))
self.InsertImageStringItem(self.GetItemCount(), '%s : %s' % (
ctrl.comp_name, className), idx)
self.opened = true
def saveCtrls(self, definedCtrls, module=None, collDeps=None):
InspectableObjectView.saveCtrls(self, definedCtrls, module, collDeps)
compns = []
for objInf in self.objects.values():
compns.append(objInf[0])
self.model.removeWindowIds(self.collectionMethod)
self.model.writeWindowIds(self.collectionMethod, compns)
def loadControl(self, CtrlClass, CtrlCompanion, ctrlName, params):
""" Create and register given control and companion.
See also: newControl """
args = self.setupArgs(ctrlName, params,
CtrlCompanion.handledConstrParams, evalDct = self.model.specialAttrs)
# Create control and companion
companion = CtrlCompanion(ctrlName, self, CtrlClass)
self.objects[ctrlName] = [companion, companion.designTimeObject(args), None]
self.objectOrder.append(ctrlName)
return ctrlName
def restore(self):
# This is needed for when the inspector switches to it's designer
self.model.editor.restore()
# XXX Should probably switch to the DataView page in the notebook.
def selectNone(self):
for itemIdx in range(self.GetItemCount()):
a = wxLIST_STATE_SELECTED
state = self.GetItemState(itemIdx, a)
self.SetItemState(itemIdx, 0, a)
def selectCtrls(self, ctrls):
for itemIdx in range(self.GetItemCount()):
name = self.GetItemText(itemIdx).split(' : ')[0]
a = wxLIST_STATE_SELECTED
if name in ctrls: f = a
else: f = 0
state = self.GetItemState(itemIdx, a)
self.SetItemState(itemIdx, f, a)
def deleteCtrl(self, name, parentRef = None):
self.selectNone()
# notify other components of deletion
if self.objects.has_key(name):
self.controllerView.notifyAction(self.objects[name][0], 'delete')
InspectableObjectView.deleteCtrl(self, name, parentRef)
self.refreshCtrl()
def renameCtrl(self, oldName, newName):
self.controllerView.renameCtrlAndParentRefs(oldName, newName)
InspectableObjectView.renameCtrl(self, oldName, newName)
self.refreshCtrl()
self.selectCtrls( (newName,) )
def destroy(self):
InspectableObjectView.destroy(self)
self.il = None
def close(self):
self.cleanup()
InspectableObjectView.close(self)
def getSelectedName(self):
return self.GetItemText(self.selection[0]).split(' : ')[0]
def getSelectedNames(self):
selected = []
for itemIdx in range(self.GetItemCount()):
name = self.GetItemText(itemIdx).split(' : ')[0]
state = self.GetItemState(itemIdx, wxLIST_STATE_SELECTED)
if state:
selected.append( (name, itemIdx) )
return selected
def OnSelectOrAdd(self, event=None):
""" Control is clicked. Either select it or add control from palette """
if self.compPal.selection:
CtrlClass, CtrlCompanion = self.compPal.selection[1:3]
# XXX this must be generic
if CtrlCompanion.host == 'Data' and self.viewName == 'Sizers' or \
CtrlCompanion.host == 'Sizers' and self.viewName == 'Data':
view = self.model.views[CtrlCompanion.host]
view.focus()
view.OnSelectOrAdd()
return
try:
objName = self.newObject(CtrlClass, CtrlCompanion)
except DesignerError, err:
if str(err) == 'Wrong Designer':
return
raise
self.compPal.selectNone()
self.refreshCtrl()
self.selectCtrls([objName])
else:
# Skip so that OnObjectSelect may be fired
if event:
event.Skip()
def updateSelection(self):
if len(self.selection) == 1:
self.inspector.selectObject(self.objects[self.selection[0][0]][0],
false, sessionHandler=self.controllerView)
else:
self.inspector.cleanup()
def OnObjectSelect(self, event):
self.inspector.containment.cleanup()
self.selection = self.getSelectedNames()
self.updateSelection()
def OnObjectDeselect(self, event):
event.Skip()
if self.vetoSelect: return
idx = 0
while idx < len(self.selection):
name, ctrlIdx = self.selection[idx]
if ctrlIdx == event.m_itemIndex:
del self.selection[idx]
else:
idx = idx + 1
self.updateSelection()
def OnPost(self, event):
""" Close all designers and save all changes """
self.controllerView.saveOnClose = true
self.close()
def OnCancel(self, event):
""" Close all designers and discard all changes """
self.controllerView.saveOnClose = false
self.controllerView.confirmCancel = true
self.close()
def OnCutSelected(self, event):
""" Cut current selection to the clipboard """
ctrls = [ni[0] for ni in self.selection]
output = []
self.cutCtrls(ctrls, [], output)
Utils.writeTextToClipboard(os.linesep.join(output))
self.refreshCtrl()
def OnCopySelected(self, event):
""" Copy current selection to the clipboard """
ctrls = [ni[0] for ni in self.selection]
output = []
self.copyCtrls(ctrls, [], output)
Utils.writeTextToClipboard(os.linesep.join(output))
def OnPasteSelected(self, event):
""" Paste current clipboard contents into the current selection """
pasted = self.pasteCtrls('', Utils.readTextFromClipboard().split(os.linesep))
if len(pasted):
self.refreshCtrl()
self.selectCtrls(pasted)
def OnControlDelete(self, event):
self.vetoSelect = true
try:
for name, idx in self.selection:
self.deleteCtrl(name)
finally:
self.vetoSelect = false
self.selection = self.getSelectedNames()
self.updateSelection()
def OnDefaultEditor(self, event):
if len(self.selection) == 1:
self.objects[self.selection[0][0]][0].defaultAction()
def OnContextHelp(self, event):
Help.showCtrlHelp(self.objects[self.selection[0][0]][0].GetClass())
def OnRecreateSelected(self, event):
wxLogError('Recreating not supported in the %s view'%self.viewName)
def OnCreationOrder(self, event):
names = [name for name, idx in self.getSelectedNames()]
self.showCreationOrderDlg(None)
self.refreshCtrl()
self.selectCtrls(names)
|