Re: Notification area application

2006-04-04 Thread James Scott Jr
On Sun, 2006-04-02 at 07:37 -0700, BobS0327 wrote:

> I am trying to develop an application that resides in the notification area
> of Fedora 5 and version 2.14.0 of the Notification area.  I have found some
> sample code on the internet  for a base system tray (notification area)
> application.  It compiles without any problem but no icon appears in the
> notification area.
> 
> Thus, can anybody provide any assistance to help me develop this base system
> tray application?
> 
> Thanx
> 

Bob,

You and I may be at the same place in writing code to this interface.  I
include three links to answer your question.  
1. look at libegg/tray and use that code as is or modified.  Your
already have a notification tray in the gnome panel (or add to panel
one), as a target for this code.  This code also includes a test program
for the two type/styles of tray_icons.
http://cvs.gnome.org/viewcvs/libegg/?only_with_tag=MAIN

2. Some guidance on how/when to use a notification area versus a
gnome-panel-applet.
http://developer.gnome.org/projects/gup/hig/2.0/desktop-notification-area.html

3. The FreeDesktop.org spec or description of the notification area
protocol.
http://standards.freedesktop.org/systemtray-spec/systemtray-spec-0.2.html

Hope this helps,
James,


> Bob
> --
> View this message in context: 
> http://www.nabble.com/Notification-area-application-t1382780.html#a3713241
> Sent from the Gtk+ - Apps Dev forum at Nabble.com.
> 
> ___
> 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: gui, g_objects and abstraction

2006-04-06 Thread James Scott Jr
On Thu, 2006-04-06 at 20:57 +0200, Andreas Kotowicz wrote:

> this is a general case question. I made myself familiar with gtk+ and
> created a few useful (and less useful) programs. I quickly began to
> realize that I do reuse some code very often. So I thought about
> abstraction and creation of objects and classes which could then be
> easily reused. so here's my question: does it make sense to create a
> class/object which only creates the main window. this object will then
> make a call to a class which creates the UI inside the window. then I
> might have different "main-window-objects" (like in evolution where you
> have a mail/calendar/task window inside the main window) which should
> get created by the UI class as requested by the user and put between the
> menu and status bars. of course the window class would create a default
> object first so the main window wouldn't be empty. 
> is this kind of abstraction useful? or would I just break a fly on the
> wheel? 
> 
> I tried to study different code (gedit, eog, evolution) but I can't
> actually see a clear strategy on this issue. I'm welcome for any
> suggestions / enlightenment.
> 
> cheers,
> Andreas
> 

Just a response.

The effort you project saving is analogous to that saved using GLADE2 or
GNOME for development.  Both the tool (glade) and the added library
(gnome) provide the same type of repetitive saving.  I would suggest
using gnome, or continuing as you are; if you don't care for generators
like glade.  "The official GNOME2 developer's guide" is the best GTK+
and GNOME programming guide I've seen so far.  Especially, if your
planning to create your own GTK widgets to package feature/functions you
use often. 

James,
(Not an Expert..., but fairly experienced)

> ___
> 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: Notification area application

2006-04-06 Thread James Scott Jr
On Thu, 2006-04-06 at 08:44 +0200, Olaf Leidinger wrote:

> Hello!
> 
> > Unfortunately, I'm not familiar on how to download files from the Gnome CVS
> > site.  Could you briefly explain how I would accomplish this download?
> > 
> 
> 
> Have a look at
> 
> http://developer.gnome.org/tools/cvs.html
> 
> In your case, open a terminal and write the following:
> 
> export CVSROOT=:pserver:[EMAIL PROTECTED]:/cvs/gnome
> 
> cvs login
> (just press return)
> 
> cvs -z3 checkout libegg
> 
> 
> Hope that helps,
> 
> Ciao,
> 
> Olaf Leidinger
> 
>  
> 
> --Signature=_Thu__6_Apr_2006_08_44_54_+0200_n936KMQb7FNESTuF--
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Bob,

Follow the above instructions - its painless.

1. the export command
2. the cvs login command with carraige-return or enter for a password
3. the cvs checkout command to actually copy the files to your current
directory
4. done - change directory to ./libegg/libegg/tray/ to see the files.

Note with minor adjustments I use the files as-is.

Design note: notification area icons work a little differently on other
none-gnome platforms.  If you need three icons for your app, create
three whole icons.  Don't do like I did - I created a single vbox and
packed three icons into it.  Worked fine on gnome, got truncated to one
icon worth of space/size on xfce, darwin, and kde.

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


Re: Random Number of Buttons

2006-04-21 Thread James Scott Jr
On Thu, 2006-04-20 at 18:40 -0700, 3saul wrote:

> OK what I'm trying to do is this:
> 
> 1. Read a directory full of images (the images in the directory will change)
> 2. Create a table with the correct number of cells.
> 3. Put a button in each cell with an image on it from the directory
> 4. In the cell below the image put the name of the file on a label
> 
> I've seen GTKIconView but that seems complicated to me (I'm a beginner)

Using an GtkIconView will be easier than anything else I can think of.  Take 
the challenge and use the treeview.  Here is my favorite tutorial for treeview 
in general: http://scentric.net/tutorial/treeview-tutorial.html

Here is a link to an complete example using the full GtkTreeView:
http://scentric.net/tutorial/sec-treeview-col-pixbufs.html

James,

> --
> View this message in context: 
> http://www.nabble.com/Random-Number-of-Buttons-t1480088.html#a4019004
> Sent from the Gtk+ - Apps Dev forum at Nabble.com.
> 
> ___
> 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: GTK+ 2.8.17 and background colours

2006-04-21 Thread James Scott Jr
On Fri, 2006-04-21 at 20:36 +0200, Francesco Montorsi wrote:

> Hi,
>   I'm struggling with my GTK+ (2.8.17 - coming with ubuntu dapper) to
> be able to set the background colour of a button.
> 
> I've googled and searched the archives of this mailing list and I have
> found exactly same questions with attached test programs.
> 
> I'm attaching two short, simple test programs which *should* be able to
> set the background colour of a button to a different colour from the
> standard one.
> 
> Unfortunately running them I don't see any difference with a standard
> GtkButton: i.e. the calls to gtk_widget_modify_bg and
> gtk_widget_modify_fg seems not to have any effect !
> 
> Could anyone more expert try to compile those files and run them to see
> if they get standard colours or not ?
> (to compile them I usually place them in the gtk\examples\helloworld
> folder and rename them to helloworld.c ;))
> 
> This seems like a GTK+ bug to me...
> 
> Thanks a lot,
> Francesco

The biggest tip I can share is "If the desired widget does not have a GtkWindow 
of its own, it draws on its parent's window!".  Now the parent window may not 
be the one you expect or think you've coded.  Use this sequence to change of 
the color of a widget without its own GtkWindow.

  GdkColor color;
...
  gdk_color_parse ("blue", &color);
...
 button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
..
 gtk_widget_modify_bg ( gtk_widget_get_parent(button), GTK_STATE_NORMAL,
&color);



gtk_widget_get_parent() is the magic api to permit changing colors of
widgets reliably. 

James,

> ___
> 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


Is it possible to implement Zoom/Shrink of a backing bitmap using only GTK+/GDK/GLIB ?

2006-05-04 Thread James Scott Jr
Folks,

I am writing a simple GTK+ line graph codeset to use in my GTK
applications; It's done but not a widget yet.

After reading several books and googling I still have this question.

Question: Is it possible using only GTK+/GDK/GLIB to create a 2000x2000
pixbuf for drawing and have the expose-event scale it to the current
window size?

It seems a gnome-canvas has the notion of world coordinates and
transforms; but I don't see this in regular GTK/GDK/GLIB.  I have
already done this using OpenGL and would like to simply use GTK without
all the fluff.

If its possible/practical - can someone point me to the right source to
learn how to do this zooming thing? or even suggest a few api as a
starting point.  I looked at "void gdk_region_shrink(GdkRegion *region,
gint dx, gint dy);", but I'm not sure it will do what I'm after.


James,



Registered Linux User #270764
FC5 on Dual AMD 2400+ MPs


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


Creating custom widget questions

2006-05-25 Thread James Scott Jr
Folks,

I am creating a xy linegraph widget for the first time, and I am
experiencing a double destroy method call during shutdown.  Plus, I
would like some clarification on which api family to use for
params ;GtkObject or GObject, and a little help with naming a new
widget.  I'm using gtk2-devel-2.8.17-1.fc5.1

Q1: Naming a new widget:  Is it ok to name it gtk_linegraph_new() ?
   - I named mine sk_linegraph_new(), but all the books i've read
did not hesitate to prefix their names with gtk_

Q2: API Families: GtkObjectClass vs GObjectClass for widget properties?
   - I want the codeset to run anywhere GTK+/GDK is supported!
   - I used GObjectClass methods ( get/set_property ) rather than
GtkObjectClass get/set_arg - initially not noticing the difference; does
it matter ?

Q3: Double-Destroy method calls: GtkWidgetClass->destroy get called at
least twice during shutdown and GTK_DESTROYED(widget) didn't seem to
work?
  - With this widget and a few others, I've noticed that the destroy
method is called multiple times at program termination
  - I included my realize/unrealize() methods as they are the only
methods related to this problem that I could find.
  - Is there a GTK2 equivalent of  GTK_DESTROYED(widget), to help
detect the 2nd+ call ?
  - Is this a problem? can I safely ignore it?

[ FILE sklinegraph.h]

typedef struct _SkLineGraph 
{ 
  GtkWidget   widget;
...
} SkLineGraph;

typedef struct _SkLineGraphClass
{
  GtkWidgetClass parent_class;
} SkLineGraphClass;


[ FILE sklinegraph.c]

G_DEFINE_TYPE (SkLineGraph, sk_linegraph, GTK_TYPE_WIDGET)

static void sk_linegraph_class_init (SkLineGraphClass  *class)
{
  GObjectClass*gobject_class   = G_OBJECT_CLASS (class);
  GtkObjectClass  *gtkobject_class = GTK_OBJECT_CLASS (class);  
  GtkWidgetClass  *widget_class= GTK_WIDGET_CLASS (class);

  gobject_class->set_property = sk_linegraph_set_property;
  gobject_class->get_property = sk_linegraph_get_property;
  gtkobject_class->destroy= sk_linegraph_destroy;

  widget_class->size_allocate = sk_linegraph_size_allocate;  
  widget_class->size_request  = sk_linegraph_size_request;
  widget_class->realize   = sk_linegraph_realize;
  widget_class->unrealize = sk_linegraph_unrealize;  
  widget_class->expose_event= sk_linegraph_expose_event;  
  widget_class->motion_notify_event =
sk_linegraph_motion_notify_event;
  widget_class->button_press_event  = sk_linegraph_button_press_event;

  g_object_class_install_property
(gobject_class,PROP_GRAPH_DRAWING_TYPE,
   g_param_spec_boolean
("graph-drawing-type",
 "Graph Drawing
Type",
 "some text",
 FALSE,

G_PARAM_READWRITE));
}

static void sk_linegraph_realize (GtkWidget *widget)
{
  SkLineGraph *slg = NULL;
  GdkWindowAttr attributes;
  gint attributes_mask;

  g_return_if_fail ( widget != NULL);
  g_return_if_fail (IS_SK_LINEGRAPH (widget));

  slg = SK_LINEGRAPH (widget);
  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);

  attributes.window_type = GDK_WINDOW_CHILD;
  attributes.x = widget->allocation.x;
  attributes.y = widget->allocation.y;
  attributes.width = widget->allocation.width;
  attributes.height = widget->allocation.height;
  attributes.wclass = GDK_INPUT_OUTPUT;
  attributes.visual = gtk_widget_get_visual (widget);
  attributes.colormap = gtk_widget_get_colormap (widget);
  attributes.event_mask = gtk_widget_get_events (widget) |
GDK_EXPOSURE_MASK | 
 GDK_BUTTON_PRESS_MASK |
GDK_POINTER_MOTION_MASK | 
 GDK_POINTER_MOTION_HINT_MASK;

  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL |
GDK_WA_COLORMAP;

  widget->window = gdk_window_new (gtk_widget_get_parent_window
(widget), &attributes, attributes_mask);
  gdk_window_set_user_data (widget->window, widget);

  widget->style = gtk_style_attach (widget->style, widget->window);
  gtk_style_set_background (widget->style, widget->window,
GTK_STATE_NORMAL);

  if (slg->lgflags & LG_GRAPH_SCALED) {
  sk_linegraph_manage_scaled_config  (slg);
  } else {
  sk_linegraph_manage_regular_config (slg);
  }

}

static void sk_linegraph_unrealize (GtkWidget *widget)
{
  g_return_if_fail (widget != NULL);
  g_return_if_fail (IS_SK_LINEGRAPH (widget));
  
  if (GTK_WIDGET_CLASS (sk_linegraph_parent_class)->unrealize)
(* GTK_WIDGET_CLASS (sk_linegraph_parent_class)->unrealize)
(widget);
}

James,


Registered Linux User #270764
FC5 on Dual AMD 2400+ MPs


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


Re: Creating custom widget questions

2006-05-25 Thread James Scott Jr
Thanks for the quick response.

On Thu, 2006-05-25 at 19:07 +0200, David Nečas (Yeti) wrote:

> On Thu, May 25, 2006 at 12:18:46PM -0400, James Scott Jr wrote:
> > 
> > Q1: Naming a new widget:  Is it ok to name it gtk_linegraph_new() ?
> >- I named mine sk_linegraph_new(), but all the books i've read
> > did not hesitate to prefix their names with gtk_
> 
> sk_linegraph_new() will not cause conflicts with future Gtk+
> versions while gtk_linegraph_new() violates Gtk+ namespace.
> Actually, sk_line_graph_new() is the right name because your
> type name is SkLineGraph not SkLinegraph.

If i want to use sk_linegraph_new() or sk_linegraph_*, I should change my type 
name to SkLinegraph.  I will make that case change



> > Q2: API Families: GtkObjectClass vs GObjectClass for widget properties?
> > 
> >- I want the codeset to run anywhere GTK+/GDK is supported!
> >- I used GObjectClass methods ( get/set_property ) rather than
> > GtkObjectClass get/set_arg - initially not noticing the difference; does
> > it matter ?
> 
> All the GtkArg stuff (as almost everything from the
> pre-GObject era) is deprecated since 2.0.

Lucked out here.



> > Q3: Double-Destroy method calls: GtkWidgetClass->destroy get called at
> > least twice during shutdown and GTK_DESTROYED(widget) didn't seem to
> > work?
> 
> Destroy method can be invoked several times.  It has to be
> idempotent (which should answer the remaining questions).
> 
> A common technique to make it idempotent is to set things to
> NULL when you free them and check them for NULL before
> freeing them (if they are not freed with plain g_free()
> which is idempotent itself).  This has the advantage it
> works equally well for things that may exist only
> optionally.

Thats exactly what i did; first pass free and set to NULL, 2nd+ test for NULL.

> Yeti
> 

Thanks

> 
> --
> Anonyms eat their boogers.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


[Fwd: Re: How to get the the current size of a widget?]

2006-06-02 Thread James Scott Jr
Luis 

If you look at the GtkWidget structure you will find it contains an
GtkAllocation  allocation, which is a simple rectangle.  It is set to
the widget's current size by the configure or realize event of all
widgets.  You can use its value reliably almost anytime after the
gtk_main() has had an opportunity to run and start processing
events/messages.

example:
widget->allocation.x
widget->allocation.y
widget->allocation.width
widget->allocation.height

http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#GtkAllocation

James,
 Forwarded Message 

> From: Luis Menina <[EMAIL PROTECTED]>
> To: heavenscape <[EMAIL PROTECTED]>
> Cc: gtk-app-devel-list@gnome.org
> Subject: Re: How to get the the current size of a widget?
> Date: Fri, 02 Jun 2006 23:12:58 +0200
> 
> 
> Use the "configure-event" event...
> 
> It's not well documented in GTK doc:
> http://developer.gnome.org/doc/API/2.0/gtk/GtkWidget.html#GtkWidget-configure-event
> 
> But the pygtk help tells it's called when the window changes its size
> http://pygtk.org/pygtk2reference/class-gtkwidget.html#signal-gtkwidget--configure-event
> 
> Cheers
> 
> Luis
> 
> heavenscape a écrit :
> > I am displaying a image in my main window, and I want it to automatically
> > resize with the main window. Can anyone tell me how to get the current size
> > of the main window or any widget from within a callback?
> > 
> > Regards!
> > --
> > View this message in context: 
> > http://www.nabble.com/How-to-get-the-the-current-size-of-a-widget--t1721682.html#a4676723
> > Sent from the Gtk+ - Apps Dev forum at Nabble.com.
> > 
> > ___
> > 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: C/GTK question

2006-06-17 Thread James Scott Jr
On Thu, 2006-06-15 at 12:08 -0300, Matías Torres wrote:

> I'm building an application in C that uses GTK. The reason i'm doing this is
> to learn GTK (and C as well) the main problem I've found is that i write all
> the GTK code in only one file and is getting too da## big, so i tried to
> divide the GTK code in different files, but it seems i'm do not understand C
> that good. This is what i did:
> 
> global.c
>GtkWidget *mainWindow
> 
> gtkarch1.c   gtkarch2.c  gtkarch3.c   gtkarch4.c
> /* Al this files uses the mainWindow variable, this is what i do:
> gtkarchX.c
>   #include global.c
>   GtkWidget *mainWindow */

** Remove this from all X.c files.  It is the cause of your compiler error. **



> ant then the main.c file which looks like this:
> 
> main.c
> #include "gtkarch1.c"
> #include "gtkarch2.c"
> #include "gtkarch3.c"
> 
> But the compiler gives me an error, which I understand but i don't know how
> to solve it, that says that i'm redefining the variables declared in
> global.c in each gtkarchX.c

** By including the other C files from the main.c file the compiler
treats the set of files as if they were just one big file named main.c.

James,


> 
> So Help? please?
> ___
> 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: Systray icon..

2006-08-11 Thread James Scott Jr
Here is an example of using eggtrayicon.c and eggtrayicon.h

http://mysite.verizon.net/skoona/id2.html

James,

On Fri, 2006-08-11 at 17:05 +0200, Enrico wrote:

