pre animation

This commit is contained in:
2026-01-23 22:13:07 -05:00
parent e4c0a0c05a
commit 634543eea6

View File

@@ -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) if success:
# Use the actual font family name from the TTF file
# Try to get the font family name from pyglet self.custom_font_family = "RimWordFont"
# Load the font to get its actual family name self.custom_font_available = True
pyglet_font = pyglet.font.load(None, 12, bold=False, italic=False) return
# 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
print(f"Successfully loaded font with pyglet: {font_name}")
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
try:
import ctypes
from ctypes import wintypes
# Add font resource to Windows
gdi32 = ctypes.windll.gdi32
result = gdi32.AddFontResourceW(abs_font_path)
if result > 0:
print(f"Successfully registered font with Windows")
# Notify Windows that fonts have changed
try:
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
# Sometimes the family name is different from what we expect
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:
print(f"Windows font registration error: {e}")
self.custom_font_available = False
else: else:
print(f"Font file not found: {font_path}")
self.custom_font_available = False self.custom_font_available = False
except Exception as e: except Exception as e:
print(f"Error loading custom font: {e}")
self.custom_font_available = False 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:
from ctypes import windll, byref, create_unicode_buffer
# Constants for AddFontResourceEx
FR_PRIVATE = 0x10 # Font is private to this process
FR_NOT_ENUM = 0x20 # Font won't appear in font enumeration
# Create unicode buffer for the font path
pathbuf = create_unicode_buffer(fontpath)
# Use AddFontResourceExW for Unicode strings
AddFontResourceEx = windll.gdi32.AddFontResourceExW
# Set flags: private (unloaded when process dies) and not enumerable
flags = FR_PRIVATE | FR_NOT_ENUM
# Add the font resource
numFontsAdded = AddFontResourceEx(byref(pathbuf), flags, 0)
return bool(numFontsAdded)
except Exception:
return 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"""