Skip to content

Commit 4a2be0b

Browse files
committed
FEAT: add informative error message when trying to activate a file type we do not support
1 parent 5a1da4e commit 4a2be0b

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

larray_editor/arraywidget.py

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
# worth it for a while.
6060

6161
import math
62+
from pathlib import Path
6263

6364
import numpy as np
6465

@@ -1151,34 +1152,40 @@ def activate_cell(self, index: QModelIndex):
11511152
global_h_pos = model.h_offset + index.column()
11521153
new_data = model.adapter.cell_activated(global_v_pos, global_h_pos)
11531154
if new_data is not None:
1155+
# the adapter wants us to open a sub-element
11541156
editor_widget = self.parent().parent()
11551157
assert isinstance(editor_widget, ArrayEditorWidget)
11561158
adapter_creator = get_adapter_creator(new_data)
1157-
if adapter_creator is not None:
1158-
if adapter_creator is get_path_suffix_adapter:
1159-
adapter = get_path_suffix_adapter(new_data, {})
1160-
if adapter is None:
1161-
logger.info("File type not handled")
1162-
return
1163-
from larray_editor.editor import AbstractEditorWindow, MappingEditorWindow
1164-
widget = self
1165-
while (widget is not None and
1166-
not isinstance(widget, AbstractEditorWindow) and
1167-
callable(widget.parent)):
1168-
widget = widget.parent()
1169-
if isinstance(widget, MappingEditorWindow):
1170-
kernel = widget.kernel
1171-
if kernel is not None:
1172-
# make the current object available in the console
1173-
kernel.shell.push({
1174-
'__current__': new_data
1175-
})
1176-
# TODO: we should add an operand on the future quickbar instead
1177-
editor_widget.back_button_bar.add_back(editor_widget.data,
1178-
editor_widget.data_adapter)
1179-
# TODO: we should open a new window instead (see above)
1180-
editor_widget.set_data(new_data)
1159+
if adapter_creator is None:
1160+
if isinstance(new_data, Path):
1161+
title = "File type not supported"
1162+
msg = f"Cannot display {new_data.suffix} files"
1163+
else:
1164+
obj_type = type(new_data)
1165+
title = "Object type not supported"
1166+
msg = f"Cannot display objects of type {obj_type.__name__}"
1167+
QMessageBox.information(self, title, msg)
11811168
return True
1169+
1170+
from larray_editor.editor import AbstractEditorWindow, MappingEditorWindow
1171+
widget = self
1172+
while (widget is not None and
1173+
not isinstance(widget, AbstractEditorWindow) and
1174+
callable(widget.parent)):
1175+
widget = widget.parent()
1176+
if isinstance(widget, MappingEditorWindow):
1177+
kernel = widget.kernel
1178+
if kernel is not None:
1179+
# make the current object available in the console
1180+
kernel.shell.push({
1181+
'__current__': new_data
1182+
})
1183+
# TODO: we should add an operand on the future quickbar instead
1184+
editor_widget.back_button_bar.add_back(editor_widget.data,
1185+
editor_widget.data_adapter)
1186+
# TODO: we should open a new window instead (see above)
1187+
editor_widget.set_data(new_data)
1188+
return True
11821189
return False
11831190

11841191
class ScrollBar(QScrollBar):

0 commit comments

Comments
 (0)