예제 #1
0
    def paintTeam(self, painter, team, xOffset):
        pickXOffset = xOffset
        banXOffset = xOffset

        for player in self.championSelect.getTeam(team):
            if player.champion:
                qim = ImageQt(player.champion.image.image)
                qim = qim.scaled(40, 40, Qt.KeepAspectRatio)

                painter.drawImage(QPoint(qim.width() * pickXOffset, 0), qim)

                pickXOffset += 1

            for champion in player.bannedChampions.values():
                qim = ImageQt(champion.image.image)
                qim = qim.scaled(40, 40, Qt.KeepAspectRatio)

                painter.drawImage(
                    QPoint(qim.width() * banXOffset, qim.height()), qim)

                painter.drawLine(qim.width() * banXOffset, qim.height(),
                                 qim.width() * (banXOffset + 1),
                                 qim.height() * 2)
                painter.drawLine(qim.width() * (banXOffset + 1), qim.height(),
                                 qim.width() * banXOffset,
                                 qim.height() * 2)

                banXOffset += 1

        return max(pickXOffset, banXOffset)
예제 #2
0
 def __init__(self, m, c, p, path, parent=None):
     super(watcher, self).__init__(parent)
     im = PIL.Image.open(path)
     self.color = self.get_dominant_color(im)
     desktop =QtGui.QApplication.desktop()
     width = desktop.width()
     height = desktop.height()
     qim = ImageQt(im)
     
     self.fixLength = height - 150
     if qim.height()>=qim.width():
         _img = qim.scaled(self.fixLength, self.fixLength, Qt.Qt.KeepAspectRatio)
     else:
         _img = qim.scaled(qim.width()*self.fixLength/qim.height(), qim.width()*self.fixLength/qim.height(), Qt.Qt.KeepAspectRatio)
     self.setStyleSheet(("background-color: rgb"+str(self.color)+";"))
     self.setFixedSize(_img.width(), _img.height()+50)
     self.setWindowIcon(QtGui.QIcon("../pics/icon/icon.png"))
     self.move((width - self.width())/2, (height - self.height())/2-25)
     
     self.labelPhoto = QtGui.QLabel(self)
     self.labelPhoto.setPixmap(QtGui.QPixmap.fromImage(_img))
     self.labelPhoto.setGeometry(0, 0, _img.width(), _img.height())
     
     '''照片名字显示'''
     font = QtGui.QFont(u'微软雅黑', 15)
     name = path.split('\\')[-1]
     self.labelName = QtGui.QLabel(u'● '+name, self)
     self.labelName.setGeometry(10, _img.height(), len(name)*17, 50)
     self.nameColor = (int(255-self.color[0]), int(255-self.color[1]), int(255-self.color[2]))        
     self.labelName.setStyleSheet(("color: rgb"+str(self.nameColor)+";"))
     self.labelName.setFont(font)
     self.setWindowTitle("xiaoyWatcher v1.0 "+name)
     
     '''照片心情显示'''
     tipMood = [u'无', u'好', u'良', u'差']
     self.labelmood = QtGui.QLabel(self)
     self.labelmood.setPixmap(QtGui.QPixmap('../pics/watcher/moodGOOD'+str(m)+'.png'))
     self.labelmood.setGeometry(_img.width()-100, _img.height()+13, 34, 26)
     self.labelmood.setToolTip(tipMood[m])
     
     '''照片云标记显示'''
     tipCloud = [u'本地', u'云端']
     if c == 0:
         pathC = '../pics/watcher/cloudNO.png'
     else:
         pathC = '../pics/watcher/cloudYES.png'
     self.labelcloud = QtGui.QLabel(self)
     self.labelcloud.setPixmap(QtGui.QPixmap(pathC))
     self.labelcloud.setGeometry(_img.width()-150, _img.height()+14, 34, 21)
     self.labelcloud.setToolTip(tipCloud[c])
     
     '''显示照片评论'''
     self.comment = QtGui.QLabel(self)
     self.comment.setPixmap(QtGui.QPixmap('../pics/watcher/comment.png'))
     self.comment.setGeometry(_img.width()-50, _img.height()+12, 34, 29)
     if p:
         self.comment.setToolTip(u'评论:'+p)
     else:
         self.comment.setToolTip(u'尚未添加评论')
