def main(argv=sys.argv[1:]): """ Entry point of pympress. Parse command line arguments, instantiate the UI, and start the main loop. """ 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="]) opts = dict(opts) except getopt.GetoptError: usage() sys.exit(2) ett, log_level, notes_pos = parse_opts(opts) logger.setLevel(log_level) # Create windows gui = ui.UI() # Connect proper exit function to interrupt signal.signal(signal.SIGINT, gui.save_and_quit) # pass command line args if ett: gui.est_time.set_time(ett) gui.swap_document(os.path.abspath(args[0])) if args else gui.pick_file() if notes_pos is not None: gui.change_notes_pos(notes_pos, force_change=True) gui.run()
def main(argv=sys.argv[1:]): signal.signal(signal.SIGINT, signal.SIG_DFL) try: opts, args = getopt.getopt(argv, "ht:", ["help", "talk-time=", "log="]) except getopt.GetoptError: usage() sys.exit(2) ett = 0 log_level = logging.ERROR for opt, arg in opts: if opt in ("-h", "--help"): usage() sys.exit() 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(text)) usage() sys.exit(2) except IndexError: s = 0 ett = m * 60 + s elif opt == "--log": numeric_level = getattr(logging, arg.upper(), None) if isinstance(numeric_level, int): log_level = numeric_level else: print( _("Invalid log level \"{}\", try one of {}").format( arg, "DEBUG, INFO, WARNING, ERROR, CRITICAL")) logging.basicConfig(filename=os.path.join(tempfile.gettempdir(), 'pympress.log'), level=log_level) pympress_meta = util.get_pympress_meta() logger.info('\n '.join( ['Pympress version {} by:'.format(pympress_meta.__version__)] + pympress_meta.__copyright__.split('\n'))) # PDF file to open passed on command line? name = os.path.abspath(args[0]) if len(args) > 0 else None # Create windows from pympress import ui gui = ui.UI(ett, name) gui.run()
def do_activate(self, timestamp=GLib.get_current_time()): """ Activate: show UI windows. Build them if they do not exist, otherwise bring to front. """ if self.gui is None: if self.auto_log_level: self.activate_action('log-level', logging.INFO) self.action_startup_queue.append(('log-level', logging.ERROR)) # Build the UI and windows self.gui = ui.UI(self, self.config) while self.action_startup_queue: self.activate_action(*self.action_startup_queue.pop(0)) Gtk.Application.do_activate(self) self.gui.p_win.present_with_time(timestamp)
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) try: opts, args = getopt.getopt(argv, "hn:t:", ["help", "notes=", "talk-time=", "log="]) except getopt.GetoptError: usage() sys.exit(2) 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(text)) usage() sys.exit(2) except IndexError: s = 0 ett = m * 60 + s elif opt == "--log": numeric_level = getattr(logging, arg.upper(), None) if isinstance(numeric_level, int): log_level = numeric_level else: print( _("Invalid log level \"{}\", try one of {}").format( arg, "DEBUG, INFO, WARNING, ERROR, CRITICAL")) 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 ', '.'.join(map(str, GLib.glib_version)), '; Poppler', document.Poppler.get_version(), document.Poppler.get_backend().value_nick, '; Cairo', ui.cairo.cairo_version_string(), ', pycairo', ui.cairo.version, '; Media:', media_overlay.VideoOverlay.backend_version() ])) logger.setLevel(log_level) # Create windows gui = ui.UI() # pass command line args if ett: gui.est_time.set_time(ett) gui.swap_document(os.path.abspath(args[0])) if args else gui.pick_file() if notes_pos is not None: gui.change_notes_pos(notes_pos, force_change=True) gui.run()