mirror of https://github.com/gmbrax/Pilgrim.git
Compare commits
4 Commits
4aaef95596
...
5c03823df6
| Author | SHA1 | Date |
|---|---|---|
|
|
5c03823df6 | |
|
|
83fdb885a9 | |
|
|
0c6de1ea2e | |
|
|
ed8619fbf9 |
|
|
@ -9,6 +9,7 @@ from textual.containers import Vertical, Container, Horizontal
|
||||||
|
|
||||||
from pilgrim.models.travel_diary import TravelDiary
|
from pilgrim.models.travel_diary import TravelDiary
|
||||||
from pilgrim.ui.screens.about_screen import AboutScreen
|
from pilgrim.ui.screens.about_screen import AboutScreen
|
||||||
|
from pilgrim.ui.screens.diary_settings_screen import SettingsScreen
|
||||||
from pilgrim.ui.screens.edit_diary_modal import EditDiaryModal
|
from pilgrim.ui.screens.edit_diary_modal import EditDiaryModal
|
||||||
from pilgrim.ui.screens.new_diary_modal import NewDiaryModal
|
from pilgrim.ui.screens.new_diary_modal import NewDiaryModal
|
||||||
from pilgrim.ui.screens.edit_entry_screen import EditEntryScreen
|
from pilgrim.ui.screens.edit_entry_screen import EditEntryScreen
|
||||||
|
|
@ -23,6 +24,7 @@ class DiaryListScreen(Screen):
|
||||||
Binding("enter", "open_selected_diary", "Open diary"),
|
Binding("enter", "open_selected_diary", "Open diary"),
|
||||||
Binding("e", "edit_selected_diary", "Edit diary"),
|
Binding("e", "edit_selected_diary", "Edit diary"),
|
||||||
Binding("r", "force_refresh", "Force refresh"),
|
Binding("r", "force_refresh", "Force refresh"),
|
||||||
|
Binding("s", "diary_settings", "Open The Selected Diary Settings"),
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
@ -285,4 +287,14 @@ class DiaryListScreen(Screen):
|
||||||
|
|
||||||
def action_quit(self):
|
def action_quit(self):
|
||||||
"""Action to quit the application"""
|
"""Action to quit the application"""
|
||||||
self.app.exit()
|
self.app.exit()
|
||||||
|
|
||||||
|
def action_diary_settings(self):
|
||||||
|
if self.selected_diary_index is not None:
|
||||||
|
diary_id = self.diary_id_map.get(self.selected_diary_index)
|
||||||
|
if diary_id:
|
||||||
|
self.app.push_screen(SettingsScreen(diary_id=diary_id))
|
||||||
|
else:
|
||||||
|
self.notify("Invalid diary ID")
|
||||||
|
else:
|
||||||
|
self.notify("Select a diary to open the settings")
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ from textual.reactive import reactive
|
||||||
from textual.binding import Binding
|
from textual.binding import Binding
|
||||||
from textual import on
|
from textual import on
|
||||||
|
|
||||||
from pilgrim import TravelDiary
|
from pilgrim.models.travel_diary import TravelDiary
|
||||||
from pilgrim.ui.screens.modals.delete_all_entries_from_diary_modal import DeleteAllEntriesModal
|
from pilgrim.ui.screens.modals.delete_all_entries_from_diary_modal import DeleteAllEntriesModal
|
||||||
from pilgrim.ui.screens.modals.delete_all_photos_from_diary_modal import DeleteAllPhotosModal
|
from pilgrim.ui.screens.modals.delete_all_photos_from_diary_modal import DeleteAllPhotosModal
|
||||||
from pilgrim.ui.screens.modals.delete_diary_modal import DeleteDiaryModal
|
from pilgrim.ui.screens.modals.delete_diary_modal import DeleteDiaryModal
|
||||||
|
|
@ -19,21 +19,22 @@ class SettingsScreen(Screen):
|
||||||
Binding("escape","cancel","Cancel"),
|
Binding("escape","cancel","Cancel"),
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self,diary:TravelDiary):
|
def __init__(self,diary_id:int):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.current_diary = diary
|
self.current_diary = self.app.service_manager.get_travel_diary_service().read_by_id(diary_id)
|
||||||
|
|
||||||
self.header = Header()
|
self.header = Header()
|
||||||
self.footer = Footer()
|
self.footer = Footer()
|
||||||
self.title = "Settings"
|
self.title = "Settings"
|
||||||
|
|
||||||
self.diary_name = Static(self.current_diary.name,id="DiarySettingsScreen-DiaryName")
|
self.diary_name = Static(self.current_diary.name,id="DiarySettingsScreen-DiaryName")
|
||||||
self.is_the_diary_set_to_auto_open = False
|
self.notify(str(self.app.config_manager))
|
||||||
self.diary_entry_count = Static("0")
|
self.is_the_diary_set_to_auto_open = self.app.config_manager.get_auto_open_diary() == self.current_diary.name
|
||||||
self.diary_photo_count = Static("0")
|
self.diary_entry_count = Static(str(len(self.current_diary.entries)))
|
||||||
self.save_button = Button("Save")
|
self.diary_photo_count = Static(str(len(self.current_diary.photos)))
|
||||||
|
self.save_button = Button("Save",id="DiarySettingsScreen-SaveButton" )
|
||||||
self.cancel_button = Button("Cancel",id="DiarySettingsScreen-cancel_button")
|
self.cancel_button = Button("Cancel",id="DiarySettingsScreen-cancel_button")
|
||||||
self.apply_button = Button("Apply")
|
self.apply_button = Button("Apply",id="DiarySettingsScreen-ApplyButton")
|
||||||
self.backup_diary_button = Button("Backup Diary")
|
self.backup_diary_button = Button("Backup Diary")
|
||||||
self.delete_diary_button = Button("Delete Diary",id="DiarySettingsScreen-DeleteDiaryButton")
|
self.delete_diary_button = Button("Delete Diary",id="DiarySettingsScreen-DeleteDiaryButton")
|
||||||
self.delete_all_entries_button = Button("Delete All Entries",id="DiarySettingsScreen-DeleteAllEntriesButton")
|
self.delete_all_entries_button = Button("Delete All Entries",id="DiarySettingsScreen-DeleteAllEntriesButton")
|
||||||
|
|
@ -132,7 +133,7 @@ class SettingsScreen(Screen):
|
||||||
@on(Checkbox.Changed, "#set_auto_open_to_this_diary")
|
@on(Checkbox.Changed, "#set_auto_open_to_this_diary")
|
||||||
def on_checkbox_changed(self, event):
|
def on_checkbox_changed(self, event):
|
||||||
self.is_changed = not self.is_changed
|
self.is_changed = not self.is_changed
|
||||||
self.notify("Checkboxed")
|
|
||||||
|
|
||||||
@on(Button.Pressed, "#DiarySettingsScreen-cancel_button")
|
@on(Button.Pressed, "#DiarySettingsScreen-cancel_button")
|
||||||
def on_cancel_button_pressed(self, event):
|
def on_cancel_button_pressed(self, event):
|
||||||
|
|
@ -154,7 +155,15 @@ class SettingsScreen(Screen):
|
||||||
if self.is_changed:
|
if self.is_changed:
|
||||||
self.notify("Cancel button pressed, but changes are not saved",severity="error")
|
self.notify("Cancel button pressed, but changes are not saved",severity="error")
|
||||||
return
|
return
|
||||||
self.app.exit()
|
self.dismiss()
|
||||||
|
|
||||||
|
@on(Button.Pressed, "#DiarySettingsScreen-SaveButton")
|
||||||
|
def on_save_button_pressed(self, event):
|
||||||
|
self.action_save()
|
||||||
|
|
||||||
|
@on(Button.Pressed, "#DiarySettingsScreen-ApplyButton")
|
||||||
|
def on_apply_button_pressed(self, event):
|
||||||
|
self.action_apply()
|
||||||
|
|
||||||
|
|
||||||
def watch_is_changed(self, value):
|
def watch_is_changed(self, value):
|
||||||
|
|
@ -170,7 +179,102 @@ class SettingsScreen(Screen):
|
||||||
yield Footer()
|
yield Footer()
|
||||||
|
|
||||||
def on_mount(self):
|
def on_mount(self):
|
||||||
pass
|
if self.app.config_manager.get_auto_open_diary() == self.current_diary.name:
|
||||||
|
self.call_after_refresh(self.set_checkbox_state)
|
||||||
|
|
||||||
def set_checkbox_state(self):
|
def set_checkbox_state(self):
|
||||||
self.set_auto_open_to_this_diary.value = True
|
self.set_auto_open_to_this_diary.value = True
|
||||||
|
|
||||||
|
def _set_auto_open_diary(self,value):
|
||||||
|
|
||||||
|
self.app.config_manager.set_auto_open_diary(value)
|
||||||
|
self.app.config_manager.save_config()
|
||||||
|
self.is_changed = False
|
||||||
|
|
||||||
|
def _get_auto_open_diary(self):
|
||||||
|
return self.app.config_manager.get_auto_open_diary()
|
||||||
|
|
||||||
|
def _make_auto_open_diary_value(self):
|
||||||
|
value = None
|
||||||
|
if self.set_auto_open_to_this_diary.value:
|
||||||
|
value = self.current_diary.name
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def action_save(self):
|
||||||
|
|
||||||
|
if not self.is_changed:
|
||||||
|
self.dismiss()
|
||||||
|
return
|
||||||
|
|
||||||
|
value = self._make_auto_open_diary_value()
|
||||||
|
current_auto_open = self._get_auto_open_diary()
|
||||||
|
|
||||||
|
|
||||||
|
if current_auto_open is None:
|
||||||
|
self._set_auto_open_diary(value)
|
||||||
|
self.notify("Settings saved")
|
||||||
|
self.dismiss()
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
if current_auto_open == self.current_diary.name:
|
||||||
|
if value is None:
|
||||||
|
|
||||||
|
self._set_auto_open_diary(None)
|
||||||
|
self.notify("Auto-open disabled")
|
||||||
|
else:
|
||||||
|
|
||||||
|
self.is_changed = False
|
||||||
|
self.notify("No changes made")
|
||||||
|
self.dismiss()
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
if value is not None:
|
||||||
|
|
||||||
|
self._set_auto_open_diary(value)
|
||||||
|
self.notify(f"Auto-open changed from '{current_auto_open}' to '{self.current_diary.name}'")
|
||||||
|
self.dismiss()
|
||||||
|
else:
|
||||||
|
|
||||||
|
self.is_changed = False
|
||||||
|
self.notify("No changes made")
|
||||||
|
self.dismiss()
|
||||||
|
|
||||||
|
|
||||||
|
def action_apply(self):
|
||||||
|
|
||||||
|
if not self.is_changed:
|
||||||
|
return
|
||||||
|
|
||||||
|
value = self._make_auto_open_diary_value()
|
||||||
|
current_auto_open = self._get_auto_open_diary()
|
||||||
|
|
||||||
|
|
||||||
|
if current_auto_open is None:
|
||||||
|
self._set_auto_open_diary(value)
|
||||||
|
self.notify("Settings applied")
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
if current_auto_open == self.current_diary.name:
|
||||||
|
if value is None:
|
||||||
|
|
||||||
|
self._set_auto_open_diary(None)
|
||||||
|
self.notify("Auto-open disabled")
|
||||||
|
else:
|
||||||
|
|
||||||
|
self.is_changed = False
|
||||||
|
self.notify("No changes made")
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
if value is not None:
|
||||||
|
|
||||||
|
self._set_auto_open_diary(value)
|
||||||
|
self.notify(f"Auto-open changed from '{current_auto_open}' to '{self.current_diary.name}'")
|
||||||
|
else:
|
||||||
|
|
||||||
|
self.is_changed = False
|
||||||
|
self.notify("No changes made")
|
||||||
|
|
@ -46,6 +46,8 @@ class ConfigManager(metaclass=SingletonMeta):
|
||||||
|
|
||||||
if self.__data["settings"]["diary"]["auto_open_diary_on_startup"] == "":
|
if self.__data["settings"]["diary"]["auto_open_diary_on_startup"] == "":
|
||||||
self.auto_open_diary = None
|
self.auto_open_diary = None
|
||||||
|
else:
|
||||||
|
self.auto_open_diary = self.__data["settings"]["diary"]["auto_open_diary_on_startup"]
|
||||||
self.auto_open_new_diary = self.__data["settings"]["diary"]["auto_open_on_creation"]
|
self.auto_open_new_diary = self.__data["settings"]["diary"]["auto_open_on_creation"]
|
||||||
else:
|
else:
|
||||||
print("Error: config.toml not found.")
|
print("Error: config.toml not found.")
|
||||||
|
|
@ -103,5 +105,8 @@ class ConfigManager(metaclass=SingletonMeta):
|
||||||
def set_auto_open_diary(self, value: str):
|
def set_auto_open_diary(self, value: str):
|
||||||
self.auto_open_diary = value
|
self.auto_open_diary = value
|
||||||
|
|
||||||
|
def get_auto_open_diary(self):
|
||||||
|
return self.auto_open_diary
|
||||||
|
|
||||||
def set_auto_open_new_diary(self, value: bool):
|
def set_auto_open_new_diary(self, value: bool):
|
||||||
self.auto_open_new_diary = value
|
self.auto_open_new_diary = value
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue