Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(config):
super(Config, config).__init__()
# populate values first from the default config file, then from the proper one
config.read(util.get_default_config())
config.load_window_layouts()
all_commands = dict(config.items('shortcuts')).keys()
config.read(config.path_to_config(True))
config.upgrade()
config.load_window_layouts()
for command in all_commands:
parsed = {Gtk.accelerator_parse(l) for l in config.get('shortcuts', command).split()}
if (0, 0) in parsed:
logger.warning('Failed parsing 1 or more shortcuts for ' + command)
parsed.remove((0, 0))
config.shortcuts.update({s: command for s in parsed})
def main(argv = sys.argv[1:]):
signal.signal(signal.SIGINT, signal.SIG_DFL)
# 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)
frame = gtk.Frame("Clock")
table.attach(frame, 5, 10, 1, 2, yoptions=gtk.FILL)
align = gtk.Alignment(0.5, 0.5, 1, 1)
align.set_padding(10, 10, 12, 0)
frame.add(align)
self.label_clock = gtk.Label()
self.label_clock.set_justify(gtk.JUSTIFY_CENTER)
self.label_clock.set_use_markup(True)
align.add(self.label_clock)
# Add events
win.add_events(gtk.gdk.KEY_PRESS_MASK | gtk.gdk.SCROLL_MASK)
win.connect("key-press-event", self.doc.navigation_cb)
win.connect("scroll-event", self.doc.navigation_cb)
if pympress.util.poppler_links_available():
self.da_current.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.POINTER_MOTION_MASK)
self.da_current.connect("button-press-event", self.doc.link_cb, self.get_current_page)
self.da_current.connect("motion-notify-event", self.doc.link_cb, self.get_current_page)
self.da_next.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.POINTER_MOTION_MASK)
self.da_next.connect("button-press-event", self.doc.link_cb, self.get_next_page)
self.da_next.connect("motion-notify-event", self.doc.link_cb, self.get_next_page)
# Set page
number, current, next = doc.get_two_pages(doc.nb_current)
self.set_page(current, next, number, False)
# Setup timer
gobject.timeout_add(1000, self.update_time)
win.show_all()
# Setup logging, and catch all uncaught exceptions in the log file.
# Load pympress.util early (OS and path-specific things) to load and setup gettext translation asap.
logger = logging.getLogger(__name__)
logging.basicConfig(filename=util.get_log_path(), level=logging.DEBUG)
def uncaught_handler(*exc_info):
logger.critical('Uncaught exception:\n{}'.format(logging.Formatter().formatException(exc_info)))
sys.__excepthook__(*exc_info)
sys.excepthook = uncaught_handler
if util.IS_WINDOWS:
if os.getenv('LANG') is None:
lang, enc = locale.getdefaultlocale()
os.environ['LANG'] = lang
locale.setlocale(locale.LC_ALL, '')
gettext.install('pympress', util.get_locale_dir())
# Load python bindings for gobject introspections, aka pygobject, aka gi.
# This is a dependency that is not specified in the setup.py, so we need to start here
# see https://github.com/Cimbali/pympress/issues/100
try:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GLib
def load_icons(self):
""" Set the icon list for both windows.
"""
try:
icon_list = [GdkPixbuf.Pixbuf.new_from_file(i) for i in util.list_icons()]
except Exception:
logger.exception('Error loading icons')
return
self.c_win.set_icon_list(icon_list)
self.p_win.set_icon_list(icon_list)
@type navigation_cb: GTK event handler function
@param link_cb: callback function that will be called when the user
moves the mouse over a link or activates one
@type link_cb: GTK event handler function
"""
black = gtk.gdk.Color(0, 0, 0)
# Main window
self.win = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.win.set_title("pympress content")
self.win.set_default_size(800, 600)
self.win.modify_bg(gtk.STATE_NORMAL, black)
self.win.connect("delete-event", gtk.main_quit)
# Icons
self.win.set_icon_list(*pympress.util.load_icons())
# Aspect frame
self.frame = gtk.AspectFrame(ratio=4./3., obey_child=False)
self.frame.modify_bg(gtk.STATE_NORMAL, black)
# Drawing area
self.da = gtk.DrawingArea()
self.da.modify_bg(gtk.STATE_NORMAL, black)
self.da.connect("expose-event", self.on_expose)
# Prepare the window
self.frame.add(self.da)
self.win.add(self.frame)
# Add events
self.win.add_events(gtk.gdk.KEY_PRESS_MASK | gtk.gdk.SCROLL_MASK)
# Drawing area
self.da = gtk.DrawingArea()
self.da.modify_bg(gtk.STATE_NORMAL, black)
self.da.connect("expose-event", self.on_expose)
# Prepare the window
self.frame.add(self.da)
self.win.add(self.frame)
# Add events
self.win.add_events(gtk.gdk.KEY_PRESS_MASK | gtk.gdk.SCROLL_MASK)
self.win.connect("key-press-event", navigation_cb)
self.win.connect("scroll-event", navigation_cb)
if pympress.util.poppler_links_available():
self.da.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.POINTER_MOTION_MASK)
self.da.connect("button-press-event", link_cb, self.get_page)
self.da.connect("motion-notify-event", link_cb, self.get_page)
# Don't start in fullscreen mode
self.fullscreen = False
# Add the page
self.set_page(page)
self.win.show_all()
import logging
import os
import sys
import getopt
import signal
import locale
import gettext
import platform
from pympress import util
# Setup logging, and catch all uncaught exceptions in the log file.
# Load pympress.util early (OS and path-specific things) to load and setup gettext translation asap.
logger = logging.getLogger(__name__)
logging.basicConfig(filename=util.get_log_path(), level=logging.DEBUG)
def uncaught_handler(*exc_info):
logger.critical('Uncaught exception:\n{}'.format(logging.Formatter().formatException(exc_info)))
sys.__excepthook__(*exc_info)
sys.excepthook = uncaught_handler
if util.IS_WINDOWS:
if os.getenv('LANG') is None:
lang, enc = locale.getdefaultlocale()
os.environ['LANG'] = lang
locale.setlocale(locale.LC_ALL, '')
gettext.install('pympress', util.get_locale_dir())