Esempio n. 1
0
File: align.py Progetto: 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)
Esempio n. 2
0
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)
Esempio n. 3
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)
Esempio n. 4
0
    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)