def reply_finished(self, reply): url = reply.url() print 'URL Downloaded:', str(url.toEncoded()) if reply.error(): error_message = str(reply.errorString()) print 'Download of %s failed: %s' % (url.toEncoded(), error_message) else: # print 'Mime-type:', str(reply.header(QNetworkRequest.ContentTypeHeader).toString()) data = reply.readAll() attribute = reply.request().attribute(QNetworkRequest.User) if not attribute.isNull(): request_type, request_metadata = attribute.toPyObject() if request_type == 0: # Daily wallpaper XML. self.parse_daily_xml(data, True) elif request_type == 1: start_date, copyright_info = request_metadata wallpaper_image = QImage.fromData(data) self.download_finished.emit(wallpaper_image, start_date, copyright_info) if request_type == 3: # History thumbnails. day_index = request_metadata self.parse_daily_xml(data, False, day_index) elif request_type == 4: image_date, copyright_info, image_day_index = request_metadata wallpaper_image = QImage.fromData(data) self.thumbnail_download_finished.emit(wallpaper_image, image_date, copyright_info, image_day_index)
def gotThumbnail(self): if not empty(self.recipe.thumbnail_url): data = urllib.urlopen(self.recipe.thumbnail_url).read() img = QImage.fromData(data) self.ui.imageLabel.setPixmap( QPixmap.fromImage(img).scaledToHeight(100, Qt.SmoothTransformation))
def gotThumbnail(self, backend, video): if not backend: return if video.thumbnail and video.thumbnail.data: img = QImage.fromData(video.thumbnail.data) self.ui.imageLabel.setPixmap(QPixmap.fromImage(img))
def gotThumbnail(self): if empty(self.movie.thumbnail_url) and self.movie.thumbnail_url != NotAvailable: self.backend.fill_movie(self.movie, ('thumbnail_url')) if not empty(self.movie.thumbnail_url): data = urllib.urlopen(self.movie.thumbnail_url).read() img = QImage.fromData(data) self.ui.imageLabel.setPixmap(QPixmap.fromImage(img).scaledToHeight(100,Qt.SmoothTransformation))
def gotThumbnail(self, backend, video): if not backend: return if video.thumbnail and video.thumbnail.data: img = QImage.fromData(video.thumbnail.data) self.ui.imageLabel.setPixmap(QPixmap.fromImage(img))
def display_photo(self): if self.displayed_photo_idx >= len(self.contact.photos): self.displayed_photo_idx = len(self.contact.photos) - 1 if self.displayed_photo_idx < 0: self.ui.photoUrlLabel.setText('') return photo = self.contact.photos.values()[self.displayed_photo_idx] if photo.data: data = photo.data if photo.id in self.process_photo: self.process_photo.pop(photo.id) else: self.process_photo[photo.id] = QtDo(self.weboob, lambda b,p: self.display_photo()) self.process_photo[photo.id].do('fillobj', photo, ['data'], backends=self.contact.backend) if photo.thumbnail_data: data = photo.thumbnail_data else: return img = QImage.fromData(data) img = img.scaledToWidth(self.width()/3) self.ui.photoLabel.setPixmap(QPixmap.fromImage(img)) if photo.url is not NotLoaded: text = '<a href="%s">%s</a>' % (photo.url, photo.url) if photo.hidden: text += '<br /><font color=#ff0000><i>(Hidden photo)</i></font>' self.ui.photoUrlLabel.setText(text)
def gotThumbnail(self): if empty(self.movie.thumbnail_url) and self.movie.thumbnail_url != NotAvailable: self.backend.fill_movie(self.movie, ('thumbnail_url')) if not empty(self.movie.thumbnail_url): data = urllib.urlopen(self.movie.thumbnail_url).read() img = QImage.fromData(data) self.ui.imageLabel.setPixmap(QPixmap.fromImage(img).scaledToHeight(100,Qt.SmoothTransformation))
def display_photo(self): if not self.housing.photos: self.ui.photosFrame.hide() return if self.displayed_photo_idx >= len(self.housing.photos): self.displayed_photo_idx = len(self.housing.photos) - 1 if self.displayed_photo_idx < 0: self.ui.photosFrame.hide() return self.ui.photosFrame.show() photo = self.housing.photos[self.displayed_photo_idx] if photo.data: data = photo.data if photo.id in self.process_photo: self.process_photo.pop(photo.id) else: self.process_photo[photo.id] = QtDo(self.weboob, lambda b,p: self.display_photo()) self.process_photo[photo.id].do('fillobj', photo, ['data'], backends=self.housing.backend) return img = QImage.fromData(data) img = img.scaledToWidth(self.width()/3) self.ui.photoLabel.setPixmap(QPixmap.fromImage(img)) if photo.url is not NotLoaded: text = '<a href="%s">%s</a>' % (photo.url, photo.url) self.ui.photoUrlLabel.setText(text)
def get_favicon(self): """ Get favicon for the site. This is called when the site_url can't be loaded or when that page doesn't contain a link tag with rel set to icon (the new way of doing site icons.) """ if self.site_icon: return if not with_pyqt: self.site_icon = None return ico_url = urlparse.urljoin(self.icon_url, "/favicon.ico") ico_request = urllib2.Request(ico_url) if self.user_agent: ico_request.add_header('User-agent', self.user_agent) ico_response = urllib2.urlopen(ico_request) if 200 != ico_response.code: self.site_icon = None return self.site_icon = QImage.fromData(ico_response.read()) max_size = QSize(self.max_icon_size, self.max_icon_size) ico_size = self.site_icon.size() if ico_size.width() > max_size.width() \ or ico_size.height() > max_size.height(): self.site_icon = self.site_icon.scaled( max_size, Qt.KeepAspectRatio, Qt.SmoothTransformation)
def gotThumbnail(self): if self.recipe.picture_url and not empty(self.recipe.picture_url): data = urllib.urlopen(self.recipe.picture_url).read() img = QImage.fromData(data) self.ui.imageLabel.setPixmap( QPixmap.fromImage(img).scaledToWidth(250, Qt.SmoothTransformation))
def startScanning(self): if self.comboDevice.count()==0: return self.scanner.setSelectedColor(self.comboColor.currentIndex()) self.scanner.setSelectedResolution(self.comboResolution.currentIndex()) self.scanner.setSelectedScanArea(self.comboArea.currentIndex()) ext = self.scanner.extension args = self.scanner.getArgs() self.statusbar.showMessage("Scan Started") wait(20) self.process.start('scanimage', args) if not self.process.waitForFinished(-1) or self.process.exitCode(): self.statusbar.showMessage("Scanning Failed !") return data = self.process.readAllStandardOutput() filename = self.filenameEdit.text() + ext # to get more accurate scanned area when A4 at 300 dpi if (self.scanner.crop_needed): image = QImage.fromData(data) image = image.copy(self.scanner.crop_rect) image.save(filename) else: img_file = QFile(filename, self) img_file.open(QIODevice.WriteOnly) img_file.write(data) img_file.close() data.clear() self.statusbar.showMessage("Scan Completed Successfully") self.filenameEdit.setText(self.newFileName())
def QImage_from_Image(image): """ Convert an Enaml Image into a QImage. Parameters ---------- image : Image The Enaml Image object. Returns ------- result : QImage The QImage instance for the given Enaml image. """ format = image.format if format == 'auto': format = '' qimage = QImage.fromData(image.data, format) if -1 not in image.size and not qimage.isNull(): qsize = QSize(*image.size) if qsize != qimage.size(): mode = ASPECT_RATIO_MODE[image.aspect_ratio_mode] transform = TRANSFORM_MODE[image.transform_mode] qimage = qimage.scaled(qsize, mode, transform) return qimage
def QImage_from_Image(image): """ Convert an Enaml Image into a QImage. Parameters ---------- image : Image The Enaml Image object. Returns ------- result : QImage The QImage instance for the given Enaml image. """ format = image.format if format == 'auto': format = '' qimage = QImage.fromData(image.data, format) if -1 not in image.size and not qimage.isNull(): qsize = QSize(*image.size) if qsize != qimage.size(): mode = ASPECT_RATIO_MODE[image.aspect_ratio_mode] transform = TRANSFORM_MODE[image.transform_mode] qimage = qimage.scaled(qsize, mode, transform) return qimage
def get_favicon(self): """ Get favicon for the site. This is called when the site_url can't be loaded or when that page doesn't contain a link tag with rel set to icon (the new way of doing site icons.) """ if self.site_icon: return if not with_pyqt: self.site_icon = None return ico_url = urlparse.urljoin(self.icon_url, "/favicon.ico") ico_request = urllib2.Request(ico_url) if self.user_agent: ico_request.add_header('User-agent', self.user_agent) ico_response = urllib2.urlopen(ico_request) if 200 != ico_response.code: self.site_icon = None return self.site_icon = QImage.fromData(ico_response.read()) max_size = QSize(self.max_icon_size, self.max_icon_size) ico_size = self.site_icon.size() if ico_size.width() > max_size.width() \ or ico_size.height() > max_size.height(): self.site_icon = self.site_icon.scaled( max_size, Qt.KeepAspectRatio, Qt.SmoothTransformation)
def display_photo(self): if not self.housing.photos: self.ui.photosFrame.hide() return if self.displayed_photo_idx >= len(self.housing.photos): self.displayed_photo_idx = len(self.housing.photos) - 1 if self.displayed_photo_idx < 0: self.ui.photosFrame.hide() return self.ui.photosFrame.show() photo = self.housing.photos[self.displayed_photo_idx] if photo.data: data = photo.data if photo.id in self.process_photo: self.process_photo.pop(photo.id) else: self.process_photo[photo.id] = QtDo(self.weboob, lambda b,p: self.display_photo()) self.process_photo[photo.id].do('fillobj', photo, ['data'], backends=self.housing.backend) return img = QImage.fromData(data) img = img.scaledToWidth(self.width()/3) self.ui.photoLabel.setPixmap(QPixmap.fromImage(img)) if photo.url is not NotLoaded: text = '<a href="%s">%s</a>' % (photo.url, photo.url) self.ui.photoUrlLabel.setText(text)
def display_photo(self): if self.displayed_photo_idx >= len(self.contact.photos): self.displayed_photo_idx = len(self.contact.photos) - 1 if self.displayed_photo_idx < 0: self.ui.photoUrlLabel.setText('') return photo = self.contact.photos.values()[self.displayed_photo_idx] if photo.data: data = photo.data if photo.id in self.process_photo: self.process_photo.pop(photo.id) else: self.process_photo[photo.id] = QtDo( self.weboob, lambda b, p: self.display_photo()) self.process_photo[photo.id].do('fillobj', photo, ['data'], backends=self.contact.backend) if photo.thumbnail_data: data = photo.thumbnail_data else: return img = QImage.fromData(data) img = img.scaledToWidth(self.width() / 3) self.ui.photoLabel.setPixmap(QPixmap.fromImage(img)) if photo.url is not NotLoaded: text = '<a href="%s">%s</a>' % (photo.url, photo.url) if photo.hidden: text += '<br /><font color=#ff0000><i>(Hidden photo)</i></font>' self.ui.photoUrlLabel.setText(text)
def updateAvatar(self, avatarData): image = QImage.fromData(avatarData) pixmap = QPixmap.fromImage(image) if pixmap.isNull(): return False scaledAvatar = pixmap.scaled(32, 32) self.avatarLabel.setPixmap(scaledAvatar) return True
def updateAvatar(self, avatarData): image = QImage.fromData(avatarData) pixmap = QPixmap.fromImage(image) if pixmap.isNull(): return False scaledAvatar = pixmap.scaled(32, 32) self.avatarLabel.setPixmap(scaledAvatar) return True
def get_new_image(self): """ Descript. : reads new image, flips it if necessary and returns the result or None on error """ image = self.http_get("?action=snapshot") if image is not None: return QImage.fromData(image).mirrored(self.flip["h"], self.flip["v"]) return None
def parse_thumbnail(self, resp, image_path): image = QImage.fromData(resp.read()) if image.isNull(): self.logger.warning("Failed to generate image from raw data for", image_path) self.tree_controller.thumbs[image_path] = None # So we dont come here again return pixmap = QPixmap.fromImage(image) self.tree_controller.thumbs[image_path] = pixmap self.tree_controller.update_thumbnail(True, pixmap)
def _getWebFavIcon(url): from favicon import find_favicon_from_url import requests shortcutURL = find_favicon_from_url(url) if shortcutURL is not None: r = requests.get(shortcutURL) return QIcon(QPixmap.fromImage(QImage.fromData(r.content))) else: return None
def updateAvatar(self, avatarData): image = QImage.fromData(avatarData) pixmap = QPixmap.fromImage(image) if pixmap.isNull(): return False scaledAvatar = pixmap.scaled(32, 32) try: self.avatarLabel.setPixmap(scaledAvatar) return True except Exception as ex: # logging.warn("Updating a deleted chat item") self.avatarLabel = None self = None
def _createThumbnail(self, inFile, inPath, inURL, inImage, category): """Called asynchronously""" try: fileName = None # if category already has a thumbnail, overwrite curPath = self._storage.getCategoryThumbnail(category) if curPath is not None: try: # check if we can write the file open(curPath, 'wb').close() fileName = curPath except: pass if fileName is None: outFile = self._createPictureFile(category) fileName = outFile.name outFile.close() oldImage = None imageData = None if inImage: oldImage = inImage elif inFile: imageData = inFile.read() elif inPath and os.path.exists(inPath): with contextlib.closing(open(inPath, 'rb')) as inFile: imageData = inFile.read() else: imageData = urllib2.urlopen(inURL.encode('utf-8')).read() if oldImage is None: oldImage = QImage.fromData(imageData) if oldImage.width() > CategoriesModel.MAX_THUMBNAIL_SIZE or oldImage.height() > CategoriesModel.MAX_THUMBNAIL_SIZE: newImage = oldImage.scaled(CategoriesModel.MAX_THUMBNAIL_SIZE, CategoriesModel.MAX_THUMBNAIL_SIZE, Qt.KeepAspectRatio, Qt.SmoothTransformation) else: # no up-scaling here newImage = oldImage newImage.save(fileName, 'jpeg') return fileName, inFile, category except: self.logger.exception("Error trying to create thumbnail for category") return None, inFile, category
def maybe_get_icon(self): u""" Get icon for the site as a QImage if we haven’t already. Get the site icon, either the 'rel="icon"' or the favicon, for the web page at url or passed in as page_html and store it as a QImage. This function can be called repeatedly and loads the icon only once. """ if self.site_icon: return if not with_pyqt: self.site_icon = None return page_request = urllib2.Request(self.icon_url) if self.user_agent: page_request.add_header('User-agent', self.user_agent) page_response = urllib2.urlopen(page_request) if 200 != page_response.code: self.get_favicon() return page_soup = soup(page_response) try: icon_url = page_soup.find(name='link', attrs={'rel': 'icon'})['href'] except (TypeError, KeyError): self.get_favicon() return # The url may be absolute or relative. if not urlparse.urlsplit(icon_url).netloc: icon_url = urlparse.urljoin(self.url, urllib.quote(icon_url.encode('utf-8'))) icon_request = urllib2.Request(icon_url) if self.user_agent: icon_request.add_header('User-agent', self.user_agent) icon_response = urllib2.urlopen(icon_request) if 200 != icon_response.code: self.site_icon = None return self.site_icon = QImage.fromData(icon_response.read()) max_size = QSize(self.max_icon_size, self.max_icon_size) icon_size = self.site_icon.size() if icon_size.width() > max_size.width() \ or icon_size.height() > max_size.height(): self.site_icon = self.site_icon.scaled(max_size, Qt.KeepAspectRatio, Qt.SmoothTransformation)
def maybe_get_icon(self): """ Get icon for the site as a QImage if we haven't already. Get the site icon, either the 'rel="icon"' or the favicon, for the web page at url or passed in as page_html and store it as a QImage. This function can be called repeatedly and loads the icon only once. """ if self.site_icon: return if not with_pyqt: self.site_icon = None return page_request = urllib2.Request(self.icon_url) if self.user_agent: page_request.add_header('User-agent', self.user_agent) page_response = urllib2.urlopen(page_request) if 200 != page_response.code: self.get_favicon() return page_soup = soup(page_response) try: icon_url = page_soup.find( name='link', attrs={'rel': 'icon'})['href'] except (TypeError, KeyError): self.get_favicon() return # The url may be absolute or relative. if not urlparse.urlsplit(icon_url).netloc: icon_url = urlparse.urljoin( self.url, urllib.quote(icon_url.encode('utf-8'))) icon_request = urllib2.Request(icon_url) if self.user_agent: icon_request.add_header('User-agent', self.user_agent) icon_response = urllib2.urlopen(icon_request) if 200 != icon_response.code: self.site_icon = None return self.site_icon = QImage.fromData(icon_response.read()) max_size = QSize(self.max_icon_size, self.max_icon_size) icon_size = self.site_icon.size() if icon_size.width() > max_size.width() \ or icon_size.height() > max_size.height(): self.site_icon = self.site_icon.scaled( max_size, Qt.KeepAspectRatio, Qt.SmoothTransformation)
def maybe_get_icon(self): if self.site_icon: return if not with_pyqt: self.site_icon = None return try: icon_data = self.get_data_from_url(self.full_icon_url) except: AudioDownloader.maybe_get_icon(self) else: self.site_icon = QImage.fromData(icon_data) max_size = QSize(self.max_icon_size, self.max_icon_size) ico_size = self.site_icon.size() if ico_size.width() > max_size.width() \ or ico_size.height() > max_size.height(): self.site_icon = self.site_icon.scaled( max_size, Qt.KeepAspectRatio, Qt.SmoothTransformation)
def maybe_get_icon(self): if self.site_icon: return if not with_pyqt: self.site_icon = None return try: icon_data = self.get_data_from_url(self.full_icon_url) except: AudioDownloader.maybe_get_icon(self) else: self.site_icon = QImage.fromData(icon_data) max_size = QSize(self.max_icon_size, self.max_icon_size) ico_size = self.site_icon.size() if ico_size.width() > max_size.width() \ or ico_size.height() > max_size.height(): self.site_icon = self.site_icon.scaled( max_size, Qt.KeepAspectRatio, Qt.SmoothTransformation)
def setPhoto(self, contact, item): if not contact: return False try: self.photo_processes.pop(contact.id, None) except KeyError: pass img = None for photo in contact.photos.itervalues(): if photo.thumbnail_data: img = QImage.fromData(photo.thumbnail_data) break if img: item.setIcon(QIcon(QPixmap.fromImage(img))) return True return False
def get_flag_icon(self): """ Set self.site_icon to the right icon. We should use different icons, depending on the request language. We store these icons in self.site_icon_dict and use the AudioDownloader.maybe_get_icon() if we don't have it yet. """ if not with_pyqt: return try: # If this works we already have it. self.site_icon = self.site_icon_dict[self.language] except KeyError: # We have to get it ourself. (We know it's just 16x16, so # no resize. And we know the address). self.site_icon_dict[self.language] = \ QImage.fromData(self.get_data_from_url( self.icon_url_dict[self.language])) self.site_icon = self.site_icon_dict[self.language]
def setPhoto(self, contact, item): if not contact: return False try: self.photo_processes.pop(contact.id, None) except KeyError: pass img = None for photo in contact.photos.itervalues(): if photo.thumbnail_data: img = QImage.fromData(photo.thumbnail_data) break if img: item.setIcon(QIcon(QPixmap.fromImage(img))) return True return False
def run(self): """Main method of a thread to receive the MJEPG-stream. For every frame received, the SIGNAL newFrame() is thrown. Never call this directly. Always use start(). """ self.updateControls = self.hasUpdateControls() self.inputAvt = self.isInputAvt() self.running = True while (self.running): frame = self.httpGet("?action=snapshot") if (frame): self.raw = frame frame = QImage.fromData(frame) oldWidth = frame.size().width() oldHeight = frame.size().height() if self.rotation is not None: #print "rot" #print "before", frame.size().width(),frame.size().height() transf = QTransform() transf.rotate(self.rotation) frame = frame.transformed(transf) #print "after", frame.size().width(),frame.size().height() newWidth = frame.size().width() newHeight = frame.size().height() addedHeight = oldWidth * math.sin( math.radians(self.rotation)) addedWidth = oldHeight * math.sin( math.radians(self.rotation)) h = oldHeight / math.sin(math.radians(self.rotation)) #l1 = #print "addedwidth,Height",addedWidth,addedHeight if (self.transformMode is not None and not (self.width == frame.width() and self.height == frame.height())): frame = frame.scaled(self.width, self.height, self.aspectRatio, self.transformMode) self.frame = frame self.emit(SIGNAL("newFrame()"))
def editImage(self): global jpeg_dirname fileName = QFileDialog.getOpenFileName(self, _("JPEG-Filename"), jpeg_dirname, _("JPEG-Files (*.jpg)")) if fileName != "": fileName = str(fileName) (jpeg_dirname, ramsch) = os.path.split(fileName) if self.image is None: self.result.append((jpegPhoto, [""], False)) self.image = "" for key, text, is_editable in self.result: if key == jpegPhoto: string = open(fileName,"r").read() byarr = QByteArray(string) by64 = byarr.toBase64() text[0] = str(by64) self.iconLabel.setPixmap(QPixmap.fromImage( QImage.fromData(byarr, "JPG"))) self.iconButton.setText(_("Change picture"))
def setPhoto(self, housing, item): if not housing: return False try: self.process_photo.pop(housing.id, None) except KeyError: pass if not housing.photos: return False img = None for photo in housing.photos: if photo.data: img = QImage.fromData(photo.data) break if img: item.setIcon(QIcon(QPixmap.fromImage(img))) return True return False
def setPhoto(self, housing, item): if not housing: return False try: self.process_photo.pop(housing.id, None) except KeyError: pass if not housing.photos: return False img = None for photo in housing.photos: if photo.data: img = QImage.fromData(photo.data) break if img: item.setIcon(QIcon(QPixmap.fromImage(img))) return True return False
def gotThumbnail(self): if self.recipe.picture_url and not empty(self.recipe.picture_url): data = urllib.urlopen(self.recipe.picture_url).read() img = QImage.fromData(data) self.ui.imageLabel.setPixmap(QPixmap.fromImage(img).scaledToWidth(250, Qt.SmoothTransformation))
def update(self, episode, force_change=True): """Update all the episode info.""" if not force_change: # if not forced, only update what is being shown if the current episode # is the one to be updated if self.current_episode != episode.episode_id: return self.current_episode = episode.episode_id # image if episode.image_data is not None: # have the image data already!! qimg = QImage.fromData(episode.image_data) pixmap = QPixmap.fromImage(qimg) self.image_episode.setPixmap(pixmap) self.image_episode.show() elif episode.image_url is not None: # this must be before the get_image call, as it may call # immediately to image_episode_loaded (showing the image and # hiding the throber) self.image_episode.hide() self.throbber.show() # now do call the get_image self.get_image(episode.episode_id, episode.image_url.encode('utf-8')) # all description if episode.subtitle is None: msg = u"<center><h3>%s</h3></center><br/><br/>%s" % ( episode.composed_title, episode.description) else: msg = u"<center><h3>%s</h3>%s</center><br/><br/>%s" % ( episode.composed_title, episode.subtitle, episode.description) self.text_edit.setHtml(msg) # action button self.button.show() if episode.state == data.Status.downloaded: label = "Reproducir" func = self.main_window.play_episode enable = True remove = False elif episode.state == data.Status.downloading: label = u"Cancelar descarga" func = self.main_window.cancel_download enable = True remove = False elif episode.state == data.Status.waiting: label = u"Sacar de la cola" func = self.main_window.unqueue_download enable = True remove = True else: label = u"Descargar" func = self.main_window.download_episode enable = bool(self.main_window.have_config()) remove = False def _exec(func, episode, remove): """Execute a function on the episode and update its info.""" func(episode) if not remove: self.update(episode) # set button text, disconnect if should, and connect new func self.button.setEnabled(enable) self.button.setText(label) if self.button.connected: self.button.clicked.disconnect() self.button.connected = True self.button.clicked.connect(lambda: _exec(func, episode, remove))
def pixmap(self): """Update and returns the pixmap (QPixmap) of the contained image""" if self.changed: self._pixmap = QPixmap(QImage.fromData(self.img.make_blob("jpg"), "jpg"))#self.img.format)) self.changed = False return self._pixmap
def __init__(self, geoservice, image_ba, parent=None): QWidget.__init__(self, parent) self.layout = QHBoxLayout(self) # self.layout.addSpacing(0) self.layout.setContentsMargins(5, 10, 5, 10) self.setLayout(self.layout) self.service_icon = QLabel(self) self.service_icon.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.service_icon.resize(24, 24) qimg = QImage.fromData(image_ba) pixmap = QPixmap.fromImage(qimg) self.service_icon.setPixmap(pixmap) self.layout.addWidget(self.service_icon) self.service_desc_layout = QGridLayout(self) self.service_desc_layout.setSpacing(0) self.layout.addLayout(self.service_desc_layout) self.service_name = QLabel(self) self.service_name.setTextFormat(Qt.RichText) self.service_name.setWordWrap(True) self.service_name.setText(u" <strong> {} </strong>".format( geoservice.get('name', u""))) self.service_desc_layout.addWidget(self.service_name, 0, 0, 1, 3) self.service_type = QLabel(self) self.service_type.setTextFormat(Qt.RichText) self.service_type.setWordWrap(True) self.service_type.setText(geoservice.get('type', u"").upper() + " ") self.service_desc_layout.addWidget(self.service_type, 1, 0) self.service_deteils = QLabel(self) self.service_deteils.setTextFormat(Qt.RichText) self.service_deteils.setWordWrap(True) self.service_deteils.setOpenExternalLinks(True) self.service_deteils.setText(u"<a href=\"{}\">details</a>, ".format( Client().geoservice_info_url(geoservice.get('id', u"")))) self.service_desc_layout.addWidget(self.service_deteils, 1, 1) self.service_report = QLabel(self) self.service_report.setTextFormat(Qt.RichText) self.service_report.setWordWrap(True) self.service_report.setOpenExternalLinks(True) self.service_report.setText( u"<a href=\"{}\">report a problem</a><div/>".format( Client().geoservice_report_url(geoservice.get('id', u"")))) self.service_desc_layout.addWidget(self.service_report, 1, 2) self.service_desc_layout.setColumnStretch(2, 1) # self.service_desc = QLabel(self) # self.service_desc.setTextFormat(Qt.RichText) # self.service_desc.setOpenExternalLinks(True) # self.service_desc.setWordWrap(True) # self.service_desc.setText( # u"<strong> {} </strong><div style=\"margin-top: 3px\">{}, <a href=\"{}\">details</a>, <a href=\"{}\">report</a><div/>".format( # # "{}<div style=\"margin-top: 3px\"> <em> {} </em>, <a href=\"{}\"> details <a/> <div/>".format( # geoservice.get('name', u""), # geoservice.get('type', u"").upper(), # Client().geoservice_info_url(geoservice.get('id', u"")), # Client().geoservice_report_url(geoservice.get('id', u"")) # ) # ) # self.layout.addWidget(self.service_desc) self.addButton = QToolButton() self.addButton.setText("Add") self.addButton.clicked.connect(self.addToMap) self.layout.addWidget(self.addButton) self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum) self.geoservice = geoservice self.image_ba = image_ba
def preview(self, num): self.preview_label.clear() try: self.preview_label.setPixmap(QPixmap(QImage.fromData(self.cv.png[num].make_blob(), self.cv.png[num].format))) except: self.preview_label.setText("Sin imagenes")
def draw_Image(self, painter, x, y, img): import base64 _head, img = img.split('\n', 1) data = base64.b64decode(img) qimg = QImage.fromData(data) painter.drawImage(x, y, qimg)
def setPieceImage(o, rawdata): o.img = QImage.fromData(rawdata) o._got_image = True
def update(self, episode, force_change=True): """Update all the episode info.""" if not force_change: # if not forced, only update what is being shown if the current episode # is the one to be updated if self.current_episode != episode.episode_id: return self.current_episode = episode.episode_id # image if episode.image_data is not None: # have the image data already!! qimg = QImage.fromData(episode.image_data) pixmap = QPixmap.fromImage(qimg) self.image_episode.setPixmap(pixmap) self.image_episode.show() elif episode.image_url is not None: # this must be before the get_image call, as it may call # immediately to image_episode_loaded (showing the image and # hiding the throber) self.image_episode.hide() self.throbber.show() # now do call the get_image self.get_image(episode.episode_id, episode.image_url.encode('utf-8')) # all description if episode.subtitle is None: msg = u"<center><h3>%s</h3></center><br/><br/>%s" % ( episode.composed_title, episode.description) else: msg = u"<center><h3>%s</h3>%s</center><br/><br/>%s" % ( episode.composed_title, episode.subtitle, episode.description) self.text_edit.setHtml(msg) # action button self.button.show() if episode.state == data.Status.downloaded: label = "Reproducir" func = self.main_window.play_episode enable = True remove = False elif episode.state == data.Status.downloading: label = u"Cancelar descarga" func = self.main_window.cancel_download enable = True remove = False elif episode.state == data.Status.waiting: label = u"Sacar de la cola" func = self.main_window.unqueue_download enable = True remove = True else: label = u"Descargar" func = self.main_window.download_episode enable = bool(self.main_window.have_config()) remove = False def _exec(func, episode, remove): """Execute a function on the episode and update its info.""" func(episode) if not remove: self.update(episode) # set button text, disconnect if should, and connect new func self.button.setEnabled(enable) self.button.setText(label) if self.button.connected: self.button.clicked.disconnect() self.button.connected = True self.button.clicked.connect(lambda: _exec(func, episode, remove))
def gotThumbnail(self): if not empty(self.movie.thumbnail_url): data = urllib.urlopen(self.movie.thumbnail_url).read() img = QImage.fromData(data) self.ui.imageLabel.setPixmap(QPixmap.fromImage(img).scaledToWidth(220,Qt.SmoothTransformation))
def draw_Image(self, painter, x, y, img): import base64 _head, img = img.split('\n',1) data = base64.b64decode(img) qimg = QImage.fromData(data) painter.drawImage(x, y, qimg)
def __init__(self, name, l, uid, new=False, parent=None): super(EditDialog, self).__init__(parent) self.name = name self.uid = uid self.l = l self.error = False self.image = None try: res = l.search_s( "uid={l:s},{dn:s}".format(l=uid, dn=ldap_dn), ldap.SCOPE_SUBTREE, "objectclass=*", ) edit_form = [] keys = res[0][1].keys() keys.sort() for key in keys: is_editable = True if key == jpegPhoto: jpeg = res[0][1][key][0] jpba = QByteArray.fromBase64(jpeg) self.image = QImage.fromData(jpba, "JPG") for not_edit in not_editable: if key == not_edit: is_editable = False edit_form.append((key+":", key, res[0][1][key], is_editable)) frameLayout = QVBoxLayout() editLayout = QHBoxLayout() iconLayout = QHBoxLayout() self.iconLabel = QLabel() if self.image is not None: self.iconLabel.setPixmap(QPixmap.fromImage(self.image)) buttonText = _("Change picture") else: buttonText = _("Insert picture") self.iconButton = QPushButton(buttonText) self.iconButton.setFocusPolicy(Qt.NoFocus) self.connect(self.iconButton, SIGNAL("clicked()"), self.editImage) iconLayout.addStretch() iconLayout.addWidget(self.iconLabel) iconLayout.addWidget(self.iconButton) iconLayout.addStretch() frameLayout.addLayout(iconLayout) width = 4 rowLayout = [] for i in range(width): rowLayout.append(QVBoxLayout()) editLayout.addLayout(rowLayout[i]) i = 0 self.result = [] for labeltext, key, text, is_editable in edit_form: if is_editable: is_single = False for single in single_value: if key == single: is_single = True if not is_single: text.append("") for t in text: leLayout = QHBoxLayout() label = QLabel(labeltext) edit = QLineEdit(t) leLayout.addWidget(label) leLayout.addWidget(edit) rowLayout[i].addLayout(leLayout) i += 1 if i == width: i = 0 self.result.append((key, edit, True)) else: self.result.append((key, text, False)) for i in range(width): rowLayout[i].addStretch() button2Layout = QHBoxLayout() button2Layout.addStretch() for text, slot, icon in ((_("Save"), self.close, "dialog-ok-apply.png"), (_("Cancel"), self.cancel, "dialog-cancel.png"), ): button = QPushButton(text) button.setFocusPolicy(Qt.NoFocus) if icon != "": button.setIcon(QIcon(os.path.join(imagespath,icon))) button2Layout.addWidget(button) self.connect(button, SIGNAL("clicked()"), slot) button2Layout.addStretch() frameLayout.addLayout(editLayout) layout = QVBoxLayout() layout.addLayout(frameLayout) layout.addLayout(button2Layout) self.setLayout(layout) self.setWindowTitle(self.name) except ldap.LDAPError, e: error_msg(self, _("LDAP Error"), e)