Simple Gtk app.



Jose Eusebio Roza Pando escribió:

Ahh! I think i know the solution.
The callback must return TRUE.
            Eusebio

Mark Hannah escribió:

Hi,
   The part about the callbacks and the signal handler
make sense to me, but I don't know what the
"gtk_widget_set[add]_events" part does?

I have copied my program below. The problem is that
when a key is pressed, the callbacjk function is not
being run.

I am sure I am doing something silly, I just don't
know what.

-------------------------------
-------------------------------

#include <gnome.h>

static void key_press_cb(GtkWidget *widget,
GdkEventKey* event)
{
  // Print the keyvalue pressed.
  printf("A key has been pressed!\n");

  /* prevent the default handler from being run */
  gtk_signal_emit_stop_by_name
(GTK_OBJECT(widget),"key_press_event");
}

int main(int argc, char* argv[])
{
        GtkWidget *window;
        GtkWidget *image;

        gtk_init(&argc, &argv);

        // Create a new window.
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

        // The keypress callback function.

gtk_signal_connect(GTK_OBJECT(window),"key_press_event",GTK_SIGNAL_FUNC(key_press_cb),NULL);

        gtk_widget_set_events(window, GDK_KEY_PRESS_MASK);

        // Load the image from a file.
        image = gnome_pixmap_new_from_file("image1.jpg");

        // Test that our image loaded ok.
        if (image == NULL) printf("Failed to load
image!\n");
        else printf("Loaded image!\n");

        // Add the pixmap to the window.
        gtk_container_add(GTK_CONTAINER(window),image);

        // Set the window size.

gtk_window_set_default_size((GtkWindow*)window,100,100);

        // Display the new window.
        gtk_widget_show_all(window);

        // The main gnome loop runs forever.
        gtk_main();

        return(0);
}

--- Jose Eusebio Roza Pando <jeroza alu uah es> wrote:
To interpret the keystrokes you can use the code
shown below.
I do not know the way to move the pixmap in gtk, but
i know
that is possible with gtkextra lib. You must create
a canvas
and you must insert inside a child (a pixmap for
example) and
move it easily.
    Eusebio
The code was generated by Carlos Pereira in other
mail:

These examples should answer your question.
Carlos

------------monitor events----------------
gtk_widget_set[add]_events (GTK_WIDGET (window),
GDK_EXPOSURE_MASK |
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK |
GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);

--------connect-------------
gtk_signal_connect(GTK_OBJECT (window),
"key_press_event",

GTK_SIGNAL_FUNC(app_gtk_handle_key_press), data);

--------callback---------------
#include <gdk/gdkkeysyms.h>

gint app_gtk_handle_key_press (GtkWidget *widget,
GdkEventKey *event,
gpointer data)
{
switch (event->keyval)
  {
  case GDK_Escape:

  case GDK_F2:

  case GDK_F3:

  case GDK_Page_Down:
  }

/* prevent the default handler from being run */
gtk_signal_emit_stop_by_name
(GTK_OBJECT(widget),"key_press_event");

return TRUE;
}

Mark Hannah escribió:

Hi,
    I'm having problems writing a simple Gtk app.

What I want to do is open a window and place a
pixmap
image in the window. I would then like to use the
keyboard arrow keys to move the image around the
window.

I can get as far as displaying thr pixmap in the
window, but I do not know how to capture and
interpret
the keystrokes or move the pixmap position.

Can anyone help?

Many thanks,
Mark.



____________________________________________________________
Do You Yahoo!?
Get your free @yahoo.co.uk address at
http://mail.yahoo.co.uk
or your free @yahoo.ie address at
http://mail.yahoo.ie

_______________________________________________
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

____________________________________________________________
Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]