Skip to main content

无主见、极简主义、可重用、可稍微配置的通用文件对话框。

项目描述

通用文件对话框

安装和开始:

pip install Ufd --upgrade

或者

git clone https://github.com/emboiko/Ufd.git

或者

在此处下载 .zip

进口:

from Ufd.Ufd import Ufd

构造:

dialog = Ufd(**Kwargs)
result = dialog()

或指定一堆选项

dialog = Ufd(
    title="My Dialog",
    icon="path/to/some_icon.ico",
    show_hidden=True,
    multiselect=False
    select_dirs=False
)
result = dialog()

Ufd 的完整构造函数签名如下所示:

def __init__(
    self,
    title:str="Universal File Dialog",
    icon:str="",
    show_hidden:bool=False,
    include_files:bool=True,
    multiselect:bool=True,
    select_dirs:bool=True,
    select_files:bool=True,
    unix_delimiter:bool=True,
    stdout:bool=False
):

title : str: 窗口标题

icon : str: 自定义 icon.ico 文件的路径

show_hidden : bool: 在树视图中包含隐藏文件或文件夹

include_files : bool: 在树视图中包含文件

multiselect : bool: 文件列表多选支持,无论哪种方式都返回一个列表

select_dirs : bool: 文件列表显示目录(文件夹浏览器)

select_files : bool: 文件列表显示文件(文件浏览器)

unix_delimiter : bool: 返回以“/”或“\”分隔的路径

stdout :bool:在返回之前将对话框选择的换行符分隔列表打印到标准输出(如果您不从 Python 调用对话框,则很有用)

Ufd 仍然有几个 [boolean constructor parameters] 选项和开发中的行为调整,可以选择性地限制/扩展其行为以匹配使用它的上下文。

在没有 Python 的情况下使用 Ufd

Ufd.exe 是使用 PyInstaller 为 x64 系统编译的 Windows 二进制文件。( dist_win64/Ufd/Ufd.exe)

#include <iostream>
#include <fstream>
#include <string>
#include <vector>

int main(int argc, char *argv[]) {
    system("/path/to/ufd.exe stdout=True > paths.txt");
    std::ifstream inFile("paths.txt");

    std::vector<std::string> results;
    std::string result;

    while (getline(inFile, result)) results.push_back(result);

    inFile.close();
    std::remove("paths.txt");

    for (std::string path : results) std::cout << path << "\n";

    std::cin.ignore();
    return 0;
}

为什么要使用 Ufd?

  • 这很简单
  • 没有外部依赖
  • Ufd 不在乎它作为什么样的对话。您可以用自己的方式处理任何歧义。

想要从同一个对话框中选择 3 个目录和 2 个文件,并将它们的路径作为列表返回?

dialog = Ufd()
result = dialog()
>> result
>> ["C:some_dir/dir1", "C:some_dir/dir2", "C:some_dir/dir3", "C:some_dir/file1.ext", "C:some_dir/file2.ext"]

或者,如果您希望让用户选择一个文件:

dialog = Ufd(multiselect=False, select_dirs=False)
result = dialog()
>> result
>> ["C:some_dir/file1.ext"]

提示与技巧:

  • <Doubleclick>使用、<Enter>和/或箭头键钻取树视图。
  • Treeview 支持单选通过<Doubleclick>或提交按钮。
  • 使用鼠标或箭头键导航右侧的列表框。<Shift>(span) & <Ctrl>(individuals) 或单击 + 拖动鼠标支持多选。<Ctrl+A>按预期全选。<Enter>使用或 提交按钮确认列表框中的选择。
  • 通过<Ctrl-w>、取消按钮或窗口管理器取消都将从对话框中返回一个空列表。

去做
  • 仅树视图模式/文件夹浏览器模式
  • Treeview 错误的 x_scroll
  • Treeview窃听边框
  • 列表框过滤器
  • 列表框导航

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

ufd-1.0.0.tar.gz (45.6 kB 查看哈希

已上传 source

内置分布

Ufd-1.0.0-py3-none-any.whl (43.4 kB 查看哈希

已上传 py3