首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有谁知道如何使用PyQt 'uic‘模块方法’编译uic‘吗?

有谁知道如何使用PyQt 'uic‘模块方法’编译uic‘吗?
EN

Software Engineering用户
提问于 2014-02-18 12:12:54
回答 1查看 1.3K关注 0票数 0

我不认为docstring很清楚:

代码语言:javascript
复制
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关键字参数,没有简单的示例可供使用。

这是在期待地图的争论吗?如:

代码语言:javascript
复制
uic.compileUiDir("ui/", map=("ui/", "../widget/test.py"))

它是如何形成的?

基本上,我在.ui目录中有几个ui文件,并希望编译它们,并将生成的.py文件放在另一个名为widget的目录中。

它们有test1Widget.uitest2Widget.ui等名称,我希望它们被重命名为test1.pytest2.py等。

有人能给我一些指点吗?

EN

回答 1

Software Engineering用户

回答已采纳

发布于 2014-02-18 15:10:43

好吧,所以我误解了docstring。

它声明需要一个可调用的(必须读取可调用的!)使用.ui文件的名称输入原始目录,然后用目标文件名返回目标目录。

下面是这方面的代码,它运行得很顺利!:)

代码语言:javascript
复制
    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)

因此,我有所需的输出命名和目录结构。

我今天当然学到了一些新的东西,希望它能帮助别人解决同样的问题!

和平

票数 0
EN
页面原文内容由Software Engineering提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://softwareengineering.stackexchange.com/questions/229349

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档