예제 #1
0
파일: tree.py 프로젝트: pbrod/pyface
    def _create_lhs(self, parent):
        """ Creates the left hand side or top depending on the split. """

        self._tree = FileTree(parent, root=os.path.abspath(os.curdir))

        self._tree.on_trait_change(self._on_tree_anytrait_changed)

        return self._tree.control
예제 #2
0
파일: tree.py 프로젝트: enthought/pyface
    def _create_lhs(self, parent):
        """ Creates the left hand side or top depending on the split. """

        self._tree = FileTree(parent, root=os.path.abspath(os.curdir))

        self._tree.observe(
            self._on_tree_anytrait_changed,
            match(lambda name, ctrait: True)  # listen to all traits
        )

        return self._tree.control
예제 #3
0
class MainWindow(SplitApplicationWindow):
    """ The main application window. """

    #### 'SplitApplicationWindow' interface ###################################

    # The ratio of the size of the left/top pane to the right/bottom pane.
    ratio = Float(0.3)

    # The direction in which the window is split.
    direction = Str('vertical')

    ###########################################################################
    # Protected 'SplitApplicationWindow' interface.
    ###########################################################################

    def _create_lhs(self, parent):
        """ Creates the left hand side or top depending on the split. """

        self._tree = FileTree(
            parent,
            root=os.path.abspath(os.curdir),
        )

        self._tree.on_trait_change(self._on_tree_anytrait_changed)

        return self._tree.control

    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the split. """

        self._python_shell = PythonShell(parent)
        self._python_shell.bind('widget', self._tree)
        self._python_shell.bind('w', self._tree)

        return self._python_shell.control

    ###########################################################################
    # Private interface.
    ###########################################################################

    #### Trait event handlers #################################################

    def _on_tree_anytrait_changed(self, tree, trait_name, old, new):
        """ Called when any trait on the tree has changed. """

        print('trait', trait_name, 'value', new)

        return
예제 #4
0
파일: tree.py 프로젝트: enthought/pyface
class MainWindow(SplitApplicationWindow):
    """ The main application window. """

    # 'SplitApplicationWindow' interface -----------------------------------

    # The ratio of the size of the left/top pane to the right/bottom pane.
    ratio = Float(0.3)

    # The direction in which the window is split.
    direction = Str("vertical")

    # ------------------------------------------------------------------------
    # Protected 'SplitApplicationWindow' interface.
    # ------------------------------------------------------------------------

    def _create_lhs(self, parent):
        """ Creates the left hand side or top depending on the split. """

        self._tree = FileTree(parent, root=os.path.abspath(os.curdir))

        self._tree.observe(
            self._on_tree_anytrait_changed,
            match(lambda name, ctrait: True)  # listen to all traits
        )

        return self._tree.control

    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the split. """

        self._python_shell = PythonShell(parent)
        self._python_shell.bind("widget", self._tree)
        self._python_shell.bind("w", self._tree)

        return self._python_shell.control

    # ------------------------------------------------------------------------
    # Private interface.
    # ------------------------------------------------------------------------

    # Trait event handlers -------------------------------------------------

    def _on_tree_anytrait_changed(self, event):
        """ Called when any trait on the tree has changed. """

        print("trait", event.name, "value", event.new)

        return
예제 #5
0
def depth_first_traversal(parent_element, elements):
    """
    Depth first traversal helper to generate the parent-child
    relationships by elements on the document.
    """

    file_tree = FileTree(parent_element.get("paragraph").get("elements")[0] \
                                .get("textRun").get("content").strip())

    # Base elements: elements that are not indented.
    if "bullet" not in parent_element.get("paragraph"):
        parent_nesting_level = -1
    elif "nestingLevel" not in parent_element.get("paragraph")["bullet"]:
        parent_nesting_level = 0
    else:
        parent_nesting_level = parent_element.get(
            "paragraph")["bullet"]["nestingLevel"]

    for index, element in enumerate(elements):
        try:
            cur_nesting_level = element.get(
                "paragraph")["bullet"]["nestingLevel"]
        except:
            cur_nesting_level = 0

        # Append direct descendents to the children list of the current node
        # while recursing on the direct descendent.
        if cur_nesting_level == parent_nesting_level + 1:
            file_tree.children.append(
                depth_first_traversal(element, elements[index + 1::]))
        # All child elements have been found, exit loop.
        elif cur_nesting_level <= parent_nesting_level:
            break

    return file_tree
