Re: Pass more widgets as gpointer.

2009-04-22 Thread Vlad Volodin
Hello again
Well, yes, you are right about globals (I don't use them, but tried to
show one of the ways to resolve a task). But, I think, usage of many
structures also makes code hard readable. Just imagine, you have
Struct1 (with some objects), Struct2, Struct3 etc. There are too many
structures with single (or double) time useful. It isn't good too.
For example, I have a structure type with pointer members (it is just
a type), then I create an object and fill it's members with allocated
memory chunks. After that, I pass it as a callback variable (and use
it in code). But!!! how do I detach and free these chunks or free
other pointers? In handmade destructor? No. After callback
initialization? Again no, because this callback is using only pointer,
and after the object deallocation, it will point to dirty place. You
will also have to use global variables.
That is why, I prefer GObjects and manipulate with self variables,
constructors and destructors.

Best regards,
Vlad Volodin.

2009/4/21 Claudio Saavedra csaave...@igalia.com:
 On Tue, Apr 21, 2009 at 08:57:41AM +0400, Vlad Volodin wrote:
 Hello, Jens

 The other way is to make your widgets global. Especially, me? I use
 GOjects, and always pass self object. For example, I inherit  main
 window object from GtkWindow and later in widgets definition pass
 itself to callback. Also, you can use g_object_set_data for storing
 some useful pointers.

 Don't use global variables, they make the code hard to read and
 difficult to understand the context of the variables.


 Good luck

 2009/4/20 Jens Hansen jensh...@gmail.com:
  Hello All.
 
  I'm quite new to C, but have done some gtk programming in perl.
  I've been looking for answers on the web, and in various tutorials, without
  any luck.
  My question is how to pass more widgets as a gpointer, to a callback
  function. (in C )
 
  For instance if a OK button, has to read the state of three other
  widgets...
 
  In perl I would make an array of the widgets, and then pass the ref as the
  data argument to the callback. I cannot grasp how to do something like that
  in C.

 A typical approach to this is to create a FooContext structure that will
 hold pointers to all the elements that you need to use in your callback.
 You can instanciate it with g_new0() and later free it with g_free(). Be
 careful to hold object references and release them when you don't need
 them anymore.

 You could also use an array for this, but I prefer the structure
 approach, since you don't want to rely on the order you put the elements
 in the array later when you use them, removing/adding more elements you
 may need in the future can be a little cumbersome, etc.

 Claudio

 
  An example snippet would be really helpfull.
 
  Thx
 
  Jens
  ___
  gtk-app-devel-list mailing list
  gtk-app-devel-list@gnome.org
  http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
 
 ___
 gtk-app-devel-list mailing list
 gtk-app-devel-list@gnome.org
 http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Pass more widgets as gpointer.

2009-04-22 Thread Jens Hansen
Hi All.

Thanks for all ideas, to this problem. I figured out how to pass more
widgets in an array, which is IMHO the best way to do it. Just for
reference, the following snippet.

Packing the widgets pointers in the array
 GtkWidget * *data;
 data = malloc(sizeof(GtkWidget *)*3);
 data[0]=spinbutton;
 data[1]=combobox;
 data[2]=check_hidden
And unpacking them
GtkWidget * *array=(GtkWidget **)data;
Then you just need to type cast the elements of the array:
for instance
 gtk_combo_box_get_active((GtkComboBox *)array[1])
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Pass more widgets as gpointer.

2009-04-22 Thread Vlad Volodin
Hi, Jens

Yes, your way is good (thank you for a small code, maybe I will use it
in my projects). But, are you sure your way is safe?
You don't know the size of array (at the first),
where do you free the array of pointers itself (try g_malloc and
g_free, because it is GLIB :) ) (at the second).
And I think, your way isn't type-safe (at the third), because you
won't be sure that your element's type is needed.
Well, of course I have many questions and now answers :) I think, in
small projects your way is good (but you can also easily forget the
order of the elements). Maybe HashTables, or STL sets will be more
applicable.

What do you think about all of this?

Good luck in GTK programming :),
Vlad Volodin

2009/4/22 Jens Hansen jensh...@gmail.com:
 Hi All.

 Thanks for all ideas, to this problem. I figured out how to pass more
 widgets in an array, which is IMHO the best way to do it. Just for
 reference, the following snippet.

 Packing the widgets pointers in the array
  GtkWidget * *data;
  data = malloc(sizeof(GtkWidget *)*3);
  data[0]=spinbutton;
  data[1]=combobox;
  data[2]=check_hidden
 And unpacking them
 GtkWidget * *array=(GtkWidget **)data;
 Then you just need to type cast the elements of the array:
 for instance
  gtk_combo_box_get_active((GtkComboBox *)array[1])
 ___
 gtk-app-devel-list mailing list
 gtk-app-devel-list@gnome.org
 http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Hiding a GtkDialog and Cancel Callback

