Skip to content

Commit d43f6cc

Browse files
authored
Merge pull request #12 from Chilipp/master
Add DockMixin.position_dock and reset of expanded items
2 parents d3aa76b + cb4a37b commit d43f6cc

File tree

5 files changed

+79
-5
lines changed

5 files changed

+79
-5
lines changed

.circleci/config.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ commands:
1616
conda config --add channels psyplot
1717
conda update -q conda
1818
conda install conda-build anaconda-client conda-verify
19-
if [[ $CIRCLE_TAG == "" ]]; then conda config --add channels psyplot/label/${CIRCLE_BRANCH}; fi
19+
if [[ $CIRCLE_PULL_REQUEST != "" ]]; then
20+
conda config --add channels psyplot/label/master;
21+
elif [[ $CIRCLE_TAG == "" ]]; then
22+
conda config --add channels psyplot/label/master;
23+
conda config --add channels psyplot/label/${CIRCLE_BRANCH};
24+
fi
2025
- run:
2126
name: Environment info
2227
command: |
@@ -93,6 +98,6 @@ workflows:
9398
- build_linux
9499
- build_linux:
95100
python_version: "3.7"
96-
- build_windows
97-
- build_windows:
98-
python_version: "3.7"
101+
# - build_windows
102+
# - build_windows:
103+
# python_version: "3.7"

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ v1.2.5
44
see `#10 <https://github.com/psyplot/psyplot-gui/pull/10>`__
55
- Add option to start the GUI without importing QtWebEngineWidgets
66
`#11 <https://github.com/psyplot/psyplot-gui/pull/11>`__
7+
- Dockmixins (i.e. plugins) can now reimplement the `position_dock` method that
8+
controls where the dock is exactly placed in the GUI
9+
(see `#12 <https://github.com/psyplot/psyplot-gui/pull/12>`__)
710

811
v1.2.4
912
======

psyplot_gui/common.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,25 @@ def to_dock(self, main, title=None, position=None, docktype='pane', *args,
9595
main.dockwidgets.append(self.dock)
9696
self.create_central_widget_action(main)
9797
self.create_view_action(main, docktype)
98-
main.addDockWidget(position, self.dock, *args, **kwargs)
98+
self.position_dock(main, *args, **kwargs)
9999
config_page = self.config_page
100100
if config_page is not None:
101101
main.config_pages.append(config_page)
102102
return self.dock
103103

104+
def position_dock(self, main, *args, **kwargs):
105+
"""Set the position of the dock widget
106+
107+
This method places the plugin widget at the desired dock position
108+
(by default, indicated with the :attr:`dock_position` attribute)
109+
110+
Parameters
111+
----------
112+
main: psyplot_gui.main.Mainwindow
113+
The main window where the dock is added"""
114+
main.addDockWidget(self.dock_position, self.dock, *args, **kwargs)
115+
116+
104117
def show_plugin(self):
105118
"""Show the plugin widget"""
106119
a = self.dock.toggleViewAction()

psyplot_gui/content_widget.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,22 @@ def set_columns(self, columns=['long_name', 'dims', 'shape']):
449449
self.setHeaderLabels(['Dataset'] + list(columns))
450450
self.attr_columns = columns
451451

452+
def expanded_items(self):
453+
"Create a mapping from dataset numbers to variables that are expanded."
454+
ret = {}
455+
for item in map(self.topLevelItem, range(self.topLevelItemCount())):
456+
if item.isExpanded() and item.ds() is not None:
457+
ds = item.ds()
458+
ret[ds.psy.num] = d = {}
459+
for child in map(item.child, range(item.childCount())):
460+
if child.childCount() and child.isExpanded():
461+
d[child.text(0)] = variables = []
462+
for vchild in map(
463+
child.child, range(child.childCount())):
464+
if vchild.childCount() and vchild.isExpanded():
465+
variables.append(vchild.text(0))
466+
return ret
467+
452468
def add_datasets_from_cp(self, project=None):
453469
"""Clear the tree and add the datasets based upon the given `project`
454470
@@ -466,6 +482,8 @@ def add_datasets_from_cp(self, project=None):
466482
else:
467483
sp_arrs = project.arrays
468484
project = project.main
485+
486+
expanded_items = self.expanded_items()
469487
# remove items from the tree
470488
self.clear()
471489
for i, ds_desc in six.iteritems(project._get_ds_descriptions(
@@ -484,6 +502,27 @@ def add_datasets_from_cp(self, project=None):
484502
for arr in ds_desc['arr']:
485503
arr.psy.onbasechange.connect(self.add_datasets_from_cp)
486504
self.addTopLevelItem(top_item)
505+
self.expand_items(expanded_items)
506+
507+
def expand_items(self, expanded_items):
508+
"""Expand tree items
509+
510+
Parameters
511+
----------
512+
expanded_items: dict
513+
A mapping as returned by the :meth:`expanded_items` method"""
514+
for top in map(self.topLevelItem, range(self.topLevelItemCount())):
515+
ds = top.ds()
516+
if ds.psy.num in expanded_items:
517+
self.expandItem(top)
518+
d = expanded_items[ds.psy.num]
519+
for child in map(top.child, range(top.childCount())):
520+
if child.text(0) in d:
521+
self.expandItem(child)
522+
for vchild in map(child.child,
523+
range(child.childCount())):
524+
if vchild.text(0) in d[child.text(0)]:
525+
self.expandItem(vchild)
487526

488527
def open_menu(self, pos):
489528
menu = QMenu()

tests/test_project_content.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,20 @@ def test_refresh_all(self):
249249
self._test_ds_representation(ds)
250250
self._test_ds_representation(ds2)
251251

252+
def test_expansion_reset(self):
253+
"""Test whether the expansion state is recovered"""
254+
fname = self.get_file('test-t2m-u-v.nc')
255+
psy.plot.plot2d(fname, name='t2m')
256+
self.tree.expandItem(self.tree.topLevelItem(0))
257+
self.tree.expandItem(self.tree.topLevelItem(0).child(1))
258+
259+
# trigger an update
260+
psy.plot.plot2d(fname, name='t2m')
261+
self.assertTrue(self.tree.topLevelItem(0).isExpanded())
262+
self.assertFalse(self.tree.topLevelItem(0).child(0).isExpanded())
263+
self.assertTrue(self.tree.topLevelItem(0).child(1).isExpanded())
264+
self.assertFalse(self.tree.topLevelItem(0).child(2).isExpanded())
265+
252266
def test_make_plot(self):
253267
"""Test the making of plots"""
254268
fname = self.get_file('test-t2m-u-v.nc')

0 commit comments

Comments
 (0)