Skip to content

Commit

Permalink
Split into show menu + compact mode and rework menu bar
Browse files Browse the repository at this point in the history
Also ensure we properly remember the mode set from previous run.
  • Loading branch information
Cimbali committed Apr 17, 2024
1 parent eefd4f8 commit ddc46eb
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 107 deletions.
3 changes: 3 additions & 0 deletions pympress/share/defaults.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ show_annotations = off
scroll_number = off
slide_ratio = 0.75
next_slide_count = 1
hide_menu = off
compact_mode = off

[deck-overview]
max-slides-per-row = 6
Expand Down Expand Up @@ -197,6 +199,7 @@ zoom = z
unzoom = u
notes-mode = n
compact-mode = c
hide-menu = <ctrl>m
annotations = a
highlight = h
deck-overview = d
Expand Down
148 changes: 79 additions & 69 deletions pympress/share/xml/menu_bar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,79 @@
<attribute name="action">app.edit-talk-time</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Fullscreen</attribute>
<attribute name="action">app.content-fullscreen</attribute>
<attribute name="label" translatable="yes">_Notes mode</attribute>
<attribute name="action">app.notes-mode</attribute>
</item>
<submenu>
<attribute name="label" translatable="yes">Notes position</attribute>
<item>
<attribute name="label" translatable="yes">_Right half of slide</attribute>
<attribute name="action">app.notes-pos</attribute>
<attribute name="target">right</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Bottom half of slide</attribute>
<attribute name="action">app.notes-pos</attribute>
<attribute name="target">bottom</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Left half of slide</attribute>
<attribute name="action">app.notes-pos</attribute>
<attribute name="target">left</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Top half of slide</attribute>
<attribute name="action">app.notes-pos</attribute>
<attribute name="target">top</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_After slide pages</attribute>
<attribute name="action">app.notes-pos</attribute>
<attribute name="target">after</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Every second page</attribute>
<attribute name="action">app.notes-pos</attribute>
<attribute name="target">odd</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Prefixed labels</attribute>
<attribute name="action">app.notes-pos</attribute>
<attribute name="target">map</attribute>
</item>
</submenu>

<item>
<attribute name="label" translatable="yes">Timing breakdown</attribute>
<attribute name="action">app.timing-report</attribute>
</item>
</submenu>

<submenu>
<attribute name="label" translatable="yes">_View</attribute>
<section>
<item>
<attribute name="label" translatable="yes">_Swap screens</attribute>
<attribute name="action">app.swap-screens</attribute>
<attribute name="label" translatable="yes">_Fullscreen</attribute>
<attribute name="action">app.content-fullscreen</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Notes mode</attribute>
<attribute name="action">app.notes-mode</attribute>
<attribute name="label" translatable="yes">_Highlight</attribute>
<attribute name="action">app.highlight</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Blank screen</attribute>
<attribute name="action">app.blank-screen</attribute>
<attribute name="label" translatable="yes">_Deck overview</attribute>
<attribute name="action">app.deck-overview</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Align _content</attribute>
<attribute name="action">app.align-content</attribute>
<attribute name="label" translatable="yes">_Zoom in</attribute>
<attribute name="action">app.zoom</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Compact mode</attribute>
<attribute name="action">app.compact-mode</attribute>
<attribute name="label" translatable="yes">_Undo zoom</attribute>
<attribute name="action">app.unzoom</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">_Annotations</attribute>
<attribute name="action">app.annotations</attribute>
Expand All @@ -79,12 +129,24 @@
<attribute name="action">app.big-buttons</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Highlight</attribute>
<attribute name="action">app.highlight</attribute>
<attribute name="label" translatable="yes">_Compact mode</attribute>
<attribute name="action">app.compact-mode</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Deck overview</attribute>
<attribute name="action">app.deck-overview</attribute>
<attribute name="label" translatable="yes">_Hide menu</attribute>
<attribute name="action">app.hide-menu</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Blank screen</attribute>
<attribute name="action">app.blank-screen</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Swap screens</attribute>
<attribute name="action">app.swap-screens</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Align _content</attribute>
<attribute name="action">app.align-content</attribute>
</item>
<submenu>
<attribute name="label" translatable="yes">_Pointer</attribute>
Expand Down Expand Up @@ -154,59 +216,7 @@
</item>
</section>
</submenu>

<item>
<attribute name="label" translatable="yes">_Zoom in</attribute>
<attribute name="action">app.zoom</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Undo zoom</attribute>
<attribute name="action">app.unzoom</attribute>
</item>

