Gui::PyResource Class Reference

The PyResource class provides an interface to create widgets or to load .ui files from Python. More...

#include <WidgetFactory.h>

Inheritance diagram for Gui::PyResource:
Base::PyObjectBase

List of all members.

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.
PyObjectconnect (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 PyParentObjectGetParents (void)
virtual PyTypeObject * GetType (void)
void load (const char *name)
 Loads an .ui file with the name name.
 PyResource (PyTypeObject *T=&Type)
PyObjectsetValue (PyObject *args)
 Searches for a widget, its value name and the new value in the argument object args to set even this new value.
PyObjectshow (PyObject *args)
 If any resouce has been loaded this methods shows it as a modal dialog.
PyObjectvalue (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 PyObjectPyMake (PyObject *, PyObject *)
 for construction in Python
static PyObjectsconnect (PyObject *self, PyObject *args, PyObject *)
static PyObjectssetValue (PyObject *self, PyObject *args, PyObject *)
static PyObjectsshow (PyObject *self, PyObject *args, PyObject *)
static PyObjectsvalue (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 ()

Detailed Description

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.

Remarks:
The callback function must have exactly one parameter. This parameter points to the dialog you have just created.
 # define a callback function with one argument
 def TestCall(obj):
      # sets the value from lineedit if "Button_Name" was pressed
      obj.SetValue("lineedit", "text", "Show this text here!")
      print "Button clicked"

 d = Gui.CreateDialog("test.ui")
 d.Connect("Button_Name", "clicked()", TestCall)
 d.Show()

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

 f = d.GetValue("lineedit", "text")
 print f
Author:
Werner Mayer

Definition at line 326 of file WidgetFactory.h.


Constructor & Destructor Documentation

PyResource::~PyResource (  )  [protected]

Definition at line 344 of file WidgetFactory.cpp.

PyResource::PyResource ( PyTypeObject *  T = &Type  ) 

Definition at line 330 of file WidgetFactory.cpp.


Member Function Documentation

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.

PyObject * PyResource::connect ( PyObject args  ) 

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.

References connect(), and result.

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.

PyObject * PyResource::PyMake ( PyObject ignored,
PyObject args 
) [static]

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.

PyObject * PyResource::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.

In the case it fails 0 is returned.

Definition at line 611 of file WidgetFactory.cpp.

PyObject * PyResource::show ( PyObject args  ) 

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.

PyObject * PyResource::value ( PyObject args  ) 

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.


Member Data Documentation

PyMethodDef PyResource::Methods [static]
Initial value:
 {
                                        {"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]
Initial value:
 {
                                    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.


The documentation for this class was generated from the following files:

Generated on Wed Nov 23 19:02:01 2011 for FreeCAD by  doxygen 1.6.1