예제 #3
0
    def paintEvent(self, QPaintEvent):
        super(LabelerWindow, self).paintEvent(QPaintEvent)

        p = QtGui.QPainter(self)
        image = ImageQt(Image.fromarray(self.buffer))
        image = image.scaled(self.width(), self.height())
        p.drawImage(0, 0, image)

        # Now for the HUD

        # -> Draw green cross-hairs
        old_pen = p.pen()
        new_pen = QPen()
        new_pen.setColor(Qt.green)
        new_pen.setStyle(Qt.DotLine)
        new_pen.setWidth(1)
        p.setPen(new_pen)
        p.drawLine(0, self.height()/2, self.width(), self.height()/2)
        p.drawLine(self.width()/2, 0, self.width()/2, self.height())
        p.setPen(old_pen)

        # -> Show help for keystrokes
        help = "[X] Pos. [C] Neg. [UP] Zoom in [DN] Zoom Out [LT] Undo Last [RT] Ignore [LMB] Move "
        p.fillRect(0, 0, self.width(),  p.fontMetrics().height()*1.5, Qt.gray)
        p.drawText(0, p.fontMetrics().height(),  help)
예제 #4
0
    def paintEvent(self, QPaintEvent):
        super(LabelerWindow, self).paintEvent(QPaintEvent)

        p = QtGui.QPainter(self)
        image = ImageQt(Image.fromarray(self.buffer))
        image = image.scaled(self.width(), self.height())
        p.drawImage(0, 0, image)

        # Now for the HUD

        # -> Draw green cross-hairs
        old_pen = p.pen()
        new_pen = QPen()
        new_pen.setColor(Qt.green)
        new_pen.setStyle(Qt.DotLine)
        new_pen.setWidth(1)
        p.setPen(new_pen)
        p.drawLine(0, self.height() / 2, self.width(), self.height() / 2)
        p.drawLine(self.width() / 2, 0, self.width() / 2, self.height())
        p.setPen(old_pen)

        # -> Show help for keystrokes
        help = "[X] Pos. [C] Neg. [UP] Zoom in [DN] Zoom Out [LT] Undo Last [RT] Ignore [LMB] Move "
        p.fillRect(0, 0, self.width(), p.fontMetrics().height() * 1.5, Qt.gray)
        p.drawText(0, p.fontMetrics().height(), help)
예제 #5
0
 def winddir_rotation(self, x):
     im = Image.open('icons\\winddir.png')
     rot = im.rotate(-1 * self.winddirs[x] - 180,
                     resample=Image.BICUBIC,
                     expand=True)
     rot = rot.crop((0, 0, 128, 128))
     rot = ImageQt(rot)
     rot = QPixmap.fromImage(rot)
     rot = rot.scaled(64, 64)
     self.winddirimg.setPixmap(rot)
예제 #6
0
def slidepath_to_pximap(slidepath, icon_size: QSize):
    img_key = "{}_{}".format(slidepath, str(icon_size))
    icon_pixmap = QPixmapCache.find(img_key)
    if icon_pixmap is None:
        # pilimg: Image.Image = Image.open(slidepath)
        with openslide.open_slide(slidepath) as slide:
            pilimg = slide.get_thumbnail(
                (icon_size.width(), icon_size.height()))
            icon_image = QImage(icon_size, QImage.Format_RGB888)
            painter = QPainter(icon_image)
            painter.fillRect(icon_image.rect(), painter.background())
            img = ImageQt(pilimg)
            scaled_icon_image = img.scaled(icon_size, Qt.KeepAspectRatio)
            p = QPoint((icon_size.width() - scaled_icon_image.width()) / 2,
                       (icon_size.height() - scaled_icon_image.height()) / 2)
            painter.drawImage(p, scaled_icon_image)
            painter.end()
            icon_pixmap = QPixmap.fromImage(icon_image)
            QPixmapCache.insert(img_key, icon_pixmap)

    return icon_pixmap
