Example #1
0
    def __init__(self, app, image_data, parent=None):
        """ Image_data contains: {name, mediapath, owner, id, date, memo, fulltext}
        """

        sys.excepthook = exception_handler
        self.app = app
        self.image_data = image_data
        QtWidgets.QDialog.__init__(self)
        self.ui = Ui_Dialog_view_image()
        self.ui.setupUi(self)
        try:
            w = int(self.app.settings['dialogviewimage_w'])
            h = int(self.app.settings['dialogviewimage_h'])
            if h > 50 and w > 50:
                self.resize(w, h)
        except:
            pass
        font = 'font: ' + str(self.app.settings['fontsize']) + 'pt '
        font += '"' + self.app.settings['font'] + '";'
        self.setStyleSheet(font)
        self.setWindowTitle(self.image_data['mediapath'])
        try:
            source = self.app.project_path + self.image_data['mediapath']
        except Exception as e:
            mb = QtWidgets.QMessageBox()
            mb.setStyleSheet("* {font-size:" +
                             str(self.app.settings['fontsize']) + "pt} ")
            mb.setWindowTitle(_('Image error'))
            mb.setText(_("Image file not found: ") + source + "\n" + str(e))
            mb.exec_()
        image = QtGui.QImage(source)
        if image.isNull():
            mb = QtWidgets.QMessageBox()
            mb.setStyleSheet("* {font-size:" +
                             str(self.app.settings['fontsize']) + "pt} ")
            mb.setWindowTitle(_('Image error'))
            mb.setText(_("Cannot open: ") + source)
            mb.exec_()
            self.close()
            return
        self.pixmap = QtGui.QPixmap.fromImage(image)
        self.label = QtWidgets.QLabel()
        self.label.setSizePolicy(QtWidgets.QSizePolicy.Ignored,
                                 QtWidgets.QSizePolicy.Ignored)
        self.label.setFixedWidth(self.pixmap.width())
        self.label.setFixedHeight(self.pixmap.height())
        self.label.setScaledContents(True)
        self.label.setPixmap(self.pixmap)
        self.ui.scrollArea.setWidget(self.label)
        self.ui.horizontalSlider.valueChanged[int].connect(self.change_scale)
        self.ui.textEdit.setText(self.image_data['memo'])
Example #2
0
    def __init__(self, settings, image_data, parent=None):
        ''' Image_data contains: {name, imagepath, owner, id, date, memo, fulltext}
        '''

        sys.excepthook = exception_handler
        self.settings = settings
        self.image_data = image_data
        QtWidgets.QDialog.__init__(self)
        self.ui = Ui_Dialog_view_image()
        self.ui.setupUi(self)
        newfont = QtGui.QFont(settings['font'], settings['fontsize'],
                              QtGui.QFont.Normal)
        self.setFont(newfont)
        self.setWindowTitle("Image: " + self.image_data['name'])
        try:
            source = self.settings['path'] + "/images/" + self.image_data[
                'name']
        except Exception as e:
            QtWidgets.QMessageBox.warning(
                None, "Image error", "Image file not found. %s\n" + str(e),
                source)
        image = QtGui.QImage(source)
        if image.isNull():
            QtWidgets.QMessageBox.warming(None, "Immage Error",
                                          "Cannot open %s." % source)
            self.close()
            return
        self.pixmap = QtGui.QPixmap.fromImage(image)
        self.label = QtWidgets.QLabel()
        self.label.setSizePolicy(QtWidgets.QSizePolicy.Ignored,
                                 QtWidgets.QSizePolicy.Ignored)
        self.label.setFixedWidth(self.pixmap.width())
        self.label.setFixedHeight(self.pixmap.height())
        self.label.setScaledContents(True)
        self.label.setPixmap(self.pixmap)
        self.ui.scrollArea.setWidget(self.label)
        self.ui.horizontalSlider.valueChanged[int].connect(self.change_scale)
        self.ui.textEdit.setText(self.image_data['memo'])
Example #3
0
class DialogViewImage(QtWidgets.QDialog):
    """ View image. View and edit displayed memo.
    Show a scaleable and scrollable image.
    The slider values range from 10 to 99.
    """

    app = None
    image_data = None
    pixmap = None
    label = None

    def __init__(self, app, image_data, parent=None):
        """ Image_data contains: {name, mediapath, owner, id, date, memo, fulltext}
        """

        sys.excepthook = exception_handler
        self.app = app
        self.image_data = image_data
        QtWidgets.QDialog.__init__(self)
        self.ui = Ui_Dialog_view_image()
        self.ui.setupUi(self)
        try:
            w = int(self.app.settings['dialogviewimage_w'])
            h = int(self.app.settings['dialogviewimage_h'])
            if h > 50 and w > 50:
                self.resize(w, h)
        except:
            pass
        font = 'font: ' + str(self.app.settings['fontsize']) + 'pt '
        font += '"' + self.app.settings['font'] + '";'
        self.setStyleSheet(font)
        self.setWindowTitle(self.image_data['mediapath'])
        try:
            source = self.app.project_path + self.image_data['mediapath']
        except Exception as e:
            mb = QtWidgets.QMessageBox()
            mb.setStyleSheet("* {font-size:" +
                             str(self.app.settings['fontsize']) + "pt} ")
            mb.setWindowTitle(_('Image error'))
            mb.setText(_("Image file not found: ") + source + "\n" + str(e))
            mb.exec_()
        image = QtGui.QImage(source)
        if image.isNull():
            mb = QtWidgets.QMessageBox()
            mb.setStyleSheet("* {font-size:" +
                             str(self.app.settings['fontsize']) + "pt} ")
            mb.setWindowTitle(_('Image error'))
            mb.setText(_("Cannot open: ") + source)
            mb.exec_()
            self.close()
            return
        self.pixmap = QtGui.QPixmap.fromImage(image)
        self.label = QtWidgets.QLabel()
        self.label.setSizePolicy(QtWidgets.QSizePolicy.Ignored,
                                 QtWidgets.QSizePolicy.Ignored)
        self.label.setFixedWidth(self.pixmap.width())
        self.label.setFixedHeight(self.pixmap.height())
        self.label.setScaledContents(True)
        self.label.setPixmap(self.pixmap)
        self.ui.scrollArea.setWidget(self.label)
        self.ui.horizontalSlider.valueChanged[int].connect(self.change_scale)
        self.ui.textEdit.setText(self.image_data['memo'])

    def closeEvent(self, event):
        """ Save dialog and splitter dimensions. """

        self.app.settings['dialogviewimage_w'] = self.size().width()
        self.app.settings['dialogviewimage_h'] = self.size().height()

    def change_scale(self):
        """ Resize image. Idea from:
        https://github.com/baoboa/pyqt5/blob/master/examples/widgets/imageviewer.py
        """

        scale = (self.ui.horizontalSlider.value() + 1) / 100
        new_label = self.label.resize(scale * self.label.pixmap().size())
        self.label.setFixedWidth(scale * self.pixmap.width())
        self.label.setFixedHeight(scale * self.pixmap.height())
        self.ui.scrollArea.setWidget(new_label)