예제 #6
0
    def _widgets(self):
        splitter = QSplitter()

        # -- Left
        left_splitter = QSplitter(Qt.Vertical)
        splitter.addWidget(left_splitter)

        # Top left
        filetree = FileTree(self._root_path,
                            self._on_filetree_selection_changed)
        left_splitter.addWidget(filetree)

        # Bottom left
        tagging = Tagging()
        left_splitter.addWidget(tagging)

        # -- Right
        image = ImageDisplay()
        # Wrap it in a resizable scroll area
        area = QScrollArea()
        area.setWidget(image)
        area.setWidgetResizable(True)
        area.setAlignment(Qt.AlignCenter)
        splitter.addWidget(area)

        # A slight hack to split width equally
        splitter.setSizes([100000, 100000])

        return splitter, filetree, tagging, image
예제 #7
0
파일: tree.py 프로젝트: bergtholdt/pyface
class MainWindow(SplitApplicationWindow):
    """ The main application window. """

    #### 'SplitApplicationWindow' interface ###################################

    # The ratio of the size of the left/top pane to the right/bottom pane.
    ratio = Float(0.3)

    # The direction in which the window is split.
    direction = Str('vertical')

    ###########################################################################
    # Protected 'SplitApplicationWindow' interface.
    ###########################################################################

    def _create_lhs(self, parent):
        """ Creates the left hand side or top depending on the split. """

        self._tree = FileTree(
            parent, root=os.path.abspath(os.curdir),
        )

        self._tree.on_trait_change(self._on_tree_anytrait_changed)

        return self._tree.control

    def _create_rhs(self, parent):
        """ Creates the right hand side or bottom depending on the split. """

        self._python_shell = PythonShell(parent)
        self._python_shell.bind('widget', self._tree)
        self._python_shell.bind('w', self._tree)

        return self._python_shell.control

    ###########################################################################
    # Private interface.
    ###########################################################################

    #### Trait event handlers #################################################

    def _on_tree_anytrait_changed(self, tree, trait_name, old, new):
        """ Called when any trait on the tree has changed. """

        print('trait', trait_name, 'value', new)

        return
예제 #8
0
파일: tree.py 프로젝트: bergtholdt/pyface
    def _create_lhs(self, parent):
        """ Creates the left hand side or top depending on the split. """

        self._tree = FileTree(
            parent, root=os.path.abspath(os.curdir),
        )

        self._tree.on_trait_change(self._on_tree_anytrait_changed)

        return self._tree.control
예제 #9
0
def parse_document(elements):
    """
    Parses a document with content heirarchy defined by bullet indentation
    into a tree data structure.
    """

    file_tree = FileTree("Base")

    for index, element in enumerate(elements[1::]):
        # Base level only contains elements that are not indented.
        if "bullet" not in element.get("paragraph"):
            file_tree.children.append(
                depth_first_traversal(element, elements[1 + index + 1::]))

    return file_tree
예제 #10
0
    def _create_content(self, parent):
        """ Create some context for an expandable panel. """

        tree = FileTree(parent, root=os.path.abspath(os.curdir))

        return tree.control
예제 #11
0
 def __tree_default(self):
     return FileTree(root_path=self.root_path, filters=self.filters)
def flatten_file_system2(path):
    file_tree = FileTree(path)
    return file_tree.dfs_list()
def flatten_file_system1(path):
    file_tree = FileTree(path)
    tree_levels = file_tree.tree_levels()
    return flatten(tree_levels)
예제 #14
0
    def showFileTree(self):

        if len(self.Editors):
            curr_editor = self._get_current_editor()
            directory = os.path.dirname(self.Filenames[curr_editor])
            FileTree(curr_editor, directory)