예제 #7
0
    def update_pixmap(self):
        if self._img is None:
            self.setPixmap(self._pix_none)
        else:
            if self._transfo is None:
                img = self._img
            else:
                img = self._img.transpose(self._transfo)

            # find scale to fit screen
            w, h = img.size
            wa = self.width() / float(w)
            ha = self.height() / float(h)
            ratio = min(wa, ha)
            self._ratio = ratio

            # create Qt image
            iq = ImageQt(img)
            pix = QPixmap.fromImage(
                iq.scaled(int(w * ratio), int(h * ratio), Qt.IgnoreAspectRatio,
                          Qt.SmoothTransformation))

            self.setPixmap(pix)
예제 #8
0
    def print_report(self):
        if not self.validate_report_dates():
            return

        entries = self.model.get_records(
            self.view.report_date_from.date().toPython(),
            self.view.report_date_to.date().toPython(),
            self.view.comboBox.currentText(),
        )
        balance = self.model.get_balance(
            self.view.report_date_from.date().toPython(),
            self.view.report_date_to.date().toPython(),
        )
        if not self.create_pdf(self.model.pdf_file.name, entries, balance):
            return

        printer = QPrinter(QPrinter.HighResolution)
        dialog = QPrintDialog(printer)
        if dialog.exec_() != QPrintDialog.Accepted:
            return

        with TemporaryDirectory() as path:
            images = convert_from_path(self.model.pdf_file.name,
                                       dpi=300,
                                       output_folder=path)
            painter = QPainter()
            painter.begin(printer)
            for i, image in enumerate(images):
                if i > 0:
                    printer.newPage()
                rect = painter.viewport()
                qtImage = ImageQt(image)
                qtImageScaled = qtImage.scaled(rect.size(), Qt.KeepAspectRatio,
                                               Qt.SmoothTransformation)
                painter.drawImage(rect, qtImageScaled)
            painter.end()
예제 #9
0
class ImagePlayer(QWidget):
    def __init__(self, img_path, parent=None):
        super(ImagePlayer, self).__init__(parent)
        if __name__ == '__main__':
            self.setWindowTitle("Viewer")
            self.setGeometry(0, 0, 640, 480)
            self.main = QWidget()
        else:
            self.setGeometry(0, 0, parent.width(), parent.height())
            self.main = parent

        self.vue = QGraphicsView()
        self.vue.setDragMode(QGraphicsView.ScrollHandDrag)
        self.vue.wheelEvent = self.wheel_event

        self.statusBar = QStatusBar()
        self.statusBar.setFont(QFont("Noto Sans", 7))
        self.statusBar.setFixedHeight(14)

        self.verticalLayout = QVBoxLayout()
        self.verticalLayout.addWidget(self.vue)
        self.verticalLayout.addWidget(self.statusBar)

        self.setPixmapView(img_path)

        self.statusBar.showMessage(img_path)

        if __name__ == '__main__':
            self.image_btn = QToolButton()
            self.image_btn.setText("Image")
            self.image_btn.setObjectName("image_btn")
            self.image_btn.clicked.connect(self.get_image)
            self.verticalLayout.addWidget(self.image_btn)

            self.setLayout(self.verticalLayout)
            self.show()
        else:
            self.main.setLayout(self.verticalLayout)

    def get_image(self):
        img, _p = QFileDialog.getOpenFileName(
            self, "Ouvrir un fichier", QDir.homePath(),
            "All Files *.* ;; PNG *.png ;; JPG *.jpg ;; BMP *.bmp")
        if not img:
            with open("img.txt", "w") as file:
                file.write("not img")
            return
        self.setPixmapView(img)

    def setPixmapView(self, img_path):
        self.current_image = ImageQt(img_path)
        w, h = self.size().width(), self.size().height()
        self.pixmap = QPixmap.fromImage(
            self.current_image.scaled(w, h, Qt.KeepAspectRatio,
                                      Qt.FastTransformation))
        self.view_current()
        self.statusBar.showMessage(img_path)

    def view_current(self):
        w_pix, h_pix = self.pixmap.width(), self.pixmap.height()
        self.scene = QGraphicsScene()
        self.scene.setSceneRect(0, 0, w_pix, h_pix)
        self.scene.addPixmap(self.pixmap)
        self.vue.setScene(self.scene)

    def wheel_event(self, event):
        steps = event.angleDelta().y() / 120.0
        self.zoom(steps)
        event.accept()

    def zoom(self, step):
        w_pix, h_pix = self.pixmap.width(), self.pixmap.height()
        w, h = w_pix * (1 + 0.1 * step), h_pix * (1 + 0.1 * step)
        self.pixmap = QPixmap.fromImage(
            self.current_image.scaled(w, h, Qt.KeepAspectRatio,
                                      Qt.FastTransformation))
        self.view_current()
