Skip to content

Commit

Permalink
various compatibility fixes for mpl and ipython
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilipp committed Jul 24, 2023
1 parent 22b60e7 commit 0dc9bc1
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 19 deletions.
4 changes: 3 additions & 1 deletion psyplot_gui/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def __init__(self, canvas, num):

self.window.setWindowTitle("Figure %d" % num)

self.toolbar = self._get_toolbar(canvas, parent_widget)
if hasattr(self, "_get_toolbar"):
# legacy solution for matplotlib < 3.6
self.toolbar = self._get_toolbar(canvas, parent_widget)

Check warning on line 111 in psyplot_gui/backend.py

View check run for this annotation

Codecov / codecov/patch

psyplot_gui/backend.py#L111

Added line #L111 was not covered by tests

# add text label to status bar
self.statusbar_label = mainwindow.figures_label
Expand Down
19 changes: 14 additions & 5 deletions psyplot_gui/config/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,30 @@ def _load_plugin_entrypoints(self):
logger = logging.getLogger(__name__)
self._plugins = self._plugins or []
for ep in iter_entry_points('psyplot_gui'):
plugin_name = '%s:%s:%s' % (ep.module_name, ':'.join(ep.attrs),

try:
ep.module
except AttributeError: # python<3.10
try:
ep.module = ep.pattern.match(ep.value).group("module")
except AttributeError: # python<3.8
ep.module = ep.module_name

plugin_name = '%s:%s:%s' % (ep.module, ':'.join(ep.attrs),
ep.name)
# check if the user wants to explicitly this plugin
include_user = None
if inc:
include_user = (
ep.module_name in inc or ep.name in inc or
'%s:%s' % (ep.module_name, ':'.join(ep.attrs)) in inc)
ep.module in inc or ep.name in inc or
'%s:%s' % (ep.module, ':'.join(ep.attrs)) in inc)
if include_user is None and exc == 'all':
include_user = False
elif include_user is None:
# check for exclude
include_user = not (
ep.module_name in exc or ep.name in exc or
'%s:%s' % (ep.module_name, ':'.join(ep.attrs)) in exc)
ep.module in exc or ep.name in exc or
'%s:%s' % (ep.module, ':'.join(ep.attrs)) in exc)
if not include_user:
logger.debug('Skipping plugin %s: Excluded by user',
plugin_name)
Expand Down
2 changes: 1 addition & 1 deletion psyplot_gui/content_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ def add_figures_from_cp(self, project):
child.disconnect_from_array()
for fig, arrays in six.iteritems(project.figs):
item = QTreeWidgetItem(0)
item.setText(0, fig.canvas.get_window_title())
item.setText(0, fig.canvas.manager.get_window_title())
item.addChildren(
[FiguresTreeItem(weakref.ref(arr), 0) for arr in arrays])
self.addTopLevelItem(item)
9 changes: 7 additions & 2 deletions psyplot_gui/fmt_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,13 @@ def run_code(self):
else:
code = "psy.gcp().update(%s={'%s': %s})" % (param, key, text)
if ExecutionInfo is not None:
info = ExecutionInfo(raw_cell=code, store_history=False,
silent=True, shell_futures=False)
info = ExecutionInfo(
raw_cell=code,
store_history=False,
silent=True,
shell_futures=False,
cell_id=None
)
e = ExecutionResult(info)
else:
e = ExecutionResult()
Expand Down
2 changes: 1 addition & 1 deletion psyplot_gui/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ def load_plugin_pages(self):
if rc is None:
rc = RcParams()
w = RcParamsWidget(parent=self)
w.title = 'rcParams of ' + ep.module_name
w.title = 'rcParams of ' + ep.module
w.default_path = PsyRcParamsWidget.default_path
w.initialize(rcParams=rc, validators=validators,
descriptions=descriptions)
Expand Down
12 changes: 6 additions & 6 deletions tests/test_plot_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ def test_add_subplots(self):
nfigs = int(ceil(nvar / 3.))
# create the subplots
axes = self.pc.array_table.axes
self.assertEqual([ax.numCols for ax in axes], [2] * nvar)
self.assertEqual([ax.numRows for ax in axes], [2] * nvar)
self.assertEqual([ax.get_gridspec().ncols for ax in axes], [2] * nvar)
self.assertEqual([ax.get_gridspec().nrows for ax in axes], [2] * nvar)
rows = [0, 0, 1] * nfigs
cols = [0, 1, 0] * nfigs
self.assertEqual([get_row_num(ax) for ax in axes], rows)
Expand All @@ -182,8 +182,8 @@ def test_add_single_subplots(self):
# create the subplots
axes = self.pc.array_table.axes
# test rows, cols and figure numbers
self.assertEqual([ax.numCols for ax in axes], [2] * nvar)
self.assertEqual([ax.numRows for ax in axes], [2] * nvar)
self.assertEqual([ax.get_gridspec().ncols for ax in axes], [2] * nvar)
self.assertEqual([ax.get_gridspec().nrows for ax in axes], [2] * nvar)
self.assertEqual([get_row_num(ax) for ax in axes], [0] * nvar)
self.assertEqual([get_col_num(ax) for ax in axes], [1] * nvar)
self.assertEqual([ax.get_figure().number for ax in axes], list(
Expand Down Expand Up @@ -215,8 +215,8 @@ def test_axescreator_subplots(self):
# create the subplots
axes = self.pc.array_table.axes
# test rows, cols and figure numbers
self.assertEqual([ax.numCols for ax in axes], [2] * nvar)
self.assertEqual([ax.numRows for ax in axes], [2] * nvar)
self.assertEqual([ax.get_gridspec().ncols for ax in axes], [2] * nvar)
self.assertEqual([ax.get_gridspec().nrows for ax in axes], [2] * nvar)
self.assertEqual([get_row_num(ax) for ax in axes], [0] * nvar)
self.assertEqual([get_col_num(ax) for ax in axes], [1] * nvar)
self.assertEqual([ax.get_figure().number for ax in axes], list(
Expand Down
9 changes: 6 additions & 3 deletions tests/test_project_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,11 @@ def check_figs(msg=None):
figs = iter(sp.figs)
for item in map(self.tree.topLevelItem,
range(self.tree.topLevelItemCount())):
self.assertEqual(asstring(item.text(0)),
next(figs).canvas.get_window_title(), msg=msg)
self.assertEqual(
asstring(item.text(0)),
next(figs).canvas.manager.get_window_title(),
msg=msg
)
sp = psy.plot.plot2d(self.get_file('test-t2m-u-v.nc'), name='t2m',
time=[0, 1])
check_figs()
Expand All @@ -145,7 +148,7 @@ def check_figs(msg=None):
for i, (fig, val) in enumerate(sp.figs.items()):
top = self.tree.topLevelItem(i)
self.assertEqual(asstring(top.text(0)),
fig.canvas.get_window_title())
fig.canvas.manager.get_window_title())
for child in map(top.child, range(top.childCount())):
self.assertEqual(asstring(child.text(0)),
next(arrays).psy._short_info(), msg=msg)
Expand Down

0 comments on commit 0dc9bc1

Please sign in to comment.