Re: Cant get GtkTextBuffer from GtkTextView widget

2008-04-14 Thread Tiberius DULUMAN
The handler should be:

static void handler(GtkWidget *widget, GtkTextView *tview)
{
GtkTextBuffer *buffer = NULL;
GtkTextIter iterator;

buffer = gtk_text_view_get_buffer(tview);
g_assert(buffer != NULL);  assert that it is not null
gtk_text_buffer_get_end_iter(buffer, iterator);pass an allocated
iterator
gtk_text_buffer_insert(buffer, iterator, Info message, -1);
}


2008/4/14 Roman Makurin [EMAIL PROTECTED]:

 Hi All!

 I`ve got a problem with GtkTextView object. I want to append text to it
 everytime when some event occurs.

 Here is code snippet:

 static void handler(GtkWidget *widget, GtkTextView *tview) {
GtkTextBuffer *buffer;
GtkTextIter *iterator;

buffer = gtk_text_view_get_buffer(tview);
g_assert(buffer == NULL);
gtk_text_buffer_get_end_iter(buffer, iterator);
gtk_text_buffer_insert(buffer, iterator,
Info message, -1);
 }

 int main(int argc, char ** argv) {
GtkWiget *tview;
tview = gtk_text_view_new();

g_signal_connect(G_OBJECT(button), clicked,
G_CALLBACK(handler), tview);

return 0;
 }


 When I`m trying to get buffer object in habdler() it allways returned as
 NULL and I`ve got segmentation fault. I can`t figure out where is my
 fault :(

 How can I append text to GtkTextView ?

 Thanks

 PS: Sorry for my english
 --
 If you think of MS-DOS as mono, and Windows as stereo,
  then Linux is Dolby Digital and all the music is free...


 ___
 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: Callback Question

2008-04-14 Thread Alexander Semenov
Hi. Perhaps, this discussion was related to threads?
  
 Thank you all for this! Especialy for the long example, but, it was just 
 an example.
 I've made an application that works perfectly on Linux but in Window$ it 
 crashes a lot!
 I've been trying to find a solution (actually a clue of what the problem 
 might be) in any discussion I was able to find about GTK crashes in the 
 internet.
 In one of these discussions it was said that gtk functions can't be 
 called inside callbacks, that it wasn't safe yet. That, if you call any 
 gtk function inside a callback, it should be done using 
 g_object_idle_add. Unfortunatly I didn't check the date of the 
 discussion, maybe, it is too old.
 
 Thanks.
 
 Matías.
 ___
 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: Cant get GtkTextBuffer from GtkTextView widget

2008-04-14 Thread Roman Makurin
В Пнд, 14/04/2008 в 09:59 +0300, Tiberius DULUMAN пишет:
 The handler should be:
 
 static void handler(GtkWidget *widget, GtkTextView *tview)
 {
 GtkTextBuffer *buffer = NULL;
 GtkTextIter iterator;
 
 buffer = gtk_text_view_get_buffer(tview);
 g_assert(buffer != NULL);  assert that it is not null
 gtk_text_buffer_get_end_iter(buffer, iterator);pass an allocated
 iterator
 gtk_text_buffer_insert(buffer, iterator, Info message, -1);
 }

Thanks, it helps me.

-- 
If you think of MS-DOS as mono, and Windows as stereo,
 then Linux is Dolby Digital and all the music is free...

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

Re: Preventing Multiple instance of GTK application

2008-04-14 Thread Liam R E Quin
On Sat, 2008-04-12 at 15:16 +0100, Carlos Pereira wrote:

 You can write a .lock file everytime you start and then remove it when 
 you close. To know if other instance is running, you just have to check 
 if your .lock file exists.

Please don't do this.

If you must, take into account
(1) multiple instances may create the file -- especially if it is
on a network file system.  You can use O_CREAT|E_EXCL but it
is not guaranteed to work over a network and neither in
practice.

(2) after a system crash, or if your application crashes, the lock
file will not be removed.
A way round this is to make the lock file by a symbolic link
to a non-existant file with your process ID in it, and then on
startup to check if that process name exists use kill(the_proc, 0),
but this will fail on a network drive if the program is running on
another machine.
A way round this is to include your machine's IP address in the
link, but this fails on a laptop (say) that gets a new IP address
each time it starts and which might get shut down quickly.

(3) if your application was run as root, or as another user, you might
not be able to delete the lock file.

(4) the above 3 items don't have portable solutions between operating
systems.

It is much better to use dbus, or an X Windows property..

