本文整理汇总了Python中component.Manager类的典型用法代码示例。如果您正苦于以下问题:Python Manager类的具体用法?Python Manager怎么用?Python Manager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Manager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AddNode
def AddNode(self, parent, node):
# Append tree item
try:
comp = Manager.getNodeComp(node, None)
className = comp.klass
except:
className = node.getAttribute('class')
# Try to create some generic component on-the-fly
attributes = []
isContainer = False
for n in node.childNodes:
if is_object(n):
isContainer = True
elif n.nodeType == node.ELEMENT_NODE and not n.tagName in attributes:
attributes.append(n.tagName)
if isContainer:
comp = Container(className, 'unknown', attributes)
else:
comp = Component(className, 'unknown', attributes)
Manager.register(comp)
wx.LogWarning('Unknown component class "%s", registered as generic' % className)
item = self.AppendItem(parent, comp.getTreeText(node),
image=comp.getTreeImageId(node),
data=wx.TreeItemData(node))
self.SetItemStyle(item, node)
# Try to find children objects
if comp.isContainer():
for n in filter(is_object, node.childNodes):
self.AddNode(item, comp.getTreeNode(n))
示例2: OnData
def OnData(self, x, y, d):
view.testWin.RemoveHighlightDT()
self.onHL = self.left = False
self.GetData()
id = int(self.do.GetDataHere())
d,other = self.WhereToDrop(x, y, d)
if d != wx.DragNone and other:
obj,item = other
g.Presenter.setData(item)
comp = Manager.findById(id)
mouseState = wx.GetMouseState()
forceSibling = mouseState.ControlDown()
forceInsert = mouseState.ShiftDown()
g.Presenter.updateCreateState(forceSibling, forceInsert)
if not g.Presenter.checkCompatibility(comp):
return wx.DragNone
item = g.Presenter.create(comp)
node = view.tree.GetPyData(item)
parentItem = view.tree.GetItemParent(item)
parentNode = view.tree.GetPyData(parentItem)
parentComp = Manager.getNodeComp(parentNode)
# If pos if not set by default and parent is not a sizer, set pos to
# drop coordinates
if 'pos' in comp.attributes and not comp.getAttribute(node, 'pos') \
and parentComp.isContainer() and \
not parentComp.isSizer():
# Calc relative coords
rect = view.testWin.FindObjectRect(parentItem)
x -= rect[0].x
y -= rect[0].y
comp.addAttribute(node, 'pos', '%d,%d' % (x, y))
g.Presenter.setData(item)
view.frame.SetStatusText('Object created')
return d
示例3: FindObject
def FindObject(self, item):
tree = view.tree
if not item or item == tree.root:
return None
if item == self.item: return self.object
# Traverse tree until we reach the root or the test object
items = [item]
while 1:
item = tree.GetItemParent(item)
if item == tree.root: return None # item outside if the test subtree
elif item == self.item: break
else: items.append(item)
# Now traverse back, searching children
obj = self.object
comp = Manager.getNodeComp(tree.GetPyData(self.item))
while items and obj:
if not (isinstance(obj, wx.Window) or isinstance(obj, wx.Sizer)):
return None
parentItem = item
item = items.pop()
index = tree.ItemIndex(item)
obj = comp.getChildObject(tree.GetPyData(parentItem), obj, index)
node = tree.GetPyData(item)
comp = Manager.getNodeComp(node)
return obj
示例4: paste
def paste(self):
success = success_node = False
if wx.TheClipboard.IsOpened() or wx.TheClipboard.Open():
try:
data = wx.CustomDataObject("XRCED_elem")
if wx.TheClipboard.IsSupported(data.GetFormat()):
try:
success = wx.TheClipboard.GetData(data)
except:
# there is a problem if XRCED_node is in clipboard
# but previous SetData was for XRCED
pass
if not success: # try other format
data = wx.CustomDataObject("XRCED_node")
if wx.TheClipboard.IsSupported(data.GetFormat()):
success_node = wx.TheClipboard.GetData(data)
finally:
wx.TheClipboard.Close()
if not success and not success_node:
wx.MessageBox("There is no data in the clipboard in the required format", "Error")
return
# XML representation of element or node value string
data = cPickle.loads(data.GetData())
implicit = None
if success:
if type(data) is list:
node = Model.parseString(data[0])
implicit = Model.parseString(data[1])
else:
node = Model.parseString(data)
else:
node = Model.dom.createComment(data)
comp = Manager.getNodeComp(node)
# Check compatibility
if not self.checkCompatibility(comp):
node.unlink()
return
item = view.tree.GetSelection()
if item and not self.applied:
self.update(item)
item = self.create(comp, node)
if implicit: # copy parameters for implicit node if possible
parentNode = view.tree.GetPyData(view.tree.GetItemParent(item))
parentComp = Manager.getNodeComp(parentNode)
if parentComp.requireImplicit(node) and parentComp.implicitKlass == implicit.getAttribute("class"):
parentComp.copyImplicitAttributes(implicit, node.parentNode, parentComp)
implicit.unlink()
# Add children
for n in filter(is_object, node.childNodes):
view.tree.AddNode(item, comp.getTreeNode(n))
self.setModified()
return item
示例5: createRef
def createRef(self, ref, child=None):
'''Create object_ref element node.'''
if child is None:
child = Model.createRefNode(ref)
refNode = Model.findResource(ref)
if refNode:
comp = Manager.getNodeComp(refNode)
else:
comp = Manager.getNodeComp(child)
self.create(comp, child)
示例6: createTestWin
def createTestWin(self, item):
TRACE('createTestWin')
# Create a window with this resource
node = view.tree.GetPyData(item)
# Close old window, remember where it was
comp = Manager.getNodeComp(node)
# Create memory XML file
elem = node.cloneNode(True)
if not node.hasAttribute('name'):
name = 'noname'
else:
name = node.getAttribute('name')
elem.setAttribute('name', STD_NAME)
Model.setTestElem(elem)
Model.saveTestMemoryFile()
xmlFlags = 0
if not g.conf.useSubclassing:
xmlFlags |= xrc.XRC_NO_SUBCLASSING
# Use translations if encoding is not specified
if not Model.dom.encoding:
xmlFlags |= xrc.XRC_USE_LOCALE
res = xrc.EmptyXmlResource(xmlFlags)
xrc.XmlResource.Set(res) # set as global
# Init other handlers
Manager.addXmlHandlers(res)
Manager.preload(res)
# Same module list
res.Load('memory:test.xrc')
object = None
testWin = view.testWin
try:
try:
frame, object = comp.makeTestWin(res, name)
if not object: # skip the rest
raise EOFError
# Reset previous tree item and locate tool
if testWin.item:
view.tree.SetItemBold(testWin.item, False)
testWin.SetView(frame, object, item)
testWin.Show()
view.tree.SetItemBold(item, True)
except EOFError:
pass
except NotImplementedError:
wx.LogError('Test window not implemented for %s' % node.getAttribute('class'))
logger.exception('error creating test view')
except:
logger.exception('error creating test view')
wx.LogError('Error creating test view')
if get_debug(): raise
finally:
# Cleanup
res.Unload(TEST_FILE)
xrc.XmlResource.Set(None)
wx.MemoryFSHandler.RemoveFile(TEST_FILE)
示例7: setData
def setData(self, item):
'''Set data and view for current tree item.'''
self.item = item
if item == view.tree.root:
TRACE('setData: root node')
self.container = None
self.comp = Manager.rootComponent
self.panels = view.panel.SetData(self.container, self.comp, Model.mainNode)
else:
node = view.tree.GetPyData(item)
if node.nodeType != node.COMMENT_NODE:
TRACE('setData: %s', node.getAttribute('class'))
self.comp = Manager.getNodeComp(node)
parentItem = view.tree.GetItemParent(item)
parentNode = view.tree.GetPyData(parentItem)
if parentNode == Model.mainNode:
self.container = Manager.rootComponent
else:
parentClass = parentNode.getAttribute('class')
self.container = Manager.components[parentClass]
self.panels = view.panel.SetData(self.container, self.comp, node)
# Create new pending undo
self.createUndoEdit(self.item)
if view.testWin.IsShown():
self.highlight(item)
示例8: undo
def undo(self):
Presenter.unselect()
# Updating DOM. Find parent node first
parentItem = view.tree.ItemAtFullIndex(self.itemIndex[:-1])
parentNode = view.tree.GetPyData(parentItem)
parentComp = Manager.getNodeComp(parentNode)
nextItem = view.tree.ItemAtFullIndex(self.itemIndex)
if nextItem:
nextNode = parentComp.getTreeOrImplicitNode(view.tree.GetPyData(nextItem))
else:
nextNode = None
# Insert before next
parentNode.insertBefore(self.node, nextNode)
# Remember test window item
if view.testWin.item is not None:
testItemIndex = view.tree.ItemFullIndex(view.testWin.item)
# Update tree and presenter
view.tree.FlushSubtree(parentItem, parentNode)
view.tree.SetFullState(self.state)
# Restore test window item
if view.testWin.item is not None:
view.testWin.item = view.tree.ItemAtFullIndex(testItemIndex)
item = view.tree.ItemAtFullIndex(self.itemIndex)
view.tree.EnsureVisible(item)
# This will generate events
view.tree.SelectItem(item)
示例9: setData
def setData(self, item):
"""Set data and view for current tree item."""
self.item = item
if item == view.tree.root:
TRACE("setData: root node")
self.container = None
self.comp = Manager.rootComponent
# self.panels = []
# view.panel.Clear()
self.panels = view.panel.SetData(self.container, self.comp, Model.mainNode)
else:
node = view.tree.GetPyData(item)
TRACE("setData: %s", node.getAttribute("class"))
self.comp = Manager.getNodeComp(node)
parentItem = view.tree.GetItemParent(item)
parentNode = view.tree.GetPyData(parentItem)
if parentNode == Model.mainNode:
self.container = Manager.rootComponent
else:
parentClass = parentNode.getAttribute("class")
self.container = Manager.components[parentClass]
self.panels = view.panel.SetData(self.container, self.comp, node)
# Create new pending undo
self.createUndoEdit(self.item)
if view.testWin.IsShown():
self.highlight(item)
示例10: moveLeft
def moveLeft(self):
parentItem = view.tree.GetItemParent(self.item)
grandParentItem = view.tree.GetItemParent(parentItem)
parent = view.tree.GetPyData(parentItem)
grandParent = view.tree.GetPyData(grandParentItem)
if grandParent is Model.mainNode:
grandParentComp = Manager.rootComponent
else:
grandParentComp = Manager.getNodeComp(grandParent)
if not grandParentComp.canHaveChild(self.comp):
wx.LogError('Incompatible parent/child: parent is %s, child is %s!' %
(grandParentComp.klass, self.comp.klass))
return
node = view.tree.GetPyData(self.item)
nextItem = view.tree.GetNextSibling(parentItem)
self.container.removeChild(parent, node)
if nextItem:
nextNode = view.tree.GetPyData(nextItem)
grandParentComp.insertBefore(grandParent, node, nextNode)
else:
grandParentComp.appendChild(grandParent, node)
index = view.tree.ItemFullIndex(self.item)
self.flushSubtree(grandParentItem, grandParent)
index.pop()
index[-1] += 1
self.item = view.tree.ItemAtFullIndex(index)
self.setModified()
view.tree.SelectItem(self.item)
示例11: OnComponentReplace
def OnComponentReplace(self, evt):
'''Hadnler for creating new elements.'''
comp = Manager.findById(evt.GetId() - ID.SHIFT)
item = self.tree.GetSelection()
index = self.tree.ItemFullIndex(item)
oldComp = Presenter.comp
oldNode = Presenter.replace(comp)
g.undoMan.RegisterUndo(undo.UndoReplace(index, oldComp, oldNode))
示例12: AddNode
def AddNode(self, parent, node):
# Append tree item
try:
comp = Manager.getNodeComp(node, None)
className = comp.klass
except:
className = node.getAttribute("class")
# Try to create some generic component on-the-fly
attributes = []
isContainer = False
for n in node.childNodes:
if is_element(n):
isContainer = True
elif n.nodeType == node.ELEMENT_NODE and not n.tagName in attributes:
attributes.append(n.tagName)
if isContainer:
comp = Container(className, "unknown", attributes)
else:
comp = Component(className, "unknown", attributes)
Manager.register(comp)
wx.LogWarning('Unknown component class "%s", registered as generic' % className)
item = self.AppendItem(
parent, comp.getTreeText(node), image=comp.getTreeImageId(node), data=wx.TreeItemData(node)
)
self.SetItemStyle(item, node)
# Try to find children objects
if comp.isContainer():
for n in filter(is_object, node.childNodes):
self.AddNode(item, comp.getTreeNode(n))
elif node.nodeType == node.COMMENT_NODE:
if node.data and node.data[0] == "%" and g.conf.allowExec != "no":
if g.conf.allowExec == "ask" and Model.allowExec is None:
say = wx.MessageBox(
"""This file contains executable comment directives. \
Allow to execute?""",
"Warning",
wx.ICON_EXCLAMATION | wx.YES_NO,
)
if say == wx.YES:
Model.allowExec = True
else:
Model.allowExec = False
if g.conf.allowExec == "yes" or Model.allowExec:
code = node.data[1:] # skip '%'
self.ExecCode(code)
示例13: OnComponentCreate
def OnComponentCreate(self, evt):
'''Hadnler for creating new elements.'''
comp = Manager.findById(evt.GetId())
g.undoMan.RegisterUndo(undo.UndoGlobal()) # !!! TODO
if comp.groups[0] == 'component':
node = Model.createComponentNode('Component')
Presenter.create(comp, node)
else:
Presenter.create(comp)
示例14: createRef
def createRef(self, ref, child=None):
"""Create object_ref element node."""
if child is None:
child = Model.createRefNode(ref)
refNode = Model.findResource(ref)
if not refNode:
return None
comp = Manager.getNodeComp(refNode)
self.create(comp, child)
示例15: OnComponentCreate
def OnComponentCreate(self, evt):
'''Hadnler for creating new elements.'''
state = self.tree.GetFullState() # state just before
comp = Manager.findById(evt.GetId())
if comp.groups[0] == 'component':
node = Model.createComponentNode('Component')
item = Presenter.create(comp, node)
else:
item = Presenter.create(comp)
itemIndex = self.tree.ItemFullIndex(item)
g.undoMan.RegisterUndo(undo.UndoPasteCreate(itemIndex, state))