Skip to content

Commit a712b30

Browse files
committed
FEAT: add informative error message when trying to activate a file type we do not support
1 parent f5eb745 commit a712b30

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

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

11851192
class ScrollBar(QScrollBar):

0 commit comments

Comments
 (0)