Skip to content

Commit 1ba61bb

Browse files
committed
Add button icons in configuration window
1 parent 1fc58c9 commit 1ba61bb

4 files changed

Lines changed: 139 additions & 16 deletions

File tree

configure.py

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@
3636
try:
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+
4748
except Exception as e:
4849
print("""Import error: %s
4950
Please follow start guide to install required packages: https://github.com/mathoudebine/turing-smart-screen-python/wiki/System-monitor-:-how-to-start
@@ -169,6 +170,26 @@
169170
DISABLED_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+
172193
def 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\nfolder",
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\nfolder", 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)

res/fonts/NotoColorEmoji/LICENSE

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
Copyright 2013 Google LLC
2+
3+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
4+
This license is copied below, and is also available with a FAQ at:
5+
https://scripts.sil.org/OFL
6+
7+
8+
-----------------------------------------------------------
9+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10+
-----------------------------------------------------------
11+
12+
PREAMBLE
13+
The goals of the Open Font License (OFL) are to stimulate worldwide
14+
development of collaborative font projects, to support the font creation
15+
efforts of academic and linguistic communities, and to provide a free and
16+
open framework in which fonts may be shared and improved in partnership
17+
with others.
18+
19+
The OFL allows the licensed fonts to be used, studied, modified and
20+
redistributed freely as long as they are not sold by themselves. The
21+
fonts, including any derivative works, can be bundled, embedded,
22+
redistributed and/or sold with any software provided that any reserved
23+
names are not used by derivative works. The fonts and derivatives,
24+
however, cannot be released under any other type of license. The
25+
requirement for fonts to remain under this license does not apply
26+
to any document created using the fonts or their derivatives.
27+
28+
DEFINITIONS
29+
"Font Software" refers to the set of files released by the Copyright
30+
Holder(s) under this license and clearly marked as such. This may
31+
include source files, build scripts and documentation.
32+
33+
"Reserved Font Name" refers to any names specified as such after the
34+
copyright statement(s).
35+
36+
"Original Version" refers to the collection of Font Software components as
37+
distributed by the Copyright Holder(s).
38+
39+
"Modified Version" refers to any derivative made by adding to, deleting,
40+
or substituting -- in part or in whole -- any of the components of the
41+
Original Version, by changing formats or by porting the Font Software to a
42+
new environment.
43+
44+
"Author" refers to any designer, engineer, programmer, technical
45+
writer or other person who contributed to the Font Software.
46+
47+
PERMISSION & CONDITIONS
48+
Permission is hereby granted, free of charge, to any person obtaining
49+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
50+
redistribute, and sell modified and unmodified copies of the Font
51+
Software, subject to the following conditions:
52+
53+
1) Neither the Font Software nor any of its individual components,
54+
in Original or Modified Versions, may be sold by itself.
55+
56+
2) Original or Modified Versions of the Font Software may be bundled,
57+
redistributed and/or sold with any software, provided that each copy
58+
contains the above copyright notice and this license. These can be
59+
included either as stand-alone text files, human-readable headers or
60+
in the appropriate machine-readable metadata fields within text or
61+
binary files as long as those fields can be easily viewed by the user.
62+
63+
3) No Modified Version of the Font Software may use the Reserved Font
64+
Name(s) unless explicit written permission is granted by the corresponding
65+
Copyright Holder. This restriction only applies to the primary font name as
66+
presented to the users.
67+
68+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69+
Software shall not be used to promote, endorse or advertise any
70+
Modified Version, except to acknowledge the contribution(s) of the
71+
Copyright Holder(s) and the Author(s) or with their explicit written
72+
permission.
73+
74+
5) The Font Software, modified or unmodified, in part or in whole,
75+
must be distributed entirely under this license, and must not be
76+
distributed under any other license. The requirement for fonts to
77+
remain under this license does not apply to any document created
78+
using the Font Software.
79+
80+
TERMINATION
81+
This license becomes null and void if any of the above conditions are
82+
not met.
83+
84+
DISCLAIMER
85+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93+
OTHER DEALINGS IN THE FONT SOFTWARE.
10.2 MB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/googlefonts/noto-emoji/raw/main/fonts/NotoColorEmoji.ttf

0 commit comments

Comments
 (0)