[Gtk-sharp-list] Opening a DYK dialog

Aaron Oxford aaron at hardwarehookups.com.au
Fri Apr 20 03:12:21 EDT 2007


Hi all,

I'm still struggling with this code (attached and posted below). I've 
tried all kinds of work-arounds, but the basic problem still comes 
down to what is demonstrated by the code. I'm guessing that since I 
haven't heard from anyone so far it works on some people's systems, 
but the question still remains: Why? :-)

Thanks in advance for any help,

Aaron.


using System;
using Gtk;
using Gdk;

public class Test
{
     private Label label = null;
     private int counter = 0;
     private bool configurationFailed = false;
     private Gtk.Window wnd;

     // Want to display a dialog, but can't...
     public static void Main()
     {
         if (!GLib.Thread.Supported) GLib.Thread.Init();
         Gdk.Threads.Init();
         Application.Init();

         Test t = new Test();

         // ...after constructing main window.
         t.showMessage("ioLet Composer.");

         GLib.Timeout.Add(100, new GLib.TimeoutHandler(t.Tick));

         // ...after starting the timer.
         //t.showMessage("VioLet Composer.");

         Gdk.Threads.Enter();

         // ...after the magic call.
         //t.showMessage("oLet Composer.");

         Application.Run();
         Gdk.Threads.Leave();
     }

     public Test()
     {
         wnd = new Gtk.Window("Test");
         wnd.Destroyed += new EventHandler(wnd_Destroyed);

         // Ladida, Gtk# is cool...
         VBox vbox = new VBox();
         label = new Label(counter.ToString());
         vbox.PackStart(label, false, false, 0);
         wnd.Add(vbox);
         wnd.ShowAll();

         // ...and then for some reason:
         // (this line invokes the timer based popup).
         configurationFailed = true;
     }

     void wnd_Destroyed(object sender, EventArgs e)
     {
         Application.Quit();
     }

     private bool Tick()
     {
         if (configurationFailed)
         {
             // ...during a timer (ie AFTER Gtk starts)
             //showMessage("new settings for VioLet Composer.");
             configurationFailed = false;
         }
         label.Text = "" + counter;
         counter++;
         return true;
     }

     private void showMessage(string p)
     {
         Gtk.Dialog dlg = new Dialog("caption", wnd, DialogFlags.Modal);
         dlg.AddButton(Gtk.Stock.Ok, Gtk.ResponseType.Ok);
         dlg.DefaultResponse = Gtk.ResponseType.Ok;
         ScrolledWindow sw = new ScrolledWindow();
         Label l = new Label(p);
         l.Wrap = true;
         sw.AddWithViewport(l);
         dlg.VBox.PackStart(sw);
         dlg.SetDefaultSize(320, 160);

         dlg.ShowAll();
         dlg.Run();
         dlg.Destroy();
     }
}
-------------- next part --------------
using System;
using Gtk;
using Gdk;

public class Test
{
    private Label label = null;
    private int counter = 0;
    private bool configurationFailed = false;
    private Gtk.Window wnd;

    // Want to display a dialog, but can't...
    public static void Main()
    {
        if (!GLib.Thread.Supported) GLib.Thread.Init();
        Gdk.Threads.Init();
        Application.Init();

        Test t = new Test();

        // ...after constructing main window.
        t.showMessage("ioLet Composer.");

        GLib.Timeout.Add(100, new GLib.TimeoutHandler(t.Tick));

        // ...after starting the timer.
        //t.showMessage("VioLet Composer.");

        Gdk.Threads.Enter();

        // ...after the magic call.
        //t.showMessage("oLet Composer.");

        Application.Run();
        Gdk.Threads.Leave();
    }

    public Test()
    {
        wnd = new Gtk.Window("Test");
        wnd.Destroyed += new EventHandler(wnd_Destroyed);

        // Ladida, Gtk# is cool...
        VBox vbox = new VBox();
        label = new Label(counter.ToString());
        vbox.PackStart(label, false, false, 0);
        wnd.Add(vbox);
        wnd.ShowAll();

        // ...and then for some reason:
        // (this line invokes the timer based popup).
        configurationFailed = true;
    }

    void wnd_Destroyed(object sender, EventArgs e)
    {
        Application.Quit();
    }

    private bool Tick()
    {
        if (configurationFailed)
        {
            // ...during a timer (ie AFTER Gtk starts)
            //showMessage("new settings for VioLet Composer.");
            configurationFailed = false;
        }
        label.Text = "" + counter;
        counter++;
        return true;
    }

    private void showMessage(string p)
    {
        Gtk.Dialog dlg = new Dialog("caption", wnd, DialogFlags.Modal);
        dlg.AddButton(Gtk.Stock.Ok, Gtk.ResponseType.Ok);
        dlg.DefaultResponse = Gtk.ResponseType.Ok;
        ScrolledWindow sw = new ScrolledWindow();
        Label l = new Label(p);
        l.Wrap = true;
        sw.AddWithViewport(l);
        dlg.VBox.PackStart(sw);
        dlg.SetDefaultSize(320, 160);

        dlg.ShowAll();
        dlg.Run();
        dlg.Destroy();
    }
}
-------------- next part --------------
---------------------------------------------------------------------------------
Aaron Oxford   -   aaron+hardwarehookups .com .au
Director, Innovative Computer Solutions (Aust) Pty. Ltd.
49 Maitland Rd, Mayfield, NSW 2304 Australia
http://www.ic-solutions.com.au
Developer, SourceForge project VioLet Composer
http://sourceforge.net/projects/buzz-like


More information about the Gtk-sharp-list mailing list