mirror of
https://github.com/ModOrganizer2/modorganizer-plugin_python.git
synced 2026-07-27 14:03:33 -07:00
Minor fixes for typing.
This commit is contained in:
@@ -665,6 +665,14 @@ namespace mo2::python {
|
||||
|
||||
void add_iinstallation_manager_classes(py::module_ m)
|
||||
{
|
||||
// add this here to get proper typing
|
||||
py::enum_<IPluginInstaller::EInstallResult>(m, "InstallResult")
|
||||
.value("SUCCESS", IPluginInstaller::RESULT_SUCCESS)
|
||||
.value("FAILED", IPluginInstaller::RESULT_FAILED)
|
||||
.value("CANCELED", IPluginInstaller::RESULT_CANCELED)
|
||||
.value("MANUAL_REQUESTED", IPluginInstaller::RESULT_MANUALREQUESTED)
|
||||
.value("NOT_ATTEMPTED", IPluginInstaller::RESULT_NOTATTEMPTED);
|
||||
|
||||
py::class_<IInstallationManager>(m, "IInstallationManager")
|
||||
.def("getSupportedExtensions",
|
||||
&IInstallationManager::getSupportedExtensions)
|
||||
|
||||
@@ -95,29 +95,21 @@ namespace mo2::python {
|
||||
py::class_<IFileTree, FileTreeEntry, std::shared_ptr<IFileTree>>(
|
||||
m, "IFileTree", py::multiple_inheritance());
|
||||
|
||||
// this is FILE_OR_DIRECTORY but as a FileType since we kind of cheat for the
|
||||
// exposure in Python and this help pybind11 creates proper typing
|
||||
|
||||
const auto FILE_OR_DIRECTORY = static_cast<FileTreeEntry::FileType>(
|
||||
FileTreeEntry::FILE_OR_DIRECTORY.toInt());
|
||||
|
||||
// we do not use the enum directly, we will mostly bind the FileTypes
|
||||
// (with an S)
|
||||
py::enum_<FileTreeEntry::FileType>(fileTreeEntryClass, "FileTypes",
|
||||
py::arithmetic{})
|
||||
.value("FILE", FileTreeEntry::FileType::FILE)
|
||||
.value("DIRECTORY", FileTreeEntry::FileType::DIRECTORY)
|
||||
.value("FILE_OR_DIRECTORY", static_cast<FileTreeEntry::FileType>(
|
||||
FileTreeEntry::FILE_OR_DIRECTORY.toInt()))
|
||||
.value("FILE_OR_DIRECTORY", FILE_OR_DIRECTORY)
|
||||
.export_values();
|
||||
|
||||
fileTreeEntryClass
|
||||
.def_property_readonly_static("FILE",
|
||||
[](py::object) {
|
||||
return FileTreeEntry::FILE;
|
||||
})
|
||||
.def_property_readonly_static("DIRECTORY",
|
||||
[](py::object) {
|
||||
return FileTreeEntry::DIRECTORY;
|
||||
})
|
||||
.def_property_readonly_static("FILE_OR_DIRECTORY", [](py::object) {
|
||||
return FileTreeEntry::FILE_OR_DIRECTORY;
|
||||
});
|
||||
|
||||
fileTreeEntryClass
|
||||
|
||||
.def("isFile", &FileTreeEntry::isFile)
|
||||
@@ -177,11 +169,10 @@ namespace mo2::python {
|
||||
iFileTreeClass.def("exists",
|
||||
py::overload_cast<QString, IFileTree::FileTypes>(
|
||||
&IFileTree::exists, py::const_),
|
||||
py::arg("path"),
|
||||
py::arg("type") = IFileTree::FILE_OR_DIRECTORY);
|
||||
py::arg("path"), py::arg("type") = FILE_OR_DIRECTORY);
|
||||
iFileTreeClass.def(
|
||||
"find", py::overload_cast<QString, IFileTree::FileTypes>(&IFileTree::find),
|
||||
py::arg("path"), py::arg("type") = IFileTree::FILE_OR_DIRECTORY);
|
||||
py::arg("path"), py::arg("type") = FILE_OR_DIRECTORY);
|
||||
iFileTreeClass.def("pathTo", &IFileTree::pathTo, py::arg("entry"),
|
||||
py::arg("sep") = "\\");
|
||||
|
||||
|
||||
@@ -96,13 +96,6 @@ namespace mo2::python {
|
||||
// multiple installers
|
||||
void add_iplugininstaller_bindings(pybind11::module_ m)
|
||||
{
|
||||
py::enum_<IPluginInstaller::EInstallResult>(m, "InstallResult")
|
||||
.value("SUCCESS", IPluginInstaller::RESULT_SUCCESS)
|
||||
.value("FAILED", IPluginInstaller::RESULT_FAILED)
|
||||
.value("CANCELED", IPluginInstaller::RESULT_CANCELED)
|
||||
.value("MANUAL_REQUESTED", IPluginInstaller::RESULT_MANUALREQUESTED)
|
||||
.value("NOT_ATTEMPTED", IPluginInstaller::RESULT_NOTATTEMPTED);
|
||||
|
||||
// this is bind but should not be inherited in Python - does not make sense,
|
||||
// having it makes it simpler to bind the Simple and Custom installers
|
||||
py::class_<IPluginInstaller, PyPluginInstallerBase<IPluginInstaller>, IPlugin,
|
||||
|
||||
@@ -41,7 +41,9 @@ namespace pybind11::detail::qt {
|
||||
parent);
|
||||
}
|
||||
|
||||
PYBIND11_TYPE_CASTER(Type, const_name("Iterable[") + value_conv::name +
|
||||
// we type these as "Sequence" even if these can be constructed from Iterable,
|
||||
// otherwise the return type will be typed as "Iterable" which is problematic
|
||||
PYBIND11_TYPE_CASTER(Type, const_name("Sequence[") + value_conv::name +
|
||||
const_name("]"));
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user