The PyResource class provides an interface to create widgets or to load .ui files from Python. More...
#include <WidgetFactory.h>
Public Member Functions | |
PyObject * | _getattr (char *attr) |
GetAttribute implementation This method implements the retriavel of object attributes. | |
int | _setattr (char *attr, PyObject *value) |
SetAttribute implementation This method implements the seting of object attributes. | |
PyObject * | connect (PyObject *args) |
Searches for the sender, the signal and the callback function to connect with in the argument object args. | |
bool | connect (const char *sender, const char *signal, PyObject *cb) |
Makes a connection between the sender widget sender and its signal signal of the created resource and Python callback function cb. | |
virtual PyParentObject * | GetParents (void) |
virtual PyTypeObject * | GetType (void) |
void | load (const char *name) |
Loads an .ui file with the name name. | |
PyResource (PyTypeObject *T=&Type) | |
PyObject * | setValue (PyObject *args) |
Searches for a widget, its value name and the new value in the argument object args to set even this new value. | |
PyObject * | show (PyObject *args) |
If any resouce has been loaded this methods shows it as a modal dialog. | |
PyObject * | value (PyObject *args) |
Searches for a widget and its value in the argument object args to returns its value as Python object. | |
Static Public Member Functions | |
static PyObject * | PyMake (PyObject *, PyObject *) |
for construction in Python | |
static PyObject * | sconnect (PyObject *self, PyObject *args, PyObject *) |
static PyObject * | ssetValue (PyObject *self, PyObject *args, PyObject *) |
static PyObject * | sshow (PyObject *self, PyObject *args, PyObject *) |
static PyObject * | svalue (PyObject *self, PyObject *args, PyObject *) |
Static Public Attributes | |
static PyMethodDef | Methods [] |
static PyParentObject | Parents [] = {&PyObjectBase::Type,&PyResource::Type, NULL} |
static PyTypeObject | Type |
Py_Header struct from python.h. | |
Protected Member Functions | |
~PyResource () |
The PyResource class provides an interface to create widgets or to load .ui files from Python.
With
d = Gui.CreateDialog("test.ui")
you can create a PyResource object containing the widget. If a relative file name is given PyResource looks first in the current working directory and afterwards in the home path where FreeCAD resides.
If the appropriate .ui file cannot be found or creation fails an exception is thrown. In case the widget in the .ui file does not inherit from QDialog it is embedded in a ContainerDialog object. To show the widget you can call
d.Show()
Furthermore it is possible to get or set values from any widgets inside the parent widget or to connect a Python callback function with a widget.
If the button with the name "Button_Name" is clicked the message "Button clicked" is printed. For example if you have a QLineEdit inside your widget you can set the text with
# sets "Show this text here!" to the text property d.SetValue("lineedit", "text", "Show this text here!") d.Show()
or retrieve the entered text with
Definition at line 326 of file WidgetFactory.h.
PyResource::~PyResource | ( | ) | [protected] |
Definition at line 344 of file WidgetFactory.cpp.
PyResource::PyResource | ( | PyTypeObject * | T = &Type |
) |
Definition at line 330 of file WidgetFactory.cpp.
PyObject * PyResource::_getattr | ( | char * | attr | ) | [virtual] |
GetAttribute implementation This method implements the retriavel of object attributes.
If you want to implement attributes in your class, reimplement this method. You have to call the method of the base class. Note: if you reimplement _gettattr() in a inheriting class you need to call the method of the base class! Otherwise even the methods of the object will disapiear!
Reimplemented from Base::PyObjectBase.
Definition at line 356 of file WidgetFactory.cpp.
References _getattr_up, and Base::PyObjectBase::PyObjectBase().
int PyResource::_setattr | ( | char * | attr, | |
PyObject * | value | |||
) | [virtual] |
SetAttribute implementation This method implements the seting of object attributes.
If you want to implement attributes in your class, reimplement this method. You have to call the method of the base class.
Reimplemented from Base::PyObjectBase.
Definition at line 362 of file WidgetFactory.cpp.
Searches for the sender, the signal and the callback function to connect with in the argument object args.
In the case it fails 0 is returned.
Definition at line 479 of file WidgetFactory.cpp.
bool PyResource::connect | ( | const char * | sender, | |
const char * | signal, | |||
PyObject * | cb | |||
) |
Makes a connection between the sender widget sender and its signal signal of the created resource and Python callback function cb.
If the sender widget does not exist or no resource has been loaded this method returns FALSE, otherwise it returns TRUE.
Definition at line 444 of file WidgetFactory.cpp.
Referenced by connect().
virtual PyParentObject* Gui::PyResource::GetParents | ( | void | ) | [inline, virtual] |
Reimplemented from Base::PyObjectBase.
Definition at line 329 of file WidgetFactory.h.
virtual PyTypeObject* Gui::PyResource::GetType | ( | void | ) | [inline, virtual] |
Reimplemented from Base::PyObjectBase.
Definition at line 329 of file WidgetFactory.h.
void PyResource::load | ( | const char * | name | ) |
Loads an .ui file with the name name.
If the .ui file cannot be found or the QWidgetFactory cannot create an instance an exception is thrown. If the created resource does not inherit from QDialog an instance of ContainerDialog is created to embed it.
Definition at line 373 of file WidgetFactory.cpp.
References DrawingExample::file, App::GetApplication(), and RobotExample::w.
for construction in Python
Definition at line 335 of file WidgetFactory.cpp.
static PyObject* Gui::PyResource::sconnect | ( | PyObject * | self, | |
PyObject * | args, | |||
PyObject * | ||||
) | [inline, static] |
Definition at line 354 of file WidgetFactory.h.
Searches for a widget, its value name and the new value in the argument object args to set even this new value.
In the case it fails 0 is returned.
Definition at line 611 of file WidgetFactory.cpp.
If any resouce has been loaded this methods shows it as a modal dialog.
Definition at line 513 of file WidgetFactory.cpp.
static PyObject* Gui::PyResource::ssetValue | ( | PyObject * | self, | |
PyObject * | args, | |||
PyObject * | ||||
) | [inline, static] |
Definition at line 352 of file WidgetFactory.h.
static PyObject* Gui::PyResource::sshow | ( | PyObject * | self, | |
PyObject * | args, | |||
PyObject * | ||||
) | [inline, static] |
Definition at line 353 of file WidgetFactory.h.
static PyObject* Gui::PyResource::svalue | ( | PyObject * | self, | |
PyObject * | args, | |||
PyObject * | ||||
) | [inline, static] |
Definition at line 351 of file WidgetFactory.h.
Searches for a widget and its value in the argument object args to returns its value as Python object.
In the case it fails 0 is returned.
Definition at line 540 of file WidgetFactory.cpp.
PyMethodDef PyResource::Methods [static] |
{ {"GetValue", (PyCFunction) svalue, Py_NEWARGS}, {"SetValue", (PyCFunction) ssetValue, Py_NEWARGS}, {"Show", (PyCFunction) sshow, Py_NEWARGS}, {"Connect", (PyCFunction) sconnect, Py_NEWARGS}, {NULL, NULL} }
Reimplemented from Base::PyObjectBase.
Definition at line 329 of file WidgetFactory.h.
PyParentObject PyResource::Parents = {&PyObjectBase::Type,&PyResource::Type, NULL} [static] |
Reimplemented from Base::PyObjectBase.
Definition at line 329 of file WidgetFactory.h.
PyTypeObject PyResource::Type [static] |
{ PyObject_HEAD_INIT(&PyType_Type) 0, "PyResource", sizeof(PyResource), 0, PyDestructor, 0, __getattr, __setattr, 0, __repr, 0, 0, 0, 0, 0, }
Py_Header struct from python.h.
To prevent subclasses of PyTypeObject to be subclassed in Python we should remove the Py_TPFLAGS_BASETYPE flag.
Every PyObjectBase object is also a python object. So you can use every Python C-Library function also on a PyObjectBase object
For example, the classes App::VectorPy and App::MatrixPy have removed this flag and its Python proxies App.Vector and App.Matrix cannot be subclassed. In case we want to allow to derive from subclasses of PyTypeObject in Python we must either reimplment tp_new, tp_dealloc, tp_getattr, tp_setattr, tp_repr or set them to 0 and define tp_base as 0.
Reimplemented from Base::PyObjectBase.
Definition at line 329 of file WidgetFactory.h.