Skip to content

Add DockMixin.position_dock and reset of expanded items #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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