11import gi
2- gi .require_version ('Gtk' , '4.0' )
3- from gi .repository import Gtk , Gdk , GLib
4- import subprocess
5- import shlex
6- import locale
2+
3+ gi .require_version ("Gtk" , "4.0" )
74import gettext
5+ import locale
86import os
7+ import shlex
8+ import subprocess
9+
10+ from gi .repository import Gdk , GdkPixbuf , GLib , Gtk
911
1012# Set up gettext for application localization.
11- DOMAIN = ' biglinux-welcome'
12- LOCALE_DIR = ' /usr/share/locale'
13- locale .setlocale (locale .LC_ALL , '' )
13+ DOMAIN = " biglinux-welcome"
14+ LOCALE_DIR = " /usr/share/locale"
15+ locale .setlocale (locale .LC_ALL , "" )
1416locale .bindtextdomain (DOMAIN , LOCALE_DIR )
1517locale .textdomain (DOMAIN )
1618gettext .bindtextdomain (DOMAIN , LOCALE_DIR )
1921
2022APP_PATH = None
2123
24+
2225class ActionWidget (Gtk .Box ):
2326 """
2427 A custom widget that can be either a clickable button with an icon and label,
2528 or a static image with a label.
2629 """
30+
2731 def __init__ (self , label , icon_name , action_type , command , ** kwargs ):
2832 super ().__init__ (orientation = Gtk .Orientation .VERTICAL , spacing = 6 , ** kwargs )
2933
@@ -37,10 +41,25 @@ def __init__(self, label, icon_name, action_type, command, **kwargs):
3741
3842 def build_image_widget (self , label , icon_name ):
3943 """Builds a non-clickable image widget."""
40- # Icon/Image
44+ # Icon/Image - Use GdkPixbuf for sharp rendering
4145 image_path = os .path .join (APP_PATH , "image" , icon_name )
42- image = Gtk .Image .new_from_file (image_path )
43- image .set_pixel_size (200 )
46+
47+ try :
48+ pixbuf = GdkPixbuf .Pixbuf .new_from_file_at_size (image_path , 64 , 64 )
49+ image = Gtk .Image .new_from_pixbuf (pixbuf )
50+ image .set_pixel_size (64 )
51+ except GLib .Error as e :
52+ print (f"Error loading image { image_path } : { e } . Using fallback." )
53+ # Fallback
54+ fallback_path = os .path .join (APP_PATH , "image" , "main" , "image-missing-symbolic.svg" )
55+ try :
56+ pixbuf = GdkPixbuf .Pixbuf .new_from_file_at_size (fallback_path , 64 , 64 )
57+ image = Gtk .Image .new_from_pixbuf (pixbuf )
58+ image .set_pixel_size (64 )
59+ except GLib .Error :
60+ image = Gtk .Image .new_from_icon_name ("image-missing" )
61+ image .set_pixel_size (64 )
62+
4463 image .set_halign (Gtk .Align .CENTER )
4564 self .append (image )
4665
@@ -60,31 +79,40 @@ def build_button_widget(self, label, icon_name):
6079 content_box = Gtk .Box (orientation = Gtk .Orientation .VERTICAL , spacing = 6 )
6180 button .set_child (content_box )
6281
63- # Use Gtk.Image, which is simpler for theme icons
64- if icon_name .startswith ("image/" ) or "/" in icon_name or icon_name .endswith (".svg" ) or icon_name .endswith (".png" ):
65- # Try to load as file relative to APP_PATH
66-
67- potential_path = os .path .join (APP_PATH , icon_name )
68- if not os .path .exists (potential_path ) and icon_name .startswith ("image/" ):
69- pass
70-
71- if os .path .exists (potential_path ):
72- icon = Gtk .Image .new_from_file (potential_path )
73- else :
74- # Fallback: try inside image/ folder directly if not found
75- icon_path_in_image_folder = os .path .join (APP_PATH , "image" , os .path .basename (icon_name ))
76- if os .path .exists (icon_path_in_image_folder ):
77- icon = Gtk .Image .new_from_file (icon_path_in_image_folder )
78- else :
79- # Fallback to icon name if file not found
80- icon = Gtk .Image .new_from_icon_name (icon_name )
81-
82- # Use larger size for file images (like QR codes)
83- icon .set_pixel_size (200 )
82+ # Try to load from file - check both direct path and nested folder paths
83+ # Use GdkPixbuf to render SVG at exact size for sharpness (same strategy as browser_widget)
84+ icon_path = os .path .join (APP_PATH , "image" , icon_name )
85+ icon_size = 64 # Match browser page icon size
86+
87+ if os .path .exists (icon_path ):
88+ try :
89+ pixbuf = GdkPixbuf .Pixbuf .new_from_file_at_size (icon_path , icon_size , icon_size )
90+ icon = Gtk .Image .new_from_pixbuf (pixbuf )
91+ icon .set_pixel_size (icon_size )
92+ except GLib .Error as e :
93+ print (f"Error loading icon { icon_path } : { e } . Using fallback." )
94+ # Fallback to missing icon image
95+ fallback_path = os .path .join (APP_PATH , "image" , "main" , "image-missing-symbolic.svg" )
96+ try :
97+ pixbuf = GdkPixbuf .Pixbuf .new_from_file_at_size (fallback_path , 64 , 64 )
98+ icon = Gtk .Image .new_from_pixbuf (pixbuf )
99+ icon .set_pixel_size (64 )
100+ except GLib .Error :
101+ # Ultimate fallback
102+ icon = Gtk .Image .new_from_icon_name ("image-missing" )
103+ icon .set_pixel_size (64 )
84104 else :
85- icon = Gtk .Image .new_from_icon_name (icon_name )
86- icon .set_pixel_size (64 )
87-
105+ # Fallback to missing icon image
106+ fallback_path = os .path .join (APP_PATH , "image" , "main" , "image-missing-symbolic.svg" )
107+ try :
108+ pixbuf = GdkPixbuf .Pixbuf .new_from_file_at_size (fallback_path , 64 , 64 )
109+ icon = Gtk .Image .new_from_pixbuf (pixbuf )
110+ icon .set_pixel_size (64 )
111+ except GLib .Error :
112+ icon = Gtk .Image .new_from_icon_name ("image-missing" )
113+ icon .set_pixel_size (64 )
114+ print (f"Warning: Icon not found at { icon_path } , using fallback" )
115+
88116 content_box .append (icon )
89117
90118 # Label
0 commit comments