diff --git a/configure.py b/configure.py index 9d799969..ef6aaf0a 100755 --- a/configure.py +++ b/configure.py @@ -36,7 +36,7 @@ try: import tkinter.ttk as ttk from tkinter import * - from PIL import ImageTk + from PIL import ImageTk, ImageFont, ImageDraw import psutil import ruamel.yaml import sv_ttk @@ -44,6 +44,7 @@ from PIL import Image from serial.tools.list_ports import comports from tktooltip import ToolTip + except Exception as e: print("""Import error: %s 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 @@ DISABLED_COLOR = "#C0C0C0" +def emoji_to_img(size, text): + # Use platform-specific emoji font + if sys.platform == "win32": + font = ImageFont.truetype("seguiemj.ttf", size=int(round(size * 72 / 96, 0))) + # pixels = points * 96 / 72 : 96 is windowsDPI + im = Image.new("RGBA", (size, size), (255, 255, 255, 0)) + draw = ImageDraw.Draw(im) + draw.text((size / 2, size / 2), text, embedded_color=True, font=font, anchor="mm") + else: + emoji_font = str(MAIN_DIRECTORY / "res" / "fonts" / "NotoColorEmoji" / "NotoColorEmoji.ttf") + # Noto Color Emoji font can only be used with size=109 + font = ImageFont.truetype(emoji_font, size=109) + bbox = font.getbbox(text) + im = Image.new("RGBA", bbox[2:], (255, 255, 255, 0)) + draw = ImageDraw.Draw(im) + draw.text((0,0), text, embedded_color=True, font=font) + im.thumbnail((size, size), Image.Resampling.LANCZOS) + return ImageTk.PhotoImage(im) + + def get_theme_data(name: str): dir = THEMES_DIR / name @@ -227,7 +248,7 @@ class TuringConfigWindow: def __init__(self): self.window = Tk() self.window.title('Turing System Monitor configuration') - self.window.geometry("820x580") + self.window.geometry("820x590") self.window.iconphoto(True, PhotoImage(file=str( 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 self.window.bind("", self.on_theme_change) @@ -237,7 +258,7 @@ def __init__(self): self.more_config_window = MoreConfigWindow(self) # Make TK look better with Sun Valley ttk theme - sv_ttk.set_theme("light") + sv_ttk.use_light_theme() self.theme_preview_img = None self.theme_preview = ttk.Label(self.window) @@ -336,22 +357,30 @@ def __init__(self): version_label = ttk.Label(self.window, text=version, foreground=DISABLED_COLOR) version_label.place(x=5, y=550) - self.weather_ping_btn = ttk.Button(self.window, text="Weather & ping", - command=lambda: self.on_weatherping_click()) - self.weather_ping_btn.place(x=80, y=520, height=50, width=130) + self.weather_ping_emoji = emoji_to_img(20, "⛅") + self.weather_ping_btn = ttk.Button(self.window, text="Weather\n& Ping", image=self.weather_ping_emoji, + compound="left", command=lambda: self.on_weatherping_click()) + self.weather_ping_btn.place(x=80, y=520, height=60, width=130) - self.open_theme_folder_btn = ttk.Button(self.window, text="Open themes\nfolder", - command=lambda: self.on_open_theme_folder_click()) - self.open_theme_folder_btn.place(x=220, y=520, height=50, width=130) + self.open_theme_emoji = emoji_to_img(20, "📂") + self.open_theme_folder_btn = ttk.Button(self.window, text="Open themes\nfolder", image=self.open_theme_emoji, + compound="left", command=lambda: self.on_open_theme_folder_click()) + self.open_theme_folder_btn.place(x=220, y=520, height=60, width=130) - self.edit_theme_btn = ttk.Button(self.window, text="Edit theme", command=lambda: self.on_theme_editor_click()) - self.edit_theme_btn.place(x=360, y=520, height=50, width=130) + self.edit_theme_emoji = emoji_to_img(20, "🎨") + self.edit_theme_btn = ttk.Button(self.window, text="Edit theme", image=self.edit_theme_emoji, compound="left", + command=lambda: self.on_theme_editor_click()) + self.edit_theme_btn.place(x=360, y=520, height=60, width=130) - self.save_btn = ttk.Button(self.window, text="Save settings", command=lambda: self.on_save_click()) - self.save_btn.place(x=500, y=520, height=50, width=130) + self.save_emoji = emoji_to_img(20, "💾") + self.save_btn = ttk.Button(self.window, text="Save settings", image=self.save_emoji, compound="left", + command=lambda: self.on_save_click()) + self.save_btn.place(x=500, y=520, height=60, width=130) - self.save_run_btn = ttk.Button(self.window, text="Save and run", command=lambda: self.on_saverun_click()) - self.save_run_btn.place(x=640, y=520, height=50, width=130) + self.save_run_emoji = emoji_to_img(20, "▶️") + self.save_run_btn = ttk.Button(self.window, text="Save and run", image=self.save_run_emoji, compound="left", + command=lambda: self.on_saverun_click()) + self.save_run_btn.place(x=640, y=520, height=60, width=140) self.config = None self.load_config_values() @@ -657,7 +686,7 @@ def __init__(self, main_window: TuringConfigWindow): self.main_window = main_window # Make TK look better with Sun Valley ttk theme - sv_ttk.set_theme("light") + sv_ttk.use_light_theme() self.ping_label = ttk.Label(self.window, text='Hostname / IP to ping') self.ping_label.place(x=10, y=10) diff --git a/res/fonts/NotoColorEmoji/LICENSE b/res/fonts/NotoColorEmoji/LICENSE new file mode 100644 index 00000000..d09d3d0e --- /dev/null +++ b/res/fonts/NotoColorEmoji/LICENSE @@ -0,0 +1,93 @@ +Copyright 2013 Google LLC + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/res/fonts/NotoColorEmoji/NotoColorEmoji.ttf b/res/fonts/NotoColorEmoji/NotoColorEmoji.ttf new file mode 100644 index 00000000..943741df Binary files /dev/null and b/res/fonts/NotoColorEmoji/NotoColorEmoji.ttf differ diff --git a/res/fonts/NotoColorEmoji/source.txt b/res/fonts/NotoColorEmoji/source.txt new file mode 100644 index 00000000..c67a972d --- /dev/null +++ b/res/fonts/NotoColorEmoji/source.txt @@ -0,0 +1 @@ +https://github.com/googlefonts/noto-emoji/raw/main/fonts/NotoColorEmoji.ttf