and even better to use a library that packages all this stuff,
as was suggested by others.

If you do end up making a lock file, consider making it a directory,
as there are generally fewer locking problems.

best,

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org www.advogato.org

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


Re: Draw text to a GdkPixbuf

2008-04-14 Thread Francesco Sepic
On Mon, Apr 14, 2008 at 12:31 PM, Alexander Semenov [EMAIL PROTECTED] wrote:
 Hi.

  What about drawing GdkPixbuf and then your text on GdkWindow?


I'm drawing a scale bar on a map and I'd like to have different types
of scale bar.
The position of the text that i have to draw (for example 50 km)
depends on specific scale bar.
So i want to create different functions that return a GdkPixbuf with
the text already rendered.

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


cairo_path_t to GdkRegion?

2008-04-14 Thread Brian J. Tarricone
Hi all,

I'm writing a semi-transparent window widget that uses cairo for
drawing.  I'm using an ARGB window, and the window itself isn't
necessarily rectangular (sometimes it'll have rounded corners of
arbitrary radius, and other non-regular shapes are possible).

Since I'm using cairo to do the drawing, I can of course very easily
get a cairo_path_t for the visible outline of the window.

I want to be able to draw this at least passably well for users not
running a compositing manager (and it would be nice to set an input
shape as well).  Anybody know of a way to munge a cairo_path_t into at
least an approximate GdkRegion (i.e. suitable for
gdk_window_shape_combine_region())?  Or is there a better way to do
this?

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


Re: Draw text to a GdkPixbuf

2008-04-14 Thread Alexander Semenov
Hi.

What about drawing GdkPixbuf and then your text on GdkWindow?

On Mon, 2008-04-14 at 12:05 +0200, Francesco Sepic wrote:
 Hello,
 is it possible to draw text on a GdkPixbuf using Pango?
 gdk_draw_text () takes a GdkDrawable as the destination on which draw
 text. Is it possible to get a GdkDrawable from a GdkPixbuf?
 
 Thanks.

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


Draw text to a GdkPixbuf

2008-04-14 Thread Francesco Sepic
Hello,
is it possible to draw text on a GdkPixbuf using Pango?
gdk_draw_text () takes a GdkDrawable as the destination on which draw
text. Is it possible to get a GdkDrawable from a GdkPixbuf?

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


Re: Preventing Multiple instance of GTK application

2008-04-14 Thread Carlos Pereira
Liam R E Quin wrote:
 On Sat, 2008-04-12 at 15:16 +0100, Carlos Pereira wrote:

   
I agree with everything you said.

But in some cases lock files can be useful... this is the way
vim checks if other instances of the same file are open,
so the new instance is open in read-only mode... of course
you need to remove the .filename.swp file yourself, if your machine
crashs... as you said...

I suppose it depends of the specific needs... but in general
I agree with your advices, thank you!

Carlos
 You can write a .lock file everytime you start and then remove it when 
 you close. To know if other instance is running, you just have to check 
 if your .lock file exists.
 

 Please don't do this.

 If you must, take into account
 (1) multiple instances may create the file -- especially if it is
 on a network file system.  You can use O_CREAT|E_EXCL but it
 is not guaranteed to work over a network and neither in
 practice.

 (2) after a system crash, or if your application crashes, the lock
 file will not be removed.
 A way round this is to make the lock file by a symbolic link
 to a non-existant file with your process ID in it, and then on
 startup to check if that process name exists use kill(the_proc, 0),
 but this will fail on a network drive if the program is running on
 another machine.
 A way round this is to include your machine's IP address in the
 link, but this fails on a laptop (say) that gets a new IP address
 each time it starts and which might get shut down quickly.

 (3) if your application was run as root, or as another user, you might
 not be able to delete the lock file.

 (4) the above 3 items don't have portable solutions between operating
 systems.

 It is much better to use dbus, or an X Windows property..

 and even better to use a library that packages all this stuff,
 as was suggested by others.

 If you do end up making a lock file, consider making it a directory,
 as there are generally fewer locking problems.

 best,

 Liam

   

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


Re: Draw text to a GdkPixbuf

2008-04-14 Thread Alexander Semenov
Why don't you want to draw the text you need in your expose function?
You simply redefine the GtkWidgetClass expose-event and draw there.

