Quantcast

Fwd: wxPostscriptDC problems

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Fwd: wxPostscriptDC problems

Andrew Jones-12
I have an application where I create a graph that I need to be able to print to postscript in order to collate it with some other postscript I generate.  On linux I was able to get this to work by going through the print framework to print to a file without prompting the user.  When I port this to windows however, the print framework uses a wx.PrinterDC instead of the wx.PostscriptDC so instead of postscript I get some unusable printer code.  I'm trying to just create my own wx.PostscriptDC and plot directly to that, but I keep getting an error message complaining of an 'invalid postscript dc'.  Does anybody know how to either force windows to use the PostScriptDC, or how to use a PostScriptDC directly?

Thanks

Andrew

Here is my attempt to use a PostscriptDC directly:

def OnPrint(s, evt):
    printData = wx.PrintData()
    printData.SetPaperId(wx.PAPER_LETTER)

    printData.SetPrintMode(wx.PRINT_MODE_FILE)
   
    tf = tempfile.mktemp(".ps")
    printData.SetFilename(tf)
    dc = wx.PostScriptDC(printData)

    dc.StartPage()
    s.Plot(dc)
    dc.EndPage()
    s.disp.ViewPSFile(tf)

And the error message that results:

Traceback (most recent call last):
  File "C:\Users\Andrew\Work\dataminer/lib\crossplot\crossplot.py", line 1200, in OnPrint
    dc.StartPage()
  File "C:\NER\Python24\lib\site-packages\wx-2.8-msw-unicode\wx\_gdi.py", line 3647, in StartPage
    return _gdi_.DC_StartPage(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "m_pstream" failed at ..\..\src\generic\dcpsg.cpp(2232) in wxPostScriptDC::PsPrint(): invalid postscript dc

I have also tried the following on the off chance the PrintDialogData class set something in printData that would make it work, but it failed with the same error message...

def OnPrint(s, evt):
    printData = wx.PrintData()
    printData.SetPaperId(wx.PAPER_LETTER)

    printData.SetPrintMode(wx.PRINT_MODE_FILE)
   
    tf = tempfile.mktemp(".ps")
    printData.SetFilename(tf)

    pdd = wx.PrintDialogData()
    pdd.SetPrintData(s.printData)

    pdd.SetPrintToFile(1)

    dc = wx.PostScriptDC(pdd.GetPrintData())

    dc.StartPage()
    s.Plot(dc)
    dc.EndPage()
    s.disp.ViewPSFile(tf)



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Fwd: wxPostscriptDC problems

Robin Dunn
Quoting Andrew Jones <[hidden email]>:

> I have an application where I create a graph that I need to be able to print
> to postscript in order to collate it with some other postscript I generate.
> On linux I was able to get this to work by going through the print framework
> to print to a file without prompting the user.  When I port this to windows
> however, the print framework uses a wx.PrinterDC instead of the
> wx.PostscriptDC so instead of postscript I get some unusable printer code.
> I'm trying to just create my own wx.PostscriptDC and plot directly to that,
> but I keep getting an error message complaining of an 'invalid postscript
> dc'.  Does anybody know how to either force windows to use the PostScriptDC,
> or how to use a PostScriptDC directly?


> Here is my attempt to use a PostscriptDC directly:
>
> def OnPrint(s, evt):
>     printData = wx.PrintData()
>     printData.SetPaperId(wx.PAPER_LETTER)
>     printData.SetPrintMode(wx.PRINT_MODE_FILE)
>
>     tf = tempfile.mktemp(".ps")
>     printData.SetFilename(tf)
>     dc = wx.PostScriptDC(printData)
>
>     dc.StartPage()
>     s.Plot(dc)
>     dc.EndPage()
>     s.disp.ViewPSFile(tf)

The wx.PostScriptDC requires that you call dc.StartDoc.  That's where
it creates the output file (and assigns it to the m_pstream variable
you see mentioned in the exception message.)  Call EndDoc when you are
done, to write the last bits to the file and close it.

--
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Fwd: wxPostscriptDC problems

Andrew Jones-12
That fixed it. Thanks a lot!

Andrew

On Thu, Apr 24, 2008 at 8:56 PM, Robin Dunn <[hidden email]> wrote:
Quoting Andrew Jones <[hidden email]>:

I have an application where I create a graph that I need to be able to print
to postscript in order to collate it with some other postscript I generate.
On linux I was able to get this to work by going through the print framework
to print to a file without prompting the user.  When I port this to windows
however, the print framework uses a wx.PrinterDC instead of the
wx.PostscriptDC so instead of postscript I get some unusable printer code.
I'm trying to just create my own wx.PostscriptDC and plot directly to that,
but I keep getting an error message complaining of an 'invalid postscript
dc'.  Does anybody know how to either force windows to use the PostScriptDC,
or how to use a PostScriptDC directly?


Here is my attempt to use a PostscriptDC directly:

def OnPrint(s, evt):
   printData = wx.PrintData()
   printData.SetPaperId(wx.PAPER_LETTER)
   printData.SetPrintMode(wx.PRINT_MODE_FILE)

   tf = tempfile.mktemp(".ps")
   printData.SetFilename(tf)
   dc = wx.PostScriptDC(printData)

   dc.StartPage()
   s.Plot(dc)
   dc.EndPage()
   s.disp.ViewPSFile(tf)

The wx.PostScriptDC requires that you call dc.StartDoc.  That's where
it creates the output file (and assigns it to the m_pstream variable
you see mentioned in the exception message.)  Call EndDoc when you are
done, to write the last bits to the file and close it.

--
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!




_______________________________________________
wxpython-users mailing list
[hidden email]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Loading...