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

File: Allow selecting files with arbitrary extensions #6894

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

janezd
Copy link
Contributor

@janezd janezd commented Sep 19, 2024

Issue

Resolves #6792. Requires biolab/orange-widget-base#278 (without, it should work, but without offering the . option).

Description of changes

Following the discussion with @markotoplak, I propose the following.

Readers are determined as follows:

  1. If the file is taken from recent paths, it contains the format setting.
  2. Otherwise, the type is determined by the extension.
  3. If the extension is not known, the type is set in the combo (which the user must set).

Notes:

  • For any loaded file, if the user changes the selection in the combo, this is store in recent paths, so rule 1 applies.
  • For any file that is loaded anew, the first rule no longer applies.
  • For successive files with unknown extensions, the rule 3 applies without resetting the combo.

Usage scenarios

Here are a few interesting sequences and the way they are resolved according to the above rules, which should also serve to write tests if we agree upon this.

In the following "Load" refers to clicking ... and selecting the file in directory, and "Select" refers to selecting the file from the recent file list.

  1. The widget stores reader settings.
  • Select Iris.tab. Combo is auto detect, file is read.
  • Load a-tab-file.xlsx (a tab file, but with wrong extension). Combo is auto detect, a reading error appears.
  • In combo, select Tab. File is read.
  • Select Iris. Combo goes to auto detect.
  • Reselect a-tab-file.xlsx. Combo goes to Tab, file is read.
  • Alt 1:
    • Select Iris. Combo goes to auto detect.
    • Load a-tab-file.xlsx: the file is not taken from recent paths, so combo is auto detect, a reading error appears.
  • Alt 2:
    • Load a-tab-file.xlsx: the file is not taken from recent paths, so combo is auto detect, a reading error appears.
  • Alt 3:
    • Reload. Probably take the format from recent paths.
  1. Reading subsequent files keeps the format.
  • Select Iris.tab. Combo is auto detect, file is read.
  • Load a-tab-file.foo. Combo is auto detect, a reading error appears.
  • Set the correct type in combo: Tab. File is read.
  • Load b-tab-file.foo. Combo remains Tab, file is read.

(... continues in 3)

  1. Known extensions have precedence over the combo (for files that are loaded, not selected from recent paths).

(continued from above)

  • Alt 1: Load b-tab-file.xlsx. Combo is auto detect, an read error appears because the widget attempts to read this as Excel.
  • Alt 2: Load any Excel file. Combo is auto detect, it is read as Excel.
  • Alt 3: Load b-tab-file.xlsx. Combo is auto detect, it is read as Excel.

Notes

  • Apart from add_all="*" and a few different error messages, the most complicate change is in _get_reader. Reviewer should concentrate on this.
  • mark_problematic_reader was needed because the combo state was not changed to the reader from the recent path. This is no longer the case.
  • _initialize_reader_combo could be shorter (block signals, reinitialize, set the current index to previous value), but the current form makes its function more explicit.
Includes
  • Code changes
  • Tests
  • Documentation

@janezd janezd changed the title File: Allow selecting a file with an arbitrary extension File: Allow selecting files with arbitrary extensions Sep 19, 2024
@janezd janezd added the needs discussion Core developers need to discuss the issue label Sep 19, 2024
Copy link

codecov bot commented Sep 23, 2024

Codecov Report

Attention: Patch coverage is 94.11765% with 2 lines in your changes missing coverage. Please review.

Project coverage is 88.18%. Comparing base (1d90230) to head (6cb4225).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6894   +/-   ##
=======================================
  Coverage   88.18%   88.18%           
=======================================
  Files         326      326           
  Lines       71194    71208   +14     
=======================================
+ Hits        62783    62797   +14     
  Misses       8411     8411           

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs discussion Core developers need to discuss the issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File widget : Accept any file
2 participants