跳转至

pyguiadapter.widgets.fileselect

控件配置类

FileSelectConfig dataclass

Bases: CommonParameterWidgetConfig

FileSelect的配置类。

Source code in pyguiadapter\widgets\extend\fileselect.py
@dataclasses.dataclass(frozen=True)
class FileSelectConfig(CommonParameterWidgetConfig):
    """FileSelect的配置类。"""

    default_value: Optional[str] = ""
    """默认值"""

    placeholder: str = ""
    """占位符文字"""

    dialog_title: str = ""
    """文件对话框标题"""

    start_dir: str = ""
    """文件对话框起始路径"""

    filters: str = ""
    """文件对话框的文件过滤器"""

    save_file: bool = False
    """是否为保存文件对话框"""

    select_button_text: str = "..."
    """选择按钮文字"""

    clear_button: bool = False
    """是否显示清除按钮"""

    drag_n_drop: bool = True
    """是否启用文件拖放功能"""

    drag_n_drop_filter: Optional[Callable[[str, str], bool]] = default_dnd_filter
    """文件拖放功能的过滤函数。该函数应接收两个参数:文件过滤器(即本类的`filters`属性)和拖放的文件路径。
    若返回True,则表示该文件可以被拖放;否则,则表示该文件不能被拖放。该属性也可以设置为None,表示不对拖放文件进行过滤。
    默认情况下,使用`default_dnd_filter`函数作为过滤函数,该函数会将待拖放的文件的文件名与文件过滤器进行匹配,若命中任意文件过滤器,则返回True,
    否则返回False。比如,若文件过滤器为'Text files (*.txt);;Python files (*.py)', 则文件'hello.txt'可以被拖放,因为其命中了'Text files (*.txt)';
    文件'hello.py'也可以被拖放,因为其命中了'Python files (*.py)';文件'hello.png'则不能被拖放,因为其没有命中任何文件过滤器。"""

    normalize_path: bool = False
    """是否将路径标准化。若设置为True,则在获取路径时,将使用os.path.normpath()函数进行标准化"""

    absolutize_path: bool = False
    """是否将路径绝对化。若设置为True,则在获取路径时,将使用os.path.abspath()函数进行绝对化"""

    @classmethod
    def target_widget_class(cls) -> Type["FileSelect"]:
        return FileSelect

absolutize_path: bool = False class-attribute instance-attribute

是否将路径绝对化。若设置为True,则在获取路径时,将使用os.path.abspath()函数进行绝对化

clear_button: bool = False class-attribute instance-attribute

是否显示清除按钮

default_value: Optional[str] = '' class-attribute instance-attribute

默认值

dialog_title: str = '' class-attribute instance-attribute

文件对话框标题

drag_n_drop: bool = True class-attribute instance-attribute

是否启用文件拖放功能

drag_n_drop_filter: Optional[Callable[[str, str], bool]] = default_dnd_filter class-attribute instance-attribute

文件拖放功能的过滤函数。该函数应接收两个参数:文件过滤器(即本类的filters属性)和拖放的文件路径。 若返回True,则表示该文件可以被拖放;否则,则表示该文件不能被拖放。该属性也可以设置为None,表示不对拖放文件进行过滤。 默认情况下,使用default_dnd_filter函数作为过滤函数,该函数会将待拖放的文件的文件名与文件过滤器进行匹配,若命中任意文件过滤器,则返回True, 否则返回False。比如,若文件过滤器为'Text files (.txt);;Python files (.py)', 则文件'hello.txt'可以被拖放,因为其命中了'Text files (.txt)'; 文件'hello.py'也可以被拖放,因为其命中了'Python files (.py)';文件'hello.png'则不能被拖放,因为其没有命中任何文件过滤器。

filters: str = '' class-attribute instance-attribute

文件对话框的文件过滤器

normalize_path: bool = False class-attribute instance-attribute

是否将路径标准化。若设置为True,则在获取路径时,将使用os.path.normpath()函数进行标准化

placeholder: str = '' class-attribute instance-attribute

占位符文字

save_file: bool = False class-attribute instance-attribute

是否为保存文件对话框

select_button_text: str = '...' class-attribute instance-attribute

选择按钮文字

start_dir: str = '' class-attribute instance-attribute

文件对话框起始路径

MultiFileSelectConfig dataclass

Bases: CommonParameterWidgetConfig

MultiFileSelect的配置类。

absolutize_path: bool = False class-attribute instance-attribute

是否将路径绝对化。若设置为True,则在设置控件值或者从控件获取值时,将使用os.path.abspath()函数进行绝对化

clear_button: bool = True class-attribute instance-attribute

是否显示清除按钮

default_value: Union[Sequence[str], str, type(None)] = () class-attribute instance-attribute

默认值

dialog_title: str = '' class-attribute instance-attribute

文件对话框标题

drag_n_drop: bool = True class-attribute instance-attribute

是否启用文件拖放功能

drag_n_drop_filter: Optional[Callable[[str, str], bool]] = default_dnd_filter class-attribute instance-attribute

文件拖放功能的过滤函数。该函数应接收两个参数:文件过滤器(即本类的filters属性)和拖放的文件路径。 若返回True,则表示该文件可以被拖放;否则,则表示该文件不能被拖放。该属性也可以设置为None,表示不对拖放文件进行过滤。 默认情况下,使用default_dnd_filter函数作为过滤函数,该函数会将待拖放的文件的文件名与文件过滤器进行匹配,若命中任意文件过滤器,则返回True, 否则返回False。比如,若文件过滤器为'Text files (.txt);;Python files (.py)', 则文件'hello.txt'可以被拖放,因为其命中了'Text files (.txt)'; 文件'hello.py'也可以被拖放,因为其命中了'Python files (.py)';文件'hello.png'则不能被拖放,因为其没有命中任何文件过滤器。

file_separator: str = ';;' class-attribute instance-attribute

文件分隔符

filters: str = '' class-attribute instance-attribute

文件对话框的文件过滤器

normalize_path: bool = False class-attribute instance-attribute

是否将路径标准化。若设置为True,则在设置控件值或者从控件获取值时,使用os.path.normpath()函数进行标准化

placeholder: str = '' class-attribute instance-attribute

占位符文字

select_button_text: str = '...' class-attribute instance-attribute

选择按钮文字

start_dir: str = '' class-attribute instance-attribute

文件对话框起始路径

控件类

FileSelect

MultiFileSelect

对应参数数据类型

  • file_t
  • files_t