zauberzeug / nicegui

Create web-based user interfaces with Python. The nice way.
https://nicegui.io
MIT License
9.8k stars 581 forks source link

The local_file_picker module cannot open the path selection box sometimes. #3181

Closed Jabbahao closed 4 months ago

Jabbahao commented 4 months ago

Description

When I add a label element and bind the attribute to the path attribute, the dialog box may not display the complete file selection box. Only the label attribute is displayed.

class local_file_picker(ui.dialog):

    def __init__(self, directory: str, *,
                 upper_limit: Optional[str] = ...,
                 multiple: bool = False,
                 show_hidden_files: bool = False,
                 show_file: bool = True) -> None:
        """Local File Picker

        This is a simple file picker that allows you to select a file from the local filesystem where NiceGUI is running.

        :param directory: The directory to start in.
        :param upper_limit: The directory to stop at (None: no limit, default: same as the starting directory).
        :param multiple: Whether to allow multiple files to be selected.
        :param show_hidden_files: Whether to show hidden files.
        """
        super().__init__()

        self.path = Path(directory).expanduser()
        if upper_limit is None:
            self.upper_limit = None
        else:
            self.upper_limit = Path(directory if upper_limit == ... else upper_limit).expanduser()
        self.show_hidden_files = show_hidden_files
        self.show_file = show_file

        with self, ui.card():
            select_path = ui.label()
            select_path.set_visibility(False)
            self.add_drives_toggle()
            self.grid = ui.aggrid({
                'columnDefs': [{'field': 'name', 'headerName': '文件'}],
                'rowSelection': 'multiple' if multiple else 'single',
            }, html_columns=[0]).classes('w-96').on('cellDoubleClicked', self.handle_double_click)
            with ui.row().classes('w-full justify-end'):
                ui.button('取消', on_click=self.close).props('outline')
                ui.button('确认', on_click=self._handle_ok)
        select_path.bind_text_from(self, 'path', lambda x: f"路径: {x}")
        self.update_grid()
        select_path.set_visibility(True)
falkoschindler commented 4 months ago

Hi @Jabbahao,

Can you, please, try to provide a minimum reproducible example? Thanks! Why is it important to provide a minimal reproducible example?

python-and-fiction commented 4 months ago

i copy your code into https://github.com/zauberzeug/nicegui/tree/main/examples/local_file_picker/ whose init function and do it in single py file, it runs as expected ,there is no error you said. May you record it in gif ? or provide a minimum reproducible example which shows your question?

falkoschindler commented 4 months ago

I'll close this issue as stale. Feel free to re-open it once you've got new information for us. Thanks!