From 3b321df6b03cb1e94306cf494fe58e6d6f473092 Mon Sep 17 00:00:00 2001 From: Jonathan Harris Date: Sun, 7 Apr 2019 14:56:58 +0100 Subject: [PATCH] Use "Euro Caps" font with transparent theme Addresses #412 --- EDMarketConnector.wxs | 4 ++++ README.md | 1 + setup.py | 1 + theme.py | 30 ++++++++++++++++-------------- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/EDMarketConnector.wxs b/EDMarketConnector.wxs index 91b8e38e..841926d9 100644 --- a/EDMarketConnector.wxs +++ b/EDMarketConnector.wxs @@ -156,6 +156,9 @@ + + + @@ -514,6 +517,7 @@ + diff --git a/README.md b/README.md index df8ae2ac..7619fcca 100644 --- a/README.md +++ b/README.md @@ -333,6 +333,7 @@ Acknowledgements * Uses [Sparkle](https://github.com/sparkle-project/Sparkle) by [Andy Matuschak](http://andymatuschak.org/) and the [Sparkle Project](https://github.com/sparkle-project). * Uses [WinSparkle](https://github.com/vslavik/winsparkle/wiki) by [Václav Slavík](https://github.com/vslavik). * Uses [OneSky](http://www.oneskyapp.com/) for [translation management](https://marginal.oneskyapp.com/collaboration/project?id=52710). +* Uses "Euro Caps" font by [Tom Oetken](https://www.dafont.com/profile.php?user=298681). License ------- diff --git a/setup.py b/setup.py index 19f48719..5e895118 100755 --- a/setup.py +++ b/setup.py @@ -124,6 +124,7 @@ elif sys.platform=='win32': requests.certs.where(), 'WinSparkle.dll', 'WinSparkle.pdb', # For debugging - don't include in package + 'EUROCAPS.TTF', 'commodity.csv', 'rare_commodity.csv', 'snd_good.wav', diff --git a/theme.py b/theme.py index 24c568c0..1005e7a4 100644 --- a/theme.py +++ b/theme.py @@ -6,6 +6,7 @@ # from sys import platform +from os.path import join import Tkinter as tk import ttk @@ -14,6 +15,16 @@ import tkFont from config import appname, applongname, config +if platform == 'win32': + import ctypes + from ctypes.wintypes import LPCWSTR, DWORD, LPCVOID + AddFontResourceEx = ctypes.windll.gdi32.AddFontResourceExW + AddFontResourceEx.restypes = [LPCWSTR, DWORD, LPCVOID] + FR_PRIVATE = 0x10 + FR_NOT_ENUM = 0x20 + AddFontResourceEx(join(config.respath, u'EUROCAPS.TTF'), FR_PRIVATE, 0) + + class _Theme: def __init__(self): @@ -56,15 +67,6 @@ class _Theme: style = ttk.Style() if platform == 'linux2': style.theme_use('clam') - elif platform == 'darwin': - # Default ttk font spacing looks bad on El Capitan - osxfont = tkFont.Font(family='TkDefaultFont', size=13, weight=tkFont.NORMAL) - style.configure('TLabel', font=osxfont) - style.configure('TButton', font=osxfont) - style.configure('TLabelframe.Label', font=osxfont) - style.configure('TCheckbutton', font=osxfont) - style.configure('TRadiobutton', font=osxfont) - style.configure('TEntry', font=osxfont) # Default dark theme colors if not config.get('dark_text'): @@ -85,8 +87,9 @@ class _Theme: 'font' : 'TkDefaultFont', } # Overrides - if platform == 'darwin': - self.current['font'] = osxfont + if theme > 1 and not 0x250 < ord(_('Cmdr')[0]) < 0x3000: + # Font only supports Latin 1 / Supplement / Extended, and a few General Punctuation and Mathematical Operators + self.current['font'] = tkFont.Font(family='Euro Caps', size=tkFont.Font().actual()['size'], weight=tkFont.NORMAL) else: # System colors @@ -102,7 +105,6 @@ class _Theme: # Overrides if platform == 'darwin': self.current['background'] = 'systemMovableModalBackground' - self.current['font'] = osxfont elif platform == 'win32': # Menu colors self.current['activebackground'] = 'SystemHighlight' @@ -124,7 +126,8 @@ class _Theme: elif 'cursor' in widget.keys() and str(widget['cursor']) not in ['', 'arrow']: # Hack - highlight widgets like HyperlinkLabel with a non-default cursor widget.configure(foreground = self.current['highlight'], - background = self.current['background']) + background = self.current['background'], + font = self.current['font']) elif 'activeforeground' in widget.keys(): # e.g. tk.Button, tk.Label, tk.Menu widget.configure(foreground = self.current['foreground'], @@ -172,7 +175,6 @@ class _Theme: window.setAppearance_(appearance) elif platform == 'win32': - import ctypes GWL_STYLE = -16 WS_MAXIMIZEBOX = 0x00010000 # tk8.5.9/win/tkWinWm.c:342