diff --git a/Orange/widgets/data/owfile.py b/Orange/widgets/data/owfile.py index fd2ca9e4247..689862c31b2 100644 --- a/Orange/widgets/data/owfile.py +++ b/Orange/widgets/data/owfile.py @@ -91,7 +91,7 @@ class OWFile(widget.OWWidget, RecentPathsWComboMixin): want_main_area = False SEARCH_PATHS = [("sample-datasets", get_sample_datasets_dir())] - + SIZE_LIMIT = 1e7 LOCAL_FILE, URL = range(2) settingsHandler = PerfectDomainContextHandler() @@ -118,6 +118,10 @@ class OWFile(widget.OWWidget, RecentPathsWComboMixin): for f in sorted(set(FileFormat.readers.values()), key=list(FileFormat.readers.values()).index))) + class Warning(widget.OWWidget.Warning): + file_too_big = widget.Msg("The file is too large to load automatically." + " Press Reload to load.") + def __init__(self): super().__init__() RecentPathsWComboMixin.__init__(self) @@ -214,10 +218,17 @@ def __init__(self): self.set_file_list() # Must not call open_file from within __init__. open_file # explicitly re-enters the event loop (by a progress bar) - QTimer.singleShot(0, self.load_data) self.setAcceptDrops(True) + reader = self._get_reader() + if self.source == self.LOCAL_FILE and \ + os.path.getsize(reader.filename) > self.SIZE_LIMIT: + self.Warning.file_too_big() + return + + QTimer.singleShot(0, self.load_data) + def sizeHint(self): return QSize(600, 550) @@ -263,7 +274,7 @@ def load_data(self): # file readers # pylint: disable=broad-except self.editor_model.set_domain(None) - + self.Warning.file_too_big.clear() error = None try: self.reader = self._get_reader() diff --git a/Orange/widgets/data/tests/test_owfile.py b/Orange/widgets/data/tests/test_owfile.py index 8fae90a8318..761ace701eb 100644 --- a/Orange/widgets/data/tests/test_owfile.py +++ b/Orange/widgets/data/tests/test_owfile.py @@ -64,4 +64,8 @@ def _drop_event(self, url): QPoint(0, 0), Qt.MoveAction, data, Qt.NoButton, Qt.NoModifier, QDropEvent.Drop) - + def test_check_file_size(self): + self.assertFalse(self.widget.Warning.file_too_big.is_shown()) + self.widget.SIZE_LIMIT = 4000 + self.widget.__init__() + self.assertTrue(self.widget.Warning.file_too_big.is_shown())