优化专署封面的渲染
parent
d4b0e78d12
commit
acb4d0c396
|
@ -4,9 +4,10 @@ import gi, cairo, math
|
|||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk, Gdk, GdkPixbuf
|
||||
|
||||
from utils import empty_pixbuf
|
||||
|
||||
class ScaleImage(Gtk.Image):
|
||||
def __init__(self, filepath):
|
||||
def __init__(self, filepath = empty_pixbuf):
|
||||
Gtk.Image.__init__(self)
|
||||
self.width = None
|
||||
self.height = None
|
||||
|
@ -17,7 +18,7 @@ class ScaleImage(Gtk.Image):
|
|||
if type(filepath) == str:
|
||||
self.origin = GdkPixbuf.Pixbuf.new_from_file(filepath)
|
||||
else:
|
||||
self.origin = filepath
|
||||
self.origin = filepath or empty_pixbuf
|
||||
|
||||
if self.width is None:
|
||||
self.pixbuf = self.origin
|
||||
|
@ -50,7 +51,7 @@ class ScaleImage(Gtk.Image):
|
|||
w = self.origin.get_width()
|
||||
h = self.origin.get_height()
|
||||
_size = min(w, h) # 按小边裁剪成正方形
|
||||
size = min(size, _size) # 缩放按最小值来
|
||||
# size = min(size, _size) # 缩放按最小值来
|
||||
self.width = size
|
||||
self.height = size
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ class SonistWindow(Gtk.Window):
|
|||
# 唱片
|
||||
disk = ScaleImage(image_dict['disk'])
|
||||
handler = ScaleImage(image_dict['handler'])
|
||||
album = ScaleImage(image_dict['album'])
|
||||
album = ScaleImage()
|
||||
|
||||
disk.resize(192, 192)
|
||||
album.clip_resize(128).set_radius(64)
|
||||
|
@ -332,8 +332,8 @@ class SonistWindow(Gtk.Window):
|
|||
self.update_album()
|
||||
|
||||
@idle
|
||||
def update_album(self, filepath = image_dict['avatar']):
|
||||
self.set_background_image(filepath)
|
||||
def update_album(self, filepath = None):
|
||||
self.set_background_image(filepath or image_dict['album'])
|
||||
self.album.reset(filepath, True).set_radius(64)
|
||||
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 13 KiB |
Binary file not shown.
Before Width: | Height: | Size: 73 KiB |
Loading…
Reference in New Issue