[MonoDevelop] Stetic add-in and treeview widget event question

Paddy Joy mono at paddyjoy.com
Sun Apr 9 18:30:12 EDT 2006


Thanks Matze,

I searched google for GLib.ConnectBefore and found some extra info about 
it in the Gtk# FAQ!

Paddy


      3.3  Why don't I get ButtonPressEvents from my Button/Treeview?

As of release 0.15, Gtk# started using the CONNECT_AFTER flag when 
connecting event handlers to signals. This means that the event handlers 
are not run until after the default signal handlers, which means that 
the widget will be updated when the event handlers run. A side effect of 
this change is that in the case where default handlers return true to 
stop signal propogation, Gtk# events will not be emitted. This is the 
case for example in Gtk.Button, where the button-press-event default 
signal handler is overridden to emit Pressed events. TreeView has a 
similar situation.

While potentially confusing, this is not really a bug. When you use a 
Gtk.Button, you are getting a widget that emits Pressed events in 
response to Button1 presses. If you also want your Button to change 
colors, or popup a context menu on Button3 presses, that's not a 
Gtk.Button. The correct way to implement such a widget is to subclass 
Gtk.Button and override the OnButtonPressEvent virtual method to 
implement the new behaviors you desire.

Many Gtk+ developers have gotten used to being able to do these kind of 
things via signal handlers since g_signal_connect is typically used 
without the CONNECT_AFTER flag in C code. If you are convinced that you 
want to use g_signal_connect to pierce the encapsulation of a Widget and 
alter its default behavior, you can tag your callback method with the 
[GLib.ConnectBefore] attribute to force it to run before the default 
handler. This attribute was added in version 0.18 due to public outcry, 
but the default behavior is still to run event handlers after the 
default handler.



Matze Braun wrote:
> The problem with the code is that you have to use the
> [GLib.ConnectBefore] attribute on the OnButtonPress handler. Otherwise
> the treeview will eat the buttonpress and your custom handler won't run
> anymore. I haven't used stetic yet and can't say if or how this is
> possible in stetic.
>
> Greetings,
> 	Matze
>
> Am Sonntag, den 09.04.2006, 12:04 +1000 schrieb Paddy Joy:
>   
>> Sorry I attached the wrong code that time!
>>
>> Paddy
>>
>>     
>>> Hi,
>>>
>>> I have recently started playing with the new monodevelop stetic 
>>> add-in, I'm very impressed, well done everyone!
>>>
>>> Just as a simple test what I am trying to do is add a treeview to my 
>>> main window and then when a user clicks on a treeview item I want to 
>>> take an action. So far my event handlers work ok for the 
>>> KeyReleaseEvent but don't work for the ButtonPressEvent. These are the 
>>> exact steps I'm doing in monodevelop:
>>>
>>> 1.      Create new gtk# project
>>> 2.      Double click to open MainWindow in gui editor
>>> 3.      Add treeview to main window
>>> 4.      Click on signals tab
>>> 5.      Under Common Widget Signals double click on KeyReleaseEvent to 
>>> add event handler
>>> 6.      Under Common Widget Signals double click on ButtonPressEvent 
>>> to add event handler
>>> 7.      Click on source tab to see code for MainWindow.cs
>>> 8.      Add Console.WriteLine()'s to both handlers
>>> 9.      Add some code to populate the treeview
>>>
>>>        TreeView                treeview1;
>>> :
>>> :
>>> :
>>> :
>>>
>>>        Gtk.ListStore musicListStore = new Gtk.ListStore (typeof 
>>> (Gdk.Pixbuf),
>>>                        typeof (string),  typeof (string));
>>>
>>>                treeview1.AppendColumn ("Icon", new 
>>> Gtk.CellRendererPixbuf (), "pixbuf", 0);
>>>                treeview1.AppendColumn ("Artist", new 
>>> Gtk.CellRendererText (), "text", 1);
>>>                treeview1.AppendColumn ("Title", new 
>>> Gtk.CellRendererText (), "text", 2);
>>>
>>>                musicListStore.AppendValues (new Gdk.Pixbuf 
>>> ("TreeViewRupertIcon.png"),
>>>                        "Rupert", "Yellow bananas");
>>>
>>>                treeview1.Model = musicListStore;
>>>
>>> 10.     Compile and run project
>>> 11.     Click on treeview item then press a key, text writen to 
>>> console as expected
>>> 12.     Click on item, no text writen to console
>>>
>>> It seems like my ButtonPressEvent handler is never being called. Am I 
>>> doing something wrong here? I have attached some relevant code.
>>>
>>> Thanks,
>>> Paddy
>>>
>>>       
>> einfaches Textdokument-Anlage (gui.stetic)
>> <?xml version="1.0" encoding="utf-8"?>
>> <stetic-interface>
>>   <widget class="Gtk.Window" id="MainWindow" design-size="400 300">
>>     <property name="Title" translatable="yes">MainWindow</property>
>>     <property name="WindowPosition">CenterOnParent</property>
>>     <property name="Visible">True</property>
>>     <property name="Events">0</property>
>>     <signal name="DeleteEvent" handler="OnDeleteEvent" />
>>     <child>
>>       <widget class="Gtk.TreeView" id="treeview1">
>>         <property name="Visible">True</property>
>>         <property name="CanFocus">True</property>
>>         <property name="Events">0</property>
>>         <signal name="RowActivated" handler="OnTreeview1RowActivated" />
>>         <signal name="ButtonPressEvent" handler="ButtonPressEvent" />
>>         <signal name="KeyReleaseEvent" handler="KeyReleaseHandler" />
>>       </widget>
>>     </child>
>>   </widget>
>> </stetic-interface>
>> _______________________________________________ Monodevelop-list mailing list Monodevelop-list at lists.ximian.com http://lists.ximian.com/mailman/listinfo/monodevelop-list
>>     
>
>   


More information about the Monodevelop-list mailing list