<submenu>
<attribute name="label" translatable="yes">Notes position</attribute>
<item>
<attribute name="label" translatable="yes">_Right half of slide</attribute>
<attribute name="action">app.notes-pos</attribute>
<attribute name="target">right</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Bottom half of slide</attribute>
<attribute name="action">app.notes-pos</attribute>
<attribute name="target">bottom</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Left half of slide</attribute>
<attribute name="action">app.notes-pos</attribute>
<attribute name="target">left</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Top half of slide</attribute>
<attribute name="action">app.notes-pos</attribute>
<attribute name="target">top</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_After slide pages</attribute>
<attribute name="action">app.notes-pos</attribute>
<attribute name="target">after</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Every second page</attribute>
<attribute name="action">app.notes-pos</attribute>
<attribute name="target">odd</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Prefixed labels</attribute>
<attribute name="action">app.notes-pos</attribute>
<attribute name="target">map</attribute>
</item>
</submenu>

<item>
<attribute name="label" translatable="yes">Timing breakdown</attribute>
<attribute name="action">app.timing-report</attribute>
</item>
</section>
</submenu>

<submenu>
Expand Down
103 changes: 65 additions & 38 deletions pympress/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import logging
logger = logging.getLogger(__name__)

import collections

Check failure on line 37 in pympress/ui.py

View workflow job for this annotation

GitHub Actions / lint (3.7)

E402 module level import not at top of file

Check failure on line 37 in pympress/ui.py

View workflow job for this annotation

GitHub Actions / lint (3.8)

E402 module level import not at top of file

Check failure on line 37 in pympress/ui.py

View workflow job for this annotation

GitHub Actions / lint (3.9)

E402 module level import not at top of file

Check failure on line 37 in pympress/ui.py

View workflow job for this annotation

GitHub Actions / lint (3.10)

E402 module level import not at top of file

Check failure on line 37 in pympress/ui.py

View workflow job for this annotation

GitHub Actions / lint (3.11)

E402 module level import not at top of file
import pathlib
import math
import sys
Expand Down Expand Up @@ -101,6 +102,8 @@ class UI(builder.Builder):

#: Whether to be in compact mode or not
compact_mode = False
#: Whether to hide or show the menu
hide_menu = False
#: Whether to display annotations or not
show_annotations = True
#: Whether to display big buttons or not
Expand All @@ -126,6 +129,8 @@ class UI(builder.Builder):
placeable_widgets = {}
#: Map of :class:`~Gtk.Paned` to the relative position (`float` between 0 and 1) of its handle
pane_handle_pos = {}
#: Map of :class:`~Gtk.Widget` to the tuple of margins (4 `float`s)
widget_margins = {}

#: :class:`~pympress.config.Config` to remember preferences
config = None
Expand Down Expand Up @@ -203,11 +208,11 @@ def __init__(self, app, config):
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)

self.margin_buffer = dict()

self.show_annotations = self.config.getboolean('presenter', 'show_annotations')
self.chosen_notes_mode = document.PdfPage[self.config.get('notes position', 'horizontal').upper()]
self.show_bigbuttons = self.config.getboolean('presenter', 'show_bigbuttons')
self.compact_mode = self.config.getboolean('presenter', 'compact_mode')
self.hide_menu = self.config.getboolean('presenter', 'hide_menu')

# Surface cache
self.cache = surfacecache.SurfaceCache(self.doc, self.config.getint('cache', 'maxpages'))
Expand Down Expand Up @@ -237,7 +242,8 @@ def __init__(self, app, config):
'notes-pos': dict(activate=self.change_notes_pos, parameter_type=str,
state=self.chosen_notes_mode.name.lower()),
'annotations': dict(activate=self.switch_annotations, state=self.show_annotations),
'compact-mode': dict(activate=self.switch_compact_mode, state=self.compact_mode),
'compact-mode': dict(activate=self.switch_compact_mode, state=self.compact_mode),

Check failure on line 245 in pympress/ui.py

View workflow job for this annotation

GitHub Actions / lint (3.7)

E241 multiple spaces after ':'

Check failure on line 245 in pympress/ui.py

View workflow job for this annotation

GitHub Actions / lint (3.8)

E241 multiple spaces after ':'

Check failure on line 245 in pympress/ui.py

View workflow job for this annotation

GitHub Actions / lint (3.9)

E241 multiple spaces after ':'

Check failure on line 245 in pympress/ui.py

View workflow job for this annotation

GitHub Actions / lint (3.10)

E241 multiple spaces after ':'

Check failure on line 245 in pympress/ui.py

View workflow job for this annotation

GitHub Actions / lint (3.11)

E241 multiple spaces after ':'
'hide-menu': dict(activate=self.switch_menu, state=self.hide_menu),

Check failure on line 246 in pympress/ui.py

View workflow job for this annotation

