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

[FIX] OWFile: Do not load large files automatically #1703

Merged
merged 1 commit into from
Nov 4, 2016
Merged
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
16 changes: 13 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,16 @@ 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)

if self.source == self.LOCAL_FILE and \
os.path.getsize(self.last_path()) > 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 +273,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())