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

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 5531a46 was 03a8b16, checked in by Jae Cho <jhjcho@…>, 13 years ago

fixed C++ error on close

  • Property mode set to 100644
File size: 3.7 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        wx.EVT_CLOSE(self.parent, self.OnClose)
49       
50    def OnOpenButton(self, event):
51        """
52        Open file button
53        """
54        # make sure you have PDF files available on your drive
55        dlg = wx.FileDialog(self, wildcard="*.pdf")
56        dlg.SetDirectory(os.path.dirname(self.path))
57        if dlg.ShowModal() == wx.ID_OK:
58            wx.BeginBusyCursor()
59            file = dlg.GetPath()
60            self.pdf.LoadFile(file)
61            self.parent.SetTitle(os.path.basename(file.split('.')[0]))
62            wx.EndBusyCursor()
63        dlg.Destroy()
64        # Let Panel know the file changed: Avoiding C++ error
65        self.Update()
66       
67    def OnLoad(self, event=None, path=None):
68        """
69        Load a pdf file
70       
71        : Param path: full path to the file
72        """
73        self.pdf.LoadFile(path)
74
75       
76    def OnPrevPageButton(self, event):
77        """
78        Goes to Previous page
79        """
80        self.pdf.gotoPreviousPage()
81
82    def OnNextPageButton(self, event):
83        """
84        Goes to Next page
85        """
86        self.pdf.gotoNextPage()
87       
88    def OnClose(self, event):
89        """
90        Close panel
91        """
92        self.parent.Destroy()
93
94class PDFFrame(wx.Frame):
95    """
96    Frame for PDF panel
97    """
98    def __init__(self, parent, id, title, path):
99        """
100        Init
101       
102        :param parent: parent panel/container
103        :param path: full path of the pdf file
104        """
105        # Initialize the Frame object
106        wx.Frame.__init__(self, parent, id, title,
107                          wx.DefaultPosition, wx.Size(600, 830))
108        # make an instance of the class
109        PDFPanel(self, path) 
110       
111class ViewApp(wx.App):
112    def OnInit(self):
113        path = None
114        frame = PDFFrame(None, -1, "PDFView", path=path) 
115         
116        frame.Show(True)
117        #self.SetTopWindow(frame)
118       
119        return True
120               
121if __name__ == "__main__": 
122    app = ViewApp(0)
123    app.MainLoop()     
Note: See TracBrowser for help on using the repository browser.