How to use the pympress.extras function in pympress

To help you get started, we’ve selected a few pympress examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Cimbali / pympress / pympress / __main__.py View on Github external
# prefere X11 on posix systems because Wayland still has some shortcomings for us,
    # specifically libVLC and the ability to disable screensavers
    if util.IS_POSIX:
        Gdk.set_allowed_backends('x11,*')
    Gtk.init(argv)

    pympress_meta = util.get_pympress_meta()['version']
    logger.info(' '.join(['Pympress:', pympress_meta,
            '; Python:', platform.python_version(),
            '; OS:', platform.system(), platform.release(), #platform.version(),
            '; Gtk {}.{}.{}'.format(Gtk.get_major_version(), Gtk.get_minor_version(), Gtk.get_micro_version()),
            '; GLib {}.{}.{}'.format(GLib.MAJOR_VERSION, GLib.MINOR_VERSION, GLib.MICRO_VERSION),
            '; Poppler', document.Poppler.get_version(), document.Poppler.get_backend().value_nick,
            '; Cairo', ui.cairo.cairo_version_string(), ', pycairo', ui.cairo.version,
            '; Media:', extras.Media.backend_version()
        ]))

    try:
        opts, args = getopt.getopt(argv, "hn:t:", ["help", "notes=", "talk-time=", "log="])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    ett, log_level, notes_pos = parse_opts(opts)
    logger.setLevel(log_level)

    # Create windows
    gui = ui.UI()

    # pass command line args
    if ett: gui.est_time.set_time(ett)
github Cimbali / pympress / pympress / scribble.py View on Github external
Returns:
            `bool`: whether it was possible to disable (thus if it was not disabled already)
        """
        if not self.scribbling_mode:
            return False

        self.swap_layout('highlight', None)
        p_layout = self.p_central.get_children()[0]

        self.off_render.add(self.scribble_overlay)
        self.scribbling_mode = False
        self.pres_highlight.set_active(self.scribbling_mode)

        self.p_central.queue_draw()
        extras.Cursor.set_cursor(self.p_central)

        return True
github Cimbali / pympress / pympress / ui.py View on Github external
# Where did the event occur?
        if widget is self.p_da_next:
            page = self.doc.next_page()
            if page is None:
                return
        else:
            page = self.doc.current_page()

        x, y = self.zoom.get_slide_point(widget, event)
        page_mode = self.notes_mode if widget is self.p_da_notes else self.notes_mode.complement()

        if page.get_link_at(x, y, page_mode):
            extras.Cursor.set_cursor(widget, 'pointer')
            return False
        else:
            extras.Cursor.set_cursor(widget, 'parent')
            return True
github Cimbali / pympress / pympress / ui.py View on Github external
""" 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.

        Args:
            docpath (`str`): the absolute path to the new document
            page (`int`): the page at which to start the presentation
            reloading (`bool`): whether we are reloading or detecting stuff from the document
        """
        try:
            self.doc = document.Document.create(self, docpath)

            if not reloading and docpath:
                Gtk.RecentManager.get_default().add_item(self.doc.get_uri())
                extras.FileWatcher.watch_file(docpath, self.reload_document)

        except GLib.Error:
            if reloading:
                return
            self.doc = document.Document.create(self, None)
            self.error_opening_file(docpath)
            extras.FileWatcher.stop_watching()

        # Guess notes mode by default if the document has notes
        if not reloading:
            hpref = self.config.get('notes position', 'horizontal')
            vpref = self.config.get('notes position', 'vertical')
            self.chosen_notes_mode = target_mode = self.doc.guess_notes(hpref, vpref)

            # don't toggle from NONE to NONE
            if self.chosen_notes_mode == document.PdfPage.NONE:
github Cimbali / pympress / pympress / pointer.py View on Github external
# Set mouse pointer and cursors on/off, if windows are already mapped
        self.show_pointer = False
        for slide_widget in [self.p_da_cur, self.c_da]:
            ww, wh = slide_widget.get_allocated_width(), slide_widget.get_allocated_height()
            if max(ww, wh) == 1:
                continue

            pointer_coordinates = slide_widget.get_window().get_pointer()

            if 0 < pointer_coordinates.x < ww and 0 < pointer_coordinates.y < wh \
                    and self.pointer_mode == PointerMode.CONTINUOUS:
                # Laser activated right away
                self.pointer_pos = (pointer_coordinates.x / ww, pointer_coordinates.y / wh)
                self.show_pointer = True
                extras.Cursor.set_cursor(slide_widget, 'invisible')
            else:
                extras.Cursor.set_cursor(slide_widget, 'parent')

        self.redraw_current_slide()
github Cimbali / pympress / pympress / pointer.py View on Github external
event (:class:`~Gdk.Event`):  the GTK event.

        Returns:
            `bool`: whether the event was consumed
        """
        # Only handle enter/leave events on one of the current slides
        if self.pointer_mode != PointerMode.CONTINUOUS or widget not in [self.c_da, self.p_da_cur]:
            return False

        if event.type == Gdk.EventType.ENTER_NOTIFY:
            self.show_pointer = True
            extras.Cursor.set_cursor(widget, 'invisible')

        elif event.type == Gdk.EventType.LEAVE_NOTIFY:
            self.show_pointer = False
            extras.Cursor.set_cursor(widget, 'parent')

        self.redraw_current_slide()
        return True
