Skip to content

Commit

Permalink
OWFile: Do not load large files automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
VesnaT committed Nov 2, 2016
1 parent 2fb5812 commit 3439664
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
17 changes: 14 additions & 3 deletions Orange/widgets/data/owfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion Orange/widgets/data/tests/test_owfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

0 comments on commit 3439664

Please sign in to comment.