-
-
Notifications
You must be signed in to change notification settings - Fork 394
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
Conversation
@@ -134,6 +139,64 @@ def setFilePath(self, filepath): | |||
""" | |||
self.filepath = filepath | |||
|
|||
def truncate_single_filepath(self, filepath): |
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.
please add type annotation here, and some tests for this method, thanks.
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.
There currently doesn't seem to be tests for the front end, at least until 332 is merged
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.
this function can be tested even without QT, no? Path
goes inside -> string goes outside, so no frontend is needed here.
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)) |
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.
a cleaner solution would be to use QToolTip
to show the full path instead of doing this, what do you think?
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.
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
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.
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
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.
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.
makes sense. but the test would be still useful to have.
Moves path decorators to an overriden setText
d180cb7
to
0ee9bbd
Compare
This is now based on #430 for now |
Decided this is not the right direction. |
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