ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change
on this file since 0ba0774 was
31c5b58,
checked in by Piotr Rozyczko <rozyczko@…>, 8 years ago
|
Refactored to allow running with run.py.
Minor fixes to plotting.
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Line | |
---|
1 | import os |
---|
2 | import sys |
---|
3 | import logging |
---|
4 | |
---|
5 | from PyQt4 import QtCore |
---|
6 | |
---|
7 | |
---|
8 | class XStream(QtCore.QObject): |
---|
9 | _stdout = None |
---|
10 | _stderr = None |
---|
11 | messageWritten = QtCore.pyqtSignal(str) |
---|
12 | |
---|
13 | def flush(self): |
---|
14 | pass |
---|
15 | |
---|
16 | def fileno(self): |
---|
17 | return -1 |
---|
18 | |
---|
19 | def write(self, msg): |
---|
20 | if(not self.signalsBlocked()): |
---|
21 | self.messageWritten.emit(unicode(msg)) |
---|
22 | |
---|
23 | @staticmethod |
---|
24 | def stdout(): |
---|
25 | if(not XStream._stdout): |
---|
26 | XStream._stdout = XStream() |
---|
27 | sys.stdout = XStream._stdout |
---|
28 | return XStream._stdout |
---|
29 | |
---|
30 | @staticmethod |
---|
31 | def stderr(): |
---|
32 | if(not XStream._stderr): |
---|
33 | XStream._stderr = XStream() |
---|
34 | sys.stderr = XStream._stderr |
---|
35 | return XStream._stderr |
---|
36 | |
---|
37 | class QtHandler(logging.Handler): |
---|
38 | """ |
---|
39 | Version of logging handler |
---|
40 | "emitting" the message to custom stdout() |
---|
41 | """ |
---|
42 | def __init__(self): |
---|
43 | logging.Handler.__init__(self) |
---|
44 | |
---|
45 | def emit(self, record): |
---|
46 | record = self.format(record) |
---|
47 | if record: |
---|
48 | XStream.stdout().write('%s\n'%record) |
---|
49 | |
---|
50 | |
---|
51 | # Define the default logger |
---|
52 | logger = logging.getLogger() |
---|
53 | |
---|
54 | # Add the file handler |
---|
55 | logging.basicConfig(level=logging.INFO, |
---|
56 | format='%(asctime)s %(levelname)s %(message)s', |
---|
57 | filename=os.path.join(os.path.expanduser("~"), |
---|
58 | 'sasview.log')) |
---|
59 | # Add the qt-signal logger |
---|
60 | handler = QtHandler() |
---|
61 | handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s")) |
---|
62 | logger.addHandler(handler) |
---|
Note: See
TracBrowser
for help on using the repository browser.