Skip to content

Commit

Permalink
Fix #214. Ensure capture button produces a unique title.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmeyer committed Dec 31, 2024
1 parent cbe7933 commit 996fd84
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions nion/instrumentation/test/CameraControl_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ def test_capturing_during_view_captures_new_data_items(self):
hardware_source.stop_playing(sync_timeout=TIMEOUT)
document_controller.periodic()
self.assertEqual(len(document_model.data_items), 2)
self.assertTrue(document_model.data_items[1].title.endswith(" Capture 1"))

def test_capturing_during_view_captures_eels_2d(self):
with self._test_context(is_eels=True) as test_context:
Expand Down
5 changes: 5 additions & 0 deletions nion/instrumentation/test/ScanControl_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,11 @@ def display_new_data_item(data_item):
scan_hardware_source.get_next_xdatas_to_finish()
document_controller.periodic()
self.assertEqual(len(document_model.data_items), 4)
# check that the new data item titles are different
self.assertNotEqual(document_model.data_items[2], document_model.data_items[3])
# check that the new data item titles both have the same index
self.assertTrue(document_model.data_items[2].title.endswith(" Capture 1"))
self.assertTrue(document_model.data_items[3].title.endswith(" Capture 1"))

def test_capturing_during_view_captures_session(self):
with self._test_context() as test_context:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

# local libraries
from nion.data import DataAndMetadata
from nion.instrumentation import Acquisition
from nion.instrumentation import camera_base
from nion.instrumentation import HardwareSource
from nion.swift import DataItemThumbnailWidget
Expand Down Expand Up @@ -305,6 +306,7 @@ def capture_xdatas(data_promises: typing.Sequence[HardwareSource.DataAndMetadata
if self.__captured_xdatas_available_event:
self.__captured_xdatas_available_event.close()
self.__captured_xdatas_available_event = None
Acquisition.session_manager.begin_acquisition(self.__document_model) # bump the index
for index, data_promise in enumerate(data_promises):
def add_data_item(data_item: DataItem.DataItem) -> None:
self.__document_model.append_data_item(data_item)
Expand All @@ -317,7 +319,11 @@ def add_data_item(data_item: DataItem.DataItem) -> None:
data_item = DataItem.new_data_item(xdata)
display_name = xdata.metadata.get("hardware_source", dict()).get("hardware_source_name")
display_name = display_name if display_name else _("Capture")
data_item.title = display_name
acquisition_number = Acquisition.session_manager.get_project_acquisition_index(self.__document_model)
data_item_title = display_name
if acquisition_number:
data_item_title += f" Capture {acquisition_number}"
data_item.title = data_item_title
data_item.session_metadata = ApplicationData.get_session_metadata_dict()
self.queue_task(functools.partial(add_data_item, data_item))
self.queue_task(self.__update_buttons)
Expand Down
10 changes: 9 additions & 1 deletion nionswift_plugin/nion_instrumentation_ui/ScanControlPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

# local libraries
from nion.data import DataAndMetadata
from nion.instrumentation import Acquisition
from nion.instrumentation import HardwareSource
from nion.instrumentation import scan_base
from nion.instrumentation import stem_controller
Expand Down Expand Up @@ -589,6 +590,7 @@ def receive_new_xdatas(data_promises: typing.Sequence[HardwareSource.DataAndMeta
if self.__captured_xdatas_available_listener:
self.__captured_xdatas_available_listener.close()
self.__captured_xdatas_available_listener = None
Acquisition.session_manager.begin_acquisition(self.__document_model) # bump the index
for data_promise in data_promises:
def add_data_item(data_item: DataItem.DataItem) -> None:
if self.on_display_new_data_item:
Expand All @@ -599,7 +601,13 @@ def add_data_item(data_item: DataItem.DataItem) -> None:
display_name = xdata.metadata.get("hardware_source", dict()).get("hardware_source_name")
display_name = display_name if display_name else _("Capture")
channel_name = xdata.metadata.get("hardware_source", dict()).get("channel_name")
data_item.title = "%s (%s)" % (display_name, channel_name) if channel_name else display_name
acquisition_number = Acquisition.session_manager.get_project_acquisition_index(self.__document_model)
data_item_title = display_name
if channel_name:
data_item_title += f" ({channel_name})"
if acquisition_number:
data_item_title += f" Capture {acquisition_number}"
data_item.title = data_item_title
data_item.session_metadata = ApplicationData.get_session_metadata_dict()
self.queue_task(functools.partial(add_data_item, data_item))
self.queue_task(self.__update_buttons)
Expand Down

0 comments on commit 996fd84

Please sign in to comment.