class Win(QMainWindow): def __init__(self, options): super(Win, self).__init__() self.db = dbtag.Db() self.db.open(options.db) self.db.create_tables() self.rootPath = options.filespath self._init_widgets() self._init_more() def _init_widgets(self): bigsplitter = QSplitter(Qt.Horizontal, self) self.setCentralWidget(bigsplitter) leftsplitter = QSplitter(Qt.Vertical, self) self.tabWidget = QTabWidget(self) self.tagChooser = TagChooser(self.db) self.dirChooser = QTreeView(self) self.tabWidget.addTab(self.dirChooser, 'Dir') self.tabWidget.addTab(self.tagChooser, 'Tags') self.tagEditor = TagEditor(self.db) self.imageList = ImageList() leftsplitter.addWidget(self.tabWidget) leftsplitter.addWidget(self.tagEditor) bigsplitter.addWidget(leftsplitter) bigsplitter.addWidget(self.imageList) self.viewer = ImageViewer(self.db) def _init_more(self): self.setWindowTitle('Tags4') self.dirModel = QFileSystemModel() self.dirModel.setFilter(QDir.AllDirs | QDir.Drives | QDir.Hidden | QDir.NoDotAndDotDot) qidx = self.dirModel.setRootPath(self.rootPath) self.dirChooser.setModel(self.dirModel) self.dirChooser.setRootIndex(qidx) self.dirChooser.clicked.connect(self.browseSelectedDir) self.imageList.itemSelectionChanged.connect(self._editTagsItems) self.imageList.itemDoubleClicked.connect(self._spawnViewerItem) self.imageList.setSelectionMode(QAbstractItemView.ExtendedSelection) self.tabWidget.currentChanged.connect(self._tabSelected) self.tagChooser.changed.connect(self.browseSelectedTags) def editTags(self, path): self.tagEditor.setFile(path) def editTagsItems(self, paths): self.tagEditor.setFiles(paths) def spawnViewer(self, files, currentFile): self.viewer.spawn(files, currentFile) @Slot() def _editTagsItems(self): self.editTagsItems([qitem.getPath() for qitem in self.imageList.selectedItems()]) @Slot(QListWidgetItem) def _spawnViewerItem(self, qitem): self.spawnViewer(self.imageList.getFiles(), qitem.getPath()) @Slot() def browseSelectedDir(self): path = self.dirModel.filePath(self.dirChooser.currentIndex()) if not path: return files = [os.path.join(path, f) for f in os.listdir(path)] files = filter(os.path.isfile, files) files.sort() self.imageList.setFiles(files) @Slot() def browseSelectedTags(self): self.imageList.setFiles(self.tagChooser.matchingFiles()) @Slot(int) def _tabSelected(self, idx): if idx == 0: self.browseSelectedDir() else: self.browseSelectedTags() def browsePath(self, path): self.imageList.setFiles(os.path.join(path, f) for f in os.listdir(path))
class ImageViewer(QMainWindow): def __init__(self, db): super(ImageViewer, self).__init__() self.db = db self.currentIndex = -1 self.files = [] self._init_widgets() def _init_widgets(self): #self.toolbar = AutoHideToolBar() self.toolbar = QToolBar() self.addToolBar(self.toolbar) self.toolbar.hide() self.toolbar.addAction('Z 1:1').triggered.connect(self.doNormalZoom) self.toolbar.addAction('Z Fit').triggered.connect(self.doFitAllZoom) self.toolbar.addAction('Z FitExp').triggered.connect(self.doFitCutZoom) self.toolbar.addAction('Z x1.5').triggered.connect(self.zoom) self.toolbar.addAction('Z /1.5').triggered.connect(self.unzoom) self.toolbar.addAction('Copy tags').triggered.connect(self.copyPreviousTags) self.fullscreenAction = self.toolbar.addAction('Fullscreen') self.fullscreenAction.setCheckable(True) self.fullscreenAction.toggled.connect(self.setFullscreen) act = self.toolbar.addAction('Prev') act.setShortcut(QKeySequence(Qt.Key_Backspace)) act.triggered.connect(self.showPreviousFile) act = self.toolbar.addAction('Next') act.setShortcut(QKeySequence(Qt.Key_Space)) act.triggered.connect(self.showNextFile) #~ act.setShortcutContext(Qt.WidgetWithChildrenShortcut) self.tageditor = TagEditor(self.db) self.docktagger = AutoHideDock() self.docktagger.setWidget(self.tageditor) self.addDockWidget(Qt.LeftDockWidgetArea, self.docktagger) self.docktagger.hide() self.scrollview = ImageViewerCenter() self.scrollview.installEventFilter(self) ### ! self.setCentralWidget(self.scrollview) self.scrollview.topZoneEntered.connect(self.toolbar.show) self.scrollview.topZoneLeft.connect(self.toolbar.hide) self.scrollview.leftZoneEntered.connect(self.docktagger.show) self.scrollview.leftZoneLeft.connect(self.docktagger.hide) #~ self.setWindowState(self.windowState() | Qt.WindowMaximized) ''' self.qtagwl = QListWidget() self.qtagwl.setParent(self) self.qtagwl.hide() #self.qtagwl.setFixedSize(self.qtagwl.minimumSizeHint()) self.qtagwl.setFrameShape(QFrame.NoFrame) self.qtagwl.setStyleSheet('QListWidget{background-color: rgba(255,255,255,200);}\n *{background-color:rgba(0,255,255,255);}') self.qtagwl.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) self.qthtimer = QTimer() self.connect(self.qthtimer, SIGNAL('timeout()'), self.qtaghide) ''' def eventFilter(self, sview, ev): if ev.type() == QEvent.KeyPress: if ev.key() == Qt.Key_Escape: self.fullscreenAction.setChecked(False) return True elif ev.key() in [Qt.Key_PageUp, Qt.Key_Backspace]: # qactions self.showPreviousFile() return True elif ev.key() in [Qt.Key_PageDown, Qt.Key_Space]: self.showNextFile() return True return super(ImageViewer, self).eventFilter(sview, ev) @Slot() def doNormalZoom(self): self.scrollview.setZoomFactor(1.) @Slot() def doFitAllZoom(self): self.scrollview.setZoomMode(ZOOM_FITALL) @Slot() def doFitCutZoom(self): self.scrollview.setZoomMode(ZOOM_FITCUT) @Slot() def zoom(self): self.scrollview.multiplyZoomFactor(1.5) @Slot() def unzoom(self): self.scrollview.multiplyZoomFactor(1/1.5) def spawn(self, files, currentFile): self.files = files self.currentIndex = files.index(currentFile) self.setFile(currentFile) if self.isHidden(): #~ self.setWindowState(self.windowState() | Qt.WindowMaximized) #~ self.show() self.fullscreenAction.setChecked(False) self.fullscreenAction.setChecked(True) #~ self.showMaximized() else: self.show() def setFile(self, file): self.tageditor.setFile(file) self.scrollview.setFile(file) @Slot() def copyPreviousTags(self): tags = self.db.find_tags_by_file(self.files[self.currentIndex - 1]) self.db.tag_file(self.files[self.currentIndex], tags) self.tageditor.setFile(self.files[self.currentIndex]) def setFullscreen(self, full): if full: self.showFullScreen() else: self.showNormal() @Slot() def showPreviousFile(self): if self.currentIndex > 0: self.currentIndex -= 1 self.setFile(self.files[self.currentIndex]) @Slot() def showNextFile(self): if self.currentIndex < len(self.files) - 1: self.currentIndex += 1 self.setFile(self.files[self.currentIndex])