Re: Problem swapping GtkScrolledWindow contents on the fly

2010-01-13 Thread Andrew Wood

Still getting strange results with this.

Ive posted a skeleton app at  www.simple.org/TCSAdminGTK.tar which 
is a single source file which can be comiled with g++ ./main.cpp 
`pkg-config --cflags --libs libgnome-2.0 libgnomeui-2.0 libglade-2.0`


When you click one of the options on the left the contents changes on 
the right. At present only 'General' and 'Calls' are implemented. As you 
can see the first time you click one of these the widgets show correctly 
but the second time you click it they don't but you get no error on the 
console either.



The guts of the issue are contained in the functions showGeneralPage() 
and showCallsPage()



The closest explaination Ive been able to find is that the call to

gtk_container_remove (GTK_CONTAINER 
(rightpanescrollview),gtk_bin_get_child(GTK_BIN(rightpanescrollview)));


is deleting the widgets as well as just removing them from the 
container, but theres no error to suggest this, and I would have thought 
the calls to gtk_widget_ref(callspage) or gtk_widget_ref(generalpage) 
would have prevented this.


There must be something very simple Im overlooking here. Any ideas?

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


gtk_builder_add_from_file error handling

2010-01-13 Thread Gabriele Greco
I just found that with a builder file with a syntax error my app crashed
with:

*** glibc detected *** ./packager: double free or corruption (out):
0x09aa33d0 ***

I think I'm using gtkbuilder error handling in the right way and
documentation does not suggest my how to use it:

GError *err = NULL;
if (!gtk_builder_add_from_file(builder_, myfile.xml, erro)) {

}

-- 
Ing. Gabriele Greco, DARTS Engineering
Tel: +39-0105761240  Fax: +39-0105760224
s-mail: Via G.T. Invrea 14 - 16129 GENOVA (ITALY)
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


gtk_builder_add_from_file error handling

2010-01-13 Thread Gabriele Greco
Sorry last message was sent by accident pushing an hotkey while editing...

This should be the complete version of my question:


I just found that with a builder file with a syntax error my app crashed
with:

*** glibc detected *** ./packager: double free or corruption (out):
0x09aa33d0 ***

I think I'm using gtkbuilder error handling in the right way and
documentation does not suggest my how to use it:

GError *err = NULL;
if (!gtk_builder_add_from_file(builder_, myfile.xml, err)) {
   if (err) {
  cerr  builder load fail:   err-message  '\n';
  g_free(err); // commenting this solves the crash but other gtk apis
  // and examples I've found always free error handling
pointers
   }
   else
  cerr  builder load fail, unknown error\n;

   return false;
}

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


Re: gtk_builder_add_from_file error handling

