Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 swap_document(self, docpath, page = 0, reloading = False):
""" Replace the currently open document with a new one.
The new document is possibly and EmptyDocument if docpath is None.
The state of the ui and cache are updated accordingly.
Args:
docpath (`str`): the absolute path to the new document
page (`int`): the page at which to start the presentation
reloading (`bool`): whether we are reloading or detecting stuff from the document
"""
try:
self.doc = document.Document.create(self, docpath)
if not reloading and docpath:
Gtk.RecentManager.get_default().add_item(self.doc.get_uri())
extras.FileWatcher.watch_file(docpath, self.reload_document)
except GLib.Error:
if reloading:
return
self.doc = document.Document.create(self, None)
self.error_opening_file(docpath)
extras.FileWatcher.stop_watching()
# Guess notes mode by default if the document has notes
if not reloading:
hpref = self.config.get('notes position', 'horizontal')
vpref = self.config.get('notes position', 'vertical')
wh (`int`): target height in pixels
dtype (:class:`~pympress.document.PdfPage`): the type of document that should be rendered
"""
pass
def can_render(self):
""" Informs that rendering is *not* necessary (avoids checking the type).
Returns:
`bool`: `False`, no rendering
"""
return False
class EmptyDocument(Document):
""" A dummy document, placeholder for when no document is open.
"""
def __init__(self):
self.path = None
self.doc = None
self.nb_pages = 0
self.cur_page = -1
self.pages_cache = {-1: EmptyPage()}
self.notes = False
def page(self, number):
""" Retrieve a page from the document.
Args:
""" Initializes a Document by passing it a :class:`~Poppler.Document`.
Args:
builder (:class:`pympress.builder.Builder`): A builder to load callbacks
path (`str`): Absolute path to the PDF file to open
page (`int`): page number to which the file should be opened
Returns:
:class:`~pympress.document.Document`: The initialized document
"""
if path is None:
doc = EmptyDocument()
else:
uri = Document.path_to_uri(path)
poppler_doc = Poppler.Document.new_from_file(uri, None)
doc = Document(builder, poppler_doc, path, page)
return doc
def create(builder, path, page=0):
""" Initializes a Document by passing it a :class:`~Poppler.Document`.
Args:
builder (:class:`pympress.builder.Builder`): A builder to load callbacks
path (`str`): Absolute path to the PDF file to open
page (`int`): page number to which the file should be opened
Returns:
:class:`~pympress.document.Document`: The initialized document
"""
if path is None:
doc = EmptyDocument()
else:
uri = Document.path_to_uri(path)
poppler_doc = Poppler.Document.new_from_file(uri, None)
doc = Document(builder, poppler_doc, path, page)
return doc