8
8
import os
9
9
import sys
10
10
import time
11
+ import io
11
12
from contextlib import redirect_stdout
12
13
from ipaddress import ip_address
13
14
from urllib .parse import urlparse
14
- from typing import Any , Callable , Dict , Optional , Type , Tuple
15
+ from typing import Any , Callable , Dict , Optional , Tuple
15
16
16
17
import simplejson as json
17
18
from PyQt5 .QtCore import QObject , pyqtSignal , QSettings
18
19
from PyQt5 .QtWidgets import QMessageBox
19
20
20
- from constants import log_File , DefaultCache , wqueue , MAX_INPUTS_NO_WARNING
21
+ from constants import log_File , DefaultCache , MAX_INPUTS_NO_WARNING
21
22
22
23
23
24
def add_defaultKeys_to_dict (dictObj : Dict [str , Any ], defaultObj : Dict [str , Any ]) -> None :
@@ -26,7 +27,7 @@ def add_defaultKeys_to_dict(dictObj: Dict[str, Any], defaultObj: Dict[str, Any])
26
27
dictObj [key ] = defaultObj [key ]
27
28
28
29
29
- QT_MESSAGE_TYPE : Dict [str , Type [ QMessageBox .Icon ] ] = {
30
+ QT_MESSAGE_TYPE : Dict [str , QMessageBox .Icon ] = {
30
31
"info" : QMessageBox .Information ,
31
32
"warn" : QMessageBox .Warning ,
32
33
"crit" : QMessageBox .Critical ,
@@ -158,7 +159,7 @@ def myPopUp(parentWindow: Any, messType: str, messTitle: str, messText: str, def
158
159
def myPopUp_sb (parentWindow : Any , messType : str , messTitle : str , messText : str , singleButton : QMessageBox .StandardButton = QMessageBox .Ok ) -> int :
159
160
message_type = QT_MESSAGE_TYPE .get (messType , QMessageBox .Information )
160
161
mess = QMessageBox (message_type , messTitle , messText , singleButton , parent = parentWindow )
161
- mess .setStandardButtons (singleButton | singleButton )
162
+ mess .setStandardButtons (singleButton )
162
163
return mess .exec_ ()
163
164
164
165
@@ -258,8 +259,9 @@ def readCacheSettings() -> Dict[str, Any]:
258
259
259
260
260
261
def redirect_print (what : str ) -> None :
261
- with redirect_stdout (WriteStream (wqueue )):
262
- print (what )
262
+ with io .StringIO () as buffer :
263
+ with redirect_stdout (buffer ):
264
+ print (what )
263
265
264
266
265
267
def saveCacheSettings (cache : Dict [str , Any ]) -> None :
@@ -316,6 +318,18 @@ def flush(self) -> None:
316
318
pass
317
319
318
320
321
+ class WrapperWriteStream :
322
+ def __init__ (self , write_stream : WriteStream ):
323
+ self .write_stream = write_stream
324
+
325
+ def write (self , message : str ) -> int :
326
+ self .write_stream .write (message )
327
+ return len (message )
328
+
329
+ def flush (self ) -> None :
330
+ self .write_stream .flush ()
331
+
332
+
319
333
# QObject (to be run in QThread) that blocks until data is available
320
334
# and then emits a QtSignal to the main thread.
321
335
class WriteStreamReceiver (QObject ):
0 commit comments