예제 #10
0
class ImageViewer:
    ''' Basic image viewer class to show an image with zoom and pan functionaities.
        Requirement: Qt's Qlabel widget name where the image will be drawn/displayed.
    '''
    def __init__(self, qlabel):
        self.qlabel_image = qlabel  # widget/window name where image is displayed (I'm usiing qlabel)
        self.qimage_scaled = QImage(
        )  # scaled image to fit to the size of qlabel_image
        self.qpixmap = QPixmap()  # qpixmap to fill the qlabel_image

        self.zoomX = 1  # zoom factor w.r.t size of qlabel_image
        self.position = [
            0, 0
        ]  # position of top left corner of qimage_label w.r.t. qimage_scaled
        self.panFlag = False  # to enable or disable pan

        self.qlabel_image.setSizePolicy(QtWidgets.QSizePolicy.Ignored,
                                        QtWidgets.QSizePolicy.Ignored)

    def loadImage(self, imagePath):
        ''' To load and display new image.'''
        self.qimage = QImage(imagePath)
        self.update_image()

    def loadImagePIL(self, image):
        self.qimage = ImageQt(image)
        self.update_image()

    def update_image(self):
        self.qpixmap = QPixmap(self.qlabel_image.size())
        if not self.qimage.isNull():
            # reset Zoom factor and Pan position
            self.zoomX = 1
            self.position = [0, 0]
            self.qimage_scaled = self.qimage.scaled(self.qlabel_image.width(),
                                                    self.qlabel_image.height(),
                                                    QtCore.Qt.KeepAspectRatio)
            self.update()

    def update(self):
        ''' This function actually draws the scaled image to the qlabel_image.
            It will be repeatedly called when zooming or panning.
            So, I tried to include only the necessary operations required just for these tasks. 
        '''
        if not self.qimage_scaled.isNull():
            # check if position is within limits to prevent unbounded panning.
            px, py = self.position
            px = px if (px <= self.qimage_scaled.width() -
                        self.qlabel_image.width()) else (
                            self.qimage_scaled.width() -
                            self.qlabel_image.width())
            py = py if (py <= self.qimage_scaled.height() -
                        self.qlabel_image.height()) else (
                            self.qimage_scaled.height() -
                            self.qlabel_image.height())
            px = px if (px >= 0) else 0
            py = py if (py >= 0) else 0
            self.position = (px, py)

            if self.zoomX == 1:
                self.qpixmap.fill(QtCore.Qt.white)

            # the act of painting the qpixamp
            painter = QPainter()
            painter.begin(self.qpixmap)
            painter.drawImage(
                QtCore.QPoint(0, 0), self.qimage_scaled,
                QtCore.QRect(self.position[0], self.position[1],
                             self.qlabel_image.width(),
                             self.qlabel_image.height()))
            painter.end()

            self.qlabel_image.setPixmap(self.qpixmap)
        else:
            pass