Skip to content

Commit

Permalink
Merge pull request #12 from Chilipp/master
Browse files Browse the repository at this point in the history
Add DockMixin.position_dock and reset of expanded items
  • Loading branch information
Chilipp committed Apr 14, 2020
2 parents d3aa76b + cb4a37b commit d43f6cc
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 5 deletions.
13 changes: 9 additions & 4 deletions .circleci/config.yml
Expand Up @@ -16,7 +16,12 @@ commands:
conda config --add channels psyplot
conda update -q conda
conda install conda-build anaconda-client conda-verify
if [[ $CIRCLE_TAG == "" ]]; then conda config --add channels psyplot/label/${CIRCLE_BRANCH}; fi
if [[ $CIRCLE_PULL_REQUEST != "" ]]; then
conda config --add channels psyplot/label/master;
elif [[ $CIRCLE_TAG == "" ]]; then
conda config --add channels psyplot/label/master;
conda config --add channels psyplot/label/${CIRCLE_BRANCH};
fi
- run:
name: Environment info
command: |
Expand Down Expand Up @@ -93,6 +98,6 @@ workflows:
- build_linux
- build_linux:
python_version: "3.7"
- build_windows
- build_windows:
python_version: "3.7"
# - build_windows
# - build_windows:
# python_version: "3.7"
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -4,6 +4,9 @@ v1.2.5
see `#10 <https://github.com/psyplot/psyplot-gui/pull/10>`__
- Add option to start the GUI without importing QtWebEngineWidgets
`#11 <https://github.com/psyplot/psyplot-gui/pull/11>`__
- Dockmixins (i.e. plugins) can now reimplement the `position_dock` method that
controls where the dock is exactly placed in the GUI
(see `#12 <https://github.com/psyplot/psyplot-gui/pull/12>`__)

v1.2.4
======
Expand Down
15 changes: 14 additions & 1 deletion psyplot_gui/common.py
Expand Up @@ -95,12 +95,25 @@ def to_dock(self, main, title=None, position=None, docktype='pane', *args,
main.dockwidgets.append(self.dock)
self.create_central_widget_action(main)
self.create_view_action(main, docktype)
main.addDockWidget(position, self.dock, *args, **kwargs)
self.position_dock(main, *args, **kwargs)
config_page = self.config_page
if config_page is not None:
main.config_pages.append(config_page)
return self.dock

def position_dock(self, main, *args, **kwargs):
"""Set the position of the dock widget
This method places the plugin widget at the desired dock position
(by default, indicated with the :attr:`dock_position` attribute)
Parameters
----------
main: psyplot_gui.main.Mainwindow
The main window where the dock is added"""
main.addDockWidget(self.dock_position, self.dock, *args, **kwargs)


def show_plugin(self):
"""Show the plugin widget"""
a = self.dock.toggleViewAction()
Expand Down
39 changes: 39 additions & 0 deletions psyplot_gui/content_widget.py
Expand Up @@ -449,6 +449,22 @@ def set_columns(self, columns=['long_name', 'dims', 'shape']):
self.setHeaderLabels(['Dataset'] + list(columns))
self.attr_columns = columns

def expanded_items(self):
"Create a mapping from dataset numbers to variables that are expanded."
ret = {}
for item in map(self.topLevelItem, range(self.topLevelItemCount())):
if item.isExpanded() and item.ds() is not None:
ds = item.ds()
ret[ds.psy.num] = d = {}
for child in map(item.child, range(item.childCount())):
if child.childCount() and child.isExpanded():
d[child.text(0)] = variables = []
for vchild in map(
child.child, range(child.childCount())):
if vchild.childCount() and vchild.isExpanded():
variables.append(vchild.text(0))
return ret

def add_datasets_from_cp(self, project=None):
"""Clear the tree and add the datasets based upon the given `project`
Expand All @@ -466,6 +482,8 @@ def add_datasets_from_cp(self, project=None):
else:
sp_arrs = project.arrays
project = project.main

expanded_items = self.expanded_items()
# remove items from the tree
self.clear()
for i, ds_desc in six.iteritems(project._get_ds_descriptions(
Expand All @@ -484,6 +502,27 @@ def add_datasets_from_cp(self, project=None):
for arr in ds_desc['arr']:
arr.psy.onbasechange.connect(self.add_datasets_from_cp)
self.addTopLevelItem(top_item)
self.expand_items(expanded_items)

def expand_items(self, expanded_items):
"""Expand tree items
Parameters
----------
expanded_items: dict
A mapping as returned by the :meth:`expanded_items` method"""
for top in map(self.topLevelItem, range(self.topLevelItemCount())):
ds = top.ds()
if ds.psy.num in expanded_items:
self.expandItem(top)
d = expanded_items[ds.psy.num]
for child in map(top.child, range(top.childCount())):
if child.text(0) in d:
self.expandItem(child)
for vchild in map(child.child,
range(child.childCount())):
if vchild.text(0) in d[child.text(0)]:
self.expandItem(vchild)

def open_menu(self, pos):
menu = QMenu()
Expand Down
14 changes: 14 additions & 0 deletions tests/test_project_content.py
Expand Up @@ -249,6 +249,20 @@ def test_refresh_all(self):
self._test_ds_representation(ds)
self._test_ds_representation(ds2)

def test_expansion_reset(self):
"""Test whether the expansion state is recovered"""
fname = self.get_file('test-t2m-u-v.nc')
psy.plot.plot2d(fname, name='t2m')
self.tree.expandItem(self.tree.topLevelItem(0))
self.tree.expandItem(self.tree.topLevelItem(0).child(1))

# trigger an update
psy.plot.plot2d(fname, name='t2m')
self.assertTrue(self.tree.topLevelItem(0).isExpanded())
self.assertFalse(self.tree.topLevelItem(0).child(0).isExpanded())
self.assertTrue(self.tree.topLevelItem(0).child(1).isExpanded())
self.assertFalse(self.tree.topLevelItem(0).child(2).isExpanded())

def test_make_plot(self):
"""Test the making of plots"""
fname = self.get_file('test-t2m-u-v.nc')
Expand Down

0 comments on commit d43f6cc

Please sign in to comment.