SHARE
TWEET

Marcelo Fernndez

a guest Apr 12th, 2009 381 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. import wx
  3. import wx.lib.wxcairo
  4. import sys
  5. import poppler
  6.  
  7. class MyFrame(wx.Frame):
  8.  
  9.     def __init__(self):
  10.         wx.Frame.__init__(self, None, -1, "Cairo Test", size=(500,400))
  11.         self.Bind(wx.EVT_PAINT, self.OnPaint)
  12.         uri = "file://" + sys.argv[1]
  13.         self.document = poppler.document_new_from_file (uri, None)
  14.         self.n_pages = self.document.get_n_pages()
  15.  
  16.         self.current_page = self.document.get_page(0)
  17.         self.scale = 1
  18.         self.width, self.height = self.current_page.get_size()
  19.         self.SetSize((self.width, self.height))
  20.  
  21.     def OnPaint(self, event):
  22.         dc = wx.PaintDC(self)
  23.         cr = wx.lib.wxcairo.ContextFromDC(dc)
  24.         cr.set_source_rgb(1, 1, 1)
  25.  
  26.         if self.scale != 1:
  27.             cr.scale(self.scale, self.scale)
  28.        
  29.         cr.rectangle(0, 0, self.width, self.height)
  30.         cr.fill()
  31.         self.current_page.render(cr)
  32.  
  33.  
  34. if __name__=="__main__":
  35.     app = wx.App()
  36.     f = MyFrame()
  37.     f.Show()
  38.     app.MainLoop()
RAW Paste Data
Want to get better at Python?
Learn to code Python in 2017
Top