Esempio n. 1
0
    def match(self, context):
        query = context.query()
        if query == "." or query == "..":
            return

        if not query.startswith(self._triggerWord):
            return

        query = query[len(self._triggerWord):].lower()

        if len(query) > 2:
            query = "*{}*".format(query)

        for file in filter(lambda f: fnmatch.fnmatch(f.name.lower(), query),
                           self._path.iterdir()):
            if not context.isValid():
                return
            elif file.name.startswith("."):
                continue

            match = krunner.QueryMatch(self)
            match.setText("Open {}".format(file))
            match.setData(str(file))
            match.setId(str(file))

            db = QtCore.QMimeDatabase()
            match.setIconName(db.mimeTypeForFile(str(file)).iconName())

            if str(self._path).lower() == query:
                match.setRelevance(1.0)
                match.setType(krunner.QueryMatch.ExactMatch)
            else:
                match.setRelevance(0.8)
            context.addMatch(match)
Esempio n. 2
0
    def __init__(self, parent, app, config, image_toolkit):
        super().__init__()
        self.app = app
        self.parent = parent
        self.config = config
        self.image_toolkit = image_toolkit

        __current_screen = QtWidgets.QApplication.desktop().cursor().pos()
        __screen = QtWidgets.QDesktopWidget().screenNumber(__current_screen)
        __screen_geo = QtWidgets.QApplication.desktop().screenGeometry(
            __screen)

        self.screen = __screen
        self.height, self.width, self.left, self.top = (__screen_geo.height(),
                                                        __screen_geo.width(),
                                                        __screen_geo.left(),
                                                        __screen_geo.top())
        self.setGeometry((self.left + (self.width / 2 - 300)),
                         (self.top + (self.height / 2 - 175)), 600, 350)

        self.setFixedSize(600, 350)
        self.setWindowTitle("Chizuhoru")

        self.file_filter = 'png'
        self.typed_dir_hint_list = []

        _dirpath = os.path.dirname(os.path.realpath(__file__))
        self.hist_dir = os.path.join(_dirpath, '../.history')
        self.hist = os.path.join(self.hist_dir, 'index.json')
        self.mime_db = QtCore.QMimeDatabase()
        self.thread = None

        self.init_layout()