> Hi at all!
> 
> How can I display an icon in the system tray without using GtkStatusIcon 
> (I've only GTK 2.8).
> 
> Many thanks!
> 
> Enrico
> ___
> 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: Fwd: Systray icon..

2006-08-13 Thread James Scott Jr
Tried compiling what? eggtrayicon.c, edgestatusicon.c ?  What was the
error-code/messages ?
James,

On Sun, 2006-08-13 at 10:58 -0500, Samuel Cormier-Iijima wrote:

> I tried compiling it once, and it didn't seem to work with GTK 2.0... :-)
> 
> On 8/13/06, Enrico <[EMAIL PROTECTED]> wrote:
> > Fernando Apesteguía pronuncio' le seguenti parole il 11/08/2006 17:09:
> > > Using eggtrayicon.c and eggtrayicon.h
> > >
> > > Best regards
> > >
> >
> > Many thanks for the help! I have noticed that there is also an
> > edgestatusicon.c and an edgestatusicon.h, what is the difference?
> >
> > Thanks
> >
> > Enrico
> > ___
> > 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: Fwd: Systray icon..

2006-08-14 Thread James Scott Jr
I was able to compile it, after a few minor changes.  If you wanting to
use it on a linux platform download my example for this url.
http://mysite.verizon.net/skoona/id2.html

The example program demonstrates adding and removing an icon, adding
tooltips, popup-menus to an icon, etc.

Let me know, if you cannot compile my example.
James,

On Mon, 2006-08-14 at 00:35 -0500, Samuel Cormier-Iijima wrote:

> eggstatusicon. it was a while ago, so maybe they've updated it, but I
> remember that eggtrayicon was what i needed (putting an icon in the
> systray)
> 
> On 8/14/06, James Scott Jr <[EMAIL PROTECTED]> wrote:
> >
> >  Tried compiling what? eggtrayicon.c, edgestatusicon.c ?  What was the
> > error-code/messages ?
> >  James,
> >
> >
> >  On Sun, 2006-08-13 at 10:58 -0500, Samuel Cormier-Iijima wrote:
> >  I tried compiling it once, and it didn't seem to work with GTK 2.0... :-)
> >
> > On 8/13/06, Enrico <[EMAIL PROTECTED]> wrote:
> > > Fernando Apesteguía pronuncio' le seguenti parole il 11/08/2006 17:09:
> > > > Using eggtrayicon.c and eggtrayicon.h
> > > >
> > > > Best regards
> > > >
> > >
> > > Many thanks for the help! I have noticed that there is also an
> > > edgestatusicon.c and an edgestatusicon.h, what is the difference?
> > >
> > > Thanks
> > >
> > > Enrico
> > > ___
> > > 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

Linux signals and GLIB g_io_channel usage

2006-10-23 Thread James Scott Jr
Folks,

I am about to write the socket module of a program that follows the gnu
standard structure for a daemon.  I am using glib wherever possible and
have a question concerning the use of linux signals.  Basically, I have
blocked all signals on all threads according to the standard daemon
model and use a single thread with a sigwait() to process the ones I'm
interested in; like SIGHUP to reload the config file.

Question: Will having all signals blocked interfere with the normal
operation of glib, in such a way that that I need to rethink how to
handle signals?  I plan to use g_io_channel...() and g_io_add_watch() to
handle asynchronous reads from sockets.  

This is what I mean by "signals blocked".

  /* block all signals */
sigfillset (&signal_set);
pthread_sigmask (SIG_BLOCK, &signal_set, NULL);

if (i_debug != 88) {
/* Fork off the parent process */
if ( (daemon (0, 0) ) != 0)  {
g_warning ("Fork() Failure -- shutdown");
exit (EXIT_FAILURE);
}
/* Change the file mode mask */
umask (0);
}


Thanks in advance.

James,


Registered Linux User #270764
FC5 on Dual AMD 2400+ MPs


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


Re: Linux signals and GLIB g_io_channel usage

2006-10-23 Thread James Scott Jr

On Mon, 2006-10-23 at 13:42 -0400, Tristan Van Berkom wrote:

> James Scott Jr wrote:
> > Folks,
> > 
> 
> Hi James,
> in a phrase - I've done it and it works fine.
> 
> some places might call for special attention though - for
> example - if you were to call g_spawn_sync() or g_child_watch(),
> you may want to have leave SIGCHLD available.
> 

Thats what prompted the question.  I noticed that I needed to un-block
around a call to g_spawn_command_line_async() and wondered if I was
getting into trouble on this path.  Now I will only unblock SIGCHLD
around those calls instead of all signals.  

Thanks for the quick response.


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


RE: Linux signals and GLIB g_io_channel usage

2006-11-13 Thread James Scott Jr
On Mon, 2006-11-13 at 02:15 -0500, Freddie Unpenstein wrote:

> On Mon 10/23, James Scott Jr < [EMAIL PROTECTED] > wrote:
> > I am about to write the socket module of a program that follows the
> > gnu standard structure for a daemon. I am using glib wherever
> > possible and have a question concerning the use of linux signals.
> > Basically, I have blocked all signals on all threads according to
> > the standard daemon model and use a single thread with a sigwait()
> > to process the ones I'm interested in; like SIGHUP to reload the
> > config file.
> 
> I'm curious, to know where this documentation is...  Happen to have a URL 
> handy?
> 

The docs are also in most devhelp installations, try "$ devhelp" on your
console.

http://developer.gnome.org/doc/API/2.0/glib/glib-IO-Channels.html

> 
> Fredderic
> 
> ___
> Join Excite! - http://www.excite.com
> The most personalized portal on the Web!
> 
> 
> ___
> 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: Linux signals and GLIB g_io_channel usage

2006-11-13 Thread James Scott Jr
On Mon, 2006-11-13 at 17:02 -0800, C.R. Kirkwood-Watts wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> James Scott Jr wrote:
> > On Mon, 2006-11-13 at 02:15 -0500, Freddie Unpenstein wrote:
> > 
> >> On Mon 10/23, James Scott Jr < [EMAIL PROTECTED] > wrote:
> >>> I am about to write the socket module of a program that follows the
> >>> gnu standard structure for a daemon. I am using glib wherever
> >>> possible and have a question concerning the use of linux signals.
> >>> Basically, I have blocked all signals on all threads according to
> >>> the standard daemon model and use a single thread with a sigwait()
> >>> to process the ones I'm interested in; like SIGHUP to reload the
> >>> config file.
> >> I'm curious, to know where this documentation is...  Happen to have a URL 
> >> handy?
> >>
> > 
> > The docs are also in most devhelp installations, try "$ devhelp" on your
> > console.
> 
> I assumed that the question pertained to the "gnu standard structure for
> a daemon" part of your post.  In either case, I would like to know
> whence _that_ documentation.
> 
> Chris.
> 

Ok, I may have misunderstood the question, as my answer related to
g_io_channel... usage.  

If I am back on track, the standard daemon model is based on my
interpretation of google results where like these:
http://www.linuxprofilm.com/articles/linux-daemon-howto.html
http://www.enderunix.org/documents/eng/daemon.php .  Where a particular
sequence of startup steps are repeated over and over throughout multiple
search hits.  The summary statement "gnu standard structure for a
daemon" is solely my observation, and not official.  

Additionally, this daemon search lead me to look for additional info on
linux signals and posix threads; where the "Linux Journal" and "Advanced
Linux Programming" yeided the best answers.  Here are couple links
related to signal handling with multiple posix threads -
http://www.linuxjournal.com/article/2121, and
http://www.linuxjournal.com/article/3985 .

I hope this is what your after.

James,


Registered Linux User #270764
FC5 on Dual AMD 2400+ MPs


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

Re: Proper way to show unique icon in treeview <--with code

2006-12-17 Thread James Scott Jr
Tony,

I don't claim to be an expert but I have used IconViews & TreeViews.  I
have never seen it attempted the way you show.  Using GDK_TYPE_PIXBUF as
the column type is all I have every tried, based on code I've seen from
others, and it has always worked.

Here are a few observation of your code.
1. I have been successful using the following creation order.
A. Load all icons I plan to use into an array of *pixbuf or some
type of permanent(life of the app) container.
B. Create the list store
model = GTK_TREE_MODEL (gtk_list_store_new (2,
  GDK_TYPE_PIXBUF,  /* ICON
*/
  G_TYPE_STRING /*
Location Name  */
));
C. Create the iconview (or treeview) & show it, plan on adding it to
a scrolled_window.
  iconview = gtk_icon_view_new_with_model (GTK_TREE_MODEL (model));
  gtk_icon_view_set_orientation (GTK_ICON_VIEW (iconview),
GTK_ORIENTATION_VERTICAL);
  gtk_icon_view_set_columns (GTK_ICON_VIEW (iconview), -1);
  gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (iconview),
GTK_SELECTION_SINGLE);
  gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (iconview),
ID_SEL_ICON);
  gtk_icon_view_set_markup_column (GTK_ICON_VIEW (iconview),
ID_SEL_LABEL);

D. Load each record to the list store with a pointer to pixmap, and
text string
  gtk_list_store_prepend (GTK_LIST_STORE (model), &iter);
  gtk_list_store_set (GTK_LIST_STORE (model), &iter,
  ID_SEL_ICON, pixbuf, ID_SEL_LABEL, "Home", -1);

Iconviews don't need all the renderer fuss and may work well for you.
gfhcm.sourceforge.net contains an application i wrote that uses both
icon views and tree views, look at the gfhcm-client or gfhcmc codeset.  

You might also find answers for the GTK API Docs or the TreeView
tutorial.
http://developer.gnome.org/doc/API/2.0/gtk/TreeWidget.html
http://developer.gnome.org/doc/API/2.0/gtk/GtkIconView.html
http://scentric.net/tutorial/treeview-tutorial.html

Hope this helps,

James,

On Sun, 2006-12-17 at 23:06 -0500, Tony Freeman wrote:

> > Hello,
> > 
> > I need help understanding how one would create a treeview so that the
> > first column is an icon and the second column is text.  The icon and
> > text represent the type of machine the user can choose (linux
> > workstation, linux server, hp).  I want to have a different icon for
> > each machine; however, I notice that whatever icon is called last in the
> > code that I have written, is the icon that is shown for ALL the rows.  
> > 
> > Please help!  What am I doing wrong?
> 
> I forgot to attach the code!
> 
> Here it is:
> 
> 
> void build_server_list (GtkWidget *treeview)
> {
>   GtkListStore *liststore;
>   GtkTreeIter iter;
>   GtkCellRenderer *text_renderer;
>   GtkCellRenderer *icon_renderer;
>   gint i = 0;
>   gint count = 0;
>   
> 
>   icon_renderer = gtk_cell_renderer_pixbuf_new();
>   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW(treeview),
>0,  
>" ",  
>icon_renderer,
>NULL);
>   
>   text_renderer = gtk_cell_renderer_text_new();
>   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW(treeview),
>1,  
>" ",  
>text_renderer,
>NULL);
>   
>   liststore = gtk_list_store_new(2, GDK_TYPE_PIXBUF, G_TYPE_STRING);
>   
>   /* workstations */
>   count = g_strv_length(workstations);
>   g_object_set(icon_renderer, "stock-id", "gtk-close", NULL);
>   for (i=0; i   gtk_list_store_append(liststore, &iter);
>   gtk_list_store_set(liststore, &iter,
>   0, icon_renderer,
>   1, workstations[i], -1);
>   }
>   
>   /* linux servers */
>   count = g_strv_length(servers_linux);
>   g_object_set(icon_renderer, "stock-id", "gtk-save", NULL);
>   for (i=0; i   gtk_list_store_append(liststore, &iter);
>   gtk_list_store_set(liststore, &iter,
>   0, icon_renderer,
>   1, servers_linux[i], -1);
>   }
>   
>   
>   /* hp servers */
>   count = g_strv_length(servers_hp);
>   g_object_set(icon_renderer, "stock-id", "gtk-open", NULL);
>   for (i=0; i   gtk_list_store_append(liststore, &iter);
>   gtk_list_store_set(liststore, &iter,
>   0, icon_renderer,
>   1, servers_hp[i], -1);
>   }
>   
>   gtk_tree_view_set_model(GTK_TREE_VIEW(treeview),
> GTK_TREE_MODEL

Re: How does one pipe output from process to text buffer? <-- FIXED

2006-12-30 Thread James Scott Jr
On Sun, 2006-12-31 at 05:43 +, [EMAIL PROTECTED] wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> On Sat, Dec 30, 2006 at 12:15:33AM -0500, Tony Freeman wrote:
> > Thanks everyone, I have this working now :-)  Special thanks to Tomas!
> 
> happy it helped :-)
> 
> Still strange that it blocks, though. Perhaps
> g_spawn_async_with_pipes(...) gives you channels in blocking mode (I'd
> doubt that, but I don't know for sure).
> 
> You might try this out e.g. with
> 
>   g_io_channel_set_flags(gioout,
>  G_IO_FLAG_NONBLOCK | g_io_channel_get_flags(gioout)),
>  &err); /* or NULL, if you live on the edge */
> 
> right after the gioout = g_io_channel_unix_new(...)
> 

g_io_channel_...() could be buffering the input/output.  try adding a
g_io_channel_set_encoding(gioout, NULL, NULL); after the
g_io_channel_new() call.  Also, the following text may provide some
insight.

"The default encoding for GIOChannel is UTF-8. If your application is
reading output from a command using via pipe, you may need to set the
encoding to the encoding of the current locale (see g_get_charset())
with the g_io_channel_set_encoding() function.

If you want to read raw binary data without interpretation, then call
the g_io_channel_set_encoding() function with NULL for the encoding
argument."

James,


> Regards
> - -- tomás
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.1 (GNU/Linux)
> 
> iD8DBQFFl04NBcgs9XrR2kYRAlG+AJ9LCauFArjjFzraf0GTLQ4Z+6oOUQCdFYt6
> US5gnFcIbPS44N0OoxYrvA4=
> =8p1T
> -END PGP SIGNATURE-
> 
> ___
> 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: Coding systems ?

2007-01-22 Thread James Scott Jr
On Mon, 2007-01-22 at 19:56 +0100, Olivier Ramare wrote:

> Many thanks to all, my handling of files and strings
> was in fact faulty. I used
> 
> while(fp != NULL){
>   fgets(line ,256, fp);
>   gtk_text_buffer_insert_at_cursor(...);}
> 
> which results in the last line being read twice,
> with wrong charaters at the beginning the second time.
> An eof character most probably somewhere.
> 
> The test !feof(fp) is no better, but the easy
> and clean code :
> 
> while( fgets(line ,256, fp)!= NULL){
>   gtk_text_buffer_insert_at_cursor(...);}
> 


Olivier,
If you use glib at all, you might want to try this api for the text file
io.

gbooleang_file_get_contents (const gchar *filename,

  gchar **contents,
  gsize *length,
  GError **error);

James,

> does wonder. I promise, next time I'll
> check my code more thoroughly before
> incriminating gtk!
> 
> Best,
> Amities,
>Olivier
> 
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

James Scott, Jr. 
Registered Linux User #270764
FC6 on Dual AMD-MP 2400+
Author: {gfhcm, gkrellfah2,gapcmon,giw}.sourceforge.net
http://mysite.verizon.net/skoona/index.html
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: scrolledview

2007-02-06 Thread James Scott Jr
On Tue, 2007-02-06 at 21:40 +0100, Mehmet YASAR wrote:

> Hi,
> 
> I need some advice about scrolled views.
> 
> I have a gtkscrolledview containing a gtkvbox, I'm adding many 
> gtktextviews to the vbox. I'd like to select which gtktextview is 
> displayed when I call gtk_widget_show(gkvbox).
> 
> The problem I have is related to the fact that each widget have a 
> different height, so "size negociation" with the gtkvbox takes many steps.
> 
> I can't find the FINAL height of the gtkvbox (after all the widgets have 
> been added and their height allocated), so I am unable to scroll to the 
> correct position before gtk_widget_show.


If you have caused the GtkVBox to be Realized, meaning all the widget
have done their size negotiations, then to get the x/y position of the
desired GtkTextView - relative to the GtkVBox, you can try something
like this.

if ( GTK_WIDGET_REALIZED(gvbox) ) 
{
GTK_WIDGET(gkvbox)->allocation.height;  /* this is the allocated
height */
GTK_WIDGET(desired_gtktextview)->allocation.y; /* this would be your
scroll to point to display this widget */

/* this point is inside the gvbox's height range */
}

Hope this helps

James,



> 
> Can someone help me ?
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

James Scott, Jr. 
Registered Linux User #270764
FC6 on Dual AMD-MP 2400+
Author: {gfhcm, gkrellfah2,gapcmon,giw}.sourceforge.net
http://mysite.verizon.net/skoona/index.html
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: scrolledview

2007-02-09 Thread James Scott Jr
On Thu, 2007-02-08 at 05:53 +, [EMAIL PROTECTED] wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> On Wed, Feb 07, 2007 at 08:32:26PM +0100, Mehmet YASAR wrote:
> > [EMAIL PROTECTED] a écrit :
> [...]
> > >> how can I know that all the widget have done their size negotiations ?
> > >> I can't rely on the "realized" signal since the gtkvbox is already 
> > >> realized ...
> > > 
> > > I'd put my bets on the widget's size-allocate signal -- but I don't know
> > > for sure.
> > 
> > I had already done some experimentation and I've found that widgets may 
> > get more than one size-allocate signal.
> 
> [...]
> 
> Yes, I suppose you'd have to "track" the size as it changes. If you have
> to do an action  hwenever the size really, truly changed (meaning it has
> been displayed and all is quiescent), perhaps an idle handler would be
> the right place.
> 
> Regards
> - -- tomás
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.1 (GNU/Linux)
> 
> iD8DBQFFyrrRBcgs9XrR2kYRAv5IAJ492lpDlVYRLNQMTW5tyQg7tyzCtQCfdpVr
> CbfgmDGn4JNUmPkHHam9lZI=
> =UcZq
> -END PGP SIGNATURE-
> 

Mehmet,

An idle handler would be a good fit here.  I assumed that you are
creating and filling textviews during the startup of your program and
possibly before you enter the main_loop or gtk_main.  Or possibly in a
routine that does everything at once.  Here is the potential problem:
your create and populate actions require some additional gtk messages to
be processed, which are waiting to get serviced by the gtk_main() loop.
So thing s will not appear to settle down until after the gtk_main has
been allowed to run.  Using an idle handler puts your call to a
Position/Size routine at the back of the waiting queue of needed
messages, so by the time it's processed the other messages have done
their job and all the textviews/scrollbars/gtkvboxes, and scrolled
windows have settled down.  -- wait, this assumes you issued a
gtk_widget_show{_all} on the main window containing all this stuff!  Its
the gtk_widget_show that starts the cascade of messages which includes
the size and realize messages.  

g_idle_add() or g_timeout_add(250,...) show do the trick.

James,



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

James Scott, Jr. 
Registered Linux User #270764
FC6 on Dual AMD-MP 2400+
Author: {gfhcm, gkrellfah2,gapcmon,giw}.sourceforge.net
http://mysite.verizon.net/skoona/index.html
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: libglade frustration redux - back away from the keyboard

2007-02-17 Thread James Scott Jr
Geraldi,

I take notice of the following comment.   "I give up!  I throw in the
towel".  This is certainly your option, but I will tell you that your
experience with libglade is typical for persons who approach programming
the wrong way.  Let me suggest an alternative that WILL yield different
and better results.

First, this gtk application developers mailing list is monitored by some
of the original authors of gtk and many many developers who have
acquired a significant level of skill.  Collectively we can help anyone
with a programming problem, and as you have seen from the rambling  of
this thread - we clearly have opinions.  Let break this un-productive
cycle and fix something.

What your programing problem?  I assume you have a small outline, maybe
the first steps.  Post them and I will send you back a working GTK
sample which you can use to get started; and ask clarification questions
based on a working sample.

It seems you have be pointed to a wealth of resources related to GTK and
LibGlade.  Ignore libglade for the moment, lets focus on GTK for now.
Also, a great development information tool for GTK is 'DevHelp', most
destro's include by default.  I personally use 'Eclipse' as my
development IDE with the CDT plugin.  Fedora Core 5/6 include these two
tools by defaults.   Also, have a look as some of the source code I
share from this website "http://mysite.verizon.net/skoona/index.html";.
Nothing special, but it may give you ideal on how to organize your
questions and ideals.  Here is one book I found very useful for
reference and learning GTK: "The official GNOME2 Developers Guide" and
the GTK tutorial, installed with GTK already on your machine; look for
"/usr/share/doc/gtk2-devel-2.10.8/tutorial/book1.html" in your
filesystem.

There are a few 'AH' 'HA' moments that you must
acquire/experience/endure related to event programming;  but they are
neither hard nor complex - just some basic rules to follow when
organizing your code.

I will help, and I know others will help answer questions related to GTK
programing.  How can we help you?


James Scott, Jr. 
Registered Linux User #270764
FC6 on Dual AMD-MP 2400+
Author: {gfhcm, gkrellfah2,gapcmon,giw}.sourceforge.net
http://mysite.verizon.net/skoona/index.html
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: gtk box and flow layout

2007-02-18 Thread James Scott Jr
daa84,

You may want to explore using the GtkLayout container.  From what I know
of the Java FlowLayout, both GtkTable and GtkLayout are close
approximations of the FlowLayout.   

http://developer.gnome.org/doc/API/2.0/gtk/GtkLayout.html



On Sun, 2007-02-18 at 11:14 +0300, daa84 wrote:

> Hello!
> 
> Can I create flow layout box in gtk like java FlowLayout Layout Manager?
> Or it is need to create derivative class (from GtkTable for example) and 
> release it behaviour itself?
> 
> Thanks.
> 
> Sorry for my bad english:)
> 

James Scott, Jr. 
Registered Linux User #270764
FC6 on Dual AMD-MP 2400+
Author: {gfhcm, gkrellfah2,gapcmon,giw}.sourceforge.net
http://mysite.verizon.net/skoona/index.html
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Problems with Threading Concept

2007-02-19 Thread James Scott Jr
if (gtk_events_pending())  -- never do this unless your
certain what your doing */
/*  gtk_main_iteration(); */

/*-A  gdk_threads_leave ();--- again not needed */
}

}

void hello_print( GtkWidget *widget,
gpointer   data )
{  
   if(toggle==0)
{
 toggle=1;
 flag=1;
 pthread_create (&yes_tid, NULL,(void *)hello, NULL);
}
else
{
 flag=0;
 toggle=0;
}

}
int main(int   argc,
  char *argv[] )
{

GtkWidget *window;
GtkWidget *button;
g_thread_init (NULL);
gdk_threads_init ();

/*-C  gdk_threads_enter ();   -- too early */

gtk_init (&argc, &argv);

/* create a new window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

g_signal_connect (G_OBJECT (window), "destroy",
  G_CALLBACK (gtk_main_quit), NULL);

gtk_container_set_border_width (GTK_CONTAINER (window), 100);

button = gtk_button_new_with_label("click it");

g_signal_connect (G_OBJECT (button), "clicked",
  G_CALLBACK (hello_print), NULL);

gtk_container_add (GTK_CONTAINER (window), button);

gtk_widget_show (button);
gtk_widget_show (window);

   gdk_threads_enter (); /*-C  -- correct place for this */
gtk_main ();
   gdk_threads_leave ();

return 0;
}



James Scott, Jr. 
Registered Linux User #270764
FC6 on Dual AMD-MP 2400+
Author: {gfhcm, gkrellfah2,gapcmon,giw}.sourceforge.net
http://mysite.verizon.net/skoona/index.html
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: trying to launch a dialog from outside the main gui thread by emiting a signal to the thread.

2007-03-06 Thread James Scott Jr
On Tue, 2007-03-06 at 12:45 -0500, Kevin Lambert wrote:

> I am currently working on a multithreaded application which has a primary
> GUI that is always running and I need to be able to get that GUI to show a
> popup to put images in.  The problem I am having is how do I tell the GUI to
> show the popup from outside of its own code?  
> 
> As a test I connected the "keys-changed" signal for the GUI's window so that
> if that signal gets emitted it launches my dialog.  I then added an external
> function which emits that signal which, when called, crashes the application
> with:
> 
> Xlib: unexpected async reply (sequence 0x995)!
> Xlib: sequence lost (0x108c7 > 0xfd) in reply type 0x8!
> Xlib: sequence lost (0x1 > 0xfd) in reply type 0x0!
> 
> I do know that only the primary GUI thread is allowed to handle X calls
> which is why I had the signal handler launching my dialog.  I have tried
> googling for information but Im not finding much.
> 
> Thanks,
> 
> Kevin
> 


Kevin,

There several ways to communication between threads, and there are some
design options available which depending on what your doing may not
require you to create a formal thread.   First communications between
threads:

GASyncQueue
This glib allows api allows you to allocate a structure or pointer,
fill it with the logical message, and post it asynchronously to the
foreground GUI thread for formatting into a displayed message.  This
approch assumes async messages are ok.  If its not1. , create a second
queue, and after posting to display_que have the background thread read
from the done_que - it will sleep until the foreground displays the
message and post the original (or any) pointer to the Done_que.  
How does the foreground pickup the message.  Start a g_timeout_add()
function to peak at the queue every x seconds, then read  que if peak
counts is more than 0.  Be sure to return true to keep the
g_timeout_add() routine running, otherwise false will make it stop.

Alternates to formal threads.
g_idle_add()
g_io_watch()
g_io_timeout_add()

Hopefully you have the application devhelp and can look up these api's.

James,

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

James Scott, Jr. 
Registered Linux User #270764
FC6 on Dual AMD-MP 2400+
Author: {gfhcm, gkrellfah2,gapcmon,giw}.sourceforge.net
http://mysite.verizon.net/skoona/index.html
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: is there a g_option_print_usage() command?

2007-03-12 Thread James Scott Jr
On Mon, 2007-03-12 at 12:08 -0700, Rick Jones wrote:

> I see that goption can uatomagically handle --help and the like.  I'd 
> like to emit a usage string when someone gives a bogus option - is there 
>   a call one can make to just print the same stuff that goption does on 
> its own with --help, or do I have to mess about with error hooks?
> 
> http://developer.gnome.org/doc/API/2.0/glib/glib-Commandline-option-parser.html
> didn't mention one - before I use something I find from source I'd want 
> to check that it was simply an oversight in the api docs :)
> 
> thanks,
> 
> rick jones
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Rick,

The link you supplied gave a partial example that works.  However, here
is a full example; notice the if statement around
g_option_context_parse().

BEGIN EXAMPLE

/* gapc_notify.c20070123
 
  libnotify messaging routine for Linux scripting languages.
  output a titled message box to the graphical screen for 10 seconds

  Copyright (C) 2007 James Scott, Jr. <[EMAIL PROTECTED]>
  
  Compile Requirements: { tested on FC6 }
libnotify-0.4.2
libnotify-devel-0.4.2
gtk-2.6+
glib-2.6+

  Compile Command:
   $ gcc `pkg-config --cflags --libs libnotify` -o gapc_notify
gapc_notify.c
   
  Usage:
   $ ./gapc_notify -s 5 -t "title of messagebox" -m "message in the box"
   or 
   $ ./gapc_notify --help

  GPL2
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   
*/

#include 
#include 
#include 

static gchar   *gd_pch_title;
static gchar   *gd_pch_body;
static gchar   *gd_pch_icon;
static gint gd_i_seconds;

int main(int argc, char * argv[] ) 
{
NotifyNotification *nctx;  
GError  *gerror = NULL;
GOptionContext *context = NULL;
GOptionEntry entries[] = {
  {"title", 't', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
&gd_pch_title,
 "Title text on msg box", "Uninterruptible Power Supply"},
  {"message", 'm', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
&gd_pch_body,
 "Message body text", "message"},
  {"icon-name", 'i', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
&gd_pch_icon,
 "icon to include next to message",
"gtk-dialog-info ...-warning ...-error"},
  {"show-seconds", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT,
&gd_i_seconds,
 "seconds to display message", "10"}, 
  {NULL}
};

/* Get command line parms */
context = g_option_context_new (
" - APCUPSD Commandline Notification Utility"
" GPL2 [2007] <[EMAIL PROTECTED]>");
g_option_context_add_main_entries(context, entries, NULL);
g_option_context_set_ignore_unknown_options(context, FALSE);
if (!(g_option_context_parse(context, &argc, &argv, &gerror))) {
 g_warning ("Parse command line failed: %s", gerror->message);
 g_option_context_free(context);
 g_error_free(gerror);
 return (1);
}

if (gd_pch_title == NULL) {
gd_pch_title = "Uninterruptible Power Supply";
}
if (gd_pch_body == NULL) {
gd_pch_body = "message";
}
if (gd_pch_icon == NULL) {
gd_pch_icon = "gtk-dialog-info";
}
if (gd_i_seconds < 1 ) {
gd_i_seconds = 10;
}
  
notify_init("gapc_notify");

nctx = notify_notification_new (gd_pch_title, gd_pch_body,
gd_pch_icon, NULL); 

notify_notification_set_timeout (nctx, (gd_i_seconds * 1000) ); //
10 seconds

if (!notify_notification_show (nctx, NULL)) 
{
fprintf(stderr, "failed to send notification\n");
return 2;
}

g_object_unref(G_OBJECT(nctx));

notify_uninit();

return 0;
}


END EXAMPLE




James Scott, Jr. 
Registered Linux User #270764
FC6 on Dual AMD-MP 2400+
Author: {gfhcm, gkrellfah2,gapcmon,giw}.sourceforge.net
http://mysite.verizon.net/skoona/index.html
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: how to read data with g_io_read_channel throwed it through a normal socket

2007-04-12 Thread James Scott Jr
On Thu, 2007-04-12 at 13:36 -0700, nahuel9728 wrote:

> Hi everyone. Im developing a interface for a server program and I have some
> problems.Step by step:
> - I put the server in listen:
>   fd_dealer2server=socket..
>   bind
>   listen(fd_dealer2server,MAX_CON)
> 
> - I create a channel and I add a watch to the the port binded for everytime
> a data goes in
> io = g_io_channel_unix_new (fd_dealer2server);
> if (!g_io_add_watch (io, G_IO_IN, (GIOFunc) my_func, NULL)){g_error }
> 
> -Tll here everything its ok Later in my_func:
> static void my_func (GIOChannel *gio, GIOCondition condition, gpointer
> data){
> guint mensaje[1];
>   gsize bytes_read;
>  if(g_io_channel_read (gio, (gchar *) mensaje , sizeof(mensaje) , &
> bytes_read) != G_IO_ERROR_NONE){
>   g_warning("Error\n");
>   }
> 
> And Finally I have my client binded to the shame port
> fd=socket
> connect(fd,
> int sms = atoi(argv[2]);
> send( fd, &sms, sizeof(int) ,0);
> 
> It catch the event G_IO_IN but g_io_read doesnt works..Always get error. Any
> hint???
> Regards to every1, Nahuel


Nahuel,

You need to perform the socket accept() before the
g_io_channel_unix_new() is called.  

The http://gfhcmd.sourceforge.net/ package contains a gfhcmd server
module and the gfhcmc contains its matching client; I offer them as a
example of using g_io_channel... with sockets and gtk/glib.

Here is an example routine that picks up where you left off (at the
listen).  You should find the select(),  then accept(), then the
g_io_channel_unix_new() calls.  

[CODE]
/* 
 * Accept a TCP connection, waiting for upto 80 seconds.
 * Returns NULL on error, or connected GIOChannel
 * 
 */
extern GIOChannel *sknet_net_accept(PSKCOMM psk)
{
   socklen_t clilen = sizeof(struct sockaddr_in);
   intnewfd;
   struct sockaddr_in client_addr;
   GIOChannel*ioc = NULL;
   gint   rc = 0, ecount = 0;
   fd_set fdset;
   struct timeval timev, *tv = NULL;


   g_return_val_if_fail (psk != NULL, NULL);

   /*
* Wait on an incoming connection 
*/
   ecount = 0;
   tv = &timev;
   rc = 0;
   while ( rc <= 0) {
  timev.tv_sec = 8;
  timev.tv_usec = 0;
  FD_ZERO(&fdset);
  FD_SET(psk->fd_server, &fdset);
  if ( ecount > 10 ) {
  g_snprintf(psk->ch_error_msg, sizeof(psk->ch_error_msg), 
 "accept select(failed), retry=%d {%s}",
 ecount, g_strerror(errno));
   psk->ioc = NULL;
   return NULL;
  }
  rc = select(psk->fd_server+1, &fdset, NULL, NULL, tv);
  if ( rc == 0 ) { continue; } /* timed out */
  if ( rc == -1 ) { 
  g_snprintf(psk->ch_error_msg, sizeof(psk->ch_error_msg), 
 "tv.sec=%d, retrying=%d {%s}",
 (int)timev.tv_sec, ecount, g_strerror(errno));
  sknet_util_log_msg("sknet_net_accept", "accept select()
failing", 
 psk->ch_error_msg);

  g_usleep(100); 
  } /* error */  

  ecount++; 
   } /* end-while */

   /*
* Prepare to accept the connection
*/
   memset (&client_addr, 0, sizeof(struct sockaddr_in));

   newfd = accept(psk->fd_server, (struct sockaddr *)&client_addr,
&clilen);

   if (newfd < 0) {
   sknet_util_log_msg("Net_Accept issue ", "newfd<0", (gchar
*)g_strerror(errno));
   g_snprintf(psk->ch_error_msg,
sizeof(psk->ch_error_msg),"sknet_net_accept(%s)",
 (gchar *) g_strerror (errno));
   psk->ioc = NULL;  
  return NULL; /* error */
   }

   /*
*  get session partners name */
   getnameinfo ((struct sockaddr *)&client_addr, clilen, 
psk->ch_ip_client, sizeof(psk->ch_ip_client),
psk->ch_ip_client_port, sizeof(psk->ch_ip_client_port), 
NI_NUMERICSERV);

   ioc = g_io_channel_unix_new( newfd);
   g_io_channel_set_encoding (ioc, NULL, NULL);   
   g_io_channel_set_buffered (ioc, FALSE);

   psk->ioc = ioc;
   return ioc;
}

[/CODE]
___
gtk-app-devel-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: GTK Thread init problem

2007-04-16 Thread James Scott Jr
On Mon, 2007-04-16 at 18:09 +0530, prabahar k wrote:

> hi
>  i am trying to use a threaded GTK program. While running the
> program it gives segmentation fault and it seem to be an
> thread init problem. is there any thing i am missing? Please
> give u r comments.
> 
> the code is:
> /***gtk19.c**/
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> 
> pthread_t thrd1;
> 
> void destroy (GtkWidget *widget, gpointer data)
> {
>  gtk_main_quit ();
> }
> 
> void *argument_thread (void *args)
> {
> gdk_threads_enter ();
>  for (;;)
>{
>  /* sleep a while */
> 
> 
> 
>  sleep(1);
>  g_print("Inside thread");
> 
> 
>}
> gdk_threads_leave ();
>  return NULL;
> }
> 
> int main (int argc, char *argv[])
> {
>  GtkWidget *window;
> 
>   /* init threads */
> 
>  g_thread_init (NULL);
>  gdk_threads_init ();
>  /* init gtk */
>  gdk_threads_enter ();
> /*[Line :70] */gtk_init(&argc, &argv);
> 
>  g_print("After init\n");
> 
>  /* create a window */
>  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
> 
>  gtk_signal_connect (GTK_OBJECT (window), "destroy",
>  GTK_SIGNAL_FUNC (destroy), NULL);
> 
>  gtk_container_set_border_width (GTK_CONTAINER (window), 10);
>  gtk_widget_show (window);
> 
>  pthread_create (&thrd1, NULL, argument_thread, NULL);
> 
>  gtk_main ();
>  gdk_threads_leave ();
> 
>  return 0;
> }
> /**/
> 
> I compile it as
> gcc -Wall -g gtk19.c -o base -lpthread `pkg-config --cflags gtk+-2.0`
> `pkg-config --libs gtk+-2.0` `gtk-config --cflags --libs gthread`
> 
> 
> After core dump bt gives
> #0  0x00484aa2 in pthread_mutex_lock () from /lib/libpthread.so.0
> #1  0x0025f63a in g_mem_chunk_new () from /usr/lib/libglib-2.0.so.0
> #2  0x002408c6 in g_ptr_array_sized_new () from /usr/lib/libglib-2.0.so.0
> #3  0x002408e3 in g_ptr_array_new () from /usr/lib/libglib-2.0.so.0
> #4  0x00146f0d in gdk_x11_atom_to_xatom () from /usr/lib/libgdk-x11-2.0.so.0
> #5  0x00146f7b in gdk_atom_intern () from /usr/lib/libgdk-x11-2.0.so.0
> #6  0x001454d9 in gdk_keymap_translate_keyboard_state () from
> /usr/lib/libgdk-x11-2.0.so.0
> #7  0x0011267e in gdk_pre_parse_libgtk_only () from /usr/lib/libgdk-
> x11-2.0.so.0
> #8  0x00598330 in gtk_disable_setlocale () from /usr/lib/libgtk-x11-2.0.so.0
> #9  0x00264c8c in g_option_context_parse () from /usr/lib/libglib-2.0.so.0
> #10 0x00598789 in gtk_parse_args () from /usr/lib/libgtk-x11-2.0.so.0
> #11 0x005987c3 in gtk_init_check () from /usr/lib/libgtk-x11-2.0.so.0
> #12 0x00598801 in gtk_init () from /usr/lib/libgtk-x11-2.0.so.0
> #13 0x08048be7 in main (argc=2, argv=0xbfab7144) at gtk19.c:70
> 
> 
> 
> 
> ---
> 
> prabahar
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



prabahar,

I just modified your code to show the needed changes.  Notice that the
gdk_threads_enter/leave is removed from the thread and the thread is
created using glib's api.  I also updated the includes and compile
command.

James,

BEGIN CODE ***
/***gtk19m.c**/
/* gcc -O2 -Wall `pkg-config --cflags --libs gtk+-2.0 glib-2.0
gthread-2.0` gtk19m.c -o gtk19m */

#include 
#include 


void destroy (GtkWidget *widget, gpointer data)
{
 gtk_main_quit (); /* the window is almost invalid when this is
called */
   /* consider "delete-event" */
}

/*
 * Does not need gdk_threads_enter/leave() wrapping 
 *  if no GTK/GDK apis are called
*/
gpointer argument_thread (gpointer *args)
{
 for (;(gboolean)*args;)   /* exit loop when flag is cleared */
   {
 /* sleep a while */

 g_usleep(100);
 g_print("Inside thread");
   }

 g_thread_exit (NULL);/* not required just good pratice */
 return NULL;
}

int main (int argc, char *argv[])
{
 GtkWidget *window;
 GThread   *gth = NULL; /* thread id */
 gboolean  b_run_flag = TRUE;   /* used as exit flag for threads */


 g_thread_init (NULL);/* Initialize GLIB thread support */
 gdk_threads_init (); /* Initialize GDK locks */


 gdk_threads_enter ();/* Acquire GDK locks */
 gtk_init(&argc, &argv);  /* initialize GTK*/

 g_print("After init\n");

 /* create a window */
 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

 gtk_signal_connect (GTK_OBJECT (window), "destroy",
 GTK_SIGNAL_FUNC (destroy), NULL);

 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
 gtk_widget_show (window);

 /* Create a bg thread using glib */
 gth = g_thread_create ( (GThreadFunc)argument_thread,
(gpointer)&b_run_flag, TRUE, NULL);

 gtk_main (); /* --- ANYTHING EXECUTED VIA THIS LOOP HAS GDK LOCKS
ALREADY APPLIED */
 gdk_threads_leave ();  /* release GDK locks */

 b_run_flag = FALSE;  /* flag threads to stop and exit

Re: GTK Thread init problem

2007-04-17 Thread James Scott Jr
On Tue, 2007-04-17 at 13:56 +0530, prabahar k wrote:
> Hi
> 
> Thanks Tristan for u r suggestion for using g_thread_create.
> Thanks James for u r nice code.
> 
> 
> Also If we want to retain the p_thread_create() in the program then
> its enough to change the compile time flags to include
> `pkg-config --cflags --libs gtk+-2.0 gthread-2.0`
> Its working fine.
> 
> Here is the code:
> /**gtk19mod.c
>  compile:
>  gcc -g -o gtk19mod gtk19mod.c `pkg-config --cflags --libs gtk+-2.0
> gthread-2.0`
> /
> 
> #include 
> #include 
> #include 
> pthread_t thrd1;
> 
> void destroy (GtkWidget *widget, gpointer data)
> {
>  gtk_main_quit ();
> }
> 
> void *argument_thread (void *args)
> {
> 
> 
>  for (;(*(gboolean *)args);)
>{
>  /* sleep a while */
>  g_usleep(100);
>  g_print("Inside thread");
>}
>  g_thread_exit (NULL);

OK, but don't mix the threading api's.  remove the g_thread_exit().  For
portability and stability - I always use glib's threading apis when
using GTK/GDK.  

James,


> 
>  return NULL;
> }
> 
> int main (int argc, char *argv[])
> {
>  GtkWidget *window;
> 
>  gboolean  b_run_flag = TRUE;
> 
>  /* init threads */
>  g_print("Going thread init\n");
> 
>  g_thread_init (NULL);
>  gdk_threads_init ();
> 
>  gdk_threads_enter ();
> 
>  gtk_init(&argc, &argv);
> 
>  g_print("After init\n");
>  /* create a window */
> 
>  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
>  gtk_signal_connect (GTK_OBJECT (window), "destroy",
>  GTK_SIGNAL_FUNC (destroy), NULL);
>  gtk_container_set_border_width (GTK_CONTAINER (window), 10);
>  gtk_widget_show (window);
> 
> 
>  pthread_create (&thrd1, NULL, argument_thread, (void*)&b_run_flag);
> 
> 
>  gtk_main ();
>  gdk_threads_leave ();
> 
>  b_run_flag = FALSE;
>  return 0;
> }
> /End***/
> 
> 
> On 4/17/07, James Scott Jr <[EMAIL PROTECTED]> wrote:
> >
> > On Mon, 2007-04-16 at 18:09 +0530, prabahar k wrote:
> >
> > hi i am trying to use a threaded GTK program. While running theprogram it 
> > gives segmentation fault and it seem to be anthread init problem. is there 
> > any thing i am missing? Pleasegive u r comments.
> > the code 
> > is:/***gtk19.c**/#include 
> > #include #include #include #include 
> > #include #include 
> > pthread_t thrd1;
> > void destroy (GtkWidget *widget, gpointer data){ gtk_main_quit ();}
> > void *argument_thread (void *args){gdk_threads_enter (); for (;;)   { 
> > /* sleep a while */
> >
> >
> >  sleep(1); g_print("Inside thread");
> >
> >}gdk_threads_leave (); return NULL;}
> > int main (int argc, char *argv[]){ GtkWidget *window;
> >   /* init threads */
> >  g_thread_init (NULL); gdk_threads_init (); /* init gtk */ 
> > gdk_threads_enter ();/*[Line :70] */gtk_init(&argc, &argv);
> >  g_print("After init\n");
> >  /* create a window */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
> >  gtk_signal_connect (GTK_OBJECT (window), "destroy", 
> > GTK_SIGNAL_FUNC (destroy), NULL);
> >  gtk_container_set_border_width (GTK_CONTAINER (window), 10); 
> > gtk_widget_show (window);
> >  pthread_create (&thrd1, NULL, argument_thread, NULL);
> >  gtk_main (); gdk_threads_leave ();
> >  return 0;}/**/
> > I compile it asgcc -Wall -g gtk19.c -o base -lpthread `pkg-config --cflags 
> > gtk+-2.0``pkg-config --libs gtk+-2.0` `gtk-config --cflags --libs gthread`
> >
> > ---
> > prabahar
> > ___gtk-app-devel-list mailing 
> > [EMAIL PROTECTED]://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
> >
> >
> >
> > prabahar,
> >
> > I just modified your code to show the needed changes.  Notice that the
> > gdk_threads_enter/leave is removed from the thread and the thread is created
> > using glib's api.  I also updated the includes and compile command.
> >
> > James,
> >
> >
> >
> ___
> 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: g_io_add_watch, g_io_channel_read stops working after sometime.

2007-04-18 Thread James Scott Jr
On Wed, 2007-04-18 at 04:39 -0700, Rehan wrote:

> Hi, 
> 
>  I am trying to write a program based on client-server architecture. I need
> only one client connection hence i am first listening to client then
> accept() is called. after accept() i call g_io_channel_unix_new () and then
> g_io_add_watch() and later in the function i use g_io_channel_read to read
> data from the channel. 
> 
>   Everything works fine till 4-5 requests from the client. Later the server
> simply stops listening to client. I have tried tcpdump on server side and i
> do recieve the TCP packet from the client. So it means there is some bug at
> server side. I am not sure if i have done something wrong or some bug in
> core library... 
> 
> I am confused as the code works for 4-5 request and then simply starts
> ignoring the client messages. Is g_io_add_watch ignoring the incoming
> signals?? thats what i can detect from my gdb tracing there is no
> invocation of my function even if i recieve a packet on server side from the
> client 
> 
> in summary function calls: 
> 
> ->socket(AF_INET,SOCK_STREAM,0) 
> ->bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) 
> ->listen(sockfd,5) 
> ->accept(sockfd, (struct sockaddr *) &cli_addr, &clilen) 
> ->g_io_channel_unix_new (global_sock) 
> ->g_io_add_watch(listenonsocket, G_IO_IN | 
> G_IO_PRI,read_request,&global_sock) 

Rehan,

What is "listenonsocket" ?  Why no "G_IO_HUP" ?   the above sequence is
correct; however the api values seem to be wrong and in the wrong order!
Post or include the real code.  

As an example, look at the code in this sample "sknet" for the following
url.
http://mysite.verizon.net/skoona/id1.html



James,


> ->g_io_channel_read(channel,&len,sizeof(len),&bytes_read); 
> 
> I hope somebody comes to my rescue its been now 3 days i am trying to solve
> this problem but no success... 
> 
> Thanks in advance for all great coders 
> 
> Regards, 
> RS.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Plotting graphs

2007-05-24 Thread James Scott Jr
On Thu, 2007-05-24 at 06:27 -0700, Bluezapper wrote:
> Hi,
> 
> Can someone refer me to an example  which plots a simple 2D graph using 
> gtkextra API.
> 
> 
> thanks,
> 
> bluezapper. 
> 

I have used successfully both GtkExtra and GtkDataBox libraries.
However, for the app I was writing I found them too big for the simple
graph I needed; so I created my own.  Here is the link:

GLINEGRAPH http://mysite.verizon.net/skoona/id1.html


As a result of creating my own I have also contributed to a embedded
project which also contains a GTK based 2D scientific graph; here is its
link:

http://giw.sourceforge.net/

James,
>  
> -
> Never miss an email again!
> Yahoo! Toolbar alerts you the instant new Mail arrives. Check it out.
> ___
> 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: treeview: seg fault When Collapsing a Row Containg a Selected Item

2007-06-16 Thread James Scott Jr

On Sat, 2007-06-16 at 12:15 -0400, Marshall Lake wrote:

> I have a treeview/treestore containing many top-level rows.  Each 
> top-level row contains many children.  The treeview works fine except for 
> one thing.  If the user expands a top-level row, selects a child, and then 
> collapses that row the program seg faults with the console error:
> 
> gtk_tree_store_get_value: assertion `iter->stamp == GTK_TREE_STORE 
> (tree_model)->stamp' failed
> gtype.c:3351: type id `0' is invalid
> can't peek value table for type `' which is not currently referenced
> 

Without seeing the code I can only guess.  I seems that the iter your
using is invalid -- or no longer valid.  This could occur if you used a
LOCAL variable to create the iter; then saved the pointer of that inter
and tried to use it somewhere else which creates the segfault.

To poke around looking for it, use this api to test iters before use:
bool=gtk_tree_store_iter_is_valid(GtkTreeStore *tree_model, GtkTreeIter
*iter)

never trust an iter...

James,


> The treeview works fine if the user never collapses the row and goes on to 
> make another selection, either in that same top-level or a different 
> top-level.  Also, if a row is expanded and then collapsed with no child 
> being selected it works fine.
> 
> As an aside (?), I tried gtk_tree_selection_unselect_iter() on the child 
> after it was selected and got a seg fault and the same error as noted 
> above at the point the gtk_tree_selection_unselect_iter() was executed.
> 
> Can someone tell me what might need to be done to avoid the seg fault?
> 
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: treeview: seg fault When Collapsing a Row Containg a Selected Item

2007-06-18 Thread James Scott Jr
On Sun, 2007-06-17 at 09:37 -0400, Marshall Lake wrote: 

> >> I have a treeview/treestore containing many top-level rows.  Each 
> >> top-level row contains many children.  The treeview works fine except 
> >> for one thing.  If the user expands a top-level row, selects a child, 
> >> and then collapses that row the program seg faults with the console 
> >> error:
> >>
> >> gtk_tree_store_get_value: assertion `iter->stamp == GTK_TREE_STORE 
> >> (tree_model)->stamp' failed
> >> gtype.c:3351: type id `0' is invalid
> >> can't peek value table for type `' which is not currently 
> >> referenced
> 
> > Without seeing the code I can only guess.  I seems that the iter your 
> > using is invalid -- or no longer valid.  This could occur if you used a 
> > LOCAL variable to create the iter; then saved the pointer of that inter 
> > and tried to use it somewhere else which creates the segfault.
> >
> > To poke around looking for it, use this api to test iters before use: 
> > bool=gtk_tree_store_iter_is_valid(GtkTreeStore *tree_model, GtkTreeIter 
> > *iter)
> 
> I apologize for not posting the code originally.  See below.
> 
> I don't quite understand how the gtk_tree_store_iter_is_valid() function 
> will help me since the seg fault occurs when the top-level row is 
> collapsed and is (seemingly ?) out of my control.
> 
> 
> 
> void
> TeamSelected2 (GtkTreeSelection *selection) {
>  GtkTreeModel *model;
>  GtkTreePath *path;
>  GtkTreeIter iter;
>  gint sub, row_count, x;
>  gchar *teamname, path_str[10] = " ";
>  gboolean valid;
> 
>  gtk_tree_selection_get_selected (selection, &model, &iter);


The gtk_tree_selection_get_selected() api returns TRUE is something is
selected.  You never checked its return value!

consider doing this:

 if (selection == NULL) {
return;
}

if ( !( gtk_tree_selection_get_selected (selection, &model, &iter) ) )
{
   return;
}

   

>  gtk_tree_model_get (model, &iter, NAME_COLUMN, &teamname, -1);
> 
>  if (strlen (teamname) == 4)
>  /* user clicked on a year */
>  return;
> 

Not sure what your looking for here?  you already have the iter to the selected 
row?

> 
>  for (sub = row_count = 0; sub < toplevelentries; sub++, row_count = 0) {
>  /* walk through the root level of data (years) */
>  sprintf (&path_str[0], "%d:0", sub);
>  path = gtk_tree_path_new_from_string (&path_str[0]);
> 
>  valid = gtk_tree_model_get_iter (model, &iter, path);
>  while (valid) {
>  /* walk through the sub-level (teams), looking for the selected 
> row */
>  if (gtk_tree_selection_iter_is_selected (selection, &iter) == 
> TRUE)
>  /* get out of the for() loop */
>  goto GetOutFor;
> 
>  row_count++;
>  valid = gtk_tree_model_iter_next (model, &iter);
>  }
>  }
> GetOutFor:
> 
> [do some processing and return]
> 
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: GTK plot graph

2007-06-29 Thread James Scott Jr
Dieterle,

If you would like an even simpler example/tool - pick up glinegraph from
this link http://sourceforge.net/project/showfiles.php?group_id=157888

It does exactly what I needed and may work for you.

James,


On Fri, 2007-06-29 at 12:06 +0200, Daniel Dieterle wrote:
> Hey,
> 
> after googling: "draw curves in gtk"
> 
> i found the gtk+extra packages. I think GtkPlot is what i need.
> 
> Sorry for disturbing you. Perhaps this contribution helps the next guy
> to find the right tool.
> 
> Daniel.
> 
> 
> 
> On Fri, 2007-06-29 at 11:45 +0200, Daniel Dieterle wrote:
> > Hi,
> > 
> > my goal is to plot a simple array of floating-values in a gtk plot.
> > I want some basic operations on the graph, like zooming in/out, fast
> > redrawing of the graph , ...
> > 
> > - gtk-curve seems not to be poweful enough.
> > Also: "This widget is considered too specialized/little-used for GTK+,
> > and will in the future be moved to some other package." from the
> > gtk-API. So it seems not to good.
> > 
> > - there seems a way to user gnu-plot, which is interesting, but i
> > doesn't want of performance reasons.
> > 
> > 
> > Isn't there a easy and powerful way to plot graphs in GTK?
> > 
> > Thanks,
> > 
> > Daniel.
> > 
> > PS:
> > - Platform: Linux
> > - Language: c
> > 
> > ___
> > 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: waveform display in gtk

2007-07-17 Thread James Scott Jr
The GIW package at http://giw.sourceforge.net/ contains a linegraph
which may work for you application.  There is a screenshot to help you
evaluate.

James,

On Thu, 2007-07-12 at 11:53 +0100, Iain * wrote:
> On 7/12/07, Stefan Kost <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > there is a few. Jokosher, Swami, they all have one. Unfortunately a
> > waveform display is quite specific - its not easy to come up with a
> > generic one. Some need markers, some need range-selection.
> >
> 
> There's one in marlin, but its fairly tied into how marlin stores audio 
> samples.
> 
> iain
> ___
> 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: gtk_widget_show() not showing window

2007-08-27 Thread James Scott Jr
Try this instead.  The gtk_widget_show_all() then gtk_widget_hide() then
gtk_widget_show() is the cause of your problem; unless you were thinking
the window should blink once before appearing.

James,

#include 

> 
> static void
> button_clicked_cb(GtkButton *button, gpointer data)
> {
>   GtkWidget *window2;
>   window2 = gtk_window_new(GTK_WINDOW_TOPLEVEL);
>   gtk_widget_show_all(window2);
> }
> 
> int
> main(int argc, char **argv)
> {
>   GtkWidget *window;
>   GtkWidget *button;
> 
>   gtk_init(&argc, &argv);
> 
>   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
>   g_signal_connect(G_OBJECT(window), "delete_event",
>G_CALLBACK(gtk_main_quit), NULL);
> 
>   button = gtk_button_new_with_label("Click me");
>   g_signal_connect(G_OBJECT(button), "clicked",
>G_CALLBACK(button_clicked_cb), NULL);
>   gtk_container_add(GTK_CONTAINER(window), button);
> 
>   gtk_widget_show_all(window);
>   gtk_main();
> 
>   return 0;
> }


On Mon, 2007-08-27 at 19:00 +, G. Paul Ziemba wrote:

> Greetings,
> 
> gtk_widget_show() does not seem to be operating the way I expect;
> could one of the experts please tell me if something is wrong with
> this code or if something is wrong with gtk?
> 
> When I run this small bit of code, the window appears briefly
> and then disappears immediately. The program does not exit.
> I expect the window to stay visible (due to gtk_widget_show()),
> but it's not happening.
> 
> many thanks!
> 
> Versions:
> OS: FreeBSD 6.2-STABLE #0: Sun Jun  3 19:55:09 PDT 2007
> gtk: gtk-2.10.12, gtk-2.10.14
> 
> 
> Test program compiled with:
> gcc -o test test.c `pkg-config --cflags --libs gtk+-2.0`
> 
> Test Program:
> #include 
> 
> static void
> button_clicked_cb(GtkButton *button, gpointer data)
> {
>   GtkWidget *window2;
>   window2 = gtk_window_new(GTK_WINDOW_TOPLEVEL);
>   gtk_widget_show_all(window2);
>   gtk_widget_hide(window2);
>   gtk_widget_show(window2);
> }
> 
> int
> main(int argc, char **argv)
> {
>   GtkWidget *window;
>   GtkWidget *button;
> 
>   gtk_init(&argc, &argv);
> 
>   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
>   g_signal_connect(G_OBJECT(window), "delete_event",
>G_CALLBACK(gtk_main_quit), NULL);
> 
>   button = gtk_button_new_with_label("Click me");
>   g_signal_connect(G_OBJECT(button), "clicked",
>G_CALLBACK(button_clicked_cb), NULL);
>   gtk_container_add(GTK_CONTAINER(window), button);
> 
>   gtk_widget_show_all(window);
>   gtk_widget_hide(window);
>   gtk_widget_show(window);
> 
>   gtk_main();
> 
>   return 0;
> }
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: gtk_widget_show() not showing window

2007-09-02 Thread James Scott Jr
Paul,

I am not sure if you got an answer, so here is my expectation - am I am
no expert.  
GTK _show/_hide api have an impact on the expose or painting function of
gtk widgets.  This effect is a consolidation of area needing repaint as
a result of many factors.  Thus a _show_all. _hide, and _show should be
netted to the effect of a single  gtk_widget_show(); unless there is an
opportunity to process the gtk_main() loop in between calls; and I
didn't see that.
Is this your experience?

James,

On Tue, 2007-08-28 at 06:58 +, G. Paul Ziemba wrote:

> >On Mon, 2007-08-27 at 19:00 +, G. Paul Ziemba wrote:
> >>gtk_widget_show_all(window);
> >>gtk_widget_hide(window);
> >>gtk_widget_show(window);
> >> 
> >>    gtk_main();
> 
> 
> [EMAIL PROTECTED] (James Scott Jr) writes:
> 
> >Try this instead.  The gtk_widget_show_all() then gtk_widget_hide() then
> >gtk_widget_show() is the cause of your problem; unless you were thinking
> >the window should blink once before appearing.
> 
> >>gtk_widget_show_all(window);
> >>gtk_main();
> 
> Thank you for your suggestion - I must apologize because
> I should have mentioned (but forgot) in my original post that I
> am actually trying/helping to debug a problem in a larger piece 
> of software (http://bugzilla.gnome.org/show_bug.cgi?id=467776).
> 
> This test program is a minimal set of code that demonstrates
> the problem. My real question is, should the show_all/hide/show
> sequence work?
> 
> thanks,
> 
>  ~!paul
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: gtk pango draw rotated text

2007-09-09 Thread James Scott Jr
Take a look at the excellent example in the program 'gtk-demo', which
should be installed on your system already.
Try '# gtk-demo', then choose the 'rotated text' example.  Note:
double-clinking the choice launches the example, also notice the two
tabs - one show description, one show the actual code.

James,

On Mon, 2007-09-10 at 00:33 +0100, Luis Rodrigues wrote:

> Hi,
> 
> I want to draw some rotated text on a Window. I've tried every code I
> found on the net but still no solution :(
> 
> I would like to draw some rotated text on a window, the rotation point
> should X,Y and not to the center of the rectangle where the text is
> draw.
> 
> Can anyone please help me?
> 
> This is my current code (in pascal):
> 
> WidgetCont := pango_layout_get_context(UseFont);
> rotated_matrix.xx := 1.0;
> rotated_matrix.xy := 0.0;
> rotated_matrix.yx := 0.0;
> rotated_matrix.yy := 1.0;
> rotated_matrix.x0 := 0.0;
> rotated_matrix.y0 := 0.0;
> pango_matrix_rotate (@rotated_matrix, 45);
> pango_context_set_matrix (WidgetCont, @rotated_matrix);
> pango_layout_context_changed (UseFont); 
> gdk_draw_layout_with_colors(DevCtx.drawable, DevCtx.GC, X, Y, UseFont,
> Foreground, nil);
> 
> 
> Thanks in advance.
> 
> Luis
> 
> 
> ___
> 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: Row number in TreeView

2007-09-15 Thread James Scott Jr
LUK,

One way is to create a Selection when you define the treeview, then
whenever a double-click selection occurs your callback will be called
with its parms point to the row that was selected.  the callbacks params
will have the current and correct path as input params.

review this tutorial for selections for information and review the
examples include in 'gtk-demo'; a gtk demonstration program installed on
your machine when gtk's development libs were installed.  try '#
gtk-demo" then choose treeviews.

GTK TreeView Tutorial  http://scentric.net/tutorial/

James,

On Sun, 2007-09-16 at 00:32 +0100, Lukasz Gromotowicz wrote:

> Hi all,
> 
> I know it is probably something simple, but I am new to the gtk. I have a
> TreeView and associated ListStore. I am trying to get the row number after I
> double-click on it. I have a "path" which I think I should use, but I do not
> know how.
> 
> Could anybody help me please?
> 
> Best regards,
> LUK
> ___
> 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: Row number in TreeView

2007-09-17 Thread James Scott Jr
LUK,

This link answers your original "double-click" question!  Read the
Tutorial!
http://scentric.net/tutorial/sec-selections-double-click.html

James ,

On Mon, 2007-09-17 at 09:29 +0100, Lukasz Gromotowicz wrote:

> Thanks for the response. I still have a problem. Maybe because I use GTKmm.
> I have signal_row_activated connected to the  function:
> void TMainWindow::on_TreeView1_dblclick(
> const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*
> tvcolumn)
> 
> I have taken it from GTKmm documentation.
> in this function I put what you suggested:
> 
> gint* i = gtk_tree_path_get_indices (path);
> 
> Compilation returns an error:
> cannot convert 'const Gtk::TreePath' to 'GtkTreePath*' for argument '1' to
> 'gint* gtk_tree_path_get_indices(GtkTreePath*)'
> 
> What should I change? Where to find the clear explanation of the TreeView
> widget (gtk.org and gtkmm.org are the best places?)
> 
> Does GTKmm defines EVERYTHING from the GTK+ or sometimes I will have to use
> functions from the GTK+?
> 
> Best regards,
> LUK
> 
> 2007/9/16, Claudio Saavedra <[EMAIL PROTECTED]>:
> >
> >
> > El dom, 16-09-2007 a las 00:32 +0100, Lukasz Gromotowicz escribió:
> > > Hi all,
> > >
> > > I know it is probably something simple, but I am new to the gtk. I have
> > a
> > > TreeView and associated ListStore. I am trying to get the row number
> > after I
> > > double-click on it. I have a "path" which I think I should use, but I do
> > not
> > > know how.
> >
> > With gtk_tree_path_get_indices ().
> >
> > Claudio
> >
> > --
> > Claudio Saavedra  <[EMAIL PROTECTED]>
> >
> > Día del Software Libre, Curicó  http://curico.diadelsoftwarelibre.cl
> >
> >
> ___
> 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: GtkNotebookPage

2007-09-30 Thread James Scott Jr
On Sun, 2007-09-30 at 10:07 -0400, dhk wrote:

> I have a notebook with a treeview on each page.  I'm trying to reference
> a treeview on a notebook tab when it is clicked and compare it to
> another treeview on another tab; I'm using the "switch-page" signal.
> The treeviews are in vbox's in the tabs and I can't seem to get to the
> one on the tab that was clicked.  The callback is like this . . .
> 
> void
> on_ipm_notebook1_switch_page  (GtkNotebook *notebook,
> GtkNotebookPage *page,
> guintpage_num,
> gpointer user_data)
> {
>   GtkWidget *tv=(GtkWidget *)user_data;
>   /* the treeview is in c_page */
>   GtkWidget *c_page=gtk_notebook_get_nth_page(notebook, page_num);
> 
> }
> 


When creating the notebook page and treeview.  set the treeview's
pointer into the vbox as userdata, then during the callback routine get
that userdata or pointer.  now you have the pointer to the treeview,
preform normal treeview operation.

During Create:
g_object_set_data (G_OBJECT(vbox), "TreeView-ptr", (gpointer)ptreeview);

During Callback:
treeview = (GtkTreeView *)g_object_get_data (G_OBJECT(page),
"TreeView-ptr");

Note: from the callback param list, '*page' is the value you supplied to
'gtk_notebook_append_page(p1, p2,p3)' as p2.  This would normally be
your vbox.

James,


> How would I get the treeview that's on the c_page?  Is there a way to
> send more than one object in with user_data?  user_data doesn't seem to
> like pointer-to-pointer (GtkWidget **tv) data.
> 
> Also, what can you do with the GtkNotebookPage object?  I don't see why
> this is passed in since there doesn't seem to be a way to use it.
> 
> Thanks in advance,
> 
> --dhk
> 
> ___
> 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: timeout function not called

2007-10-03 Thread James Scott Jr
On Tue, 2007-10-02 at 10:51 -0400, [EMAIL PROTECTED] wrote:

> I'm still muddling my way through my first GTK application (and I'm a 
> relative newbie on all software matters).
> 
> I have the following in one of my callbacks:
> 
> timer = g_timout_add(50, (GSourceFunc) progress_update, 
> (gpointer)progressbar);
> 
> pid = fork( );
> 
> if (pid == 0)
> {
>  growPart ( );
>  exit(0);
> }
> ret = wait(NULL);
> 
> g_source_remove(timer);
> 
> ---
> 
> where progress_update is:
> 
> static gboolean progress_update (gpointer progressbar)
> {
>gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar));
>return true;
> }
> 
> 
> 
> I was hoping that this would mean that the progress bar would pulse while 
> growPart() was running, but instead it waits until after (is this because 
> control hasn't been returned to gtk_main yet?) at which point it is 
> removed. If I take out the g_source_remove it runs beautifullybut only 
> after growPart has completed. How can I get around this?
> 
> Thanks so much
> 


The use of FORK is a little odd, I don't think  I've seen that used in a
GTK program before.  The ret=wait(null) causes execution to stop at that
point and wait for growPart() to finish.  A way to get around the
logistics of fork() is to use threads directly.  Consider the following;

/* globals */
gboolean  b_pulse_control = FALSE
GThread  *grow_thread_id = NULL;
gint   global_ret = 0;


b_pulse_control = TRUE;
timer = g_timeout_add(50, (GSourceFunc) progress_update,
(gpointer)progressbar);

grow_thread_id = g_thread_create ( growPart_thread, &b_pulse_control,
TRUE, NULL);


static gboolean progress_update (gpointer progressbar)
{
 if (b_pulse_control)
{
 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar));
 return true;
} else {
global_ret = GPOINTER_TO_INT( g_thread_join (grow_thread)  );
return FALSE;
}

}

static gpointer growPart_thread(gpointer b_pulse)
{

 /* do work */
 growPart();

 *b_pulse = FALSE;
 g_thread_exit( GINT_TO_POINTER( 1 ) );

}

I would do the passing of control values via a structure to avoid the use of 
globals, but this should work for you.

James,


> 
> This is an e-mail from General Dynamics Land Systems. It is for the intended 
> recipient only and may contain confidential and privileged information.  No 
> one else may read, print, store, copy, forward or act in reliance on it or 
> its attachments.  If you are not the intended recipient, please return this 
> message to the sender and delete the message and any attachments from your 
> computer. Your cooperation is appreciated.
> 
> ___
> 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: timeout function not called

2007-10-04 Thread James Scott Jr
On Thu, 2007-10-04 at 13:27 -0700, [EMAIL PROTECTED] wrote:

