Пример #1
0
def GetPrevVisible(self, item):
    """Taken from the wxgeneric GetPrevVisible. 
	
	This is missing in wxGTK 2.8.* and wxMac 2.8.4.1"""
    assert item.IsOk(), "invalid tree item"
    assert self.IsVisible(item), "this item itself should be visible"

    # find out the starting point
    prevItem = self.GetPrevSibling(item)
    if not prevItem.IsOk():
        prevItem = self.GetItemParent(item)

    # find the first visible item after it
    while prevItem.IsOk() and not self.IsVisible(prevItem):
        prevItem = self.GetNext(prevItem)
        if not prevItem.IsOk() or prevItem == item:
            # there are no visible items before item
            return wx.TreeItemId()

    # from there we must be able to navigate until this item
    while (prevItem.IsOk()):
        nextItem = self.GetNextVisible(prevItem)
        if not nextItem.IsOk() or nextItem == item:
            break

        prevItem = nextItem

    return prevItem
Пример #2
0
 def GetFirstVisibleItem(self):
     # TreeListCtrl raises an exception or even crashes when invoking
     # GetFirstVisibleItem on an empty tree.
     if self.GetRootItem():
         return super(TreeAPIHarmonizer, self).GetFirstVisibleItem()
     else:
         return wx.TreeItemId()
Пример #3
0
 def FindItem(item, text):
     subItem, cookie = tree.GetFirstChild(item)
     while subItem.IsOk():
         if tree.GetItemData(subItem).Data.name == text:
             return subItem
         FindItem(subItem, text)
         subItem = tree.GetNextSibling(subItem)
     return wx.TreeItemId()
Пример #4
0
 def FindItem(self, parentItem, text):        
     item, cookie = self.tree.GetFirstChild(parentItem)
     while item:
         if self.tree.GetItemText(item) == text:
             return item
         if self.tree.ItemHasChildren(item):
             item = self.FindItem(item, text)
         item, cookie = self.tree.GetNextChild(parentItem, cookie)
     return wx.TreeItemId();
Пример #5
0
 def GetSelection(self):
     """ Extend GetSelection to never return the root item if the
         root item is hidden. """
     selection = super(IterableTreeCtrl, self).GetSelection()
     if selection == self.GetRootItem() and \
         (self.GetWindowStyle() & wx.TR_HIDE_ROOT):
         return wx.TreeItemId()  # Return an invalid TreeItemId
     else:
         return selection
Пример #6
0
 def InsertItemCopy(self, parent, src, prev, recursively = True):
     """Insert a copy of src under parent, after prev. Copy all children,
     and recurse if desired.  Returns the wx.TreeItemId of the copy, or an
     invalid item if something went wrong."""
     # Make sure parent, src, and prev are valid
     if not parent.IsOk() or not src.IsOk() or not prev.IsOk():
         return wx.TreeItemId()
     # Make sure prev is a child of parent
     if self.GetItemParent(prev) != parent:
         return wx.TreeItemId()
     # Create a new copy of src under parent
     newItem = self.InsertItem(parent, prev, self.GetItemText(src),
         self.GetItemImage(src),
         self.GetItemImage(src, wx.TreeItemIcon_Selected))
     self.SetPyData(newItem, self.GetPyData(src))
     # Copy children, recurse if desired
     self.CopyChildren(newItem, src, recursively)
     # Return the new copy
     return newItem
Пример #7
0
 def HitTest(self, point): # pylint: disable=W0221, C0103
     ''' Always return a three-tuple (item, flags, column). '''
     if type(point) == type(()):
         point = wx.Point(point[0], point[1])
     hit_test_result = super(HyperTreeList, self).HitTest(point)
     if len(hit_test_result) == 2:
         hit_test_result += (0,)
     if hit_test_result[0] is None:
         hit_test_result = (wx.TreeItemId(),) + hit_test_result[1:]
     return hit_test_result
Пример #8
0
 def FindItem(self, parentItem, text):
     """
     Найти дочерний элемент по лейблу.
     """
     item, cookie = self.tree.GetFirstChild(parentItem)
     while item:
         if self.tree.GetItemText(item) == text:
             return item
         if self.tree.ItemHasChildren(item):
             item = self.FindItem(item, text)
         item, cookie = self.tree.GetNextChild(parentItem, cookie)
     return wx.TreeItemId()
 def findItem(self, parent_item, text):
     """
     Find child item by text.
     """
     item, cookie = self.tree.GetFirstChild(parent_item)
     while item:
         if self.tree.GetItemText(item) == text:
             return item
         if self.tree.ItemHasChildren(item):
             item = self.findItem(item, text)
         item, cookie = self.tree.GetNextChild(parent_item, cookie)
     return wx.TreeItemId()
