Skip to content

Commit

Permalink
Move safe_disconnect() to utils/qthelpers.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jitseniesen committed Nov 18, 2023
1 parent fb15821 commit d1c99e6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
11 changes: 2 additions & 9 deletions spyder/plugins/variableexplorer/widgets/arrayeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
from spyder.py3compat import (is_binary_string, is_string, is_text_string,
to_binary_string, to_text_string)
from spyder.utils.icon_manager import ima
from spyder.utils.qthelpers import add_actions, create_action, keybinding
from spyder.utils.qthelpers import (
add_actions, create_action, keybinding, safe_disconnect)
from spyder.utils.stylesheet import PANES_TOOLBAR_STYLESHEET


Expand Down Expand Up @@ -128,14 +129,6 @@ def get_idx_rect(index_list):
return ( min(rows), max(rows), min(cols), max(cols) )


def safe_disconnect(signal):
"""Disconnect a QtSignal, ignoring TypeError"""
try:
signal.disconnect()
except TypeError:
# Raised when no slots are connected to the signal
pass

#==============================================================================
# Main classes
#==============================================================================
Expand Down
13 changes: 4 additions & 9 deletions spyder/plugins/variableexplorer/widgets/dataframeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
from spyder.py3compat import (is_text_string, is_type_text_string,
to_text_string)
from spyder.utils.icon_manager import ima
from spyder.utils.qthelpers import (add_actions, create_action,
MENU_SEPARATOR, keybinding,
qapplication)
from spyder.utils.qthelpers import (
add_actions, create_action, keybinding, MENU_SEPARATOR, qapplication,
safe_disconnect)
from spyder.plugins.variableexplorer.widgets.arrayeditor import get_idx_rect
from spyder.plugins.variableexplorer.widgets.basedialog import BaseDialog
from spyder.utils.palette import QStylePalette
Expand Down Expand Up @@ -1753,12 +1753,7 @@ def set_data_and_check(self, data) -> bool:
self.bgcolor.setChecked(self.dataModel.bgcolor_enabled)
self.bgcolor.setEnabled(self.dataModel.bgcolor_enabled)

try:
self.bgcolor_global.stateChanged.disconnect()
except TypeError:
# Raised when no slots are connected to the signal
pass

safe_disconnect(self.bgcolor_global.stateChanged)
self.bgcolor_global.stateChanged.connect(self.dataModel.colum_avg)
self.bgcolor_global.setChecked(self.dataModel.colum_avg_enabled)
self.bgcolor_global.setEnabled(not self.is_series and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
DEFAULT_ATTR_COLS, DEFAULT_ATTR_DETAILS, ToggleColumnTreeView,
TreeItem, TreeModel, TreeProxyModel)
from spyder.utils.icon_manager import ima
from spyder.utils.qthelpers import add_actions, create_toolbutton, qapplication
from spyder.utils.qthelpers import (
add_actions, create_toolbutton, qapplication, safe_disconnect)
from spyder.utils.stylesheet import PANES_TOOLBAR_STYLESHEET
from spyder.widgets.simplecodeeditor import SimpleCodeEditor

Expand All @@ -43,15 +44,6 @@
EDITOR_NAME = 'Object'


def safe_disconnect(signal):
"""Disconnect a QtSignal, ignoring TypeError"""
try:
signal.disconnect()
except TypeError:
# Raised when no slots are connected to the signal
pass


class ObjectExplorer(BaseDialog, SpyderConfigurationAccessor, SpyderFontsMixin):
"""Object explorer main widget window."""
CONF_SECTION = 'variable_explorer'
Expand Down
9 changes: 9 additions & 0 deletions spyder/utils/qthelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,5 +886,14 @@ def handle_applicationStateChanged(state):
app.applicationStateChanged.connect(handle_applicationStateChanged)


def safe_disconnect(signal):
"""Disconnect a QtSignal, ignoring TypeError"""
try:
signal.disconnect()
except TypeError:
# Raised when no slots are connected to the signal
pass


if __name__ == "__main__":
show_std_icons()

0 comments on commit d1c99e6

Please sign in to comment.