src/eric7/UI/UserInterface.py

branch
eric7
changeset 10816
236d97cba7c5
parent 10813
77d4d1878228
child 10817
cbdafa2fc879
child 10823
13542803c1b1
equal deleted inserted replaced
10813:77d4d1878228 10816:236d97cba7c5
22 from PyQt6 import sip 22 from PyQt6 import sip
23 from PyQt6.Qsci import QSCINTILLA_VERSION_STR 23 from PyQt6.Qsci import QSCINTILLA_VERSION_STR
24 from PyQt6.QtCore import ( 24 from PyQt6.QtCore import (
25 PYQT_VERSION_STR, 25 PYQT_VERSION_STR,
26 QDate, 26 QDate,
27 QObject,
28 QProcess, 27 QProcess,
29 QSize, 28 QSize,
30 Qt, 29 Qt,
31 QThread, 30 QThread,
32 QTimer, 31 QTimer,
63 from eric7.__version__ import Version, VersionOnly 62 from eric7.__version__ import Version, VersionOnly
64 from eric7.CondaInterface.Conda import Conda 63 from eric7.CondaInterface.Conda import Conda
65 from eric7.Debugger.DebugServer import DebugServer 64 from eric7.Debugger.DebugServer import DebugServer
66 from eric7.Debugger.DebugUI import DebugUI 65 from eric7.Debugger.DebugUI import DebugUI
67 from eric7.EricCore import EricFileSystemWatcher 66 from eric7.EricCore import EricFileSystemWatcher
67 from eric7.EricCore.EricStdRedirector import EricStdRedirector
68 from eric7.EricGui import EricPixmapCache 68 from eric7.EricGui import EricPixmapCache
69 from eric7.EricGui.EricAction import EricAction, createActionGroup 69 from eric7.EricGui.EricAction import EricAction, createActionGroup
70 from eric7.EricNetwork.EricNetworkIcon import EricNetworkIcon 70 from eric7.EricNetwork.EricNetworkIcon import EricNetworkIcon
71 from eric7.EricNetwork.EricNetworkProxyFactory import ( 71 from eric7.EricNetwork.EricNetworkProxyFactory import (
72 EricNetworkProxyFactory, 72 EricNetworkProxyFactory,
113 SSL_AVAILABLE = True 113 SSL_AVAILABLE = True
114 except ImportError: 114 except ImportError:
115 SSL_AVAILABLE = False 115 SSL_AVAILABLE = False
116 116
117 117
118 class Redirector(QObject):
119 """
120 Helper class used to redirect stdout and stderr to the log window.
121
122 @signal appendStderr(str) emitted to write data to stderr logger
123 @signal appendStdout(str) emitted to write data to stdout logger
124 """
125
126 appendStderr = pyqtSignal(str)
127 appendStdout = pyqtSignal(str)
128
129 def __init__(self, stderr, parent=None):
130 """
131 Constructor
132
133 @param stderr flag indicating stderr is being redirected
134 @type bool
135 @param parent reference to the parent object
136 @type QObject
137 """
138 super().__init__(parent)
139 self.stderr = stderr
140 self.buffer = ""
141
142 def __nWrite(self, n):
143 """
144 Private method used to write data.
145
146 @param n max number of bytes to write
147 @type int
148 """
149 if n:
150 line = self.buffer[:n]
151 if self.stderr:
152 self.appendStderr.emit(line)
153 else:
154 self.appendStdout.emit(line)
155 self.buffer = self.buffer[n:]
156
157 def __bufferedWrite(self):
158 """
159 Private method returning number of characters to write.
160
161 @return number of characters buffered or length of buffered line
162 @rtype int
163 """
164 return self.buffer.rfind("\n") + 1
165
166 def flush(self):
167 """
168 Public method used to flush the buffered data.
169 """
170 self.__nWrite(len(self.buffer))
171
172 def write(self, s):
173 """
174 Public method used to write data.
175
176 @param s data to be written (it must support the str-method)
177 @type Any
178 """
179 self.buffer += str(s)
180 self.__nWrite(self.__bufferedWrite())
181
182 def isatty(self):
183 """
184 Public method to indicate a tty.
185
186 Note: This always reports 'False'.
187
188 @return flag indicating a tty
189 @rtype bool
190 """
191 return False
192
193 @property
194 def encoding(self):
195 """
196 Public method to report the used encoding.
197
198 @return used encoding
199 @rtype str
200 """
201 return Preferences.getSystem("IOEncoding")
202
203
204 class UserInterfaceSide(enum.Enum): 118 class UserInterfaceSide(enum.Enum):
205 """ 119 """
206 Class defining the supported sides of the user interface. 120 Class defining the supported sides of the user interface.
207 """ 121 """
208 122
236 onlineStateChanged = pyqtSignal(bool) 150 onlineStateChanged = pyqtSignal(bool)
237 151
238 maxFilePathLen = 100 152 maxFilePathLen = 100
239 maxMenuFilePathLen = 75 153 maxMenuFilePathLen = 75
240 154
241 # TODO: change this to 'True' for official releases 155 # NOTE: change this to 'True' for official releases
242 ReleaseMode = False 156 ReleaseMode = False
243 157
244 ErrorLogFileName = "eric7_error.log" 158 ErrorLogFileName = "eric7_error.log"
245 159
246 def __init__( 160 def __init__(
339 253
340 splash.showMessage(self.tr("Initializing Basic Services...")) 254 splash.showMessage(self.tr("Initializing Basic Services..."))
341 logging.getLogger(__name__).debug("Initializing Basic Services...") 255 logging.getLogger(__name__).debug("Initializing Basic Services...")
342 256
343 # Generate the redirection helpers 257 # Generate the redirection helpers
344 self.stdout = Redirector(False, self) 258 self.stdout = EricStdRedirector(False, self)
345 self.stdout.appendStdout.connect(self.appendToStdout) 259 self.stdout.stdoutString.connect(self.appendToStdout)
346 self.stderr = Redirector(True, self) 260 self.stderr = EricStdRedirector(True, self)
347 self.stderr.appendStderr.connect(self.appendToStderr) 261 self.stderr.stderrString.connect(self.appendToStderr)
348 # Redirect sys.stdout and/or sys.stderr if those are None 262 # Redirect sys.stdout and/or sys.stderr if those are None
349 if sys.stdout is None or UserInterface.ReleaseMode: 263 if sys.stdout is None or UserInterface.ReleaseMode:
350 sys.stdout = self.stdout 264 sys.stdout = self.stdout
351 if sys.stderr is None or UserInterface.ReleaseMode: 265 if sys.stderr is None or UserInterface.ReleaseMode:
352 sys.stderr = self.stderr 266 sys.stderr = self.stderr

eric ide

mercurial