def show(): message = "{0} {1} ".format(appinfo.appname, appinfo.version) pixmap = QPixmap(os.path.join(__path__[0], 'splash.png')) if QApplication.desktop().screenGeometry().height() < 640: fontsize = 23 pixmap = pixmap.scaledToHeight(240, Qt.SmoothTransformation) else: fontsize = 40 splash = QSplashScreen(pixmap, Qt.SplashScreen) font = splash.font() font.setPixelSize(fontsize) font.setWeight(QFont.Bold) splash.setFont(font) splash.showMessage(message, Qt.AlignRight | Qt.AlignTop, Qt.white) splash.show() splash.repaint() def hide(): splash.deleteLater() app.appStarted.disconnect(hide) app.appStarted.connect(hide)
class ResizableImage(QLabel): def __init__(self, filename, height, min_scale, max_scale): super(ResizableImage, self).__init__() self.setAlignment(Qt.AlignCenter) self.full_pixmap = None self.scaled_pixmap = None self.aspect = None self.set_file(filename) self.set_height(height) self.min_height = self.full_pixmap.height() * min_scale * self.aspect self.min_width = self.full_pixmap.width() * min_scale / self.aspect self.max_height = self.full_pixmap.height() * max_scale * self.aspect self.max_width = self.full_pixmap.width() * max_scale / self.aspect def set_file(self, filename): self.full_pixmap = QPixmap(filename) self.aspect = float(self.full_pixmap.height()) / self.full_pixmap.width() if self.scaled_pixmap is not None: self.set_height(self.scaled_pixmap.height()) def set_height(self, height): self.scaled_pixmap = self.full_pixmap.scaledToHeight(height, Qt.SmoothTransformation) self.setPixmap(self.scaled_pixmap) def set_width(self, width): self.scaled_pixmap = self.full_pixmap.scaledToWidth(width, Qt.SmoothTransformation) self.setPixmap(self.scaled_pixmap) def resizeEvent(self, ev): width, height = ev.size().width(), ev.size().height() label_aspect = height / width if label_aspect > self.aspect: self.set_width(min(max(.9 * width, self.min_width), self.max_width)) else: self.set_height(min(max(.9 * height, self.min_height), self.max_height))
def loadImage(self, data, scaled=True, fromfile=True): """ Load the image into the widget using a bytearray An empty picture will result in the default placeholder image. """ if data is None or not data: self.removeImage() return if fromfile: pix = QPixmap(data) elif isinstance(data, QPixmap): pix = data else: pix = QPixmap() r = pix.loadFromData(data, "JPG") if not r: pix = QPixmap(data) self._orignalimage = QPixmap(pix) h = self.maximumHeight() if scaled: pix = pix.scaledToHeight(h, Qt.SmoothTransformation) self.image.setPixmap(pix) self.isDefault = False
def loadImage(self, data, scaled=True, fromfile=True): """ Load the image into the widget using a bytearray An empty picture will result in the default placeholder image. """ if data is None or not data: self.removeImage() return if fromfile: pix = QPixmap(data) elif isinstance(data, QPixmap): pix = data else: pix = QPixmap() r = pix.loadFromData(data, 'JPG') if not r: pix = QPixmap(data) self._orignalimage = QPixmap(pix) h = self.maximumHeight() if scaled: pix = pix.scaledToHeight(h, Qt.SmoothTransformation) self.image.setPixmap(pix) self.isDefault = False
def album_cover_art(self, filepath): if not filepath == '': pic = QPixmap(filepath, '1') # no clue what the 1 means but without it, png files wont load pic = pic.scaledToHeight(self.widget.labelCoverArt.frameRect().height()) else: pic = QPixmap() self.widget.labelCoverArt.setPixmap(pic)
def album_cover_art(self, filepath): if not filepath == '': pic = QPixmap( filepath, '1' ) # no clue what the 1 means but without it, png files wont load pic = pic.scaledToHeight( self.widget.labelCoverArt.frameRect().height()) else: pic = QPixmap() self.widget.labelCoverArt.setPixmap(pic)
def __init__(self): super(MyQtApp, self).__init__() self.setup0(self) # self.showMaximized() self.setWindowTitle("Proses Digital Signature") self.btn_next.clicked.connect(self.next) button = self.btn_next button.setIcon(QtGui.QIcon("images/next-arrow.png")) button.setIconSize(QtCore.QSize(35,35)) image_digital_signature = QPixmap("images/digital-signature.png") image_signing = QPixmap("images/signing.jpg") image_verifying = QPixmap("images/verifying.jpg") label_digital_signature = self.label_digital_signature label_digital_signature.setPixmap(image_digital_signature.scaledToHeight(170)) label_signing = self.label_signing label_signing.setPixmap(image_signing.scaledToHeight(100)) label_verifying = self.label_verifying label_verifying.setPixmap(image_verifying.scaledToHeight(120))
def updateScreen(self, filename, xmlPath, x=0, y=0, w=0, h=0, reloadMode=False): """ Update the screen """ self.imagePath = filename if not reloadMode: self.tableModel.mylist = [] self.tableModel.beginResetModel() self.tableModel.endResetModel() pixmap = QPixmap(filename) if pixmap is not None: self.origWidth = pixmap.width() self.origHeight = pixmap.height() self.screenResolutionLabel.setText( "Resolution=%sx%s" % (self.origWidth, self.origHeight)) #portrait if self.origWidth < self.origHeight: pixmap = pixmap.scaledToHeight(Settings.getInt( 'MobileAndroid', 'resolution-screen-height'), mode=Qt.SmoothTransformation) self.mobileImageLabel.setPixmap(pixmap) else: pixmap = pixmap.scaledToWidth(Settings.getInt( 'MobileAndroid', 'resolution-screen-width'), mode=Qt.SmoothTransformation) self.mobileImageLabel.setPixmap(pixmap) self.drawRectangle(x=x, y=y, w=w, h=h) self.resize(pixmap.width(), pixmap.height()) # convert xml to dict if len(xmlPath): f = QFile(xmlPath) if f.open(QIODevice.ReadOnly): document = QDomDocument() if document.setContent(f): newModel = DomModel(document, self) self.mobileTreeView.setModel(newModel) self.mobileTreeView.expandAll() self.mobileTreeView.resizeColumnToContents(0) f.close()
def _welcome_window(self): widget = QLabel(self) pm = QPixmap(':icons/glue_welcome.png') pm = pm.scaledToHeight(400, mode=Qt.SmoothTransformation) widget.setPixmap(pm) widget.show() widget.resize(pm.size()) sub = self._add_to_current_tab(widget, label='Getting Started') def do_close(win): sub.close() self.current_tab.subWindowActivated.connect(do_close)
def paint(self, painter, option, index): filePath = self.model.filePath(index) fileName = self.model.fileName(index) r = option.rect img = QPixmap(filePath) if img.isNull(): # If not image file, try to load icon with QFileIconProvider # according to file type (extension name). # Currently not work as intended. fileInfo = self.model.fileInfo(index) icon = QFileIconProvider().icon(fileInfo) img = icon.pixmap(QSize(32, 32)) # Scale to height, align center horizontally, align bottom vertically. if img.height() > self.thumbHeight: img = img.scaledToHeight(self.thumbHeight, Qt.SmoothTransformation) if img.width() > self.thumbHeight: img = img.scaledToWidth(self.thumbHeight, Qt.SmoothTransformation) imgLeft = (self.width - img.width()) / 2 imgTop = self.thumbHeight - img.height() painter.drawPixmap(r.left() + imgLeft, r.top() + imgTop, img) rect = QRect(r.left(), r.top() + self.thumbHeight, self.width, self.nameHeight) flag = Qt.AlignHCenter | Qt.TextWrapAnywhere # get the bounding rectangle of the fileName bdRect = painter.boundingRect(rect, flag, fileName) if bdRect.height() < rect.height(): rect = bdRect if option.state & QStyle.State_Selected: painter.setBrush(self.parent().palette().highlight()) painter.drawRoundedRect(rect, 5, 5) pen = QPen(self.parent().palette().highlightedText(), 1, Qt.SolidLine) else: pen = QPen(self.parent().palette().text(), 1, Qt.SolidLine) painter.setPen(pen) painter.drawText(rect, flag, fileName)
def paint(self, painter, option, index): filePath = self.model.filePath(index) fileName = self.model.fileName(index) r = option.rect img = QPixmap(filePath) if img.isNull(): # If not image file, try to load icon with QFileIconProvider # according to file type (extension name). # Currently not work as intended. fileInfo = self.model.fileInfo(index) icon = QFileIconProvider().icon(fileInfo) img = icon.pixmap(QSize(32, 32)) # Scale to height, align center horizontally, align bottom vertically. if img.height() > self.thumbHeight: img = img.scaledToHeight(self.thumbHeight, Qt.SmoothTransformation) if img.width() > self.thumbHeight: img = img.scaledToWidth(self.thumbHeight, Qt.SmoothTransformation) imgLeft = (self.width - img.width()) / 2 imgTop = self.thumbHeight - img.height() painter.drawPixmap(r.left()+imgLeft, r.top()+imgTop, img) rect = QRect(r.left(), r.top()+self.thumbHeight, self.width, self.nameHeight) flag = Qt.AlignHCenter | Qt.TextWrapAnywhere # get the bounding rectangle of the fileName bdRect = painter.boundingRect(rect, flag, fileName) if bdRect.height() < rect.height(): rect = bdRect if option.state & QStyle.State_Selected: painter.setBrush(self.parent().palette().highlight()) painter.drawRoundedRect(rect, 5, 5) pen = QPen(self.parent().palette().highlightedText(), 1, Qt.SolidLine) else: pen = QPen(self.parent().palette().text(), 1, Qt.SolidLine) painter.setPen(pen) painter.drawText(rect, flag, fileName)
def show(): message = "{0} {1} ".format(info.appname, info.version) pixmap = QPixmap(os.path.join(__path__[0], 'splash.png')) if QApplication.desktop().screenGeometry().height() < 640: fontsize = 23 pixmap = pixmap.scaledToHeight(240, Qt.SmoothTransformation) else: fontsize = 40 splash = QSplashScreen(pixmap, Qt.SplashScreen | Qt.WindowStaysOnTopHint) font = splash.font() font.setPixelSize(fontsize) font.setWeight(QFont.Bold) splash.setFont(font) splash.showMessage(message, Qt.AlignRight | Qt.AlignTop, Qt.white) splash.show() app.qApp.processEvents() splash.deleteLater()
def loadImage(self, data, scaled=True): """ Load the image into the widget using a bytearray An empty picture will result in the default placeholder image. """ if data is None or not data: self.removeImage() return pix = QPixmap() r = pix.loadFromData(data, 'JPG') if not r: pix = QPixmap(data) h = self.maximumHeight() if scaled: pix = pix.scaledToHeight(h, Qt.SmoothTransformation) self.image.setPixmap(pix) self.isDefault = False
def _add_file(self, fileinfo): '''docstring for _add_file''' thumb_size = 100 max_length_filename = thumb_size/9 path = fileinfo.filePath() px = QPixmap( path ) if px.size().isNull(): return filename = fileinfo.fileName() size = fileinfo.size() size_str = human( size ) if len(filename) > max_length_filename: filename = '%s...%s'%( filename[0:max_length_filename/2 ], filename[-max_length_filename/2:], ) else: filename = '%s'%( filename, ) text_item ="%(name)s \n [%(size)s]"%{'size': size_str, 'name':filename } icon = QIcon() icon.addPixmap( px.scaledToHeight( thumb_size ) ) data = { QString('path'): path , QString('size'): size, QString('human_size'): size_str, QString('fileinfo'):fileinfo, } item = QtGui.QListWidgetItem( icon, text_item, self.upload_list ) item.setData( QtCore.Qt.UserRole,QtCore.QVariant( data ) ) item.setToolTip( path) item.setSizeHint( QtCore.QSize( thumb_size+23,thumb_size+46) )
class AboutWidget(QWidget): """ Common About Dialog for the Freeseer Project. This should be used for the about dialog when including one in GUIs. Layout: Logo | About Infos | Buttons """ def __init__(self, parent=None): QWidget.__init__(self, parent) self.current_language = "en_US" self.uiTranslator = QTranslator() self.uiTranslator.load(":/languages/tr_en_US.qm") self.fontSize = self.font().pixelSize() self.fontUnit = "px" if self.fontSize == -1: # Font is set as points, not pixels. self.fontUnit = "pt" self.fontSize = self.font().pointSize() icon = QIcon() self.logoPixmap = QPixmap(_fromUtf8(":/freeseer/logo.png")) icon.addPixmap(self.logoPixmap, QIcon.Normal, QIcon.Off) self.setWindowIcon(icon) self.mainLayout = QGridLayout() self.setLayout(self.mainLayout) # Logo self.logo = QLabel("Logo") # To offset the logo so that it's to the right of the title self.logo.setStyleSheet("QLabel {{ margin-left: {} {} }}".format( 90 + (self.fontSize * 2.5), self.fontUnit)) self.logo.setPixmap(self.logoPixmap.scaledToHeight(80)) self.mainLayout.addWidget(self.logo, 0, 0, Qt.AlignTop) # Info self.aboutInfo = QLabel("About Info", openExternalLinks=True) self.aboutInfo.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.aboutInfo.setWordWrap(True) self.mainLayout.addWidget(self.aboutInfo, 0, 0) # Buttons self.buttonsLayout = QHBoxLayout() self.issueButton = QPushButton("Report an issue") self.docsButton = QPushButton("Freeseer documentation") self.contactButton = QPushButton("Contact us") self.buttonsLayout.insertWidget(0, self.docsButton) self.buttonsLayout.insertWidget(1, self.issueButton) self.buttonsLayout.insertWidget(2, self.contactButton) self.mainLayout.addLayout(self.buttonsLayout, 2, 0) self.connect(self.docsButton, SIGNAL('clicked()'), self.openDocsUrl) self.connect(self.issueButton, SIGNAL('clicked()'), self.openNewIssueUrl) self.connect(self.contactButton, SIGNAL('clicked()'), self.openContactUrl) self.retranslate() def retranslate(self, language=None): if language is not None: self.current_language = language self.uiTranslator.load(":/languages/tr_%s.qm" % self.current_language) # # Main Text # self.descriptionString = self.uiTranslator.translate( "AboutDialog", "Freeseer is a video capture utility capable of capturing presentations. It captures " "video sources such as usb, firewire, or local desktop along with audio and mixes them " "together to produce a video.") self.copyrightString = self.uiTranslator.translate( "AboutDialog", 'Copyright (C) 2014 The Free and ' 'Open Source Software Learning Centre') self.licenseTextString = self.uiTranslator.translate( "AboutDialog", "Freeseer is licensed under the GPL " "version 3. This software is provided 'as-is',without any express or implied warranty. In " "no event will the authors be held liable for any damages arising from the use of this software." ) self.aboutInfoString = u'<h1>' + NAME.capitalize() + u'</h1>' + \ u'<br><b>' + self.uiTranslator.translate("AboutDialog", "Version") + \ ": " + __version__ + u'</b>' + \ u'<p>' + self.descriptionString + u'</p>' + \ u'<p>' + self.copyrightString + u'</p>' + \ u'<p><a href="' + URL + u'">' + URL + u'</a></p>' \ u'<p>' + self.licenseTextString + u'</p>' \ u'<p>' + self.uiTranslator.translate("AboutDialog", "Record button graphics by") + \ u': <a href="' + RECORD_BUTTON_LINK + u'">' + RECORD_BUTTON_ARTIST + u'</a></p>' \ u'<p>' + self.uiTranslator.translate("AboutDialog", "Headphones graphics by") + \ u': <a href="' + HEADPHONES_LINK + u'">' + HEADPHONES_ARTIST + u'</a></p><br>' self.aboutInfo.setText(self.aboutInfoString) # --- End Main Text def openDocsUrl(self): """Opens a link to the Freeseer online documentation""" url = QUrl("http://freeseer.readthedocs.org") QDesktopServices.openUrl(url) def openNewIssueUrl(self): """Opens a link to the Freeseer new issue page""" url = QUrl("https://github.com/Freeseer/freeseer/issues/new") QDesktopServices.openUrl(url) def openContactUrl(self): """Opens a link to Freeseer's contact information""" url = QUrl("http://freeseer.readthedocs.org/en/latest/contact.html") QDesktopServices.openUrl(url)
class AboutWidget(QWidgetWithDpi): """ Common About Dialog for the Freeseer Project. This should be used for the about dialog when including one in GUIs. Layout: Logo | About Infos | Buttons """ def __init__(self, parent=None): super(AboutWidget, self).__init__(parent) self.current_language = "en_US" self.uiTranslator = QTranslator() self.uiTranslator.load(":/languages/tr_en_US.qm") self.fontSize = self.font().pixelSize() self.fontUnit = "px" if self.fontSize == -1: # Font is set as points, not pixels. self.fontUnit = "pt" self.fontSize = self.font().pointSize() icon = QIcon() self.logoPixmap = QPixmap(_fromUtf8(":/freeseer/logo.png")) icon.addPixmap(self.logoPixmap, QIcon.Normal, QIcon.Off) self.setWindowIcon(icon) self.mainLayout = QGridLayout() self.setLayout(self.mainLayout) # Logo self.logo = QLabel("Logo") # To offset the logo so that it's to the right of the title self.logo.setStyleSheet("QLabel {{ margin-left: {} {} }}" .format(self.set_width_with_dpi(90) + (self.fontSize * 2.5), self.fontUnit)) self.logo.setPixmap(self.logoPixmap.scaledToHeight(self.set_height_with_dpi(80))) self.mainLayout.addWidget(self.logo, 0, 0, Qt.AlignTop) # Info self.aboutInfo = QLabel("About Info", openExternalLinks=True) self.aboutInfo.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.aboutInfo.setWordWrap(True) self.mainLayout.addWidget(self.aboutInfo, 0, 0) # Buttons self.buttonsLayout = QHBoxLayout() self.issueButton = QPushButton("Report an issue") self.docsButton = QPushButton("Freeseer documentation") self.contactButton = QPushButton("Contact us") self.buttonsLayout.insertWidget(0, self.docsButton) self.buttonsLayout.insertWidget(1, self.issueButton) self.buttonsLayout.insertWidget(2, self.contactButton) self.mainLayout.addLayout(self.buttonsLayout, 2, 0) self.connect(self.docsButton, SIGNAL('clicked()'), self.openDocsUrl) self.connect(self.issueButton, SIGNAL('clicked()'), self.openNewIssueUrl) self.connect(self.contactButton, SIGNAL('clicked()'), self.openContactUrl) self.retranslate() def retranslate(self, language=None): if language is not None: self.current_language = language self.uiTranslator.load(":/languages/tr_%s.qm" % self.current_language) # # Main Text # self.descriptionString = self.uiTranslator.translate("AboutDialog", "Freeseer is a video capture utility capable of capturing presentations. It captures " "video sources such as usb, firewire, or local desktop along with audio and mixes them " "together to produce a video.") self.copyrightString = self.uiTranslator.translate("AboutDialog", 'Copyright (C) 2014 The Free and ' 'Open Source Software Learning Centre') self.licenseTextString = self.uiTranslator.translate("AboutDialog", "Freeseer is licensed under the GPL " "version 3. This software is provided 'as-is',without any express or implied warranty. In " "no event will the authors be held liable for any damages arising from the use of this software.") self.aboutInfoString = u'<h1>' + NAME.capitalize() + u'</h1>' + \ u'<br><b>' + self.uiTranslator.translate("AboutDialog", "Version") + \ ": " + __version__ + u'</b>' + \ u'<p>' + self.descriptionString + u'</p>' + \ u'<p>' + self.copyrightString + u'</p>' + \ u'<p><a href="' + URL + u'">' + URL + u'</a></p>' \ u'<p>' + self.licenseTextString + u'</p>' \ u'<p>' + self.uiTranslator.translate("AboutDialog", "Record button graphics by") + \ u': <a href="' + RECORD_BUTTON_LINK + u'">' + RECORD_BUTTON_ARTIST + u'</a></p>' \ u'<p>' + self.uiTranslator.translate("AboutDialog", "Headphones graphics by") + \ u': <a href="' + HEADPHONES_LINK + u'">' + HEADPHONES_ARTIST + u'</a></p><br>' self.aboutInfo.setText(self.aboutInfoString) # --- End Main Text def openDocsUrl(self): """Opens a link to the Freeseer online documentation""" url = QUrl("http://freeseer.readthedocs.org") QDesktopServices.openUrl(url) def openNewIssueUrl(self): """Opens a link to the Freeseer new issue page""" url = QUrl("https://github.com/Freeseer/freeseer/issues/new") QDesktopServices.openUrl(url) def openContactUrl(self): """Opens a link to Freeseer's contact information""" url = QUrl("http://freeseer.readthedocs.org/en/latest/contact.html") QDesktopServices.openUrl(url)
def setIcon(self, path): pix = QPixmap(path) pix = pix.scaledToHeight(200, Qt.SmoothTransformation) self.icon.setPixmap(pix)
class View(QGraphicsView): fitModes = {'view_fitBest', 'view_fitWidth', 'view_fitHeight', 'view_fitSize'} def __init__(self, fileName, fitMode): super().__init__() self.setFrameShape(QFrame.NoFrame) self.fitMode = fitMode self.setBackgroundBrush(QBrush(QColor(Config.backgroundColor))) self.openFile(fileName) def openFile(self, fileName): self.oshiri = Oshiri(fileName, 'r') self.loadFonts() self.page = 0 self.display(self.oshiri.index[self.page]) def display(self, page): scene = QGraphicsScene() self.setScene(scene) self.originalImage = QPixmap() self.originalImage.loadFromData(self.oshiri.getImage(page['image'])) self.image = self.scene().addPixmap(self.originalImage) self.contents = page['contents'] self.elements = [] for item in page['contents']: shape = item['style'].get('shape', 'rectangle') shapeArgs = (item, self.image.pixmap().width(), self.image.pixmap().height()) if shape == 'ellipse': newItem = shapes.Ellipse(*shapeArgs) elif shape == 'rectangle': newItem = shapes.Rectangle(*shapeArgs) self.elements.append(newItem) self.scene().addItem(newItem) self.updateView() def resizeEvent(self, sizes): super().resizeEvent(sizes) self.updateView() def setFitMode(self, mode): self.fitMode = mode self.updateView() if self.fitMode == 'view_fitWidth': self.centerOn(0, 0) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) else: self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) Config.checkedActions ^= __class__.fitModes Config.checkedActions.add(self.fitMode) def scaleImage(self): self.scaledImage = self.originalImage if self.fitMode != 'view_fitSize': self.scaledImage = { 'view_fitBest': self.originalImage.scaled(self.width(), self.height(), Qt.KeepAspectRatio, Qt.SmoothTransformation), 'view_fitWidth': self.originalImage.scaledToWidth(self.width(), Qt.SmoothTransformation), 'view_fitHeight': self.originalImage.scaledToHeight(self.height(), Qt.SmoothTransformation) }[self.fitMode] self.image.setPixmap(self.scaledImage) self.imageWidth = self.image.pixmap().width() self.imageHeight = self.image.pixmap().height() def updateView(self): self.scaleImage() self.scene().setSceneRect(0, 0, self.imageWidth, self.imageHeight) for element in self.elements: element.resize(self.imageWidth, self.imageHeight) def loadFonts(self): for font in self.oshiri.getFonts(): QFontDatabase().addApplicationFontFromData(font) def previousPage(self): if self.page > 0: self.page -= 1 self.display(self.oshiri.index[self.page]) def nextPage(self): if self.page < len(self.oshiri.index) - 1: self.page += 1 self.display(self.oshiri.index[self.page])