source: sasview/guiframe/pdfview.py @ 60c7011

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 60c7011 was 60c7011, checked in by Jae Cho <jhjcho@…>, 13 years ago

added tutorial viewer

  • Property mode set to 100644
File size: 3.4 KB
Line 
1# Read PDF files by embeding the Adobe Acrobat Reader
2# wx.activex module uses class ActiveX control
3
4import  wx
5if wx.Platform == '__WXMSW__':
6    from wx.lib.pdfwin import PDFWindow
7
8class PDFPanel(wx.Panel):
9    """
10    Panel that contains the pdf reader
11    """
12    def __init__(self, parent, path=None):
13        """
14        """
15        wx.Panel.__init__(self, parent, id=-1)
16       
17        self.parent = parent
18        sizer = wx.BoxSizer(wx.VERTICAL)
19        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
20       
21        self.pdf = PDFWindow(self, style=wx.SUNKEN_BORDER)
22       
23        sizer.Add(self.pdf, proportion=1, flag=wx.EXPAND)
24       
25        btn = wx.Button(self, wx.NewId(), "Open PDF File")
26        self.Bind(wx.EVT_BUTTON, self.OnOpenButton, btn)
27        btnSizer.Add(btn, proportion=1, flag=wx.EXPAND|wx.ALL, border=5)
28
29        self.pdf.LoadFile(path)
30        btn = wx.Button(self, wx.NewId(), "Previous Page")
31        self.Bind(wx.EVT_BUTTON, self.OnPrevPageButton, btn)
32        btnSizer.Add(btn, proportion=1, flag=wx.EXPAND|wx.ALL, border=5)
33
34        btn = wx.Button(self, wx.NewId(), "Next Page")
35        self.Bind(wx.EVT_BUTTON, self.OnNextPageButton, btn)
36        btnSizer.Add(btn, proportion=1, flag=wx.EXPAND|wx.ALL, border=5)
37       
38        btn = wx.Button(self, wx.NewId(), "Close")
39        self.Bind(wx.EVT_BUTTON, self.OnClose, btn)
40        btnSizer.Add(btn, proportion=1, flag=wx.EXPAND|wx.ALL, border=5)
41        btnSizer.Add((50,-1), proportion=2, flag=wx.EXPAND)
42        sizer.Add(btnSizer, proportion=0, flag=wx.EXPAND)
43
44        self.SetSizer(sizer)
45        self.SetAutoLayout(True)
46       
47    def OnOpenButton(self, event):
48        """
49        Open file button
50        """
51        # make sure you have PDF files available on your drive
52        dlg = wx.FileDialog(self, wildcard="*.pdf")
53        if dlg.ShowModal() == wx.ID_OK:
54            wx.BeginBusyCursor()
55            self.pdf.LoadFile(dlg.GetPath())
56
57            wx.EndBusyCursor()
58        dlg.Destroy()
59       
60    def OnLoad(self, event=None, path=None):
61        """
62        Load a pdf file
63       
64        : Param path: full path to the file
65        """
66        self.pdf.LoadFile(path)
67
68       
69    def OnPrevPageButton(self, event):
70        """
71        Goes to Previous page
72        """
73        self.pdf.gotoPreviousPage()
74
75    def OnNextPageButton(self, event):
76        """
77        Goes to Next page
78        """
79        self.pdf.gotoNextPage()
80       
81    def OnClose(self, event):
82        """
83        Close panel
84        """
85        self.parent.Destroy()
86
87class PDFFrame(wx.Frame):
88    """
89    Frame for PDF panel
90    """
91    def __init__(self, parent, id, title, path):
92        """
93        Init
94       
95        :param parent: parent panel/container
96        :param path: full path of the pdf file
97        """
98        # Initialize the Frame object
99        wx.Frame.__init__(self, parent, id, title,
100                          wx.DefaultPosition, wx.Size(600, 830))
101        # make an instance of the class
102        PDFPanel(self, path) 
103       
104class ViewApp(wx.App):
105    def OnInit(self):
106        path = None
107        frame = PDFFrame(None, -1, "PDFView", path=path) 
108         
109        frame.Show(True)
110        #self.SetTopWindow(frame)
111       
112        return True
113               
114if __name__ == "__main__": 
115    app = ViewApp(0)
116    app.MainLoop()     
Note: See TracBrowser for help on using the repository browser.