Skip to content

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

Merged
merged 12 commits into from
Mar 12, 2025

Conversation

HermanKassler
Copy link
Contributor

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
    image

  • Displaying the full path
    image

  • Displaying path relative to the library
    image

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.

image

Tasks Completed

  • Platforms Tested:
    • Windows x86
    • Windows ARM
    • macOS x86
    • macOS ARM
    • Linux x86
    • Linux ARM
  • Tested For:
    • Basic functionality
    • PyInstaller executable

@CyanVoxel CyanVoxel added Type: Enhancement New feature or request Type: UI/UX User interface and/or user experience Priority: Low Doesn't require immediate attention Status: Review Needed A review of this is needed labels Mar 7, 2025
@CyanVoxel CyanVoxel linked an issue Mar 7, 2025 that may be closed by this pull request
3 tasks
@CyanVoxel CyanVoxel moved this to 🚧 In progress in TagStudio Development Mar 7, 2025
@CyanVoxel CyanVoxel added Status: Blocked This issue or pull request is awaiting the outcome of another issue or pull request and removed Status: Blocked This issue or pull request is awaiting the outcome of another issue or pull request labels Mar 7, 2025
@CyanVoxel
Copy link
Member

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 main will be required to resolve the merge conflicts generated here. A merge commit is possible, however I do not recommend it as a rebase will be much smoother and much less work. I apologize again for the disruption.

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.

* refactor: update import paths to reflect recent reformat

* format: run ruff format
@HermanKassler
Copy link
Contributor Author

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.

@CyanVoxel CyanVoxel moved this from 🚧 In progress to 🏓 Ready for Review in TagStudio Development Mar 11, 2025
Comment on lines 66 to 79
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)
Copy link
Member

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.

Suggested change
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)

Copy link
Member

@CyanVoxel CyanVoxel left a 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!

Comment on lines 1752 to 1754
filepath_option: str = str(
self.settings.value(SettingItems.SHOW_FILEPATH, defaultValue="show full path", type=str)
)
Copy link
Member

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

Suggested change
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
)

Comment on lines 147 to 158
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)
Copy link
Member

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:

Suggested change
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 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"]
Copy link
Member

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.

Suggested change
"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,
],

# 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)
Copy link
Member

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

Suggested change
settings_panel.filepath_combobox.setCurrentText(filepath_option)
settings_panel.filepath_combobox.setCurrentIndex(filepath_option)

@CyanVoxel CyanVoxel moved this from 🏓 Ready for Review to 👀 In review in TagStudio Development Mar 12, 2025
@CyanVoxel CyanVoxel removed the Status: Review Needed A review of this is needed label Mar 12, 2025
@CyanVoxel CyanVoxel added this to the Alpha v9.5.2 milestone Mar 12, 2025
@HermanKassler
Copy link
Contributor Author

"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!

@CyanVoxel CyanVoxel moved this from 👀 In review to 🍃 Pending Merge in TagStudio Development Mar 12, 2025
Copy link
Member

@CyanVoxel CyanVoxel left a 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!

@CyanVoxel CyanVoxel merged commit f680ecb into TagStudioDev:main Mar 12, 2025
5 checks passed
@github-project-automation github-project-automation bot moved this from 🍃 Pending Merge to ✅ Done in TagStudio Development Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Low Doesn't require immediate attention Type: Enhancement New feature or request Type: UI/UX User interface and/or user experience
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[Feature Request]: option to not show full file paths
5 participants