本文整理汇总了Python中component.Manager.getNodeComp方法的典型用法代码示例。如果您正苦于以下问题:Python Manager.getNodeComp方法的具体用法?Python Manager.getNodeComp怎么用?Python Manager.getNodeComp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类component.Manager
的用法示例。
在下文中一共展示了Manager.getNodeComp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FindObject
# 需要导入模块: from component import Manager [as 别名]
# 或者: from component.Manager import getNodeComp [as 别名]
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
示例2: paste
# 需要导入模块: from component import Manager [as 别名]
# 或者: from component.Manager import getNodeComp [as 别名]
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
示例3: createRef
# 需要导入模块: from component import Manager [as 别名]
# 或者: from component.Manager import getNodeComp [as 别名]
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)
示例4: moveLeft
# 需要导入模块: from component import Manager [as 别名]
# 或者: from component.Manager import getNodeComp [as 别名]
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)
示例5: setData
# 需要导入模块: from component import Manager [as 别名]
# 或者: from component.Manager import getNodeComp [as 别名]
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)
示例6: setData
# 需要导入模块: from component import Manager [as 别名]
# 或者: from component.Manager import getNodeComp [as 别名]
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)
示例7: OnData
# 需要导入模块: from component import Manager [as 别名]
# 或者: from component.Manager import getNodeComp [as 别名]
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
示例8: AddNode
# 需要导入模块: from component import Manager [as 别名]
# 或者: from component.Manager import getNodeComp [as 别名]
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))
示例9: undo
# 需要导入模块: from component import Manager [as 别名]
# 或者: from component.Manager import getNodeComp [as 别名]
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)
示例10: createRef
# 需要导入模块: from component import Manager [as 别名]
# 或者: from component.Manager import getNodeComp [as 别名]
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)
示例11: createTestWin
# 需要导入模块: from component import Manager [as 别名]
# 或者: from component.Manager import getNodeComp [as 别名]
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)
示例12: paste
# 需要导入模块: from component import Manager [as 别名]
# 或者: from component.Manager import getNodeComp [as 别名]
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())
if success:
node = Model.parseString(data)
comp = Manager.getNodeComp(node)
else:
node = Model.dom.createComment(data)
raise NotImplementedError
# 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)
# Add children
for n in filter(is_object, node.childNodes):
view.tree.AddNode(item, comp.getTreeNode(n))
self.setModified()
return item
示例13: AddNode
# 需要导入模块: from component import Manager [as 别名]
# 或者: from component.Manager import getNodeComp [as 别名]
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)
示例14: undo
# 需要导入模块: from component import Manager [as 别名]
# 或者: from component.Manager import getNodeComp [as 别名]
def undo(self):
# 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)
# Update tree and presenter
view.tree.Flush()
view.tree.SetFullState(self.states)
item = view.tree.ItemAtFullIndex(self.itemIndex)
view.tree.EnsureVisible(item)
# This will generate events
view.tree.SelectItem(item)
示例15: moveRight
# 需要导入模块: from component import Manager [as 别名]
# 或者: from component.Manager import getNodeComp [as 别名]
def moveRight(self):
parentItem = view.tree.GetItemParent(self.item)
parent = view.tree.GetPyData(parentItem)
newParent = view.tree.GetPyData(view.tree.GetPrevSibling(self.item))
newParentComp = Manager.getNodeComp(newParent)
if not newParentComp.canHaveChild(self.comp):
wx.LogError('Incompatible parent/child: parent is %s, child is %s!' %
(newParentComp.klass, self.comp.klass))
return
node = view.tree.GetPyData(self.item)
self.container.removeChild(parent, node)
newParentComp.appendChild(newParent, node)
index = view.tree.ItemFullIndex(self.item)
n = view.tree.GetChildrenCount(view.tree.GetPrevSibling(self.item))
self.flushSubtree(parentItem, parent)
index[-1] -= 1
index.append(n)
self.item = view.tree.ItemAtFullIndex(index)
self.setModified()
view.tree.SelectItem(self.item)