コード例 #1
0
class MainWindow(QMainWindow):
    def __init__(self, parent=None, show=True):
        QMainWindow.__init__(self, parent)

        self.frame = QFrame()
        vlayout = QVBoxLayout()
        self.vtk_widget = QtInteractor(self.frame)
        vlayout.addWidget(self.vtk_widget)

        self.frame.setLayout(vlayout)
        self.setCentralWidget(self.frame)

        mainMenu = self.menuBar()
        fileMenu = mainMenu.addMenu('File')

        exitButton = QAction('Exit', self)
        exitButton.setShortcut('Ctrl+Q')
        exitButton.triggered.connect(self.close)

        fileMenu.addAction(exitButton)

        meshMenu = mainMenu.addMenu('Mesh')
        self.add_sphere_action = QAction('Add Sphere', self)

        self.add_sphere_action.triggered.connect(self.add_sphere)
        meshMenu.addAction(self.add_sphere_action)

        if show:
            self.show()

    def add_sphere(self):
        sphere = pyvista.Sphere()
        self.vtk_widget.add_mesh(sphere)
        self.vtk_widget.reset_camera()
コード例 #2
0
ファイル: align.py プロジェクト: ligm74/LiGM
    def __init__(self, color_caption):
        TestableWidget.__init__(self)
        self.setWindowFlags(Qt.Popup)
        self._text = self.tr("Alignment text")

        main_layout = QVBoxLayout()
        main_layout.setContentsMargins(0, 0, 0, 0)

        b = "border: 1px solid #9b9b9b;"
        self._styles = {
            "border": b,
            "border_blue": "border: 0px solid blue;",
            "frame": 'QFrame[frameShape="4"]{color: #9b9b9b;}'
        }

        self.setStyleSheet(self._styles["frame"])

        # -- CAPTION ----------------------------------
        caption = QFrame(self, flags=Qt.WindowFlags())
        caption_layout = QHBoxLayout()
        self._lbl_caption = QLabel(self._text)
        self._lbl_caption.setStyleSheet(self._styles["border_blue"])
        caption_layout.addWidget(self._lbl_caption, alignment=Qt.Alignment())
        caption.setLayout(caption_layout)
        caption_layout.setContentsMargins(9, 5, 9, 5)
        caption.setStyleSheet(
            f"background-color: {color_caption}; {self._styles['border']}")

        # -- CELLS GRID -------------------------------
        cellsbox = QFrame(self, flags=Qt.WindowFlags())
        cells = QGridLayout()
        cellsbox.setLayout(cells)
        cells.setContentsMargins(9, 0, 9, 9)
        self._clrbtn = []
        for i in range(1, 4):
            for j in range(1, 5):
                self._clrbtn.append(QToolButton())
                self._clrbtn[-1].clicked.connect(
                    lambda z, y=i, x=j: self.select_align_(x, y))
                self._clrbtn[-1].setAutoRaise(True)

                sz = 48
                self._clrbtn[-1].setFixedSize(sz, sz)
                self._clrbtn[-1].setIconSize(QSize(sz, sz))

                self._clrbtn[-1].setIcon(QIcon(img(f"editor/a{i}{j}.png")))
                # noinspection PyArgumentList
                cells.addWidget(self._clrbtn[-1], i - 1, j - 1)

        # ---------------------------------------------
        main_layout.addWidget(caption, alignment=Qt.Alignment())
        main_layout.addWidget(cellsbox, alignment=Qt.Alignment())

        self.setLayout(main_layout)
コード例 #3
0
    def initSrcFiles(self):

        row = 0

        f = QFrame()
        l = QGridLayout()
        f.setLayout(l)

        l.addWidget(QLabel('Source Files :'), row, 0)
        self.srcFilesList = QListWidget()
        self.srcFilesList.setSelectionMode(QAbstractItemView.MultiSelection)
        self.srcFilesList.setAlternatingRowColors(True)
        self.srcFilesList.model().rowsInserted.connect(
            self.handleSrcFilesChanged)
        self.srcFilesList.model().rowsRemoved.connect(
            self.handleSrcFilesChanged)
        selectionModel = self.srcFilesList.selectionModel()
        selectionModel.selectionChanged.connect(
            self.handleSrcFilesSelectionChanged)
        l.addWidget(self.srcFilesList, row, 1, 3, 1)

        self.srcFilesBtn = QPushButton('Select Files')
        self.srcFilesBtn.clicked.connect(self.handleSelectSrcFiles)
        self.srcFilesBtn.setSizePolicy(QSizePolicy.Preferred,
                                       QSizePolicy.Expanding)
        l.addWidget(self.srcFilesBtn, row, 2)
        row += 1

        self.addFilesBtn = QPushButton('Add Files')
        self.addFilesBtn.clicked.connect(self.handleAddSrcFiles)
        self.addFilesBtn.setSizePolicy(QSizePolicy.Preferred,
                                       QSizePolicy.Expanding)
        l.addWidget(self.addFilesBtn, row, 2)
        row += 1

        self.removeFilesBtn = QPushButton('Remove Files')
        self.removeFilesBtn.setEnabled(False)
        self.removeFilesBtn.clicked.connect(self.handleRemoveSrcFiles)
        self.removeFilesBtn.setSizePolicy(QSizePolicy.Preferred,
                                          QSizePolicy.Expanding)
        l.addWidget(self.removeFilesBtn, row, 2)
        row += 1

        self.errorEdit = QPlainTextEdit()
        self.errorEdit.setReadOnly(True)
        l.addWidget(self.errorEdit, row, 1, 1, 2)
        self.comms.errorSignal.connect(self.errorEdit.appendPlainText)

        return f
コード例 #4
0
    def initFileFrame(self):
        row = 0

        f = QFrame()
        l = QGridLayout()
        f.setLayout(l)
        #         f.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)

        l.addWidget(QLabel('Destination File :'), row, 0)
        self.destFilenameEdit = QLineEdit(self.destFilename)
        self.destFilenameEdit.setEnabled(False)
        self.destFilenameEdit.textChanged.connect(
            self.handleDestFilenameChanged)
        l.addWidget(self.destFilenameEdit, row, 1)
        row += 1

        self.combineRoutesBox = QCheckBox('combine_routes')
        if self.config[FORMS]['combine_routes']:
            self.combineRoutesBox.setChecked(True)
        else:
            self.combineRoutesBox.setChecked(False)
        self.combineRoutesBox.clicked.connect(self.handleCombineRoutesClicked)
        self.combineRoutesBox.setEnabled(False)
        l.addWidget(self.combineRoutesBox, row, 0)
        row += 1

        addDateInNameBox = QCheckBox('Add date to filename')
        addDateInNameBox.clicked.connect(self.handleAddDateClicked)
        l.addWidget(addDateInNameBox, row, 0)
        if self.config[FORMS]['prefix_date']:
            self.prefixDateInNameBox = QPushButton('prefix_date')
            self.prefixDateInNameBox.setEnabled(False)
        else:
            self.prefixDateInNameBox = QPushButton('Suffix date')
            self.prefixDateInNameBox.setEnabled(False)
        self.prefixDateInNameBox.setToolTip('Click to change to prefix date.')
        self.prefixDateInNameBox.clicked.connect(self.handlePrefixDateClicked)

        l.addWidget(self.prefixDateInNameBox, row, 1)
        row += 1

        addRouteInNameBox = QCheckBox('Add route to filename')
        addRouteInNameBox.clicked.connect(self.handleAddRouteClicked)
        l.addWidget(addRouteInNameBox, row, 0)
        #         row += 1

        return f
コード例 #5
0
    def initResultPage(self):
        f = QFrame()
        l = QHBoxLayout()
        f.setLayout(l)

        self.convertedTabs = QTabWidget()
        l.addWidget(self.convertedTabs)
        '''
        This just adds a blank page with an empty tab widget.
        Pages are added on the fly when the files are converted as
        this could involve one or many pages depending on combine_route
        flag and number of routes.

        self.convertedTabs is the empty tab widget
        '''

        return f
コード例 #6
0
    def initConfigPage(self):
        row = 0

        f = QFrame()
        l = QGridLayout()
        f.setLayout(l)

        srcLbl = QLabel('Source directory :')
        srcLbl.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        l.addWidget(srcLbl, row, 0)

        self.srcDirBox = QLineEdit()
        self.srcDirBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        self.srcDirBox.setText(self.config[PATHS]['download_path'])
        l.addWidget(self.srcDirBox, row, 1)

        srcDirSelectBtn = QPushButton('Select')
        srcDirSelectBtn.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        srcDirSelectBtn.clicked.connect(self.handleSelectSrcDirectory)
        l.addWidget(srcDirSelectBtn, row, 2)

        row += 1

        destLbl = QLabel('Destination directory :')
        destLbl.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        l.addWidget(destLbl, row, 0)

        self.destDirBox = QLineEdit()
        self.destDirBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        self.destDirBox.setText(self.config[PATHS]['save_path'])
        l.addWidget(self.destDirBox, row, 1)

        destDirSelectBtn = QPushButton('Select')
        destDirSelectBtn.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        destDirSelectBtn.clicked.connect(self.handleSelectDestDirectory)
        l.addWidget(destDirSelectBtn, row, 2)

        row += 1

        l.addWidget(QFrame(), row, 0, 1, 3)

        return f
コード例 #7
0
    def initGui(self):
        self.setGeometry(300, 300, 800, 600)
        self.setWindowTitle('Road warrior Upload File Converter')
        self.center()

        fMain = QFrame()
        mainLayout = QGridLayout()
        fMain.setLayout(mainLayout)
        self.setCentralWidget(fMain)

        tabWidget = QTabWidget()
        mainLayout.addWidget(tabWidget, 0, 0)

        self.closeBtn = QPushButton('Close Application')
        self.closeBtn.clicked.connect(self.handleCloseClicked)
        mainLayout.addWidget(self.closeBtn, 1, 0)

        tabWidget.addTab(self.initConvertPage(), 'Converter')
        tabWidget.addTab(self.initResultPage(), 'Converter')
        tabWidget.addTab(self.initConfigPage(), 'Configuration')
コード例 #8
0
class TstWindow(MainWindow):
    def __init__(self, parent=None, show=True, off_screen=True):
        MainWindow.__init__(self, parent)

        self.frame = QFrame()
        vlayout = QVBoxLayout()
        self.vtk_widget = QtInteractor(
            parent=self.frame,
            off_screen=off_screen,
            stereo=False,
        )
        vlayout.addWidget(self.vtk_widget.interactor)

        self.frame.setLayout(vlayout)
        self.setCentralWidget(self.frame)

        mainMenu = _create_menu_bar(parent=self)

        fileMenu = mainMenu.addMenu('File')
        self.exit_action = QAction('Exit', self)
        self.exit_action.setShortcut('Ctrl+Q')
        self.exit_action.triggered.connect(self.close)
        fileMenu.addAction(self.exit_action)

        meshMenu = mainMenu.addMenu('Mesh')
        self.add_sphere_action = QAction('Add Sphere', self)
        self.exit_action.setShortcut('Ctrl+A')
        self.add_sphere_action.triggered.connect(self.add_sphere)
        meshMenu.addAction(self.add_sphere_action)

        self.signal_close.connect(self.vtk_widget.close)

        if show:
            self.show()

    def add_sphere(self):
        sphere = pyvista.Sphere(phi_resolution=6, theta_resolution=6)
        self.vtk_widget.add_mesh(sphere)
        self.vtk_widget.reset_camera()
