def OnInit(self): self.presentationScreens = [] self.presentorsScreens = [] config.loadFile(appcfg.configFile) parser, args = config.loadArgv(sys.argv) if config['predouf00']: os.system(config['predouf00']) if config['postdouf00']: atexit.register(lambda: os.system(config['postdouf00'])) if len(args) > 1: parser.error('Only one slidepath is supported.') elif len(args) == 1: slidepath = args[0] else: if config['slidepath']: slidepath = config['slidepath'] else: slidepath = wx.FileSelector( 'Choose a file to open', wildcard='*.pdf') if not slidepath: print >>sys.stderr, parser.format_help() sys.exit('No path specified') slidetype = guessFiletype(slidepath) if not slidetype == 'PDF': if config['password']: parser.error('Option -S is only suitable for PDF files') if config['blankpage']: parser.error('Option -B is only supported with PDF files') pdfpass = None if config['password']: pdfpass = wx.GetPasswordFromUser('PDF password') if slidetype == 'dir': if config['blankslide']: config['blankslide'] = os.path.abspath(config['blankslide']) try: os.chdir(slidepath) except OSError: sys.exit('No such file or directory') appcfg.pictureFiles = [] files = os.listdir(os.getcwd()) # support for more picture types for fname in files: if guessFiletype(fname) in ('JPEG', 'PNG', 'BMP', 'PCX'): appcfg.pictureFiles.append(fname) appcfg.pictureFiles.sort() if config['blankslide']: if guessFiletype(config['blankslide']) in ('JPEG', 'PNG', 'BMP', 'PCX'): appcfg.blankslide = ('image', config['blankslide']) if appcfg.blankslide[1] in appcfg.pictureFiles: appcfg.pictureFiles.remove(appcfg.blankslide[1]) else: sys.exit('File type not supported') else: appcfg.blankslide = '' elif slidetype == 'PDF': pdf.load(os.path.abspath(slidepath), password=pdfpass) appcfg.pictureFiles = [] for i in xrange(pdf.get_n_pages()): appcfg.pictureFiles.append(i) if config['blankslide']: if guessFiletype(config['blankslide']) in ('JPEG', 'PNG', 'BMP', 'PCX'): appcfg.blankslide = ('image', config['blankslide']) if appcfg.blankslide[1] in appcfg.pictureFiles: appcfg.pictureFiles.remove(appcfg.blankslide[1]) else: sys.exit('File type not supported') elif not config['blankpage'] == 0: appcfg.blankslide = ('PDF', config['blankpage'] - 1) appcfg.pictureFiles.remove(appcfg.blankslide[1]) else: appcfg.blankslide = '' elif slidetype is None: sys.exit('File type not supported') appcfg.slidelist = ImageList() displayCount = wx.Display.GetCount() self.numberFrames = [] for d in xrange(displayCount): self.numberFrames.append(NumberFrame(d)) self.choice = DisplayChoice() self.choice.button.Bind(wx.EVT_BUTTON, self.Run) if config['autostart']: self.Run(None) return True
def OnInit(self): self.presentationScreens = [] self.presentorsScreens = [] atexit.register(self.exit) config.loadFile(appcfg.configFile) parser, args = config.loadArgv(sys.argv) self.preApp() atexit.register(self.postApp) if len(args) > 1: parser.error('Only one slidpath is supported.') elif len(args) == 1: slidepath = args[0] else: if config['slidepath']: slidepath = config['slidepath'] else: slidepath = wx.FileSelector('Choose a file to open', wildcard='*.pdf') if not slidepath: print parser.format_help() sys.exit('No path specified') slidetype = guessFiletype(slidepath) if not slidetype == 'PDF': if config['password']: parser.error('Option -S is only suitable for PDF files') if config['blankpage']: parser.error('Option -B is only supported with PDF files') if config['password']: appcfg.pdfpass = wx.GetPasswordFromUser('PDF password') if slidetype == 'dir': if config['blankslide']: config['blankslide'] = os.path.abspath(config['blankslide']) try: os.chdir(slidepath) except OSError: sys.exit('No such file or directory') appcfg.pictureFiles = [] files = os.listdir(os.getcwd()) # support for more picture types for fname in files: if guessFiletype(fname) in ('JPEG', 'PNG', 'BMP', 'PCX'): appcfg.pictureFiles.append(fname) appcfg.pictureFiles.sort() if config['blankslide']: if guessFiletype(config['blankslide']) in ('JPEG', 'PNG', 'BMP', 'PCX'): appcfg.blankslide = ('image', config['blankslide']) if appcfg.blankslide[1] in appcfg.pictureFiles: appcfg.pictureFiles.remove(appcfg.blankslide[1]) else: print('File type not supported') sys.exit(1) else: appcfg.blankslide = '' elif slidetype == 'PDF': try: import poppler except ImportError: print 'python-poppler required' sys.exit(1) appcfg.pdfdoc = poppler.document_new_from_file( 'file://%s' % (os.path.abspath(slidepath)), appcfg.pdfpass) appcfg.pictureFiles = [] for i in xrange(appcfg.pdfdoc.get_n_pages()): appcfg.pictureFiles.append(i) if config['blankslide']: if guessFiletype(config['blankslide']) in ('JPEG', 'PNG', 'BMP', 'PCX'): appcfg.blankslide = ('image', config['blankslide']) if appcfg.blankslide[1] in appcfg.pictureFiles: appcfg.pictureFiles.remove(appcfg.blankslide[1]) else: print('File type not supported') sys.exit(1) elif not config['blankpage'] == 0: appcfg.blankslide = ('PDF', config['blankpage'] - 1) appcfg.pictureFiles.remove(appcfg.blankslide[1]) else: appcfg.blankslide = '' elif slidetype == None: print('File type not supported') sys.exit(1) appcfg.thumbnaillist = ImageList('Thumbnails', appcfg.THUMBNAIL_SIZE) appcfg.slidelist = ImageList('Slides') displayCount = wx.Display.GetCount() self.numberFrames = [] for d in xrange(displayCount): self.numberFrames.append(NumberFrame(d)) self.choice = DisplayChoice() self.choice.button.Bind(wx.EVT_BUTTON, self.Run) self.runTime = 120 self.startTime = int(time.mktime(time.localtime())) self.remainingTime = self.runTime self.elapsedTime = 0 if config['autostart']: self.Run(None) return True