Пример #1
0
class TestPanel(wx.Panel):
    def __init__(self, parent, log):
        wx.Panel.__init__(self, parent, -1)

        mainsizer = wx.BoxSizer(wx.HORIZONTAL)
        leftsizer = wx.BoxSizer(wx.VERTICAL)
        self.pdf = PDFWindow(self, style=wx.SUNKEN_BORDER)
        leftsizer.Add(self.pdf, proportion=1, flag=wx.EXPAND)

        box = wx.StaticBox(self, wx.NewId(), "" )
        buttonsizer = wx.StaticBoxSizer(box, wx.HORIZONTAL )
    
        b1 = wx.Button(self, wx.NewId(), "First")
        buttonsizer.Add(b1, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
        self.Bind(wx.EVT_BUTTON, self.OnFirstPageButton, b1)

        b2 = wx.Button(self,  wx.NewId(), "Previous")
        buttonsizer.Add(b2, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
        self.Bind(wx.EVT_BUTTON, self.OnPreviousPageButton, b2)
        
        tx1 = wx.StaticText(self, wx.NewId(), "   Go to page" )
        buttonsizer.Add(tx1, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
        tc1 = wx.TextCtrl(self, wx.NewId(), "0", size=[30,-1])
        buttonsizer.Add( tc1, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
        self.Bind(wx.EVT_TEXT, self.OnGotoPage, tc1)
    
        b3 = wx.Button(self, wx.NewId(), "Next")
        buttonsizer.Add(b3, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
        self.Bind(wx.EVT_BUTTON, self.OnNextPageButton, b3)

        b4 = wx.Button(self, wx.NewId(), "Last")
        buttonsizer.Add(b4, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
        self.Bind(wx.EVT_BUTTON, self.OnLastPageButton, b4)

        tx2 = wx.StaticText(self, wx.NewId(), "     Zoom")
        buttonsizer.Add(tx2, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
 
        ch1 = wx.Choice(self, wx.NewId(),
                        choices=["Default", "Fit", "FitH", "FitV",
                                 "25%", "50%", "75%", "100%", "125%", "200%", "400%"])
        ch1.SetSelection(0)
        buttonsizer.Add(ch1, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
        self.Bind(wx.EVT_CHOICE, self.OnZoom, ch1)

        leftsizer.Add(buttonsizer, proportion=0)
        mainsizer.Add(leftsizer, proportion=1, flag=wx.GROW|wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, border=5)

        box = wx.StaticBox(self, wx.NewId(), "" )
        rightsizer = wx.StaticBoxSizer(box, wx.VERTICAL)
    
        b5 = wx.Button(self, wx.NewId(), "Load PDF")
        rightsizer.Add(b5, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
        self.Bind(wx.EVT_BUTTON, self.OnLoadButton, b5)

        b6 = wx.Button(self, wx.NewId(), "Print")
        rightsizer.Add(b6, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
        self.Bind(wx.EVT_BUTTON, self.OnPrintButton, b6)

        tx3 = wx.StaticText(self, wx.NewId(), "Page mode:")
        rightsizer.Add(tx3, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)

        ch2 = wx.Choice(self, wx.NewId(),size=[100,-1],
                        choices=["None", "Bookmarks", "Thumbs"])
        ch2.SetSelection(0)
        rightsizer.Add(ch2, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
        self.Bind(wx.EVT_CHOICE, self.OnPageMode, ch2)

        tx4 = wx.StaticText(self, wx.NewId(), "Layout mode:")
        rightsizer.Add(tx4, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)

        ch3 = wx.Choice(self, wx.NewId(),size=[100,-1],
                        choices=["DontCare", "SinglePage",
                                 "OneColumn", "TwoColumnLeft", "TwoColumnRight" ])
        ch3.SetSelection(0)
        rightsizer.Add(ch3, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
        self.Bind(wx.EVT_CHOICE, self.OnLayoutMode, ch3)

        cx1 = wx.CheckBox(self, wx.NewId(), "Toolbar")
        cx1.SetValue( True )
        rightsizer.Add( cx1,proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
        self.Bind(wx.EVT_CHECKBOX, self.OnToolbar, cx1)

        cx2 = wx.CheckBox(self, wx.NewId(), "Scrollbars")
        cx2.SetValue( True )
        rightsizer.Add( cx2,proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
        self.Bind(wx.EVT_CHECKBOX, self.OnScrollbars, cx2)

        mainsizer.Add( rightsizer, proportion=0, flag=wx.ALL, border=15)
        self.SetSizer(mainsizer)
        self.SetAutoLayout(True)

    def OnFirstPageButton(self, event):
        self.pdf.gotoFirstPage()

    def OnPreviousPageButton(self, event):
        self.pdf.gotoPreviousPage()

    def OnNextPageButton(self, event):
        self.pdf.gotoNextPage()

    def OnLastPageButton(self, event):
        self.pdf.gotoLastPage()

    def OnGotoPage(self, event):
        npage = event.GetEventObject().GetValue()
        try:
            self.pdf.setCurrentPage(int(npage))
        except ValueError:
            pass

    def OnZoom(self, event):
        astring = event.GetEventObject().GetStringSelection()
        if astring.startswith('Fit'):
            self.pdf.setView(astring)
        else:
            try:
                percent = float(astring.replace('%',''))
                self.pdf.setZoom(percent)
            except ValueError:
                pass
        
    def OnLoadButton(self, event):
        dlg = wx.FileDialog(self, wildcard="*.pdf")
        if dlg.ShowModal() == wx.ID_OK:
            wx.BeginBusyCursor()
            self.pdf.LoadFile(dlg.GetPath())
            wx.EndBusyCursor()
        dlg.Destroy()

    def OnPrintButton(self, event):
        self.pdf.Print()

    def OnPageMode(self, event):
        astring = event.GetEventObject().GetStringSelection()
        self.pdf.setPageMode(astring.lower())

    def OnLayoutMode(self, event):
        astring = event.GetEventObject().GetStringSelection()
        self.pdf.setLayoutMode(astring)

    def OnToolbar(self, event):
        on = event.GetEventObject().GetValue()
        self.pdf.setShowToolbar(on)

    def OnScrollbars(self, event):
        on = event.GetEventObject().GetValue()
        self.pdf.setShowScrollbars(on)
Пример #2
0
class TestPanel(wx.Panel):
    def __init__(self, parent, log):
        wx.Panel.__init__(self, parent, -1)

        mainsizer = wx.BoxSizer(wx.HORIZONTAL)
        leftsizer = wx.BoxSizer(wx.VERTICAL)
        self.pdf = PDFWindow(self, style=wx.SUNKEN_BORDER)
        leftsizer.Add(self.pdf, proportion=1, flag=wx.EXPAND)

        box = wx.StaticBox(self, wx.NewId(), "" )
        buttonsizer = wx.StaticBoxSizer(box, wx.HORIZONTAL )
    
        b1 = wx.Button(self, wx.NewId(), "First")
        buttonsizer.Add(b1, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
        self.Bind(wx.EVT_BUTTON, self.OnFirstPageButton, b1)

        b2 = wx.Button(self,  wx.NewId(), "Previous")
        buttonsizer.Add(b2, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
        self.Bind(wx.EVT_BUTTON, self.OnPreviousPageButton, b2)
        
        tx1 = wx.StaticText(self, wx.NewId(), "   Go to page" )
        buttonsizer.Add(tx1, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
        tc1 = wx.TextCtrl(self, wx.NewId(), "0", size=[30,-1])
        buttonsizer.Add( tc1, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
        self.Bind(wx.EVT_TEXT, self.OnGotoPage, tc1)
    
        b3 = wx.Button(self, wx.NewId(), "Next")
        buttonsizer.Add(b3, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
        self.Bind(wx.EVT_BUTTON, self.OnNextPageButton, b3)

        b4 = wx.Button(self, wx.NewId(), "Last")
        buttonsizer.Add(b4, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
        self.Bind(wx.EVT_BUTTON, self.OnLastPageButton, b4)

        tx2 = wx.StaticText(self, wx.NewId(), "     Zoom")
        buttonsizer.Add(tx2, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
 
        ch1 = wx.Choice(self, wx.NewId(),
                        choices=["Default", "Fit", "FitH", "FitV",
                                 "25%", "50%", "75%", "100%", "125%", "200%", "400%"])
        ch1.SetSelection(0)
        buttonsizer.Add(ch1, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
        self.Bind(wx.EVT_CHOICE, self.OnZoom, ch1)

        leftsizer.Add(buttonsizer, proportion=0)
        mainsizer.Add(leftsizer, proportion=1, flag=wx.GROW|wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, border=5)

        box = wx.StaticBox(self, wx.NewId(), "" )
        rightsizer = wx.StaticBoxSizer(box, wx.VERTICAL)
    
        b5 = wx.Button(self, wx.NewId(), "Load PDF")
        rightsizer.Add(b5, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
        self.Bind(wx.EVT_BUTTON, self.OnLoadButton, b5)

        b6 = wx.Button(self, wx.NewId(), "Print")
        rightsizer.Add(b6, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
        self.Bind(wx.EVT_BUTTON, self.OnPrintButton, b6)

        tx3 = wx.StaticText(self, wx.NewId(), "Page mode:")
        rightsizer.Add(tx3, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)

        ch2 = wx.Choice(self, wx.NewId(),size=[100,-1],
                        choices=["None", "Bookmarks", "Thumbs"])
        ch2.SetSelection(0)
        rightsizer.Add(ch2, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
        self.Bind(wx.EVT_CHOICE, self.OnPageMode, ch2)

        tx4 = wx.StaticText(self, wx.NewId(), "Layout mode:")
        rightsizer.Add(tx4, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)

        ch3 = wx.Choice(self, wx.NewId(),size=[100,-1],
                        choices=["DontCare", "SinglePage",
                                 "OneColumn", "TwoColumnLeft", "TwoColumnRight" ])
        ch3.SetSelection(0)
        rightsizer.Add(ch3, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
        self.Bind(wx.EVT_CHOICE, self.OnLayoutMode, ch3)

        cx1 = wx.CheckBox(self, wx.NewId(), "Toolbar")
        cx1.SetValue( True )
        rightsizer.Add( cx1,proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
        self.Bind(wx.EVT_CHECKBOX, self.OnToolbar, cx1)

        cx2 = wx.CheckBox(self, wx.NewId(), "Scrollbars")
        cx2.SetValue( True )
        rightsizer.Add( cx2,proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
        self.Bind(wx.EVT_CHECKBOX, self.OnScrollbars, cx2)

        mainsizer.Add( rightsizer, proportion=0, flag=wx.ALL, border=15)
        self.SetSizer(mainsizer)
        self.SetAutoLayout(True)

    def OnFirstPageButton(self, event):
        self.pdf.gotoFirstPage()

    def OnPreviousPageButton(self, event):
        self.pdf.gotoPreviousPage()

    def OnNextPageButton(self, event):
        self.pdf.gotoNextPage()

    def OnLastPageButton(self, event):
        self.pdf.gotoLastPage()

    def OnGotoPage(self, event):
        npage = event.GetEventObject().GetValue()
        try:
            self.pdf.setCurrentPage(int(npage))
        except ValueError:
            pass

    def OnZoom(self, event):
        astring = event.GetEventObject().GetStringSelection()
        if astring.startswith('Fit'):
            self.pdf.setView(astring)
        else:
            try:
                percent = float(astring.replace('%',''))
                self.pdf.setZoom(percent)
            except ValueError:
                pass
        
    def OnLoadButton(self, event):
        dlg = wx.FileDialog(self, wildcard="*.pdf")
        if dlg.ShowModal() == wx.ID_OK:
            wx.BeginBusyCursor()
            self.pdf.LoadFile(dlg.GetPath())
            wx.EndBusyCursor()
        dlg.Destroy()

    def OnPrintButton(self, event):
        self.pdf.Print()

    def OnPageMode(self, event):
        astring = event.GetEventObject().GetStringSelection()
        self.pdf.setPageMode(astring.lower())

    def OnLayoutMode(self, event):
        astring = event.GetEventObject().GetStringSelection()
        self.pdf.setLayoutMode(astring)

    def OnToolbar(self, event):
        on = event.GetEventObject().GetValue()
        self.pdf.setShowToolbar(on)

    def OnScrollbars(self, event):
        on = event.GetEventObject().GetValue()
        self.pdf.setShowScrollbars(on)
Пример #3
0
class My_Frame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self,
                          parent,
                          -1,
                          title,
                          size=(720, 600),
                          style=wx.DEFAULT_FRAME_STYLE
                          | wx.NO_FULL_REPAINT_ON_RESIZE)

        #------------

        # Simplified init method.
        self.CreateCtrls()
        self.LoadPdf()
        self.BindEvents()
        self.DoLayout()

        #---------------------------------------------------------------

        self.CenterOnScreen()

    #-------------------------------------------------------------------

    def CreateCtrls(self):
        """
        ...
        """

        fontSize = self.GetFont().GetPointSize()
        boldFont = wx.Font(fontSize, wx.SWISS, wx.NORMAL, wx.BOLD)

        #------------

        self.panel = wx.Panel(self, -1)

        #------------

        # Add PDFWindow
        self.pdf = PDFWindow(self.panel, style=wx.SUNKEN_BORDER)
        self.pdf.setView("FitV")
        self.pdf.setPageMode("Bookmarks")
        self.pdf.setLayoutMode("SinglePage")
        self.pdf.setShowScrollbars(True)

        #------------

        # Add controls
        self.btn1 = wx.Button(self.panel, -1, "&Open")
        self.btn1.SetToolTip("Open PDF file.")

        self.btn2 = wx.Button(self.panel, -1, "<<", size=(30, -1))
        self.btn2.SetToolTip("First page.")
        self.btn2.SetFont(boldFont)

        self.btn3 = wx.Button(self.panel, -1, "<", size=(30, -1))
        self.btn3.SetToolTip("Previous page.")
        self.btn3.SetFont(boldFont)

        self.btn4 = wx.Button(self.panel, -1, ">", size=(30, -1))
        self.btn4.SetToolTip("Next page.")
        self.btn4.SetFont(boldFont)

        self.btn5 = wx.Button(self.panel, -1, ">>", size=(30, -1))
        self.btn5.SetToolTip("Last page.")
        self.btn5.SetFont(boldFont)

        self.txt1 = wx.StaticText(self.panel, -1, "   Go to page")
        self.txtCtrl = wx.TextCtrl(self.panel, -1, "0", size=[30, -1])

        self.txt2 = wx.StaticText(self.panel, -1, "     Zoom")
        self.zoom = wx.Choice(self.panel,
                              -1,
                              choices=[
                                  "Default", "Fit", "FitH", "FitV", "25%",
                                  "50%", "75%", "100%", "125%", "200%", "400%"
                              ])
        self.zoom.SetSelection(0)
        self.zoom.SetToolTip("Zoom.")

        self.btn6 = wx.Button(self.panel, -1, "&Pr&int")
        self.btn6.SetToolTip("Print PDF file.")

        self.btn7 = wx.Button(self.panel, -1, "&Quit")
        self.btn7.SetToolTip("Quit application.")

    def BindEvents(self):
        """
        Bind all the events related to my frame.
        """

        self.Bind(wx.EVT_BUTTON, self.OnOpenBtn, self.btn1)
        self.Bind(wx.EVT_BUTTON, self.OnFirstPageBtn, self.btn2)
        self.Bind(wx.EVT_BUTTON, self.OnPrevPageBtn, self.btn3)
        self.Bind(wx.EVT_BUTTON, self.OnNextPageBtn, self.btn4)
        self.Bind(wx.EVT_BUTTON, self.OnLastPageBtn, self.btn5)
        self.Bind(wx.EVT_BUTTON, self.OnPrintBtn, self.btn6)
        self.Bind(wx.EVT_BUTTON, self.OnCloseBtn, self.btn7)

        self.Bind(wx.EVT_TEXT, self.OnGotoPage, self.txtCtrl)
        self.Bind(wx.EVT_CHOICE, self.OnZoom, self.zoom)

        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)

    def DoLayout(self):
        """
        Manage widgets Layout.
        """

        # MainSizer is the top-level one that manages everything.
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.pdf, proportion=1, flag=wx.EXPAND)

        #------------

        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
        btnSizer.Add(self.btn1,
                     proportion=0,
                     flag=wx.ALIGN_CENTER | wx.ALL,
                     border=5)
        btnSizer.Add(self.btn2,
                     proportion=0,
                     flag=wx.ALIGN_CENTER | wx.ALL,
                     border=2)
        btnSizer.Add(self.btn3,
                     proportion=0,
                     flag=wx.ALIGN_CENTER | wx.ALL,
                     border=2)
        btnSizer.Add(self.btn4,
                     proportion=0,
                     flag=wx.ALIGN_CENTER | wx.ALL,
                     border=2)
        btnSizer.Add(self.btn5,
                     proportion=0,
                     flag=wx.ALIGN_CENTER | wx.ALL,
                     border=2)
        btnSizer.Add(self.txt1,
                     proportion=0,
                     flag=wx.ALIGN_CENTER | wx.ALL,
                     border=5)
        btnSizer.Add(self.txtCtrl,
                     proportion=0,
                     flag=wx.ALIGN_CENTER | wx.ALL,
                     border=5)
        btnSizer.Add(self.txt2,
                     proportion=0,
                     flag=wx.ALIGN_CENTER | wx.ALL,
                     border=5)
        btnSizer.Add(self.zoom,
                     proportion=0,
                     flag=wx.ALIGN_CENTER | wx.ALL,
                     border=5)
        btnSizer.Add(self.btn6,
                     proportion=0,
                     flag=wx.ALIGN_CENTER | wx.ALL,
                     border=5)
        btnSizer.Add(self.btn7,
                     proportion=0,
                     flag=wx.ALIGN_CENTER | wx.ALL,
                     border=5)
        btnSizer.Add((50, -1), proportion=2, flag=wx.EXPAND)

        #------------

        sizer.Add(btnSizer, proportion=0, flag=wx.EXPAND)

        #------------

        # Finally, tell the panel to use the mainSizer for layout.
        self.panel.SetSizer(sizer)
        self.panel.SetAutoLayout(True)

    def LoadPdf(self):
        """
        ...
        """

        self.pdf.LoadFile(doc)

    def OnOpenBtn(self, event):
        """
        ...
        """

        dlg = wx.FileDialog(self, wildcard="*.pdf")

        if dlg.ShowModal() == wx.ID_OK:
            wx.BeginBusyCursor()
            self.pdf.LoadFile(dlg.GetPath())
            wx.EndBusyCursor()

        dlg.Destroy()

    def OnFirstPageBtn(self, event):
        """
        ...
        """

        self.pdf.gotoFirstPage()

    def OnPrevPageBtn(self, event):
        """
        ...
        """

        self.pdf.gotoPreviousPage()

    def OnNextPageBtn(self, event):
        """
        ...
        """

        self.pdf.gotoNextPage()

    def OnLastPageBtn(self, event):
        """
        ...
        """

        self.pdf.gotoLastPage()

    def OnGotoPage(self, event):
        """
        ...
        """

        npage = event.GetEventObject().GetValue()

        try:
            self.pdf.setCurrentPage(int(npage))
        except ValueError:
            pass

    def OnZoom(self, event):
        """
        ...
        """

        astring = event.GetEventObject().GetStringSelection()

        if astring.startswith('Fit'):
            self.pdf.setView(astring)
        else:
            try:
                percent = float(astring.replace('%', ''))
                self.pdf.setZoom(percent)
            except ValueError:
                pass

    def OnPrintBtn(self, event):
        """
        ...
        """

        self.pdf.Print()

    def OnCloseBtn(self, event):
        """
        ...
        """

        self.Close(True)

    def OnEraseBackground(self, event):
        """
        ...
        """

        dc = event.GetDC()

        if not dc:
            dc = wx.ClientDC(self)
            rect = self.GetUpdateRegion().GetBox()
            dc.SetClippingRect(rect)

    def OnCloseWindow(self, event):
        """
        ...
        """

        self.Destroy()