683{
684 auto ui = host.def_submodule(
685 "ui",
686 "Host UI: native dialogs and interactive HTML windows. Calls run on the main/UI "
687 "thread (marshaled from the plugin thread). See the plugin docs for the window.orca bridge. "
688 "Do not call these from a slicing pipeline hook (SlicingPipeline capability): that hook runs "
689 "on the slicing worker thread, which the UI thread can itself be blocked waiting on, so a "
690 "marshaled UI call from there can deadlock the application. Once the application is closing, a "
691 "call from a background thread raises RuntimeError instead of waiting for the UI thread.");
692
693 ui.def("message", &ui_message, py::arg("text"), py::arg("title") = "OrcaSlicer", py::arg("buttons") = "ok",
694 py::arg("icon") = "info",
695 "Show a native modal message box; returns the clicked button id "
696 "(\"ok\"/\"cancel\"/\"yes\"/\"no\"). buttons: \"ok\"|\"ok_cancel\"|\"yes_no\"|\"yes_no_cancel\"; "
697 "icon: \"info\"|\"warning\"|\"error\"|\"question\".");
698
699 ui.attr("PD_APP_MODAL") = py::int_(wxPD_APP_MODAL);
700 ui.attr("PD_AUTO_HIDE") = py::int_(wxPD_AUTO_HIDE);
701 ui.attr("PD_CAN_ABORT") = py::int_(wxPD_CAN_ABORT);
702 ui.attr("PD_CAN_SKIP") = py::int_(wxPD_CAN_SKIP);
703 ui.attr("PD_ELAPSED_TIME") = py::int_(wxPD_ELAPSED_TIME);
704 ui.attr("PD_ESTIMATED_TIME") = py::int_(wxPD_ESTIMATED_TIME);
705 ui.attr("PD_REMAINING_TIME") = py::int_(wxPD_REMAINING_TIME);
706 ui.attr("WINDOW_MODELESS") = py::int_(WINDOW_MODELESS);
707 ui.attr("WINDOW_MODAL") = py::int_(WINDOW_MODAL);
708
709 py::class_<UiWindowHandle>(ui, "UiWindow", "Handle to a plugin HTML window or modal dialog created by create_window().")
710 .def_property_readonly("id", [](const UiWindowHandle& h) { return h.id; })
711 .def(
712 "post", [](
const UiWindowHandle& h, py::object data) {
handle_post(h.id, std::move(data)); },
713 py::arg("data"), "Send a payload to the page (delivered to window.orca.onMessage handlers).")
714 .def(
715 "close", [](
const UiWindowHandle& h) {
handle_close(h.id); },
"Close the window (fires on_close).")
716 .def(
717 "is_open", [](const UiWindowHandle& h) { return UiRegistry::instance().is_open(h.id); },
718 "Return True while the window is open.");
719
720 ui.def("create_window", &ui_create_window, py::arg("html"), py::arg("title") = "OrcaSlicer", py::arg("width") = 820,
721 py::arg("height") = 600, py::arg("on_message") = py::none(), py::arg("on_close") = py::none(),
722 py::arg("style") = WINDOW_MODELESS, py::arg("on_submit") = py::none(),
723 "Open a persistent HTML window or modal dialog and return a UiWindow. style is WINDOW_MODELESS "
724 "or WINDOW_MODAL. on_message(data) is called on the UI thread when the page posts; on_submit(data) "
725 "is called when the page submits; offload heavy work to a thread and push results back with window.post().");
726
727 py::class_<UiDockPanelHandle>(ui, "UiDockPanel", "Handle to a dockable plugin HTML panel created by create_dock_panel().")
728 .def_property_readonly("id", [](const UiDockPanelHandle& h) { return h.id; })
729 .def(
730 "post", [](
const UiDockPanelHandle& h, py::object data) {
handle_post(h.id, std::move(data)); },
731 py::arg("data"), "Send a payload to the page (delivered to window.orca.onMessage handlers).")
732 .def(
733 "show", [](
const UiDockPanelHandle& h) {
handle_show(h.id,
true); },
"Show the panel again after hide().")
734 .def(
735 "hide", [](
const UiDockPanelHandle& h) {
handle_show(h.id,
false); },
"Hide the panel without closing it.")
736 .def(
737 "close", [](
const UiDockPanelHandle& h) {
handle_close(h.id); },
"Close the panel (fires on_close).")
738 .def(
739 "is_open", [](const UiDockPanelHandle& h) { return UiRegistry::instance().is_open(h.id); },
740 "Return True until the panel is closed; a hidden panel is still open.");
741
742 ui.def("create_dock_panel", &ui_create_dock_panel, py::arg("html"), py::arg("title") = "OrcaSlicer",
743 py::arg("width") = 320, py::arg("height") = 480, py::arg("on_message") = py::none(),
744 py::arg("on_close") = py::none(), py::arg("dock") = "right",
745 "Open an HTML panel docked beside the 3D view and return a UiDockPanel. dock is \"left\", \"right\", "
746 "\"bottom\" or \"float\", and width/height are in DIPs; the user can move and resize the panel, and a panel "
747 "opened again comes back where the window layout was last saved. The panel belongs to the Prepare and "
748 "Preview tabs. on_message(data) is called on the UI thread when the page posts; window.orca.close() "
749 "or the panel's close button closes it and calls on_close(). A post() made before the page has "
750 "loaded can be dropped, so have the page request its first data.");
751
752 py::class_<UiProgressHandle>(ui, "ProgressDialog", "Handle to a native progress dialog.")
753 .def(py::init(&new_progress_dialog), py::arg("title"), py::arg("message"), py::arg("maximum") = 100,
754 py::arg("style") = wxPD_APP_MODAL | wxPD_AUTO_HIDE)
755 .def_property_readonly("id", [](const UiProgressHandle& h) { return h.id; })
756 .def(
757 "pulse", [](
const UiProgressHandle& h,
const std::string& message) {
return progress_pulse(h.id, message); },
758 py::arg("message") = "", "Pulse the dialog gauge; returns False if the dialog is closed or cancelled.")
759 .def(
760 "update",
761 [](const UiProgressHandle& h, int value, const std::string& message) {
763 },
764 py::arg("value"), py::arg("message") = "",
765 "Set the dialog progress value; returns False if the dialog is closed or cancelled.")
766 .def(
767 "start_pulse",
768 [](const UiProgressHandle& h, int interval_ms, const std::string& message) {
770 },
771 py::arg("interval_ms") = 100, py::arg("message") = "", "Start periodic pulsing.")
772 .def(
773 "stop_pulse", [](
const UiProgressHandle& h) {
progress_stop_pulse(h.id); },
"Stop periodic pulsing.")
774 .def(
775 "close", [](
const UiProgressHandle& h) {
progress_close(h.id); },
"Close the progress dialog.")
776 .def(
777 "is_open", [](
const UiProgressHandle& h) {
return progress_is_open(h.id); },
778 "Return True while this progress dialog is registered.")
779 .def("__enter__", [](UiProgressHandle& h) -> UiProgressHandle& { return h; }, py::return_value_policy::reference_internal)
780 .def("__exit__", [](const UiProgressHandle& h, py::object, py::object, py::object) {
782 return false;
783 });
784
785 ui.def("create_progress_dialog", &ui_create_progress_dialog, py::arg("title"), py::arg("message"),
786 py::arg("maximum") = 100, py::arg("style") = wxPD_APP_MODAL | wxPD_AUTO_HIDE,
787 "Create a native progress dialog and return a ProgressDialog handle.");
788
789 py::enum_<GUI::NotificationManager::NotificationLevel>(ui, "NotificationLevel")
799 .export_values();
800
801 ui.def("push_notification", &plater_notification, py::arg("notification_level"), py::arg("text"),
802 py::arg("hyper_text") = "", py::arg("on_click") = py::none(),
803 "Push a plater notification. hyper_text is an underlined label; on_click() is called when it is clicked "
804 "and may return True to close the notification.");
805}
@ WarningNotificationLevel
Definition NotificationManager.hpp:224
@ PrintInfoShortNotificationLevel
Definition NotificationManager.hpp:220
@ SeriousWarningNotificationLevel
Definition NotificationManager.hpp:226
@ ProgressBarNotificationLevel
Definition NotificationManager.hpp:212
@ HintNotificationLevel
Definition NotificationManager.hpp:214
@ PrintInfoNotificationLevel
Definition NotificationManager.hpp:218
@ ImportantNotificationLevel
Definition NotificationManager.hpp:222
@ RegularNotificationLevel
Definition NotificationManager.hpp:216
@ ErrorNotificationLevel
Definition NotificationManager.hpp:228
void handle_close(int id)
Definition PluginHostUi.cpp:541
bool progress_pulse(int id, const std::string &message)
Definition PluginHostUi.cpp:595
void progress_start_pulse(int id, int interval_ms, const std::string &message)
Definition PluginHostUi.cpp:611
void handle_post(int id, py::object data)
Definition PluginHostUi.cpp:527
void progress_stop_pulse(int id)
Definition PluginHostUi.cpp:619
void handle_show(int id, bool show)
Definition PluginHostUi.cpp:554
bool progress_update(int id, int value, const std::string &message)
Definition PluginHostUi.cpp:603
void progress_close(int id)
Definition PluginHostUi.cpp:627
bool progress_is_open(int id)
Definition PluginHostUi.cpp:590