本文整理汇总了Python中PyQt4.QtCore.QUrl.hasQuery方法的典型用法代码示例。如果您正苦于以下问题:Python QUrl.hasQuery方法的具体用法?Python QUrl.hasQuery怎么用?Python QUrl.hasQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QUrl
的用法示例。
在下文中一共展示了QUrl.hasQuery方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import hasQuery [as 别名]
class CoverArtImage:
support_types = False
# consider all images as front if types aren't supported by provider
is_front = True
def __init__(self, url=None, types=[u'front'], comment=''):
if url is not None:
self.parse_url(url)
else:
self.url = None
self.types = types
self.comment = comment
def parse_url(self, url):
self.url = QUrl(url)
self.host = str(self.url.host())
self.port = self.url.port(80)
self.path = str(self.url.encodedPath())
if self.url.hasQuery():
self.path += '?' + str(self.url.encodedQuery())
def is_front_image(self):
# CAA has a flag for "front" image, use it in priority
if self.is_front:
return True
# no caa front flag, use type instead
return u'front' in self.types
def __repr__(self):
p = []
if self.url is not None:
p.append("url=%r" % self.url.toString())
p.append("types=%r" % self.types)
if self.comment:
p.append("comment=%r" % self.comment)
return "%s(%s)" % (self.__class__.__name__, ", ".join(p))
def __unicode__(self):
p = [u'Image']
if self.url is not None:
p.append(u"from %s" % self.url.toString())
p.append(u"of type %s" % u','.join(self.types))
if self.comment:
p.append(u"and comment '%s'" % self.comment)
return u' '.join(p)
def __str__(self):
return unicode(self).encode('utf-8')
示例2: __init__
# 需要导入模块: from PyQt4.QtCore import QUrl [as 别名]
# 或者: from PyQt4.QtCore.QUrl import hasQuery [as 别名]
class CoverArtImage:
# Indicate if types are provided by the source, ie. CAA or certain file
# formats may have types associated with cover art, but some other sources
# don't provide such information
support_types = False
# `is_front` has to be explicitly set, it is used to handle CAA is_front
# indicator
is_front = None
sourceprefix = "URL"
def __init__(self, url=None, types=[], comment='', data=None):
if url is not None:
self.parse_url(url)
else:
self.url = None
self.types = types
self.comment = comment
self.datahash = None
# thumbnail is used to link to another CoverArtImage, ie. for PDFs
self.thumbnail = None
self.can_be_saved_to_tags = True
self.can_be_saved_to_disk = True
self.can_be_saved_to_metadata = True
if data is not None:
self.set_data(data)
def parse_url(self, url):
self.url = QUrl(url)
self.host = str(self.url.host())
self.port = self.url.port(80)
self.path = str(self.url.encodedPath())
if self.url.hasQuery():
self.path += '?' + str(self.url.encodedQuery())
@property
def source(self):
if self.url is not None:
return u"%s: %s" % (self.sourceprefix, self.url.toString())
else:
return u"%s" % self.sourceprefix
def is_front_image(self):
"""Indicates if image is considered as a 'front' image.
It depends on few things:
- if `is_front` was set, it is used over anything else
- if `types` was set, search for 'front' in it
- if `support_types` is False, default to True for any image
- if `support_types` is True, default to False for any image
"""
if not self.can_be_saved_to_metadata:
# ignore thumbnails
return False
if self.is_front is not None:
return self.is_front
if u'front' in self.types:
return True
return (self.support_types is False)
def imageinfo_as_string(self):
if self.datahash is None:
return ""
return "w=%d h=%d mime=%s ext=%s datalen=%d file=%s" % (self.width,
self.height,
self.mimetype,
self.extension,
self.datalength,
self.tempfile_filename)
def __repr__(self):
p = []
if self.url is not None:
p.append("url=%r" % self.url.toString())
if self.types:
p.append("types=%r" % self.types)
if self.is_front is not None:
p.append("is_front=%r" % self.is_front)
if self.comment:
p.append("comment=%r" % self.comment)
return "%s(%s)" % (self.__class__.__name__, ", ".join(p))
def __unicode__(self):
p = [u'Image']
if self.url is not None:
p.append(u"from %s" % self.url.toString())
if self.types:
p.append(u"of type %s" % u','.join(self.types))
if self.comment:
p.append(u"and comment '%s'" % self.comment)
return u' '.join(p)
def __str__(self):
return unicode(self).encode('utf-8')
def set_data(self, data):
"""Store image data in a file, if data already exists in such file
it will be re-used and no file write occurs
"""
if self.datahash:
self.datahash.delete_file()
#.........这里部分代码省略.........