Skip to content

Commit

Permalink
Beginning of an API documentation with epydoc
Browse files Browse the repository at this point in the history
epydoc can be downloaded from http://epydoc.sourceforge.net/.
At the moment, only pympress.Document is concerned.
  • Loading branch information
Thomas Jost committed Jun 9, 2009
1 parent b7f58f3 commit 4a4d3e0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.pyc
apidoc/
12 changes: 12 additions & 0 deletions epydoc.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[epydoc]
name: pympress
url: http://www.pympress.org/

modules: pympress

output: html
target: apidoc

graph: all

include-log: no
44 changes: 44 additions & 0 deletions pympress/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,30 @@
import pympress.content, pympress.presenter

class Document:
"""
This is the main class. It deals with the Poppler library for PDF document
handling, and a little bit with the GUI too.
@ivar doc : the PDF document that is currently displayed
@type doc : poppler.Document
@ivar nb_pages : number of pages in the document
@type nb_pages : integer
@ivar current : number of the current page
@type current : integer
@ivar presenter: pympress's Presenter window
@type presenter: L{pympress.Presenter}
@ivar content : pympress's Content window
@type content : L{pympress.Content}
"""

def __init__(self, uri, page=0):
"""
@param uri : URI to the PDF file to open (local only, starting with file://)
@type uri : string
@param page: page number to which the file should be opened
@type page: integer
"""

# Open PDF file
self.doc = poppler.document_new_from_file(uri, None)

Expand All @@ -40,6 +63,15 @@ def __init__(self, uri, page=0):
self.content = pympress.content.Content(first, self.event_callback)

def get_current_and_next(self, page):
"""
Return the specified page and the next one. If there is no next page,
C{None} is returned instead.
@param page: number of the page to retrieve
@type page: integer
@return : the specified page and the next one
@rtype : (poppler.Page, poppler.Page)
"""
if page >= self.nb_pages:
page = self.nb_pages-1
elif page < 0:
Expand All @@ -53,24 +85,36 @@ def get_current_and_next(self, page):
return (page, current, next)

def run(self):
"""Run the GTK main loop."""
gtk.main()

def next(self):
"""Switch to the next page."""
page, current, next = self.get_current_and_next(self.current + 1)
self.content.set_page(current)
self.presenter.set_page(current, next, page)
self.current = page

def prev(self):
"""Switch to the previous page."""
page, current, next = self.get_current_and_next(self.current - 1)
self.content.set_page(current)
self.presenter.set_page(current, next, page)
self.current = page

def fullscreen(self):
"""Switch between fullscreen and normal mode."""
self.content.switch_fullscreen()

def event_callback(self, widget, event):
"""
Manage events as key presses or clicks.
@param widget: the widget in which the event occured
@type widget: gtk.Widget
@param event : the event that occured
@type event : gtk.gdk.Event
"""
if event.type == gtk.gdk.KEY_PRESS:
name = gtk.gdk.keyval_name(event.keyval)

Expand Down

0 comments on commit 4a4d3e0

Please sign in to comment.