From ff375e5f0020275294066dea58f65a7a32ca0ac8 Mon Sep 17 00:00:00 2001 From: Cimbali Date: Tue, 12 Dec 2023 13:57:27 +0000 Subject: [PATCH] Make annotations wrap Closes #303 --- pympress/extras.py | 12 ++++++++++++ pympress/share/xml/presenter.glade | 7 ++----- pympress/ui.py | 3 +++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pympress/extras.py b/pympress/extras.py index 3a0ba470..874265fe 100644 --- a/pympress/extras.py +++ b/pympress/extras.py @@ -46,6 +46,10 @@ class Annotations(object): annotations_treeview = None #: The containing :class:`~Gtk.ListStore` storing the annotations to be displayed annotations_liststore = None + #: The :class:`~Gtk.TreeViewColumn` where the text is rendered + annotation_column = None + #: The :class:`~Gtk.CellRendererText` defining how text is rendered + annotation_renderer = None #: The :class:`~Gtk.Entry` in which we are currently editing an annotation, or None editing = None @@ -92,6 +96,14 @@ def try_cancel(self): return True + def rewrap_annotations(self): + """ Update the wrap-width of the annotation column to fit its actual width + """ + width = self.annotations_treeview.get_allocated_width() + self.annotation_renderer.set_property('wrap-width', width - 4) + self.annotation_column.queue_resize() + + def key_event(self, widget, event): """ Handle a key (press/release) event. diff --git a/pympress/share/xml/presenter.glade b/pympress/share/xml/presenter.glade index 5fc724d9..2fa79f8c 100644 --- a/pympress/share/xml/presenter.glade +++ b/pympress/share/xml/presenter.glade @@ -838,6 +838,7 @@ True True True + external in @@ -845,15 +846,11 @@ True True True - immediate annotations_liststore False False - True - True 0 False - True @@ -880,7 +877,7 @@ - False + True True end 1 diff --git a/pympress/ui.py b/pympress/ui.py index fd1cea0e..b372980e 100644 --- a/pympress/ui.py +++ b/pympress/ui.py @@ -693,6 +693,8 @@ def redraw_panes(self): self.p_da_notes.queue_draw() if self.redraw_timeout: self.redraw_timeout = 0 + if self.show_annotations: + self.annotations.rewrap_annotations() self.config.update_layout_from_widgets(self.layout_name(self.notes_mode), self.p_central.get_children()[0], self.pane_handle_pos) @@ -1873,6 +1875,7 @@ def switch_annotations(self, gaction, target): else: size = parent.get_allocated_height() parent.set_position(self.pane_handle_pos[parent] * size) + self.annotations.rewrap_annotations() GLib.idle_add(self.redraw_panes)