GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

events with libglade

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
satyria
Familiar Face


Joined: 25 Feb 2008
Posts: 18

PostPosted: Thu Jun 12, 2008 11:03 am    Post subject: events with libglade Reply with quote

Hello,

I created a program with Glade, produced a GtkEventBox and included it with glade_xml_new in the program.

I would now like the position of the mouse query when the button was pressed.
Is there somewhere an example?

I Use:
Glade 3

Greetings, Satyria
Back to top
satyria
Familiar Face


Joined: 25 Feb 2008
Posts: 18

PostPosted: Thu Jun 12, 2008 11:25 am    Post subject: Reply with quote

Here are the mini-source code

Code: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <glade/glade.h>
#include <gtk/gtk.h>

G_MODULE_EXPORT void on_event (GtkToolButton *item)
{
  g_print ("Ein Event wurde ausgeloest!\n");

/*How can I retrieve the events?*/
 
}

G_MODULE_EXPORT void on_event_key_press_event (GtkToolButton *item)
{
  g_print ("Taste wurde gedrueckt!\n");
  gtk_main_quit();
}


G_MODULE_EXPORT void on_window_delete_event (GtkToolButton *item)
{
  g_print ("Beenden wurde gedrueckt!\n");
  gtk_main_quit();
}



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

  gtk_init (&argc, &argv);

  xml = glade_xml_new ("zeichnen.glade", NULL, NULL);
  window = glade_xml_get_widget (xml, "window");
 
  glade_xml_signal_autoconnect (xml);

  gtk_widget_show_all (window);
  gtk_main ();
 
  return 0;
}

and the glade code:
Code: (BC (Unix Calc))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.3 on Thu Jun 12 13:07:28 2008 -->
<glade-interface>
  <widget class="GtkWindow" id="window">
    <property name="title" translatable="yes">Zeichnen</property>
    <property name="default_width">300</property>
    <property name="default_height">300</property>
    <property name="icon">einhorn.jpg</property>
    <property name="icon_name">Zeichnen</property>
    <signal name="delete_event" handler="on_window_delete_event"/>
    <signal name="destroy_event" handler="on_window_delete_event"/>
    <child>
      <widget class="GtkEventBox" id="event">
        <property name="visible">True</property>
        <signal name="button_press_event" handler="on_event_button_press_event"/>
        <signal name="event" handler="on_event" object="user_event"/>
        <signal name="key_press_event" handler="on_event_key_press_event"/>
        <signal name="button_release_event" handler="on_event_button_release_event"/>
        <child>
          <widget class="GtkDrawingArea" id="drawingarea">
            <property name="visible">True</property>
            <property name="app_paintable">True</property>
          </widget>
        </child>
      </widget>
    </child>
  </widget>
</glade-interface>


Problem see line 8!
Back to top
satyria
Familiar Face


Joined: 25 Feb 2008
Posts: 18

PostPosted: Thu Jun 12, 2008 12:33 pm    Post subject: Reply with quote

Hello, I've found a way and my problem is solved.

Also:

In the file galde were deleted the events (which makes sense for this?).
In the source code, I have added these lines:

Code: (C)
1
2
3
4
5
6
7
8

   area =  glade_xml_get_widget (xml, "drawingarea");
   parray g_ptr_array_sized_new = (5000);

   gtk_widget_add_events (area, GDK_BUTTON_PRESS_MASK);
   
   g_signal_connect (G_OBJECT (area), "button_press_event"
                     
G_CALLBACK (button_pressed), parray);

And this feature:

Code: (C)
1
2
3
4
5
6
7
8
9
10
11
static gboolean button_pressed (GtkWidget * area,
                 GdkEventButton * event,
                 Parray GPtrArray *)
(
   int x, y;
   x = event-> x;
   y = event-> y;

   g_print ( "Der Button wurde bei %i %i ausgeloest\ n", x, y);
   return FALSE;
)
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP