-
-
Notifications
You must be signed in to change notification settings - Fork 400
feat: add setting to not display full file path #841
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
Conversation
I apologize for the inconvenience - a large refactor was recently merged (#844) that has moved several files throughout the codebase. This was done in order to correct some deep issues with the project's layout and was performed now as it seemed to be the best opportunity (as of 3/6/25) to disrupt as few open PRs as possible. Unfortunately this PR is one that's been disrupted by this change. A rebase targeting I also noticed that some of the workflows (Ruff, Mypy) were failing before this change. Please let me know if you would like any assistance with this. |
* feat: implement file path option for file attributes --------- Co-authored-by: Zarko Sesto <sesto@kth.se>
Co-authored-by: Zarko Sesto <sesto@kth.se>
Co-authored-by: Zarko Sesto <sesto@kth.se> style: formatted code changes with ruff (#16)
enhancement: formated using RUFF test: addeded test to check title bar update
* refactor: update import paths to reflect recent reformat * format: run ruff format
No worries! The changes have now been rebased onto main + some minor changes to fix some imports to reflect the refactor, and fix ruff/mypy. |
self.filepath_options = ["show full path", "show relative path", "show only file name"] | ||
self.filepath_combobox = QComboBox() | ||
self.filepath_combobox.addItems(self.filepath_options) | ||
show_filepath: str = str( | ||
driver.settings.value( | ||
SettingItems.SHOW_FILEPATH, defaultValue="show full path", type=str | ||
) | ||
) | ||
show_filepath = ( | ||
"show full path" if show_filepath not in self.filepath_options else show_filepath | ||
) | ||
self.filepath_combobox.setCurrentIndex(self.filepath_options.index(show_filepath)) | ||
self.filepath_combobox.currentIndexChanged.connect(lambda: self.apply_filepath_setting()) | ||
self.form_layout.addRow("Show file path", self.filepath_combobox) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(See enums and translation suggestions first) Here's how the combobox could look with the enums mapping to the translation strings via a dict. Here I've mapped each enum int value to a translation string, and then I'm using those int values as the indexes for the combobox. The combobox now can be set and read from completely via these index integers and no longer rely on the string values for determining the indexes to use.
self.filepath_options = ["show full path", "show relative path", "show only file name"] | |
self.filepath_combobox = QComboBox() | |
self.filepath_combobox.addItems(self.filepath_options) | |
show_filepath: str = str( | |
driver.settings.value( | |
SettingItems.SHOW_FILEPATH, defaultValue="show full path", type=str | |
) | |
) | |
show_filepath = ( | |
"show full path" if show_filepath not in self.filepath_options else show_filepath | |
) | |
self.filepath_combobox.setCurrentIndex(self.filepath_options.index(show_filepath)) | |
self.filepath_combobox.currentIndexChanged.connect(lambda: self.apply_filepath_setting()) | |
self.form_layout.addRow("Show file path", self.filepath_combobox) | |
# Show Filepath ======================================================== | |
filepath_option_map: dict[int, str] = { | |
ShowFilepathOption.SHOW_FULL_PATHS: Translations["settings.filepath.option.full"], | |
ShowFilepathOption.SHOW_RELATIVE_PATHS: Translations[ | |
"settings.filepath.option.relative" | |
], | |
ShowFilepathOption.SHOW_FILENAMES_ONLY: Translations["settings.filepath.option.name"], | |
} | |
self.filepath_combobox = QComboBox() | |
self.filepath_combobox.addItems(list(filepath_option_map.values())) | |
filepath_option: int = int( | |
driver.settings.value( | |
SettingItems.SHOW_FILEPATH, defaultValue=ShowFilepathOption.DEFAULT.value, type=int | |
) | |
) | |
filepath_option = 0 if filepath_option not in filepath_option_map else filepath_option | |
self.filepath_combobox.setCurrentIndex(filepath_option) | |
self.filepath_combobox.currentIndexChanged.connect(self.apply_filepath_setting) | |
self.form_layout.addRow(Translations["settings.filepath.label"], self.filepath_combobox) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work on this so far! This is easily one of the cleanest and most professional-looking pull requests I've had the pleasure of reviewing. Even down to the test file (which I also apologize, I understand testing the UI isn't the easiest to do right now)!
All of the logic seems functionally sound and works as intended! The code style also perfectly matches the requirements from the contributing.md as well as the ruff and mypy workflows. I also appreciate you noting that the current settings panel is temporary - it is indeed my intention to improve it at some point in the future, however for now I understand that it's the best place to add a feature such as this 😉
The only real further request I have from this PR is to implement some base translation strings to use for the user interface. These would be added to the en.json
file, which is sorted alphabetically. The new strings would look something like the following:
"settings.filepath.label": "Filepath Visibility",
"settings.filepath.option.full": "Show Full Paths",
"settings.filepath.option.name": "Show Filenames Only",
"settings.filepath.option.relative": "Show Relative Paths",
In fact, I would encourage you to use those exact keys and strings.
As for actually using these inside the program, I believe creating an enum would be the most straightforward way of hooking everything up while ensuring that everything still works outside of the context of the settings screen.
An enum class for the "show_filepath" settings could look like this, and be located underneath the SettingItems class inside src/tagstudio/core/enums.py:
class ShowFilepathOption(int, enum.Enum):
"""Values representing the options for the "show_filenames" setting."""
SHOW_FULL_PATHS = 0
SHOW_RELATIVE_PATHS = 1
SHOW_FILENAMES_ONLY = 2
DEFAULT = SHOW_RELATIVE_PATHS
Here each enum would represent an int value which we can use as the indexes in the combobox. As you can see, I've also gone ahead and added a DEFAULT
value which makes changing this default value much easier instead of updating it everywhere the previous value was used. I've also set the default to the "relative paths" option instead of the previous "full paths" one, since I quite like the way the relative paths look and operate in comparison!
I've provided some more specific implementation examples and pointers throughout the rest of the code review. If you have any questions or concerns, please feel free to @ me anytime! I'll do my best to respond promptly. Thank you so much for your work on this so far, and thank you for bearing with the rebase! 😬 This is genuinely such a great addition to the program and I look forward to seeing it through to the end!
src/tagstudio/qt/ts_qt.py
Outdated
filepath_option: str = str( | ||
self.settings.value(SettingItems.SHOW_FILEPATH, defaultValue="show full path", type=str) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(In the context of enums) Using a default settings value from an enum will also require needing .value
, which isn't readily apparent so I wanted to make sure I mentioned it
filepath_option: str = str( | |
self.settings.value(SettingItems.SHOW_FILEPATH, defaultValue="show full path", type=str) | |
) | |
filepath_option: int = int( | |
self.settings.value( | |
SettingItems.SHOW_FILEPATH, defaultValue=ShowFilepathOption.DEFAULT.value, type=int | |
) |
filepath_option = self.driver.settings.value( | ||
SettingItems.SHOW_FILEPATH, defaultValue="show full path", type=str | ||
) | ||
|
||
self.library_path = self.library.library_dir | ||
display_path = filepath | ||
if filepath_option == "show full path": | ||
display_path = filepath | ||
elif filepath_option == "show relative path": | ||
display_path = Path(filepath).relative_to(self.library_path) | ||
elif filepath_option == "show only file name": | ||
display_path = Path(filepath.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(In the context of enums) This is how the enums would be used in a block of logic such as this:
filepath_option = self.driver.settings.value( | |
SettingItems.SHOW_FILEPATH, defaultValue="show full path", type=str | |
) | |
self.library_path = self.library.library_dir | |
display_path = filepath | |
if filepath_option == "show full path": | |
display_path = filepath | |
elif filepath_option == "show relative path": | |
display_path = Path(filepath).relative_to(self.library_path) | |
elif filepath_option == "show only file name": | |
display_path = Path(filepath.name) | |
filepath_option = self.driver.settings.value( | |
SettingItems.SHOW_FILEPATH, defaultValue=ShowFilepathOption.DEFAULT.value, type=int | |
) | |
self.library_path = self.library.library_dir | |
display_path = filepath | |
if filepath_option == ShowFilepathOption.SHOW_FULL_PATHS: | |
display_path = filepath | |
elif filepath_option == ShowFilepathOption.SHOW_RELATIVE_PATHS: | |
display_path = Path(filepath).relative_to(self.library_path) | |
elif filepath_option == ShowFilepathOption.SHOW_FILENAMES_ONLY: | |
display_path = Path(filepath.name) |
tests/qt/test_file_path_options.py
Outdated
|
||
# Tests to see if the file path setting is applied correctly | ||
@pytest.mark.parametrize( | ||
"filepath_option", ["show full path", "show relative path", "show only file name"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(In the context of enums) This is also how the tests would look when using enums instead of the old strings.
"filepath_option", ["show full path", "show relative path", "show only file name"] | |
"filepath_option", | |
[ | |
ShowFilepathOption.SHOW_FULL_PATHS.value, | |
ShowFilepathOption.SHOW_RELATIVE_PATHS.value, | |
ShowFilepathOption.SHOW_FILENAMES_ONLY.value, | |
], |
tests/qt/test_file_path_options.py
Outdated
# Mock the update_recent_lib_menu method | ||
with patch.object(qt_driver, "update_recent_lib_menu", return_value=None): | ||
# Set the file path option | ||
settings_panel.filepath_combobox.setCurrentText(filepath_option) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(In the context of enums) And just like the combobox in the settings menu we'd be using setting from indexes rather than setting the text directly here now
settings_panel.filepath_combobox.setCurrentText(filepath_option) | |
settings_panel.filepath_combobox.setCurrentIndex(filepath_option) |
"Some examples and pointers" is underselling it a mile and a half, this level of quality feedback is honestly crazy! We've more or less implemented your suggestions directly with some additional fixes to add the enum system. If there is anything else, just let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for implementing the suggestions! I'm glad the feedback was helpful, I can tell how much care and effort went into this so I wanted to make sure I returned the favor! 😁
Everything looks great on the code side now and seems to work just as intended in the program! Thank you again so much for this feature addition, it really brings a nice level of additional polish and customization to the program. This is now ready for me to merge and should be making its way into future builds starting with v9.5.2!
Summary
This PR adds the functionality described in #301, this being an option to not display the full file path but rather the path relative to a library or just the file name.
Displaying only the file name

Displaying the full path

Displaying path relative to the library

Due to the status of #647 seeming to be a bit up in the air, we decided to implement this using the temporary settings menu introduced in #803.
Tasks Completed