@@ -34,14 +34,11 @@ class Progress(QtCore.QObject):
34
34
remove_query_signal = QtCore .Signal (str )
35
35
progress_signal = QtCore .Signal (str , int , int )
36
36
37
- def __init__ (self , min_duration = 1000 ):
37
+ def __init__ (self , parent , min_duration = 1000 ):
38
38
39
- super ().__init__ ()
39
+ super ().__init__ (parent )
40
40
self ._progress_dialog = None
41
41
42
- from .main_window import MainWindow
43
- self ._parent = MainWindow .instance ()
44
-
45
42
# Timer called for refreshing the progress dialog status
46
43
self ._rtimer = QtCore .QTimer ()
47
44
self ._rtimer .timeout .connect (self .update )
@@ -98,6 +95,10 @@ def _cancelSlot(self):
98
95
for query in self ._queries .copy ().values ():
99
96
query ["response" ].abort ()
100
97
98
+ def _rejectSlot (self ):
99
+ self ._progress_dialog = None
100
+ self ._cancelSlot ()
101
+
101
102
def update (self ):
102
103
if len (self ._queries ) == 0 and (time .time () * 1000 ) >= self ._display_start_time + self ._minimum_duration :
103
104
self .hide ()
@@ -106,8 +107,9 @@ def update(self):
106
107
107
108
def show (self ):
108
109
if self ._progress_dialog is None or self ._progress_dialog .wasCanceled ():
109
- progress_dialog = QtWidgets .QProgressDialog ("Waiting for server response" , None , 0 , 0 , self ._parent )
110
+ progress_dialog = QtWidgets .QProgressDialog ("Waiting for server response" , None , 0 , 0 , self .parent () )
110
111
progress_dialog .canceled .connect (self ._cancelSlot )
112
+ progress_dialog .rejected .connect (self ._rejectSlot )
111
113
progress_dialog .setWindowModality (Qt .Qt .ApplicationModal )
112
114
progress_dialog .setWindowTitle ("Please wait" )
113
115
progress_dialog .setMinimumDuration (self ._minimum_duration )
@@ -180,13 +182,14 @@ def context(self, **kwargs):
180
182
self ._cancel_button_text = old_cancel_button_text
181
183
182
184
@staticmethod
183
- def instance ():
185
+ def instance (parent = None ):
184
186
"""
185
187
Singleton to return only one instance of Progress.
186
188
187
189
:returns: instance of Progress
188
190
"""
189
191
190
192
if not hasattr (Progress , "_instance" ) or Progress ._instance is None :
191
- Progress ._instance = Progress ()
193
+ Progress ._instance = Progress (parent )
192
194
return Progress ._instance
195
+
0 commit comments