DUECA/DUSIME
|
A GUI window directly from a glade interface file. More...
#include <GtkGladeWindow.hxx>
Classes | |
struct | OptionMapping |
Struct for mapping enum name to representation string. More... | |
struct | OptionMappings |
Struct for describing mappings. More... | |
Public Member Functions | |
GtkGladeWindow () | |
Constructor. | |
~GtkGladeWindow () | |
Destructor. | |
bool | readGladeFile (const char *file, const char *mainwidget, gpointer client=NULL, const GladeCallbackTable *table=reinterpret_cast< GladeCallbackTable * >(NULL), bool connect_signals=false, bool warn=true) |
Initialization of the glade window. | |
void | connectCallbacks (gpointer client, const GladeCallbackTable *table, bool warn=true) |
Connect callbacks to widgets. | |
void | connectCallbacksAfter (gpointer client, const GladeCallbackTable *table, bool warn=true) |
Connect callbacks to widgets. | |
void | connectCallbackSymbols (gpointer user_data=NULL) |
Connect GObject in-code callbacks, note that this is effective only once, and called when connect_signals=true in the readGladeFile function. | |
GtkWidget * | operator[] (const char *wname) |
Access the widgets in this interface. | |
GObject * | getObject (const char *name) |
Access anything in the interface file as objects. | |
void | show (const char *widget=NULL) |
Open the window. | |
void | hide (const char *widget=NULL) |
Close the window. | |
bool | fillOptions (const char *dcoclass, const char *format, const char *arrformat=NULL, const OptionMappings *mapping=NULL, bool warn=false) |
Use the enum items in a DCO object to fill combobox tree models in the interface. | |
unsigned | setValues (CommObjectReader &dco, const char *format, const char *arrformat=NULL, bool warn=false) |
Use a DCO object to set the state of the interface. | |
unsigned | getValues (CommObjectWriter &dco, const char *format, const char *arrformat=NULL, bool warn=false) |
Find the current state of the interface and push into a DCO object. | |
template<typename T > | |
bool | loadComboText (const char *name, const T &values) |
Initialize a text combobox with a given list or array of values. | |
void | setWindow (const std::vector< int > &p) |
Change position and size of the window. | |
A GUI window directly from a glade interface file.
Supply the interface file name, and a table of pointers to callback functions. As an example:
Check the signatures for the callback functions in the Gtk3 documentation. Stick to the signature generated by glade, since deviating from that signature may result in all kinds of unclean mess.
The last argument of the callback function, the gpointer argument, is normally a pointer to user data that one can add to the signal connection in gtk. However, the callback system used by GtkGladeWindow already uses that gpointer. You can add a new value by specifying it in the last column of the GladeCallbackTable.
It is also possible to quickly link and load DCO objects to elements in your interface. Take the following dco object as an example:
If you now ensure that the widgets holding this data (for the float a TextEntry, an Adjustment, a SpinButton or a Range, for the enum a ComboBox) are properly named, the GtkGladeWindow can:
As an example, for a glade window with a SpinButton named "mywidgets_a" and a ComboBox named "mywidgets_command", the following code should work:
You can also use (fixed-size) arrays with values in the DCO objects, and have the interface fill these; the second format string "arrformat", describes how these are labeled.
In your glade gui, ensure that:
dueca::GtkGladeWindow::~GtkGladeWindow | ( | ) |
Destructor.
Also closes the window if not already closed.
bool dueca::GtkGladeWindow::readGladeFile | ( | const char * | file, |
const char * | mainwidget, | ||
gpointer | client = NULL, | ||
const GladeCallbackTable * | table = reinterpret_cast< GladeCallbackTable * >(NULL), | ||
bool | connect_signals = false, | ||
bool | warn = true ) |
Initialization of the glade window.
Loads the interface code from the file and creates the main widget. Connects callbacks given in the table, and optionally connects callback signals to symbols found in the application's symbol table.
file | Name of the glade interface file |
mainwidget | Top-level widget (normally a window) in that file that will be opened. |
client | Pointer to the class that will be receiving the callbacks. |
table | Table linking widget, signal, callback function and optionally the pointer argument to the callback function. |
connect_signals | Connect gobject callback signals. The user_data argument to callback functions is obtained from the "client" argument. |
warn | Warn when widgets in the callback table are not found in the interface. |
void dueca::GtkGladeWindow::connectCallbacks | ( | gpointer | client, |
const GladeCallbackTable * | table, | ||
bool | warn = true ) |
Connect callbacks to widgets.
You can repeatedly use this function, adding more callbacks to the widgets.
client | Pointer to the class that will be receiving the callbacks. |
table | Table linking widget, signal, callback function and optionally the pointer argument to the callback function. |
warn | Warn when widgets in the callback table are not found in the interface. |
void dueca::GtkGladeWindow::connectCallbacksAfter | ( | gpointer | client, |
const GladeCallbackTable * | table, | ||
bool | warn = true ) |
Connect callbacks to widgets.
Callbacks will be added as last. You can repeatedly use this function, adding more callbacks to the widgets.
client | Pointer to the class that will be receiving the callbacks. |
table | Table linking widget, signal, callback function and optionally the pointer argument to the callback function. |
warn | Warn when widgets in the callback table are not found in the interface. |
Access the widgets in this interface.
Most objects in the interface will be widgets; note that for GtkListStore and GtkTreeStore objects you need getObject().
wname | Widget name. |
Access anything in the interface file as objects.
name | Object name. |
Open the window.
By default, this uses the main window/widget.
widget | Optional, widget name to show other widget or window |
Close the window.
By default, this uses the main window/widget.
widget | Optional, widget name to hide other widget or window. |
bool dueca::GtkGladeWindow::fillOptions | ( | const char * | dcoclass, |
const char * | format, | ||
const char * | arrformat = NULL, | ||
const OptionMappings * | mapping = NULL, | ||
bool | warn = false ) |
Use the enum items in a DCO object to fill combobox tree models in the interface.
dcoclass | Object class |
format | Format string, to be written with sprintf, use "%s" to insert the element name, e.g., "mywidgets_%s" |
arrformat | Format string to be used when connecting to an array element, e.g., "mywidgets_%s_%02d" |
mapping | Optional mapping table, defining sets of member name + enum string, to representation, NULL-terminated. |
warn | If true, warn for DCO members that are not matched in the interface ID's. |
unsigned dueca::GtkGladeWindow::setValues | ( | CommObjectReader & | dco, |
const char * | format, | ||
const char * | arrformat = NULL, | ||
bool | warn = false ) |
Use a DCO object to set the state of the interface.
Parses the DCO object, create an ID based on the name and possibly an element number and tries to find matching elements in the interface based on the format, then pushes the DCO values in the corresponding widgets, if possible.
dco | Reader object |
format | Format string, to be written with sprintf, use "%s" to insert the element name, e.g., "mywidgets_%s" |
arrformat | Format string to be used when connecting to an array element, e.g. "mywidgets_%s_%02d" |
warn | Warn if either an element is not found, or widget and datatype do not match. |
unsigned dueca::GtkGladeWindow::getValues | ( | CommObjectWriter & | dco, |
const char * | format, | ||
const char * | arrformat = NULL, | ||
bool | warn = false ) |
Find the current state of the interface and push into a DCO object.
Parses the DCO object, create an ID based on the name and possibly an element number and tries to find matching elements in the interface based on the format, then reads the interface state and sets the values in the DCO.
dco | Writer object |
format | Format string, to be written with sprintf, use "%s" to insert the element name, e.g., "mywidgets_%s" |
arrformat | Format string to be used when connecting to an array element, e.g. "mywidgets_%s_%02d" |
warn | Warn if either an element is not found, or widget and datatype do not match. |
Initialize a text combobox with a given list or array of values.
name | Name of the combo box. |
values | Iterable (list, vector, etc.) of std::string (or string-like) objects, these need a "c_str()" method. |
Change position and size of the window.
p | Vector with offset and size elements, p[0] offset x. p[1] offset y, if either < 0, position hints are ignored. p[2] width, p[3] height, if either <= 0, size hints are ignored. Vector must have 2 or 4 elements. |