gtk: add .png icons support close #733
This commit is contained in:
parent
792e1bf8bf
commit
32fab0482f
@ -1,4 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import contextlib
|
||||||
import gi
|
import gi
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@ -108,16 +109,19 @@ class KlippyGtk:
|
|||||||
la.get_style_context().add_class(style)
|
la.get_style_context().add_class(style)
|
||||||
return la
|
return la
|
||||||
|
|
||||||
def Image(self, image_name, width=None, height=None):
|
def Image(self, image_name=None, width=None, height=None):
|
||||||
|
if image_name is None:
|
||||||
|
return Gtk.Image()
|
||||||
width = width if width is not None else self.img_width
|
width = width if width is not None else self.img_width
|
||||||
height = height if height is not None else self.img_height
|
height = height if height is not None else self.img_height
|
||||||
filename = os.path.join(self.themedir, f"{image_name}.svg")
|
filename = os.path.join(self.themedir, image_name)
|
||||||
if os.path.exists(filename):
|
for ext in ["svg", "png"]:
|
||||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(filename, int(width), int(height))
|
with contextlib.suppress(Exception):
|
||||||
return Gtk.Image.new_from_pixbuf(pixbuf)
|
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(f"{filename}.{ext}", int(width), int(height))
|
||||||
else:
|
if pixbuf is not None:
|
||||||
logging.error(f"Unable to find image {filename}")
|
return Gtk.Image.new_from_pixbuf(pixbuf)
|
||||||
return Gtk.Image()
|
logging.error(f"Unable to find image {filename}.{ext}")
|
||||||
|
return Gtk.Image()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def PixbufFromFile(filename, width=-1, height=-1):
|
def PixbufFromFile(filename, width=-1, height=-1):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user