gtk programming - Linux

This is a discussion on gtk programming - Linux ; Hello, I've started programming with gtk libs, and I have few questions about them: 1. Looking at Pango reference manual, I found a useful function named pango_parse_markup(). How is possible to use this to draw text with attributes together with ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: gtk programming

  1. gtk programming


    Hello,
    I've started programming with gtk libs, and I have few questions about
    them:

    1. Looking at Pango reference manual, I found a useful function named
    pango_parse_markup(). How is possible to use this to draw text with
    attributes together with GtkTextBuffer and GtkTextView?

    2. Are there widgets that display media contents, or how can I use
    current
    widgets to play a video with a player (as mplayer, or xine, for
    example)?

    3. Suppose I have to make a drawing area in which the cursor
    must change when entered. Look at this code:


    GtkWidget *dr = gtk_drawing_area_new();

    gtk_widget_add_events(dr, GDK_BUTTON_PRESS_MASK);
    gtk_widget_set_size_request(dr, width, height);
    g_signal_connect(dr, "expose_event", G_CALLBACK(expose_callback),
    NULL);
    g_signal_connect(dr, "button_press_event",
    G_CALLBACK(mouse_pressed), NULL);
    gdk_window_set_cursor(dr->window, gdk_cursor_new(GDK_PENCIL));


    However, when I run it I receive this objection:

    Gdk-CRITICAL **: gdk_window_set_cursor: assertion `GDK_IS_WINDOW
    (window)' failed

    If I put gdk_window_set_cursor in the expose_callback() it works,
    but I don't know
    if it is needed or is a *bad* way.

    Another problem: if I have multiple pixbufs to be over a drawing
    area, there is
    a way to draw them over only a pixbuf and repaint only it at expose
    events or I
    have to redraw all of them (in other words: can I use gdk-pixbuf or
    another widget
    as a offscreen drawable?)

    Thanks,
    Gaetano


  2. Re: gtk programming

    gaetanoortisi@yahoo.it writes:

    > Hello,
    > I've started programming with gtk libs, and I have few questions about
    > them:
    >
    > 1. Looking at Pango reference manual, I found a useful function named
    > pango_parse_markup(). How is possible to use this to draw text with
    > attributes together with GtkTextBuffer and GtkTextView?
    >
    > 2. Are there widgets that display media contents, or how can I use
    > current
    > widgets to play a video with a player (as mplayer, or xine, for
    > example)?
    >
    > 3. Suppose I have to make a drawing area in which the cursor
    > must change when entered. Look at this code:
    >
    >
    > GtkWidget *dr = gtk_drawing_area_new();
    >
    > gtk_widget_add_events(dr, GDK_BUTTON_PRESS_MASK);
    > gtk_widget_set_size_request(dr, width, height);
    > g_signal_connect(dr, "expose_event", G_CALLBACK(expose_callback),
    > NULL);
    > g_signal_connect(dr, "button_press_event",
    > G_CALLBACK(mouse_pressed), NULL);
    > gdk_window_set_cursor(dr->window, gdk_cursor_new(GDK_PENCIL));
    >
    >
    > However, when I run it I receive this objection:
    >
    > Gdk-CRITICAL **: gdk_window_set_cursor: assertion `GDK_IS_WINDOW
    > (window)' failed
    >
    > If I put gdk_window_set_cursor in the expose_callback() it works,
    > but I don't know
    > if it is needed or is a *bad* way.
    >
    > Another problem: if I have multiple pixbufs to be over a drawing
    > area, there is
    > a way to draw them over only a pixbuf and repaint only it at expose
    > events or I
    > have to redraw all of them (in other words: can I use gdk-pixbuf or
    > another widget
    > as a offscreen drawable?)
    >
    > Thanks,
    > Gaetano
    >


    I'm afraid I can not help directly, but be aware of the nabble forums
    and the gtk mailing lists.

    http://www.nabble.com/Gtk%2B-f1329.html
    http://www.gtk.org/mailinglists.html

    Good luck.

  3. Re: gtk programming

    Hi,

    On Mon, 25 Dec 2006 02:50:24 -0800, gaetanoortisi wrote:
    > Hello,
    > I've started programming with gtk libs, and I have few questions about
    > them:
    >
    > 1. Looking at Pango reference manual, I found a useful function named
    > pango_parse_markup(). How is possible to use this to draw text with
    > attributes together with GtkTextBuffer and GtkTextView?


    I don't know. GtkTextBuffer/GtkTextView have a model/view separation that can hurt big time. You might be better off to create GtkTextTag instances and insert them with gtk_text_buffer_insert_with_tags.

    > 2. Are there widgets that display media contents, or how can I use
    > current
    > widgets to play a video with a player (as mplayer, or xine, for
    > example)?


    Use a GtkSocket and call mplayer, passing its ID with "-xid " and probably -slave", "-nomouseinput", "-quiet", "-zoom".

    Alternatively use gstreamer (overkill for most "player" uses and seems to bork most of the time for me).

    > 3. Suppose I have to make a drawing area in which the cursor
    > must change when entered. Look at this code:
    >
    >
    > GtkWidget *dr = gtk_drawing_area_new();
    >
    > gtk_widget_add_events(dr, GDK_BUTTON_PRESS_MASK);
    > gtk_widget_set_size_request(dr, width, height);
    > g_signal_connect(dr, "expose_event", G_CALLBACK(expose_callback),
    > NULL);
    > g_signal_connect(dr, "button_press_event",
    > G_CALLBACK(mouse_pressed), NULL);
    > gdk_window_set_cursor(dr->window, gdk_cursor_new(GDK_PENCIL));
    >
    >
    > However, when I run it I receive this objection:
    >
    > Gdk-CRITICAL **: gdk_window_set_cursor: assertion `GDK_IS_WINDOW
    > (window)' failed


    Realize the window first:

    gtk_widget_realize(dr);
    gdk_window_set_cursor(dr->window, gdk_cursor_new(GDK_PENCIL));

    Whoever made that ->window geh into the API must really like pain. I'd have made an accessor function that would just realize the Gdk Window and *then* return it. Sigh.

    > Another problem: if I have multiple pixbufs to be over a drawing
    > area, there is
    > a way to draw them over only a pixbuf and repaint only it at expose
    > events or I
    > have to redraw all of them (in other words: can I use gdk-pixbuf or
    > another widget
    > as a offscreen drawable?)


    GdkPixmap is a offscreen drawable, processing on the X server.
    You can also compose other GdkPixbuf instances into a new GdkPixbuf (gdk_pixbuf_compose_simple) and then draw that on the drawing area, processing in your process, though.

    cheers,
    Danny

  4. Re: gtk programming

    On Sat, 27 Jan 2007 15:35:03 +0000 (UTC), "Danny Milosavljevic"
    wrote:

    >On Mon, 25 Dec 2006 02:50:24 -0800, gaetanoortisi wrote:
    >> Hello,
    >> I've started programming with gtk libs, and I have few questions about
    >> them:
    >>
    >> 1. Looking at Pango reference manual, I found a useful function named
    >> pango_parse_markup(). How is possible to use this to draw text with
    >> attributes together with GtkTextBuffer and GtkTextView?


    You might be better off asking these questions on the maillist at
    http://mail.gnome.org/mailman/listinfo/gtk-list

    As far as Pango and textviews go, I have a Perl example at
    http://zentara.net/perlplay/vgrep/

    you basically work the pango markup in thru the tag mechanism.
    There may be other ways too, so it's best to ask the maillists.

    zentara

    --
    I'm not really a human, but I play one on earth.
    http://zentara.net/japh.html

+ Reply to Thread