3636try :
3737 import tkinter .ttk as ttk
3838 from tkinter import *
39- from PIL import ImageTk
39+ from PIL import ImageTk , ImageFont , ImageDraw
4040 import psutil
4141 import ruamel .yaml
4242 import sv_ttk
4343 from pathlib import Path
4444 from PIL import Image
4545 from serial .tools .list_ports import comports
4646 from tktooltip import ToolTip
47+
4748except Exception as e :
4849 print ("""Import error: %s
4950Please follow start guide to install required packages: https://github.com/mathoudebine/turing-smart-screen-python/wiki/System-monitor-:-how-to-start
169170DISABLED_COLOR = "#C0C0C0"
170171
171172
173+ def emoji_to_img (size , text ):
174+ # Use platform-specific emoji font
175+ if sys .platform == "win32" :
176+ font = ImageFont .truetype ("seguiemj.ttf" , size = int (round (size * 72 / 96 , 0 )))
177+ # pixels = points * 96 / 72 : 96 is windowsDPI
178+ im = Image .new ("RGBA" , (size , size ), (255 , 255 , 255 , 0 ))
179+ draw = ImageDraw .Draw (im )
180+ draw .text ((size / 2 , size / 2 ), text , embedded_color = True , font = font , anchor = "mm" )
181+ else :
182+ emoji_font = str (MAIN_DIRECTORY / "res" / "fonts" / "NotoColorEmoji" / "NotoColorEmoji.ttf" )
183+ # Noto Color Emoji font can only be used with size=109
184+ font = ImageFont .truetype (emoji_font , size = 109 )
185+ bbox = font .getbbox (text )
186+ im = Image .new ("RGBA" , bbox [2 :], (255 , 255 , 255 , 0 ))
187+ draw = ImageDraw .Draw (im )
188+ draw .text ((0 ,0 ), text , embedded_color = True , font = font )
189+ im .thumbnail ((size , size ), Image .Resampling .LANCZOS )
190+ return ImageTk .PhotoImage (im )
191+
192+
172193def get_theme_data (name : str ):
173194 dir = THEMES_DIR / name
174195
@@ -227,7 +248,7 @@ class TuringConfigWindow:
227248 def __init__ (self ):
228249 self .window = Tk ()
229250 self .window .title ('Turing System Monitor configuration' )
230- self .window .geometry ("820x580 " )
251+ self .window .geometry ("820x590 " )
231252 self .window .iconphoto (True , PhotoImage (file = str (
232253 MAIN_DIRECTORY / "res/icons/monitor-icon-17865/64.png" ))) # When window gets focus again, reload theme preview in case it has been updated by theme editor
233254 self .window .bind ("<FocusIn>" , self .on_theme_change )
@@ -237,7 +258,7 @@ def __init__(self):
237258 self .more_config_window = MoreConfigWindow (self )
238259
239260 # Make TK look better with Sun Valley ttk theme
240- sv_ttk .set_theme ( "light" )
261+ sv_ttk .use_light_theme ( )
241262
242263 self .theme_preview_img = None
243264 self .theme_preview = ttk .Label (self .window )
@@ -336,22 +357,30 @@ def __init__(self):
336357 version_label = ttk .Label (self .window , text = version , foreground = DISABLED_COLOR )
337358 version_label .place (x = 5 , y = 550 )
338359
339- self .weather_ping_btn = ttk .Button (self .window , text = "Weather & ping" ,
340- command = lambda : self .on_weatherping_click ())
341- self .weather_ping_btn .place (x = 80 , y = 520 , height = 50 , width = 130 )
360+ self .weather_ping_emoji = emoji_to_img (20 , "⛅" )
361+ self .weather_ping_btn = ttk .Button (self .window , text = "Weather\n & Ping" , image = self .weather_ping_emoji ,
362+ compound = "left" , command = lambda : self .on_weatherping_click ())
363+ self .weather_ping_btn .place (x = 80 , y = 520 , height = 60 , width = 130 )
342364
343- self .open_theme_folder_btn = ttk .Button (self .window , text = "Open themes\n folder" ,
344- command = lambda : self .on_open_theme_folder_click ())
345- self .open_theme_folder_btn .place (x = 220 , y = 520 , height = 50 , width = 130 )
365+ self .open_theme_emoji = emoji_to_img (20 , "📂" )
366+ self .open_theme_folder_btn = ttk .Button (self .window , text = "Open themes\n folder" , image = self .open_theme_emoji ,
367+ compound = "left" , command = lambda : self .on_open_theme_folder_click ())
368+ self .open_theme_folder_btn .place (x = 220 , y = 520 , height = 60 , width = 130 )
346369
347- self .edit_theme_btn = ttk .Button (self .window , text = "Edit theme" , command = lambda : self .on_theme_editor_click ())
348- self .edit_theme_btn .place (x = 360 , y = 520 , height = 50 , width = 130 )
370+ self .edit_theme_emoji = emoji_to_img (20 , "🎨" )
371+ self .edit_theme_btn = ttk .Button (self .window , text = "Edit theme" , image = self .edit_theme_emoji , compound = "left" ,
372+ command = lambda : self .on_theme_editor_click ())
373+ self .edit_theme_btn .place (x = 360 , y = 520 , height = 60 , width = 130 )
349374
350- self .save_btn = ttk .Button (self .window , text = "Save settings" , command = lambda : self .on_save_click ())
351- self .save_btn .place (x = 500 , y = 520 , height = 50 , width = 130 )
375+ self .save_emoji = emoji_to_img (20 , "💾" )
376+ self .save_btn = ttk .Button (self .window , text = "Save settings" , image = self .save_emoji , compound = "left" ,
377+ command = lambda : self .on_save_click ())
378+ self .save_btn .place (x = 500 , y = 520 , height = 60 , width = 130 )
352379
353- self .save_run_btn = ttk .Button (self .window , text = "Save and run" , command = lambda : self .on_saverun_click ())
354- self .save_run_btn .place (x = 640 , y = 520 , height = 50 , width = 130 )
380+ self .save_run_emoji = emoji_to_img (20 , "▶️" )
381+ self .save_run_btn = ttk .Button (self .window , text = "Save and run" , image = self .save_run_emoji , compound = "left" ,
382+ command = lambda : self .on_saverun_click ())
383+ self .save_run_btn .place (x = 640 , y = 520 , height = 60 , width = 140 )
355384
356385 self .config = None
357386 self .load_config_values ()
@@ -657,7 +686,7 @@ def __init__(self, main_window: TuringConfigWindow):
657686 self .main_window = main_window
658687
659688 # Make TK look better with Sun Valley ttk theme
660- sv_ttk .set_theme ( "light" )
689+ sv_ttk .use_light_theme ( )
661690
662691 self .ping_label = ttk .Label (self .window , text = 'Hostname / IP to ping' )
663692 self .ping_label .place (x = 10 , y = 10 )
0 commit comments