[MonoDevelop] Stetic add-in and treeview widget event question
Paddy Joy
mono at paddyjoy.com
Sun Apr 9 06:39:56 EDT 2006
After playing around with this for a bit more I have found that when a
user clicks on a treeview item the ButtonPressEvent is not fired however
when releasing the mouse button the ButtonReleaseEvent is fired.
Is this a bug? Should the ButtonPressEvent be fired when the user clicks?
Paddy
> 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
>>
>
> ------------------------------------------------------------------------
>
> using System;
> using Gtk;
>
> public class MainWindow: Gtk.Window
> {
> TreeView treeview1;
>
> public MainWindow (): base ("")
> {
> Stetic.Gui.Build (this, "MainWindow");
>
> 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 ("/tmp/1.jpg"),
> "Rupert", "Yellow bananas");
>
> treeview1.Model = musicListStore;
>
> }
>
> protected void OnDeleteEvent (object sender, DeleteEventArgs a)
> {
> Application.Quit ();
> a.RetVal = true;
> }
>
> protected virtual void OnTreeview1RowActivated(object o, Gtk.RowActivatedArgs args)
> {
> Console.WriteLine("OnTreeViewRowActivated");
> }
>
> protected virtual void ButtonPressEvent(object o, Gtk.ButtonPressEventArgs args)
> {
> Console.WriteLine("OnTreeViewButtonPressEvent");
> }
>
> protected virtual void KeyReleaseHandler(object o, Gtk.KeyReleaseEventArgs args)
> {
> Console.WriteLine("KeyReleaseHandler");
> }
>
> protected override bool OnButtonPressEvent(Gdk.EventButton evnt){
> base.OnButtonPressEvent(evnt);
> return false;
> }
>
>
> }
> ------------------------------------------------------------------------
>
> // ------------------------------------------------------------------------------
> // <autogenerated>
> // This code was generated by a tool.
> // Mono Runtime Version: 1.1.4322.2032
> //
> // Changes to this file may cause incorrect behavior and will be lost if
> // the code is regenerated.
> // </autogenerated>
> // ------------------------------------------------------------------------------
>
> namespace Stetic {
>
> class Gui {
>
> public static void Build(object obj, System.Type type) {
> Stetic.Gui.Build(obj, type.FullName);
> }
>
> public static void Build(object obj, string id) {
> System.Collections.Hashtable widgets = new System.Collections.Hashtable();
> if ((id == "MainWindow")) {
> Gtk.Window cobj = ((Gtk.Window)(obj));
> // Widget MainWindow
> cobj.Title = "MainWindow";
> cobj.WindowPosition = ((Gtk.WindowPosition)(4));
> cobj.Events = ((Gdk.EventMask)(0));
> cobj.Name = "MainWindow";
> // Container child MainWindow.Gtk.Container+ContainerChild
> Gtk.TreeView w1 = new Gtk.TreeView();
> w1.CanFocus = true;
> w1.Events = ((Gdk.EventMask)(0));
> w1.Name = "treeview1";
> widgets["treeview1"] = w1;
> cobj.Add(w1);
> cobj.DefaultWidth = 400;
> cobj.DefaultHeight = 300;
> widgets["MainWindow"] = cobj;
> w1.Show();
> cobj.Show();
> cobj.DeleteEvent += ((Gtk.DeleteEventHandler)(System.Delegate.CreateDelegate(typeof(Gtk.DeleteEventHandler), cobj, "OnDeleteEvent")));
> w1.RowActivated += ((Gtk.RowActivatedHandler)(System.Delegate.CreateDelegate(typeof(Gtk.RowActivatedHandler), cobj, "OnTreeview1RowActivated")));
> w1.ButtonPressEvent += ((Gtk.ButtonPressEventHandler)(System.Delegate.CreateDelegate(typeof(Gtk.ButtonPressEventHandler), cobj, "ButtonPressEvent")));
> w1.KeyReleaseEvent += ((Gtk.KeyReleaseEventHandler)(System.Delegate.CreateDelegate(typeof(Gtk.KeyReleaseEventHandler), cobj, "KeyReleaseHandler")));
> }
> System.Reflection.FieldInfo[] fields = obj.GetType().GetFields(((System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic) | System.Reflection.BindingFlags.Instance));
> for (int n = 0; (n < fields.Length); n = (n + 1)) {
> System.Reflection.FieldInfo field = fields[n];
> object widget = widgets[field.Name];
> if (((widget != null) && field.FieldType.IsInstanceOfType(widget))) {
> field.SetValue(obj, widget);
> }
> }
> }
> }
>
> }
>
> ------------------------------------------------------------------------
>
> <?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>
More information about the Monodevelop-list
mailing list