Esempio n. 3
0
    def __init__(self, paths: List[str]) -> None:
        super(MainWindow, self).__init__()
        self.setWindowTitle('Photo Organizer')
        self.resize(config.config['width'], config.config['height'])
        if config.config['maximized']:
            self.setWindowState(C.Qt.WindowMaximized)
        self.picture_size = config.config['picture_size']

        self.loaded_files: Set[str] = set()

        self.mime_db = C.QMimeDatabase()
        self.current_index = 0

        self.from_model = G.QStandardItemModel()
        self.from_list = W.QListView()
        self.from_list.setViewMode(W.QListView.IconMode)
        self.from_list.setMovement(W.QListView.Static)
        self.from_list.setResizeMode(W.QListView.Adjust)
        self.from_list.setSelectionMode(W.QAbstractItemView.ExtendedSelection)
        self.from_list.setModel(self.from_model)
        sm = self.from_list.selectionModel()
        sm.selectionChanged.connect(  # type: ignore
            lambda s, d: self.check_from_selection())

        self.to_model = G.QStandardItemModel()
        self.to_list = W.QListView()
        self.to_list.setViewMode(W.QListView.IconMode)
        self.to_list.setMovement(W.QListView.Static)
        self.to_list.setResizeMode(W.QListView.Adjust)
        self.to_list.setSelectionMode(W.QAbstractItemView.ExtendedSelection)
        self.to_list.setModel(self.to_model)
        self.to_list.selectionModel().selectionChanged.connect(  # type: ignore
            lambda s, d: self.check_to_selection())

        move_layout = W.QVBoxLayout()

        self.add_button = W.QToolButton()
        self.add_button.setText('Add')
        self.add_button.setIcon(config.get_icon('arrow-right-bold'))
        self.add_button.clicked.connect(lambda _: self.add_items())
        self.add_button.setEnabled(False)
        self.add_button.setShortcut(C.Qt.ALT + C.Qt.Key_Right)
        helper.set_tooltip(self.add_button)
        self.remove_button = W.QToolButton()
        self.remove_button.setText('Remove')
        self.remove_button.setIcon(config.get_icon('arrow-left-bold'))
        self.remove_button.clicked.connect(lambda _: self.remove_items())
        self.remove_button.setEnabled(False)
        self.remove_button.setShortcut(C.Qt.ALT + C.Qt.Key_Left)
        helper.set_tooltip(self.remove_button)
        move_layout.addWidget(self.add_button)
        move_layout.addWidget(self.remove_button)

        arrange_layout = W.QVBoxLayout()
        self.up_button = W.QToolButton()
        self.up_button.setText('Up')
        self.up_button.setIcon(config.get_icon('arrow-up-bold'))
        self.up_button.clicked.connect(lambda _: self.move_up())
        self.up_button.setEnabled(False)
        self.up_button.setEnabled(False)
        self.up_button.setShortcut(C.Qt.ALT + C.Qt.Key_Up)
        self.down_button = W.QToolButton()
        self.down_button.setText('Down')
        self.down_button.setIcon(config.get_icon('arrow-down-bold'))
        self.down_button.clicked.connect(lambda _: self.move_down())
        self.down_button.setEnabled(False)
        self.down_button.setShortcut(C.Qt.ALT + C.Qt.Key_Down)
        helper.set_tooltip(self.down_button)
        arrange_layout.addWidget(self.up_button)
        arrange_layout.addWidget(self.down_button)

        splitter = W.QSplitter()

        from_layout = W.QHBoxLayout()
        from_layout.addWidget(self.from_list)
        from_layout.addLayout(move_layout)
        from_widget = W.QWidget()
        from_widget.setLayout(from_layout)
        splitter.addWidget(from_widget)

        to_layout = W.QHBoxLayout()
        to_layout.addWidget(self.to_list)
        to_layout.addLayout(arrange_layout)
        to_widget = W.QWidget()
        to_widget.setLayout(to_layout)
        splitter.addWidget(to_widget)

        self.setCentralWidget(splitter)

        toolbar = W.QToolBar()
        clear_action = toolbar.addAction(config.get_icon('file-outline'),
                                         'Clear', self.clear)
        clear_action.setShortcut(C.Qt.ALT + C.Qt.Key_C)
        helper.set_tooltip(clear_action)
        add_action = toolbar.addAction(config.get_icon('folder'), 'Add folder',
                                       lambda: self.add_dir(recursive=False))
        add_action.setShortcut(C.Qt.ALT + C.Qt.Key_F)
        helper.set_tooltip(add_action)
        toolbar.addAction(config.get_icon('file-tree'), 'Add tree',
                          lambda: self.add_dir(recursive=True))
        toolbar.addSeparator()
        zoom_in_action = toolbar.addAction(
            config.get_icon('magnify-plus'), 'Zoom in', lambda: self.
            resize_pictures(self.picture_size + picture_size_step))
        zoom_in_action.setShortcut(C.Qt.CTRL + C.Qt.Key_Plus)
        helper.set_tooltip(zoom_in_action)
        zoom_out_action = toolbar.addAction(
            config.get_icon('magnify-minus'), 'Zoom out', lambda: self.
            resize_pictures(self.picture_size - picture_size_step))
        zoom_out_action.setShortcut(C.Qt.CTRL + C.Qt.Key_Minus)
        helper.set_tooltip(zoom_out_action)
        toolbar.addSeparator()
        self.apply_action = toolbar.addAction(config.get_icon('floppy'),
                                              'Apply', self.apply)
        self.apply_action.setEnabled(False)
        self.addToolBar(toolbar)
        self.apply_action.setShortcut(C.Qt.ALT + C.Qt.Key_A)
        helper.set_tooltip(self.apply_action)

        self.load_pictures_task = task.Task(self.load_pictures)
        C.QCoreApplication.postEvent(self, InitEvent(paths))