[python-win32] Re: StartDoc failed

Roger Upole rwupole at msn.com
Tue Feb 22 00:14:01 CET 2005


You should be able to use win32print.GetPrinter to check
the state.  Either the status or the attributes (or both) should
change when it's not available. (Atributes are element 13
of the returned tuple, Status is element 18)
    hth
        Roger


----- Original Message ----- 
From: "Luc Saffre" <luc.saffre at gmx.net>
To: <python-win32 at python.org>
Sent: Saturday, February 19, 2005 9:21 AM
Subject: [python-win32] StartDoc failed


> Hello,
>
> if my default windows printer is a network printer and not available, then 
> dc.StartDoc() causes a traceback which I cannot catch using try...except. 
> According to
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_CDC.3a3a.StartDoc.asp
> I would have expected it to simply return 0 or negative on failure.
>
> Example:
>
>  #file startjob.py
>  import win32ui
>  dc = win32ui.CreateDC()
>  dc.CreatePrinterDC(None)
>  try:
>     dc.StartDoc("foo")
>     # ... print to printer
>     dc.EndDoc()
>  except Exception,e:
>     print "your default printer is not reachable"
>
> If I run this, I get:
>
> Traceback (most recent call last):
>   File "startjob.py", line 6, in ?
>     dc.StartDoc("foo")
> win32ui: StartDoc failed
>
> Is there a workaround? How can I catch and handle the case of a non-ready 
> printer?
>
> (i'm using pywin32 build 203 and python 2.3)
>
> tia,
> Luc
>
> 



More information about the Python-win32 mailing list