pre animation
This commit is contained in:
@@ -12,14 +12,6 @@ from dotenv import load_dotenv
|
|||||||
# Load environment variables
|
# Load environment variables
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
# Try to import pyglet for font loading
|
|
||||||
try:
|
|
||||||
import pyglet
|
|
||||||
PYGLET_AVAILABLE = True
|
|
||||||
except ImportError:
|
|
||||||
PYGLET_AVAILABLE = False
|
|
||||||
print("pyglet not available - custom fonts may not work properly")
|
|
||||||
|
|
||||||
class SteamWorkshopGUI:
|
class SteamWorkshopGUI:
|
||||||
def __init__(self, root):
|
def __init__(self, root):
|
||||||
self.root = root
|
self.root = root
|
||||||
@@ -54,108 +46,75 @@ class SteamWorkshopGUI:
|
|||||||
self.create_output_section(right_frame)
|
self.create_output_section(right_frame)
|
||||||
|
|
||||||
def load_custom_font(self):
|
def load_custom_font(self):
|
||||||
"""Load the RimWorld font using pyglet"""
|
"""Load the RimWorld font using Windows AddFontResourceEx with private flag"""
|
||||||
try:
|
try:
|
||||||
font_path = os.path.join("art", "RimWordFont4.ttf")
|
font_path = os.path.join("art", "RimWordFont4.ttf")
|
||||||
if os.path.exists(font_path):
|
if os.path.exists(font_path):
|
||||||
abs_font_path = os.path.abspath(font_path)
|
abs_font_path = os.path.abspath(font_path)
|
||||||
print(f"Font file found: {abs_font_path}")
|
|
||||||
|
|
||||||
if PYGLET_AVAILABLE:
|
# Use the Stack Overflow method with AddFontResourceEx
|
||||||
try:
|
success = self._load_font_private(abs_font_path)
|
||||||
# Use pyglet to add the font
|
|
||||||
pyglet.font.add_file(abs_font_path)
|
|
||||||
|
|
||||||
# Try to get the font family name from pyglet
|
if success:
|
||||||
# Load the font to get its actual family name
|
# Use the actual font family name from the TTF file
|
||||||
pyglet_font = pyglet.font.load(None, 12, bold=False, italic=False)
|
self.custom_font_family = "RimWordFont"
|
||||||
|
|
||||||
# Common RimWorld font family names to try
|
|
||||||
possible_names = [
|
|
||||||
"RimWorld",
|
|
||||||
"RimWorldFont",
|
|
||||||
"RimWordFont4",
|
|
||||||
"Calibri",
|
|
||||||
"Arial"
|
|
||||||
]
|
|
||||||
|
|
||||||
# Test each possible font name
|
|
||||||
for font_name in possible_names:
|
|
||||||
try:
|
|
||||||
test_font = font.Font(family=font_name, size=10)
|
|
||||||
# If we get here, the font worked
|
|
||||||
self.custom_font_family = font_name
|
|
||||||
self.custom_font_available = True
|
self.custom_font_available = True
|
||||||
print(f"Successfully loaded font with pyglet: {font_name}")
|
|
||||||
return
|
return
|
||||||
except Exception as e:
|
|
||||||
continue
|
|
||||||
|
|
||||||
print("pyglet loaded font but couldn't find working family name")
|
|
||||||
self.custom_font_available = False
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"pyglet font loading failed: {e}")
|
|
||||||
self.custom_font_available = False
|
|
||||||
else:
|
else:
|
||||||
print("pyglet not available, trying Windows registration...")
|
self.custom_font_available = False
|
||||||
# Fall back to Windows registration method
|
|
||||||
|
else:
|
||||||
|
self.custom_font_available = False
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
self.custom_font_available = False
|
||||||
|
|
||||||
|
# Initialize fallback values if font loading failed
|
||||||
|
if not hasattr(self, 'custom_font_available'):
|
||||||
|
self.custom_font_available = False
|
||||||
|
if not hasattr(self, 'custom_font_family'):
|
||||||
|
self.custom_font_family = None
|
||||||
|
|
||||||
|
def _load_font_private(self, fontpath):
|
||||||
|
"""
|
||||||
|
Load font privately using AddFontResourceEx
|
||||||
|
Based on Stack Overflow solution by Felipe
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
import ctypes
|
from ctypes import windll, byref, create_unicode_buffer
|
||||||
from ctypes import wintypes
|
|
||||||
|
|
||||||
# Add font resource to Windows
|
# Constants for AddFontResourceEx
|
||||||
gdi32 = ctypes.windll.gdi32
|
FR_PRIVATE = 0x10 # Font is private to this process
|
||||||
result = gdi32.AddFontResourceW(abs_font_path)
|
FR_NOT_ENUM = 0x20 # Font won't appear in font enumeration
|
||||||
|
|
||||||
if result > 0:
|
# Create unicode buffer for the font path
|
||||||
print(f"Successfully registered font with Windows")
|
pathbuf = create_unicode_buffer(fontpath)
|
||||||
|
|
||||||
# Notify Windows that fonts have changed
|
# Use AddFontResourceExW for Unicode strings
|
||||||
try:
|
AddFontResourceEx = windll.gdi32.AddFontResourceExW
|
||||||
HWND_BROADCAST = 0xFFFF
|
|
||||||
WM_FONTCHANGE = 0x001D
|
|
||||||
ctypes.windll.user32.SendMessageW(HWND_BROADCAST, WM_FONTCHANGE, 0, 0)
|
|
||||||
print("Sent font change notification to Windows")
|
|
||||||
except Exception as notify_error:
|
|
||||||
print(f"Could not send font change notification: {notify_error}")
|
|
||||||
|
|
||||||
# For Windows registration, let's try using the actual font file name
|
# Set flags: private (unloaded when process dies) and not enumerable
|
||||||
# Sometimes the family name is different from what we expect
|
flags = FR_PRIVATE | FR_NOT_ENUM
|
||||||
self.custom_font_family = "RimWorld" # Default assumption
|
|
||||||
self.custom_font_available = True
|
|
||||||
print(f"Using Windows-registered font: {self.custom_font_family}")
|
|
||||||
else:
|
|
||||||
print("Failed to register font with Windows")
|
|
||||||
self.custom_font_available = False
|
|
||||||
|
|
||||||
except Exception as e:
|
# Add the font resource
|
||||||
print(f"Windows font registration error: {e}")
|
numFontsAdded = AddFontResourceEx(byref(pathbuf), flags, 0)
|
||||||
self.custom_font_available = False
|
|
||||||
|
|
||||||
else:
|
return bool(numFontsAdded)
|
||||||
print(f"Font file not found: {font_path}")
|
|
||||||
self.custom_font_available = False
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception:
|
||||||
print(f"Error loading custom font: {e}")
|
return False
|
||||||
self.custom_font_available = False
|
|
||||||
|
|
||||||
def get_font(self, size=10, weight='normal'):
|
def get_font(self, size=10, weight='normal'):
|
||||||
"""Get font tuple for UI elements"""
|
"""Get font tuple for UI elements"""
|
||||||
if self.custom_font_available:
|
if self.custom_font_available and self.custom_font_family:
|
||||||
try:
|
try:
|
||||||
# Use the registered font family name
|
return font.Font(family=self.custom_font_family, size=size, weight=weight)
|
||||||
font_obj = font.Font(family=self.custom_font_family, size=size, weight=weight)
|
except Exception:
|
||||||
print(f"Created font: {self.custom_font_family}, size={size}, weight={weight}")
|
pass
|
||||||
return font_obj
|
|
||||||
except Exception as e:
|
# Fall back to system font
|
||||||
print(f"Error using custom font: {e}")
|
return font.Font(family='Arial', size=size, weight=weight)
|
||||||
# Fall back to a distinctive font so we can see the difference
|
|
||||||
return font.Font(family='Courier New', size=size, weight=weight)
|
|
||||||
else:
|
|
||||||
print(f"Using fallback font: Courier New, size={size}")
|
|
||||||
return font.Font(family='Courier New', size=size, weight=weight)
|
|
||||||
|
|
||||||
def setup_dark_theme(self):
|
def setup_dark_theme(self):
|
||||||
"""Configure dark theme colors"""
|
"""Configure dark theme colors"""
|
||||||
|
|||||||
Reference in New Issue
Block a user