Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if not action_obj:
continue
action = self.get_annot_action(action_obj.any.type, action_obj, annotation.area)
if not action:
continue
elif annot_type == Poppler.AnnotType.FILE_ATTACHMENT:
attachment = annotation.annot.get_attachment()
prefix, ext = os.path.splitext(attachment.name)
with tempfile.NamedTemporaryFile('wb', suffix=ext, prefix=prefix, delete=False) as f:
# now the file name is shotgunned
filename = f.name
self.parent.remove_on_exit(filename)
if not attachment.save(filename):
logger.error(_("Pympress can not extract attached file"))
continue
action = Link.build_closure(fileopen, filename)
elif annot_type in {Poppler.AnnotType.TEXT, Poppler.AnnotType.POPUP,
Poppler.AnnotType.FREE_TEXT}:
# text-only annotations, hide them from screen
self.page.remove_annot(annotation.annot)
continue
elif annot_type in {Poppler.AnnotType.STRIKE_OUT, Poppler.AnnotType.HIGHLIGHT,
Poppler.AnnotType.UNDERLINE, Poppler.AnnotType.SQUIGGLY,
Poppler.AnnotType.POLYGON, Poppler.AnnotType.POLY_LINE,
Poppler.AnnotType.SQUARE, Poppler.AnnotType.CIRCLE,
Poppler.AnnotType.CARET, Poppler.AnnotType.LINE,
Poppler.AnnotType.STAMP, Poppler.AnnotType.INK}:
# Poppler already renders annotation of these types, nothing more can be done
# even though the rendering isn't always perfect.
continue
else:
logger.warning(_("Pympress can not interpret annotation of type:") + " {} ".format(annot_type))
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)
def parse_opts(opts):
ett = 0
log_level = logging.ERROR
notes_pos = None
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
sys.exit()
if opt in ("-n", "--notes"):
if arg.lower()[0] == 'n': notes_pos = document.PdfPage.NONE
if arg.lower()[0] == 'l': notes_pos = document.PdfPage.LEFT
if arg.lower()[0] == 'r': notes_pos = document.PdfPage.RIGHT
if arg.lower()[0] == 't': notes_pos = document.PdfPage.TOP
if arg.lower()[0] == 'b': notes_pos = document.PdfPage.BOTTOM
elif opt in ("-t", "--talk-time"):
t = ["0" + n.strip() for n in arg.split(':')]
try:
m = int(t[0])
s = int(t[1])
except ValueError:
print(_("Invalid time (mm or mm:ss expected), got \"{}\"").format(arg))
usage()
sys.exit(2)
except IndexError:
s = 0
ett = m * 60 + s
elif opt == "--log":
numeric_level = getattr(logging, arg.upper(), None)
def parse_opts(opts):
ett = 0
log_level = logging.ERROR
notes_pos = None
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
sys.exit()
if opt in ("-n", "--notes"):
if arg.lower()[0] == 'n': notes_pos = document.PdfPage.NONE
if arg.lower()[0] == 'l': notes_pos = document.PdfPage.LEFT
if arg.lower()[0] == 'r': notes_pos = document.PdfPage.RIGHT
if arg.lower()[0] == 't': notes_pos = document.PdfPage.TOP
if arg.lower()[0] == 'b': notes_pos = document.PdfPage.BOTTOM
elif opt in ("-t", "--talk-time"):
t = ["0" + n.strip() for n in arg.split(':')]
try:
m = int(t[0])
s = int(t[1])
except ValueError:
print(_("Invalid time (mm or mm:ss expected), got \"{}\"").format(arg))
usage()
sys.exit(2)
except IndexError:
s = 0
ett = m * 60 + s
try:
return getattr(target, handler_name)
except AttributeError:
attr_list = handler_name.split('.')
if len(attr_list) == 1:
logger.error('Handler name not in target object. Expected "." but got: {}'.format(handler_name),
exc_info = True)
raise
# Dynamically resolved handler for 'doc' (only) since target.doc may change
if 'doc' in attr_list:
return lambda *args, **kwargs: Builder.signal_resolver(target, attr_list)(*args, **kwargs)
else:
return Builder.signal_resolver(target, attr_list)
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)
ett, log_level, notes_pos = parse_opts(opts)
logger.setLevel(log_level)
# Create windows
gui = ui.UI()
if response == gtk.RESPONSE_OK:
name = dialog.get_filename()
elif response != gtk.RESPONSE_CANCEL:
raise ValueError("Invalid response")
dialog.destroy()
if name is None:
# Use a GTK dialog to tell we need a file
msg="""No file selected!\n\nYou can specify the PDF file to open on the command line if you don't want to use the "Open File" dialog."""
dialog = gtk.MessageDialog(type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK, message_format=msg)
dialog.set_position(gtk.WIN_POS_CENTER)
dialog.run()
sys.exit(1)
else:
doc = pympress.document.Document("file://" + name)
doc.run()
def parse_opts(opts):
ett = 0
log_level = logging.ERROR
notes_pos = None
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
sys.exit()
if opt in ("-n", "--notes"):
if arg.lower()[0] == 'n': notes_pos = document.PdfPage.NONE
if arg.lower()[0] == 'l': notes_pos = document.PdfPage.LEFT
if arg.lower()[0] == 'r': notes_pos = document.PdfPage.RIGHT
if arg.lower()[0] == 't': notes_pos = document.PdfPage.TOP
if arg.lower()[0] == 'b': notes_pos = document.PdfPage.BOTTOM
elif opt in ("-t", "--talk-time"):
t = ["0" + n.strip() for n in arg.split(':')]
try:
m = int(t[0])
s = int(t[1])
except ValueError:
print(_("Invalid time (mm or mm:ss expected), got \"{}\"").format(arg))
usage()
sys.exit(2)
except IndexError:
s = 0
ett = m * 60 + s
elif opt == "--log":
# 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)