Пример #10
0
    def GetItemByLabel(self, tree, search_text, root_item):
        item, cookie = tree.GetFirstChild(root_item)

        while item.IsOk():
            text = tree.GetItemText(item)
            if text.lower() == search_text.lower():
                return item
            if tree.ItemHasChildren(item):
                match = self.GetItemByLabel(tree, search_text, item)
                if match.IsOk():
                    return match
            item, cookie = tree.GetNextChild(root_item, cookie)

        return wx.TreeItemId()
Пример #11
0
 def InsertItemMove(self, parent, src, prev):
     """Move src, and all its descendants, under parent, after parent's
     child prev.  If src is an ancestor of parent, do nothing.  Returns the
     wx.TreeItemId of the copy, or an invalid item if something went
     wrong."""
     # If src is an ancestor of parent, return. (Cannot move
     # a branch into its own sub-branch)
     if self.ItemIsAncestorOf(src, parent):
         return wx.TreeItemId()
     # Copy src to parent and recurse
     newItem = self.InsertItemCopy(parent, src, prev, True)
     # Delete src and all its children
     self.Delete(src)
     return newItem
Пример #12
0
    def _get_item_by_label(self, search_text):
        """
        Search a label with given text and return its id.
        :param search_text: label to search in the tree
        :return: Id of the label
        """

        item, cookie = self.tree.GetFirstChild(self.root)

        while item.IsOk():
            text = self.tree.GetItemText(item)
            if text == search_text:
                return item
            item, cookie = self.tree.GetNextChild(self.root, cookie)
        return wx.TreeItemId()
Пример #13
0
 def AppendItemCopy(self, parent, src, recursively = True):
     """Append a copy of src under parent. Copy all children, and recurse if
     desired.  Returns the wx.TreeItemId of the copy, or an invalid item if
     something went wrong."""
     # Make sure parent and src are valid
     if not parent.IsOk() or not src.IsOk():
         return wx.TreeItemId()
     # Create a new copy of src under parent
     newItem = self.AppendItem(parent, self.GetItemText(src),
         self.GetItemImage(src), self.GetItemImage(src, wx.TreeItemIcon_Selected))
     self.SetPyData(newItem, self.GetPyData(src))
     # Copy children, recurse if desired
     self.CopyChildren(newItem, src, recursively)
     # Return the new copy
     return newItem
Пример #14
0
    def _get_item_by_label(self, search_text, root_item):
        """ Search the item that as 'search_text' as text and returns it.
        If not found, return a new wx.TreeItemId()

        """
        item, cookie = self._filestree.GetFirstChild(root_item)

        while item.IsOk():
            text = self._filestree.GetItemText(item)
            if text.lower() == search_text.lower():
                return item
            if self._filestree.ItemHasChildren(item):
                match = self._get_item_by_label(search_text, item)
                if match.IsOk():
                    return match
            item, cookie = self._filestree.GetNextChild(root_item, cookie)

        return wx.TreeItemId()
Пример #15
0
    def GetNextSiblingRecursively(self, item):
        """ 
        GetNextSiblingRecursively(self, TreeItemId item) -> TreeItemId

        Returns the next sibling of item if it has one. If item has no
        next sibling the next sibling of the parent of item is returned. 
        If the parent has no next sibling the next sibling of the parent 
        of the parent is returned, etc. If none of the ancestors of item
        has a next sibling, an invalid item is returned. 
        """
        if item == self.GetRootItem():
            return wx.TreeItemId()  # Return an invalid TreeItemId
        nextSibling = self.GetNextSibling(item)
        if nextSibling:
            return nextSibling
        else:
            parent = self.GetItemParent(item)
            return self.GetNextSiblingRecursively(parent)
Пример #16
0
    def RecursiveFindByNode(self, tree, tree_item, node):
        tree_node = tree.GetItemData(tree_item)

        if tree_node == node:
            return tree_item

        elif tree.ItemHasChildren(tree_item):
            child, cookie = tree.GetFirstChild(tree_item)

            while child.IsOk():
                item = self.RecursiveFindByNode(tree, child, node)

                if item.IsOk():
                    return item

                else:
                    child, cookie = tree.GetNextChild(tree_item, cookie)

        return wx.TreeItemId()
Пример #17
0
    def GetNextSiblingRecursively(self, item):
        """
        Returns the next sibling of item if it has one. If item has no
        next sibling the next sibling of the parent of item is returned.
        If the parent has no next sibling the next sibling of the parent
        of the parent is returned, etc. If none of the ancestors of item
        has a next sibling, an invalid item is returned.

        :param TreeItemId `item`: a :class:`TreeItemId`
        :return: :class:`TreeItemId` of the next item or an invalid item
        :rtype: :class:`TreeItemId`

        """
        if item == self.GetRootItem():
            return wx.TreeItemId()  # Return an invalid TreeItemId
        nextSibling = self.GetNextSibling(item)
        if nextSibling:
            return nextSibling
        else:
            parent = self.GetItemParent(item)
            return self.GetNextSiblingRecursively(parent)
