mirror of https://github.com/gmbrax/Pilgrim.git
				
				
				
			Compare commits
	
		
			10 Commits
		
	
	
		
			1312674186
			...
			f2fc60300f
		
	
	| Author | SHA1 | Date | 
|---|---|---|
| 
							
							
								 | 
						f2fc60300f | |
| 
							
							
								 | 
						6dc2c01325 | |
| 
							
							
								 | 
						860fee2d19 | |
| 
							
							
								 | 
						fce47db0f8 | |
| 
							
							
								 | 
						6ab35e680d | |
| 
							
							
								 | 
						de0e415ee2 | |
| 
							
							
								 | 
						f42d15048c | |
| 
							
							
								 | 
						40104db405 | |
| 
							
							
								 | 
						d13750f725 | |
| 
							
							
								 | 
						0b9b3c8cf0 | 
| 
						 | 
					@ -25,7 +25,7 @@ structured and accessible format.
 | 
				
			||||||
To install the application you must issue the command:
 | 
					To install the application you must issue the command:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```bash
 | 
					```bash
 | 
				
			||||||
 pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple Pilgrim
 | 
					pip install pilgrim
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Usage
 | 
					## Usage
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,33 +24,26 @@ class EditEntryScreen(Screen):
 | 
				
			||||||
    BINDINGS = [
 | 
					    BINDINGS = [
 | 
				
			||||||
        Binding("ctrl+q", "quit", "Quit"),
 | 
					        Binding("ctrl+q", "quit", "Quit"),
 | 
				
			||||||
        Binding("ctrl+s", "save", "Save"),
 | 
					        Binding("ctrl+s", "save", "Save"),
 | 
				
			||||||
        Binding("shift+f5", "new_entry", "New Entry"),
 | 
					        Binding("ctrl+n", "new_entry", "New Entry"),
 | 
				
			||||||
        Binding("f5", "next_entry", "Next Entry"),
 | 
					        Binding("ctrl+shift+n", "next_entry", "Next Entry"),
 | 
				
			||||||
        Binding("f4", "prev_entry", "Previous Entry"),
 | 
					        Binding("ctrl+shift+p", "prev_entry", "Previous Entry"),
 | 
				
			||||||
        Binding("ctrl+r", "rename_entry", "Rename Entry"),
 | 
					        Binding("ctrl+r", "rename_entry", "Rename Entry"),
 | 
				
			||||||
        Binding("f8", "toggle_sidebar", "Toggle Photos"),
 | 
					        Binding("f8", "toggle_sidebar", "Toggle Photos"),
 | 
				
			||||||
        Binding("f9", "toggle_focus", "Toggle Focus"),
 | 
					        Binding("f9", "toggle_focus", "Toggle Focus"),
 | 
				
			||||||
        Binding("escape", "back_to_list", "Back to List"),
 | 
					        Binding("escape", "back_to_list", "Back to List"),
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, diary_id: int = 1,create_new: bool = True):
 | 
					    def __init__(self, diary_id: int = 1):
 | 
				
			||||||
        super().__init__()
 | 
					        super().__init__()
 | 
				
			||||||
 | 
					 | 
				
			||||||
        if create_new:
 | 
					 | 
				
			||||||
            self.current_entry_index = -1
 | 
					 | 
				
			||||||
            self.is_new_entry = True
 | 
					 | 
				
			||||||
            self.next_entry_id = None
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            self.is_new_entry = False
 | 
					 | 
				
			||||||
            self.current_entry_index = 0
 | 
					 | 
				
			||||||
            self.next_entry_id = 1
 | 
					 | 
				
			||||||
        self.new_entry_title = ""
 | 
					 | 
				
			||||||
        self.new_entry_content = ""
 | 
					 | 
				
			||||||
        self.diary_id = diary_id
 | 
					        self.diary_id = diary_id
 | 
				
			||||||
        self.diary_name = f"Diary {diary_id}"
 | 
					        self.diary_name = f"Diary {diary_id}"
 | 
				
			||||||
 | 
					        self.current_entry_index = 0
 | 
				
			||||||
        self.entries: List[Entry] = []
 | 
					        self.entries: List[Entry] = []
 | 
				
			||||||
 | 
					        self.is_new_entry = False
 | 
				
			||||||
        self.has_unsaved_changes = False
 | 
					        self.has_unsaved_changes = False
 | 
				
			||||||
 | 
					        self.new_entry_content = ""
 | 
				
			||||||
 | 
					        self.new_entry_title = "New Entry"
 | 
				
			||||||
 | 
					        self.next_entry_id = 1
 | 
				
			||||||
        self._updating_display = False
 | 
					        self._updating_display = False
 | 
				
			||||||
        self._original_content = ""
 | 
					        self._original_content = ""
 | 
				
			||||||
        self.is_refreshing = False
 | 
					        self.is_refreshing = False
 | 
				
			||||||
| 
						 | 
					@ -913,22 +906,11 @@ class EditEntryScreen(Screen):
 | 
				
			||||||
                self.notify("Empty entry cannot be saved")
 | 
					                self.notify("Empty entry cannot be saved")
 | 
				
			||||||
                return
 | 
					                return
 | 
				
			||||||
            # Passe a lista de fotos para o método de criação
 | 
					            # Passe a lista de fotos para o método de criação
 | 
				
			||||||
            if self.new_entry_title == "":
 | 
					 | 
				
			||||||
               self.app.push_screen(RenameEntryModal(current_name=""), lambda result: self._handle_save_after_rename(result,content,
 | 
					 | 
				
			||||||
                                                                                               photos_to_link))
 | 
					 | 
				
			||||||
            else:
 | 
					 | 
				
			||||||
            self.call_later(self._async_create_entry, content, photos_to_link)
 | 
					            self.call_later(self._async_create_entry, content, photos_to_link)
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            # Passe a lista de fotos para o método de atualização
 | 
					            # Passe a lista de fotos para o método de atualização
 | 
				
			||||||
            self.call_later(self._async_update_entry, content, photos_to_link)
 | 
					            self.call_later(self._async_update_entry, content, photos_to_link)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _handle_save_after_rename(self, result: str | None, content: str, photos_to_link: List[Photo]) -> None:
 | 
					 | 
				
			||||||
        if result is None:
 | 
					 | 
				
			||||||
            self.notify("Save cancelled")
 | 
					 | 
				
			||||||
            return
 | 
					 | 
				
			||||||
        self.new_entry_title = result
 | 
					 | 
				
			||||||
        self.call_later(self._async_create_entry, content, photos_to_link)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    async def _async_create_entry(self, content: str, photos_to_link: List[Photo]):
 | 
					    async def _async_create_entry(self, content: str, photos_to_link: List[Photo]):
 | 
				
			||||||
        """Creates a new entry and links the referenced photos."""
 | 
					        """Creates a new entry and links the referenced photos."""
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
| 
						 | 
					@ -955,7 +937,7 @@ class EditEntryScreen(Screen):
 | 
				
			||||||
                self.is_new_entry = False
 | 
					                self.is_new_entry = False
 | 
				
			||||||
                self.has_unsaved_changes = False
 | 
					                self.has_unsaved_changes = False
 | 
				
			||||||
                self._original_content = new_entry.text
 | 
					                self._original_content = new_entry.text
 | 
				
			||||||
                self.new_entry_title = ""
 | 
					                self.new_entry_title = "New Entry"
 | 
				
			||||||
                self.next_entry_id = max(entry.id for entry in self.entries) + 1
 | 
					                self.next_entry_id = max(entry.id for entry in self.entries) + 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                self._update_entry_display()
 | 
					                self._update_entry_display()
 | 
				
			||||||
| 
						 | 
					@ -1000,36 +982,28 @@ class EditEntryScreen(Screen):
 | 
				
			||||||
        except Exception as e:
 | 
					        except Exception as e:
 | 
				
			||||||
            self.notify(f"Error updating entry: {str(e)}")
 | 
					            self.notify(f"Error updating entry: {str(e)}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def check_key(self, event):
 | 
					    def on_key(self, event):
 | 
				
			||||||
        """Check for custom key handling before bindings are processed"""
 | 
					        # Sidebar contextual shortcuts
 | 
				
			||||||
 | 
					 | 
				
			||||||
        # Sidebar shortcuts
 | 
					 | 
				
			||||||
        if self.sidebar_focused and self.sidebar_visible:
 | 
					        if self.sidebar_focused and self.sidebar_visible:
 | 
				
			||||||
            sidebar_keys = ["i", "n", "d", "e"]
 | 
					
 | 
				
			||||||
            if event.key in sidebar_keys:
 | 
					 | 
				
			||||||
            if event.key == "i":
 | 
					            if event.key == "i":
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                self.action_insert_photo()
 | 
					                self.action_insert_photo()
 | 
				
			||||||
 | 
					                event.stop()
 | 
				
			||||||
            elif event.key == "n":
 | 
					            elif event.key == "n":
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                self.action_ingest_new_photo()
 | 
					                self.action_ingest_new_photo()
 | 
				
			||||||
 | 
					                event.stop()
 | 
				
			||||||
            elif event.key == "d":
 | 
					            elif event.key == "d":
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                self.action_delete_photo()
 | 
					                self.action_delete_photo()
 | 
				
			||||||
 | 
					                event.stop()
 | 
				
			||||||
            elif event.key == "e":
 | 
					            elif event.key == "e":
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                self.action_edit_photo()
 | 
					                self.action_edit_photo()
 | 
				
			||||||
                return True  # Indica que o evento foi processado
 | 
					                event.stop()
 | 
				
			||||||
 | 
					        # Shift+Tab: remove indent
 | 
				
			||||||
        # Text area shortcuts
 | 
					        elif self.focused is self.text_entry and event.key == "shift+tab":
 | 
				
			||||||
        elif self.focused is self.text_entry:
 | 
					 | 
				
			||||||
            if event.key in ["tab", "shift+tab"]:
 | 
					 | 
				
			||||||
                if event.key == "shift+tab":
 | 
					 | 
				
			||||||
                    self._handle_shift_tab()
 | 
					 | 
				
			||||||
                elif event.key == "tab":
 | 
					 | 
				
			||||||
                    self.text_entry.insert('\t')
 | 
					 | 
				
			||||||
                return True  # Indica que o evento foi processado
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return False  # Não foi processado, continuar com bindings
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def _handle_shift_tab(self):
 | 
					 | 
				
			||||||
        """Handle shift+tab for removing indentation"""
 | 
					 | 
				
			||||||
            textarea = self.text_entry
 | 
					            textarea = self.text_entry
 | 
				
			||||||
            row, col = textarea.cursor_location
 | 
					            row, col = textarea.cursor_location
 | 
				
			||||||
            lines = textarea.text.splitlines()
 | 
					            lines = textarea.text.splitlines()
 | 
				
			||||||
| 
						 | 
					@ -1049,11 +1023,11 @@ class EditEntryScreen(Screen):
 | 
				
			||||||
                    lines[row] = line[to_remove:]
 | 
					                    lines[row] = line[to_remove:]
 | 
				
			||||||
                    textarea.text = '\n'.join(lines)
 | 
					                    textarea.text = '\n'.join(lines)
 | 
				
			||||||
                    textarea.cursor_location = (row, max(col - to_remove, 0))
 | 
					                    textarea.cursor_location = (row, max(col - to_remove, 0))
 | 
				
			||||||
 | 
					 | 
				
			||||||
    def on_key(self, event):
 | 
					 | 
				
			||||||
        if self.check_key(event):
 | 
					 | 
				
			||||||
            event.stop()
 | 
					            event.stop()
 | 
				
			||||||
            return
 | 
					        # Tab: insert tab
 | 
				
			||||||
 | 
					        elif self.focused is self.text_entry and event.key == "tab":
 | 
				
			||||||
 | 
					            self.text_entry.insert('\t')
 | 
				
			||||||
 | 
					            event.stop()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def on_footer_action(self, event) -> None:
 | 
					    def on_footer_action(self, event) -> None:
 | 
				
			||||||
        """Handle clicks on footer actions (Textual 3.x)."""
 | 
					        """Handle clicks on footer actions (Textual 3.x)."""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue