I don’t find the docstring to be very clear:
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.
"""
with regards to the map keyword argument and there is no simple example to go with it.
Is it expecting a map argument? as in:
uic.compileUiDir("ui/", map=("ui/", "../widget/test.py"))
and how is it formed?
I basically have a few .ui
files in the ui
directory and wish to compile them and place the resulting .py
files in another directory called widget
.
They have names like test1Widget.ui
, test2Widget.ui
, etc. and I would like for them to be renamed to test1.py
, test2.py
, etc.
Can anyone give me some pointers please?
ok, so I misunderstood the docstring.
It states that a callable is required (had to read up on callables!) taking in the original directory with the name of the .ui file and spitting back out the target directory with the target file name.
Here is the code for this and it works swimmingly well! 🙂
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)
Hence, I have the output naming and directory structure I required.
I certainly learnt something new today and hope it helps someone else out with the same problem!
Peace