Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » GTK+
  • » How to add callback to tell owner something [RSS Feed]

#1 Nov. 30, 2005 14:21:34

rion10 (.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

How to add callback to tell owner something


How to tell the owner that something has done at one function in my class?Just like as following:main(){  TMyClass me;  me.DoSomething(); //not done yet if the function return  ...}void TMyClass::OnSomeEvent(){  if (something has done) {    //Add a callback to tell owner that the transfer is done, how to do it?  }}Thanks a lotSent from theGtk+ - Generalforum at Nabble.com:How to add callback to tell owner something_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

#2 Nov. 30, 2005 14:29:08

Tristan V.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

How to add callback to tell owner something


rion10 (sent by Nabble.com) wrote:How to tell the owner that something has done at one function in my class?
Just like as following:After reading your mail, I think you are looking for
GSignal documentation... here it is:http://developer.gnome.org/doc/API/2.0/gobject/gobject-Signals.htmlGSignal is complex, I sugest starting by finding an
example (in the GTK+ source for instance) and working from
there.

Cheers,
-Tristan

_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

#3 Nov. 30, 2005 14:41:47

rion10 (.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

How to add callback to tell owner something


could you give me a simple example, I'm a gtk+ beginner. Thanks.Sent from theGtk+ - Generalforum at Nabble.com:Re: How to add callback to tell owner something_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

#4 Nov. 30, 2005 14:56:02

Paul D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

How to add callback to tell owner something


On Wed, 2005-11-30 at 10:38 -0500, Tristan Van Berkom wrote:
> rion10 (sent by Nabble.com) wrote:
> > How to tell the owner that something has done at one function in my class?
> > Just like as following:
>
> After reading your mail, I think you are looking for
> GSignal documentation... here it is:
>
>http://developer.gnome.org/doc/API/2.0/gobject/gobject-Signals.html>
> GSignal is complex, I sugest starting by finding an
> example (in the GTK+ source for instance) and working from
> there.

if you are working in C++, forget GSignal; use libsigc++ and its very
very easy:

class MyClass : public sigc::trackable
{
...

sigc::signal<void,int> SomethingHappened;

void do_something () {
int what;
....
SomethingHappened (what);
}
};


class MyOtherClass : public sigc::trackable
{
...

void when_something_happens (int what) {
...
}
}

MyClass mine;
MyOtherClass myOther;

mine.SomethingHappened.connect (mem_fun (myOther,
&MyOtherClass::when_something_happens);

mine.do_something ();


please don't send email to me asking about this; the net is littered
with loads of sample code. and use gtkmm, not gtk+, your life will be
much easier.

--p


_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

#5 Nov. 30, 2005 15:11:20

Tristan V.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

How to add callback to tell owner something


rion10 (sent by Nabble.com) wrote:could you give me a simple example, I'm a gtk+ beginner. Thanks.Not really, like I said; GSignal is complex;

so heres a complex example:

First of all; you need to have a function to be called
by default on your class:

-----------------------------------
struct _MyObjectClass {
GObjectClass parent_class;
/* ... */

void (* event_happened) (MyObject *, gint);
}
-----------------------------------

Now, you must keep track of all the signals you declare
in your object, in C; usually you do this globally:
-----------------------------------
enum {
EVENT_HAPPENED,
/* ... other signals ... */
N_SIGNALS
}

guint my_object_signals;
-----------------------------------

Now you need to actually declare them in your
class initializer:
-----------------------------------
void
my_object_class_init (MyObjectClass *class)
{
/* ... */

/* Assign a base class handler for the "event_happened"
* signal
*/
class->event_happened = my_object_event_happened;

/* ... */

/* Declare the signal that returns VOID and
* takes one INT after its implicit OBJECT parameter.
*/
my_object_signals =
g_signal_new ("event-happened",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (MyObjectClass,
event_happened),
NULL, NULL,
g_cclosure_marshal_VOID__INT,
G_TYPE_NONE, 1, G_TYPE_INT);
}
-----------------------------------

Now you can fire the signal with:
-----------------------------------
g_signal_emit (G_OBJECT (my_object),
my_object_signals,
0, 5);
-----------------------------------

And clients of your object can connect to the
signal using g_signal_connect.

Now that I've written a short book this morning,
you'll have to delve into the API docs to figure
out more precicely all the meanings of all these
parameters to all these functions, some pointers
for you are "marshalers"
(g_cclosure_marshal_VOID__INT is a marshaler,
generated by glib-genmarshal)

and accumulators.. which arent used in this example
but are used to handle signal return values; usually
these are written by hand.

You shouldn't need to delve into GClosure to use the API.

Ummm and also... read this:http://developer.gnome.org/doc/API/2.0/gobject/index.htmlCheers,
-Tristan

_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

#6 Nov. 30, 2005 15:36:21

Martyn R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

How to add callback to tell owner something


On Wed, 2005-11-30 at 06:41 -0800, rion10 (sent by Nabble.com) wrote:
> could you give me a simple example, I'm a gtk+ beginner. Thanks.

If you want an example of how to do GObject coding, perhaps you would
benefit form looking at Gossip or some other Gnome application which use
GObject.

Gossip uses GObject quite extensively and there are copious examples to
choose from (mostly in libgossip sub directory). Some modules derive
from GtkComboBox, GtkTreeView and GtkButton and add Gossip specific
implementations and signals.

You can see the source here:http://cvs.gnome.org/viewcvs/gossip/One of the simpler examples might be:http://cvs.gnome.org/viewcvs/gossip/libgossip/gossip-event-manager.chttp://cvs.gnome.org/viewcvs/gossip/libgossip/gossip-event-manager.hTo see where this is used, look at:http://cvs.gnome.org/viewcvs/gossip/src/gossip-app.c--
Regards,
Martyn

_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

#7 Dec. 1, 2005 07:12:26

rion10 (.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

How to add callback to tell owner something


sorry, I can only use glib1.2, so I can't use g_signal_emit(), g_signal_connect(), etc functions. Is there any other way for this problem?ThanksSent from theGtk+ - Generalforum at Nabble.com:Re: How to add callback to tell owner something_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

  • Root
  • » GTK+
  • » How to add callback to tell owner something [RSS Feed]

Board footer

Moderator control

Enjoy the 27th of April
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support