2010-01-13 Thread Florian Müllner
On Wed, 2010-01-13 at 11:52 +0100, Gabriele Greco wrote:
 GError *err = NULL;
 if (!gtk_builder_add_from_file(builder_, myfile.xml, err)) {
if (err) {
   cerr  builder load fail:   err-message  '\n';
   g_free(err); // commenting this solves the crash but other gtk apis
   // and examples I've found always free error handling
 pointers

I don't know gtkmm, but at least in C GErrors are freed with
g_error_free(err).
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Problem swapping GtkScrolledWindow contents on the fly

2010-01-13 Thread David Nečas
On Wed, Jan 13, 2010 at 10:33:07AM +, Andrew Wood wrote:
 Still getting strange results with this.

 Ive posted a skeleton app at  www.simple.org/TCSAdminGTK.tar which  
 is a single source file which can be comiled with g++ ./main.cpp  
 `pkg-config --cflags --libs libgnome-2.0 libgnomeui-2.0 libglade-2.0`

 When you click one of the options on the left the contents changes on  
 the right. At present only 'General' and 'Calls' are implemented. As you  
 can see the first time you click one of these the widgets show correctly  
 but the second time you click it they don't but you get no error on the  
 console either.


 The guts of the issue are contained in the functions showGeneralPage()  
 and showCallsPage()


 The closest explaination Ive been able to find is that the call to

 gtk_container_remove (GTK_CONTAINER  
 (rightpanescrollview),gtk_bin_get_child(GTK_BIN(rightpanescrollview)));

 is deleting the widgets as well as just removing them from the  
 container, but theres no error to suggest this, and I would have thought  
 the calls to gtk_widget_ref(callspage) or gtk_widget_ref(generalpage)  
 would have prevented this.

 There must be something very simple Im overlooking here. Any ideas?

Indeed, the children get removed from the container when the page is
removed so the next time it's show it's empty.  This is somehow caused
by the widget being constructed by libglade because if you construct
it manually, it does no happen.

I can't help with libglade and it's already obsolete...

BTW please don't use things like gtk_widget_ref() that were deprectated
many years ago.

Yeti

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


Re: gtk_builder_add_from_file error handling

2010-01-13 Thread Gabriele Greco
 GError *err = NULL;
  if (!gtk_builder_add_from_file(builder_, myfile.xml, err)) {
 if (err) {
g_free(err); // commenting this solves the crash but other gtk apis

 I don't know gtkmm, but at least in C GErrors are freed with
 g_error_free(err).


You are obviously right. I always used g_free() to free errors, my fault.
I've grepped tons of sources and I had everywhere the code bugged, then I
googled around to search some more examples and I've found there are a lot
of other sources in the net where a GError is freed with g_free, I think
improving the documentation of the functions that use a GError as input
parameter may help programmers do not write wrong code in this situation.

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


Re: gtk_builder_add_from_file error handling

2010-01-13 Thread David Nečas
On Wed, Jan 13, 2010 at 04:48:29PM +0100, Gabriele Greco wrote:
 ... I've found there are a lot
 of other sources in the net where a GError is freed with g_free, I think
 improving the documentation of the functions that use a GError as input
 parameter may help programmers do not write wrong code in this situation.

The proper handling of GErrors is described in great detail in the
GError documentation.

I don't think it is reasonable to explain this in the documentation of
every function that uses GError to report errors as there are almost 80
of them just in Gtk+ (and over 400 in GLib, and many more elsewhere).

Yeti

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


Re: gtk_builder_add_from_file error handling

2010-01-13 Thread Gabriele Greco


 The proper handling of GErrors is described in great detail in the
 GError documentation.

 I don't think it is reasonable to explain this in the documentation of
 every function that uses GError to report errors as there are almost 80
 of them just in Gtk+ (and over 400 in GLib, and many more elsewhere).


I think, and I'm used to see in almost every framework documentations, that
every time a function allocates something that the API user must free
himself the documentation should explicitly say so. Documentation should be
redundant when it may cause errors the fact it is not.

This is the case of GError and for
instance gtk_ui_manager_add_ui_from_file/string
and gtk_builder_add_from_file/string.

It's not a case that in UI toolkit debates one of the most common criticism
to GTK is the lack of documentation.

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


Re: gtk_builder_add_from_file error handling

2010-01-13 Thread Emmanuele Bassi
On Wed, 2010-01-13 at 17:18 +0100, Gabriele Greco wrote:
 
 
  The proper handling of GErrors is described in great detail in the
  GError documentation.
 
  I don't think it is reasonable to explain this in the documentation of
  every function that uses GError to report errors as there are almost 80
  of them just in Gtk+ (and over 400 in GLib, and many more elsewhere).
 
 
 I think, and I'm used to see in almost every framework documentations, that
 every time a function allocates something that the API user must free
 himself the documentation should explicitly say so. Documentation should be
 redundant when it may cause errors the fact it is not.

that's why gtk-doc creates cross-links for each data type.

 This is the case of GError and for
 instance gtk_ui_manager_add_ui_from_file/string
 and gtk_builder_add_from_file/string.
 
 It's not a case that in UI toolkit debates one of the most common criticism
 to GTK is the lack of documentation.

the lack of documentation refers to empty (or FIXME) sections of the
API reference and to high-level documentation. the fact that a non-NULL
GError must be freed using the corresponding GError free function is
documented in great detail and that documentation linked by every
function in a gtk-doc-generated API reference and part of the behavior
of the framework.

the API reference does not gain anything by adding:

  @error: a return location for a #GError or %NULL.
+   Use g_error_free() to free the #GError if @error is not %NULL
+   after calling this function

for each and every GError-using function. you'd just be writing
redundant documentation.

if you can't be bothered to follow through a link then you're probably
using g_free() on every single data structure, which yields
interesting results when done on, say, GString or worse GObject.

ciao,
 Emmanuele.

-- 
W: http://www.emmanuelebassi.name
B: http://blogs.gnome.org/ebassi

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


Re: gtk_builder_add_from_file error handling

2010-01-13 Thread David Nečas
On Wed, Jan 13, 2010 at 05:18:04PM +0100, Gabriele Greco wrote:
 
 I think, and I'm used to see in almost every framework documentations, that
 every time a function allocates something that the API user must free
 himself the documentation should explicitly say so. Documentation should be
 redundant when it may cause errors the fact it is not.
 
 This is the case of GError and for
 instance gtk_ui_manager_add_ui_from_file/string
 and gtk_builder_add_from_file/string.

I'm sorry but this is nonsense.

1) The problem was not whether you had to free the error or not.  You
just used the wrong function to free it.

Very few data structures used in GLib can be freed by mere g_free(), the
only common exception is the raw C string -- but that's not a GLib data
type.  GErrors are no exception in that.

2) GError is the try/catch mechanism (well, a rough approximation of
that it permitted by C semantics).  You must read the GError
documentation to use it properly.

If you don't know how try/catch works in any language, the only thing
you can do is to ignore the possibility of failure.  That's exactly what
passing NULL for the error acomplishes with GLib and it works
flawlessly.

Yeti

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


Draggable Targets

2010-01-13 Thread Tim Corio
I have another newbie question.  I'm grateful that this list has been
very indulgent of my recent questions.

I want to let the user place a target (either a cross-hair or a circle)
on an image and then be able to drag it to a new location.  This seems
like common functionality that GTK+ might directly support.  How do I
implement this functionality?

The underlying image is in a Drawing Area which is inside a Scrolled
Window.

My first thought was to place a small image (of the cross-hair) on top
of the image.  I would need to specify the x/y offset of the target
image inside the Scrolled Window, but I don't see how that is supported
in GTK+,

My second thought is to draw the target directly in the Drawing Area,
then redraw then create the drag effect in the motion_event callback by
redrawing the background where the target used to be, and drawing the
target where is now.

Thanks,
Tim


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


Re: Problem swapping GtkScrolledWindow contents on the fly

2010-01-13 Thread Andrew Wood

Great thanks


On 13 Jan 2010, at 11:05, David Nečas wrote:


On Wed, Jan 13, 2010 at 10:33:07AM +, Andrew Wood wrote:

Still getting strange results with this.

Ive posted a skeleton app at  www.simple.org/TCSAdminGTK.tar  
which

is a single source file which can be comiled with g++ ./main.cpp
`pkg-config --cflags --libs libgnome-2.0 libgnomeui-2.0 libglade-2.0`

When you click one of the options on the left the contents changes on
the right. At present only 'General' and 'Calls' are implemented.  
As you
can see the first time you click one of these the widgets show  
correctly
but the second time you click it they don't but you get no error on  
the

console either.


The guts of the issue are contained in the functions  
showGeneralPage()

and showCallsPage()


The closest explaination Ive been able to find is that the call to

gtk_container_remove (GTK_CONTAINER
(rightpanescrollview 
),gtk_bin_get_child(GTK_BIN(rightpanescrollview)));


is deleting the widgets as well as just removing them from the
container, but theres no error to suggest this, and I would have  
thought

the calls to gtk_widget_ref(callspage) or gtk_widget_ref(generalpage)
would have prevented this.

There must be something very simple Im overlooking here. Any ideas?


Indeed, the children get removed from the container when the page is
removed so the next time it's show it's empty.  This is somehow caused
by the widget being constructed by libglade because if you construct
it manually, it does no happen.

I can't help with libglade and it's already obsolete...

BTW please don't use things like gtk_widget_ref() that were  
deprectated

many years ago.

Yeti


__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
__


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

Re: Problem swapping GtkScrolledWindow contents on the fly

2010-01-13 Thread Andrew Wood
Just tried it with a simple vbox and label created manually and am 
getting exactly the same problem so its not specific to libglade



David Nečas wrote:

On Wed, Jan 13, 2010 at 10:33:07AM +, Andrew Wood wrote:
  

Still getting strange results with this.

Ive posted a skeleton app at  www.simple.org/TCSAdminGTK.tar which  
is a single source file which can be comiled with g++ ./main.cpp  
`pkg-config --cflags --libs libgnome-2.0 libgnomeui-2.0 libglade-2.0`


When you click one of the options on the left the contents changes on  
the right. At present only 'General' and 'Calls' are implemented. As you  
can see the first time you click one of these the widgets show correctly  
but the second time you click it they don't but you get no error on the  
console either.



The guts of the issue are contained in the functions showGeneralPage()  
and showCallsPage()



The closest explaination Ive been able to find is that the call to

gtk_container_remove (GTK_CONTAINER  
(rightpanescrollview),gtk_bin_get_child(GTK_BIN(rightpanescrollview)));


is deleting the widgets as well as just removing them from the  
container, but theres no error to suggest this, and I would have thought  
the calls to gtk_widget_ref(callspage) or gtk_widget_ref(generalpage)  
would have prevented this.


There must be something very simple Im overlooking here. Any ideas?



Indeed, the children get removed from the container when the page is
removed so the next time it's show it's empty.  This is somehow caused
by the widget being constructed by libglade because if you construct
it manually, it does no happen.

I can't help with libglade and it's already obsolete...

BTW please don't use things like gtk_widget_ref() that were deprectated
many years ago.

Yeti


__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
__
  


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

Re: Problem swapping GtkScrolledWindow contents on the fly

2010-01-13 Thread David Nečas
On Wed, Jan 13, 2010 at 08:26:57PM +, Andrew Wood wrote:
 Just tried it with a simple vbox and label created manually and am  
 getting exactly the same problem so its not specific to libglade

If I do this:

--- main.cpp.orig   2010-01-13 22:36:25.0 +0100
+++ main.cpp2010-01-13 22:36:38.0 +0100
@@ -116,10 +116,10 @@
g_print(Showing General Page\n);
if (generalpageinitialised==false)
{
-   generalpage= glade_xml_get_widget(generalpagexml,mainvbox);
-   glade_xml_signal_autoconnect(generalpagexml);
-   generalpageinitialised=true;
-   gtk_widget_ref(generalpage);
+generalpage = gtk_vbox_new(FALSE, 0);
+gtk_container_add(GTK_CONTAINER(generalpage),
+  gtk_label_new(Just testing...));
+g_object_ref(generalpage);

}
 

the General page content (i.e. the label) no longer disappears and stays
there -- and this is the behaviour I'd expect.

Yeti


P.S.: If you post a tarball it is more helpful to include a two-line
Makefile than Glade backup files and a.out that no one sane will run...

P.P.S: The code looks like a parade of obsolete and deprecated libraries
and functions (see http://live.gnome.org/LibgnomeMustDie).  I hope it is
not a new project...
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list