コード例 #9
0
    def initConvertPage(self):
        f = QFrame()
        l = QGridLayout()
        f.setLayout(l)

        row = 0

        l.addWidget(QLabel('Converter :'), row, 0)
        currentPluginBox = QComboBox()
        currentPluginBox.currentTextChanged.connect(self.selectPlugin)
        l.addWidget(currentPluginBox, row, 1)
        for key in self.plugins.keys():
            currentPluginBox.addItem(key)
        row += 1

        l.addWidget(QLabel('Destination path :'), row, 0)
        self.destPathLbl = QLabel(
            self.joinSavePath(self.config[PATHS]['save_path'],
                              self.config[FILES]['save_file'],
                              self.config[FILES]['save_ext']))
        self.destPathLbl.setSizePolicy(QSizePolicy.Expanding,
                                       QSizePolicy.Fixed)
        l.addWidget(self.destPathLbl, row, 1)

        row += 1

        f2 = QFrame()
        l2 = QHBoxLayout()
        f2.setLayout(l2)

        f3 = QFrame()
        l3 = QGridLayout()
        f3.setLayout(l3)

        l3.addWidget(QLabel('Destination Files :'), 0, 0)
        self.destFilesList = QListWidget()
        self.destFilesList.setAlternatingRowColors(True)
        l3.addWidget(self.destFilesList, 1, 0)

        l2.addWidget(self.initFileFrame())
        l2.addWidget(f3)
        l.addWidget(f2, row, 0, 1, 3)

        row += 1

        l.addWidget(self.initSrcFiles(), row, 0, 1, 3)

        row += 1

        self.convertBtn = QPushButton('Convert')
        self.convertBtn.clicked.connect(self.handleConvertClicked)
        self.convertBtn.setEnabled(False)
        l.addWidget(self.convertBtn, row, 0, 1, 3)

        return f