Пример #18
0
    def _add_item(self, parent, son, isdir=False):
        """ Add an item 'son' of type 'type' to the node 'parent'

        :param son: is text of the item to be added
        :param parent: is the node to which the item will be added
        :param isdir: is true if the item to add is a dir

        :returns the child

        """
        fileName, fileExtension = os.path.splitext(son.lower())

        if isdir:
            child = self._filestree.AppendItem(parent, son)
            self._filestree.SetPyData(child, None)
            self._filestree.SetItemImage(child,
                                         self.fldridx,
                                         which=wx.TreeItemIcon_Normal)
            self._filestree.SetItemImage(child,
                                         self.fldropenidx,
                                         which=wx.TreeItemIcon_Expanded)

        elif fileExtension in sppas.src.audiodata.aio.extensions:
            child = self._filestree.AppendItem(parent, son)
            self._filestree.SetPyData(child, None)
            self._filestree.SetItemImage(child, self.wavfileidx,
                                         wx.TreeItemIcon_Normal)

        elif fileExtension in [".txt", ".ctm", ".stm", ".lab", ".mlf"]:
            child = self._filestree.AppendItem(parent, son)
            self._filestree.SetPyData(child, None)
            self._filestree.SetItemImage(child, self.txtfileidx,
                                         wx.TreeItemIcon_Normal)

        elif fileExtension == ".csv":
            child = self._filestree.AppendItem(parent, son)
            self._filestree.SetPyData(child, None)
            self._filestree.SetItemImage(child, self.csvfileidx,
                                         wx.TreeItemIcon_Normal)

        elif fileExtension == ".textgrid":
            child = self._filestree.AppendItem(parent, son)
            self._filestree.SetPyData(child, None)
            self._filestree.SetItemImage(child, self.tgridfileidx,
                                         wx.TreeItemIcon_Normal)

        elif fileExtension in [".pitchtier", ".hz"]:
            child = self._filestree.AppendItem(parent, son)
            self._filestree.SetPyData(child, None)
            self._filestree.SetItemImage(child, self.ptierfileidx,
                                         wx.TreeItemIcon_Normal)

        elif fileExtension == ".trs":  # Transcriber
            child = self._filestree.AppendItem(parent, son)
            self._filestree.SetPyData(child, None)
            self._filestree.SetItemImage(child, self.trsfileidx,
                                         wx.TreeItemIcon_Normal)

        elif fileExtension == ".mrk":  # Phonedit
            child = self._filestree.AppendItem(parent, son)
            self._filestree.SetPyData(child, None)
            self._filestree.SetItemImage(child, self.mrkfileidx,
                                         wx.TreeItemIcon_Normal)

        elif fileExtension == ".eaf":  # Elan
            child = self._filestree.AppendItem(parent, son)
            self._filestree.SetPyData(child, None)
            self._filestree.SetItemImage(child, self.eaffileidx,
                                         wx.TreeItemIcon_Normal)

        elif fileExtension == ".xra":  # SPPAS
            child = self._filestree.AppendItem(parent, son)
            self._filestree.SetPyData(child, None)
            self._filestree.SetItemImage(child, self.xrafileidx,
                                         wx.TreeItemIcon_Normal)

        elif fileExtension in [".srt", ".sub"]:
            child = self._filestree.AppendItem(parent, son)
            self._filestree.SetPyData(child, None)
            self._filestree.SetItemImage(child, self.subfileidx,
                                         wx.TreeItemIcon_Normal)

        elif fileExtension == ".anvil":
            child = self._filestree.AppendItem(parent, son)
            self._filestree.SetPyData(child, None)
            self._filestree.SetItemImage(child, self.anvilfileidx,
                                         wx.TreeItemIcon_Normal)

        elif fileExtension == ".antx":
            child = self._filestree.AppendItem(parent, son)
            self._filestree.SetPyData(child, None)
            self._filestree.SetItemImage(child, self.antxfileidx,
                                         wx.TreeItemIcon_Normal)

        elif fileExtension == ".tdf":
            child = self._filestree.AppendItem(parent, son)
            self._filestree.SetPyData(child, None)
            self._filestree.SetItemImage(child, self.xtransfileidx,
                                         wx.TreeItemIcon_Normal)

        elif fileExtension == ".aup":
            child = self._filestree.AppendItem(parent, son)
            self._filestree.SetPyData(child, None)
            self._filestree.SetItemImage(child, self.aupfileidx,
                                         wx.TreeItemIcon_Normal)

        else:
            return wx.TreeItemId()

        return child
Пример #19
0
 def testTreeItemIdIsFalseDefault(self):
     self.failIf(wx.TreeItemId())