-
Notifications
You must be signed in to change notification settings - Fork 22
[ENH] Added dropdown to select drives and to select files from the tree view while selecting location of new project #475
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
[ENH] Added dropdown to select drives and to select files from the tree view while selecting location of new project #475
Conversation
Signed-off-by: sumana sree <[email protected]>
Hello @JoeZiminski @adamltyson I have tried to solve the issue #448 but got stuck in the process. As shown in the video, I have added a dropdown to select drives, the dropdown is successfully showing the available files. But the tree view is not updating the files according to the drive selected. Can you please help me how to refine the code to correctly add this feature. Thank you!!! |
@sumana-2705 thanks for this! This is a really nice addition and will be very useful for users, please see comments above. I can take a look at the linux / macOS situation next week and will let you know about that ASAP (feel free to look into this also if you have access to these systems). It is possible to mount external drives on macOS / linux and so it will be nice to support these also if possible. We will also need to add a test for this, unfortunately it is not a simple thing to test. I think it will be impossible to actually test the behaviour on real drives (we at the NIU might have to add this to our internal tests). However, we can at least test the interface. I think the approach will be:
You can take a look at this function on the test suite for inspiration. However this is quite advanced so happy to give more detail and an example once this round of comments have been responded too. Thanks again! |
Thank you for providing the reference and background, @JoeZiminski. Unfortunately, most of my peers at university use Windows, so I currently don’t have access to Mac or Linux systems. For now, I will focus on understanding and implementing monkeypatch. I will provide an update as soon as possible. Once it is working properly, we can test it on different systems and refine the tests accordingly. |
Sounds good! Thanks @sumana-2705 I'll get back to you ASAP, let me know if you have any questions about the monkeypatching. |
Hello @JoeZiminski @adamltyson Before adding tests using |
HI @sumana-2705, I'm very sorry when I last reviewed your PR I did not click the submit button, I thought I had in the process of posting the summary. Please see some suggested changes, apologies for this oversight. That's a good question, I think textual has a |
Thank you for the suggestions @JoeZiminski I will go through them clearly and work on them |
Thank you @JoeZiminski all the suggestions worked like a magic. Now everything is perfect, I tried so hard to correct this issue but it was not updating properly even after so many attempts. You helped me a lot by suggesting changes. Thank you once again. Also I wanted to conform that whether Untitled.video.-.Made.with.Clipchamp.mp4 |
Hi @sumana-2705 great glad it helped! Yes textual can be hard to work with at first because it is a huge package and there are a lot of different ways to do similar things. Yes |
BTW I did not have time in the end this week to test on the macOS in the office, but I will do next week. In terms of working on this PR don't worry much about it, it should just be a quick check to find what the mount paths are and setting appropriately. |
Got it! It took me some time since I'm new to TUI development, but I'm gaining valuable experience while working on these issues. I'll also try to check this on a Mac in the meantime. Thanks for your support! |
Hello @JoeZiminski I have checked the behavior of the directory tree on Mac and modified the code to ensure the functionalities work correctly on both Windows and Mac. Here is a picture of the directory tree on Mac for reference. |
HI @sumana-2705 thanks again for this PR, I tested on linux and it works perfectly! Did you have a chance to play around with the tests? I'm happy to finish this off and add a few before merging if things are busy at the moment. |
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.
Hey @sumana-2705 I just had a very small suggestions
Thanks for your review @JoeZiminski Sure I'll make changes as early as possible. I was inactive for a few days due to my thesis work and end semester exams. Thanks again for the suggestions 😊 |
Hey @sumana-2705 thanks, it seems that first issue is because:
since Yes |
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.
Hey @sumana-2705 this is coming along nicely, the test is structured well and attacks the problem nicely. I've suggested some changes please let me know what you think. BTW just for your interest in case it is useful to see, the steps I took to solve the bug with the textual.widgets._select.InvalidSelectValueError: Illegal select value 'C:\\'
was:
-
The stack trace from textual is quite cryptic, but sort-of indicated it was a problem with the set up of the select in the compose function
-
went to the definition of the select widget in the compose function and added a breakpoint. These are useful for stopping execution of the program so you can see the state of the variables:
breakpoint()
yield Container(
Static(label_message, id="select_directory_tree_screen_label"),
Select( # Dropdown for drives
[(drive, drive) for drive in self.get_drives()],
value=self.selected_drive,
allow_blank=False,
id="select_directory_tree_drive_select",
),
Then I played around with the inputs to the Select until it was clear that the value
was the problem.
""" | ||
|
||
# Set up fake and real drives | ||
actual_drive = ( |
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.
On further reflection, I think we can just have two separate names, Drive 1
, Drive 2
(as we are artificially setting the drive, it doesn't matter if they are real or not, as long as they are different
"#select_directory_tree_drive_select" | ||
) | ||
|
||
while not select.options: |
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 was getting an error select.options
was not found, I found removing this line worked
Hi @JoeZiminski, Thank you so much for helping me out and taking the time to explain everything so clearly. It really made things much easier to understand. Just wanted to let you know that the test is now passing successfully. Thanks again!! |
Great! Thanks @sumana-2705. A couple of fixes are now on the main branch, if you git rebase your branch onto the most recent main, I think the tests should pass on the CI. Then I believe this is good to go! Let me know if you have any questions about rebasing it can be a bit mysterious the first few times you do it. |
Signed-off-by: sumana sree <[email protected]>
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Hello @JoeZiminski. I've rebased the |
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.
Hey @sumana-2705 I added psutils
to the pyproject.toml
and everything seems to be working well! Just one minor change suggested and this is good to merge!
value=( | ||
self.selected_drive | ||
if self.selected_drive in drives | ||
else drives[0] |
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.
Hey @sumana-2705 a very small thing, here this makes sense to handle the test case. But as a general rule it is good to try and avoid test cases being handled explicitly in the code (as it might be confusing how such a case could occur in general use).
In this case, I think it makes sense to factor out
def get_selected_drive(self):
if platform.system() == "Windows":
selected_drive = self.path_.drive + "\\"
else:
selected_drive = "/"
return selected drive
and do self.selected_drive = self.get_selected_drive()
and then monkeypatch this function in the test. It still unfortunately does change the main code for the tests, but it is a more general refactoring than explicit handling of a test case which (should hopefully) never occur in the real world. I hope that makes sense let me know if not!
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.
Hello @JoeZiminski I have made changes as suggested by you. Please review it
…5/datashuttle into mount_external_drives
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.
Hey @sumana-2705 this is good to go! I merged in main and fixed the tests, and just made a few very minor edits:
- set
all=True
for thepsutil
call as it will also show mounted drives which can be useful - call the functions directly to set the
Select
rather than use intermediate attributes on the class - on macos / linux, for the default drive use the current first-folder rather than
/
Thanks again for this great contribution!
Description
What is this PR
Why is this PR needed?
Currently,
SelectDirectoryTreeScreen
starts atPath.home()
by default, which is not ideal for selecting external drives. Windows and some Linux systems do not have a master root where all drives are listed, making drive selection difficult. This PR introduces a dropdown to allow users to choose the drive they want to navigate.What does this PR do?
References
fixes #448
How has this PR been tested?
I have tested it my windows laptop, the dropdown successfully worked. But the directory tree is not getting refreshed, I need your help to fix this. I am attaching the current state of the window:
datashuttle.mp4
Is this a breaking change?
No, this PR does not break existing functionality. It only enhances the directory selection process by allowing users to switch between drives.
Does this PR require an update to the documentation?
Yes, documentation should be updated to mention the new drive selection feature in
SelectDirectoryTreeScreen
.Checklist: