Debian Codegraph @

plugins/script/interfaces/DialogInterface.cpp

raw
1 #include "DialogInterface.h"
2
3 #include <pybind11/pybind11.h>
4
5 namespace script
6 {
7
8 ScriptDialog DialogManagerInterface::createDialog(const std::string& title)
9 {
10 return ScriptDialog(GlobalDialogManager().createDialog(title));
11 }
12
13 ScriptDialog DialogManagerInterface::createMessageBox(const std::string& title,
14 const std::string& text,
15 ui::IDialog::MessageType type)
16 {
17 return ScriptDialog(GlobalDialogManager().createMessageBox(title, text, type));
18 }
19
20 // IScriptInterface implementation
21 void DialogManagerInterface::registerInterface(py::module& scope, py::dict& globals)
22 {
23 py::class_<DialogManagerInterface> dialogMgr(scope, "DialogManager");
24 dialogMgr.def("createDialog", &DialogManagerInterface::createDialog);
25 dialogMgr.def("createMessageBox", &DialogManagerInterface::createMessageBox);
26
27 // Now point the Python variable "GlobalDialogManager" to this instance
28 globals["GlobalDialogManager"] = this;
29
30 // Add the declaration for the IDialog class
31 py::class_<ScriptDialog> dialog(scope, "Dialog");
32 dialog.def(py::init<const ui::IDialogPtr&>());
33
34 // Add the methods to the dialog object
35 dialog.def("setTitle", &ScriptDialog::setTitle);
36 dialog.def("run", &ScriptDialog::run);
37 dialog.def("addLabel", &ScriptDialog::addLabel);
38 dialog.def("addComboBox", &ScriptDialog::addComboBox);
39 dialog.def("addEntryBox", &ScriptDialog::addEntryBox);
40 dialog.def("addPathEntry", &ScriptDialog::addPathEntry);
41 dialog.def("addSpinButton", &ScriptDialog::addSpinButton);
42 dialog.def("addCheckbox", &ScriptDialog::addCheckbox);
43 dialog.def("getElementValue", &ScriptDialog::getElementValue);
44 dialog.def("setElementValue", &ScriptDialog::setElementValue);
45
46 // Expose the enums in the Dialog's scope
47 py::enum_<ui::IDialog::Result>(dialog, "Result")
48 .value("CANCELLED", ui::IDialog::RESULT_CANCELLED)
49 .value("OK", ui::IDialog::RESULT_OK)
50 .value("NO", ui::IDialog::RESULT_NO)
51 .value("YES", ui::IDialog::RESULT_YES)
52 .export_values();
53
54 py::enum_<ui::IDialog::MessageType>(dialog, "MessageType")
55 .value("CONFIRM", ui::IDialog::MESSAGE_CONFIRM)
56 .value("ASK", ui::IDialog::MESSAGE_ASK)
57 .value("WARNING", ui::IDialog::MESSAGE_WARNING)
58 .value("ERROR", ui::IDialog::MESSAGE_ERROR)
59 .value("YESNOCANCEL", ui::IDialog::MESSAGE_YESNOCANCEL)
60 .export_values();
61 }
62
63
64 } // namespace script