本文整理汇总了Python中PyQt5.Qt.QPropertyAnimation.setEndValue方法的典型用法代码示例。如果您正苦于以下问题:Python QPropertyAnimation.setEndValue方法的具体用法?Python QPropertyAnimation.setEndValue怎么用?Python QPropertyAnimation.setEndValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QPropertyAnimation
的用法示例。
在下文中一共展示了QPropertyAnimation.setEndValue方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pressedPandoraButton
# 需要导入模块: from PyQt5.Qt import QPropertyAnimation [as 别名]
# 或者: from PyQt5.Qt.QPropertyAnimation import setEndValue [as 别名]
def pressedPandoraButton(self):
pandoraButtonCurrentGeometry = QtCore.QRect(self.pandoraToolButton.geometry())
pandoraButtonAnimation = QPropertyAnimation(self.pandoraToolButton,'geometry'.encode(encoding='utf_8'))
pandoraButtonAnimation.setDuration(self.ANIMATIONDURATION)
pandoraButtonAnimation.setStartValue(pandoraButtonCurrentGeometry)
pandoraWidgetCurrentGeometry = QtCore.QRect(self.pandoraWidget.geometry())
pandoraWidgetAnimation = QPropertyAnimation(self.pandoraWidget,'geometry'.encode(encoding='utf_8'))
pandoraWidgetAnimation.setDuration(self.ANIMATIONDURATION)
pandoraWidgetAnimation.setStartValue(pandoraWidgetCurrentGeometry)
if self.PandoraCurrentState == 'Closed':
pandoraButtonEndTopLeftCorner = QtCore.QPoint(self.pandoraToolButton.pos() - QtCore.QPoint(275, 0))
pandoraWidgetEndTopLeftCorner = QtCore.QPoint(self.pandoraWidget.pos() - QtCore.QPoint(275, 0))
self.PandoraCurrentState = 'Open'
if self.Pandora.started == True:
self.playToolButton.hide()
self.pauseToolButton.show()
else:
pandoraButtonEndTopLeftCorner = QtCore.QPoint(self.pandoraToolButton.pos() + QtCore.QPoint(275, 0))
pandoraWidgetEndTopLeftCorner = QtCore.QPoint(self.pandoraWidget.pos() + QtCore.QPoint(275, 0))
self.PandoraCurrentState = 'Closed'
pandoraButtonFinalGeometry = QtCore.QRect(pandoraButtonEndTopLeftCorner, QtCore.QSize(self.pandoraToolButton.width(), self.pandoraToolButton.height()))
pandoraButtonAnimation.setEndValue(pandoraButtonFinalGeometry)
pandoraWidgetFinalGeometry = QtCore.QRect(pandoraWidgetEndTopLeftCorner, QtCore.QSize(self.pandoraWidget.width(), self.pandoraWidget.height()))
pandoraWidgetAnimation.setEndValue(pandoraWidgetFinalGeometry)
pandoraButtonAnimation.start()
pandoraWidgetAnimation.start()
#self.setpandoraWidgetStyleSheet()
self.PandoraIconAnimation = pandoraButtonAnimation
self.PandoraWidgetAnimation = pandoraWidgetAnimation
示例2: pressedAlarmButton
# 需要导入模块: from PyQt5.Qt import QPropertyAnimation [as 别名]
# 或者: from PyQt5.Qt.QPropertyAnimation import setEndValue [as 别名]
def pressedAlarmButton(self):
try:
alarmButtonCurrentGeometry = QtCore.QRect(self.alarmToolButton.geometry())
alarmButtonAnimation = QPropertyAnimation(self.alarmToolButton,'geometry'.encode(encoding='utf_8'))
alarmButtonAnimation.setDuration(self.ANIMATIONDURATION)
alarmButtonAnimation.setStartValue(alarmButtonCurrentGeometry)
alarmWidgetCurrentGeometry = QtCore.QRect(self.alarmWidget.geometry())
alarmWidgetAnimation = QPropertyAnimation(self.alarmWidget,'geometry'.encode(encoding='utf_8'))
alarmWidgetAnimation.setDuration(self.ANIMATIONDURATION)
alarmWidgetAnimation.setStartValue(alarmWidgetCurrentGeometry)
if self.AlarmCurrentState == 'Closed':
alarmButtonEndTopLeftCorner = QtCore.QPoint(self.alarmToolButton.pos() - QtCore.QPoint(275, 0))
alarmWidgetEndTopLeftCorner = QtCore.QPoint(self.alarmWidget.pos() - QtCore.QPoint(275, 0))
self.AlarmCurrentState = 'Open'
else:
alarmButtonEndTopLeftCorner = QtCore.QPoint(self.alarmToolButton.pos() + QtCore.QPoint(275, 0))
alarmWidgetEndTopLeftCorner = QtCore.QPoint(self.alarmWidget.pos() + QtCore.QPoint(275, 0))
self.AlarmCurrentState = 'Closed'
alarmButtonFinalGeometry = QtCore.QRect(alarmButtonEndTopLeftCorner, QtCore.QSize(self.alarmToolButton.width(), self.alarmToolButton.height()))
alarmButtonAnimation.setEndValue(alarmButtonFinalGeometry)
alarmWidgetFinalGeometry = QtCore.QRect(alarmWidgetEndTopLeftCorner, QtCore.QSize(self.alarmWidget.width(), self.alarmWidget.height()))
alarmWidgetAnimation.setEndValue(alarmWidgetFinalGeometry)
alarmButtonAnimation.start()
alarmWidgetAnimation.start()
#self.setAlarmWidgetStyleSheet()
self.AlarmIconAnimation = alarmButtonAnimation
self.AlarmWidgetAnimation = alarmWidgetAnimation
except Exception as e:
print (e.strerror)
示例3: ThrobbingButton
# 需要导入模块: from PyQt5.Qt import QPropertyAnimation [as 别名]
# 或者: from PyQt5.Qt.QPropertyAnimation import setEndValue [as 别名]
class ThrobbingButton(QToolButton):
@pyqtProperty(int)
def icon_size(self):
return self._icon_size
@icon_size.setter
def icon_size(self, value):
self._icon_size = value
def __init__(self, *args):
QToolButton.__init__(self, *args)
# vertically size policy must be expanding for it to align inside a
# toolbar
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
self._icon_size = -1
QToolButton.setIcon(self, QIcon(I('donate.png')))
self.setText('\xa0')
self.animation = QPropertyAnimation(self, b'icon_size', self)
self.animation.setDuration(60/72.*1000)
self.animation.setLoopCount(4)
self.animation.valueChanged.connect(self.value_changed)
self.setCursor(Qt.PointingHandCursor)
self.animation.finished.connect(self.animation_finished)
def animation_finished(self):
self.icon_size = self.iconSize().width()
def enterEvent(self, ev):
self.start_animation()
def leaveEvent(self, ev):
self.stop_animation()
def value_changed(self, val):
self.update()
def start_animation(self):
if config['disable_animations']:
return
if self.animation.state() != self.animation.Stopped or not self.isVisible():
return
size = self.iconSize().width()
smaller = int(0.7 * size)
self.animation.setStartValue(smaller)
self.animation.setEndValue(size)
QMetaObject.invokeMethod(self.animation, 'start', Qt.QueuedConnection)
def stop_animation(self):
self.animation.stop()
self.animation_finished()
def paintEvent(self, ev):
size = self._icon_size if self._icon_size > 10 else self.iconSize().width()
p = QPainter(self)
opt = QStyleOptionToolButton()
self.initStyleOption(opt)
s = self.style()
opt.iconSize = QSize(size, size)
s.drawComplexControl(s.CC_ToolButton, opt, p, self)
示例4: ThrobbingButton
# 需要导入模块: from PyQt5.Qt import QPropertyAnimation [as 别名]
# 或者: from PyQt5.Qt.QPropertyAnimation import setEndValue [as 别名]
class ThrobbingButton(QToolButton):
def __init__(self, *args):
QToolButton.__init__(self, *args)
self.animation = QPropertyAnimation(self, 'iconSize', self)
self.animation.setDuration(60/72.*1000)
self.animation.setLoopCount(4)
self.normal_icon_size = QSize(64, 64)
self.animation.valueChanged.connect(self.value_changed)
self.setCursor(Qt.PointingHandCursor)
self.animation.finished.connect(self.animation_finished)
def set_normal_icon_size(self, w, h):
self.normal_icon_size = QSize(w, h)
self.setIconSize(self.normal_icon_size)
try:
self.setMinimumSize(self.sizeHint())
except:
self.setMinimumSize(QSize(w+5, h+5))
def animation_finished(self):
self.setIconSize(self.normal_icon_size)
def enterEvent(self, ev):
self.start_animation()
def leaveEvent(self, ev):
self.stop_animation()
def value_changed(self, val):
self.update()
def start_animation(self):
if config['disable_animations']:
return
if self.animation.state() != self.animation.Stopped or not self.isVisible():
return
size = self.normal_icon_size.width()
smaller = int(0.7 * size)
self.animation.setStartValue(QSize(smaller, smaller))
self.animation.setEndValue(self.normal_icon_size)
QMetaObject.invokeMethod(self.animation, 'start', Qt.QueuedConnection)
def stop_animation(self):
self.animation.stop()
self.animation_finished()
示例5: pressedCalendarButton
# 需要导入模块: from PyQt5.Qt import QPropertyAnimation [as 别名]
# 或者: from PyQt5.Qt.QPropertyAnimation import setEndValue [as 别名]
def pressedCalendarButton(self):
try:
calendarButtonCurrentGeometry = QtCore.QRect(self.calendarToolButton.geometry())
calendarButtonAnimation = QPropertyAnimation(self.calendarToolButton,'geometry'.encode(encoding='utf_8'))
calendarButtonAnimation.setDuration(self.ANIMATIONDURATION)
calendarButtonAnimation.setStartValue(calendarButtonCurrentGeometry)
calendarWidgetCurrentGeometry = QtCore.QRect(self.calendarWidget.geometry())
calendarWidgetAnimation = QPropertyAnimation(self.calendarWidget,'geometry'.encode(encoding='utf_8'))
calendarWidgetAnimation.setDuration(self.ANIMATIONDURATION)
calendarWidgetAnimation.setStartValue(calendarWidgetCurrentGeometry)
if self.CalendarCurrentState == 'Closed':
calendarButtonEndTopLeftCorner = QtCore.QPoint(self.calendarToolButton.pos() - QtCore.QPoint(275, 0))
calendarWidgetEndTopLeftCorner = QtCore.QPoint(self.calendarWidget.pos() - QtCore.QPoint(275, 0))
self.CalendarCurrentState = 'Open'
self.Calendar = Calendar()
self.calendarLabel.setText(self.Calendar.EventList)
else:
calendarButtonEndTopLeftCorner = QtCore.QPoint(self.calendarToolButton.pos() + QtCore.QPoint(275, 0))
calendarWidgetEndTopLeftCorner = QtCore.QPoint(self.calendarWidget.pos() + QtCore.QPoint(275, 0))
self.CalendarCurrentState = 'Closed'
calendarButtonFinalGeometry = QtCore.QRect(calendarButtonEndTopLeftCorner, QtCore.QSize(self.calendarToolButton.width(), self.calendarToolButton.height()))
calendarButtonAnimation.setEndValue(calendarButtonFinalGeometry)
calendarWidgetFinalGeometry = QtCore.QRect(calendarWidgetEndTopLeftCorner, QtCore.QSize(self.calendarWidget.width(), self.calendarWidget.height()))
calendarWidgetAnimation.setEndValue(calendarWidgetFinalGeometry)
calendarButtonAnimation.start()
calendarWidgetAnimation.start()
#self.setcalendarWidgetStyleSheet()
self.CalendarIconAnimation = calendarButtonAnimation
self.CalendarWidgetAnimation = calendarWidgetAnimation
except Exception as e:
print (e.strerror)
示例6: RevealBar
# 需要导入模块: from PyQt5.Qt import QPropertyAnimation [as 别名]
# 或者: from PyQt5.Qt.QPropertyAnimation import setEndValue [as 别名]
class RevealBar(QWidget): # {{{
def __init__(self, parent):
QWidget.__init__(self, parent)
self.setVisible(False)
self._animated_size = 1.0
self.animation = QPropertyAnimation(self, b'animated_size', self)
self.animation.setEasingCurve(QEasingCurve.Linear)
self.animation.setDuration(1000), self.animation.setStartValue(0.0), self.animation.setEndValue(1.0)
self.animation.valueChanged.connect(self.animation_value_changed)
self.animation.finished.connect(self.animation_done)
@pyqtProperty(float)
def animated_size(self):
return self._animated_size
@animated_size.setter
def animated_size(self, val):
self._animated_size = val
def animation_value_changed(self, *args):
self.update()
def animation_done(self):
self.setVisible(False)
self.update()
def start(self, bar):
self.setGeometry(bar.geometry())
self.setVisible(True)
self.animation.start()
def paintEvent(self, ev):
if self._animated_size < 1.0:
rect = self.rect()
painter = QPainter(self)
pal = self.palette()
col = pal.color(pal.Button)
rect.setLeft(rect.left() + (rect.width() * self._animated_size))
painter.setClipRect(rect)
painter.fillRect(self.rect(), col)
示例7: CoverDelegate
# 需要导入模块: from PyQt5.Qt import QPropertyAnimation [as 别名]
# 或者: from PyQt5.Qt.QPropertyAnimation import setEndValue [as 别名]
class CoverDelegate(QStyledItemDelegate):
MARGIN = 4
TOP, LEFT, RIGHT, BOTTOM = object(), object(), object(), object()
@pyqtProperty(float)
def animated_size(self):
return self._animated_size
@animated_size.setter
def animated_size(self, val):
self._animated_size = val
def __init__(self, parent):
super(CoverDelegate, self).__init__(parent)
self._animated_size = 1.0
self.animation = QPropertyAnimation(self, b'animated_size', self)
self.animation.setEasingCurve(QEasingCurve.OutInCirc)
self.animation.setDuration(500)
self.set_dimensions()
self.cover_cache = CoverCache()
self.render_queue = LifoQueue()
self.animating = None
self.highlight_color = QColor(Qt.white)
self.rating_font = QFont(rating_font())
def set_dimensions(self):
width = self.original_width = gprefs['cover_grid_width']
height = self.original_height = gprefs['cover_grid_height']
self.original_show_title = show_title = gprefs['cover_grid_show_title']
self.original_show_emblems = gprefs['show_emblems']
self.orginal_emblem_size = gprefs['emblem_size']
self.orginal_emblem_position = gprefs['emblem_position']
self.emblem_size = gprefs['emblem_size'] if self.original_show_emblems else 0
try:
self.gutter_position = getattr(self, self.orginal_emblem_position.upper())
except Exception:
self.gutter_position = self.TOP
if height < 0.1:
height = auto_height(self.parent())
else:
height *= self.parent().logicalDpiY() * CM_TO_INCH
if width < 0.1:
width = 0.75 * height
else:
width *= self.parent().logicalDpiX() * CM_TO_INCH
self.cover_size = QSize(width, height)
self.title_height = 0
if show_title:
f = self.parent().font()
sz = f.pixelSize()
if sz < 5:
sz = f.pointSize() * self.parent().logicalDpiY() / 72.0
self.title_height = max(25, sz + 10)
self.item_size = self.cover_size + QSize(2 * self.MARGIN, (2 * self.MARGIN) + self.title_height)
if self.emblem_size > 0:
extra = self.emblem_size + self.MARGIN
self.item_size += QSize(extra, 0) if self.gutter_position in (self.LEFT, self.RIGHT) else QSize(0, extra)
self.calculate_spacing()
self.animation.setStartValue(1.0)
self.animation.setKeyValueAt(0.5, 0.5)
self.animation.setEndValue(1.0)
def calculate_spacing(self):
spc = self.original_spacing = gprefs['cover_grid_spacing']
if spc < 0.01:
self.spacing = max(10, min(50, int(0.1 * self.original_width)))
else:
self.spacing = self.parent().logicalDpiX() * CM_TO_INCH * spc
def sizeHint(self, option, index):
return self.item_size
def render_field(self, db, book_id):
is_stars = False
try:
field = db.pref('field_under_covers_in_grid', 'title')
if field == 'size':
ans = human_readable(db.field_for(field, book_id, default_value=0))
else:
mi = db.get_proxy_metadata(book_id)
display_name, ans, val, fm = mi.format_field_extended(field)
if fm and fm['datatype'] == 'rating':
ans = rating_to_stars(val, fm['display'].get('allow_half_stars', False))
is_stars = True
return ('' if ans is None else unicode_type(ans)), is_stars
except Exception:
if DEBUG:
import traceback
traceback.print_exc()
return '', is_stars
def render_emblem(self, book_id, rule, rule_index, cache, mi, db, formatter, template_cache):
ans = cache[book_id].get(rule, False)
if ans is not False:
return ans, mi
ans = None
if mi is None:
#.........这里部分代码省略.........
示例8: CoverView
# 需要导入模块: from PyQt5.Qt import QPropertyAnimation [as 别名]
# 或者: from PyQt5.Qt.QPropertyAnimation import setEndValue [as 别名]
class CoverView(QWidget): # {{{
cover_changed = pyqtSignal(object, object)
cover_removed = pyqtSignal(object)
open_cover_with = pyqtSignal(object, object)
search_internet = pyqtSignal(object)
def __init__(self, vertical, parent=None):
QWidget.__init__(self, parent)
self._current_pixmap_size = QSize(120, 120)
self.vertical = vertical
self.animation = QPropertyAnimation(self, b'current_pixmap_size', self)
self.animation.setEasingCurve(QEasingCurve(QEasingCurve.OutExpo))
self.animation.setDuration(1000)
self.animation.setStartValue(QSize(0, 0))
self.animation.valueChanged.connect(self.value_changed)
self.setSizePolicy(
QSizePolicy.Expanding if vertical else QSizePolicy.Minimum,
QSizePolicy.Expanding)
self.default_pixmap = QPixmap(I('default_cover.png'))
self.pixmap = self.default_pixmap
self.pwidth = self.pheight = None
self.data = {}
self.do_layout()
def value_changed(self, val):
self.update()
def setCurrentPixmapSize(self, val):
self._current_pixmap_size = val
def do_layout(self):
if self.rect().width() == 0 or self.rect().height() == 0:
return
pixmap = self.pixmap
pwidth, pheight = pixmap.width(), pixmap.height()
try:
self.pwidth, self.pheight = fit_image(pwidth, pheight,
self.rect().width(), self.rect().height())[1:]
except:
self.pwidth, self.pheight = self.rect().width()-1, \
self.rect().height()-1
self.current_pixmap_size = QSize(self.pwidth, self.pheight)
self.animation.setEndValue(self.current_pixmap_size)
def show_data(self, data):
self.animation.stop()
same_item = getattr(data, 'id', True) == self.data.get('id', False)
self.data = {'id':data.get('id', None)}
if data.cover_data[1]:
self.pixmap = QPixmap.fromImage(data.cover_data[1])
if self.pixmap.isNull() or self.pixmap.width() < 5 or \
self.pixmap.height() < 5:
self.pixmap = self.default_pixmap
else:
self.pixmap = self.default_pixmap
self.do_layout()
self.update()
if (not same_item and not config['disable_animations'] and
self.isVisible()):
self.animation.start()
def paintEvent(self, event):
canvas_size = self.rect()
width = self.current_pixmap_size.width()
extrax = canvas_size.width() - width
if extrax < 0:
extrax = 0
x = int(extrax/2.)
height = self.current_pixmap_size.height()
extray = canvas_size.height() - height
if extray < 0:
extray = 0
y = int(extray/2.)
target = QRect(x, y, width, height)
p = QPainter(self)
p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
try:
dpr = self.devicePixelRatioF()
except AttributeError:
dpr = self.devicePixelRatio()
spmap = self.pixmap.scaled(target.size() * dpr, Qt.KeepAspectRatio, Qt.SmoothTransformation)
spmap.setDevicePixelRatio(dpr)
p.drawPixmap(target, spmap)
if gprefs['bd_overlay_cover_size']:
sztgt = target.adjusted(0, 0, 0, -4)
f = p.font()
f.setBold(True)
p.setFont(f)
sz = u'\u00a0%d x %d\u00a0'%(self.pixmap.width(), self.pixmap.height())
flags = Qt.AlignBottom|Qt.AlignRight|Qt.TextSingleLine
szrect = p.boundingRect(sztgt, flags, sz)
p.fillRect(szrect.adjusted(0, 0, 0, 4), QColor(0, 0, 0, 200))
p.setPen(QPen(QColor(255,255,255)))
p.drawText(sztgt, flags, sz)
p.end()
#.........这里部分代码省略.........
示例9: SlideFlip
# 需要导入模块: from PyQt5.Qt import QPropertyAnimation [as 别名]
# 或者: from PyQt5.Qt.QPropertyAnimation import setEndValue [as 别名]
class SlideFlip(QWidget):
# API {{{
# In addition the isVisible() and setVisible() methods must be present
def __init__(self, parent):
QWidget.__init__(self, parent)
self.setGeometry(0, 0, 1, 1)
self._current_width = 0
self.before_image = self.after_image = None
self.animation = QPropertyAnimation(self, 'current_width', self)
self.setVisible(False)
self.animation.valueChanged.connect(self.update)
self.animation.finished.connect(self.finished)
self.flip_forwards = True
self.setAttribute(Qt.WA_OpaquePaintEvent)
@property
def running(self):
'True iff animation is currently running'
return self.animation.state() == self.animation.Running
def initialize(self, image, forwards=True):
'''
Initialize the flipper, causes the flipper to show itself displaying
the full `image`.
:param image: The image to display as background
:param forwards: If True flipper will flip forwards, otherwise
backwards
'''
self.flip_forwards = forwards
self.before_image = QPixmap.fromImage(image)
self.after_image = None
self.setGeometry(0, 0, image.width(), image.height())
self.setVisible(True)
def __call__(self, image, duration=0.5):
'''
Start the animation. You must have called :meth:`initialize` first.
:param duration: Animation duration in seconds.
'''
if self.running:
return
self.after_image = QPixmap.fromImage(image)
if self.flip_forwards:
self.animation.setStartValue(image.width())
self.animation.setEndValue(0)
t = self.before_image
self.before_image = self.after_image
self.after_image = t
self.animation.setEasingCurve(QEasingCurve(QEasingCurve.InExpo))
else:
self.animation.setStartValue(0)
self.animation.setEndValue(image.width())
self.animation.setEasingCurve(QEasingCurve(QEasingCurve.OutExpo))
self.animation.setDuration(duration * 1000)
self.animation.start()
# }}}
def finished(self):
self.setVisible(False)
self.before_image = self.after_image = None
def paintEvent(self, ev):
if self.before_image is None:
return
canvas_size = self.rect()
p = QPainter(self)
p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
p.drawPixmap(canvas_size, self.before_image,
self.before_image.rect())
if self.after_image is not None:
width = self._current_width
iw = self.after_image.width()
sh = min(self.after_image.height(), canvas_size.height())
if self.flip_forwards:
source = QRect(max(0, iw - width), 0, width, sh)
else:
source = QRect(0, 0, width, sh)
target = QRect(source)
target.moveLeft(0)
p.drawPixmap(target, self.after_image, source)
p.end()
def set_current_width(self, val):
self._current_width = val
#.........这里部分代码省略.........
示例10: Pointer
# 需要导入模块: from PyQt5.Qt import QPropertyAnimation [as 别名]
# 或者: from PyQt5.Qt.QPropertyAnimation import setEndValue [as 别名]
class Pointer(QWidget):
def __init__(self, gui):
QWidget.__init__(self, gui)
self.setObjectName('jobs_pointer')
self.setVisible(False)
self.resize(100, 80)
self.animation = QPropertyAnimation(self, "geometry", self)
self.animation.setDuration(750)
self.animation.setLoopCount(2)
self.animation.setEasingCurve(QEasingCurve.Linear)
self.animation.finished.connect(self.hide)
taily, heady = 0, 55
self.arrow_path = QPainterPath(QPointF(40, taily))
self.arrow_path.lineTo(40, heady)
self.arrow_path.lineTo(20, heady)
self.arrow_path.lineTo(50, self.height())
self.arrow_path.lineTo(80, heady)
self.arrow_path.lineTo(60, heady)
self.arrow_path.lineTo(60, taily)
self.arrow_path.closeSubpath()
c = self.palette().color(QPalette.Active, QPalette.WindowText)
self.color = QColor(c)
self.color.setAlpha(100)
self.brush = QBrush(self.color, Qt.SolidPattern)
# from PyQt5.Qt import QTimer
# QTimer.singleShot(1000, self.start)
@property
def gui(self):
return self.parent()
def point_at(self, frac):
return (self.path.pointAtPercent(frac).toPoint() -
QPoint(self.rect().center().x(), self.height()))
def rect_at(self, frac):
return QRect(self.point_at(frac), self.size())
def abspos(self, widget):
pos = widget.pos()
parent = widget.parent()
while parent is not self.gui:
pos += parent.pos()
parent = parent.parent()
return pos
def start(self):
if config['disable_animations']:
return
self.setVisible(True)
self.raise_()
end = self.abspos(self.gui.jobs_button)
end = QPointF( end.x() + self.gui.jobs_button.width()/3.0, end.y()+20)
start = QPointF(end.x(), end.y() - 0.5*self.height())
self.path = QPainterPath(QPointF(start))
self.path.lineTo(end)
self.path.closeSubpath()
self.animation.setStartValue(self.rect_at(0.0))
self.animation.setEndValue(self.rect_at(1.0))
self.animation.setDirection(self.animation.Backward)
num_keys = 100
for i in xrange(1, num_keys):
i /= num_keys
self.animation.setKeyValueAt(i, self.rect_at(i))
self.animation.start()
def paintEvent(self, ev):
p = QPainter(self)
p.setRenderHints(p.Antialiasing)
p.setBrush(self.brush)
p.setPen(Qt.NoPen)
p.drawPath(self.arrow_path)
p.end()
示例11: CoverView
# 需要导入模块: from PyQt5.Qt import QPropertyAnimation [as 别名]
# 或者: from PyQt5.Qt.QPropertyAnimation import setEndValue [as 别名]
class CoverView(QWidget): # {{{
cover_changed = pyqtSignal(object, object)
cover_removed = pyqtSignal(object)
def __init__(self, vertical, parent=None):
QWidget.__init__(self, parent)
self._current_pixmap_size = QSize(120, 120)
self.vertical = vertical
self.animation = QPropertyAnimation(self, "current_pixmap_size", self)
self.animation.setEasingCurve(QEasingCurve(QEasingCurve.OutExpo))
self.animation.setDuration(1000)
self.animation.setStartValue(QSize(0, 0))
self.animation.valueChanged.connect(self.value_changed)
self.setSizePolicy(QSizePolicy.Expanding if vertical else QSizePolicy.Minimum, QSizePolicy.Expanding)
self.default_pixmap = QPixmap(I("book.png"))
self.pixmap = self.default_pixmap
self.pwidth = self.pheight = None
self.data = {}
self.do_layout()
def value_changed(self, val):
self.update()
def setCurrentPixmapSize(self, val):
self._current_pixmap_size = val
def do_layout(self):
if self.rect().width() == 0 or self.rect().height() == 0:
return
pixmap = self.pixmap
pwidth, pheight = pixmap.width(), pixmap.height()
try:
self.pwidth, self.pheight = fit_image(pwidth, pheight, self.rect().width(), self.rect().height())[1:]
except:
self.pwidth, self.pheight = self.rect().width() - 1, self.rect().height() - 1
self.current_pixmap_size = QSize(self.pwidth, self.pheight)
self.animation.setEndValue(self.current_pixmap_size)
def show_data(self, data):
self.animation.stop()
same_item = getattr(data, "id", True) == self.data.get("id", False)
self.data = {"id": data.get("id", None)}
if data.cover_data[1]:
self.pixmap = QPixmap.fromImage(data.cover_data[1])
if self.pixmap.isNull() or self.pixmap.width() < 5 or self.pixmap.height() < 5:
self.pixmap = self.default_pixmap
else:
self.pixmap = self.default_pixmap
self.do_layout()
self.update()
if not same_item and not config["disable_animations"] and self.isVisible():
self.animation.start()
def paintEvent(self, event):
canvas_size = self.rect()
width = self.current_pixmap_size.width()
extrax = canvas_size.width() - width
if extrax < 0:
extrax = 0
x = int(extrax / 2.0)
height = self.current_pixmap_size.height()
extray = canvas_size.height() - height
if extray < 0:
extray = 0
y = int(extray / 2.0)
target = QRect(x, y, width, height)
p = QPainter(self)
p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
p.drawPixmap(target, self.pixmap.scaled(target.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation))
if gprefs["bd_overlay_cover_size"]:
sztgt = target.adjusted(0, 0, 0, -4)
f = p.font()
f.setBold(True)
p.setFont(f)
sz = u"\u00a0%d x %d\u00a0" % (self.pixmap.width(), self.pixmap.height())
flags = Qt.AlignBottom | Qt.AlignRight | Qt.TextSingleLine
szrect = p.boundingRect(sztgt, flags, sz)
p.fillRect(szrect.adjusted(0, 0, 0, 4), QColor(0, 0, 0, 200))
p.setPen(QPen(QColor(255, 255, 255)))
p.drawText(sztgt, flags, sz)
p.end()
current_pixmap_size = pyqtProperty("QSize", fget=lambda self: self._current_pixmap_size, fset=setCurrentPixmapSize)
def contextMenuEvent(self, ev):
cm = QMenu(self)
paste = cm.addAction(_("Paste Cover"))
copy = cm.addAction(_("Copy Cover"))
remove = cm.addAction(_("Remove Cover"))
if not QApplication.instance().clipboard().mimeData().hasImage():
paste.setEnabled(False)
copy.triggered.connect(self.copy_to_clipboard)
paste.triggered.connect(self.paste_from_clipboard)
remove.triggered.connect(self.remove_cover)
cm.exec_(ev.globalPos())
#.........这里部分代码省略.........