我不认为docstring很清楚:
def compileUiDir(dir, recurse=False, map=None, **compileUi_args):
"""compileUiDir(dir, recurse=False, map=None, **compileUi_args)
Creates Python modules from Qt Designer .ui files in a directory or
directory tree.
dir is the name of the directory to scan for files whose name ends with
'.ui'. By default the generated Python module is created in the same
directory ending with '.py'.
recurse is set if any sub-directories should be scanned. The default is
False.
map is an optional callable that is passed the name of the directory
containing the '.ui' file and the name of the Python module that will be
created. The callable should return a tuple of the name of the directory
in which the Python module will be created and the (possibly modified)
name of the module. The default is None.
compileUi_args are any additional keyword arguments that are passed to
the compileUi() function that is called to create each Python module.
"""关于map关键字参数,没有简单的示例可供使用。
这是在期待地图的争论吗?如:
uic.compileUiDir("ui/", map=("ui/", "../widget/test.py"))它是如何形成的?
基本上,我在.ui目录中有几个ui文件,并希望编译它们,并将生成的.py文件放在另一个名为widget的目录中。
它们有test1Widget.ui、test2Widget.ui等名称,我希望它们被重命名为test1.py、test2.py等。
有人能给我一些指点吗?
发布于 2014-02-18 15:10:43
好吧,所以我误解了docstring。
它声明需要一个可调用的(必须读取可调用的!)使用.ui文件的名称输入原始目录,然后用目标文件名返回目标目录。
下面是这方面的代码,它运行得很顺利!:)
def rename_and_move_callable(directory, file_name):
return directory.replace("ui/", "widget/"), file_name.replace("Widget.py", ".py")
uic.compileUiDir("ui/", map=rename_and_move_callable)因此,我有所需的输出命名和目录结构。
我今天当然学到了一些新的东西,希望它能帮助别人解决同样的问题!
和平
https://softwareengineering.stackexchange.com/questions/229349
复制相似问题