コード例 #10
0
ファイル: code_Enlargement.py プロジェクト: trinkner/lapwing
class Enlargement(QMdiSubWindow, form_Enlargement.Ui_frmEnlargement):

    # create "resized" as a signal that the window can emit
    # we respond to this signal with the form's resizeMe method below
    resized = pyqtSignal()

    class MyGraphicsView(QGraphicsView):
        def __init__(self):
            QGraphicsView.__init__(self)
            self.setRenderHints(QPainter.Antialiasing
                                | QPainter.SmoothPixmapTransform)
            self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
            self.setDragMode(QGraphicsView.ScrollHandDrag)
            self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
            self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
            self.mdiParent = ""

        def wheelEvent(self, event):
            adj = 1 + event.angleDelta().y() / 120 * 0.1
            self.scale(adj, adj)

        # we need a keepress event handler here in case the user clicks on the photo.
        # when user clicks on the photo, the keypress handler is this GraphicsView, not the Englargement class.
        def keyPressEvent(self, e):

            # F key is pressed. Re-display the currentEnlargement to fit the screen
            if e.key() == Qt.Key_F:
                self.mdiParent.fitEnlargement()

            # Backspace key is pressed, so show previous image as enlargement
            if e.key() == Qt.Key_Backspace:
                self.mdiParent.showPreviousPhoto()

            # Space bar is pressed, so show next image as enlargement
            if e.key() == Qt.Key_Space:
                self.mdiParent.showNextPhoto()

            # F7 is pressed, so toggle display of cursor
            if e.key() == Qt.Key_F7:
                self.mdiParent.toggleHideCursor()

            # F9 is pressed, so toggle display of camera details
            if e.key() == Qt.Key_F9:
                self.mdiParent.toggleCameraDetails()

            # F11 is pressed, so toggle display of camera details
            if e.key() == Qt.Key_F11:
                self.mdiParent.toggleFullScreen()

            # Esc is pressed, so exit full screen mode, if we're in it
            if e.key(
            ) == Qt.Key_Escape and self.mdiParent.mdiParent.mdiParent.statusBar.isVisible(
            ) is False:
                self.mdiParent.toggleFullScreen()

            # 1-5 pressed, so rate the photo
            if e.key() in [
                    Qt.Key_0, Qt.Key_1, Qt.Key_2, Qt.Key_3, Qt.Key_4, Qt.Key_5
            ]:
                self.mdiParent.ratePhoto(e.key())

            # Right is pressed: show next photo
            if e.key() == Qt.Key_Right or e.key() == Qt.Key_PageDown:
                self.mdiParent.showNextPhoto()

            # Left is pressed: show previous photo
            if e.key() == Qt.Key_Left or e.key() == Qt.Key_PageUp:
                self.mdiParent.showPreviousPhoto()

        def contextMenuEvent(self, event):

            QApplication.restoreOverrideCursor()

            menu = QMenu(self)
            menu.setStyleSheet("color:silver; background-color: #343333;")

            actionFitToWindow = menu.addAction("Fit to window (F)")
            menu.addSeparator()
            actionShowNextPhoto = menu.addAction("Next photo (Right arrow)")
            actionShowPreviousPhoto = menu.addAction(
                "Previous photo (Left arrow)")
            menu.addSeparator()

            if self.mdiParent.isMaximized() is True:
                if self.mdiParent.cursorIsVisible:
                    actionToggleHideCursor = menu.addAction("Hide cursor (F7)")
                else:
                    actionToggleHideCursor = menu.addAction("Show cursor (F7)")

            if self.mdiParent.detailsPane.isVisible():
                actionToggleCameraDetails = menu.addAction("Hide details (F9)")
            else:
                actionToggleCameraDetails = menu.addAction("Show details (F9)")

            if self.mdiParent.isMaximized(
            ) and self.mdiParent.mdiParent.mdiParent.isFullScreen():
                actionToggleFullScreen = menu.addAction(
                    "Exit full screen (F11)")
            else:
                actionToggleFullScreen = menu.addAction("Full screen (F11)")

            menu.addSeparator()
            actionDetachFile = menu.addAction("Detach photo from Yearbird")
            menu.addSeparator()
            actionDeleteFile = menu.addAction("Delete photo from file system")

            action = menu.exec_(self.mapToGlobal(event.pos()))

            if self.mdiParent.isMaximized() is True:
                if action == actionToggleHideCursor:
                    self.parent().toggleHideCursor()

            if action == actionFitToWindow:
                self.parent().fitEnlargement()

            if action == actionShowNextPhoto:
                self.parent().showNextPhoto()

            if action == actionShowPreviousPhoto:
                self.parent().showPreviousPhoto()

            if action == actionToggleCameraDetails:
                self.parent().toggleCameraDetails()

            if action == actionToggleFullScreen:
                self.parent().toggleFullScreen()

            if action == actionDeleteFile:
                self.parent().deleteFile()

            if action == actionDetachFile:
                self.parent().detachFile()

    def __init__(self):
        super(self.__class__, self).__init__()
        self.setupUi(self)
        self.setAttribute(Qt.WA_DeleteOnClose, True)
        self.resized.connect(self.resizeMe)
        self.mdiParent = ""
        self.photoList = []
        self.currentIndex = 0

        self.pixmapEnlargement = QPixmap()

        self.layout().setDirection(1)
        self.layout().setContentsMargins(0, 0, 0, 0)
        self.layout().setSpacing(0)
        self.setStyleSheet("color:silver; background-color: #343333")

        self.detailsPaneLayout = QVBoxLayout()
        self.detailsPaneLayout.setContentsMargins(0, 0, 0, 0)
        self.detailsPaneLayout.setSpacing(0)
        self.detailsPaneLayout.setAlignment(Qt.AlignCenter)

        self.detailsPane = QFrame()
        self.detailsPane.setLayout(self.detailsPaneLayout)
        self.detailsPane.setStyleSheet(
            "color:silver; background-color: #343333")

        self.layout().addWidget(self.detailsPane)

        # create label for species common name
        self.commonName = QLabel()
        self.commonName.setStyleSheet(
            "font:12pt; font-weight:bold; color:silver; background-color: #343333; padding: 3px"
        )
        self.detailsPaneLayout.addWidget(self.commonName)

        # create label for species scientific name
        self.scientificName = QLabel()
        self.scientificName.setStyleSheet(
            "font:12pt; font-style:italic; color:silver; background-color: #343333; padding: 3px"
        )
        self.detailsPaneLayout.addWidget(self.scientificName)

        # create label for camera details text
        self.cameraDetails = QLabel()
        self.cameraDetails.setStyleSheet(
            "color:silver; background-color: #343333; padding: 3px")
        self.detailsPane.setVisible(False)
        self.detailsPaneLayout.addWidget(self.cameraDetails)

        # create horizontal layout to show rating stars
        self.horizontalGroupBox = QGroupBox()
        self.horizontalGroupBox.setContentsMargins(0, 0, 0, 0)
        self.horizontalGroupBox.setStyleSheet(
            "background-color: #343333; padding: 3px")

        self.detailsPaneLayout.addWidget(self.horizontalGroupBox)

        ratingLayout = QHBoxLayout()
        ratingLayout.setContentsMargins(0, 0, 0, 0)
        ratingLayout.setSpacing(0)

        self.star1 = QPushButton()
        self.star2 = QPushButton()
        self.star3 = QPushButton()
        self.star4 = QPushButton()
        self.star5 = QPushButton()

        self.star1.setIconSize(QSize(40, 40))
        self.star2.setIconSize(QSize(40, 40))
        self.star3.setIconSize(QSize(40, 40))
        self.star4.setIconSize(QSize(40, 40))
        self.star5.setIconSize(QSize(40, 40))

        self.star1.setStyleSheet(
            "QPushButton:pressed{ background-color: #343333; }")
        self.star1.setStyleSheet(
            "QPushButton:hover{ background-color: #343333; }")
        self.star1.setStyleSheet(
            "QPushButton:flat{ background-color: #343333; }")
        self.star1.setStyleSheet(
            "QPushButton{ background-color: #343333; border:none }")
        self.star2.setStyleSheet(
            "QPushButton:pressed{ background-color: #343333; }")
        self.star2.setStyleSheet(
            "QPushButton:hover{ background-color: #343333; }")
        self.star2.setStyleSheet(
            "QPushButton:flat{ background-color: #343333; }")
        self.star2.setStyleSheet(
            "QPushButton{ background-color: #343333; border:none }")
        self.star3.setStyleSheet(
            "QPushButton:pressed{ background-color: #343333; }")
        self.star3.setStyleSheet(
            "QPushButton:hover{ background-color: #343333; }")
        self.star3.setStyleSheet(
            "QPushButton:flat{ background-color: #343333; }")
        self.star3.setStyleSheet(
            "QPushButton{ background-color: #343333; border:none }")
        self.star4.setStyleSheet(
            "QPushButton:pressed{ background-color: #343333; }")
        self.star4.setStyleSheet(
            "QPushButton:hover{ background-color: #343333; }")
        self.star4.setStyleSheet(
            "QPushButton:flat{ background-color: #343333; }")
        self.star4.setStyleSheet(
            "QPushButton{ background-color: #343333; border:none }")
        self.star5.setStyleSheet(
            "QPushButton:pressed{ background-color: #343333; }")
        self.star5.setStyleSheet(
            "QPushButton:hover{ background-color: #343333; }")
        self.star5.setStyleSheet(
            "QPushButton:flat{ background-color: #343333; }")
        self.star5.setStyleSheet(
            "QPushButton{ background-color: #343333; border:none }")

        self.star1.setIcon(QIcon(QPixmap(":/icon_star.png")))
        self.star2.setIcon(QIcon(QPixmap(":/icon_star.png")))
        self.star3.setIcon(QIcon(QPixmap(":/icon_star.png")))
        self.star4.setIcon(QIcon(QPixmap(":/icon_star.png")))
        self.star5.setIcon(QIcon(QPixmap(":/icon_star.png")))

        self.star1.clicked.connect(lambda: self.ratePhoto(Qt.Key_1, "Clicked"))
        self.star2.clicked.connect(lambda: self.ratePhoto(Qt.Key_2))
        self.star3.clicked.connect(lambda: self.ratePhoto(Qt.Key_3))
        self.star4.clicked.connect(lambda: self.ratePhoto(Qt.Key_4))
        self.star5.clicked.connect(lambda: self.ratePhoto(Qt.Key_5))

        ratingLayout.addWidget(self.star1)
        ratingLayout.addWidget(self.star2)
        ratingLayout.addWidget(self.star3)
        ratingLayout.addWidget(self.star4)
        ratingLayout.addWidget(self.star5)

        self.horizontalGroupBox.setLayout(ratingLayout)

        self.cursorIsVisible = True

    def resizeEvent(self, event):
        #routine to handle window resize event
        self.resized.emit()
        return super(self.__class__, self).resizeEvent(event)

    def resizeMe(self):

        QTimer.singleShot(5, self.fitEnlargement)

    def scaleMe(self):

        return

    def keyPressEvent(self, e):

        # F key is pressed. Re-display the currentEnlargement to fit the screen
        if e.key() == Qt.Key_F:
            self.fitEnlargement()

        # Backspace key is pressed, so show previous image as enlargement
        if e.key() == Qt.Key_Backspace:
            self.showPreviousPhoto()

        # Space bar is pressed, so show next image as enlargement
        if e.key() == Qt.Key_Space:
            self.showNextPhoto()

        # F7 is pressed, so toggle display of cursor
        if e.key() == Qt.Key_F7:
            self.toggleHideCursor()

        # F9 is pressed, so toggle display of camera details
        if e.key() == Qt.Key_F9:
            self.toggleCameraDetails()

        # F11 is pressed, so toggle display of camera details
        if e.key() == Qt.Key_F11:
            self.toggleFullScreen()

        # Esc is pressed, so exit full screen mode, if we're in it
        if e.key(
        ) == Qt.Key_Escape and self.mdiParent.mdiParent.statusBar.isVisible(
        ) is False:
            self.toggleFullScreen()

        # 1-5 pressed, so rate the photo
        if e.key() in [
                Qt.Key_0, Qt.Key_1, Qt.Key_2, Qt.Key_3, Qt.Key_4, Qt.Key_5
        ]:
            self.ratePhoto(e.key())

        # Right is pressed: show next photo
        if e.key() == Qt.Key_Right or e.key() == Qt.Key_PageDown:
            self.showNextPhoto()

        # Left is pressed: show previous photo
        if e.key() == Qt.Key_Left or e.key() == Qt.Key_PageUp:
            self.showPreviousPhoto()

    def ratePhoto(self, ratingKey, actionType=""):

        if ratingKey == Qt.Key_0:
            self.photoList[self.currentIndex][0]["rating"] = "0"
        if ratingKey == Qt.Key_1:
            if self.photoList[self.currentIndex][0][
                    "rating"] == "1" and actionType == "Clicked":
                self.photoList[self.currentIndex][0]["rating"] = "0"
            else:
                self.photoList[self.currentIndex][0]["rating"] = "1"
        if ratingKey == Qt.Key_2:
            self.photoList[self.currentIndex][0]["rating"] = "2"
        if ratingKey == Qt.Key_3:
            self.photoList[self.currentIndex][0]["rating"] = "3"
        if ratingKey == Qt.Key_4:
            self.photoList[self.currentIndex][0]["rating"] = "4"
        if ratingKey == Qt.Key_5:
            self.photoList[self.currentIndex][0]["rating"] = "5"

        self.setCameraDetails()
        self.detailsPane.setVisible(True)
        self.mdiParent.mdiParent.db.photosNeedSaving = True
        self.viewEnlargement.setFocus()

    def showPreviousPhoto(self):

        if self.currentIndex > 0:
            self.currentIndex = self.currentIndex - 1

        if self.currentIndex >= 0:
            self.changeEnlargement()

    def showNextPhoto(self):

        if self.currentIndex < len(self.photoList) - 1:
            self.currentIndex += 1
            self.changeEnlargement()

    def fillEnlargement(self):

        # routine uses self.currentIndex to fill the right photo
        self.pixmapEnlargement = QPixmap(
            self.photoList[self.currentIndex][0]["fileName"])

        self.sceneEnlargement = QGraphicsScene()
        # save the item ID of the pixmap so we can replace the pixmap photo easily later
        self.itemPixmap = self.sceneEnlargement.addPixmap(
            self.pixmapEnlargement)

        self.viewEnlargement = self.MyGraphicsView()
        self.viewEnlargement.mdiParent = self
        self.viewEnlargement.setScene(self.sceneEnlargement)
        self.viewEnlargement.setStyleSheet(
            "QWidget{ background-color: #343333;}")

        # add viewEnlargementto the default layout of the form
        self.layout().addWidget(self.viewEnlargement)

        self.setCameraDetails()

        self.setPhotoTitle()

        QTimer.singleShot(10, self.fitEnlargement)

    def changeEnlargement(self):

        self.pixmapEnlargement = QPixmap(
            self.photoList[self.currentIndex][0]["fileName"])

        self.itemPixmap.setPixmap(self.pixmapEnlargement)

        self.setCameraDetails()

        self.setPhotoTitle()

        QTimer.singleShot(20, self.fitEnlargement)

    def fitEnlargement(self):

        # scale the view to fit the photo, edge to edge
        self.viewEnlargement.setSceneRect(0, 0, self.pixmapEnlargement.width(),
                                          self.pixmapEnlargement.height())
        self.viewEnlargement.fitInView(self.viewEnlargement.sceneRect(),
                                       Qt.KeepAspectRatio)

    def setPhotoTitle(self):

        # display the file name in the window title bar
        basename = os.path.basename(
            self.photoList[self.currentIndex][0]["fileName"])
        self.setWindowTitle(basename)

    def toggleCameraDetails(self):

        # toggle visibility of cameraDetails
        if self.detailsPane.isVisible():
            self.detailsPane.setVisible(False)
        else:
            self.detailsPane.setVisible(True)

        QTimer.singleShot(10, self.fitEnlargement)

    def toggleHideCursor(self):

        # toggle visibility of the cursor

        # abort if we're not full screen (don't want to confuse user by hiding cursor)
        if not self.isMaximized():
            return ()

        # abort if we're not full screen (don't want to confuse user by hiding cursor)
        if not self.mdiParent.mdiParent.isFullScreen():
            return ()

        if self.cursorIsVisible is True:
            QApplication.setOverrideCursor(QCursor(Qt.BlankCursor))
            self.cursorIsVisible = False
        else:
            QApplication.restoreOverrideCursor()
            self.cursorIsVisible = True

    def detachFile(self):

        # remove photo from database, but don't delete it from file system
        msgText = "Detach \n\n" + self.photoList[
            self.currentIndex][0]["fileName"] + "\n\n from Yearbird?"
        msgText = msgText + "\n\n(File will NOT be deleted from file system)"

        msg = QMessageBox()
        msg.setText(msgText)
        msg.setWindowTitle("Detach photo?")
        msg.setStandardButtons(QMessageBox.No | QMessageBox.Yes)
        buttonClicked = msg.exec_()

        if buttonClicked == QMessageBox.Yes:

            # remove photo from database
            currentPhoto = self.photoList[self.currentIndex][0]["fileName"]
            photoCommonName = self.photoList[
                self.currentIndex][1]["commonName"]
            photoLocation = self.photoList[self.currentIndex][1]["location"]

            self.mdiParent.mdiParent.db.removePhotoFromDatabase(
                photoLocation, "", "", photoCommonName, currentPhoto)

            # remove photo from current window's photo list
            self.photoList.remove(self.photoList[self.currentIndex])

            # refresh display of parent photo list
            self.mdiParent.FillPhotos(self.mdiParent.filter)

            # advance display to next photo
            if len(self.photoList) == 0:
                self.close()

            if self.currentIndex < len(self.photoList):
                self.changeEnlargement()

            else:
                self.currentIndex -= 1
                self.changeEnlargement()

            # set flag for requiring photo file save
            self.mdiParent.mdiParent.db.photosNeedSaving = True

    def deleteFile(self):

        # remove photo from database, but don't delete it from file system
        msgText = "Permanently delete \n\n" + self.photoList[
            self.currentIndex][0][
                "fileName"] + "\n\n from Yearbird and the file system?"

        msg = QMessageBox()
        msg.setText(msgText)
        msg.setWindowTitle("Permanently delete photo?")
        msg.setStandardButtons(QMessageBox.No | QMessageBox.Yes)
        buttonClicked = msg.exec_()

        if buttonClicked == QMessageBox.Yes:

            # remove photo from database
            currentPhoto = self.photoList[self.currentIndex][0]["fileName"]
            photoCommonName = self.photoList[
                self.currentIndex][1]["commonName"]
            photoLocation = self.photoList[self.currentIndex][1]["location"]

            self.mdiParent.mdiParent.db.removePhotoFromDatabase(
                photoLocation, "", "", photoCommonName, currentPhoto)

            # remove photo from current window's photo list
            self.photoList.remove(self.photoList[self.currentIndex])

            # advance display to next photo
            if len(self.photoList) == 0:
                self.close()

            if self.currentIndex < len(self.photoList):
                self.changeEnlargement()

            else:
                self.currentIndex -= 1
                self.changeEnlargement()

            # set flag for requiring photo file save
            self.mdiParent.mdiParent.db.photosNeedSaving = True

            # delete file from file system
            if os.path.isfile(currentPhoto):
                try:
                    os.remove(currentPhoto)
                except:
                    pass

            # refresh display of parent photo list
            self.mdiParent.FillPhotos(self.mdiParent.filter)

    def toggleFullScreen(self):

        # toggle visibility of filter and menu bar
        if not self.mdiParent.mdiParent.isFullScreen() is True:

            self.mdiParent.mdiParent.dckFilter.setVisible(False)
            self.mdiParent.mdiParent.dckPhotoFilter.setVisible(False)
            self.mdiParent.mdiParent.menuBar.setVisible(False)
            self.mdiParent.mdiParent.toolBar.setVisible(False)
            self.mdiParent.mdiParent.statusBar.setVisible(False)
            self.setWindowFlags(Qt.FramelessWindowHint)
            self.mdiParent.mdiParent.showFullScreen()
            self.showMaximized()

        else:

            self.mdiParent.mdiParent.dckFilter.setVisible(True)
            self.mdiParent.mdiParent.dckPhotoFilter.setVisible(True)
            self.mdiParent.mdiParent.menuBar.setVisible(True)
            self.mdiParent.mdiParent.toolBar.setVisible(True)
            self.mdiParent.mdiParent.statusBar.setVisible(True)
            self.mdiParent.mdiParent.showNormal()
            self.mdiParent.mdiParent.showMaximized()
            self.setWindowFlags(Qt.SubWindow)
            self.showNormal()
            QApplication.restoreOverrideCursor()

        QTimer.singleShot(10, self.fitEnlargement)

    def setCameraDetails(self):

        currentPhoto = self.photoList[self.currentIndex][0]["fileName"]
        photoRating = self.photoList[self.currentIndex][0]["rating"]

        photoCommonName = self.photoList[self.currentIndex][1]["commonName"]
        photoScientificName = self.photoList[
            self.currentIndex][1]["scientificName"]
        photoLocation = self.photoList[self.currentIndex][1]["location"]

        # get EXIF data

        try:
            exif_dict = piexif.load(currentPhoto)
        except:
            exif_dict = ""

        # get photo date from EXIF
        try:
            photoDateTime = exif_dict["Exif"][
                piexif.ExifIFD.DateTimeOriginal].decode("utf-8")

            #parse EXIF data for date/time components
            photoExifDate = photoDateTime[0:4] + "-" + photoDateTime[
                5:7] + "-" + photoDateTime[8:10]
            photoExifTime = photoDateTime[11:13] + ":" + photoDateTime[14:16]

            photoWeekday = datetime.datetime(int(photoDateTime[0:4]),
                                             int(photoDateTime[5:7]),
                                             int(photoDateTime[8:10]))
            photoWeekday = photoWeekday.strftime("%A") + ", "

        except:
            photoExifDate = "Date unknown"
            photoExifTime = "Time unknown"
            photoWeekday = ""

        try:
            photoExifModel = exif_dict["0th"][piexif.ImageIFD.Model].decode(
                "utf-8")
        except:
            photoExifModel = ""
        try:
            photoExifLensModel = exif_dict["Exif"][
                piexif.ExifIFD.LensModel].decode("utf-8")
        except:
            photoExifLensModel = ""

        try:
            photoExifExposureTime = exif_dict["Exif"][
                piexif.ExifIFD.ExposureTime]
            photoExifExposureTime = "1/" + str(
                floor(photoExifExposureTime[1] /
                      photoExifExposureTime[0])) + " sec"
        except:
            photoExifExposureTime = ""

        try:
            photoExifAperture = exif_dict["Exif"][piexif.ExifIFD.FNumber]
            photoExifAperture = round(
                photoExifAperture[0] / photoExifAperture[1], 1)
        except:
            photoExifAperture = ""

        try:
            photoExifISO = exif_dict["Exif"][piexif.ExifIFD.ISOSpeedRatings]
        except:
            photoExifISO = ""

        try:
            photoExifFocalLength = exif_dict["Exif"][
                piexif.ExifIFD.FocalLength]
            photoExifFocalLength = floor(photoExifFocalLength[0] /
                                         photoExifFocalLength[1])
            photoExifFocalLength = str(photoExifFocalLength) + " mm"

        except:
            photoExifFocalLength = ""

        self.commonName.setText(photoCommonName)
        self.scientificName.setText(photoScientificName)

        #         detailsText = photoCommonName + "\n"
        #         detailsText = photoScientificName + "\n"
        detailsText = "\n\n" + photoLocation + "\n"
        detailsText = detailsText + photoWeekday + photoExifDate + "\n"
        detailsText = detailsText + photoExifTime + "\n"
        detailsText = detailsText + "\n"
        detailsText = detailsText + photoExifModel + "\n"
        detailsText = detailsText + photoExifLensModel + "\n"
        detailsText = detailsText + "Focal Length: " + str(
            photoExifFocalLength) + "\n"
        detailsText = detailsText + str(photoExifExposureTime) + "\n"
        detailsText = detailsText + "Aperture: " + str(
            photoExifAperture) + "\n"
        detailsText = detailsText + "ISO: " + str(photoExifISO)
        detailsText = detailsText + "\n\n" + ntpath.basename(currentPhoto)
        detailsText = detailsText + "\n\n\n"  #add space to separate rating stars from text

        if photoRating == "0":
            self.star1.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
            self.star2.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
            self.star3.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
            self.star4.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
            self.star5.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
        if photoRating == "1":
            self.star1.setIcon(QIcon(QPixmap(":/icon_star.png")))
            self.star2.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
            self.star3.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
            self.star4.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
            self.star5.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
        if photoRating == "2":
            self.star1.setIcon(QIcon(QPixmap(":/icon_star.png")))
            self.star2.setIcon(QIcon(QPixmap(":/icon_star.png")))
            self.star3.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
            self.star4.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
            self.star5.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
        if photoRating == "3":
            self.star1.setIcon(QIcon(QPixmap(":/icon_star.png")))
            self.star2.setIcon(QIcon(QPixmap(":/icon_star.png")))
            self.star3.setIcon(QIcon(QPixmap(":/icon_star.png")))
            self.star4.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
            self.star5.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
        if photoRating == "4":
            self.star1.setIcon(QIcon(QPixmap(":/icon_star.png")))
            self.star2.setIcon(QIcon(QPixmap(":/icon_star.png")))
            self.star3.setIcon(QIcon(QPixmap(":/icon_star.png")))
            self.star4.setIcon(QIcon(QPixmap(":/icon_star.png")))
            self.star5.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
        if photoRating == "5":
            self.star1.setIcon(QIcon(QPixmap(":/icon_star.png")))
            self.star2.setIcon(QIcon(QPixmap(":/icon_star.png")))
            self.star3.setIcon(QIcon(QPixmap(":/icon_star.png")))
            self.star4.setIcon(QIcon(QPixmap(":/icon_star.png")))
            self.star5.setIcon(QIcon(QPixmap(":/icon_star.png")))

        self.cameraDetails.setText(detailsText)