On Mon, 2008-04-14 at 12:55 +0200, Francesco Sepic wrote:
 On Mon, Apr 14, 2008 at 12:31 PM, Alexander Semenov [EMAIL PROTECTED] wrote:
  Hi.
 
   What about drawing GdkPixbuf and then your text on GdkWindow?
 
 
 I'm drawing a scale bar on a map and I'd like to have different types
 of scale bar.
 The position of the text that i have to draw (for example 50 km)
 depends on specific scale bar.
 So i want to create different functions that return a GdkPixbuf with
 the text already rendered.
 
 Thanks.

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


How to draw a primitive with one color and fill it with another?

2008-04-14 Thread Sergey Parhomenko
Hello everyone.

I want to draw a red circle filled within with a green
color on my pixmap. I've set foreground and background
colors and passed TRUE as the filled parameter to
gdk_draw_arc(). But the circle is filled with the same
color as it is drawn, that is with the foreground
color - red.

How can I draw a red circle filled with green? The
relevant part of my code is below.

/* ... */

static GdkPixmap *pixmap = NULL;

void draw(GtkWidget* widget)
{
  int width = widget-allocation.width;
  int height = widget-allocation.height;
  GdkGC *gc;
  GdkColor colors[2];

  int x = width / 2;
  int y = height / 2;
  int r = 30;

  if (pixmap)
g_object_unref (pixmap);
  pixmap = gdk_pixmap_new (widget-window,
   width,
   height,
   -1);
  gc = gdk_gc_new((GdkDrawable *)pixmap);
/* clearing to white: */
  gdk_draw_rectangle (pixmap,
  widget-style-white_gc,
  TRUE,
  0, 0,
  width,
  height);

  gdk_color_parse(#ff, colors[0]);
  gdk_color_parse(#00ff00, colors[1]);
/* By the way, can I get red and green GdkColor
faster, without these gdk_color_parse()? Are some
constants for this available? */
  gdk_gc_set_rgb_fg_color(gc, colors[0]);
  gdk_gc_set_rgb_bg_color(gc, colors[1]);

  gdk_draw_arc(pixmap, gc, TRUE, x - r / 2, y - r / 2,
r, r, 0, 64 * 360);
}

/* ... */




  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

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


Re: Callback Question

2008-04-14 Thread Matí­as Alejandro Torres
Alexander Semenov escribió:
 Hi. Perhaps, this discussion was related to threads?
   
   
 Thank you all for this! Especialy for the long example, but, it was just 
 an example.
 I've made an application that works perfectly on Linux but in Window$ it 
 crashes a lot!
 I've been trying to find a solution (actually a clue of what the problem 
 might be) in any discussion I was able to find about GTK crashes in the 
 internet.
 In one of these discussions it was said that gtk functions can't be 
 called inside callbacks, that it wasn't safe yet. That, if you call any 
 gtk function inside a callback, it should be done using 
 g_object_idle_add. Unfortunatly I didn't check the date of the 
 discussion, maybe, it is too old.

 Thanks.

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


   
No, no threads are involved.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Location entry in GtkFileChooser

2008-04-14 Thread Carlos Pereira
Hullo,

In a GTkFilechooser, how can I acess the information
on the Location entry? I only find functions to get
the full filename and uri but not the actual short
filename...

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


Re: Location entry in GtkFileChooser

2008-04-14 Thread Luis Menina
Hi Carlos.

Well, I'm not familiar with GtkFileChooser, but I think you should 
retrieve the full filename, and then use g_path_get_basename to get the 
short filename.

Cheers,

Luis

Carlos Pereira a écrit :
 Hullo,
 
 In a GTkFilechooser, how can I acess the information
 on the Location entry? I only find functions to get
 the full filename and uri but not the actual short
 filename...
 
 Carlos
 ___
 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


Translation domains

2008-04-14 Thread Gorshkov
I'm working on an application, and I keep getting messages from my 
GtkEntry and GtkTextArea widgets Input method XXX should not use GTK'S 
translation domain gtk20

Where/How to I set/change the translation domain?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: cairo_path_t to GdkRegion?

2008-04-14 Thread Brian J. Tarricone
On Mon, 14 Apr 2008 02:38:27 -0700 Brian J. Tarricone wrote:

 Anybody know of a way to munge a cairo_path_t into at
 least an approximate GdkRegion (i.e. suitable for
 gdk_window_shape_combine_region())?  Or is there a better way to do
 this?

Figured out something, in case anyone's interested.  I used
cairo_copy_path_flat() to get a cairo_path_t that doesn't have any of
those pesky 'curve_to' operations in it, and then converted the path
into a series of GdkPoints, iterating over the path data as described
in the cairo docs.  Seems to work decently well, though the paths
unsurprisingly don't match exactly.

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