GitHub Actions / lint (3.7)

E241 multiple spaces after ':'

Check failure on line 246 in pympress/ui.py

View workflow job for this annotation

GitHub Actions / lint (3.8)

E241 multiple spaces after ':'

Check failure on line 246 in pympress/ui.py

View workflow job for this annotation

GitHub Actions / lint (3.9)

E241 multiple spaces after ':'

Check failure on line 246 in pympress/ui.py

View workflow job for this annotation

GitHub Actions / lint (3.10)

E241 multiple spaces after ':'

Check failure on line 246 in pympress/ui.py

View workflow job for this annotation

GitHub Actions / lint (3.11)

E241 multiple spaces after ':'
'validate-input': dict(activate=self.validate_current_input),
'cancel-input': dict(activate=self.cancel_current_input),
'align-content': dict(activate=self.adjust_frame_position),
Expand Down Expand Up @@ -312,6 +318,9 @@ def __init__(self, app, config):
self.laser_button.set_visible(self.show_bigbuttons)
self.highlight_button.set_visible(self.show_bigbuttons)
self.p_frame_annot.set_visible(self.show_annotations)
self.p_win.set_show_menubar(not self.hide_menu)
self.adjust_margins()
self.adjust_bottom_bar_font()
self.laser.activate_pointermode()

# Setup screens and show all windows
Expand Down Expand Up @@ -1858,6 +1867,27 @@ def switch_mode(self, gaction, target_mode=None, force=False):
return True


def switch_menu(self, gaction, target):
""" Toggle menu bar visibility.
Returns:
gaction (:class:`~Gio.Action`): the action triggering the call
target (:class:`~GLib.Variant`): the parameter as a variant, or None
Returns:
`bool`: whether the mode has been toggled.
"""
self.hide_menu = not self.hide_menu
self.config.set('presenter', 'hide_menu', 'on' if self.hide_menu else 'off')

self.p_win.set_show_menubar(not self.hide_menu)
GLib.idle_add(self.redraw_panes)

gaction.change_state(GLib.Variant.new_boolean(self.hide_menu))

return True


def switch_compact_mode(self, gaction, target):
""" Toggle compact mode.
Expand All @@ -1869,9 +1899,19 @@ def switch_compact_mode(self, gaction, target):
`bool`: whether the mode has been toggled.
"""
self.compact_mode = not self.compact_mode

self.config.set('presenter', 'compact_mode', 'on' if self.compact_mode else 'off')

self.adjust_margins()
self.adjust_bottom_bar_font()
GLib.idle_add(self.redraw_panes)

gaction.change_state(GLib.Variant.new_boolean(self.compact_mode))

return True


def adjust_margins(self):
""" Adjust all presenter window margins and visibilities according to compact mode. """
for frame_next in self.p_frames_next:
frame_next.get_label_widget().set_visible(not self.compact_mode)

Expand All @@ -1882,43 +1922,30 @@ def switch_compact_mode(self, gaction, target):
for handle in self.pane_handle_pos:
handle.set_wide_handle(not self.compact_mode)

self.adjust_margins()
self.adjust_bottom_bar_font()

self.p_win.set_show_menubar(not self.compact_mode)

GLib.idle_add(self.redraw_panes)

gaction.change_state(GLib.Variant.new_boolean(self.compact_mode))

return True

def adjust_margins(self):
queue: list[Gtk.Container] = [self.p_central]
while len(queue) != 0:
children = queue.pop().get_children()
queue = collections.deque([self.p_central])
while queue:
children = queue.popleft().get_children()
for child in children:
id = child.get_name()
if self.compact_mode:
saved_margin = (
child.get_margin_top(),
child.get_margin_bottom(),
child.get_margin_start(),
child.get_margin_end(),
)
self.margin_buffer[id] = saved_margin
margin = (0,0,0,0)
try:
if self.compact_mode:
self.widget_margins[child] = (
child.get_margin_top(),
child.get_margin_bottom(),
child.get_margin_start(),
child.get_margin_end(),
)
top, bot, start, end = 0, 0, 0, 0
else:
top, bot, start, end = self.widget_margins.pop(child)
except KeyError:
pass
else:
margin = self.margin_buffer.get(id)

if margin is not None:
(t,b,s,e) = margin
child.set_margin_top(t)
child.set_margin_bottom(b)
child.set_margin_start(s)
child.set_margin_end(e)
child.set_margin_top(top)
child.set_margin_bottom(bot)
child.set_margin_start(start)
child.set_margin_end(end)

if issubclass(type(child), Gtk.Container):
if isinstance(child, Gtk.Container):
queue.append(child)


Expand Down

0 comments on commit ddc46eb

Please sign in to comment.