> Thanks James for giving me my first experience with Thread programming!
> I tried the code you sent me, but unfortunately, I still can't get the  
> progress_update
> function to run, looks like it never gets called. Any idea why this  
> might be happening?
> growPart still runs.
> 
> Thanks,
> 
> Vicki
> 


The code i offered is really high level - almost sudo code.  I prefer to
evaluate a fuller example, if you care to post the whole program - or
email it to me and I will email it back.

Things I would be interested in would be as follows;
1. did you do away with the fork() and wait() calls?
2. did you compile it with something like this - with gthread included?
"# gcc -Wall `pkg-config --libs --cflags gtk+-2.0 glib-2.0
gthread-2.0` program.c "
3. Did you call g_thread_init() in main(). ?
/*
 * Initialize GLib thread support and GTK
 */
g_type_init ();
g_thread_init (NULL);
gdk_threads_init ();
gtk_init (&argc, &argv);
/* create app window */
/* create progress bar dialog */

/*
 * enter the GTK main loop
 */
gdk_threads_enter ();
gtk_main ();
gdk_flush ();
gdk_threads_leave ();
return (0);

4. How long does growPart() run? longer than 100ms
the g_timeout_add() is only for 50ms, and it waits 50ms before
making the first call kinda short, try 250 or 400

5. Assuming your created a dialog box for the progress bar and thats is
is visible it should have ran.  Stick a g_debug("update"); in the
progress_update() routine after the call to gtk_progress_bar_pulse()

6. I'm thinking the most likely cause is how the program was compiled.
send me some code to look at!

James,

> 
> [Hide Quoted Text]
> GTK program before.  The ret=wait(null) causes execution to stop at that
> 
> point and wait for growPart() to finish.  A way to get around the  
> logistics of fork() is to use threads directly.  Consider the following;
> 
> /* globals */
> gboolean  b_pulse_control = FALSE
> GThread  *grow_thread_id = NULL;
> gint   global_ret = 0;
> 
> 
> b_pulse_control = TRUE;
> timer = g_timeout_add(50, (GSourceFunc) progress_update,
> (gpointer)progressbar);
> 
> grow_thread_id = g_thread_create ( growPart_thread, &b_pulse_control,
> TRUE, NULL);
> 
> 
> static gboolean progress_update (gpointer progressbar)
> {
>   if (b_pulse_control)
>  {
>   gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar));
>   return true;
>  } else {
>  global_ret = GPOINTER_TO_INT( g_thread_join (grow_thread)  );
>  return FALSE;
>  }
> 
> }
> 
> static gpointer growPart_thread(gpointer b_pulse)
> {
> 
>   /* do work */
>   growPart();
> 
>   *b_pulse = FALSE;
>   g_thread_exit( GINT_TO_POINTER( 1 ) );
> 
> }
> 
> I would do the passing of control values via a structure to avoid  the  
> use of globals,
> but this should work for you.
> 
> 
> --
> Invent your own San Diego at sandiego.com!
> 
> 
> ___
> 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: timeout function not called

2007-10-05 Thread James Scott Jr
Vicki,
Here is a more complete example of how to resolve your issue.
Compile with this command
'# gcc -Wall -g -O2 `pkg-config --libs --cflags gtk+-2.0 glib-2.0
gthread-2.0` gprogress.c'

BEGIN-CODE

#include 


/* no globals */
typedef struct _INSTANCE_VALUES 
{
GtkWidget *progressbar;
GThread   *tid_growPart;
gboolean   b_pulse_control;
gint   i_growPart_rc;
} STEMP, *PST;

#ifndef EXIT_FAILURE
#define EXIT_FAILURE 1
#define EXIT_SUCESS 0
#endif  

static gpointer fn_growPart (PST pInstance);
static gboolean fn_progress_update (PST pInstance);
static void cb_push_button_clicked (GtkButton *button, PST pInstance);
int main (int argc, char *argv[]);


int main (int argc, char *argv[])
{ 
  GtkWidget *window = NULL;
  GtkWidget *widget = NULL;
  GtkWidget *box = NULL;
  PSTpInstance = NULL;

  g_thread_init (NULL);
  gdk_threads_init ();
  gtk_init (&argc, &argv);

  pInstance = g_new0 (STEMP, 1);
g_return_val_if_fail (pInstance != NULL, -1);
  
  /* create app window */
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  g_signal_connect(window, "delete-event", gtk_main_quit, NULL);
  gtk_window_set_title (GTK_WINDOW (window), "GrowPart Thread Example");
  
  box = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER(window), box);   
  
  pInstance->progressbar = gtk_progress_bar_new ();
gtk_progress_bar_set_text (GTK_PROGRESS_BAR(pInstance->progressbar),
"Not Running!");
gtk_box_pack_start (GTK_BOX(box), pInstance->progressbar, TRUE, TRUE,
0);
  
 widget = gtk_button_new_from_stock (GTK_STOCK_APPLY);
 g_signal_connect (G_OBJECT(widget), "clicked", 
   G_CALLBACK(cb_push_button_clicked), 
pInstance);
 gtk_box_pack_end (GTK_BOX(box), widget, TRUE, TRUE, 0);
 
 gtk_widget_show_all (GTK_WIDGET(window));

 /*
  * enter the GTK main loop
  */
  gdk_threads_enter ();
  gtk_main ();
  gdk_threads_leave ();

  g_free (pInstance);
  
 return 0;
}

static void cb_push_button_clicked (GtkButton *button, PST pInstance)
{
  g_return_if_fail (pInstance != NULL);

  pInstance->b_pulse_control = TRUE;
  gtk_progress_bar_set_text (GTK_PROGRESS_BAR(pInstance->progressbar),
"Please Wait!");  
  g_timeout_add(100, (GSourceFunc)fn_progress_update, pInstance);
  pInstance->tid_growPart = g_thread_create ( (GThreadFunc)fn_growPart,
pInstance, TRUE, NULL);
}

static gboolean fn_progress_update (PST pInstance)
{
g_return_val_if_fail (pInstance != NULL, FALSE);

 if (pInstance->b_pulse_control)
{
 gtk_progress_bar_pulse
(GTK_PROGRESS_BAR(pInstance->progressbar));
 return TRUE;
} else {
pInstance->i_growPart_rc = GPOINTER_TO_INT( g_thread_join
(pInstance->tid_growPart)  );
gtk_progress_bar_set_text
(GTK_PROGRESS_BAR(pInstance->progressbar), "Not Running!");
gtk_progress_bar_set_fraction
(GTK_PROGRESS_BAR(pInstance->progressbar),0.0);
return FALSE;
}

}

/* 
 * gthread routine
 * -- never do any gtk calls from this thread - NEVER
*/
static gpointer fn_growPart (PST pInstance)
{
  gint i_index = 0;

  if (pInstance == NULL) {
  g_thread_exit( GINT_TO_POINTER(EXIT_FAILURE) );
  }
  
 /* do work */
 /* growPart(); */
  
  while (i_index++ < 40) {
g_usleep (25);  /* 1/4 second * 40 = 10 seconds */
  }   

  pInstance->b_pulse_control = FALSE;
  
  g_thread_exit( GINT_TO_POINTER( EXIT_SUCESS ) );
  return NULL;
}


END-CODE

James,

On Thu, 2007-10-04 at 13:27 -0700, [EMAIL PROTECTED] wrote:

> Thanks James for giving me my first experience with Thread programming!
> I tried the code you sent me, but unfortunately, I still can't get the  
> progress_update
> function to run, looks like it never gets called. Any idea why this  
> might be happening?
> growPart still runs.
> 
> Thanks,
> 
> Vicki
> 
> 
> [Hide Quoted Text]
> GTK program before.  The ret=wait(null) causes execution to stop at that
> 
> point and wait for growPart() to finish.  A way to get around the  
> logistics of fork() is to use threads directly.  Consider the following;
> 
> /* globals */
> gboolean  b_pulse_control = FALSE
> GThread  *grow_thread_id = NULL;
> gint   global_ret = 0;
> 
> 
> b_pulse_control = TRUE;
> timer = g_timeout_add(50, (GSourceFunc) progress_update,
> (gpointer)progressbar);
> 
> grow_thread_id = g_thread_create ( growPart_thread, &b_pulse_control,
> TRUE, NULL);
> 
> 
> static gboolean progress_update (gpointer progressbar)
> {
>   if (b_pulse_control)
>  {
>   gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar));
>   return true;
>  } else {
>  global_ret = GPOINTER_TO_INT( g_thread_join (grow_thread)  );
>  return FALSE;
>  }
> 
> }
> 
> static gpointer growPart_thread(gpointer b_pulse)
> {
> 
>   /* do work */
>   growPart();
> 
>   *b_pulse = FALSE;
>   g_thread_exit( GINT_TO_POINTER( 1 ) );
> 
> }
> 
> I would do the passing of con

Re: Text View Complaining about Double Free or Corruption

2008-02-26 Thread James Scott Jr
Mark,

I'm not sure what in your #include "common.h", but I placed the
following in mine

#include   /* for abort() */
#include  /* for gtk, gdk, and glib */

With that single change the program compiled and executed without error
message; as I would have expected.

James,

On Tue, 2008-02-26 at 01:29 -0500, Mark Rodriguez wrote:

> Was wondering if anybody has any idea(s) why the code below would seem
> to work fine on GTK/X11 (at least I don't see any error messages), but
> fail on GTK/DirectFB? When the application is exited by hitting the
> "Quit" button, I receive the following error message:
> 
> *** glibc detected *** TextDemo: double free or corruption (out): 0x4035b1b0 
> ***
> 
> I'm trying to figure out if this is a GTK related problem (i.e., am
> I'm doing something wrong in GTK) or a problem with GTK/DirectFB. I
> have to assume that my code IS the problem, but I just don't see where
> / how. Thanks in advance for any suggestions or help.
> 
> [code]
> #include "common.h"
> 
> GtkWidget* main_window;
> 
> static gboolean destroy_event(GtkWidget* widget, void* data)
> {
>gtk_main_quit();
>return FALSE;
> }
> 
> static void button_click_event(void)
> {
>gtk_widget_destroy(main_window);
> }
> 
> int main(int argc, char* argv[])
> {
>GtkWidget *text_view, *box, *button;
> 
>// initialize multi-threading within GLib
>g_thread_init(NULL);
> 
>// initialize multi-threading within GDK
>gdk_threads_init();
> 
>// acquire thread lock
>gdk_threads_enter();
>gtk_init(&argc, &argv);
> 
>// create main window
>main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
>if (main_window == NULL)
>abort();
>g_signal_connect(G_OBJECT(main_window), "destroy",
> G_CALLBACK(destroy_event), NULL);
>gtk_widget_show(main_window);
> 
>box = gtk_vbox_new(FALSE, 5);
>if (box == NULL)
>abort();
>gtk_widget_show(box);
>gtk_container_add(GTK_CONTAINER(main_window), box);
> 
>text_view = gtk_text_view_new();
>if (text_view == NULL)
>abort();
>gtk_widget_show(text_view);
>gtk_box_pack_start(GTK_BOX(box), text_view, TRUE, TRUE, 5);
> 
>button = gtk_button_new_with_label("Quit");
>if (button == NULL)
>abort();
>g_signal_connect(G_OBJECT(button), "clicked",
> G_CALLBACK(button_click_event), NULL);
>gtk_widget_show(button);
>gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 5);
> 
>// run the main loop
>gtk_main();
> 
>// release thread lock
>gdk_threads_leave();
> 
>return 0;
> }
> [/code]
> 
> --
> Mark
> ___
> 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: Text View Complaining about Double Free or Corruption

2008-02-26 Thread James Scott Jr

On Tue, 2008-02-26 at 20:51 -0500, Mark Rodriguez wrote:

> James,
> 
> >  I'm not sure what in your #include "common.h", but I placed the following
> > in mine
> >
> >  #include   /* for abort() */
> >  #include  /* for gtk, gdk, and glib */
> 
> I have a few other things, but these are included and the app also
> build fine for me. I can even run it under Ubuntu and it behaves
> exactly as I'd expect. It was pointed ou
> >  With that single change the program compiled and executed without error
> > message; as I would have expected.
> 
> Thanks for taking to time to respond.
> 
> I too can compile and run the application without any problems under
> Ubuntu; however, when I run the same application cross compiled under
> DirectFB/GTK, it complains about double free / corruption. It was
> pointed out the my destroy handler should actually be defined to
> return void, but this didn't seem to affect anything.


The "destroy" handler is an GObject handler that is signaled almost as
the last logical breath before the object is removed from active memory.
I can see no problem using this shutdown method and I have used the same
method in 10s of multi-threaded programs.

This might be worth a try.
 g_signal_connect (G_OBJECT (main_window), "destroy", G_CALLBACK
(gtk_main_quit), NULL); 
i.e. take the fastest way out, reducing stack overhead.


> The crazy thing is that I only get this error when adding a text view.
> All other widgets (buttons, pop-ups, labels, sliders, etc.) seem to
> work just fine. Is there anything different about a text view and
> calling gtk_widget_destroy on it's parent? Should I destroy the text
> view explicitly instead of relying on the parent to clean things up?
> Perhaps I should handle things myself and follow some "special" or
> "preferred" order when destroying the text view within the window?

No special or preferred method that I am aware of, and I use text_view all the 
time.  Contextually, your problem must should be related to your Direct/FB 
setup, rather than GTK internals.  However, I am not an expert just an 
experienced long time user.

When doe s the error occur? 
0. When program starts
1. When shutting down
2. When creating the text_view the first time
3. When creating the text_view the Nth time

I will assume it happens durin shutdown (#1).


> I assume the text view can be handled just like any other widget, but
> there appears to be something special or different about it.

Yes, it should be handled like any other widget.  The only special thing is its 
text_buffer!  Consider gtk_text_view_new_with_buffer(), one is created 
automatically for when using the gtk_text_view_new() api.  I don't think 
creating the GtkTextBuffer first would make any difference -- however, that 
where you are now.  So try creating the GtkTextBuffer first, then use the 
...with_buffer() api to create the view.  This may produce a different result.

If all else fails, try using gdb to get a backtrace to see which
modules/api generated that error message.

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


Re: Text View Complaining about Double Free or Corruption

2008-02-27 Thread James Scott Jr

On Wed, 2008-02-27 at 21:03 -0500, Mark Rodriguez wrote:

> James,
> 
> >  When doe s the error occur?
> >  0. When program starts
> >  1. When shutting down
> >  2. When creating the text_view the first time
> >  3. When creating the text_view the Nth time
> >
> >  I will assume it happens durin shutdown (#1).
> 
> Yes you are correct. In the "real" application, the application
> doesn't exit. It destroys the canvas and re-uses it with new controls.
> Rather than debug that [monster], I reduced the application to
> something more manageable that exhibit the same behavior.
> 
> >  Yes, it should be handled like any other widget.  The only special thing is
> > its text_buffer!  Consider gtk_text_view_new_with_buffer(), one is created
> > automatically for when using the gtk_text_view_new() api.  I don't think
> > creating the GtkTextBuffer first would make any difference -- however, that
> > where you are now.  So try creating the GtkTextBuffer first, then use the
> > ...with_buffer() api to create the view.  This may produce a different
> > result.
> 
> Interesting. I tried a few different things today and was able to get
> the application to work as expected without crashing, but I don't like
> the solution as now it appears I'm leaking memory. Any thoughts on why
> if g_object_unref is called the application complains about the double
> free? I modified the code as follows (mainly the button_click_event
> handler was changed to handle the text buffer and to require clicking
> the 'Quit' button twice for exiting the app - this was just done for
> visibility reasons).
> 

ref's are strange things: When I run into this anomaly I do the
following, reasoning that I must have only had a weak reference, and
g_object_unref got confused -- anyway this normally works for me.

/* creation code ... */
...
   buffer = gtk_text_buffer_new(NULL);
   if (buffer != NULL) {
 g_object_ref (G_OBJECT(buffer));
 gtk_object_sink (G_OBJECT(buffer));   
   }

sinking it ensures that you have a full fledged reference that a later
unref will honor.  

If your creating and deleting this text_view as needed, you will have to
find the root cause of these messages.  I notice that you prep'ed the
main() to use threads.  Your problem maybe related to how your using
threads when creating/destroying the text view.  I would suggest
exploring this type of change.  

1a. Only create/destroy in the main gtk/gdk thread.

1b. Fire off a g_timeout_add( 50, (GSourceFunc)fn_create_routine(),
gpointer); where "gboolean fn_create_routine(gpointer gp);" calls the
normal gtk_window_new() stuff to create a dialog or the window you plan
to use the text_view in.  All this gets you out of the normal gtk signal
chain of events.  signals iterate on themselves and I've seen unwinds
cause random errors - like your double-free.

1c. Do essentially the same to destroy the window.

2a. I guess I don't actually delete/destroy main windows once created, I
just hide them and present them again when needed.
2b. Or if I do destroy them, i keep the buffer and/or tree_model in a
allocated memory structure.  Thus gtk_text_view_new_with_buffer() is the
type of call I most often use to create text_views.

3.  You seem to be _show() ing objects before adding them to something.
Look at vbox; you create it, show it, then add it to the main.window.
The recommended style is to create, add, show.   I don't think causes
any immediate problems but it could be polluting something- anyway this
strikes me as something worth cleaning up.


James,




> [code]
> GtkWidget *main_window, *text_view, *box, *button;
> GtkTextBuffer* buffer;
> 
> static void destroy_event(GtkWidget* widget, void* data)
> {
>   gtk_main_quit();
> }
> 
> static void button_click_event(void)
> {
>   if (text_view != NULL)
>   {
>   gtk_container_remove(GTK_CONTAINER(box), text_view);
>   text_view = NULL;
>   // leaking memory???
> //g_object_unref(G_OBJECT(buffer));
>   buffer = NULL;
>   }
>   else
>   {
>   gtk_widget_destroy(main_window);
>   main_window = NULL;
>   }
> }
> 
> int main(int argc, char* argv[])
> {
>   // initialize multi-threading within GLib
>   g_thread_init(NULL);
> 
>   // initialize multi-threading within GDK
>   gdk_threads_init();
> 
>   // acquire thread lock
>   gdk_threads_enter();
>   gtk_init(&argc, &argv);
> 
>   // create main window
>   main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
>   if (main_window == NULL)
>   abort();
>   g_signal_connect(G_OBJECT(main_window), "destroy",
> G_CALLBACK(destroy_event), NULL);
>   gtk_widget_show(main_window);
> 
>   box = gtk_vbox_new(FALSE, 5);
>   if (box == NULL)
>   abort();
>   gtk_widget_show(box);
>   gtk_container_add(GTK_CONTAINER(main_window), box);
> 
>   buffer = gtk_text_buffer_new(NULL);
>  

Re: Text View Complaining about Double Free or Corruption

2008-02-27 Thread James Scott Jr
g_object_ref_sink() replaces gtk_object_sink() 

Please make this substitution

James, 


On Thu, 2008-02-28 at 00:04 -0500, James Scott Jr wrote:

> On Wed, 2008-02-27 at 21:03 -0500, Mark Rodriguez wrote:
> 
> > James,
> > 
> > >  When doe s the error occur?
> > >  0. When program starts
> > >  1. When shutting down
> > >  2. When creating the text_view the first time
> > >  3. When creating the text_view the Nth time
> > >
> > >  I will assume it happens durin shutdown (#1).
> > 
> > Yes you are correct. In the "real" application, the application
> > doesn't exit. It destroys the canvas and re-uses it with new controls.
> > Rather than debug that [monster], I reduced the application to
> > something more manageable that exhibit the same behavior.
> > 
> > >  Yes, it should be handled like any other widget.  The only special thing 
> > > is
> > > its text_buffer!  Consider gtk_text_view_new_with_buffer(), one is created
> > > automatically for when using the gtk_text_view_new() api.  I don't think
> > > creating the GtkTextBuffer first would make any difference -- however, 
> > > that
> > > where you are now.  So try creating the GtkTextBuffer first, then use the
> > > ...with_buffer() api to create the view.  This may produce a different
> > > result.
> > 
> > Interesting. I tried a few different things today and was able to get
> > the application to work as expected without crashing, but I don't like
> > the solution as now it appears I'm leaking memory. Any thoughts on why
> > if g_object_unref is called the application complains about the double
> > free? I modified the code as follows (mainly the button_click_event
> > handler was changed to handle the text buffer and to require clicking
> > the 'Quit' button twice for exiting the app - this was just done for
> > visibility reasons).
> > 
> 
> ref's are strange things: When I run into this anomaly I do the
> following, reasoning that I must have only had a weak reference, and
> g_object_unref got confused -- anyway this normally works for me.
> 
> /* creation code ... */
> ...
>buffer = gtk_text_buffer_new(NULL);
>if (buffer != NULL) {
>  g_object_ref (G_OBJECT(buffer));
>  gtk_object_sink (G_OBJECT(buffer));   
>}
> 
> sinking it ensures that you have a full fledged reference that a later
> unref will honor.  
> 
> If your creating and deleting this text_view as needed, you will have to
> find the root cause of these messages.  I notice that you prep'ed the
> main() to use threads.  Your problem maybe related to how your using
> threads when creating/destroying the text view.  I would suggest
> exploring this type of change.  
> 
> 1a. Only create/destroy in the main gtk/gdk thread.
> 
> 1b. Fire off a g_timeout_add( 50, (GSourceFunc)fn_create_routine(),
> gpointer); where "gboolean fn_create_routine(gpointer gp);" calls the
> normal gtk_window_new() stuff to create a dialog or the window you plan
> to use the text_view in.  All this gets you out of the normal gtk signal
> chain of events.  signals iterate on themselves and I've seen unwinds
> cause random errors - like your double-free.
> 
> 1c. Do essentially the same to destroy the window.
> 
> 2a. I guess I don't actually delete/destroy main windows once created, I
> just hide them and present them again when needed.
> 2b. Or if I do destroy them, i keep the buffer and/or tree_model in a
> allocated memory structure.  Thus gtk_text_view_new_with_buffer() is the
> type of call I most often use to create text_views.
> 
> 3.  You seem to be _show() ing objects before adding them to something.
> Look at vbox; you create it, show it, then add it to the main.window.
> The recommended style is to create, add, show.   I don't think causes
> any immediate problems but it could be polluting something- anyway this
> strikes me as something worth cleaning up.
> 
> 
> James,
> 
> 
> 
> 
> > [code]
> > GtkWidget *main_window, *text_view, *box, *button;
> > GtkTextBuffer* buffer;
> > 
> > static void destroy_event(GtkWidget* widget, void* data)
> > {
> > gtk_main_quit();
> > }
> > 
> > static void button_click_event(void)
> > {
> > if (text_view != NULL)
> > {
> > gtk_container_remove(GTK_CONTAINER(box), text_view);
> > text_view = NULL;
> > // leaking memory???
> > //  g_object_unref(G_OBJECT(buffer));
> > buffer = 

Re: gtk+ and eclipse problems

2008-03-25 Thread James Scott Jr
I have not explored the newest version of eclispe, which reports that it
supports the autoconfig framework inside it "Managed Make" features; so
there may be an easier way than this one.

I always add a 'Makefile' in my source directory that includes the
needed commands to build a gtk+ project.  eclispe then has a properties
tab that lets you choose the default build command "i.e. make'.  Here is
an example Makefile that should work for your sample.

James,

BEGIN-MAKEFILE  (indents are required to be  TABS)
## Build the example programs

FLAGS = -Wall -O2

CFLAGS  = `pkg-config --cflags --libs gtk+-2.0 glib-2.0 gthread-2.0` -lm
COFLAGS  = `pkg-config --cflags gtk+-2.0 >= 2.4.0 glib-2.0 >= 2.4.0
gthread-2.0` -lm

[EMAIL PROTECTED] $(FLAGS) $(CFLAGS)
[EMAIL PROTECTED] $(FLAGS) $(COFLAGS)

LINK_TARGET = your_program_name_here

all: $(LINK_TARGET) 
@echo All Done

%. : %.c
@echo "Compiling A" $<
$(CC) -o $@ -c $<
@echo "built " $<

%.o : %.c
@echo "Compiling B" $<
$(CO) -o $@ -c $<
@echo "built " $<

clean:
rm -fv *.o *~ $(LINK_TARGET)

END-MAKEFILE

On Tue, 2008-03-25 at 15:24 +0300, Roman Makurin wrote:

> Hi All!
> 
> It`s my first post to this list, so be patient :) I`ve got a problem
> with compiling gtk+ project in eclipse. Here is the simplest project
> from gtk tutorial:
> 
> #include 
> 
> int main( int   argc,
>   char *argv[] )
> {
> GtkWidget *window;
> 
> gtk_init (&argc, &argv);
> 
> window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
> gtk_widget_show  (window);
> 
> gtk_main ();
> 
> return 0;
> }
> 
> As you know, to get this working I need to pass additional options
> to gcc: `pkg-config --cflags --libs gtk+-2.0`. I think my problem
> is eclipse specific. I look through project settings but can`t find
> where to place above command. Is there any howto describing gtk+
> development with eclipse ? 
> 
> Thanks
> 
> PS: Sorry for my english
> 
> ___
> 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: Histogram and other statistical graphs

2008-04-28 Thread James Scott Jr
The GIW package maybe of interest to you.  Its at giw.sourceforge.net.
James,

On Wed, 2008-04-23 at 12:29 +0200, Roberto Mantovani - A&L wrote:

> Hi,
> 
> I need to write a program that displays some statistical values so I
> would know if there are libraries fot GTK+ to draw histograms and other
> statistical rapresentations.
> 
> Best regards,
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Lost Pointer when adding GTK+ to an application

2008-05-07 Thread James Scott Jr


On Wed, 2008-05-07 at 20:33 -0600, Diego Rivera wrote:
> Hi! I am not exactly new to GTK+, however I have come across a problem i
> have no explanation for, and I'll be glad if someone could point me towards
> a possible solution.
> 
> I am currently developing an application that uses various algorithms for
> sequence alignment in biological applications (DNA, RNA, Proteins and so
> on). This application is mainly for scientific purposes.
> 
> The core algorithms are already running fine as a console application in a
> very stable version. I am working in adding some graphical interface to the
> program using GTK+. So, I built a little Window that asks for the different
> parameters and makes a call to the already defined functions in the console
> application, which are indeed stable. However, when making the call to the
> algorithm with GTK+ running, some of the pointers in my data structures get
> lost, and I just get a Segmentation Fault.
> 
> While trying to debug this weird behavior, I have narrowed the problem to
> the fact of having a window running.
> 
> Right now, I just have a main that creates a GtkWindow with a GtkButton, and
> the callback of the button calls the stable routine of the console
> application using some "hard-wired" parameters. I have made tests and the
> console application gives the correct answer for those parameters. However,
> when calling the routine from the callback, Segmentation Fault is the only
> result I have been able to get.
> 
> I have tried with different versions of GTK+ and the outcome is persistent.
> 
> The data structure of the console application looks something like this:
> 
> typedef struct{
> int length;
> char* seq;
> }sequence_t;
> 
> typedef struct{
> int n;
> int m;
> int** table;
> }table_t;
> 
> typedef struct{
> sequence_t* vp;
> sequence_t* wp;
> table_t* table;
> int scoring;
> int result;
> }alignment_t;
> 
> Using gdb i have found that the Segmentation Fault occurs at some point when
> accesing the table from the alignment.
> 
> I believe i have made no memory errors in my console application, since it
> runs ok every time. However, i haven't seen the correct output from my GTK
> application.
> 
> Is there any hint that you could give me in order to correct the error?
> 
How did you add the GTK component to the existing console app; are they
one process or two?  

Your segfault suggest that they are two separate processes.  In which
case attempting to share memory elements will cause a segfault every
time no matter how correct and hard-coded the structures.

You may need to consider designing in and using some type of IPC
(Inter-Process Communications) like a named-pipe, shared-memory, socket
communications, memory queue, etc.  Something designed to communicate
between two active processes.

James,

> Thanks
> - Diego Rivera -
> ___
> 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: Lost Pointer when adding GTK+ to an application

2008-05-07 Thread James Scott Jr


On Wed, 2008-05-07 at 21:02 -0600, Diego Rivera wrote:
> Thanks for the quick answer, however, the GTK+ component is the same
> process as the Console application. The console application checks for
> some arguments and finishes by calling the working function of the
> application with parameters that reflect the arguments received from
> the console. My GtkButton callback just calls this last function with
> some parameters i have selected. 
> 
> So no inter-process communication is requiered
> 
> Thanks for the suggestion anyway
> 
OK, then you need to post some relevant portion of the code if possible.
These type of issues can be as casued by simple things like - using
local stack memory for structures vs malloc or g_new0() memory for them.

Post your main() and the callback for us to look at.  And please do
consider the valgrind suggestion, or retry the gdb exercise.

James,

> -Diego--
> 
> On Wed, May 7, 2008 at 8:55 PM, James Scott Jr <[EMAIL PROTECTED]>
> wrote:
> 
> 
> 
> On Wed, 2008-05-07 at 20:33 -0600, Diego Rivera wrote:
> > Hi! I am not exactly new to GTK+, however I have come across
> a problem i
> > have no explanation for, and I'll be glad if someone could
> point me towards
> > a possible solution.
> >
> > I am currently developing an application that uses various
> algorithms for
> > sequence alignment in biological applications (DNA, RNA,
> Proteins and so
> > on). This application is mainly for scientific purposes.
> >
> > The core algorithms are already running fine as a console
> application in a
> > very stable version. I am working in adding some graphical
> interface to the
> > program using GTK+. So, I built a little Window that asks
> for the different
> > parameters and makes a call to the already defined functions
> in the console
> > application, which are indeed stable. However, when making
> the call to the
> > algorithm with GTK+ running, some of the pointers in my data
> structures get
> > lost, and I just get a Segmentation Fault.
> >
> > While trying to debug this weird behavior, I have narrowed
> the problem to
> > the fact of having a window running.
> >
> > Right now, I just have a main that creates a GtkWindow with
> a GtkButton, and
> > the callback of the button calls the stable routine of the
> console
> > application using some "hard-wired" parameters. I have made
> tests and the
> > console application gives the correct answer for those
> parameters. However,
> > when calling the routine from the callback, Segmentation
> Fault is the only
> > result I have been able to get.
> >
> > I have tried with different versions of GTK+ and the outcome
> is persistent.
> >
> > The data structure of the console application looks
> something like this:
> >
> > typedef struct{
> > int length;
> > char* seq;
> > }sequence_t;
> >
> > typedef struct{
> > int n;
> > int m;
> > int** table;
> > }table_t;
> >
> > typedef struct{
> > sequence_t* vp;
> > sequence_t* wp;
> > table_t* table;
> > int scoring;
> > int result;
> > }alignment_t;
> >
> > Using gdb i have found that the Segmentation Fault occurs at
> some point when
> > accesing the table from the alignment.
> >
> > I believe i have made no memory errors in my console
> application, since it
> > runs ok every time. However, i haven't seen the correct
> output from my GTK
> > application.
> >
> > Is there any hint that you could give me in order to correct
> the error?
> >
> 
> How did you add the GTK component to the existing console app;
> are they
> one process or two?
> 
> Your segfault suggest that they are two separate processes.
>  In which
> case attempting to share memory element

Re: Column Values Changing in Treeview When Row Selected

2008-05-11 Thread James Scott Jr
Andrew,

I reviewed the code you supplied.  The gtk_tree_model_get() have the
correct column numbers, so the fact that PART_COLUMN_CLASS is changing
is interesting from a gcc compiler option perspective; but not cause for
the problems you are experiencing.

PART_COLUMN_CLASS should be a fixed enum value, and any changes to its
value are likely to be caused by optimizing compiler options - not
runtime issues. What are your compiler options; "-Wall -g -ansi -O2",
where -oh two(not zero two) is significant.  I'm going to ignore that
this number is changing - as its ability to change would cause chaos for
all of gtk which makes extensive use of enums.

Most likely cause of the behavior you describe!.  The *iter value is not
set to the currently selected row.  I.E no selection mechanisum being
used, or used incorrectly.

CODE EXAMPLE:

/* at the end of the treeview create routine */
...
GtkTreeSelection *part_select = NULL;
part_select = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
gtk_tree_selection_set_mode (part_select, GTK_SELECTION_SINGLE);
g_object_set_data (G_OBJECT (treeview), "selection-pointer", (gpointer) 
part_select);
...

/* 
 * in the supplied routine -- validate the selection first, 
 * then get/set data as originally shown 
*/
GtkTreeSelection *part_select = NULL;
GtkTreeIter iter;/* will get set to the selection */

part_select = (GtkTreeSelection *)g_object_get_data (G_OBJECT(treeview),
"selection-pointer");

if (gtk_tree_selection_get_selected (prod_select, NULL, &iter))
{
gtk_tree_model_get (model, &iter...);   /* NOTICE SYNTAX OF iter --> & */
/* -- set data */
}
else
{
   /* nothing selected */

}
 
END CODE EXAMPLE:

Maybe this is what was calling your original routine, I don't know.
These are tips, research and adapt to your program as needed.  The
thinking is to set treeview for single selection, and when selected get
the selected iter, then get the data.  Getting the selected iter ensure
you get the correct one each time.

g_object_get_data/g_object_set_data() are example ways of storing values
in the common object, so your routines don't need such a long parm list.

James,




