Beispiel #1
0
 def update_breadcrumb(self, path=None):
     """Update the breadcrumb naviagtion."""
     path = path or getcwd()
     parts = path.split(os.path.sep)
     text = '<style>a{color:#43b02a;}</style>'
     cum_path = ''
     for p in parts:
         cum_path += p + os.path.sep
         text += '<a href="{link}">{p}</a>'.format(p=p, link=cum_path)
         text += '&nbsp;' + os.path.sep + '&nbsp;'
     self.label_breadcrumb.setText(text)
Beispiel #2
0
 def refresh(self, new_path=None, force_current=False):
     """Refresh widget
     force=False: won't refresh widget if path has not changed"""
     if new_path is None:
         new_path = getcwd()
     if force_current:
         index = self.set_current_folder(new_path)
         self.expand(index)
         self.setCurrentIndex(index)
     self.set_previous_enabled.emit(self.histindex is not None
                                    and self.histindex > 0)
     self.set_next_enabled.emit(self.histindex is not None
                                and self.histindex < len(self.history) - 1)
Beispiel #3
0
    def __init__(
        self,
        parent=None,
        name_filters=['*.py', '*.pyw'],
        show_all=True,
        show_cd_only=None,
        show_icontext=False,
        home=None,
    ):
        """Explorer widget."""
        QWidget.__init__(self, parent)

        self.home = home

        # Widgets
        self.treewidget = ExplorerTreeWidget(self, show_cd_only=show_cd_only)
        self.button_home = QToolButton(self)
        self.button_home.setFocusPolicy(Qt.StrongFocus)
        self.label_breadcrumb = QLabel()

        home_action = create_action(
            self,
            text="Home",
            icon=QIcon(),  # ima.icon('ArrowBack'),
            triggered=self.go_home)

        # Setup widgets
        self.treewidget.setup(name_filters=name_filters, show_all=show_all)
        self.treewidget.chdir(getcwd())

        self.button_home.setDefaultAction(home_action)

        # Layouts
        blayout = QHBoxLayout()
        blayout.addWidget(self.button_home)
        blayout.addWidget(self.label_breadcrumb)
        blayout.addStretch()

        layout = QVBoxLayout()
        layout.addLayout(blayout)
        layout.addWidget(self.treewidget)
        self.setLayout(layout)

        # Signals and slots
        self.treewidget.sig_add_to_project.connect(self.sig_add_to_project)
        self.treewidget.sig_changed_dir.connect(self.update_breadcrumb)
        self.label_breadcrumb.linkActivated.connect(self.go_to)

        self.update_breadcrumb()
Beispiel #4
0
 def go_to_parent_directory(self):
     """Go to parent directory"""
     self.chdir(osp.abspath(osp.join(getcwd(), os.pardir)))
Beispiel #5
0
    def __init__(self,
                 parent=None,
                 name_filters=['*.py', '*.pyw'],
                 show_all=False,
                 show_cd_only=None,
                 show_icontext=True):
        QWidget.__init__(self, parent)

        # Widgets
        self.treewidget = ExplorerTreeWidget(self, show_cd_only=show_cd_only)
        button_home = QToolButton(self)
        button_previous = QToolButton(self)
        button_next = QToolButton(self)
        button_parent = QToolButton(self)
        self.button_menu = QToolButton(self)
        menu = QMenu(self)

        self.action_widgets = [
            button_home, button_previous, button_next, button_parent,
            self.button_menu
        ]

        # Actions
        icontext_action = create_action(self,
                                        _("Show icons and text"),
                                        toggled=self.toggle_icontext)
        home_action = create_action(self,
                                    text=_("Home"),
                                    icon=qta.icon('fa.home'),
                                    triggered=self.treewidget.go_home)
        previous_action = create_action(
            self,
            text=_("Previous"),
            icon=qta.icon('fa.arrow-left'),
            triggered=self.treewidget.go_to_previous_directory)
        next_action = create_action(
            self,
            text=_("Next"),
            icon=qta.icon('fa.arrow-right'),
            triggered=self.treewidget.go_to_next_directory)
        parent_action = create_action(
            self,
            text=_("Parent"),
            icon=qta.icon('fa.arrow-up'),
            triggered=self.treewidget.go_to_parent_directory)
        options_action = create_action(self, text='', tip=_('Options'))

        # Setup widgets
        self.treewidget.setup(name_filters=name_filters, show_all=show_all)
        self.treewidget.chdir(getcwd())
        self.treewidget.common_actions += [None, icontext_action]

        button_home.setDefaultAction(home_action)

        button_previous.setDefaultAction(previous_action)
        previous_action.setEnabled(False)

        button_next.setDefaultAction(next_action)
        next_action.setEnabled(False)

        button_parent.setDefaultAction(parent_action)

        self.button_menu.setIcon(ima.icon('tooloptions'))
        self.button_menu.setPopupMode(QToolButton.InstantPopup)
        self.button_menu.setMenu(menu)
        add_actions(menu, self.treewidget.common_actions)
        options_action.setMenu(menu)

        self.toggle_icontext(show_icontext)
        icontext_action.setChecked(show_icontext)

        for widget in self.action_widgets:
            widget.setAutoRaise(True)
            widget.setIconSize(QSize(16, 16))

        # Layouts
        blayout = QHBoxLayout()
        blayout.addWidget(button_home)
        blayout.addWidget(button_previous)
        blayout.addWidget(button_next)
        blayout.addWidget(button_parent)
        blayout.addStretch()
        blayout.addWidget(self.button_menu)

        layout = QVBoxLayout()
        layout.addLayout(blayout)
        layout.addWidget(self.treewidget)
        self.setLayout(layout)

        # Signals and slots
        self.treewidget.set_previous_enabled.connect(
            previous_action.setEnabled)
        self.treewidget.set_next_enabled.connect(next_action.setEnabled)
        button_home.clicked.connect(self.sig_home_clicked)