Skip to content

Commit

Permalink
Make annotations wrap
Browse files Browse the repository at this point in the history
Closes #303
  • Loading branch information
Cimbali committed Dec 12, 2023
1 parent ad106c3 commit ff375e5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
12 changes: 12 additions & 0 deletions pympress/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
7 changes: 2 additions & 5 deletions pympress/share/xml/presenter.glade
Original file line number Diff line number Diff line change
Expand Up @@ -838,22 +838,19 @@
<property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="hscrollbar-policy">external</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkTreeView" id="annotations_treeview">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="resize-mode">immediate</property>
<property name="model">annotations_liststore</property>
<property name="headers-visible">False</property>
<property name="headers-clickable">False</property>
<property name="reorderable">True</property>
<property name="rules-hint">True</property>
<property name="search-column">0</property>
<property name="show-expanders">False</property>
<property name="enable-tree-lines">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="annotations_selection"/>
</child>
Expand All @@ -880,7 +877,7 @@
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="pack-type">end</property>
<property name="position">1</property>
Expand Down
3 changes: 3 additions & 0 deletions pympress/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit ff375e5

Please sign in to comment.