2009-04-22 Thread arne

Hello,
I Build my application with glade, also a dialog.

The Dialog is created from xml at startup, but not shown.

If I need the Dialog I show it and if i don't need it I hide it.

In the Callback of the Cancel button of the Dialog I just hide the Dialog.

But If I press the Cancel button,
sometimes the Dialog will be Destroyed (I think) , then I am not able to show 
it again.

Strange is, sometimes I get Gtk-Errors when I use the Dialogs Widgets after 
that, sometime not.
(Perhaps The Widgets just stay in memory and the widget-functions think they are OK, don't know how 
gtk exactly works)


Has someone an Idea?

Regards
   Arne


p.s. all that happens under win32
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Hiding a GtkDialog and Cancel Callback

2009-04-22 Thread Vlad Volodin
Hi, Arne

Well, I'm not sure the Dialog might be Destroyed. How are you call it?
Because if you call gtk_widget_destroy (dialog) this might happen. But
with GtkDialog from XML hm I'm not sure. Can you check the same
thing with other (not Cancel) buttons? And the other advice/suggestion
can you try to stop event driving after your callback (to stop do any
additional things after your click).

Best regards,
Vlad Volodin

2009/4/22 arne arne.pa...@gmx.de:
 Hello,
 I Build my application with glade, also a dialog.

 The Dialog is created from xml at startup, but not shown.

 If I need the Dialog I show it and if i don't need it I hide it.

 In the Callback of the Cancel button of the Dialog I just hide the Dialog.

 But If I press the Cancel button,
 sometimes the Dialog will be Destroyed (I think) , then I am not able to
 show it again.

 Strange is, sometimes I get Gtk-Errors when I use the Dialogs Widgets after
 that, sometime not.
 (Perhaps The Widgets just stay in memory and the widget-functions think they
 are OK, don't know how gtk exactly works)

 Has someone an Idea?

 Regards
   Arne


 p.s. all that happens under win32
 ___
 gtk-app-devel-list mailing list
 gtk-app-devel-list@gnome.org
 http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Pass more widgets as gpointer.

2009-04-22 Thread Dov Grobgeld
As I've said in he past, I believe the best thing is to sub-class GtkWindow
and then make all the pointers you want to pass around members of your new
class. Conceptually this looks like:

class MyWindow : GtkWindow {
GtkWidget *w_label;
GtkWidget *w_button;
GtkWidget *w_tooltip;
}

:
MyWindow *w_window = my_window_new();
g_signal_connect(w_button, clicked, G_CALLBACK(cb_button), w_window);
:
int cb_button(GtkWidget *widget,
  GtkButtonEvent *event,
  gpointer userdata)
   {
MyWindow *self = (MyWindow*)self;

   gtk_tool_tip...(self-w_tooltip, ...);
   gtk_label_set_text(self-w_label, foo);
   }


I hope you get the idea. The problem with this approach though is that it is
a bit of an effort quite to subclass Gtk in C, (in contrast to gtkmm, perl,
python, javascript in which it has been nicely mapped to the native objects,
not to talk about vala where a GObject is native). That's why I'm using gob2
whenever I'm writing C. It makes this technique as natural as in any other
language that I mentioned.

Regards,
Dov

2009/4/22 Vlad Volodin vest...@gmail.com

 Hi, Jens

 Yes, your way is good (thank you for a small code, maybe I will use it
 in my projects). But, are you sure your way is safe?
 You don't know the size of array (at the first),
 where do you free the array of pointers itself (try g_malloc and
 g_free, because it is GLIB :) ) (at the second).
 And I think, your way isn't type-safe (at the third), because you
 won't be sure that your element's type is needed.
 Well, of course I have many questions and now answers :) I think, in
 small projects your way is good (but you can also easily forget the
 order of the elements). Maybe HashTables, or STL sets will be more
 applicable.

 What do you think about all of this?

 Good luck in GTK programming :),
 Vlad Volodin

 2009/4/22 Jens Hansen jensh...@gmail.com:
  Hi All.
 
  Thanks for all ideas, to this problem. I figured out how to pass more
  widgets in an array, which is IMHO the best way to do it. Just for
  reference, the following snippet.
 
  Packing the widgets pointers in the array
   GtkWidget * *data;
   data = malloc(sizeof(GtkWidget *)*3);
   data[0]=spinbutton;
   data[1]=combobox;
   data[2]=check_hidden
  And unpacking them
  GtkWidget * *array=(GtkWidget **)data;
  Then you just need to type cast the elements of the array:
  for instance
   gtk_combo_box_get_active((GtkComboBox *)array[1])
  ___
  gtk-app-devel-list mailing list
  gtk-app-devel-list@gnome.org
  http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
 
 ___
 gtk-app-devel-list mailing list
 gtk-app-devel-list@gnome.org
 http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


