Beispiel #1
0
    def __init__(self, parent, initial_path):
                 #filewidget_factory=MultiFileWidget):
        QWidget.__init__(self, parent)

        self.directory = Directory(path(initial_path))
        print ">>>", initial_path

        self.path_combo = QComboBox(self)

        self.path_combo.setEditable(True)
        self.path_combo.lineEdit() \
                       .returnPressed \
                       .connect(self.pathcombo_return_pressed)

        self.filter_combo = QComboBox(self)
        self.filter_combo.setEditable(True)
        self.filter_combo.lineEdit() \
                         .returnPressed \
                         .connect(self.filtercombo_return_pressed)

        self.free_space_label = QLabel(self)
        self.free_space_label.setProperty('is_status', True)

        self.filewidget = MultiFileWidget(self, self.directory)
        self.filewidget.currentChanged.connect(self.view_widget_changed)

        for widget in self.filewidget.widgets:
            self.connect_filewidget_events(widget)

        self.filewidget.newWidget.connect(self.connect_filewidget_events)

        self.selection_status_label = DropLabel(self, self.mime_data_dropped)
        self.selection_status_label.setProperty('is_status', True)

        self.jump_button = QToolButton(self)
        self.jump_button.setIcon(icon('jump.png'))
        self.jump_button.clicked.connect(
            self.jump_menu_requested
        )

        layout = QVBoxLayout()
        layout.setSpacing(5)

        path_combo_layout = QHBoxLayout()
        path_combo_layout.setContentsMargins(0, 0, 0, 0)

        path_combo_layout.addWidget(self.path_combo)
        path_combo_layout.addWidget(self.jump_button)

        layout.addLayout(path_combo_layout)

        for widget in [self.filter_combo,
                       self.free_space_label,
                       self.filewidget,
                       self.selection_status_label]:

            layout.addWidget(widget)

        self.setLayout(layout)

        self.filewidget_dir_changed(initial_path)

        self.action_hide_jump = create_action(self,
            text="Show jump button",
            checkable=True,
            checked=False,
            triggered=self.jump_button.setVisible
        )

        self.action_hide_path = create_action(self,
            text="Show current path",
            checkable=True,
            checked=True,
            triggered=self.path_combo.setVisible
        )
        self.action_hide_path.triggered.connect(
            self.action_hide_jump.triggered.emit
        )

        self.action_hide_filter = create_action(self,
            text="Show filter",
            checkable=True,
            checked=True,
            triggered=self.filter_combo.setVisible
        )

        self.action_hide_selection_status = create_action(self,
            text="Show selection status",
            checkable=True,
            checked=True,
            triggered=self.selection_status_label.setVisible
        )

        self._last_filters = {}
Beispiel #2
0
class DirectoryPanel(QWidget):
    """
    This is the Panel which holds the Filewidget, Selectionstatus,
    the path-Combobox and so on
    """
    filterError = pyqtSignal(Exception)

    def __init__(self, parent, initial_path):
                 #filewidget_factory=MultiFileWidget):
        QWidget.__init__(self, parent)

        self.directory = Directory(path(initial_path))
        print ">>>", initial_path

        self.path_combo = QComboBox(self)

        self.path_combo.setEditable(True)
        self.path_combo.lineEdit() \
                       .returnPressed \
                       .connect(self.pathcombo_return_pressed)

        self.filter_combo = QComboBox(self)
        self.filter_combo.setEditable(True)
        self.filter_combo.lineEdit() \
                         .returnPressed \
                         .connect(self.filtercombo_return_pressed)

        self.free_space_label = QLabel(self)
        self.free_space_label.setProperty('is_status', True)

        self.filewidget = MultiFileWidget(self, self.directory)
        self.filewidget.currentChanged.connect(self.view_widget_changed)

        for widget in self.filewidget.widgets:
            self.connect_filewidget_events(widget)

        self.filewidget.newWidget.connect(self.connect_filewidget_events)

        self.selection_status_label = DropLabel(self, self.mime_data_dropped)
        self.selection_status_label.setProperty('is_status', True)

        self.jump_button = QToolButton(self)
        self.jump_button.setIcon(icon('jump.png'))
        self.jump_button.clicked.connect(
            self.jump_menu_requested
        )

        layout = QVBoxLayout()
        layout.setSpacing(5)

        path_combo_layout = QHBoxLayout()
        path_combo_layout.setContentsMargins(0, 0, 0, 0)

        path_combo_layout.addWidget(self.path_combo)
        path_combo_layout.addWidget(self.jump_button)

        layout.addLayout(path_combo_layout)

        for widget in [self.filter_combo,
                       self.free_space_label,
                       self.filewidget,
                       self.selection_status_label]:

            layout.addWidget(widget)

        self.setLayout(layout)

        self.filewidget_dir_changed(initial_path)

        self.action_hide_jump = create_action(self,
            text="Show jump button",
            checkable=True,
            checked=False,
            triggered=self.jump_button.setVisible
        )

        self.action_hide_path = create_action(self,
            text="Show current path",
            checkable=True,
            checked=True,
            triggered=self.path_combo.setVisible
        )
        self.action_hide_path.triggered.connect(
            self.action_hide_jump.triggered.emit
        )

        self.action_hide_filter = create_action(self,
            text="Show filter",
            checkable=True,
            checked=True,
            triggered=self.filter_combo.setVisible
        )

        self.action_hide_selection_status = create_action(self,
            text="Show selection status",
            checkable=True,
            checked=True,
            triggered=self.selection_status_label.setVisible
        )

        self._last_filters = {}

    def connect_filewidget_events(self, widget):
        widget.model().directoryChanged.connect(self.filewidget_dir_changed)
        widget.selectionModel().selectionChanged.connect(
            self.filewidget_selection_changed
        )

    def jump_menu_requested(self):
        pos = self.jump_button.mapToGlobal(
            self.jump_button.rect().bottomLeft()
        )
        JumpMenu(self, self.filewidget).popup(pos)

    def mime_data_dropped(self, event):
        model = self.filewidget.currentWidget().model()
        return model.dropMimeData(event.mimeData(), 0, -1, -1, QModelIndex())

    def view_widget_changed(self, index):
        """
        Gets called when the MultiFileWidgets viewmode changes
        """

        filewidget = self.filewidget
        indexwidget = filewidget.widget(index)
        filter_func = filewidget.filters.get(indexwidget)

        if filter_func:
            text = filter_func.text
        else:
            text = ''

        self.filter_combo.setEditText(text)
        self.filewidget_selection_changed()

    def pathcombo_return_pressed(self):
        text = unicode(self.path_combo.currentText())
        self.filewidget.set_path(text)

    def filtercombo_return_pressed(self):
        text = unicode(self.filter_combo.currentText())

        if not text:
            self.filewidget.set_filter(None)
            self.set_filter_background()
        else:
            self.filewidget.set_filter(self._make_filter_func(text))

        self.filewidget_dir_changed()

    def _make_filter_func(self, text):
        try:
            filterfunc = filters.make_parser(text)
        except filters.ParseError, e:
            self.set_filter_background(error=True)
            self.filterError.emit(e)
        else: