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