GtkDialog created from GtkBuilder (glade 3) isn't returning a gtk.ResponseType

2009-04-22 Thread Ethan Baldridge
I can't figure out what I'm doing wrong. I'm trying to make a login
dialog - I created it in Glade-3 making sure to use a GtkDialog
template.

But the result is always 0, which isn't in the ResponseType enum at all.

 

def login(self):

 
self.builder.add_from_file(transmission.glade)

dialog =
self.builder.get_object(login)

#okButton =
self.builder.get_object(button1)

#closeButton =
self.builder.get_object(button2)

 
window.set_default_response(gtk.RESPONSE_OK)

self.builder.connect_signals(self)

result = dialog.run()



uname =
self.builder.get_object(username).get_text()

passwd =
self.builder.get_object(password).get_text()

dialog.destroy()

return result,  uname,  passwd;

 

Thanks in advance for any help!

-Ethan

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


RE: GtkDialog created from GtkBuilder (glade 3) isn't returning agtk.ResponseType

2009-04-22 Thread Ethan Baldridge
Never mind - I spent two hours looking at this and then realized I
needed to set a Response ID on the button itself. I thought it defaulted
for the stock buttons.

-Original Message-
From: gtk-app-devel-list-boun...@gnome.org
[mailto:gtk-app-devel-list-boun...@gnome.org] On Behalf Of Ethan
Baldridge
Sent: Wednesday, April 22, 2009 4:30 PM
To: gtk-app-devel-list@gnome.org
Subject: GtkDialog created from GtkBuilder (glade 3) isn't returning
agtk.ResponseType

I can't figure out what I'm doing wrong. I'm trying to make a login
dialog - I created it in Glade-3 making sure to use a GtkDialog
template.

But the result is always 0, which isn't in the ResponseType enum at all.

 

def login(self):

 
self.builder.add_from_file(transmission.glade)

dialog =
self.builder.get_object(login)

#okButton =
self.builder.get_object(button1)

#closeButton =
self.builder.get_object(button2)

 
window.set_default_response(gtk.RESPONSE_OK)

self.builder.connect_signals(self)

result = dialog.run()



uname =
self.builder.get_object(username).get_text()

passwd =
self.builder.get_object(password).get_text()

dialog.destroy()

return result,  uname,  passwd;

 

Thanks in advance for any help!

-Ethan

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Hiding a GtkDialog and Cancel Callback

2009-04-22 Thread arne

hello,

 Well, I'm not sure the Dialog might be Destroyed. How are you call it?
It is created with with the whole application in my glade file with 
glade_xml_new(),
but it is not shown because I just gtk_show_all() my other window.

 Because if you call gtk_widget_destroy (dialog) this might happen.
The Only function effecting the dialog-widget gtk_widget_show(dialog) and 
gtk_widget_hide(dialog)

 with GtkDialog from XML hm I'm not sure. Can you check the same
 thing with other (not Cancel) buttons?
Ok, thats a good Idea, i will check it.

And the other advice/suggestion
 can you try to stop event driving after your callback (to stop do any
 additional things after your click).
Hm, how could I stop event driving, and what will be the effect (interrupting 
gtk_main)?

Best Regards
   Arne
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Pass more widgets as gpointer.

2009-04-22 Thread Freddie Unpenstein
You can use a few tricks to help manage these one-shot constructs...

One that I used quite a while ago, was a wrapper around a simple array that 
stores array size and free functions for each member, so a simple free 
function can rip through and clear everything out.  It's good as long as you're 
not trying to store too many items (it is a little wasteful).


gpointer oneshot_new(gint n) {
gpointer data = g_malloc(sizeof(GtkWidget *)*((n)*2+1));
data[0] = GINT_TO_POINTER(n);
return data;
}

void oneshot_free(gpointer data) {
gint i, count = GPOINTER_TO_INT(data[0]);
for (i = 1; i  count*2; i+=2) {
if (data[i]  data[i+1]) data[i+1](data[i]);
}
g_free(data);
}

#define oneshot_set(arr,n,data,unref) arr[n*2+1]=data,arr[n*2+2]=unref
#define oneshot_set_with_unref(arr,n,data) oneshot_set(arr,n,data,g_unref)
#define oneshot_set_with_free(arr,n,data) oneshot_set(arr,n,data,g_free)
#define oneshot_get(arr,n) arr[n*2+1]

#define oneshot_set_widget(arr,n,data) oneshot_set_with_unref(arr,n,data)
#define oneshot_get_widget(arr,n) ((GtkWidget*)(oneshot_get(arr,n)))
// can be helpful to add a type assertion into the oneshot_set_widget 
definition, etc.


Well, you get the idea.  I'm sure I've messed up the type casting and probably 
a few other bits and pieces in there somewhere, I've been working mostly in 
HLL's just lately, and haven't tested that at all.  But it's one more idea to 
keep in your bag of tricks.


Fredderic
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Using By-Value Compound Getters (Re: gtk_widget_get_allocation)

2009-04-22 Thread Steve Frécinaux

Havoc Pennington wrote:


Not sure we need to block merge of get_allocation() on this major
other patch to change the entire guideline. Changing the entire
guideline will be a giant change and giant patch anyhow, so changing
get_allocation() again will be a drop in the bucket.


Can't such big repetitive changes be addressed through some user script 
the way 2to3.py does for python2 - python3 constructs for, say, the 
planned 3.0 ABI breakage ?

___
gtk-devel-list mailing list
gtk-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-devel-list


Re: Using By-Value Compound Getters (Re: gtk_widget_get_allocation)

2009-04-22 Thread Cody Russell
On Wed, 2009-04-22 at 11:37 +0200, Steve Frécinaux wrote:
 
 Can't such big repetitive changes be addressed through some user
 script 
 the way 2to3.py does for python2 - python3 constructs for, say, the 
 planned 3.0 ABI breakage ?

Yes, I talked about this in my last email.  There's a rewriter that will
attempt to fix up C code for the transition.

http://github.com/bratsche/clang/tree/gtkrewriter


___
gtk-devel-list mailing list
gtk-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-devel-list


Re: GtkPlug not chaining up to GtkWindow's keys_changed handler?

2009-04-22 Thread Federico Mena Quintero
On Sat, 2009-04-18 at 17:22 -0400, Yu Feng wrote:

 In GTK 2.14.4, GtkPlug does not chain up to GtkWindow's keys_changed
 handler. (gtkplug.c:1043 and gtkwindow.c:7937)
 
 The effect is that the key hash in the 'gtk-window-key-hash' data member
 of the window is not updated whenever the mnemonic keys are changed, and
 any newly associated mnemonic keys are ignored.
 
 Are there any particular reasons for this behavior or it is an honest
 typo?

It could be a typo/oversight/etc.  This is not the first time that
GtkPlug has had a bug due to failing to sync up with GtkWindow.

Do you have a little reproducible test case for this problem?

  Federico

___
gtk-devel-list mailing list
gtk-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-devel-list


Re: GtkPlug not chaining up to GtkWindow's keys_changed handler?

2009-04-22 Thread Yu Feng
Hi Federico,
On Wed, 2009-04-22 at 21:20 -0500, Federico Mena Quintero wrote:
 On Sat, 2009-04-18 at 17:22 -0400, Yu Feng wrote:
 
  In GTK 2.14.4, GtkPlug does not chain up to GtkWindow's keys_changed
  handler. (gtkplug.c:1043 and gtkwindow.c:7937)
  
  The effect is that the key hash in the 'gtk-window-key-hash' data member
  of the window is not updated whenever the mnemonic keys are changed, and
  any newly associated mnemonic keys are ignored.
  
  Are there any particular reasons for this behavior or it is an honest
  typo?
 
 It could be a typo/oversight/etc.  This is not the first time that
 GtkPlug has had a bug due to failing to sync up with GtkWindow.
 
 Do you have a little reproducible test case for this problem?
 
Sorry I don't have a 'little' test case.

I discovered the problem when writing a panel applet with a MenuBar in
it(Global Menu) The problem can be reproduced by modifying the mnemonic
keys of the menu items.

If it is needed I can come up with one but it may take some time.


Yu
   Federico
 

___
gtk-devel-list mailing list
gtk-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-devel-list