def get_screen_shot(self, antialias=False, rect=None): WIDTH, HEIGHT = self.get_screen_size() if rect: x, y, w, h = rect img = QPixmap.grabWindow(QApplication.desktop().winId(), x, y, w, h).toImage() WIDTH = w HEIGHT = h else: img = QPixmap.grabWindow( QApplication.desktop().winId()).toImage() # returns 32bits if self.HALFSIZE: length = (WIDTH / 2) * (HEIGHT / 2) * BPP ## note Qt.SmoothTransform only works on 32bit images if antialias: img = img.scaled(QSize(WIDTH / 2, HEIGHT / 2), transformMode=Qt.SmoothTransformation) else: img = img.scaled(QSize(WIDTH / 2, HEIGHT / 2)) #img = img.convertToFormat( img.Format_RGB888 ) # WRONG! return ctypes.string_at(int(img.bits()), length) else: length = WIDTH * HEIGHT * BPP return ctypes.string_at(int(img.bits()), length)
def fallback(self, var): """ Returns the fallback icon for a variable according to the iconpack's settings. @param var: the variable name @type var: str @return: the resulting pixmap @rtype: QPixmap """ if self.info == "default": return QPixmap() if (self.settings.has_option("options", "FALLBACK") and self.settings.getboolean("options", "FALLBACK")): try: with IconPack(info="default") as defpack: return defpack.icon(var) except: return QPixmap() elif (self.settings.has_option("options", "PLACEHOLDER") and self.settings.getint("options", "PLACEHOLDER") == 2): ret = QPixmap(32, 32) painter = QPainter(ret) painter.setPen(QPen(Qt.blue, 2)) painter.drawRect(0, 0, 128, 128) painter.delete() return ret else: return QPixmap()
def onTextMessageEvent(self, schid, targetMode, toID, fromID, fromName, fromUniqueIdentifier, message, ffIgnored): if self.status: (error, myid) = ts3.getClientID(schid) # get plain url from bbcode url # https://github.com/DerLuemmel/pyTSon_ts3_linkinfo/blob/master/__init__.py message = message.lower() if not myid == fromID and ("[url]" in message or "[url=" in message): start = message.find("[url]") if not start == -1: end = message.find("[/url]") message = message[start + 5:end] else: start = message.find("[url=") end = message.find("]") message = message[start + 5:end] # Open stream and read content type stream = urllib.request.urlopen(message) contenttype = stream.info().get_content_type() # if contenttype is png, gif, jpeg if contenttype in self.contenttypes: # get image data data = stream.read() # label and pixmap image = QLabel("image") pixmap = QPixmap() # load url data to pixmap pixmap.loadFromData(data) # set max width to self.imageMaxHeight pixmap = pixmap.scaledToHeight(self.imageMaxHeight, Qt.FastTransformation) # set image to label image.setPixmap(pixmap) # set margins for better looking image.setStyleSheet("QLabel{margin: 10px;}") # Get chatlayout chatlayout = self.getWidgetByObjectName("MainWindowChatWidget").layout() # Add image to chatlayout chatlayout.addWidget(image) # Deletes image label after self.showTime QTimer.singleShot(self.showTime, lambda : self.removeImage(chatlayout, image))
def updatePreview(self, uid, i): try: if uid in self.badges: lst = self.badges elif uid in self.extbadges: lst = self.extbadges else: print("UID", uid, "not internal or external"); return # (QPixmap::fromImage(image.scaled(200,200)) filename = "{}\\{}_details".format(self.icons, lst[uid]["filename"]) if i == 0: self.badge1.setPixmap(QPixmap(filename).scaled(60,60)) elif i == 1: self.badge2.setPixmap(QPixmap(filename).scaled(60,60)) elif i == 2: self.badge3.setPixmap(QPixmap(filename).scaled(60,60)) except: ts3lib.logMessage(format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "pyTSon", 0)
def _createBillboardWidgets(self): self.pixmap_label = QLabel() self.pixmap_label.size = QSize(512, 352) self.pixmap_label.scaledContents = True self.pixmap_label.setPixmap( QPixmap('./data/ui/images/comm/voiceindicator.png')) self._voiceBillboardWidget = self.pixmap_label
def flag(self, code): """ Returns a QPixmap containing the flag of the given country code if exist. @param code: the country code @type code: str @returns: the flag @rtype: QPixmap """ fname = "%s.png" % code.lower() if fname in self.zip.namelist(): with self.zip.open(fname) as f: ret = QPixmap() if ret.loadFromData(f.read()): return ret return QPixmap()
def icon(self, iconid): """ Returns an icon cached on disk. @param iconid: ID of the icon @type iconid: int @return: the icon @rtype: QPixmap """ return QPixmap(os.path.join(self.path, "icons", "icon_%s" % iconid))
def get_screen_shot( self, antialias=False, rect=None ): WIDTH,HEIGHT = self.get_screen_size() if rect: x,y,w,h = rect img = QPixmap.grabWindow(QApplication.desktop().winId(), x,y,w,h).toImage() WIDTH = w; HEIGHT = h else: img = QPixmap.grabWindow(QApplication.desktop().winId()).toImage() # returns 32bits if self.HALFSIZE: length = (WIDTH/2)*(HEIGHT/2)*BPP ## note Qt.SmoothTransform only works on 32bit images if antialias: img = img.scaled( QSize(WIDTH/2, HEIGHT/2), transformMode=Qt.SmoothTransformation ) else: img = img.scaled( QSize(WIDTH/2, HEIGHT/2) ) #img = img.convertToFormat( img.Format_RGB888 ) # WRONG! return ctypes.string_at( int(img.bits()), length ) else: length = WIDTH*HEIGHT*BPP return ctypes.string_at( int(img.bits()), length )
def emoticon(self, text): """ Returns the icon replacing the emoticon string. @param text: the emoticon as string @type text: str @return: the resulting pixmap @rtype: QPixmap """ if text in self.emos: empath = os.path.join("emoticons", self.emos[text]) if self.zip: if empath in self.cont.namelist(): with self.cont.open(empath) as f: ret = QPixmap() if ret.loadFromData(f.read()): return ret else: if os.path.isfile(os.path.join(self.path, empath)): return QPixmap(os.path.join(self.path, empath)) return QPixmap()
def updateBadges(self): items = [] self.badge1.clear() self.badge2.clear() self.badge3.clear() for i in range(self.lst_active.count): uid = self.lst_active.item(index).data(Qt.UserRole) items.append(uid) if i == 0: self.badge1.setPixmap( QPixmap("{}\\{}_details".format( self.icons, self.badges[uid]["filename"]))) elif i == 1: self.badge2.setPixmap( QPixmap("{}\\{}_details".format( self.icons, self.badges[uid]["filename"]))) elif i == 2: self.badge3.setPixmap( QPixmap("{}\\{}_details".format( self.icons, self.badges[uid]["filename"]))) self.cfg.set('general', 'badges', ','.join(items)) self.setCustomBadges()
def icon(self, var): """ Returns the icon representing a variable used in the iconpack. If the icon cannot be found, the iconpack's fallback mechanisms are used. If everything fails, an empty pixmap is returned. @param var: the variable name @type var: str @return: the resulting pixmap @rtype: QPixmap """ if self.info == "default": path = self._findDefaultFilename(self.defaultName(var)) if path == "": return QPixmap() else: if not self.settings.has_option("gfxfiles", var): return self.fallback(var) path = self.settings.get("gfxfiles", var) if path == "": return self.fallback(var) if self.zip: if path in self.cont.namelist(): with self.cont.open(path) as f: ret = QPixmap() if ret.loadFromData(f.read()): return ret else: return QPixmap() else: return self.fallback(var) else: if os.path.isfile(os.path.join(self.path, path)): return QPixmap(os.path.join(self.path, path)) else: return self.fallback(var)
def setupList(self): self.chk_overwolf.setChecked( True if self.cfg.getboolean('general', 'overwolf') else False) for badge in self.badges: self.lst_available.addItem(self.badgeItem(badge)) badges = self.cfg.get('general', 'badges').split(",") if len(badges) < 1: return i = 0 for badge in badges: if not badge: return i += 1 if i == 1: self.badge1.setPixmap( QPixmap("{}\\{}_details".format( self.icons, self.badges[badge]["filename"]))) elif i == 2: self.badge2.setPixmap( QPixmap("{}\\{}_details".format( self.icons, self.badges[badge]["filename"]))) elif i == 3: self.badge3.setPixmap( QPixmap("{}\\{}_details".format( self.icons, self.badges[badge]["filename"]))) self.lst_active.addItem(self.badgeItem(badge))
def testBillboard(self): avatar = naali.getUserAvatar() avatar_pos = avatar.GetComponentRaw("EC_Placeable") self.pixmap_label = QLabel() self.pixmap_label.size = QSize(200, 200) self.pixmap_label.scaledContents = True self.pixmap_label.setPixmap(QPixmap('./data/ui/images/naali_icon.png')) self.text_label = QLabel() self.text_label.size = QSize(300, 50) self.text_label.text = "Hello world" self.my_widget = QWidget() self.my_widget.setLayout(QVBoxLayout()) self.my_widget.layout().addWidget(self.pixmap_label) self.my_widget.layout().addWidget(self.text_label) if self.my_widget is None: print("Cannot find image file.") return self.my_entity = naali.createEntity() position = self.my_entity.GetOrCreateComponentRaw( "EC_Placeable", "pos", PythonQt.private.AttributeChange.Disconnected, False) position.position = avatar_pos.position self.ec_billboard = self.my_entity.GetOrCreateComponentRaw( "EC_BillboardWidget", "test", PythonQt.private.AttributeChange.Disconnected, False) if self.ec_billboard is None: print("Cannot create EC_Billboard component.") return self.ec_billboard.SetPosition(0, 0, 1) self.ec_billboard.SetWidth(1) self.ec_billboard.SetHeight(1) self.ec_billboard.SetWidget(self.my_widget) self.size_timer = QTimer() self.size_timer.connect("timeout()", self.animateSize) self.size_timer.start(100) self.text_timer = QTimer() self.text_timer.connect("timeout()", self.animateText) self.text_timer.start(1000)
def getButton(self, name, iconname, line, action): size = QSize(20, 20) button = buttons.PyPushButton() icon = QIcon(QPixmap(iconname).scaled(size)) button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) button.setMaximumSize(size) button.setMinimumSize(size) button.text = "" button.name = name button.setIcon(icon) button.setFlat(True) if action != None: button.connect('clicked()', action) if line != None: button.setEnabled(False) line.buttons.append(button) return button