Gui::PyResource Class Reference

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

#include <WidgetFactory.h>

Public Member Functions

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. More...
 
Py::Object connect (const Py::Tuple &)
 Searches for the sender, the signal and the callback function to connect with in the argument object args. More...
 
void load (const char *name)
 Loads an .ui file with the name name. More...
 
 PyResource ()
 
Py::Object repr ()
 
Py::Object setValue (const Py::Tuple &)
 Searches for a widget, its value name and the new value in the argument object args to set even this new value. More...
 
Py::Object show (const Py::Tuple &)
 If any resource has been loaded this methods shows it as a modal dialog. More...
 
Py::Object value (const Py::Tuple &)
 Searches for a widget and its value in the argument object args to returns its value as Python object. More...
 
 ~PyResource ()
 

Static Public Member Functions

static void init_type ()
 

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

Constructor & Destructor Documentation

◆ PyResource()

PyResource::PyResource ( )

◆ ~PyResource()

PyResource::~PyResource ( )

Member Function Documentation

◆ connect() [1/2]

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.

References draftgeoutils.intersections::connect().

Referenced by connect(), and init_type().

◆ connect() [2/2]

Py::Object PyResource::connect ( const Py::Tuple &  args)

Searches for the sender, the signal and the callback function to connect with in the argument object args.

In the case it fails nullptr is returned.

References connect().

◆ init_type()

void PyResource::init_type ( void  )
static

◆ load()

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.

References App::Application::getHomePath().

Referenced by draftguitools.gui_setstyle.Draft_SetStyle_TaskPanel::loadDefaults(), draftguitools.gui_setstyle.Draft_SetStyle_TaskPanel::onLoadStyle(), and draftguitools.gui_setstyle.Draft_SetStyle_TaskPanel::onSaveStyle().

◆ repr()

Py::Object PyResource::repr ( )

◆ setValue()

Py::Object PyResource::setValue ( const Py::Tuple &  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 nullptr is returned.

Referenced by init_type().

◆ show()

Py::Object PyResource::show ( const Py::Tuple &  )

If any resource has been loaded this methods shows it as a modal dialog.

Referenced by init_type(), Mod.Show.mTempoVis.TempoVis::show_all_dependencies(), and Mod.Show.mTempoVis.TempoVis::show_all_dependent().

◆ value()


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