@@ -706,6 +706,64 @@ class EbookReader:
|
||||
'font_scale': self.base_font_scale
|
||||
}
|
||||
|
||||
# ===== Settings Persistence =====
|
||||
|
||||
def get_current_settings(self) -> Dict[str, Any]:
|
||||
"""
|
||||
Get current rendering settings.
|
||||
|
||||
Returns:
|
||||
Dictionary with all current settings
|
||||
"""
|
||||
return {
|
||||
'font_scale': self.base_font_scale,
|
||||
'line_spacing': self.page_style.line_spacing if self.manager else 5,
|
||||
'inter_block_spacing': self.page_style.inter_block_spacing if self.manager else 15,
|
||||
'word_spacing': self.page_style.word_spacing if self.manager else 0
|
||||
}
|
||||
|
||||
def apply_settings(self, settings: Dict[str, Any]) -> bool:
|
||||
"""
|
||||
Apply rendering settings from a settings dictionary.
|
||||
|
||||
This should be called after loading a book to restore user preferences.
|
||||
|
||||
Args:
|
||||
settings: Dictionary with settings (font_scale, line_spacing, etc.)
|
||||
|
||||
Returns:
|
||||
True if settings applied successfully, False otherwise
|
||||
"""
|
||||
if not self.manager:
|
||||
return False
|
||||
|
||||
try:
|
||||
# Apply font scale
|
||||
font_scale = settings.get('font_scale', 1.0)
|
||||
if font_scale != self.base_font_scale:
|
||||
self.set_font_size(font_scale)
|
||||
|
||||
# Apply line spacing
|
||||
line_spacing = settings.get('line_spacing', 5)
|
||||
if line_spacing != self.page_style.line_spacing:
|
||||
self.set_line_spacing(line_spacing)
|
||||
|
||||
# Apply inter-block spacing
|
||||
inter_block_spacing = settings.get('inter_block_spacing', 15)
|
||||
if inter_block_spacing != self.page_style.inter_block_spacing:
|
||||
self.set_inter_block_spacing(inter_block_spacing)
|
||||
|
||||
# Apply word spacing
|
||||
word_spacing = settings.get('word_spacing', 0)
|
||||
if word_spacing != self.page_style.word_spacing:
|
||||
self.set_word_spacing(word_spacing)
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error applying settings: {e}")
|
||||
return False
|
||||
|
||||
# ===== Gesture Handling =====
|
||||
# All business logic for touch input is handled here
|
||||
|
||||
@@ -1066,6 +1124,16 @@ class EbookReader:
|
||||
"word_spacing": self.page_style.word_spacing
|
||||
})
|
||||
|
||||
# Parse "action:command" format for other actions
|
||||
elif link_target.startswith("action:"):
|
||||
action = link_target.split(":", 1)[1]
|
||||
|
||||
if action == "back_to_library":
|
||||
# Close the overlay first
|
||||
self.close_overlay()
|
||||
# Return a special action for the application to handle
|
||||
return GestureResponse(ActionType.BACK_TO_LIBRARY, {})
|
||||
|
||||
# Not a setting control, close overlay
|
||||
self.close_overlay()
|
||||
return GestureResponse(ActionType.OVERLAY_CLOSED, {})
|
||||
|
||||
@@ -126,3 +126,4 @@ class ActionType:
|
||||
OVERLAY_CLOSED = "overlay_closed"
|
||||
CHAPTER_SELECTED = "chapter_selected"
|
||||
SETTING_CHANGED = "setting_changed"
|
||||
BACK_TO_LIBRARY = "back_to_library"
|
||||
|
||||
@@ -278,6 +278,12 @@ def generate_settings_overlay(
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div style="margin: 20px 0;">
|
||||
<p style="padding: 15px; margin: 5px 0; background-color: #dc3545; text-align: center; border-radius: 5px;">
|
||||
<a href="action:back_to_library" style="text-decoration: none; color: white; font-weight: bold; font-size: 14px;">◄ Back to Library</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<p style="text-align: center; margin: 15px 0 0 0; padding-top: 12px;
|
||||
border-top: 2px solid #ccc; color: #888; font-size: 11px;">
|
||||
Changes apply in real-time • Tap outside to close
|
||||
|
||||
+15
-1
@@ -78,10 +78,11 @@ class LibraryState:
|
||||
|
||||
@dataclass
|
||||
class Settings:
|
||||
"""User settings"""
|
||||
"""User settings for rendering and display"""
|
||||
font_scale: float = 1.0
|
||||
line_spacing: int = 5
|
||||
inter_block_spacing: int = 15
|
||||
word_spacing: int = 0 # Default word spacing
|
||||
brightness: int = 8
|
||||
theme: str = "day"
|
||||
|
||||
@@ -96,6 +97,7 @@ class Settings:
|
||||
font_scale=data.get('font_scale', 1.0),
|
||||
line_spacing=data.get('line_spacing', 5),
|
||||
inter_block_spacing=data.get('inter_block_spacing', 15),
|
||||
word_spacing=data.get('word_spacing', 0),
|
||||
brightness=data.get('brightness', 8),
|
||||
theme=data.get('theme', 'day')
|
||||
)
|
||||
@@ -374,6 +376,18 @@ class StateManager:
|
||||
setattr(self.state.settings, key, value)
|
||||
self._dirty = True
|
||||
|
||||
def update_settings(self, settings_dict: Dict[str, Any]):
|
||||
"""
|
||||
Update multiple settings at once.
|
||||
|
||||
Args:
|
||||
settings_dict: Dictionary with setting keys and values
|
||||
"""
|
||||
for key, value in settings_dict.items():
|
||||
if hasattr(self.state.settings, key):
|
||||
setattr(self.state.settings, key, value)
|
||||
self._dirty = True
|
||||
|
||||
def get_library_state(self) -> LibraryState:
|
||||
"""Get library state"""
|
||||
return self.state.library
|
||||
|
||||
Reference in New Issue
Block a user