Lawrence Bruhmuller <lbruhmuller@...> writes:
> Thomas Heller wrote:
>>
>>If you have a GUI application you should provide *some* way to display
>>errors. The code in boot_common is only the last ressort imo.
Obviously it is not robust enough for you, if it cannot open the file to
write to.
> We have message panes, and error dialog, and a logging framework for
> most stuff. But this is mostly to find tracebacks when we have a bug
> in our code, and we either need to find it ourselves, or more likely
> when a user (using the frozen version) needs to tell us what went
> wrong. Hence the desire to always grab this stuff ...
>
>>You could create both a GUI and a console app (the samples directories
>>show how this can be done) and run the console app instead. This should
>>let you find and fix the problem!
>>
>>
> Thanks, I'll try this now. But any tips straightaway as to what I'll
> likely be able to do (specifically, what I can import) in boot_common,
> and what I can't?
You should be able to import everything in boot_common that's in
library.zip. The problem is only: what to do when an error occurs.
>>(Sometimes I think the default behaviour should be to alloc a new
>>console and dump stderr output into this, when an unexpected exception
>>occurrs.)
>>
>>
> That would be cool, since this is hopefully only a rare case due to
> developer error, not user error. Don't suppose you have the snippet
> of code that would do this ... would the console only come up when it
> got something written to it?
The only snippet that I have is this:
from ctypes import *
class writer(object):
def __init__(self, handle):
self.handle = handle
def write(self, text):
bytes_written = c_ulong()
if isinstance(text, unicode):
windll.kernel32.WriteConsoleW(self.handle,
text,
len(text),
byref(bytes_written),
None)
else:
windll.kernel32.WriteConsoleA(self.handle,
text,
len(text),
byref(bytes_written),
None)
windll.kernel32.AllocConsole()
windll.kernel32.SetConsoleTitleA(str(title))
sys.stderr = writer(windll.kernel32.GetStdHandle(-12))
You should be able to call AllocConsole the first time the write method
is called. A remaining problem might be that the console window will
disappear automatically when the process ends - so the user may or may
not be able to read the text in it.
Thomas
|