本文整理汇总了Python中tree.Tree.getChildren方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.getChildren方法的具体用法?Python Tree.getChildren怎么用?Python Tree.getChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree.Tree
的用法示例。
在下文中一共展示了Tree.getChildren方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Foo
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import getChildren [as 别名]
class Foo(QtGui.QMainWindow):
def __init__(self):
super(Foo, self).__init__()
self.initUI()
def initUI(self):
config = Foo.readConfig('options')
self.timeOut = -1
self.radio = False
self.statusBar().showMessage('Ready')
self.createMenu()
self.setWindowTitle("Foo.cd")
self.player = Player(Foo.readConfig('audio'))
self.player.bus.connect('message::eos', self.stop)
self.player.bus.connect('message::duration-changed', self.onDurationChanged)
self.tree = Tree(self, config['tree_order'])
self.tree.addSongs.connect(self.addSongsFromTree)
self.tree.customContextMenuRequested.connect(self.tmpTag)
if not self.radio:
self.table=Table( self, config)
self.handlerATF = self.player.playbin.connect("about-to-finish", self.onAboutToFinish)
self.table.runAction.connect(self.tableAction)
else:
configRadio = Foo.readConfigRadios()
self.table=TableRadio( self, configRadio)
self.table.runAction.connect(self.tableAction)
self.handlerT = self.player.bus.connect('message::tag', self.table.onTag)
self.playbackButtons = PlaybackButtons(None)
self.playbackButtons.buttonPlay.clicked.connect(self.toggleSong)
self.playbackButtons.buttonStop.clicked.connect(self.stop)
self.playbackButtons.buttonPrev.clicked.connect(self.previous)
self.playbackButtons.buttonNext.clicked.connect(self.next)
self.volumeSlider = VolumeSlider(self)
self.volumeSlider.sliderMoved.connect(self.player.setVolume)
self.scrollSlider = ScrollSlider(self)
self.scrollSlider.sliderPressed.connect(self.player.toggle)
self.scrollSlider.sliderReleased.connect(self.player.toggle)
self.scrollSlider.sliderMoved.connect(self.player.seek)
self.pixmap = Image(self, config['cover_names'], config['extensions'])
# Album cover connections
self.tree.selectionModel().selectionChanged.connect(lambda: self.pixmap.onSelectionChanged(self.tree.getChildren()[0].get('file', None)))
self.table.selectionModel().selectionChanged.connect(lambda: self.pixmap.onSelectionChanged(self.table.getSelection().get('file', None)))
self.searchArea = SearchArea(self)
self.searchArea.searchLine.returnPressed.connect(self.startSearch)
self.playbackButtons.addWidget(self.volumeSlider)
self.playbackButtons.addWidget(self.scrollSlider)
splitterLeftRight = QtGui.QSplitter()
self.splitterTopBottom = QtGui.QSplitter(Qt.Vertical, self)
self.infoFrame = QtGui.QFrame()
infoLayout = QtGui.QVBoxLayout()
infoLayout.setContentsMargins(0,0,0,0)
infoLayout.addLayout(self.playbackButtons)
infoLayout.addWidget(self.pixmap)
self.infoFrame.setLayout(infoLayout)
libLayout = QtGui.QVBoxLayout()
libLayout.setContentsMargins(0,0,0,0)
libLayout.addWidget(self.tree)
libLayout.addLayout(self.searchArea)
libFrame = QtGui.QFrame()
libFrame.setLayout(libLayout)
self.splitterTopBottom.addWidget(self.table)
self.splitterTopBottom.addWidget(self.infoFrame)
self.splitterTopBottom.setStretchFactor(0,1)
#self.splitterTopBottom.setStretchFactor(1,0)
splitterLeftRight.addWidget(libFrame)
splitterLeftRight.addWidget(self.splitterTopBottom)
splitterLeftRight.setStretchFactor(0,2)
splitterLeftRight.setStretchFactor(1,3)
mainLayout = QtGui.QGridLayout()
mainLayout.setContentsMargins(4, 4, 4, 4)
mainLayout.addWidget(splitterLeftRight)
dummyWidget = QtGui.QWidget()
dummyWidget.setLayout(mainLayout)
self.setCentralWidget(dummyWidget)
self.setTabOrder(self.tree, self.table)
dictShortcuts = self.readConfig('shortcuts')
modifier = dictShortcuts['modifier']+'+'
self.shortQuit = QtGui.QShortcut(QtGui.QKeySequence(modifier+dictShortcuts['quit']), self, self.close)
self.shortStop = QtGui.QShortcut(QtGui.QKeySequence(modifier+dictShortcuts['stop']), self, self.stop)
self.shortPlayPause = QtGui.QShortcut(QtGui.QKeySequence(modifier+dictShortcuts['play_pause']), self, self.toggleSong)
self.shortSongPrevious = QtGui.QShortcut(QtGui.QKeySequence(modifier+dictShortcuts['previous']), self, self.previous)
#.........这里部分代码省略.........
示例2: TestTree
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import getChildren [as 别名]
class TestTree(unittest.TestCase):
def setUp(self):
self.root = Tree(NAME)
self.tree2 = None
self.tree3 = None
self.tree4 = None
def _AddChild(self, name):
new_tree = Tree(name)
self.root.addChild(new_tree)
return new_tree
def _createComplexTree(self):
"""
Creates the following tree
NAME1->NAME2->NAME4
NAME1->NAME3
"""
self.tree2 = self._AddChild(NAME2)
self.tree3 = self._AddChild(NAME3)
self.tree4 = Tree(NAME4)
self.tree2.addChild(self.tree4)
def testConstructor(self):
if IGNORE_TEST:
return
self.assertEqual(self.root._name, NAME)
self.assertEqual(len(self.root._children), 0)
def testAddChild(self):
if IGNORE_TEST:
return
new_tree = self._AddChild(NAME2)
self.assertEqual(len(self.root._children), 1)
self.assertEqual(self.root._children[0], new_tree)
newer_tree = self._AddChild(NAME3)
self.assertEqual(len(self.root._children), 2)
self.assertEqual(self.root._children[1], newer_tree)
def testAddChildComplex(self):
if IGNORE_TEST:
return
self._createComplexTree()
self.assertTrue(self.tree4 in self.tree2.getChildren())
def testRemoveChildSimple(self):
if IGNORE_TEST:
return
new_tree = self._AddChild(NAME2)
new_tree.removeTree()
self.assertIsNone(new_tree._parent)
self.assertEqual(len(self.root._children), 0)
def testRemoveChildComplex(self):
if IGNORE_TEST:
return
self._createComplexTree()
self.tree4.removeTree()
self.assertIsNone(self.tree4._parent)
self.assertEqual(len(self.tree2._children), 0)
self.assertEqual(len(self.root._children), 2)
def testGetRoot(self):
if IGNORE_TEST:
return
self._createComplexTree()
self.assertEqual(self.tree2._children[0], self.tree4)
root = self.tree4.getRoot()
self.assertEqual(root, self.root)
root = self.root.getRoot()
self.assertEqual(root, self.root)
root = self.tree3.getRoot()
self.assertEqual(root, self.root)
def testGetChildrenFromRoot(self):
if IGNORE_TEST:
return
self._createComplexTree()
children = self.tree2.getChildren(is_from_root=False)
self.assertEqual(children, [self.tree4])
children = self.tree4.getChildren(is_from_root=True,
is_recursive=True)
self.assertEqual(len(children), 3)
self.assertFalse(self.root in children)
self.assertTrue(self.tree2 in children)
self.assertTrue(self.tree4 in children)
def testGetChildrenFromSelf(self):
if IGNORE_TEST:
return
self._createComplexTree()
children = self.tree2.getChildren(is_from_root=False)
grandchildren = self.tree4.getChildren(is_from_root=False)
self.assertEqual(len(children), 1)
self.assertEqual(len(grandchildren), 0)
self.assertTrue(self.tree4 in children)
def testFindPathFromRoot(self):
#.........这里部分代码省略.........