示例#1
0
        def OnFilePrint(self, event):
            d = wx.MessageDialog(self,
"""As of this writing, printing support in wxPython is shaky at best.
Are you sure you want to do this?""", "Danger!", wx.YES_NO)
            if d.ShowModal() == wx.ID_YES:
                psdc = wx.PostScriptDC("out.ps", True, self)
                self.client.redraw(psdc)
 def OnFilePrint(self, event):
     d = wx.MessageDialog(
         self, "As of this writing, printing support "
         "in wxPython is shaky at best.\n"
         "Are you sure you want to do this?", "Warning", wx.YES_NO)
     if d.ShowModal() == wx.ID_YES:
         psdc = wx.PostScriptDC("out.ps", wx.true, self)
         self.canvas.redraw(psdc)
示例#3
0
 def OnExportAsEps(self, evt):
     n = self.AskExportFileName(_("EPS image"), "eps")
     if n is not None:
         pd = wx.PrintData()
         pd.SetPaperId(wx.PAPER_NONE)
         pd.SetPrintMode(wx.PRINT_MODE_FILE)
         pd.SetFilename(n)
         dc = wx.PostScriptDC(pd)
         dc.StartDoc(_("Exporting image as EPS..."))
         self.DrawOnDC(dc)
         dc.EndDoc()
示例#4
0
    def SaveFile(self, fileName=''):
        """Saves the file to the type specified in the extension. If no file
        name is specified a dialog box is provided.  Returns True if sucessful,
        otherwise False.
        
        .bmp  Save a Windows bitmap file.
        .xbm  Save an X bitmap file.
        .xpm  Save an XPM bitmap file.
        .png  Save a Portable Network Graphics file.
        .jpg  Save a Joint Photographic Experts Group file.
        """
        fileTypes = BITMAP_TYPE.keys()
        fileTypes.sort()
        ext = fileName[-3:].lower()
        if ext not in fileTypes:
            dlg1 = wx.FileDialog(
                self, "Save image as", ".", "", "|".join([
                    "%s files (*%s)|*%s" % (t.upper(), t, t) for t in fileTypes
                ]), wx.SAVE | wx.OVERWRITE_PROMPT)
            if dlg1.ShowModal() == wx.ID_OK:
                fileName = dlg1.GetPath()
                # Check for proper exension
                ext = os.path.splitext(fileName)[-1]
                if ext not in fileTypes:
                    ext = fileTypes[dlg1.GetFilterIndex()]
                    fileName += ext
                dlg1.Destroy()
            else:  # exit without saving
                dlg1.Destroy()
                return False

        tp = BITMAP_TYPE[ext]
        # Save...
        w, h = self.GetVirtualSize()
        if tp:
            #...as bitmap
            dc = wx.MemoryDC()
            bitmap = wx.EmptyBitmap(w + 10, h + 10)
            dc.SelectObject(bitmap)
            dc.SetBackground(wx.WHITE_BRUSH)
            dc.Clear()
            self.Redraw(dc)
            return bitmap.SaveFile(fileName, tp)
        else:
            #... as postscript
            printData = wx.PrintData()
            printData.SetFilename(fileName)
            dc = wx.PostScriptDC(printData)
            if dc.Ok():
                dc.StartDoc('Saving as postscript')
                doPrint(dc, self)
                #self.Redraw(dc)
                dc.EndDoc()
示例#5
0
 def printSizes(self, filename):
     """ Export the Canvas to Postscript """
     prdata = wx.PrintData()
     from Explorers.Explorer import openEx
     t = openEx(filename)
     prdata.SetFilename(t.currentFilename())
     dc = wx.PostScriptDC(prdata)
     if dc.Ok():
         dc.StartDoc('Export')
         self.Redraw(dc)
         dc.EndDoc()
         
         wx.LogMessage('Exported %s'%filename)
示例#6
0
    def test_PostscriptDC1(self):
        pd = wx.PrintData()
        pd.SetPrintMode(wx.PRINT_MODE_FILE)
        pd.SetFilename(fileName)

        dc = wx.PostScriptDC(pd)
        pen = wx.Pen('black')
        self.assertTrue(pen.IsOk())
        dc.StartDoc("message")
        dc.SetPen(pen)
        dc.DrawLine(0, 0, 50, 50)
        dc.EndDoc()
        del dc

        os.remove(fileName)
示例#7
0
 def PS_Print(self):
     print("Using PostScriptDC")
     PData = wx.PrintData()
     PData.SetFilename("TestPS.ps")
     DC = wx.PostScriptDC(PData)
     print("PPI", DC.GetPPI())