def _load(self, fobj): self._loaded = False if not fobj.readline().startswith(SEP): raise IOError, "Not a SlideDeX file" str = fobj.read() segments = str.split(SEP) if len(segments) < 3: raise IOError, "Could not load from file" self.settings = DocumentSettings(self, segments[0]) self.pages.clear() self.header.set_content(segments[1][1:]) # Ignore empty line for filename self.footer.set_content(segments[-1][1:]) for s in segments[2:-1]: filename, content = s.split('\n', 1) self.add_page(content, filename) pdffn = base_filename(self.fullfilename) + '.pdf' select_first_page = lambda status: self.slidelist_view.select_path((0,)) if os.path.exists(pdffn) and os.stat(pdffn).st_mtime >= os.stat(self.fullfilename).st_mtime: self.compile_pages() self.doc = poppler.document_new_from_file('file://' + os.path.abspath(pdffn), None) self.executor.add_callback(select_first_page) else: self.compile(select_first_page) self.modified = False # Set modified_since_save, and update the window title self._loaded = True
def _do_latex(self, obj, command, callback, stop_on_error): # obj is either this LatexDocument or one of its LatexSlides fn = base_filename(obj.fullfilename) def after_latex(status): if status == 0: obj.doc = poppler.document_new_from_file('file://' + os.path.abspath(fn+'.pdf'), None) if callback: callback(status) commands = [[s.format(fn=fn) for s in c.split()] for c in command.split(';')] self.executor.add(commands, stop_on_error, (after_latex,))
def __init__(self, parent, content="", filename="", render=False): self.parent = parent self.buffer = sourceview.Buffer(language=LATEXLANG) self.buffer.connect("modified-changed", self.on_buffer_modified_changed) self.doc = None self.pb = self.parent.window.render_icon(gtk.STOCK_MISSING_IMAGE, gtk.ICON_SIZE_DIALOG) self._filename = filename self._modified_since_save = True # Set to False at end of document load. self._modified_since_compile = True self.set_content(content) cached = False if self._filename: pdffn = base_filename(self.fullfilename) + '.pdf' if os.path.exists(self.fullfilename + '.tex') and os.path.exists(pdffn): self.doc = poppler.document_new_from_file('file://' + os.path.abspath(pdffn), None) self.render_thumb() self._modified_since_compile = False cached = True if render and not cached: self.compile(lambda status: not status and self.render_thumb(), False)