| 1 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
/*************************************************************************** |
| 3 |
* Copyright (c) 2011 Werner Mayer <wmayer[at]users.sourceforge.net> * |
| 4 |
* * |
| 5 |
* This file is part of the FreeCAD CAx development system. * |
| 6 |
* * |
| 7 |
* This library is free software; you can redistribute it and/or * |
| 8 |
* modify it under the terms of the GNU Library General Public * |
| 9 |
* License as published by the Free Software Foundation; either * |
| 10 |
* version 2 of the License, or (at your option) any later version. * |
| 11 |
* * |
| 12 |
* This library is distributed in the hope that it will be useful, * |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 15 |
* GNU Library General Public License for more details. * |
| 16 |
* * |
| 17 |
* You should have received a copy of the GNU Library General Public * |
| 18 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 19 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 20 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 21 |
* * |
| 22 |
***************************************************************************/ |
| 23 |
|
| 24 |
|
| 25 |
#ifndef GUI_TASKVIEW_TASKDIALOGPYTHON_H |
| 26 |
#define GUI_TASKVIEW_TASKDIALOGPYTHON_H |
| 27 |
|
| 28 |
#include "TaskDialog.h" |
| 29 |
#include "TaskWatcher.h" |
| 30 |
|
| 31 |
|
| 32 |
namespace Gui |
| 33 |
{ |
| 34 |
namespace TaskView |
| 35 |
{ |
| 36 |
|
| 37 |
class ControlPy: public Py::PythonExtension<ControlPy> |
| 38 |
{ |
| 39 |
public: |
| 40 |
static void init_type(); // announce properties and methods |
| 41 |
static ControlPy* getInstance(); |
| 42 |
|
| 43 |
ControlPy(); |
| 44 |
~ControlPy() override; |
| 45 |
|
| 46 |
Py::Object repr() override; |
| 47 |
Py::Object showDialog(const Py::Tuple&); |
| 48 |
Py::Object activeDialog(const Py::Tuple&); |
| 49 |
Py::Object activeTaskDialog(const Py::Tuple&); |
| 50 |
Py::Object closeDialog(const Py::Tuple&); |
| 51 |
Py::Object addTaskWatcher(const Py::Tuple&); |
| 52 |
Py::Object clearTaskWatcher(const Py::Tuple&); |
| 53 |
Py::Object isAllowedAlterDocument(const Py::Tuple&); |
| 54 |
Py::Object isAllowedAlterView(const Py::Tuple&); |
| 55 |
Py::Object isAllowedAlterSelection(const Py::Tuple&); |
| 56 |
Py::Object showTaskView(const Py::Tuple&); |
| 57 |
Py::Object showModelView(const Py::Tuple&); |
| 58 |
|
| 59 |
private: |
| 60 |
static ControlPy* instance; |
| 61 |
}; |
| 62 |
|
| 63 |
class GuiExport TaskWatcherPython: public TaskWatcher |
| 64 |
{ |
| 65 |
public: |
| 66 |
explicit TaskWatcherPython(const Py::Object&); |
| 67 |
~TaskWatcherPython() override; |
| 68 |
bool shouldShow() override; |
| 69 |
|
| 70 |
private: |
| 71 |
Py::Object watcher; |
| 72 |
}; |
| 73 |
|
| 74 |
/** |
| 75 |
* @brief The TaskDialogPy class |
| 76 |
* This class exposes a TaskDialog written in C++ to Python. |
| 77 |
*/ |
| 78 |
class TaskDialogPy: public Py::PythonExtension<TaskDialogPy> |
| 79 |
{ |
| 80 |
public: |
| 81 |
using BaseType = Py::PythonExtension<TaskDialogPy>; |
| 82 |
static void init_type(); // announce properties and methods |
| 83 |
|
| 84 |
explicit TaskDialogPy(TaskDialog*); |
| 85 |
~TaskDialogPy() override; |
| 86 |
|
| 87 |
Py::Object repr() override; |
| 88 |
Py::Object getattr(const char*) override; |
| 89 |
int setattr(const char*, const Py::Object&) override; |
| 90 |
|
| 91 |
public: |
| 92 |
Py::Object getDialogContent(const Py::Tuple&); |
| 93 |
|
| 94 |
/// tells the framework which buttons are wished for the dialog |
| 95 |
Py::Object getStandardButtons(const Py::Tuple&); |
| 96 |
|
| 97 |
/// Defines whether a task dialog can be rejected by pressing Esc |
| 98 |
Py::Object setEscapeButtonEnabled(const Py::Tuple&); |
| 99 |
Py::Object isEscapeButtonEnabled(const Py::Tuple&); |
| 100 |
|
| 101 |
/// Defines whether a task dialog must be closed if the document changed the |
| 102 |
/// active transaction. |
| 103 |
Py::Object setAutoCloseOnTransactionChange(const Py::Tuple&); |
| 104 |
Py::Object isAutoCloseOnTransactionChange(const Py::Tuple&); |
| 105 |
Py::Object setAutoCloseOnDeletedDocument(const Py::Tuple&); |
| 106 |
Py::Object isAutoCloseOnDeletedDocument(const Py::Tuple&); |
| 107 |
|
| 108 |
Py::Object getDocumentName(const Py::Tuple&); |
| 109 |
Py::Object setDocumentName(const Py::Tuple&); |
| 110 |
|
| 111 |
/*! |
| 112 |
Indicates whether this task dialog allows other commands to modify |
| 113 |
the document while it is open. |
| 114 |
*/ |
| 115 |
Py::Object isAllowedAlterDocument(const Py::Tuple&); |
| 116 |
|
| 117 |
/*! |
| 118 |
Indicates whether this task dialog allows other commands to modify |
| 119 |
the 3d view while it is open. |
| 120 |
*/ |
| 121 |
Py::Object isAllowedAlterView(const Py::Tuple&); |
| 122 |
|
| 123 |
/*! |
| 124 |
Indicates whether this task dialog allows other commands to modify |
| 125 |
the selection while it is open. |
| 126 |
*/ |
| 127 |
Py::Object isAllowedAlterSelection(const Py::Tuple&); |
| 128 |
Py::Object needsFullSpace(const Py::Tuple&); |
| 129 |
|
| 130 |
/// is called by the framework if the dialog is accepted (Ok) |
| 131 |
Py::Object accept(const Py::Tuple&); |
| 132 |
/// is called by the framework if the dialog is rejected (Cancel) |
| 133 |
Py::Object reject(const Py::Tuple&); |
| 134 |
|
| 135 |
private: |
| 136 |
QPointer<TaskDialog> dialog; |
| 137 |
}; |
| 138 |
|
| 139 |
/** |
| 140 |
* @brief The TaskDialogPython class |
| 141 |
* This wraps a task dialog that is written in Python. |
| 142 |
*/ |
| 143 |
class GuiExport TaskDialogPython: public TaskDialog |
| 144 |
{ |
| 145 |
public: |
| 146 |
explicit TaskDialogPython(const Py::Object&); |
| 147 |
~TaskDialogPython() override; |
| 148 |
|
| 149 |
QDialogButtonBox::StandardButtons getStandardButtons() const override; |
| 150 |
void modifyStandardButtons(QDialogButtonBox*) override; |
| 151 |
|
| 152 |
/*! |
| 153 |
Indicates whether this task dialog allows other commands to modify |
| 154 |
the document while it is open. |
| 155 |
*/ |
| 156 |
bool isAllowedAlterDocument() const override; |
| 157 |
/*! |
| 158 |
Indicates whether this task dialog allows other commands to modify |
| 159 |
the 3d view while it is open. |
| 160 |
*/ |
| 161 |
bool isAllowedAlterView() const override; |
| 162 |
/*! |
| 163 |
Indicates whether this task dialog allows other commands to modify |
| 164 |
the selection while it is open. |
| 165 |
*/ |
| 166 |
bool isAllowedAlterSelection() const override; |
| 167 |
bool needsFullSpace() const override; |
| 168 |
|
| 169 |
void autoClosedOnTransactionChange() override; |
| 170 |
void autoClosedOnDeletedDocument() override; |
| 171 |
|
| 172 |
public: |
| 173 |
/// is called by the framework when the dialog is opened |
| 174 |
void open() override; |
| 175 |
/// is called by the framework if a button is clicked which has no accept or reject role |
| 176 |
void clicked(int) override; |
| 177 |
/// is called by the framework if the dialog is accepted (Ok) |
| 178 |
bool accept() override; |
| 179 |
/// is called by the framework if the dialog is rejected (Cancel) |
| 180 |
bool reject() override; |
| 181 |
/// is called by the framework if the user press the help button |
| 182 |
void helpRequested() override; |
| 183 |
|
| 184 |
/// event handling |
| 185 |
bool eventFilter(QObject* watched, QEvent* event) override; |
| 186 |
|
| 187 |
private: |
| 188 |
bool tryLoadUiFile(); |
| 189 |
bool tryLoadForm(); |
| 190 |
void appendForm(QWidget* widget, const QPixmap& icon); |
| 191 |
void clearForm(); |
| 192 |
|
| 193 |
private: |
| 194 |
Py::Object dlg; |
| 195 |
}; |
| 196 |
|
| 197 |
} // namespace TaskView |
| 198 |
} // namespace Gui |
| 199 |
|
| 200 |
#endif // GUI_TASKVIEW_TASKDIALOGPYTHON_H |