Skip to content

feat(PreviewPanel): Truncate Path to a single line #429

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

Closed
wants to merge 11 commits into from

Conversation

seakrueger
Copy link
Collaborator

Truncates the path to a single line by removing parent dirs. The line width is calculated based on font size, and since its not a mono-spaced font the calculation under reports a little, so it might be a little over zealous in truncation

@seakrueger seakrueger changed the base branch from main to Alpha-v9.4 September 2, 2024 02:30
@CyanVoxel CyanVoxel added Type: QoL A quality of life (QoL) enhancement or suggestion Type: UI/UX User interface and/or user experience labels Sep 2, 2024
@@ -134,6 +139,64 @@ def setFilePath(self, filepath):
"""
self.filepath = filepath

def truncate_single_filepath(self, filepath):
Copy link
Contributor

@yedpodtrzitko yedpodtrzitko Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add type annotation here, and some tests for this method, thanks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There currently doesn't seem to be tests for the front end, at least until 332 is merged

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function can be tested even without QT, no? Path goes inside -> string goes outside, so no frontend is needed here.

Comment on lines 183 to 218
def enterEvent(self, event: QEnterEvent) -> None:
if self.filepath:
# Delay 250ms before revealing full path
self.timer.start(250)
return super().enterEvent(event)

def leaveEvent(self, event: QEvent) -> None:
if self.filepath:
# Cancel full path showing if mouse leaves before timer is up
self.timer.stop()
self.setText(self.truncate_single_filepath(self.filepath))
return super().leaveEvent(event)

def _show_full_path_callback(self):
"""Shows the full filepath instead of truncated version"""
self.setText(str(self.filepath))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a cleaner solution would be to use QToolTip to show the full path instead of doing this, what do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found QToolTip to be inconsistent in how long it took to appear and (in-general) the delay longer than desired. I'd be willing to go that route if you would prefer though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just by comparing the amount of code needed to achieve what can be done by calling .setToolTip(). If the arguments are "inconsistent delay" (cant reproduce), "and delay longer than desired" (subjective), then in my eyes the QTooltip is winner.

also I was suspicious that a UI toolkit wouldnt have something to trim a text in element, so I checked their docs, and there is elidedText which should do the same thing you're doing via truncate_single_filepath

Copy link
Collaborator Author

@seakrueger seakrueger Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elidedText does not truncate with knowledge of paths. It simply removes characters in the center, destroying the path names. It also just doesn't work properly sometimes, it does not crop to the correct width and falls to the new line

truncate_filepath:
image
elidedPath:
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense. but the test would be still useful to have.

@seakrueger
Copy link
Collaborator Author

This is now based on #430 for now

@CyanVoxel
Copy link
Member

This is now based on #430 for now

I've just made some changes to #430 based on yed's feedback and merged it into the 9.4 branch - I won't touch it from there, and you're free to continue this without any further interruption from me 😅

@seakrueger
Copy link
Collaborator Author

Decided this is not the right direction.

@seakrueger seakrueger closed this Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: QoL A quality of life (QoL) enhancement or suggestion Type: UI/UX User interface and/or user experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants