how to access a widget ?
Hello, I have made a program which shows a table with buttons, created like this .. for (i=0; i vertical - 1; i++) { . etc. ...etc. etc... for (j=1; j vertical; j++) { if (i j) { button = gtk_button_new (); gtk_button_set_label ( (GtkButton *) button , ); gtk_table_attach_defaults (GTK_TABLE (table), button , 1 + j, 2 + j, 1 + i, 2 + i); g_signal_connect (GTK_OBJECT(button), clicked, (GCallback) toggle_location_event, GINT_TO_POINTER (sum(i)+j)); } } .etc } I have a call-back function toggle_location_event which can change the text of the button which is pressed. Now I also want to change the text of a button that is not pressed ( in toggle_location_event). I know the location i and j of that button, but I don't know how to change the text because I don't have the object-name myself (because I use button = gtk_button_new () lots of times to create more widgets which don't have unique names). How can I retrieve the widget from the known location so I can change the text on the button ? Thanks in advance, Edward ___ gtk-list mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-list
Re: how to access a widget ?
On Sun, 2004-08-29 at 22:54, edward hage wrote: Hello, I have made a program which shows a table with buttons, created like this .. for (i=0; i vertical - 1; i++) { . etc. ...etc. etc... for (j=1; j vertical; j++) { if (i j) { button = gtk_button_new (); gtk_button_set_label ( (GtkButton *) button , ); gtk_table_attach_defaults (GTK_TABLE (table), button , 1 + j, 2 + j, 1 + i, 2 + i); g_signal_connect (GTK_OBJECT(button), clicked, (GCallback) toggle_location_event, GINT_TO_POINTER (sum(i)+j)); } } .etc } I have a call-back function toggle_location_event which can change the text of the button which is pressed. Now I also want to change the text of a button that is not pressed ( in toggle_location_event). I know the location i and j of that button, but I don't know how to change the text because I don't have the object-name myself (because I use button = gtk_button_new () lots of times to create more widgets which don't have unique names). How can I retrieve the widget from the known location so I can change the text on the button ? You can cache a matrix with your buttons and the last changed buttons in a structure[1] and then send this structure[2] as user data (in the callback). 1 - struct buttons_matrix { GtkButtons * table[][]; gint last_x; gint last_y; }; 2 - struct change_button { struct buttons_matrix *m; gint x; gint y; }; So your problem resolves in two issues: a) you need a central structure for holding your data (maybe a GObject?); b) you may need to create auxiliar structures for sending multiple arguments trough callbacks. ___ gtk-list mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-list
GObject tutorial next version
This covers everything except signals, which is the last thing to do. Warning currently its in plain text format since I haven't gotten around to fancifying it yet, however it WILL be prettied up. I'd appreciate feedback on technical, spelling, grammar, or style points. Cheers, Ryan GObject Tutorial Copyright Ryan McDougall (2004) Purpose - This document is used for two purposes: one is as a tutorial on learning Glib's GObject Type System, and the other is a step-by-step how-to for using the system. The tutorial proceeds from the point of view of designing an Object-Oriented type system in C, where GObject is the presumed solution. It is thought that this manner of presenting the material will better justify the form that the library currently takes, and help explain the steps required use it. The how-to is presented after the tutorial in a step-by-step, matter-of-fact, form with no explanations, so that it will be useful to the merely pragmatic programmer. Audience - The tutorial is meant for those who are familiar with OO concepts, but are just beginning to learn GObject or GTK+. I will assume previous knowledge of an OO'ed language, and a basic command of C. Motivation - While writing an OO system in a language that doesn't support it may sound like a foolish exercise in masochism to some, there are indeed some good reasons why one would want to do such a thing. While I will not try to justify the authors' decision, and will assume that the reader has some good reason for using Glib, I will point out some important features of the system: - C is the most portable programming language - system is fully dynamic, so types can be added at run-time - system is more extensible than a standard language, so new features can be added quickly In OO languages object oriented features and abilities are a matter of syntax. However since C doesn't support OO natively, the GObject system has to graft on object orientation manually. Often this requires some tedious, or occasionally mystifying things in order to accomplish this goal. It is my intention to enumerate all the necessary steps and incantations necessary to make this process work; and hopefully even elaborate on what it means to your program. 1. Creating a single Object with no Inheritance Design - In OO, an object consists of two types of members bound under one object reference: data fields and method functions. One way to accomplish this in C is with C structs, where data fields are regular public members and methods are implemented as function pointers. This implementation however has several serious flaws: awkward syntax, type-safety, and lack of encapsulation to name a few. However there is more practical problem -- it is a serious waste of space. Every instance object needs a 4-byte pointer for each of its methods; all of which will be identical class wide, and thus totally redundant. That is to say if we have a class with only four methods, and a program with 1000 instantiation objects of that class, we are wasting almost 16KB. Clearly we'd be better off memory-wise if we only kept one copy of those pointers in a table that could be accessed by any object in its class. Such as table is called a virtual method table (vtable), and one copy is kept in memory by the GObject system for each class. When you want to call a virtual method, you must ask the system to find the object's vtable; which as we have said above is just a struct with function pointers. With this you can now dereference the pointer and thus call the method. definition We will call these two types instance struct and class struct, and instantiations of those structs instance objects and class objects respectively. The combination of the two structs as a conceptual unit will be called a class and an instantiation of that class will be called an object. /definition The reason why functions given by this process are called virtual is because it dynamically looks up the appropriate function pointer at run-time and thus allows inherited classes to override a class method (by simply assigning a new function pointer to the corresponding entry in the vtable). This allows derived objects to behave correctly when cast to a base class, and corresponds to what we know of virtual methods in C++. convention Although this saves space and allows virtual methods, it also means that methods can no longer be tied syntactically to an object via the dot operator.Therefore we will use the convention that class methods will be called on objects as follows: NAMESPACE_TYPE_METHOD (OBJECT*, PARAMETERS) /convention Non-virtual methods will be implemented inside a regular C function, and virtual functions will be implemented by calling the appropriate method from the vtable inside a regular C function. Private methods will be implemented within the source file, but not be exported via the header file. notice While OO normally uses
Re: g_value_new Macro?
On Aug 26, 2004, at 10:56 PM, Ryan McDougall wrote: Perhaps its my ignorance of GValue, why is memory allocation GValue's problem, thus necessitating an unset function. Shouldn't I dealloc my own pointers? GValues are used in code that runs a *lot* (marshaling code for signals, property mechanism, etc), and need to be fast. allocation on the stack is far faster than allocation on the heap, and you don't have to worry about it failing (it happens automatically, even). thus, the GValue API, like the GtkTreeIter API, is designed to allow you to use values on the stack. if it's on the stack, you're not going to be calling free() on it, so you need some way to release any resources it may contain; hence g_value_unset(), which brackets nicely with g_value_set_*(). For some internal code, I prefer to pass a heap allocated GValue pointer to some unnecessary copies of stack alloc'd GValues[...] unnecessary copies of stack alloc'd GValues? could you elaborate here? from what i can see, you always pass GValues by reference, not by value. why would they be copied? , so I use it outside of the tutorial (which can be changed). Basically I don't see any reason *not* to add it once the g_new0 bug is fixed. the only place where i see heap-allocated GValues being necessary is in something like a collection container, where you're going to hang on to them for longer than the stack frame will be alive. in that case, g_new0() by itself is sufficient, but g_value_new() would be nice for readability. -- elysse (pregnant): are your hands cold? me: uh, i suppose so. elysse: will you put them on me? ___ gtk-list mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-list
Re: g_value_new Macro?
On 27/08/04 10:56, Ryan McDougall wrote: I spotted where the docs say it must be zero init'd, but I can't see in the source *why* thats needed. I guess so you don't call init on a value that has already been init'd without calling reset first. Well, the code in g_value_init() is checking whether the type field of the GValue is zeroed out. It is right there in the code. Perhaps its my ignorance of GValue, why is memory allocation GValue's problem, thus necessitating an unset function. Shouldn't I dealloc my own pointers? A GValue can be used to hold an arbitrary value, including things like strings and GObjects. In the case of a string, the GValue holds an allocated string so not calling g_value_unset() will lead to the string being leaked. In the case of a GObject, you will get a reference leak. Tommi mentioned this in his reply to you. If the GValue is allocated on the stack, you only need to g_value_unset() it. If you've allocated it on the heap, you will need to free the GValue itself. For some internal code, I prefer to pass a heap allocated GValue pointer to some unnecessary copies of stack alloc'd GValues, so I use it outside of the tutorial (which can be changed). Basically I don't see any reason *not* to add it once the g_new0 bug is fixed. When passing a GValue into a function you call, you'd usually pass it as value. Note that this won't work if you want the value to last longer than the scope you defined it in. In practice, this isn't a problem for the existing use cases (also, GValue isn't really that good a choice for long term storage). [also note that doing a straight copy of a GValue is an error in most cases. If you unset one copy, it will invalidate the other]. James. -- Email: [EMAIL PROTECTED] WWW: http://www.jamesh.id.au/ ___ gtk-list mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-list
Can panel applets be threaded?
I've seen the reference to g_thread_enter() and leave() for general GTK programming. In a panel applet, there doesn't appear to be such a place to make these calls around. Since none of the standard gnome desktop applets seem to be threaded, I wonder if this is considered an option. Any thoughts? ___ gtk-list mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-list
About Hiding Widget
Hai All experts, I have a big problem in hiding a widget, I use gtk_widget_hide(window) method, I donno i will not hide the window always, I mean it works some times and it does'nt .. I donno why? Pl guide me in this regard. This is one of the biggest problem in my application. My application requires dynamic hide and show of window , like the window should show only when the phone is offhook.. Thanks in advance. Srinivas Kandagatla Embedded Linux Engineer. Puretek Inc. Taiwan. ___ gtk-list mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-list