Pympress package¶
This page contains the inline documentation, generated from the code using sphinx.
The code is documented in the source using the Google style for docstrings. Sphinx has gathered a set of examples which serves as a better crash course than the full style reference.
Retructured text (rst) can be used inside the comments and docstrings.
Modules¶
pympress.ui
– GUI management¶
This module contains the whole graphical user interface of pympress, which is made of two separate windows: the Content window, which displays only the current page in full size, and the Presenter window, which displays both the current and the next page, as well as a time counter and a clock.
Both windows are managed by the UI
class.
-
class
pympress.ui.
UI
[source]¶ Bases:
pympress.builder.Builder
Pympress GUI management.
-
annotations
= None¶ Class
Annotations
managing the display of annotations
-
blanked
= False¶ track whether we blank the screen
-
c_da
= None¶ DrawingArea
for the Content window.
-
c_frame
= None¶ AspectFrame
for the Content window.
-
cache
= None¶ SurfaceCache
instance.
-
change_notes_pos
(widget, event=None, force_change=False)[source]¶ Switch the display mode to “Notes mode” or “Normal mode” (without notes).
- Returns
whether the mode has been toggled.
- Return type
-
chosen_notes_mode
= 4¶ Current choice of mode to toggle notes
-
click_link
(widget, event)[source]¶ Check whether a link was clicked and follow it. Handles a click on a slide.
-
est_time
= None¶ EstimatedTalkTime
to set estimated/remaining talk time
-
get_notes_mode
()[source]¶ Simple getter.
- Returns (
PdfPage
): Truthy when we split slides in content + notes
- Returns (
ToolButton
big button for touch screens, go to scribble on screen
-
hover_link
(widget, event)[source]¶ Manage events related to hyperlinks, setting the cursor to a pointer if the hovered region is clickable.
Display the “About pympress” dialog.
Handles clicks on the “about” menu.
ToolButton
big button for touch screens, go to next slide
-
notes_mode
= 0¶ Whether to use notes mode or not
-
on_configure_da
(widget, event)[source]¶ Manage “configure” events for all drawing areas, e.g. resizes.
We tell the local
SurfaceCache
cache about it, so that it can invalidate its internal cache for the specified widget and pre-render next pages at a correct size.Warning: Some not-explicitely sent signals contain wrong values! Just don’t resize in that case, since these always seem to happen after a correct signal that was sent explicitely.
-
on_drag_drop
(widget, drag_context, x, y, data, info, time)[source]¶ Receive the drag-drops (as text only). If a file is dropped, open it.
- Parameters
widget (
Widget
) – The widget on which the dragged item was droppeddrag_context (
DragContext
) –x (
float
) –y (
float
) –data (
SelectionData
) – container for the dropped datainfo (
int
) –time (
int
) –
-
on_draw
(widget, cairo_context)[source]¶ Manage draw events for both windows.
This callback may be called either directly on a page change or as an event handler by GTK. In both cases, it determines which widget needs to be updated, and updates it, using the
SurfaceCache
if possible.
Manage key presses for both windows
-
on_page_change
(unpause=True)[source]¶ Switch to another page and display it.
This is a kind of event which is supposed to be called only from the
Document
class.
-
on_pane_event
(widget, evt)[source]¶ Signal handler for gtk.paned events
This function allows to delay drawing events when resizing, and to speed up redrawing when moving the middle pane is done (which happens at the end of a mouse resize)
-
p_da_cur
= None¶ DrawingArea
for the current slide copy in the Presenter window.
-
p_da_next
= None¶ DrawingArea
for the next slide in the Presenter window.
-
p_da_notes
= None¶ DrawingArea
for the current slide in the Presenter window.
-
p_frame_cur
= None¶ AspectFrame
for the current slide copy in the Presenter window.
-
p_frame_next
= None¶ AspectFrame
for the next slide in the Presenter window.
-
p_frame_notes
= None¶ AspectFrame
for the current slide in the Presenter window.
-
page_number
= None¶ PageNumber
displaying current and max page numbers and setting current page number
-
page_preview
(widget, *args)[source]¶ Switch to another page and display it.
This is a kind of event which is supposed to be called only from the spin_cur spinner as a callback
- Parameters
widget (
SpinButton
) – The spinner button widget calling page_preview
-
page_preview_nb
= -1¶ number of page currently displayed in Controller window’s miniatures
-
placeable_widgets
= {}¶ Dictionary of
Widget
from the presenter window that can be dynamically rearranged
-
pres_annot
= None¶ CheckMenuItem
that shows whether the annotations are toggled
-
pres_blank
= None¶ CheckMenuItem
that shows whether the blank mode is toggled
-
pres_fullscreen
= None¶ CheckMenuItem
that shows whether the c_win is fullscreen
-
pres_notes
= None¶ CheckMenuItem
that shows whether the annotations are toggled
ToolButton
big button for touch screens, go to previous slide
-
recent_document
(recent_menu)[source]¶ Callback for the recent document menu.
Gets the URI and requests the document swap.
- Parameters
recent_menu (
RecentChooserMenu
) – the recent docs menu
-
redraw_panes
()[source]¶ Handler for
Paned
’s resizing signal, used for delayed drawing events of drawing areas inside the panes. This is very useful on windows where resizing gets sluggish if we try to redraw while resizing.
-
redraw_timeout
= 0¶ Tracks return values of GLib.timeout_add to cancel gtk.paned’s redraw callbacks
-
resize_panes
= False¶ Indicates whether we should delay redraws on some drawing areas to fluidify resizing gtk.paned
-
scribbler
= None¶ Class
Scribble
managing drawing by the user on top of the current slide.
-
shortcuts_window
= None¶ A
ShortcutsWindow
to show the shortcuts
-
show_annotations
= True¶ Whether to display annotations or not
Whether to display big buttons or not
-
show_timing_report
(*args)[source]¶ Show the popup with information on timing of the talk.
Gather current time, document structure, page labels etc. and pass it to timing popup for display.
-
swap_document
(docpath, page=0, reloading=False)[source]¶ Replace the currently open document with a new one
The new document is possibly and EmptyDocument if docpath is None. The state of the ui and cache are updated accordingly.
-
swap_screens
(*args)[source]¶ Swap the monitors on which each window is displayed (if there are 2 monitors at least).
-
switch_annotations
(widget, event=None)[source]¶ Switch the display to show annotations or to hide them.
- Returns
whether the mode has been toggled.
- Return type
Toggle the display of big buttons (nice for touch screens)
-
switch_blanked
(widget, event=None)[source]¶ Switch the blanked mode of the content screen.
- Returns
whether the mode has been toggled.
- Return type
-
switch_fullscreen
(widget)[source]¶ Switch the Content window to fullscreen (if in normal mode) or to normal mode (if fullscreen).
Screensaver will be disabled when entering fullscreen mode, and enabled when leaving fullscreen mode.
-
switch_mode
(widget, event=None, target_mode=None)[source]¶ Switch the display mode to “Notes mode” or “Normal mode” (without notes).
- Returns
whether the mode has been toggled.
- Return type
-
talk_time
= None¶ TimeCounter
clock tracking talk time (elapsed, and remaining)
-
timing
= None¶ TimingReport
popup to show how much time was spent on which part
-
track_clicks
(widget, event)[source]¶ Track mouse press and release events
Handles clicks on the slides.
-
track_motions
(widget, event)[source]¶ Track mouse motion events
Handles mouse motions on the “about” menu.
-
update_frame_position
(widget, user_data)[source]¶ Callback to preview the frame alignement, called from the Gtk.SpinButton.
- Parameters
widget (
SpinButton
) – The button updating the slide alignement in the drawing area widgetuser_data (
str
) – The property being set, either the x or y alignement (resp. xalign and yalign).
-
pympress.document
– document handling¶
This module contains several classes that are used for managing documents (only PDF documents are supported at the moment, but other formats may be added in the future).
An important point is that this module is completely independant from the GUI: there should not be any GUI-related code here, except for page rendering (and only rendering itself: the preparation of the target surface must be done elsewhere).
-
class
pympress.document.
Document
(builder, pop_doc, path, page=0)[source]¶ Bases:
object
This is the main document handling class.
Note
The internal page numbering scheme is the same as in Poppler: it starts at 0.
- Parameters
builder (
pympress.builder.Builder
) – A builder to load callbackspop_doc (
Document
) – Instance of the Poppler document that this class will wrappath (
str
) – Absolute path to the PDF file to openpage (
int
) – page number to which the file should be opened
-
cleanup_media_files
()[source]¶ Removes all files that were extracted from the pdf into the filesystem
-
static
create
(builder, path, page=0)[source]¶ Initializes a Document by passing it a
Document
- Parameters
builder (
pympress.builder.Builder
) – A builder to load callbackspath (
str
) – Absolute path to the PDF file to openpage (
int
) – page number to which the file should be opened
- Returns
The initialized document
- Return type
-
cur_page
= -1¶ Number of the current page
-
get_full_path
(filename)[source]¶ Returns full path, extrapolated from a path relative to this document or to the current directory.
-
get_structure
(index_iter=None)[source]¶ Gets the structure of the document from its index.
Recursive, pass the iterator.
-
goto
(number)[source]¶ Switch to another page.
- Parameters
number (
int
) – number of the destination page
-
has_labels
()[source]¶ Return whether this document has useful labels.
- Returns
False iff there are no labels or they are just the page numbers
- Return type
-
hist_pos
= -1¶ Our position in the history
-
history
= []¶ History of pages we have visited
-
label_after
(page)[source]¶ Switch to the next page with different label. If we’re within a set of pages with the same label we want to go to the last one.
-
label_before
(page)[source]¶ Switch to the previous page with different label If we’re within a set of pages with the same label we want to go before the first one.
-
nb_pages
= -1¶ Number of pages in the document
-
page_change
()¶ callback, to be connected to
on_page_change()
-
pages_cache
= {}¶ Pages cache (
dict
ofPage
). This makes navigation in the document faster by avoiding calls to Poppler when loading a page that has already been loaded.
-
pages_number
()[source]¶ Get the number of pages in the document.
- Returns
the number of pages in the document
- Return type
-
path
= None¶ Path to pdf
-
remove_on_exit
(filename)[source]¶ Remember a temporary file to delete later
- Parameters
filename (
str
) – The path to the file to delete
-
start_editing_page_number
()¶ callback, to be connected to
start_editing()
-
temp_files
= {}¶ Files that are temporary and need to be removed
-
class
pympress.document.
EmptyDocument
[source]¶ Bases:
pympress.document.Document
A dummy document, placeholder for when no document is open.
-
class
pympress.document.
EmptyPage
[source]¶ Bases:
pympress.document.Page
A dummy page, placeholder for when there are no valid pages around.
This page is a non-notes page with an aspect ratio of 1.3 and nothing else inside. Also, it has no “rendering” capability, and is made harmless by overriding its render function.
-
class
pympress.document.
Link
(x1, y1, x2, y2, action)[source]¶ Bases:
object
This class encapsulates one hyperlink of the document.
- Parameters
-
static
build_closure
(fun, *args, **kwargs)[source]¶ Return a lambda that calls fun(*args, **kwargs), with the current value of args and kwargs. By creating the lambda in a new scope, we bind the arguments, thus creating a closure and remember the arguments.
-
follow
(**kwargs)¶ function
, action to be perform to follow this link
-
class
pympress.document.
Page
(page, number, parent)[source]¶ Bases:
object
Class representing a single page.
It provides several methods used by the GUI for preparing windows for displaying pages, managing hyperlinks, etc.
- Parameters
-
annotations
= []¶ All text annotations
-
get_annot_action
(link_type, action, rect)[source]¶ Get the function to be called when the link is followed.
- Parameters
link_type (
ActionType
) – The link typeaction (
Action
) – The action to be performed when the link is clickedrect (
Rectangle
) – The region of the page where the link is
- Returns
The function to be called to follow the link
- Return type
function
-
get_link_action
(link_type, action)[source]¶ Get the function to be called when the link is followed.
- Parameters
link_type (
ActionType
) – The type of action to be performedaction (
Action
) – The atcion to be performed
- Returns
The function to be called to follow the link
- Return type
function
-
get_link_at
(x, y, dtype=<PdfPage.FULL: 1>)[source]¶ Get the
Link
corresponding to the given position, orNone
if there is no link at this position.
-
get_media
()[source]¶ Get the list of medias this page might want to play.
- Returns
medias in this page
- Return type
-
class
pympress.document.
PdfPage
[source]¶ Bases:
enum.IntEnum
Represents the part of a PDF page that we want to draw.
-
BOTTOM
= 2¶ Bottom half of PDF page
-
FULL
= 1¶ Full PDF page (without notes)
-
LEFT
= 5¶ Left half of PDF page
-
NONE
= 0¶ No notes on PDF page, only falsy value
-
RIGHT
= 4¶ Right half of PDF page
-
TOP
= 3¶ Top half of PDF page
-
from_screen
(x, y, x2=None, y2=None)[source]¶ Transform visible part of the page coordinates to full page coordinates.
Pass 2 floats to transform coordinates, 4 to transform margins, i.e. the second pair of coordinates is taken from the opposite corner.
-
pympress.ui_builder
– abstract GUI management¶
This module contains the tools to load the graphical user interface of pympress, building the widgets/objects from XML (glade) files, applying translation “manually” to avoid dealing with all the mess of C/GNU gettext’s bad portability.
-
class
pympress.builder.
Builder
[source]¶ Bases:
gi.overrides.Gtk.Builder
GUI builder, inherits from
Builder
to read XML descriptions of GUIs and load them.-
connect_signals
(base_target)[source]¶ Override default signal connector so we can map signals to the methods of (any depth of) object that are properties of self
- Parameters
base_target (
Builder
) – The target object, that has functions to be connected to signals loaded in this builder.
-
static
find_callback_handler
(target, handler_name)[source]¶ Returns the handler from its name, searching in target. Parse handler names and split on ‘.’ to use recursion.
- Parameters
- Returns
A function bound to an object or, if the object may change, a lambda calling Builder.signal_resolver to get said function bound to an object
- Return type
function
-
get_callback_handler
(handler_name)[source]¶ Convenience non-static wrapper function for
find_callback_handler()
to search in the builder object. Thehandler_name
function must be a method of this builder (realistically, a method of an inherited UI class’ instance).- Parameters
handler_name (
str
) – The name of the function to be connected to a signal- Returns
A function bound to an object or, if the object may change, a lambda calling Builder.signal_resolver to get said function bound to an object
- Return type
function
-
list_attributes
(target)[source]¶ List the None-valued attributes of target.
- Parameters
target (
dict
) – An object with None-valued attributes
-
load_ui
(resource_name)[source]¶ Loads the UI defined in the file named resource_name using the builder.
- Parameters
resource_name (
str
) – the name of the glade file (basename without extension), identifying which resource to load.
-
load_widgets
(target)[source]¶ Fill in target with the missing elements introspectively. This means that all attributes of target that are None at this time must exist under the same name in the builder.
- Parameters
target (
dict
) – An object with None-valued attributes that have the same name as built widgets, loaded from the glade file.
-
pending_pane_resizes
= {}¶ dict
mappingPaned
names to the handler ids of their size-allocate signal
-
replace_layout
(layout, top_widget, leaf_widgets, pane_resize_handler=None)[source]¶ Remix the layout below top_widget with the layout configuration given in ‘layout’ (assumed to be valid!).
- Parameters
layout (
dict
) – the json-parsed config string, thus a hierarchy of lists/dicts, with strings as leavestop_widget (
Container
) – The top-level widget under which we build the hierachyyleaf_widgets (
dict
) – the map of valid leaf identifiers (strings) to the correspondingWidget
pane_resize_handler (function) – callback function to be called when the panes are resized
- Returns
The mapping of the used
Paned
widgets to their relative handle position (float between 0 and 1)- Return type
-
resize_paned
(paned, rect, relpos)[source]¶ Resize
paned
to have its handle atrelpos
, then disconnect this signal handler. Called from theGtk.Widget.signals.size_allocate()
signal.
-
signal_connector
(builder, object, signal_name, handler_name, connect_object, flags, *user_data)[source]¶ Callback for signal connection. Implements the
BuilderConnectFunc
function interface.- Parameters
builder (
Builder
) – The builder, unusedobject (
Object
) – The object (usually a wiget) that has a signal to be connectedsignal_name (
str
) – The name of the signalhandler_name (
str
) – The name of the function to be connected to the signalconnect_object (
Object
) – unusedflags (
ConnectFlags
) – unuseduser_data (
tuple
) – supplementary positional arguments to be passed to the handler
-
static
signal_resolver
(target, attr_list)[source]¶ Dynamically resolves a signal that is target.a.b.c() when attr_list is [‘a’, ‘b’, ‘c’].
This allows to specify multi-level signals in the XML files, instead of targeting everything at the main UI object.
Also, resolving signals dynamically means the object properties of the top-level object can be replaced, and the signal will still connect to something meaningful. The downside is that this connection is done at runtime, thus probably less efficient and might fail to find the target if any attribute along the way has an unexpected value.
- Parameters
attr_list (
list
) – a list of attribute names, designating objects except the last one designating a function- Returns
The function to which we want to connect
- Return type
function
-
pympress.surfacecache
– pages prerendering and caching¶
This modules contains stuff needed for caching pages and prerendering them. This
is done by the SurfaceCache
class, using several
dict
of ImageSurface
for storing rendered pages.
The problem is, neither Gtk+ nor Poppler are particularly threadsafe. Hence the prerendering isn’t really done in parallel in another thread, but scheduled on the main thread at idle times using GLib.idle_add().
-
class
pympress.surfacecache.
OrderedDict
[source]¶ Bases:
collections.OrderedDict
OrderedDict for python2 compatibility, adding move_to_end().
-
class
pympress.surfacecache.
SurfaceCache
(doc, max_pages)[source]¶ Bases:
object
Pages caching and prerendering made (almost) easy.
-
active_widgets
= {}¶ Set of active widgets
-
add_widget
(widget, wtype, prerender_enabled=True, zoomed=False)[source]¶ Add a widget to the list of widgets that have to be managed (for caching and prerendering).
This creates new entries for
widget_name
in the needed internal data structures, and creates a new thread for prerendering pages for this widget.- Parameters
widget (
Widget
) – The widget for which we need to cachewtype (
int
) – type of document handled by the widget (seesurface_type
)prerender_enabled (
bool
) – whether this widget is initially in the list of widgets to prerender
-
clear_cache
(widget_name)[source]¶ Remove all cached values for a given widget. Useful for zoomed views.
- Parameters
widget_name (
str
) – name of the widget that is resized
-
disable_prerender
(widget_name)[source]¶ Remove a widget from the ones to be prerendered.
- Parameters
widget_name (
str
) – string used to identify a widget
-
enable_prerender
(widget_name)[source]¶ Add a widget to the ones to be prerendered.
- Parameters
widget_name (
str
) – string used to identify a widget
-
get
(widget_name, page_nb)[source]¶ Fetch a cached, prerendered page for the specified widget.
- Parameters
- Returns
the cached page if available, or
None
otherwise- Return type
-
get_widget_type
(widget_name)[source]¶ Get the document type of a widget.
- Parameters
widget_name (
str
) – string used to identify a widget- Returns
type of document handled by the widget (see
surface_type
)- Return type
-
locks
= {}¶ Dictionary of
Lock
used for managing conccurent accesses tosurface_cache
andsurface_size
-
max_pages
= 200¶ maximum number fo pages we keep in cache
-
prerender
(page_nb)[source]¶ Queue a page for prerendering.
The specified page will be prerendered for all the registered widgets.
- Parameters
page_nb (
int
) – number of the page to be prerendered
-
renderer
(widget_name, page_nb)[source]¶ Rendering thread.
This function is meant to be run in the prerendering thread. It runs infinitely (until the program ends) and does the following steps:
check if the job’s result is not already available in the cache
render it in a new
ImageSurface
if necessarystore it in the cache if it was not added there since the beginning of the process and the widget configuration is still valid
-
resize_widget
(widget_name, width, height)[source]¶ Change the size of a registered widget, thus invalidating all the cached pages.
-
set
(widget_name, page_nb, val)[source]¶ Store a rendered page in the cache.
- Parameters
widget_name (
str
) – name of the concerned widgetpage_nb (
int
) – number of the page to store in the cacheval (
ImageSurface
) – content to store in the cache
-
set_widget_type
(widget_name, wtype)[source]¶ Set the document type of a widget.
- Parameters
widget_name (
str
) – string used to identify a widgetwtype (
int
) – type of document handled by the widget (seesurface_type
)
-
surface_cache
= {}¶ The actual cache. It is a
dict
ofCache
: its keys are widget names and its values aredict
whose keys are page numbers and values are instances ofImageSurface
. In eachCache
keys are ordered by Least Recently Used (get or set), when the size is beyondmax_pages
, pages are popped from the start of the cache.
-
surface_factory
= {}¶ dict
containing functions that return aSurface
given aContext
, widthint
and heightint
seecreate_similar()
-
pympress.scribble
– Manage user drawings on the current slide¶
-
class
pympress.scribble.
Scribbler
(config, builder, notes_mode)[source]¶ Bases:
pympress.builder.Builder
-
disable_scribbling
()[source]¶ Disable the scribbling mode.
- Returns
whether it was possible to disable (thus if it was not disabled already)
- Return type
-
draw_scribble
(widget, cairo_context)[source]¶ Perform the drawings by user.
- Parameters
widget (
DrawingArea
) – The widget where to draw the scribbles.cairo_context (
Context
) – The canvas on which to render the drawings
-
enable_scribbling
()[source]¶ Enable the scribbling mode.
- Returns
whether it was possible to enable (thus if it was not enabled already)
- Return type
-
get_slide_point
()¶ callback, to be connected to
get_slide_point()
Handles an key press event: undo or disable scribbling.
-
off_render
= None¶ A
OffscreenWindow
where we render the scribbling interface when it’s not shown
-
pres_highlight
= None¶ CheckMenuItem
that shows whether the scribbling is toggled
-
redraw_current_slide
()¶ callback, to be connected to
redraw_current_slide()
-
resize_cache
()¶ callback, to be connected to
resize_widget()
-
scribble_color
= Gdk.RGBA(red=1.000000, green=1.000000, blue=1.000000, alpha=1.000000)¶ RGBA
current color of the scribbling tool
-
scribble_drawing
= False¶ Whether the current mouse movements are drawing strokes or should be ignored
-
scribble_list
= []¶ list
of scribbles to be drawn, as tuples of colorRGBA
, widthint
, and alist
of points.
-
scribble_overlay
= None¶ HBox
that is replaces normal panes when scribbling is toggled, contains buttons and scribble drawing area
-
scribble_p_da
= None¶ DrawingArea
for the scribbles in the Presenter window. Actually redraws the slide.
-
scribble_p_eb
= None¶ EventBox
for the scribbling in the Presenter window, captures freehand drawing
-
scribble_p_frame
= None¶ AspectFrame
for the slide in the Presenter’s highlight mode
-
scribbling_mode
= False¶ Whether we are displaying the interface to scribble on screen and the overlays containing said scribbles
-
start_zooming
()¶ callback, to be connected to
start_zooming()
-
stop_zooming
()¶ callback, to be connected to
stop_zooming()
-
swap_layout
()¶ callback, to be connected to
swap_layout()
-
switch_scribbling
(widget, event=None, name=None)[source]¶ Starts the mode where one can read on top of the screen
-
track_clicks
()¶ callback, to be connected to
track_clicks()
-
track_motions
()¶ callback, to be connected to
track_motions()
-
update_color
(widget)[source]¶ Callback for the color chooser button, to set scribbling color
- Parameters
widget (
ColorButton
) – the clicked button to trigger this event, if any
-
update_width
(widget, event, value)[source]¶ Callback for the width chooser slider, to set scribbling width
Button
that is clicked to stop zooming, unsensitive when there is no zooming
-
pympress.pointer
– Manage when and where to draw a software-emulated laser pointer on screen¶
-
pympress.pointer.
POINTER_HIDE
= 0¶ Pointer enabled but hidden, will be drawn on ctrl + click
-
pympress.pointer.
POINTER_OFF
= -1¶ Pointer disabled, will not be drawn
-
pympress.pointer.
POINTER_SHOW
= 1¶ Draw the pointer on the current slide
-
class
pympress.pointer.
Pointer
(config, builder)[source]¶ Bases:
object
-
change_pointer
(widget)[source]¶ Callback for a radio item selection as pointer color
- Parameters
widget (
RadioMenuItem
) – the selected radio item in the pointer type selection menu
-
load_pointer
(name)[source]¶ Perform the change of pointer using its name
- Parameters
name (
str
) – Name of the pointer to load
-
pointer
= <GdkPixbuf.Pixbuf object at 0x7ff407577168 (GdkPixbuf at 0x55c9903eb700)>¶ Pixbuf
to read XML descriptions of GUIs and load them.
-
pointer_pos
= (0.5, 0.5)¶ (float, float)
of position relative to slide, where the pointer should appear
-
redraw_current_slide
()¶ callback, to be connected to
redraw_current_slide()
-
pympress.editable_label
– A label that can be swapped out for an editable entry¶
-
class
pympress.editable_label.
EditableLabel
[source]¶ Bases:
object
-
on_keypress
(widget, event)[source]¶ Manage key presses for the editable label.
If we are editing the label, intercept some key presses (to validate or cancel editing or other specific behaviour), otherwise pass the key presses on to the button for normal behaviour.
-
on_label_event
(widget, event=None, name=None)[source]¶ Manage events on the current slide label/entry.
This function triggers replacing the label with an entry when clicked or otherwise toggled.
-
restore_label
()[source]¶ Make sure that the editable label is not in entry mode. If it is an entry, then replace it with the label.
-
-
class
pympress.editable_label.
EstimatedTalkTime
(builder, ett=0)[source]¶ Bases:
pympress.editable_label.EditableLabel
-
delayed_callback_connection
(builder)[source]¶ Connect callbacks later than at init, due to circular dependencies. Call this when the page_number module is initialized, but before needing the callback.
- Parameters
builder (builder.Builder) – The builder from which to load widgets.
-
entry_ett
= <Gtk.Entry object at 0x7ff407591360 (GtkEntry at 0x55c9904fa490)>¶ Entry
used to set the estimated talk time.
-
restore_label
()[source]¶ Make sure that the current page number is displayed in a label and not in an entry. If it is an entry, then replace it with the label.
-
set_time
(time)[source]¶ Set the talk time.
- Parameters
time (
int
) – the estimated time for the talk, in seconds.
-
stop_editing_page_number
()¶ callback, to be connected to
stop_editing()
-
-
class
pympress.editable_label.
PageNumber
(builder, page_num_scroll)[source]¶ Bases:
pympress.editable_label.EditableLabel
-
enable_labels
(enable)[source]¶ Allow to use or ignore labels.
- Parameters
enable (
bool
) – Whether to enable labels
-
find_label
()¶ callback, to be connected to
lookup_label()
-
label_after
()¶ callback, to be connected to
label_before()
-
label_before
()¶ callback, to be connected to
label_after()
-
label_sep
= None¶ Label
separatingspin_cur
andedit_label
-
more_actions
(event, name)[source]¶ Implement directions (left/right/home/end) keystrokes, otherwise pass on to
do_key_press_event()
-
on_scroll
(widget, event)[source]¶ Scroll event. Pass it on to the spin button if we’re currently editing the page number.
-
page_change
()¶ callback, to be connected to
on_page_change()
-
restore_label
()[source]¶ Make sure that the current page number is displayed in a label and not in an entry. If it is an entry, then replace it with the label.
-
set_last
(num_pages)[source]¶ Set the max number of pages, both on display and as the range of values for the spinner.
- Parameters
num_pages (
int
) – The maximum page number
-
spin_cur
= None¶ SpinButton
used to switch to another slide by typing its number.
-
stop_editing_est_time
()¶ callback, to be connected to
stop_editing()
-
update_jump_label
(label)[source]¶ Update the displayed page label.
- Parameters
label (
str
) – The current page label
-
pympress.talk_time
– Manages the clock of elapsed talk time¶
-
class
pympress.talk_time.
TimeCounter
(builder, ett)[source]¶ Bases:
object
-
ett
= None¶ EstimatedTalkTime
that handles changing the ett
-
label_colorer
= None¶ TimeLabelColorer
that handles setting the colors oflabel_time
-
pause
()[source]¶ Pause the timer if it is not paused, otherwise do nothing.
- Returns
whether the clock’s pause was toggled.
- Return type
-
pres_pause
= None¶ CheckMenuItem
that shows whether the time is toggled
-
switch_pause
(widget, event=None)[source]¶ Switch the timer between paused mode and running (normal) mode.
- Returns
whether the clock’s pause was toggled.
- Return type
-
-
class
pympress.talk_time.
TimeLabelColorer
(label_time)[source]¶ Bases:
object
Manage the colors of a label with a set of colors between which to fade, based on how much time remains (<0 has run out of time). Times are given in seconds. In between timestamps the color will interpolated linearly, outside of the intervals the closest color will be used.
- Parameters
label_time (
Gtk.Label
) – the label where the talk time is displayed
-
color_map
= []¶ list
of tuples (int
,RGBA
), which are the desired colors at the corresponding timestamps. Sorted on the timestamps.
-
color_override
= None¶ CssProvider
affecting the style context of the labels
-
load_color_from_css
(style_context, class_name=None)[source]¶ Add class class_name to the time label and return its color.
- Parameters
label_time (
Gtk.Label
) – the label where the talk time is displayedstyle_context (
StyleContext
) – the CSS context managing the color of the label
- Returns
The color of the label with class “class_name”
- Return type
pympress.config
– Configuration¶
-
class
pympress.config.
Config
[source]¶ Bases:
configparser.ConfigParser
,object
Manage configuration :Get the configuration from its file and store its back.
-
layout
= {'highlight': {'children': ['highlight', {'resizeable': True, 'children': ['next', 'annotations'], 'proportions': [0.5497787610619469, 0.4502212389380531], 'orientation': 'vertical'}], 'orientation': 'horizontal', 'proportions': [0.6715481171548117, 0.32845188284518834], 'resizeable': True}, 'notes': {'children': ['notes', {'resizeable': False, 'children': ['current', 'next'], 'orientation': 'vertical'}], 'orientation': 'horizontal', 'proportions': [0.6472893533638145, 0.35271064663618545], 'resizeable': True}, 'plain': {'children': ['current', {'resizeable': True, 'children': ['next', 'annotations'], 'proportions': [0.4416365824308063, 0.5583634175691937], 'orientation': 'vertical'}], 'orientation': 'horizontal', 'proportions': [0.5145833333333333, 0.4854166666666667], 'resizeable': True}}¶ dict
-tree of presenter layouts for various modes
-
load_window_layouts
()[source]¶ Parse and validate layouts loaded from config, with fallbacks if needed.
-
placeable_widgets
= {'annotations': 'p_frame_annot', 'current': 'p_frame_cur', 'highlight': 'scribble_overlay', 'next': 'p_frame_next', 'notes': 'p_frame_notes'}¶ Map of strings that are the valid representations of widgets from the presenter window that can be dynamically rearranged, mapping to their names
-
toggle_start
(check_item)[source]¶ Generic function to toggle some boolean startup configuration.
- Parameters
check_item (
:CheckMenuItem
) – the check button triggering the call
-
validate_layout
(layout, expected_widgets, optional_widgets={})[source]¶ Validate layout: check whether the layout of widgets built from the config string is valid.
- Parameters
Layout must have all self.placeable_widgets (leaves of the tree, as
str
) and only allowed properties on the nodes of the tree (asdict
).Contraints on the only allowed properties of the nodes are: - resizeable:
bool
(optional, defaults to no), - orientation:str
, either “vertical” or “horizontal” (mandatory) - children:list
of size >= 2, containingstr`s or `dict`s (mandatory) - proportions: `list
offloat
with sum = 1, length == len(children), representing the relative sizes of all the resizeable items (if and only if resizeable).
-
-
pympress.config.
layout_from_json
(layout_string)[source]¶ Load the layout from config, with all strings cast to type
str
(even on python2 where they default tounicode
) Raises ValueError until python 3.4, json.decoder.JSONDecodeError afterwards, on invalid input.- Parameters
layout_string (
str
) – A JSON string to be loaded.
pympress.extras
– Manages the display of fancy extras such as annotations, videos and cursors¶
-
class
pympress.extras.
Annotations
(builder)[source]¶ Bases:
object
-
add_annotations
(annotations)[source]¶ Insert text annotations into the tree view that displays them.
- Parameters
annotations (
list
) – A list of strings, that are the annotations to be displayed
-
annotation_renderer
= None¶ CellRendererText
Text renderer for the annotations
-
scrollable_treelist
= None¶ The containing widget for the annotations
-
scrolled_window
= None¶ Making the annotations list scroll if it’s too long
-
-
class
pympress.extras.
FileWatcher
[source]¶ Bases:
object
A class with only static methods that wraps object watchdogs, to trigger callbacks when a file changes.
-
classmethod
call
(callback, *args, **kwargs)[source]¶ Call the callback
- Parameters
callback (
function
) – callback to call with all the further arguments
-
classmethod
enqueue
(callback, *args, **kwargs)[source]¶ Do not call callback directly, instead delay as to avoid repeated calls in short periods of time.
- Parameters
callback (
function
) – callback to call with all the further arguments
-
monitor
= <watchdog.events.FileSystemEventHandler object>¶ A
FileSystemEventHandler
to get notified when the file changes
-
observer
= <InotifyObserver(Thread-1, initial daemon)>¶ A
Observer
to watch when the file changes
-
classmethod
stop_daemon
(wait=False)[source]¶ Stop the watchdog observer thread.
- Parameters
wait (
bool
) – whether to wait for the thread to have joined before returning
-
timeout
= 0¶
-
classmethod
-
class
pympress.extras.
Media
(builder)[source]¶ Bases:
object
-
adjust_margins_for_mode
(page_type)[source]¶ Adjust the relative margins of child widgets for notes mode update.
- Parameters
page_type (
PdfPage
) – The part of the page to display
-
static
backend_version
()[source]¶ Returns which backend is used.
- Returns
The name and version of the backend.
- Return type
-
hide
(media_id, button=None)[source]¶ Stops playing a media and hides the player. Used as a callback.
- Parameters
media_id (
int
) – A unique idientifier of the media to start playing
-
play
(media_id, button=None)[source]¶ Starts playing a media. Used as a callback.
- Parameters
media_id (
int
) – A unique idientifier of the media to start playing
-
play_pause
(media_id, *args)[source]¶ Toggles playing and pausing a media. Used as a callback.
- Parameters
media_id (
int
) – A unique idientifier of the media to start playing
-
-
class
pympress.extras.
TimingReport
(parent)[source]¶ Bases:
pympress.builder.Builder
-
reset
(reset_time)[source]¶ A timer reset. Clear the history as soon as we start changing pages again.
-
-
class
pympress.extras.
Zoom
(builder)[source]¶ Bases:
object
-
clear_cache
()¶ callback, to be connected to
clear_cache()
-
delayed_callback_connection
(scribble_builder)[source]¶ Connect callbacks later than at init, due to circular dependencies. Call this when the page_number module is initialized, but before needing the callback.
- Parameters
builder (builder.Builder) – The builder from which to load widgets for scribble
-
draw_zoom_target
(widget, cairo_context)[source]¶ Perform the drawings by user.
- Parameters
widget (
DrawingArea
) – The widget where to draw the scribbles.cairo_context (
Context
) – The canvas on which to render the drawings
-
get_matrix
(ww, wh)[source]¶ Returns the
Matrix
used to perform the zoom for the widget of size ww x wh.
-
get_slide_point
(widget, event)[source]¶ Gets the point on the slide on a scale (0..1, 0..1), from its position in the widget.
MenuItem
that is clicked to stop zooming
Handles an key press event: stop trying to select an area to zoom.
-
redraw_current_slide
()¶ callback, to be connected to
redraw_current_slide()
-
scale
= 1.0¶
-
set_scribble_zoomout_sensitive
()¶ a callback for the
set_sensitive()
function of the zoom-out button in the scribble interface
-
shift
= (0, 0)¶
-
start_zooming
(*args)[source]¶ Setup for the user to select the zooming area.
- Returns
whether the event was consumed
- Return type
-
stop_zooming
(*args)[source]¶ Cancel the zooming, if it was enabled.
- Returns
whether the event was consumed
- Return type
-
zoom_points
= None¶
-
zoom_selecting
= False¶ Whether we are displaying the interface to scribble on screen and the overlays containing said scribbles
-
pympress.util
– various utility functions¶
-
pympress.util.
fileopen
(f)[source]¶ Call the right function to open files, based on the platform.
- Parameters
f (
str
) – path to the file to open
-
pympress.util.
get_locale_dir
()[source]¶ Returns the path to the locale directory
- Returns
The path to the locale directory
- Return type
-
pympress.util.
get_ui_resource_file
(name)[source]¶ Load an UI definition file from pympress’ resources.
-
pympress.util.
load_style_provider
(style_provider)[source]¶ Load the css and in a style provider.
- Parameters
style_provider (
CssProvider
) – The style provider in which to load CSS- Returns
The style provider with CSS loaded
- Return type
pympress.media_overlay
– widget to play videos with a backend like VLC¶
-
class
pympress.media_overlay.
GifOverlay
(container, show_controls, relative_margins, page_type, callback_getter)[source]¶ Bases:
pympress.media_overlay.VideoOverlay
A simple overlay mimicking the functionality of showing videos, but showing gifs instead.
-
advance_gif
()[source]¶ Advance the gif, queue redrawing if the frame changed, and schedule the next frame.
-
anim
= None¶ A
PixbufAnimation
containing all the frames and their timing for the displayed gif
-
do_play
()[source]¶ Start playing the media file. Should run on the main thread to ensure we avoid vlc plugins’ reentrency problems.
-
do_play_pause
()[source]¶ Toggle pause mode of the media. Should run on the main thread to ensure we avoid vlc plugins’ reentrency problems.
-
do_set_time
(t)[source]¶ Set the player at time t. Should run on the main thread to ensure we avoid vlc plugins’ reentrency problems.
-
draw
(widget, ctx)[source]¶ Simple resized drawing: get the pixbuf, set the transform, draw the image.
-
iter
= None¶ A
PixbufAnimationIter
which will provide the timely access to the frames inanim
-
-
class
pympress.media_overlay.
VLCVideo
(*args, **kwargs)[source]¶ Bases:
pympress.media_overlay.VideoOverlay
Simple VLC widget.
Its player can be controlled through the ‘player’ attribute, which is a
MediaPlayer
instance.-
do_play
()[source]¶ Start playing the media file. Should run on the main thread to ensure we avoid vlc plugins’ reentrency problems.
- Returns
True
iff this function should be run again (idle_add()
convention)- Return type
-
do_play_pause
()[source]¶ Toggle pause mode of the media. Should run on the main thread to ensure we avoid vlc plugins’ reentrency problems.
- Returns
True
iff this function should be run again (idle_add()
convention)- Return type
-
do_set_time
(t)[source]¶ Set the player at time t. Should run on the main thread to ensure we avoid vlc plugins’ reentrency problems.
- Parameters
t (
float
) – the timestamp, in s- Returns
True
iff this function should be run again (idle_add()
convention)- Return type
-
handle_embed
(mapped_widget)[source]¶ Handler to embed the VLC player in the correct window, connected to the
map
signal
-
-
class
pympress.media_overlay.
VideoOverlay
(container, show_controls, relative_margins, page_type, callback_getter)[source]¶ Bases:
pympress.builder.Builder
Simple Video widget.
- Parameters
container (
Overlay
) – The container with the slide, at the top of which we add the movie areashow_controls (
bool
) – whether to display controls on the video playerpage_type (
PdfPage
) – the part of the page to displayrelative_margins (
Rectangle
) – the margins defining the position of the video in the frame.
-
do_hide
()[source]¶ Remove widget from overlays. Needs to be callded via GLib.idle_add
- Returns
True
iff this function should be run again (idle_add()
convention)- Return type
-
do_play
()[source]¶ Start playing the media file. Should run on the main thread to ensure we avoid vlc plugins’ reentrency problems.
-
do_play_pause
()[source]¶ Toggle pause mode of the media. Should run on the main thread to ensure we avoid vlc plugins’ reentrency problems.
-
do_set_time
(t)[source]¶ Set the player at time t. Should run on the main thread to ensure we avoid vlc plugins’ reentrency problems.
-
dragging_paused
= False¶ bool
that tracks whether the playback was paused when the user started dragging the position
-
format_millis
(sc, prog)[source]¶ Callback to format the current timestamp (in milliseconds) as minutes:seconds
-
handle_embed
(mapped_widget)[source]¶ Handler to embed the video player in the correct window, connected to the
map
signal
-
is_shown
()[source]¶ Returns whether the media overlay is currently added to the overlays, or hidden.
-
movie_zone
= None¶ DrawingArea
where the media is rendered.
-
play_pause
= None¶ callback, to be connected to
play_pause()
, curryfied with the correct media_id
-
progress_moved
(rng, sc, val)[source]¶ Callback to update the position of the video when the user moved the progress bar.
-
relative_margins
= None¶ tuple
containing the left/top/right/bottom space around the drawing area in the visible slide
-
relative_page_margins
= None¶ tuple
containing the left/top/right/bottom space around the drawing area in the PDF page
-
set_file
(filepath)[source]¶ Sets the media file to be played by the widget.
- Parameters
filepath (
str
) – The path to the media file path
-
set_time
= None¶ callback, to be connected to
set_time()
, curryfied with the correct media_id
-
time_format
= '{:01}:{:02}'¶ ss / m:ss when the max time is known
- Type
Format of the video time, defaults to m
- Type
ss, changed to m
-
update_margins_for_page
(page_type)[source]¶ - Parameters
page_type (
PdfPage
) – the part of the page to display
-
pympress.media_overlay.
get_window_handle
(window)[source]¶ Uses ctypes to call gdk_win32_window_get_handle which is not available in python gobject introspection porting (yet ?) Solution from http://stackoverflow.com/a/27236258/1387346
- Parameters
window (
Window
) – The window for which we want to get the handle- Returns
The handle to the win32 window