On Sat, 2008-05-10 at 19:34 -0400, Andrew Rowland wrote:
> All,
> 
> I'm not sure what I'm doing wrong.  When I select a row in a treeview,
> the values of the columns are read and used to populate various entries
> and combos.  The thing that I can't figure out is that the value of one
> column is being changed to the value of another column.
> 
> Below is a snippet of the function (ANNOTATED IN CAPS) wherein the
> column value is changing.  Running my app in gdb, I've been able to
> figure out where the change is occurring, but not why.  I've looked at
> the API docs for GTK+ and studied the use of gtk_tree_model_get at
> codase.com.  I don't see anything in my code that should cause this
> behavior.  I've also tried to use gtk_tree_model_get_value and the same
> thing occurs.
> 
> Any pointer, hints, outright solutions, or swift kicks in the keister
> would be greatly appreciated.
> 
> TIA,
> 
> Andrew "Weibullguy" Rowland
> 
> --- CODE FOLLOWS ---
> 
> gboolean
> populate_part_general_tab( GtkTreeModel *model,
>GtkTreeIter  *iter )
> {
> 
> gchar *string = NULL;
> gfloat *floater;
> gint *integer;
> 
> /* Populate the usage information. */
> gtk_tree_model_get( model, iter, PART_COLUMN_PN, &string, -1 );
> gtk_entry_set_text( GTK_ENTRY(part_number), string );
> gtk_tree_model_get( model, iter, PART_COLUMN_REFDES, &string, -1 );
> gtk_entry_set_text( GTK_ENTRY(ref_des), string );
> gtk_tree_model_get( model, iter, PART_COLUMN_COMPREFDES, &string, -
> 1 );
> gtk_entry_set_text( GTK_ENTRY(comp_ref_des), string );
> gtk_tree_model_get( model, iter, PART_COLUMN_DESC, &string, - 1 );
> gtk_entry_set_text( GTK_ENTRY(description), string );
> gtk_tree_model_get( model, iter, PART_COLUMN_QUANT, &integer, - 1 );
> snprintf(string, 3, "%d", integer);
> gtk_entry_set_text( GTK_ENTRY(quantity), string );
> 
> /* Set the part type combo box. */
> gtk_tree_model_get( model, iter, PART_COLUMN_CLASS, &integer, - 1 );
> 
> AT THIS POINT THE VALUE OF PART_COLUMN_CLASS IS 1, WHICH IS CORRECT
> 
> gtk_combo_box_set_active( GTK_COMBO_BOX( part_type ), integer);
> 
> AT THIS POINT THE VALUE OF PART_COLUMN_CLASS IS 0, WHICH IS INCORRECT
> 
> /* Set the part subtype combo box. */
> gtk_tree_model_get( model, iter, PART_COLUMN_COMP_SUBTYPE, &integer,
> - 1 );
> 
> AT THIS POINT THE VALUE OF PART_COLUMN_CLASS IS 3, WHICH IS INCORRECT
> FOR PART_COLUMN_CLASS.  BUT IS THE CORRECT VALUE OF
> PART_COLUMN_COMP_SUBTYPE.
> 
> gtk_combo_box_set_active( GTK_COMBO_BOX( part_subclass ), integer );
> 

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


Re: Creating a non-focused window

2008-05-22 Thread James Scott Jr
Tom,

This might be a opportunity to explore and use 'libnotify' and have a
libnotify-popup present your message.

As for your original question, I don't have an answer that I treid and
know for certain will work.  However, This is what I would try by
changing my code; 1. I would reread the gtk api to understand if
gtk_widget_show() vs gtk_widget_show_all() vs gdk_window_present() would
make the messagebox/window visible without redirecting focus.
Otherwise, I would disable-focus, show the window, re-enable focus. 

On the other hand, libnotify should like the best way to proceed.  Here
is a quick sampler.

James,

** required rpms: yum install libnotify libnotify-devel

BEGIN CODE:
/* notice.c  

  Compile Command:
   $ gcc `pkg-config --cflags --libs libnotify` -o notice notice.c
   
  Usage:
   $ ./notice -s 5 -t "title of messagebox" -m "message in the box"
   or 
   $ ./notice --help

*/

#include 

/* cmd line var pointers */
static gchar   *gd_pch_title;
static gchar   *gd_pch_body;
static gchar   *gd_pch_icon;
static gint gd_i_seconds;

int main(int argc, char * argv[] ) 
{
NotifyNotification *nctx;  
GError  *gerror = NULL;
GOptionContext *context = NULL; /* --help message for command line
*/
GOptionEntry entries[] = {
  {"title", 't', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
&gd_pch_title,
 "Title text on msg box", "Title goes here!"},
  {"message", 'm', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
&gd_pch_body,
 "Message body text", "message"},
  {"icon-name", 'i', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
&gd_pch_icon,
 "icon to include next to message",
"gtk-dialog-info ...-warning ...-error"},
  {"show-seconds", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT,
&gd_i_seconds,
 "seconds to display message", "10"}, 
  {NULL}
};

/* Get command line parms */
context = g_option_context_new (
" - Commandline Notification Utility"
" GPL2 [2008] <[EMAIL PROTECTED]>");
g_option_context_add_main_entries(context, entries, NULL);

g_option_context_set_ignore_unknown_options(context, FALSE); 

g_option_context_set_help_enabled (context, TRUE);

if (!(g_option_context_parse(context, &argc, &argv, &gerror))) {
 g_warning ("Parse command line failed: %s", gerror->message);
 g_option_context_free(context);
 g_error_free(gerror);
 return (1);
}


if (gd_pch_title == NULL) {
gd_pch_title = "Title really needs to be here.";
}
if (gd_pch_body == NULL) {
gd_pch_body = "message goes here.";
}
if (gd_pch_icon == NULL) {
gd_pch_icon = "gtk-dialog-info";
}
if (gd_i_seconds < 1 ) {
gd_i_seconds = 10;
}
  
notify_init(argv[0]);

nctx = notify_notification_new (gd_pch_title, gd_pch_body,
gd_pch_icon, NULL); 

notify_notification_set_timeout (nctx, (gd_i_seconds * 1000) ); //
10 seconds

if (!notify_notification_show (nctx, NULL)) 
{
g_warning ("failed to send notification");
return 2;
}

g_object_unref(G_OBJECT(nctx));

notify_uninit();

return 0;
}

END CODE:



On Thu, 2008-05-22 at 17:26 -0700, Tom Machinski wrote:
> Hi,
> 
> I wrote a simple GTK+ application that displays a popup window.
> 
> The problem is that whenever the window is displayed, it immediately gets
> ("steals") the focus. I would like to prevent that from happening: i.e., the
> window should be created and displayed, but it should not be focused, but
> instead focus should be retained by whatever window had it before the
> creation of the new window.
> 
> The only way I know to do that is by calling window.set_accept_focus(False)
> before window.show(). The serious flaw with that method is that the
> resulting window, while being prevented from stealing the focus, also can
> not receive focus at any later time, even by intentional user action.
> 
> Any better approaches?
> 
> Tom
> ___
> 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: Creating a non-focused window

2008-05-24 Thread James Scott Jr
Tom,

The word "hint" almost always refers to a potential capability of the
Window Manager; meaning the wm does not have to honor the request or
feature.  Maybe your code is working and the wm is ignoring the request!

There might be a bug in gtk, however I would want to try a different wm
or something like xfce or kde, before going down the path.

James,


On Sat, 2008-05-24 at 14:40 -0400, Keith Maika wrote:
> Just throwing out a guess here, but could it be that the hint only works 
> on secondary windows?  Meaning, maybe the first window an app opens gets 
> focus and the hint is ignored, but subsequent windows work?  Not able to 
> test myself currently, just a thought I had.
> 
> Keith.
> Tom Machinski wrote:
> > On Fri, May 23, 2008 at 5:41 PM, Bill O'Connor <[EMAIL PROTECTED]> wrote:
> > 
> >> I can't make this work in either lang.
> >> I can check that the flag is being set with
> >> gtk_window_get_focus_on_map(), but it just doesn't do anything.
> >>
> >> My suggestion is that you not do this.  
> > 
> > 
> > Thanks for checking, Billy.
> > 
> > I'm not going to give up so easily, especially given the fact that GTK+'s
> > developers saw fit to provide that option.
> > 
> > Unless all of us here on this thread missed something, this looks like a bug
> > in GTK+ gtk_window_set_focus_on_map() method, and as such should be reported
> > and fixed.
> > 
> > Thanks,
> > 
> > Tom
> > 
> > --
> >> Billy O'Connor
> >>
> > ___
> > 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: Draw in a GdkPixbuf

2008-05-28 Thread James Scott Jr
Take a look at the executable 'gtk-demo'.  It should have been installed
with gtk's development tools; i.e. already loaded on you machine.  Hint:
double click the sample for a live preview, then look at the source
code.

Additionally, here is a link to glinegraph, a simple line graph widget
written twice, once in gdk and again in cairo.

http://sourceforge.net/project/showfiles.php?group_id=157888&package_id=191712

James,




On Thu, 2008-05-29 at 03:18 +0200, Luis Menina wrote:
> Hi list!
> 
> I'm trying to find a way to draw in a GdkPixbuf (for example draw a 
> rectangle on the pixbuf) and save the result to a file afterwards.
> 
> I found in devhelp the gdk_draw_* functions, but to use them I need a 
> GdkPixmap. gdk_pixmap_new requires a GdkDrawable. The problem is that 
> I'm developping a command line application, so I don't use GTK, only 
> glib, gdk, and gdk-pixbuf. Even creating the GdkPixmap with a NULL 
> GdkDrawable, I can't workaround the problem, because the documentation 
> of gdk_draw_pixbuf tells me that "All windows have a colormap, however, 
> pixmaps only have colormap by default if they were created with a 
> non-NULL window argument. Otherwise a colormap must be set on them with 
> gdk_drawable_set_colormap()". Trying to get a colormap requires other 
> stuff, which requires other stuff, and so on...
> 
> As this seems to be quite old-fashioned way of doing things, I tried to 
> see if cairo could do the trick. But it seems there's no way to draw to 
> a GdkPixbuf with cairo (I'm unfamiliar with cairo).
> 
> So, does anyone have an hint on how to draw and save an image from a 
> GdkPixbuf, with gdk or cairo ?
> 
> Thanks for you help,
> 
> Luis
> ___
> 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: Draw in a GdkPixbuf

2008-05-29 Thread James Scott Jr
Ok,

http://cairographics.org/examples/
http://live.gnome.org/GtkCairoIntegration

These links have some examples of using everything from a raw image to a
pdf as the backend in cairo from the command line -- without the use of
gtk.

Hope this fits your need better than my last response.

James,


On Thu, 2008-05-29 at 03:18 +0200, Luis Menina wrote:
> Hi list!
> 
> I'm trying to find a way to draw in a GdkPixbuf (for example draw a 
> rectangle on the pixbuf) and save the result to a file afterwards.
> 
> I found in devhelp the gdk_draw_* functions, but to use them I need a 
> GdkPixmap. gdk_pixmap_new requires a GdkDrawable. The problem is that 
> I'm developping a command line application, so I don't use GTK, only 
> glib, gdk, and gdk-pixbuf. Even creating the GdkPixmap with a NULL 
> GdkDrawable, I can't workaround the problem, because the documentation 
> of gdk_draw_pixbuf tells me that "All windows have a colormap, however, 
> pixmaps only have colormap by default if they were created with a 
> non-NULL window argument. Otherwise a colormap must be set on them with 
> gdk_drawable_set_colormap()". Trying to get a colormap requires other 
> stuff, which requires other stuff, and so on...
> 
> As this seems to be quite old-fashioned way of doing things, I tried to 
> see if cairo could do the trick. But it seems there's no way to draw to 
> a GdkPixbuf with cairo (I'm unfamiliar with cairo).
> 
> So, does anyone have an hint on how to draw and save an image from a 
> GdkPixbuf, with gdk or cairo ?
> 
> Thanks for you help,
> 
> Luis
> ___
> 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: new object, with variables

2008-06-11 Thread James Scott Jr
Kees,

I cannot seem figure out what your trying to do.  The code I see in the
notes is not something I understand; and I am an experienced gtk
developer.

Please back away from the code for a minute and try to describe what it
is your trying to achieve with this interface or application that
spawned this series of notes.  I'm hoping you just started off
completely wrong with the wrong assumptions about how to achieve your
goal.  In which case I/we can put you back on track.  But for now I
cannot keep up.

Why do I say this?
1. "i trying to make an object inherited from GTK_ACTION, this all is
managed."
Response: 
* If you want to inherit from GTK_ACTION you make a completely new
widget.  Look for info on writing widgets from scratch.  

* Wrapping a function around a g_object_new as you have done in both
examples is miss-leading at best.  You cannot make an existing
gtk_object do something it was not designed to; i.e. add a struct in its
object_new() parms.  You can g_object_set|get_data() on an existing
object; register a function for signal from an object so you can modify
its external behaviour, on and on...

Ok.  Back to "tell me what your trying to do?"

James,




On Wed, 2008-06-11 at 23:54 +0200, Kees Scherpenhuijzen wrote:
> 2008/5/14 Kees Scherpenhuijzen <[EMAIL PROTECTED]>:
> > heyy,
> >
> > @ the moment i trying to make an object inherited from GTK_ACTION,
> > this all is managed.
> > Only now i'm trying to initialize the object with an variable,  a
> > struct. Ie read the manual about the wrapper that is used, only i
> > can't seem
> > to find a way in which i can add the struct to g_object_new or otherwise.
> >
> > to be clear, in this function:
> > GtkAction*
> > menu_action_new (const gchar *name,
> > const gchar *label)
> > {
> >GtkAction* action;
> >_thunar_return_val_if_fail (name != NULL, NULL);
> >_thunar_return_val_if_fail (label != NULL, NULL);
> >
> >action = g_object_new (MENU_TYPE_ACTION,
> >   "hide-if-empty", FALSE,
> >   "label", label,
> >   "name", name,
> >   NULL);
> >return action;
> > }
> >
> > i want to add the struct so i don't need any get of set functions, is
> > this possible?
> >
> > the thing i want to do is to init :
> >  menu_thing*item;
> > in:
> > struct _MenuTemplatesAction
> > {
> >  GtkAction __parent__;
> >  menu_thing*item;
> > };
> >
> > I hope this enough info to get me close to an answer
> >
> >
> > --
> > Kees
> >
> 
> Hi,
> 
> I've saw some examples about this problem and tried it with no luck. i
> saw that the object was cast and just added.
> i've tried:
> GtkAction*
> menu_action_new (const gchar *name,
> const gchar *label,
> Model *model)
> {
>GtkAction* action;
>_thunar_return_val_if_fail (name != NULL, NULL);
>_thunar_return_val_if_fail (label != NULL, NULL);
> 
>action = g_object_new (MENU_TYPE_ACTION,
>   "hide-if-empty", FALSE,
>   "label", label,
>   "name", name,
>   NULL);
> 
>MENU_ACTION(action)->items = model;
> 
>if(G_TYPE_FUNDAMENTAL (action) == G_TYPE_OBJECT)
>{
>g_message(model->menu->name);
>g_message(action->items);
>g_message("test");
>}
>return action;
> }
> but it seems the second g_message won't print, it gives an segmentation fault.
> 
> extra info: #define MENU_ACTION(obj)
> (G_TYPE_CHECK_INSTANCE_CAST ((obj), MENU_TYPE_ACTION,
> MenuTemplatesAction))
> 
> What am i missing here?
> 
> Thanks in advance
> 

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


Re: new object, with variables

2008-06-12 Thread James Scott Jr


On Thu, 2008-06-12 at 11:12 +0200, Kees Scherpenhuijzen wrote:
> 2008/6/12, James Scott Jr <[EMAIL PROTECTED]>:
> > Kees,
> >
> > I cannot seem figure out what your trying to do.  The code I see in the
> > notes is not something I understand; and I am an experienced gtk
> > developer.
> >
> > Please back away from the code for a minute and try to describe what it
> > is your trying to achieve with this interface or application that
> > spawned this series of notes.  I'm hoping you just started off
> > completely wrong with the wrong assumptions about how to achieve your
> > goal.  In which case I/we can put you back on track.  But for now I
> > cannot keep up.
> >
> > Why do I say this?
> > 1. "i trying to make an object inherited from GTK_ACTION, this all is
> > managed."
> > Response:
> > * If you want to inherit from GTK_ACTION you make a completely new
> > widget.  Look for info on writing widgets from scratch.
> >
> > * Wrapping a function around a g_object_new as you have done in both
> > examples is miss-leading at best.  You cannot make an existing
> > gtk_object do something it was not designed to; i.e. add a struct in its
> > object_new() parms.  You can g_object_set|get_data() on an existing
> > object; register a function for signal from an object so you can modify
> > its external behaviour, on and on...
> >
> > Ok.  Back to "tell me what your trying to do?"
> >
> > James,
> >
> >
> >
> >
> > On Wed, 2008-06-11 at 23:54 +0200, Kees Scherpenhuijzen wrote:
> > > 2008/5/14 Kees Scherpenhuijzen <[EMAIL PROTECTED]>:
> > > > heyy,
> > > >
> > > > @ the moment i trying to make an object inherited from GTK_ACTION,
> > > > this all is managed.
> > > > Only now i'm trying to initialize the object with an variable,  a
> > > > struct. Ie read the manual about the wrapper that is used, only i
> > > > can't seem
> > > > to find a way in which i can add the struct to g_object_new or 
> > > > otherwise.
> > > >
> > > > to be clear, in this function:
> > > > GtkAction*
> > > > menu_action_new (const gchar *name,
> > > > const gchar *label)
> > > > {
> > > >GtkAction* action;
> > > >_thunar_return_val_if_fail (name != NULL, NULL);
> > > >_thunar_return_val_if_fail (label != NULL, NULL);
> > > >
> > > >action = g_object_new (MENU_TYPE_ACTION,
> > > >   "hide-if-empty", FALSE,
> > > >   "label", label,
> > > >   "name", name,
> > > >   NULL);
> > > >return action;
> > > > }
> > > >
> > > > i want to add the struct so i don't need any get of set functions, is
> > > > this possible?
> > > >
> > > > the thing i want to do is to init :
> > > >  menu_thing*item;
> > > > in:
> > > > struct _MenuTemplatesAction
> > > > {
> > > >  GtkAction __parent__;
> > > >  menu_thing*item;
> > > > };
> > > >
> > > > I hope this enough info to get me close to an answer
> > > >
> > > >
> > > > --
> > > > Kees
> > > >
> > >
> > > Hi,
> > >
> > > I've saw some examples about this problem and tried it with no luck. i
> > > saw that the object was cast and just added.
> > > i've tried:
> > > GtkAction*
> > > menu_action_new (const gchar *name,
> > > const gchar *label,
> > > Model *model)
> > > {
> > >GtkAction* action;
> > >_thunar_return_val_if_fail (name != NULL, NULL);
> > >_thunar_return_val_if_fail (label != NULL, NULL);
> > >
> > >action = g_object_new (MENU_TYPE_ACTION,
> > >   "hide-if-empty", FALSE,
> > >   "label", label,
> > >   "name", name,
> > >   NULL);
> > >
> > >MENU_ACTION(action)->items = mode

Re: Forking from Gtk

2008-07-07 Thread James Scott Jr
G,

The basic design decision to use fork() as a way to do work in the
background flawed.  fork()ing is not practical for gtk program.  While
fork() has been a valid option for many non-gui programs in the absence
of threads, either g_thread_create() or pthread_create().  Today it is
not very useful -- as in stop doing it now!

Consider instead using a valid multi-threaded implementation like
g_threads_xxx() for GTK based programs.  Or if full multi-threading is
not required, look at g_timeout_add() which is a background timer
routine that can serve as one or more background execution units; neatly
inside an gtk context.

$ devhelp
$ gtk-demo

The above two program you be pre-installed on your Linux machine:
devhelp has the gtk and glib api documentation, and gtk-demo shows you
many of the gtk/glib features in action.

Having said the multi-thread phrase, here is another word of caution.
In GTK only the main or ONE thread can safely interface with GTK api
calls that change the display.  Using more than one thread to call gtk
apis at the same time will fail or cause a sigfault.  The context of GTK
being your front-end to X11 is the source of this
none-thread-safe-caution; it is in how gtk MUST interact with X that
placing the multi-thread restriction.  There are elegant work-arounds
this issue.

Here is a link to the classic FAQ answer on Multi-threaded GTK programs:
http://library.gnome.org/devel/gtk-faq/stable/x482.html

Regards,
James,


On Mon, 2008-07-07 at 23:03 +0200, G Hasse wrote:
> Hello,
> 
> I have a small demo app. This works on FreeBSD but I can't
> get to work on Linux. I know that in Linux setsid will fail
> if the child has the same session_id as the parent. So on
> Linux you must fork twice. But it also seems that the parent
> must do an exit. And I don't want that. The code is not very
> long - so I include it here.
> 
> --
> //--
> //
> //  $Id: GtkFork.c,v 1.2 2008/07/07 20:29:17 gorhas Exp $
> //
> //  Experiment to run a thing in background
> //  This works on FreeBSD but not on Linux...
> //
> //  Build with
> //
> //  CFLAGS := `pkg-config glib-2.0 --cflags` `pkg-config gtk+-2.0 
> --cflags`
> //  LDFLAGS := `pkg-config glib-2.0 --libs` `pkg-config gtk+-2.0 --libs`
> //
> //  cc $(CFLAGS) -o GtkFork GtkFork.c $(LDFLAGS)
> //
> //--
> 
> #include 
> #include 
> #include 
> #include 
> #include 
> 
> //--
> // run_btn_callback
> //
> // Try to run something in the background
> //
> //--
> static void run_btn_callback (GtkWidget *button, gpointer data)
> {
> 
>int loops_to_run = 0;
>int i = 0;
>int pid = -1;
>int ret = -1;
> 
>// Skriv ut innehållet på skärmen 
>printf("Clicked..\n");
>printf("Data was: %s\n", gtk_entry_get_text( data ));
> 
>loops_to_run = atoi( gtk_entry_get_text(data));
> 
>// We dont want to wait very long...
>if( loops_to_run > 60 )
>{
>   loops_to_run = 60;
>   printf("Adjusting to 60 loops...\n");
>}
>printf("Loops to run: %d\n", loops_to_run );
> 
> 
> 
>printf("We make a daemon\n");
>if ( ( pid = fork() ) < 0 )
>{
>   // Something went wrong
>   printf("We could not fork just exit");
>   exit(-1);
>}
>else if ( pid != 0 )
>{
>   
>   // This is the parent process
>   printf("The background process have pid:  %d\n", pid);
>   return;
>}
> 
>// Quit gtk
>gtk_main_quit();
> 
>// Become session leader
>ret = setsid();
>if( ret == -1 )
>{
>   perror("We could not be session leader\n");
>   exit(-1);
>}
> 
>// Set umask for safety
>umask(0);
>
>// Set root dir
>chdir("/");
>   
>  
>for( i = 0; i < loops_to_run; i++ )
>{
>   printf("We are running: %d\n", i );
>   sleep(1);
>} 
> 
>exit(0);
> 
> }
> 
> //--
> // When we quit
> //--
> static void quit_callback()
> {
>gtk_main_quit ();
> }
> 
> 
> //--
> //  main
> //
> //  Creates a gtk windows to specify how many loops
> //  the daemon should run.
> //
> //--
> int 
> main (int argc, char **argv)
> {
> 
>   GtkWidget *mainwin = 0L;
>   GtkWidget *number_entry = 0L;
>   GtkWidget *run_btn = 0L;
>   GtkWidget *vbox = 0L;
> 
>   /* Initialize i18n support */
>   printf("Locale is: %s\n", gtk_set_locale () );
> 
>   /* Initialize the widget set */
>   gtk_init (&argc, &argv);
> 
>   /* Create the main window */
>   mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
> 
>   /* Set up our

Re: Forking from Gtk

2008-07-08 Thread James Scott Jr
G,

I've seen most of the other responses, and better understand what you
are trying to do.  And like others -- fork() is not recommended. 

I had similar problem and resolved it in this codeset.
http://gfhcm.sourceforge.net  -- a monitor for the [EMAIL PROTECTED] project

First, like you I needed to start several executables in the background,
resolve their identify via pid number, and monitor their cpu utilization
and associated artifacts to gage their progress.  

I approached it two ways: with standalone gfhcm, and then in
client/server way using gfhcmc & gfhcmd; gfhcmc is the gtk gui and
gfhcmd is a glib helper daemon.

For your issue: I suggest g_[a]sync_command_line() as a way to launch a
background process from a gtk app.  Then using either ipc Queues, pipes,
or sockets to connect to process to echange commands and information.
Having a formal daemon will help the issue of starting/stopping the
background thread. and Finally a dedicated gui that expects to use an
IPC to communication with the process.

Anyway that you would like to proceed - I think we all can offer
solutions.  But be clear, I and maybe we think, forking is a bad ideal
for GTK program period.

My website may have something of interest:
http://mysite.verizon.net/skoona/id2.html

James,

On Tue, 2008-07-08 at 06:51 +0200, G Hasse wrote:
> On Mon, Jul 07, 2008 at 10:58:36PM -0400, James Scott Jr wrote:
> > G,
> > 
> > The basic design decision to use fork() as a way to do work in the
> > background flawed.  fork()ing is not practical for gtk program.  While
> > fork() has been a valid option for many non-gui programs in the absence
> > of threads, either g_thread_create() or pthread_create().  Today it is
> > not very useful -- as in stop doing it now!
> > 
> > Consider instead using a valid multi-threaded implementation like
> > g_threads_xxx() for GTK based programs.  Or if full multi-threading is
> > not required, look at g_timeout_add() which is a background timer
> > routine that can serve as one or more background execution units; neatly
> > inside an gtk context.
> 
> This is not a very practical solution if I want to quit the gtk program
> and go home... The example I gave was just an example. I want to create
> a process that run for a VERY long time. (a week). And to have the GUI
> running allong is not a solution. This process don't need to communicate
> with the GUI. And if so I can connect to the process with a socket and
> ask for services.
> 
> > 
> > $ devhelp
> > $ gtk-demo
> > 
> > The above two program you be pre-installed on your Linux machine:
> > devhelp has the gtk and glib api documentation, and gtk-demo shows you
> > many of the gtk/glib features in action.
> > 
> > Having said the multi-thread phrase, here is another word of caution.
> > In GTK only the main or ONE thread can safely interface with GTK api
> > calls that change the display.  Using more than one thread to call gtk
> > apis at the same time will fail or cause a sigfault.  The context of GTK
> > being your front-end to X11 is the source of this
> > none-thread-safe-caution; it is in how gtk MUST interact with X that
> > placing the multi-thread restriction.  There are elegant work-arounds
> > this issue.
> > 
> > Here is a link to the classic FAQ answer on Multi-threaded GTK programs:
> > http://library.gnome.org/devel/gtk-faq/stable/x482.html
> > 
> > Regards,
> > James,
> 
> Tanks for your answer but I don't thing threads is the solution in my
> case.
> 
> > 
> > On Mon, 2008-07-07 at 23:03 +0200, G Hasse wrote:
> > > Hello,
> > > 
> > > I have a small demo app. This works on FreeBSD but I can't
> > > get to work on Linux. I know that in Linux setsid will fail
> > > if the child has the same session_id as the parent. So on
> > > Linux you must fork twice. But it also seems that the parent
> > > must do an exit. And I don't want that. The code is not very
> > > long - so I include it here.
> > > 
> > > --
> > > //--
> > > //
> > > //  $Id: GtkFork.c,v 1.2 2008/07/07 20:29:17 gorhas Exp $
> > > //
> > > //  Experiment to run a thing in background
> > > //  This works on FreeBSD but not on Linux...
> > > //
> > > //  Build with
> > > //
> > > //  CFLAGS := `pkg-config glib-2.0 --cflags` `pkg-config gtk+-2.0 
> > > --cflags`
> > > //  LDFLAGS := `pkg-config glib-2.0 --libs` `pkg-config gtk+-2.0 --libs`
> > > //
> > > //  cc $(CFLAGS) -o GtkFork GtkFork.c $(LDF

Re: Forking from Gtk

2008-07-08 Thread James Scott Jr

On Tue, 2008-07-08 at 23:23 +0200, G Hasse wrote:
> On Tue, Jul 08, 2008 at 01:52:00PM -0400, James Scott Jr wrote:
> > G,
> > 
> > I've seen most of the other responses, and better understand what you
> > are trying to do.  And like others -- fork() is not recommended. 
> 
> I can't belive this... Certanly a forground process must be able to
> start a process that completly detatch from the parent. Gtk or not
> it could not matter. If I fork a Gtk program I migt have a lot of
> GtkWidget pointers that are of no use - but if I bother I should be
> able to free those. The gtk_main loop runs around to find out if
> signals have been emitted. So if I exit this loop no sutch activity
> should be going on.
> 
> I have been doing this on FreeBSD for a long time and I have no
> problem there. 
> 
> The only problem I realy have on Linux is that the forked process
> is marked as  and probably take a process slot until the
> parent exits. In FreeBSD I don't notice this behaviour.
> 
> The cenario you tell below is not quite applicable since my program
> don't know in advance what should be run. I only need the Gtk program
> to set a lot of parameters and then fire of the process. I klient
> server, socket or pipe solution would just make the solution 
> more complicated. And I don't need to minitor the processes during
> calculation.
> 
> > I had similar problem and resolved it in this codeset.
> > http://gfhcm.sourceforge.net  -- a monitor for the [EMAIL PROTECTED] project
> > 
> > First, like you I needed to start several executables in the background,
> > resolve their identify via pid number, and monitor their cpu utilization
> > and associated artifacts to gage their progress.  
> > 
> > I approached it two ways: with standalone gfhcm, and then in
> > client/server way using gfhcmc & gfhcmd; gfhcmc is the gtk gui and
> > gfhcmd is a glib helper daemon.
> > 
> > For your issue: I suggest g_[a]sync_command_line() as a way to launch a
> > background process from a gtk app.  Then using either ipc Queues, pipes,
> > or sockets to connect to process to echange commands and information.
> > Having a formal daemon will help the issue of starting/stopping the
> > background thread. and Finally a dedicated gui that expects to use an
> > IPC to communication with the process.
> > 
> > Anyway that you would like to proceed - I think we all can offer
> > solutions.  But be clear, I and maybe we think, forking is a bad ideal
> > for GTK program period.

Sorry. I don't se this. What i see is forking from a foreground process
and letting the foreground process still live on is a bad idea on 
*LINUX*. Or...

Göran

Ok, the glib/gtk apis can be used to meet the processing conditions you
describe.  I note that you aware of the increased complexity caused by a
design different from what your accustomed to on BSD. I think those of
us who have done a bit of gtk programming in varied situations, see a
solution that does require more effort and design.

John  stated that he got your code to work on Ubuntu with a few
minor additions. And I presume, using some type of gui toolkit on BSD
you been doing this for a while.  So with John's comment and your
experience, I think you can take it from here and use fork().  

However, if you want to redesign to take full advantage of the resources
and capability of GTK/GLIB and LINUX for the benefit of your users
experience; I got some time and would be willing to help you build a
framework -- just send me code or specs to look at.

The design changes to redo your code are not complicated or burdensome;
just different.  I think the outcome of the rework will be a better
piece of software with greater opportunity to please your users - even
if the user is only you.

James,

> > My website may have something of interest:
> > http://mysite.verizon.net/skoona/id2.html
> > 
> > James,
> > 
> > On Tue, 2008-07-08 at 06:51 +0200, G Hasse wrote:
> > > On Mon, Jul 07, 2008 at 10:58:36PM -0400, James Scott Jr wrote:
> > > > G,
> > > > 
> > > > The basic design decision to use fork() as a way to do work in the
> > > > background flawed.  fork()ing is not practical for gtk program.  While
> > > > fork() has been a valid option for many non-gui programs in the absence
> > > > of threads, either g_thread_create() or pthread_create().  Today it is
> > > > not very useful -- as in stop doing it now!
> > > > 
> > > > Consider instead using a valid multi-threaded implementation like
> > > > g_threads_xxx() for GTK based programs.  Or if full multi-threading is
> > > > not requi

Re: Howto correctly generate "expandable void"?

2008-10-24 Thread James Scott Jr
Till,

I have not tested this yet, but I can give you an ideal of what I would
try first.

Window
-vbox
-- vbutton_box(a,b,c) -- postioned using start
-- vbutton_box(x,y,z) -- postioned using end

Here is the code.

***BEGIN
/* Button Alignment */


#include 


int main(int argc, char *argv[] )
{
  GtkWidget   *window   = NULL;
  GtkWidget   *vbox = NULL;
  GtkWidget   *button   = NULL;
  GtkWidget   *bbox= NULL;
  
  gtk_init (&argc, &argv);

  /* create window, etc */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "expandable void");
  gtk_container_set_border_width (GTK_CONTAINER (window), 5);
  g_signal_connect (G_OBJECT (window), "destroy",
   G_CALLBACK (gtk_main_quit), NULL);
  
 /*
  * Create the main vbox
  */
  vbox = gtk_vbox_new (FALSE, 5);
  gtk_container_add (GTK_CONTAINER (window), vbox);

  
  /*
   * Create the Top Group of buttons
   */
  bbox = gtk_vbutton_box_new ();
  gtk_container_set_border_width (GTK_CONTAINER (bbox), 5);
  gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox),
GTK_BUTTONBOX_START);
  gtk_box_set_spacing (GTK_BOX (bbox), 6);
  gtk_box_pack_start (GTK_BOX (vbox), bbox, TRUE, TRUE, 5);  
  
  
  button = gtk_button_new_from_stock (GTK_STOCK_OK);
  gtk_container_add (GTK_CONTAINER (bbox), button);
  
  button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
  gtk_container_add (GTK_CONTAINER (bbox), button);
  
  button = gtk_button_new_from_stock (GTK_STOCK_HELP);
  gtk_container_add (GTK_CONTAINER (bbox), button);

  /*
   * Create the Bottom Group of buttons
   */
  bbox = gtk_vbutton_box_new ();
  gtk_container_set_border_width (GTK_CONTAINER (bbox), 5);
  gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
  gtk_box_set_spacing (GTK_BOX (bbox), 6);
  gtk_box_pack_end (GTK_BOX (vbox), bbox, TRUE, TRUE, 5);  
  
  
  button = gtk_button_new_from_stock (GTK_STOCK_OK);
  gtk_container_add (GTK_CONTAINER (bbox), button);
  
  button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
  gtk_container_add (GTK_CONTAINER (bbox), button);
  
  button = gtk_button_new_from_stock (GTK_STOCK_HELP);
  gtk_container_add (GTK_CONTAINER (bbox), button);
  
  
  
  gtk_widget_show_all (window);

  gtk_main();

  return 0;
}

***END


On Fri, 2008-10-24 at 21:01 +0200, Till Harbaum / Lists wrote:
> Hi,
> 
> i have a vbox with a bunch of buttons. I want some of them to appear at the 
> top
> and some of them at the bottom. The buttons should not be expanded and the
> space between them should also not expand except the space between the two
> groups. Something like this:
> 
> (a)
> (b)
> (c)
> 
> 
> 
> 
> (x)
> (y)
> (z)
> 
> How is this done correctly without having some invisible item i can place 
> between
> both groups and which is set to expand/fill?
> 
> Till
> ___
> 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: glib main loop without gtk

2008-11-14 Thread James Scott Jr
How to exit the main loop? Stick this in a timer routine and execute it
when your ready to shutdown. --g_main_loop_quit(main_loop); --

Also, the following link contains two daemons; a pure glib one, and a
pure libc one; including threads, etc...

http://mysite.verizon.net/skoona/sitebuildercontent/sitebuilderfiles/gdaemons-0.1.4.tar.bz2

James,



On Wed, 2008-11-12 at 15:20 -0600, Thomas Stover wrote:
> So if one wants to use g_io_channels with out gtk (console / server 
> app), what exactly is the idea? Does glib need an initialization 
> function called first? I see the g_main_loop_new() and friends 
> functions, and that part make sense. The thing is g_io_add_watch_full() 
> type functions don't have a main loop parameter. In other words were 
> does this "default" main loop come from?
> ___
> 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: Basic GNOME applet developement

2008-11-18 Thread James Scott Jr
Andrew,

Where are you with this problem now?  I have tried to review your posts
to better understand your dilemma, and I can make one suggestion in
reference to "add to gnome bar and it doesn't show anything".

When you have the *.server file correct, and your C code correct, in
that your printf's show console output.  Your issue may simply be that
you never added your widgets to the applet itself.  In GTK there is
always a top level window/widget which everything gets added to.  In a
gnome applet the applet itself is that top-level window.  This snippet
will attach your event_box widget to the applet, so it can be shown.

static gboolean
myexample_applet_fill (PanelApplet *applet,
   const gchar *iid,
   gpointer data)

{
...
gtk_container_add (GTK_CONTAINER(event_box),image);
gtk_container_add (GTK_CONTAINER (applet), event_box);
...
gtk_widget_show_all (GTK_WIDGET (applet));
...
}

James,
I think I sent you this link before; but here it is again - a skeleton
gnome applet program.
http://mysite.verizon.net/ressgdw8/sitebuildercontent/sitebuilderfiles/panel_applet-0.0-3.tar.bz2


On Mon, 2008-11-17 at 14:07 +0100, Andrew M. wrote:
> On Mon, November 17, 2008 7:48 am, Michael Ott wrote:
> > Hello Andrew!
> >
> >> >> I am attempting my first Gnome applet creation and I found a great
> tutorial at http://projects.gnome.org/ORBit2/appletstutorial.html .
> Unfortunately, I am stuck where the example goes to load an image. I
> >> can
> >> >> compile the applet and make it run but when I add it to the Gnome bar
> >> it
> >> >> doesn't show anything. I have some printf's in the code and those
> >> work
> >> >> on
> >> >> the console.
> >> > Do you have an .server file?
> >> >
> >> > Do you try it with panel-test-applets?
> >> >
> >> > With a server file and panel-test-applets it will work. Perhaps.
> >> I do indeed have the .server file.
> > Can you send me the file?
> 
> 
> 
>  location="/usr/lib/gnome-panel/myexample">
> 
> 
> 
> 
> 
> 
> 
> 
> 
>  location="OAFIID:ExampleApplet_Factory">
> 
> 
> 
> 
> 
> 
> 
> 
>  value="Amusements"/>
>  value="invest-big.png"/>
> 
> 
> 
> >
> >> From that same page I was able to make the first example work and do some
> >> small modifications. But when I try to go on to the second step,
> nothing happens. The applet runs from a command line and executes my
> printf()'s but nothing shows up on the panel.
> > I believe, that you cannot see anything on the panel. I tested it always
> with panel-test-applets.
> 
> I'm afraid I have no idea what panel-test-applets is..
> 
> Andrew
> 
> 
> 
> ___
> 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: Question about Callback

2009-01-12 Thread James Scott Jr
You can also use:
- in the routine that creates the button, save a unique value.
 g_object_set_data(G_OBJECT(button), "Unique-Key", &some-value)

-in button callback routine, retrieve the unique value.
some-value-pointer = g_object_get_data(G_OBJECT(button), "Unique-Key");

This in addition to any pre-allocated memory structure you passed in the
g_signal_connect(), or g_signal_connect_swapped().   The issue with
reuse of button callbacks is always how to determine which button! I do
two things;
1. pre-allocate a memory structure with the first value a fixed id of
some sort (or related to the button's function).  example

#def EXIT_BUTTON_FLAG 1
.
.
.
typedef struct _SomeButton {
 gint cb_id;
 ...
} SomeButton, *PSomeButton;
.
.
.
PSomeButton memButton = NULL;
.
memButton = g_new0(SomeButton, 1);
memButton->cb_id = EXIT_BUTTON_CBID;
.
g_signal_connect(G_OBJECT(button), "toggled", 
  G_CALLBACK(fn_callback), memButton);
.
.

2. g_object_set_data() and g_object_get_data() as described earlier.
checking the cb_id of the userdata from g_signal... and also getting
this extra value helps your positively identify which button was
pressed.  

Either method will work, but sometimes both come in handy.

Hope that helps.  Also, here is a link to source code that may help
explain better.
http://mysite.verizon.net/ressgdw8/sitebuildercontent/sitebuilderfiles/gtkstatusicon-starter-program-0.1.0.tar.bz2

And don't forget to review 'gtk-demo', it has good examples.

James,


On Sun, 2009-01-11 at 12:42 +0100, Rudolfo Pinewood wrote:
> Hi,
> I have a question regarding Callback functions for Toggle buttons.
> 
> I have several togglebuttons, that are all registered to call one
> specific function (ApplyFlags). In this function I actually don't know
> which button was activated.
> 
> My attempt was giving each button/callback an additional parameter that
> should be passed to my ApplyFlags function.
> 
> However I was not able to do so - MemberCaller1 seems to fit (regarding
> the "call one function with one parameter") but I did not manage to get
> my parameter into that Callback in
> g_signal_connect_swapped(G_OBJECT(button), "toggled", 
> G_CALLBACK(callback.getThunk()), callback.getEnvironment()).
> 
> How could this be done?
> Thanks in advance
> Christoph Hartwig
> ___
> 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: Question about Callback

2009-01-13 Thread James Scott Jr
Rudolfo,

In your case where you have multiple buttons operating on the same
logical data field, using a single callback function is very practical.

The same can be said for a callback that performs a single logical
function, all windows/object should attempt to reuse that callback if
they need that functions.  

Example; being a pair of callback I wrote that is called when a window
is hidden or shown.  All my dialogs/windows that need that service reuse
those single callbacks. To handle the fact that each window instance
saves its visibility value in a different variable/address, I pass into
the g_signal_connect(..., &b_visible) the address of that variable when
creating each window.

void cb_main_interface_show (GtkWidget * widget, gboolean *pb_visible)
{
  g_return_if_fail (pb_visible != NULL);
  *pb_visible = TRUE;
}
void cb_main_interface_hide (GtkWidget * widget, gboolean *pb_visible)
{
  g_return_if_fail (pb_visible != NULL);
  *pb_visible = FALSE;
}

To me this helps organize the code and makes it easier to maintain.  The
cost of this reuse is fairly low, and the g_object_[set|get]_data()
along with user-data cb_id flags, normally handles it well.  Of course
all this reuse can be impacted by the to many global/static variables --
which limits the re-entrancy or reuse  of any program.

My two.

James,


On Tue, 2009-01-13 at 20:40 +0100, Rudolfo Pinewood wrote:
> Hi,
> thanks for your answer. I think I understand my code a bit better now...
> I wonder whether it is "best practice" to use static functions for these 
> callbacks - in my code it is actually a member function (because of 
> having many different buttons whose states form a bitfield that is 
> "compressed" to one int value. I did not find any example that does not 
> use such static functions.
> 
> Greetings,
> Christoph Hartwig
> 
> James Scott Jr schrieb:
> > You can also use:
> > - in the routine that creates the button, save a unique value.
> >  g_object_set_data(G_OBJECT(button), "Unique-Key", &some-value)
> > 
> > -in button callback routine, retrieve the unique value.
> > some-value-pointer = g_object_get_data(G_OBJECT(button), "Unique-Key");
> > 
> > This in addition to any pre-allocated memory structure you passed in the
> > g_signal_connect(), or g_signal_connect_swapped().   The issue with
> > reuse of button callbacks is always how to determine which button! I do
> > two things;
> > 1. pre-allocate a memory structure with the first value a fixed id of
> > some sort (or related to the button's function).  example
> > 
> > #def EXIT_BUTTON_FLAG 1
> > .
> > .
> > .
> > typedef struct _SomeButton {
> >  gint cb_id;
> >  ...
> > } SomeButton, *PSomeButton;
> > .
> > .
> > .
> > PSomeButton memButton = NULL;
> > .
> > memButton = g_new0(SomeButton, 1);
> > memButton->cb_id = EXIT_BUTTON_CBID;
> > .
> > g_signal_connect(G_OBJECT(button), "toggled", 
> >   G_CALLBACK(fn_callback), memButton);
> > .
> > .
> > 
> > 2. g_object_set_data() and g_object_get_data() as described earlier.
> > checking the cb_id of the userdata from g_signal... and also getting
> > this extra value helps your positively identify which button was
> > pressed.  
> > 
> > Either method will work, but sometimes both come in handy.
> > 
> > Hope that helps.  Also, here is a link to source code that may help
> > explain better.
> > http://mysite.verizon.net/ressgdw8/sitebuildercontent/sitebuilderfiles/gtkstatusicon-starter-program-0.1.0.tar.bz2
> > 
> > And don't forget to review 'gtk-demo', it has good examples.
> > 
> > James,
> > 
> > 
> > On Sun, 2009-01-11 at 12:42 +0100, Rudolfo Pinewood wrote:
> >> Hi,
> >> I have a question regarding Callback functions for Toggle buttons.
> >>
> >> I have several togglebuttons, that are all registered to call one
> >> specific function (ApplyFlags). In this function I actually don't know
> >> which button was activated.
> >>
> >> My attempt was giving each button/callback an additional parameter that
> >> should be passed to my ApplyFlags function.
> >>
> >> However I was not able to do so - MemberCaller1 seems to fit (regarding
> >> the "call one function with one parameter") but I did not manage to get
> >> my parameter into that Callback in
> >> g_signal_connect_swapped(G_OBJECT(button), "toggled", 
> >> G_CALLBACK(callback.getThunk()), callback.getEnvironment()).
> >>
> >> How could this be done?
> >> Thanks in advance
> >> Christoph Hartwig
> >> ___
> >> 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: some erros

2009-01-15 Thread James Scott Jr
Frederico,

From your code listing part of your problem could be this syntax error:

gtk_file_chooser_add_filter(*chooser, *filtro);

it should read;

gtk_file_chooser_add_filter(chooser, filtro);

James,


On Thu, 2009-01-15 at 22:58 -0200, frederico schardong wrote:
> Hi,
> 
> anybody can help me to resolve this?
> 
> 
> 
> GtkFileFilter *filtro;
> GtkWidget *chooser;
> //GtkFileChooser *chooser;
> 
> gtk_file_filter_set_name(filtro,"bmp");
> 
> chooser = gtk_file_chooser_dialog_new ("Open File",
>   parent_window,
>   GTK_FILE_CHOOSER_ACTION_OPEN,
>   GTK_STOCK_CANCEL,
> GTK_RESPONSE_CANCEL,
>   GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
>   NULL);
> 
> gtk_file_chooser_add_filter(*chooser, *filtro);
> 
> gtk_widget_show(chooser);
> 
> if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_ACCEPT)
>   {
> char *filename;
> 
> filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
> 
> g_print (filename);
>   }
> 
> gtk_widget_destroy (chooser);
> 
> 
> how I can add filter to my chooser??
> 
> thanks
> ___
> 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: some erros -- resolved

2009-01-18 Thread James Scott Jr
Frederico,

Your CCLIST dropped the reference to gtk-app-devel-l...@gnome.org.
Which will certaily impact who can respond.

Here is your example you asked for.

Regards,

James Scott, Jr.
Registered Linux User #270764


/* Sampler.c */

#include 

static gchar* fn_get_file (GtkWindow *parent, gchar
**filter_string_array)
{
 GtkWidget *chooser  = NULL;
 gchar *fname = NULL;
 gint   index = 0;

/*
 * Create the Chooser Dialog
 */
 chooser = GTK_WIDGET (gtk_file_chooser_dialog_new ("Open File",
  parent,
  GTK_FILE_CHOOSER_ACTION_OPEN,
  GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
  GTK_STOCK_OPEN,   GTK_RESPONSE_ACCEPT,
  NULL));
 /*
  * Populate and add filter to dialog, dialog owns them afterwards
  */
 for (index = 0; filter_string_array[index] != NULL; index++) {
   GtkFileFilter *filtro = NULL;
   gchar pattn[32];

   filtro = gtk_file_filter_new();

   g_snprintf (pattn, sizeof(pattn), "*.%s",
filter_string_array[index]);
   gtk_file_filter_add_pattern(filtro, pattn);
   gtk_file_filter_set_name(filtro, filter_string_array[index]);

   gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(chooser), filtro);
 }

 /*
  * Show and Run the dialog
  */
 gtk_widget_show(chooser);
 if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_ACCEPT)
  {
fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
  }

 gtk_widget_destroy (chooser);

 return fname;
}

static void cb_get_file (GtkWidget *button, GtkWidget *label)
{
  GtkWindow*window = NULL;
  gchar   *sz_filename = NULL;
  gchar **sz_a_filters = NULL;

  g_return_if_fail (label != NULL);

  sz_a_filters = (gchar **)g_object_get_data(G_OBJECT(button),
"FILE_FILTERS");

  window = (GtkWindow *)gtk_widget_get_ancestor (button,
GTK_TYPE_WINDOW);

  if (window != NULL) {
sz_filename = fn_get_file (GTK_WINDOW(window), sz_a_filters);
if (sz_filename != NULL) {
  gtk_label_set_text(GTK_LABEL(label), sz_filename);
  g_free(sz_filename);
}
  }
}


int main (int argc, char *argv[])
{
  GtkWidget *window = NULL;
  GtkWidget   *vbox = NULL;
  GtkWidget *button = NULL;
  GtkWidget  *label = NULL;
  gchar *sz_a_filters[] = { "c", "bmp", "png", "jpg", NULL};



  gtk_init (&argc, &argv);

  /* create window, etc */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Quick Sample");
  gtk_container_set_border_width (GTK_CONTAINER (window), 5);
  gtk_window_set_default_size (GTK_WINDOW (window), 320, 200);
  g_signal_connect (G_OBJECT (window), "destroy",
   G_CALLBACK (gtk_main_quit), NULL);

  vbox = gtk_vbox_new (FALSE, 5);
  gtk_container_add (GTK_CONTAINER (window), vbox);

  label = gtk_label_new ("gFileChooser");
  gtk_box_pack_start (GTK_BOX (vbox),
  label,
  FALSE, FALSE, 0);

  button = gtk_button_new_with_label ("Open a File");
  g_object_set_data(G_OBJECT(button), "FILE_FILTERS",
sz_a_filters);
  g_signal_connect (button, "clicked", G_CALLBACK (cb_get_file),
label);
  gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);


 gtk_widget_show_all (window);

gtk_main();

  return 0;
}

END CODE



On Sat, 2009-01-17 at 11:26 -0200, frederico schardong wrote:
> please, help me
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: examples/list.c

2009-01-21 Thread James Scott Jr
look for and use the "gtk-demo" application thats normallu apart of the
devel package.  It contains current GTK examples pre-compiled with
source immediately available.  Also, consider using "devhelp", another
api document viewer for GTK/GLIB and many others.

James,


On Wed, 2009-01-21 at 21:42 +, Dave Luttinen wrote:
> 2nd post. I'm just getting warmed up . 
> 
> Compile with supplied Makefile to gtk+/gtk+-2.14.6/examples/list.c, run 
> sample application, right click on list, the following is printed: 
> 
> (list:17088): Gtk-CRITICAL **: gtk_list_add: assertion `GTK_IS_LIST_ITEM 
> (widget)' failed 
> 
> (list:17088): Gtk-CRITICAL **: gtk_widget_get_parent_window: assertion 
> `GTK_IS_WIDGET (widget)' failed 
> 
> (list:17088): Gdk-CRITICAL **: gdk_window_get_children: assertion 
> `GDK_IS_WINDOW (window)' failed 
> 
> (list:17088): Gtk-CRITICAL **: gtk_widget_get_parent_window: assertion 
> `GTK_IS_WIDGET (widget)' failed 
> ** 
> ** 
> Gtk:ERROR:(/build/buildd/gtk+2.0-2.12.9/gtk/gtkwidget.c:4810):gtk_widget_reparent_fixup_child:
>  assertion failed: (client_data != NULL) 
> Aborted 
> 
> I have placed these gtk examples in my home folder "my-projects" and they 
> compile without complaint. Is this a linking issue? 
> 
> What is occurring? 
> 
> Dave 
> ___
> 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