@@ -327,18 +327,10 @@ def __init__(self, name=None, plugin=None, parent=None):
327
327
328
328
# Info widget
329
329
if self .enable_infowidget :
330
- from spyder .widgets .browser import FrameWebView
331
-
332
- self .infowidget = FrameWebView (self )
333
- if WEBENGINE :
334
- self .infowidget .page ().setBackgroundColor (
335
- QColor (MAIN_BG_COLOR ))
336
- else :
337
- self .infowidget .setStyleSheet (
338
- "background:{}" .format (MAIN_BG_COLOR ))
339
- layout .addWidget (self .infowidget )
330
+ self ._infowidget = self ._create_info_widget ()
331
+ layout .addWidget (self ._infowidget )
340
332
else :
341
- self .infowidget = None
333
+ self ._infowidget = None
342
334
343
335
# Label to inform users how to get out of the pager
344
336
self .pager_label = QLabel (_ ("Press <b>Q</b> to exit pager" ), self )
@@ -1093,6 +1085,19 @@ def change_client_mpl_conf(o=_options, c=client):
1093
1085
1094
1086
# ---- Private methods
1095
1087
# -------------------------------------------------------------------------
1088
+ def _create_info_widget (self ):
1089
+ from spyder .widgets .browser import FrameWebView
1090
+
1091
+ infowidget = FrameWebView (self )
1092
+ if WEBENGINE :
1093
+ infowidget .page ().setBackgroundColor (
1094
+ QColor (MAIN_BG_COLOR ))
1095
+ else :
1096
+ infowidget .setStyleSheet (
1097
+ "background:{}" .format (MAIN_BG_COLOR )
1098
+ )
1099
+ return infowidget
1100
+
1096
1101
def _change_client_conf (self , client , client_conf_func , value ):
1097
1102
"""
1098
1103
Change a client configuration option, taking into account if it is
@@ -1358,6 +1363,8 @@ def _update_environment_menu(self):
1358
1363
# Render consoles menu and submenus
1359
1364
self .console_environment_menu .render ()
1360
1365
1366
+ # ---- Public API
1367
+ # -------------------------------------------------------------------------
1361
1368
def find_connection_file (self , connection_file ):
1362
1369
"""Fix connection file path."""
1363
1370
cf_path = osp .dirname (connection_file )
@@ -1382,16 +1389,34 @@ def find_connection_file(self, connection_file):
1382
1389
1383
1390
return connection_file
1384
1391
1385
- # ---- Public API
1386
- # -------------------------------------------------------------------------
1392
+ @property
1393
+ def infowidget (self ):
1394
+ """
1395
+ This is necessary to prevent an error when, in some situations, Python
1396
+ garbage collects _infowidget.
1397
+
1398
+ Notes
1399
+ -----
1400
+ * See spyder-ide/spyder#21509 and spyder-ide/spyder#23529
1401
+ """
1402
+ try :
1403
+ # We need to call a method to detect if the object was garbage
1404
+ # collected and trigger the RuntimeError we want to catch here.
1405
+ self ._infowidget .isVisible ()
1406
+ return self ._infowidget
1407
+ except RuntimeError :
1408
+ self ._infowidget = self ._create_info_widget ()
1409
+ return self ._infowidget
1410
+ except AttributeError :
1411
+ return None
1387
1412
1388
1413
# ---- General
1389
1414
# -------------------------------------------------------------------------
1390
1415
def update_font (self , font , app_font ):
1391
1416
self ._font = font
1392
1417
self ._app_font = app_font
1393
1418
1394
- if self .enable_infowidget :
1419
+ if self .enable_infowidget and self . infowidget is not None :
1395
1420
self .infowidget .set_font (app_font )
1396
1421
1397
1422
for client in self .clients :
@@ -1425,18 +1450,11 @@ def refresh_container(self, give_focus=False):
1425
1450
client .set_info_page ()
1426
1451
client .shellwidget .hide ()
1427
1452
client .layout .addWidget (self .infowidget )
1428
- self .infowidget .show ()
1453
+ if self .infowidget is not None :
1454
+ self .infowidget .show ()
1429
1455
else :
1430
- if self .enable_infowidget :
1431
- try :
1432
- self .infowidget .hide ()
1433
- except RuntimeError :
1434
- # Needed to handle the possible scenario where the
1435
- # `infowidget` (`FrameWebView`) related C/C++ object
1436
- # has been already deleted when trying to hide it.
1437
- # See spyder-ider/spyder#21509
1438
- self .enable_infowidget = False
1439
- self .infowidget = None
1456
+ if self .enable_infowidget and self .infowidget is not None :
1457
+ self .infowidget .hide ()
1440
1458
client .shellwidget .show ()
1441
1459
1442
1460
# Get reference for the control widget of the selected tab
0 commit comments