コード例 #11
0
    def __init__(self, text, colors, color_caption):
        TestableWidget.__init__(self)
        self.setWindowFlags(Qt.Popup)

        main_layout = QVBoxLayout()
        main_layout.setContentsMargins(0, 0, 0, 0)
        border = "border: 1px solid #9b9b9b;"
        self.setStyleSheet('QFrame[frameShape="4"]{  color: #9b9b9b;}')

        # -- CAPTION ----------------------------------
        caption = QFrame(self, flags=Qt.WindowFlags())
        caption_layout = QHBoxLayout()
        self._lbl_caption = QLabel(text)
        self._lbl_caption.setStyleSheet("border: 0px solid blue;")
        caption_layout.addWidget(self._lbl_caption, alignment=Qt.Alignment())
        caption.setLayout(caption_layout)
        caption_layout.setContentsMargins(9, 5, 9, 5)
        caption.setStyleSheet(f"background-color: {color_caption}; {border}")

        # -- COLORS GRID ------------------------------
        colorbox = QFrame(self, flags=Qt.WindowFlags())
        color_layout = QGridLayout()
        colorbox.setLayout(color_layout)
        color_layout.setContentsMargins(9, 0, 9, 0)
        nn = 7
        self.clrbtn = []
        for i, color in enumerate(colors):
            self.clrbtn.append(QToolButton())
            css = (f"QToolButton {{{border}background-color:{color};}}"
                   f"QToolButton:hover {{border: 1px solid red; }}")
            self.clrbtn[-1].setStyleSheet(css)
            self.clrbtn[-1].clicked.connect(
                lambda x, c=color: self.select_color_(c))
            # noinspection PyArgumentList
            color_layout.addWidget(self.clrbtn[-1], i // nn, i % nn)

        # -- SPLITTER ---------------------------------
        h_frame = QFrame(None, flags=Qt.WindowFlags())
        h_frame.setFrameShape(QFrame.HLine)
        h_frame.setContentsMargins(0, 0, 0, 0)

        # -- BOTTOM (other color) ---------------------
        btns = QFrame(self, flags=Qt.WindowFlags())
        btn_layout = QHBoxLayout()
        other = QToolButton()
        other.clicked.connect(self.other_color_)
        other.setAutoRaise(True)
        other.setIcon(QIcon(img("editor/colorwheel")))
        btn_layout.addWidget(other, alignment=Qt.Alignment())
        self._lbl_other = QLabel(self.tr("other colors"))
        btn_layout.addWidget(self._lbl_other, alignment=Qt.Alignment())
        btns.setLayout(btn_layout)
        btn_layout.setContentsMargins(9, 0, 9, 9)
        self.clrbtn.append(other)

        # ---------------------------------------------
        main_layout.addWidget(caption, alignment=Qt.Alignment())
        main_layout.addWidget(colorbox, alignment=Qt.Alignment())
        main_layout.addWidget(h_frame, alignment=Qt.Alignment())
        main_layout.addWidget(btns, alignment=Qt.Alignment())

        self.setLayout(main_layout)
コード例 #12
0
ファイル: instable.py プロジェクト: ligm74/LiGM
    def __init__(self, color_caption):
        TestableWidget.__init__(self)
        self.setWindowFlags(Qt.Popup)
        self._text = self.tr("Table")

        main_layout = QVBoxLayout()
        main_layout.setContentsMargins(0, 0, 0, 0)

        b = "border: 1px solid #9b9b9b;"
        self._styles = {
            "border": b,
            "border_blue": "border: 0px solid blue;",
            "selection": f"QToolButton {{{b}background-color:#fee5e2;}}",
            "white": f"QToolButton {{{b}background-color:white;}}",
            "frame": 'QFrame[frameShape="4"]{color: #9b9b9b;}'}

        self.setStyleSheet(self._styles["frame"])

        # -- CAPTION ----------------------------------
        caption = QFrame(self, flags=Qt.WindowFlags())
        caption_layout = QHBoxLayout()
        self._lbl_caption = QLabel(self._text)
        self._lbl_caption.setStyleSheet(self._styles["border_blue"])
        caption_layout.addWidget(self._lbl_caption, alignment=Qt.Alignment())
        caption.setLayout(caption_layout)
        caption_layout.setContentsMargins(9, 5, 9, 5)
        caption.setStyleSheet(
            f"background-color: {color_caption}; {self._styles['border']}")

        # -- CELLS GRID -------------------------------
        cellsbox = QFrame(self, flags=Qt.WindowFlags())
        cells = QGridLayout()
        cells.setSpacing(1)
        cellsbox.setLayout(cells)
        cells.setContentsMargins(9, 0, 9, 0)
        self._nn = 10
        self._clrbtn = []
        colors = ["white" for _ in range(self._nn ** 2)]
        cellsbox.leaveEvent = lambda x: self._leave_cell()
        for i, color in enumerate(colors):
            self._clrbtn.append(QToolButton())
            # noinspection PyPep8Naming
            self._clrbtn[-1].enterEvent = lambda x, n=i: self._enter_cell(n)
            self._clrbtn[-1].setStyleSheet(self._styles["white"])
            self._clrbtn[-1].clicked.connect(
                lambda x, n=i: self.select_size_(n))
            # noinspection PyArgumentList
            cells.addWidget(self._clrbtn[-1], i // self._nn, i % self._nn)

        # -- SPLITTER ---------------------------------
        h_frame = QFrame(None, flags=Qt.WindowFlags())
        h_frame.setFrameShape(QFrame.HLine)
        h_frame.setContentsMargins(0, 0, 0, 0)

        # -- BOTTOM (other color) ---------------------
        btns = QFrame(self, flags=Qt.WindowFlags())
        btn_layout = QHBoxLayout()
        other = QToolButton()
        other.clicked.connect(self.other_size_)
        other.setAutoRaise(True)
        other.setIcon(QIcon(img("editor/table_gray")))
        btn_layout.addWidget(other, alignment=Qt.Alignment())
        self._lbl_other = QLabel(self.tr("insert table"))
        btn_layout.addWidget(self._lbl_other, alignment=Qt.Alignment())
        btns.setLayout(btn_layout)
        btn_layout.setContentsMargins(9, 0, 9, 9)
        self._clrbtn.append(other)

        # ---------------------------------------------
        main_layout.addWidget(caption, alignment=Qt.Alignment())
        main_layout.addWidget(cellsbox, alignment=Qt.Alignment())
        main_layout.addWidget(h_frame, alignment=Qt.Alignment())
        main_layout.addWidget(btns, alignment=Qt.Alignment())

        self.setLayout(main_layout)