github Cimbali / pympress / pympress / ui.py View on Github external
util.load_style_provider(Gtk.CssProvider()),
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
        )

        self.show_annotations = self.config.getboolean('presenter', 'show_annotations')

        # Surface cache
        self.cache = surfacecache.SurfaceCache(self.doc, self.config.getint('cache', 'maxpages'))

        # Make and populate windows
        self.load_ui('presenter')
        self.load_ui('content')

        self.zoom = extras.Zoom(self)
        self.scribbler = scribble.Scribbler(self.config, self, self.notes_mode)
        self.annotations = extras.Annotations(self)
        self.medias = extras.Media(self, self.config)
        self.laser = pointer.Pointer(self.config, self)
        self.est_time = editable_label.EstimatedTalkTime(self)
        self.page_number = editable_label.PageNumber(self, self.config.getboolean('presenter', 'scroll_number'))
        self.talk_time = talk_time.TimeCounter(self, self.est_time)
        self.timing = extras.TimingReport(self)

        # solve circular creation-time dependency
        self.est_time.delayed_callback_connection(self)
        self.zoom.delayed_callback_connection(self.scribbler)

        # Get placeable widgets. NB, get the highlight one manually from the scribbler class
        self.placeable_widgets = {
            name: self.get_object(widget_name) for name, widget_name in self.config.placeable_widgets.items()
        }
        self.placeable_widgets['highlight'] = self.scribbler.scribble_overlay
github Cimbali / pympress / pympress / ui.py View on Github external
Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(),
            util.load_style_provider(Gtk.CssProvider()),
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
        )

        self.show_annotations = self.config.getboolean('presenter', 'show_annotations')

        # Surface cache
        self.cache = surfacecache.SurfaceCache(self.doc, self.config.getint('cache', 'maxpages'))

        # Make and populate windows
        self.load_ui('presenter')
        self.load_ui('content')

        self.zoom = extras.Zoom(self)
        self.scribbler = scribble.Scribbler(self.config, self, self.notes_mode)
        self.annotations = extras.Annotations(self)
        self.medias = extras.Media(self, self.config)
        self.laser = pointer.Pointer(self.config, self)
        self.est_time = editable_label.EstimatedTalkTime(self)
        self.page_number = editable_label.PageNumber(self, self.config.getboolean('presenter', 'scroll_number'))
        self.talk_time = talk_time.TimeCounter(self, self.est_time)
        self.timing = extras.TimingReport(self)

        # solve circular creation-time dependency
        self.est_time.delayed_callback_connection(self)
        self.zoom.delayed_callback_connection(self.scribbler)

        # Get placeable widgets. NB, get the highlight one manually from the scribbler class
        self.placeable_widgets = {
            name: self.get_object(widget_name) for name, widget_name in self.config.placeable_widgets.items()