Skip to content
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

Small improvements to ComponentIDComboHelper #1060

Merged
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
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ v0.9.0 (unreleased)
preference pane for Plotly export has now been removed in favor of this new
way to set the options. [#1057]

* Renamed the ``ComponentIDComboHelper`` and ``ManualDataComboHelper``
``append`` methods to ``append_data`` and the ``remove`` methods to
``remove_data``, and added a new ``ComponentIDComboHelper.set_multiple_data``
method. [#1060]

v0.8.3 (unreleased)
-------------------

Expand Down
38 changes: 27 additions & 11 deletions glue/core/qt/data_combo_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def categorical(self, value):
self._categorical = value
self.refresh()

def append(self, data):
def append_data(self, data):

if self.hub is None:
if data.hub is None:
Expand All @@ -99,10 +99,26 @@ def append(self, data):

self.refresh()

def remove(self, data):
def remove_data(self, data):
self._data.remove(data)
self.refresh()

def set_multiple_data(self, datasets):
"""
Add multiple datasets to the combo in one go (and clear any previous datasets).

Parameters
----------
datasets : list
The list of :class:`~glue.core.data.Data` objects to add
"""
try:
self._data.clear()
except AttributeError: # PY2
self._data[:] = []
self._data.extend(datasets)
self.refresh()

@property
def hub(self):
return self._hub
Expand Down Expand Up @@ -162,7 +178,7 @@ def register_to_hub(self, hub):
handler=nonpartial(self.refresh),
filter=lambda msg: msg.data in self._data)
hub.subscribe(self, DataCollectionDeleteMessage,
handler=lambda msg: self.remove(msg.data),
handler=lambda msg: self.remove_data(msg.data),
filter=lambda msg: msg.sender is self._data_collection)

def unregister(self, hub):
Expand Down Expand Up @@ -197,14 +213,14 @@ def refresh_component_ids(self):
for helper in self._component_id_helpers:
helper.clear()
if self._data is not None:
helper.append(self._data)
helper.append_data(self._data)
helper.refresh()

def add_component_id_combo(self, combo):
helper = ComponentIDComboHelper(combo)
self._component_id_helpers.append(helper)
self._component_id_helpers.append_data(helper)
if self._data is not None:
helper.append(self._data)
helper.append_data(self._data)

@property
def hub(self):
Expand All @@ -226,8 +242,8 @@ class ManualDataComboHelper(BaseDataComboHelper):
that is manually curated.

Datasets are added and removed using the
:meth:`~ManualDataComboHelper.append` and
:meth:`~ManualDataComboHelper.remove` methods.
:meth:`~ManualDataComboHelper.append_data` and
:meth:`~ManualDataComboHelper.remove_data` methods.

Parameters
----------
Expand All @@ -249,11 +265,11 @@ def __init__(self, data_combo, data_collection):
self._datasets = []
self.hub = data_collection.hub

def append(self, data):
def append_data(self, data):
self._datasets.append(data)
self.refresh()

def remove(self, data):
def remove_data(self, data):
self._datasets.remove(data)
self.refresh()

Expand All @@ -265,7 +281,7 @@ def register_to_hub(self, hub):
handler=nonpartial(self.refresh),
filter=lambda msg: msg.sender in self._datasets)
hub.subscribe(self, DataCollectionDeleteMessage,
handler=lambda msg: self.remove(msg.data),
handler=lambda msg: self.remove_data(msg.data),
filter=lambda msg: msg.sender is self._data_collection)


Expand Down
16 changes: 8 additions & 8 deletions glue/core/qt/tests/test_data_combo_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ def test_component_id_combo_helper():
data1 = Data(x=[1,2,3], y=[2,3,4], label='data1')

dc.append(data1)
helper.append(data1)
helper.append_data(data1)

assert _items_as_string(combo) == "x:y"

data2 = Data(a=[1,2,3], b=['a','b','c'], label='data2')

dc.append(data2)
helper.append(data2)
helper.append_data(data2)

assert _items_as_string(combo) == "data1:x:y:data2:a:b"

Expand All @@ -59,7 +59,7 @@ def test_component_id_combo_helper():
# data1.id['x'].label = 'z'
# assert _items_as_string(combo) == "z:y"

helper.remove(data1)
helper.remove_data(data1)

assert _items_as_string(combo) == ""

Expand All @@ -76,19 +76,19 @@ def test_component_id_combo_helper_init():
dc.append(data)

helper = ComponentIDComboHelper(combo, dc)
helper.append(data)
helper.append_data(data)
assert _items_as_string(combo) == "a:b"

helper = ComponentIDComboHelper(combo, dc, numeric=False)
helper.append(data)
helper.append_data(data)
assert _items_as_string(combo) == "b"

helper = ComponentIDComboHelper(combo, dc, categorical=False)
helper.append(data)
helper.append_data(data)
assert _items_as_string(combo) == "a"

helper = ComponentIDComboHelper(combo, dc, numeric=False, categorical=False)
helper.append(data)
helper.append_data(data)
assert _items_as_string(combo) == ""


Expand All @@ -106,7 +106,7 @@ def test_manual_data_combo_helper():

assert _items_as_string(combo) == ""

helper.append(data1)
helper.append_data(data1)

assert _items_as_string(combo) == "data1"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def setup_method(self, method):

self.component_helper = ComponentIDComboHelper(self.attribute_combo, self.data_collection)

self.component_helper.append(self.data)
self.component_helper.append_data(self.data)

self.x_id = self.data.visible_components[0]
self.y_id = self.data.visible_components[1]
Expand Down