source: sasview/sansguiframe/src/sans/guiframe/pdfview.py @ f52d870

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 f52d870 was 8c347a6, checked in by Gervaise Alina <gervyh@…>, 13 years ago

moving guiframe under sansguiframe

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