-
I wonder whether it would be possible to have in a Python3 script that records sound while Pympress displays a presentation, writing slide transition times to a text file. The same way that a presentation is started by pressing space, this would start sound recording and mark the starting time for the transition times. After that, each slide transition time should be written to a text file (page number isn’t required in the text file). Once the last slide is reached, the next pressing of the space key should stop sound recording (and write the last slide transition time [which actually contains its duration]). Many thanks for your help. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
I think a key element to write that script here would be to use DBus messages that pympress emits on play/pause and slide transitions. That’s one of the nice side effects of using the Gtk.Application (since v1.6.0). Below some excerpts from a On document load, page set to 1 and timer paused:
Un-pause timer:
page change:
Following the pretty good dbus tutorial here, I managed to write the following (rather simple) code: #!/usr/bin/env python3
import dbus
from dbus.mainloop.glib import DBusGMainLoop
import time
import gi
from gi.repository import GLib
class PympressTimer:
def __init__(self):
self.paused_at = 0
self.start = None
self.page = 0
def handle(self, *messages):
timestamp = time.time()
for msg in messages:
if not isinstance(msg, dbus.Dictionary) or msg.signature != 'sv':
continue
if 'pause-timer' in msg:
if msg['pause-timer']:
self.paused_at = timestamp
else:
self.start = timestamp - self.paused_at
self.paused_at = None
if 'page' in msg:
self.page = msg['page']
if self.start is not None:
print(f'{timestamp - self.start:4.2f} page', self.page)
def run(self):
DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
bus.add_signal_receiver(self.handle, 'Changed', 'org.gtk.Actions', 'io.github.pympress')
loop = GLib.MainLoop()
loop.run()
if __name__ == '__main__':
PympressTimer().run() This tracks whenever page transitions are made and only counts up the time when the pympress timer is un-paused |
Beta Was this translation helpful? Give feedback.
-
I don’t know whether I should open a bug report, but for some strange reason I’m on Fedora 35 and I cannot imagine which dependency I might be missing. I’m using version 1.7b1. Is this a bug or what am I missing? Many thanks for your help. |
Beta Was this translation helpful? Give feedback.
I think a key element to write that script here would be to use DBus messages that pympress emits on play/pause and slide transitions. That’s one of the nice side effects of using the Gtk.Application (since v1.6.0).
Below some excerpts from a
dbus-monitor
output that could be useful.On document load, page set to 1 and timer paused: