rawpython / remi

Python REMote Interface library. Platform independent. In about 100 Kbytes, perfect for your diet.
Apache License 2.0
3.48k stars 401 forks source link

[Question] How can I find all the local partitions when working with gui.FileSelectionDialog widget? #531

Closed plusmid closed 3 months ago

plusmid commented 3 months ago

I found that gui.FileSelectionDialog widget is good implement file/folder selections in the app. But it can only navigate within the app's working partition/directory after several attempts like below.

gui.FileSelectionDialog('File browser', 'CSV is the only acceptable format',False, '/') or gui.FileSelectionDialog('File browser', 'CSV is the only acceptable format',False, '.')

Any thoughts? Thanks in advance!

dddomodossola commented 3 months ago

Hello @plusmid ,

FileSelectionDialog doesn't actually include a way to list all partitions. You can consider to load directories externally by doing:

psutil.disk_partitions(all=True)

and then provide the returned address to the FileSelectionDialog. Kind Regards, Davide

plusmid commented 3 months ago

Thanks for promt comment, @dddomodossola ! When it comes to multiple local parittions, psutil.disk_partitions(all=True) returned a list of these partitions. Is it possbile to put all these partitions in a single selection widget? Like the view below, navigate to c:\ by default and have d:/ e:/ in like a dropdown selection? image

dddomodossola commented 3 months ago

Hello @plusmid ,

You can do it in different ways of course. A possible solution could be the following one:

import remi.gui as gui
from remi import start, App
import psutil

class MyApp(App):
    def main(self):
        # creating a container VBox type, vertical (you can use also HBox or Widget)
        main_container = gui.HBox(style={'margin': '0px auto'})

        #creating devices list
        list_view = gui.ListView( style={'border-right':'1px solid gray'} )
        list_view.onselection.do(lambda emitter, selected_key:folder_navi.chdir(list_view.children[selected_key].get_value()))
        devices = psutil.disk_partitions(all=True)
        for d in devices:
            device_name = d.device
            list_item = gui.ListItem(device_name)
            list_view.append(list_item)

        #instance of the file folder navigator
        folder_navi = gui.FileFolderNavigator(width = '500px', height = '300px')
        #adjusting the grid by adding 'devices_list_view'
        folder_navi.define_grid([('button_back','url_editor','button_go'), ('devices_list_view','items','items')])
        #appending the list to the file folder navigator
        folder_navi.append(list_view, 'devices_list_view')

        main_container.append(folder_navi)

        # returning the root widget
        return main_container

if __name__ == "__main__":
    # starts the webserver
    start(MyApp, address='0.0.0.0', port=0, start_browser=True)

Kind Regards