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

Restore ability to do quick single exports #1173

Closed
Closed
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
27 changes: 23 additions & 4 deletions nion/swift/DocumentController.py
Original file line number Diff line number Diff line change
Expand Up @@ -2639,7 +2639,7 @@ def create_context_menu_for_display(self, display_items: typing.List[DisplayItem
def populate_context_menu(self, menu: UserInterface.Menu, action_context: DocumentController.ActionContext) -> None:
self.add_action_to_menu_if_enabled(menu, "display.reveal", action_context)
self.add_action_to_menu_if_enabled(menu, "file.export", action_context)

self.add_action_to_menu_if_enabled(menu, "file.export_batch", action_context)
data_item = action_context.data_item
if data_item:
source_data_items = self.document_model.get_source_data_items(data_item)
Expand Down Expand Up @@ -3014,7 +3014,7 @@ def get_action_name(self, context: Window.ActionContext) -> str:

class ExportAction(Window.Action):
action_id = "file.export"
action_name = _("Export...")
action_name = _("Single Export...")

def execute(self, context: Window.ActionContext) -> Window.ActionResult:
raise NotImplementedError()
Expand All @@ -3023,6 +3023,25 @@ def invoke(self, context: Window.ActionContext) -> Window.ActionResult:
context = typing.cast(DocumentController.ActionContext, context)
window = typing.cast(DocumentController, context.window)
selected_display_item = context.display_item
if selected_display_item:
window.export_file(selected_display_item)
return Window.ActionResult(Window.ActionStatus.FINISHED)

def is_enabled(self, context: Window.ActionContext) -> bool:
context = typing.cast(DocumentController.ActionContext, context)
return len(context.display_items) == 1 and context.display_item is not None


class ExportBatchAction(Window.Action):
action_id = "file.export_batch"
action_name = _("Batch Export...")

def execute(self, context: Window.ActionContext) -> Window.ActionResult:
raise NotImplementedError()

def invoke(self, context: Window.ActionContext) -> Window.ActionResult:
context = typing.cast(DocumentController.ActionContext, context)
window = typing.cast(DocumentController, context.window)
selected_display_items = context.display_items
if len(selected_display_items) > 0:
window.export_files(selected_display_items)
Expand All @@ -3049,7 +3068,7 @@ def invoke(self, context: Window.ActionContext) -> Window.ActionResult:

def is_enabled(self, context: Window.ActionContext) -> bool:
context = typing.cast(DocumentController.ActionContext, context)
return len(context.display_items) > 0 or context.display_item is not None
return len(context.display_items) == 1 and context.display_item is not None


class ImportDataAction(Window.Action):
Expand Down Expand Up @@ -3081,12 +3100,12 @@ def invoke(self, context: Window.ActionContext) -> Window.ActionResult:
Window.register_action(DeleteItemAction())
Window.register_action(DeleteDataItemAction())
Window.register_action(ExportAction())
Window.register_action(ExportBatchAction())
Window.register_action(ExportSVGAction())
Window.register_action(ImportDataAction())
Window.register_action(ImportFolderAction())



class DataItemRecorderAction(Window.Action):
action_id = "window.data_item_recorder"
action_name = _("Data Item Recorder...")
Expand Down
10 changes: 8 additions & 2 deletions nion/swift/resources/menu_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,20 @@
"type": "item",
"action_id": "file.import_data"
},

{
"type": "item",
"action_id": "file.export"
"action_id":"file.export"
},
{
{
"type": "item",
"action_id":"file.export_batch"
},
{
"type": "item",
"action_id": "file.export_svg"
},

{
"type": "separator"
},
Expand Down
6 changes: 3 additions & 3 deletions nion/swift/test/DisplayPanel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,13 +1365,13 @@ def test_image_display_panel_produces_context_menu_with_correct_item_count(self)
self.assertIsNone(self.document_controller.ui.popup)
self.display_panel.root_container.canvas_widget.on_context_menu_event(500, 500, 500, 500)
# show, sep, delete, sep, split h, split v, sep, none, sep, data, thumbnails, browser, sep
self.assertEqual(20, len(self.document_controller.ui.popup.items))
self.assertEqual(21, len(self.document_controller.ui.popup.items))

def test_image_display_panel_produces_context_menu_with_correct_item_count_outside_image_area(self):
self.assertIsNone(self.document_controller.ui.popup)
self.display_panel.root_container.canvas_widget.on_context_menu_event(10, 32, 10, 32) # header + 10
# show, sep, delete, sep, split h, split v, sep, none, sep, data, thumbnails, browser, sep
self.assertEqual(20, len(self.document_controller.ui.popup.items))
self.assertEqual(21, len(self.document_controller.ui.popup.items))

def test_image_display_panel_with_no_image_produces_context_menu_with_correct_item_count(self):
self.display_panel.set_display_panel_display_item(None)
Expand All @@ -1398,7 +1398,7 @@ def test_browser_display_panel_produces_context_menu_with_correct_item_count_ove
self.display_panel.root_container.refresh_layout_immediate()
self.display_panel.root_container.canvas_widget.on_context_menu_event(40, 40, 40, 40)
# show, sep, delete, sep, split h, split v, sep, none, sep, data, thumbnails, browser, sep
self.assertEqual(20, len(self.document_controller.ui.popup.items))
self.assertEqual(21, len(self.document_controller.ui.popup.items))

def test_browser_display_panel_produces_context_menu_with_correct_item_count_over_area_to_right_of_data_item(self):
d = {"type": "image", "display-panel-type": "browser-display-panel"}
Expand Down