本文整理汇总了Python中PyQt4.Qt.QImage.isNull方法的典型用法代码示例。如果您正苦于以下问题:Python QImage.isNull方法的具体用法?Python QImage.isNull怎么用?Python QImage.isNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QImage
的用法示例。
在下文中一共展示了QImage.isNull方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_cover
# 需要导入模块: from PyQt4.Qt import QImage [as 别名]
# 或者: from PyQt4.Qt.QImage import isNull [as 别名]
def render_cover(self, book_id):
if self.ignore_render_requests.is_set():
return
tcdata, timestamp = self.thumbnail_cache[book_id]
use_cache = False
if timestamp is None:
# Not in cache
has_cover, cdata, timestamp = self.model().db.new_api.cover_or_cache(book_id, 0)
else:
has_cover, cdata, timestamp = self.model().db.new_api.cover_or_cache(book_id, timestamp)
if has_cover and cdata is None:
# The cached cover is fresh
cdata = tcdata
use_cache = True
if has_cover:
p = QImage()
p.loadFromData(cdata, CACHE_FORMAT if cdata is tcdata else "JPEG")
if p.isNull() and cdata is tcdata:
# Invalid image in cache
self.thumbnail_cache.invalidate((book_id,))
self.update_item.emit(book_id)
return
cdata = None if p.isNull() else p
if not use_cache: # cache is stale
if cdata is not None:
width, height = p.width(), p.height()
scaled, nwidth, nheight = fit_image(
width, height, self.delegate.cover_size.width(), self.delegate.cover_size.height()
)
if scaled:
if self.ignore_render_requests.is_set():
return
p = p.scaled(nwidth, nheight, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
cdata = p
# update cache
if cdata is None:
self.thumbnail_cache.invalidate((book_id,))
else:
try:
self.thumbnail_cache.insert(book_id, timestamp, image_to_data(cdata))
except EncodeError as err:
self.thumbnail_cache.invalidate((book_id,))
prints(err)
except Exception:
import traceback
traceback.print_exc()
elif tcdata is not None:
# Cover was removed, but it exists in cache, remove from cache
self.thumbnail_cache.invalidate((book_id,))
self.delegate.cover_cache.set(book_id, cdata)
self.update_item.emit(book_id)
示例2: paste
# 需要导入模块: from PyQt4.Qt import QImage [as 别名]
# 或者: from PyQt4.Qt.QImage import isNull [as 别名]
def paste(self):
clipboard = QApplication.clipboard()
md = clipboard.mimeData()
if md.hasImage():
img = QImage(md.imageData())
if not img.isNull():
self.undo_stack.push(Replace(img, _('Paste image'), self))
else:
error_dialog(self, _('No image'), _(
'No image available in the clipboard'), show=True)
示例3: __init__
# 需要导入模块: from PyQt4.Qt import QImage [as 别名]
# 或者: from PyQt4.Qt.QImage import isNull [as 别名]
def __init__(self, dirpath):
pictureflow.FlowImages.__init__(self)
self.images = []
self.captions = []
self.subtitles = []
for f in os.listdir(dirpath):
f = os.path.join(dirpath, f)
img = QImage(f)
if not img.isNull():
self.images.append(img)
self.captions.append(os.path.basename(f))
self.subtitles.append('%d bytes'%os.stat(f).st_size)
示例4: render_cover
# 需要导入模块: from PyQt4.Qt import QImage [as 别名]
# 或者: from PyQt4.Qt.QImage import isNull [as 别名]
def render_cover(self, book_id):
cdata = self.model().db.new_api.cover(book_id)
if self.ignore_render_requests.is_set():
return
if cdata is not None:
p = QImage()
p.loadFromData(cdata)
cdata = None
if not p.isNull():
width, height = p.width(), p.height()
scaled, nwidth, nheight = fit_image(width, height, self.delegate.cover_size.width(), self.delegate.cover_size.height())
if scaled:
if self.ignore_render_requests.is_set():
return
p = p.scaled(nwidth, nheight, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
cdata = p
self.delegate.cover_cache.set(book_id, cdata)
self.update_item.emit(book_id)
示例5: __call__
# 需要导入模块: from PyQt4.Qt import QImage [as 别名]
# 或者: from PyQt4.Qt.QImage import isNull [as 别名]
def __call__(self, container):
from PyQt4.Qt import QImage
from calibre.gui2 import pixmap_to_data
ext = container.mime_map[self.name].split('/')[-1].upper()
if ext == 'JPG':
ext = 'JPEG'
if ext not in ('PNG', 'JPEG', 'GIF'):
return False
with container.open(self.name, 'r+b') as f:
raw = f.read()
i = QImage()
i.loadFromData(raw)
if i.isNull():
return False
raw = pixmap_to_data(i, format=ext, quality=95)
f.seek(0)
f.truncate()
f.write(raw)
return True
示例6: dropEvent
# 需要导入模块: from PyQt4.Qt import QImage [as 别名]
# 或者: from PyQt4.Qt.QImage import isNull [as 别名]
def dropEvent(self, event):
event.setDropAction(Qt.CopyAction)
md = event.mimeData()
x, y = dnd_get_image(md)
if x is not None:
# We have an image, set cover
event.accept()
if y is None:
# Local image
self.undo_stack.push(Replace(x.toImage(), _('Drop image'), self))
else:
d = DownloadDialog(x, y, self.gui)
d.start_download()
if d.err is None:
with open(d.fpath, 'rb') as f:
img = QImage()
img.loadFromData(f.read())
if not img.isNull():
self.undo_stack.push(Replace(img, _('Drop image'), self))
event.accept()
示例7: VoivoiShow
# 需要导入模块: from PyQt4.Qt import QImage [as 别名]
# 或者: from PyQt4.Qt.QImage import isNull [as 别名]
class VoivoiShow(Slide):
'''
VoiVoi Slideshow class for displaying images from voivoi database
'''
imgList = list()
eventID = 0
mostRecent = datetime.fromtimestamp(0)
host = "127.0.0.1"
user = "anonymous"
passwd = "secret"
db = "voivoi"
def __init__(self, parent = None):
'''
Constructor
'''
super(VoivoiShow, self).__init__(parent)
#self.setStyleSheet("background: #000;")
self.splashscreen = QImage("res/splashscreen.jpg")
#print(self.splashscreen.isNull())
if not self.splashscreen.isNull():
self.imgList.append(self.splashscreen)
self.imageLabel = QLabel()
self.imageLabel.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
self.imageLabel.setParent(self)
self.httpPool = urllib3.PoolManager()
self.slideIterator = 0
self.timer.timeout.connect(self.nextImage)
self.updateTimer = QTimer()
self.updateTimer.timeout.connect(self.updateImages)
self.mostRecent = datetime.fromtimestamp(0)
self.layout = QHBoxLayout()
self.layout.setMargin(0)
self.layout.addWidget(self.imageLabel)
self.layout.setAlignment(self.imageLabel, Qt.AlignHCenter)
self.setLayout(self.layout)
self.voivoifont = QFont("Helvetica", 48)
self.voivoifont.setBold(True)
def setup(self, host, user, passwd, event_id, database="voivoi", slideInterval=10, updateInterval=60):
''' setup the slide for it's display routine '''
self.host = host
print(self.host)
self.user = user
self.passwd = passwd
self.interval = slideInterval
self.updateInterval = updateInterval
self.db=database
self.eventID = event_id
self.updateImages()
def updateImages(self, buffer_limit=20):
try:
db_connection = pymysql.connect(self.host, self.user, self.passwd, self.db)
except:
print("Database connection not available")
return
sqlquery = "SELECT `categoryOrder`, `userID`, `dayID`, `comment`, `timestamp`, `eventID` FROM `pictures` WHERE `eventID`>=" + str(self.eventID) + " AND `timestamp`>'" + str(self.mostRecent) + "' ORDER BY `timestamp` ASC"
#print(sqlquery)
try:
with db_connection.cursor() as cursor:
cursor.execute(sqlquery)
result = cursor.fetchall()
for entry in result:
print(entry[4])
#print(self.mostRecent)
if entry[4] > self.mostRecent:
if entry[0] == 0:
print("BREAKING")
continue
self.mostRecent = entry[4]
image_url = "http://voivoi.eventfive.de/events/" + str(entry[5]) + "/uploads/" + str(entry[0]) + "_" + str(entry[1]) + "_" + str(entry[2]) + ".jpg"
req = self.httpPool.request('GET',image_url)
if req.status == 200:
data = req.data
print("Newer file downloaded")
might_be_image = QImage()
if might_be_image.loadFromData(data) :
#print("URL is valid")
self.drawOverlay(might_be_image, entry)
if len(self.imgList) > buffer_limit-1: #TODO: change behaviour to iteration over fixed list, to prevent jumps
self.imgList.pop(1)
self.imgList.append(might_be_image)
finally:
print("Update done, closing connection")
db_connection.close()
def drawOverlay(self, image, entry):
#.........这里部分代码省略.........
示例8: rescale
# 需要导入模块: from PyQt4.Qt import QImage [as 别名]
# 或者: from PyQt4.Qt.QImage import isNull [as 别名]
def rescale(self, qt=True):
from calibre.utils.magick.draw import Image
is_image_collection = getattr(self.opts, 'is_image_collection', False)
if is_image_collection:
page_width, page_height = self.opts.dest.comic_screen_size
else:
page_width, page_height = self.opts.dest.width, self.opts.dest.height
page_width -= (self.opts.margin_left + self.opts.margin_right) * self.opts.dest.dpi/72.
page_height -= (self.opts.margin_top + self.opts.margin_bottom) * self.opts.dest.dpi/72.
for item in self.oeb.manifest:
if item.media_type.startswith('image'):
ext = item.media_type.split('/')[-1].upper()
if ext == 'JPG':
ext = 'JPEG'
if ext not in ('PNG', 'JPEG', 'GIF'):
ext = 'JPEG'
raw = item.data
if hasattr(raw, 'xpath') or not raw:
# Probably an svg image
continue
try:
img = Image()
img.load(raw)
except:
continue
width, height = img.size
try:
if self.check_colorspaces and img.colorspace == 'CMYKColorspace':
# We cannot do an imagemagick conversion of CMYK to RGB as
# ImageMagick inverts colors if you just set the colorspace
# to rgb. See for example: https://bugs.launchpad.net/bugs/1246710
from PyQt4.Qt import QImage
from calibre.gui2 import pixmap_to_data
qimg = QImage()
qimg.loadFromData(raw)
if not qimg.isNull():
raw = item.data = pixmap_to_data(qimg, format=ext, quality=95)
img = Image()
img.load(raw)
self.log.warn(
'The image %s is in the CMYK colorspace, converting it '
'to RGB as Adobe Digital Editions cannot display CMYK' % item.href)
else:
self.log.warn(
'The image %s is in the CMYK colorspace, you should convert'
' it to sRGB as Adobe Digital Editions cannot render CMYK' % item.href)
except Exception:
pass
scaled, new_width, new_height = fit_image(width, height,
page_width, page_height)
if scaled:
new_width = max(1, new_width)
new_height = max(1, new_height)
self.log('Rescaling image from %dx%d to %dx%d'%(
width, height, new_width, new_height), item.href)
try:
img.size = (new_width, new_height)
data = img.export(ext.lower())
except KeyboardInterrupt:
raise
except:
self.log.exception('Failed to rescale image')
else:
item.data = data
item.unload_data_from_memory()