On 05/20/13 08:52, bat wrote:
> is there a way to send the result(s) of a callback function back
> to 'main' in a way that is independent of these widget things so
> that the info can be used by another callback function?
There's a few ways to go.
The easiest is to use globals that both the callbacks and main()
have access to. But globals are considered bad programming practice,
since it makes modules dependent on globals, and thereby less 'modular'.
The more common way (but involves some work on your part)
is to set up your callbacks to have userdata that points to
this data you want main() and the widgets to have access to.
This way the widgets can access the data through the userdata
instead of through a global.. this makes the widget more modular
(so that it can be used in other applications, or can be instanced
so as to refer to different data, instead of just of fixed globals)
A more flexible approach (for very large apps) is to send messages
between widgets, avoiding callback data and pointers entirely.
I like to use text messages, which allows one to easily see messages
flying back and forth, and lets one make 'scripts' to trigger GUI events,
and also to have ascii config files that allow users to customize menus
and buttons, and make custom text messages send when those buttons/menus are hit.
It's common to make an "Application" class in which all widgets and windows
exist, and has all global data inside of it. This way you can have several
instances of the application class, so that main() can access data through
the application class, as well as the widgets.