[Gtk-sharp-list] Annoying disappearing window problem
Aaron Oxford
aaron at hardwarehookups.com.au
Thu Jul 5 07:13:20 EDT 2007
Hi all,
I'm still having this problem where my main window loses focus after
showing a dialog. The rather contrived scenario is one of the ways I
can find to replicate the problem, which appears to occur as a result
of launching one dialog from another dialog (for a context menu).
Here I've demonstrated it occurring as a result of showing two dialogs at once.
It's not just that the window becomes inactive, Gtk# actively seeks
out another application's window, brings it to the front, and
activates it. This is making my application impossible to use. Please help!
Aaron.
using System;
using Gtk;
using Gdk;
public class Test
{
private Label label = null;
private int counter = 0;
private int configurationFailed = 0;
private Gtk.Window wnd;
const string s = "the quick brown fox jumped over the lazy dog. ";
// Create the window.
public static void Main()
{
if (!GLib.Thread.Supported) GLib.Thread.Init();
Gdk.Threads.Init();
Gdk.Threads.Enter();
Application.Init();
Test t = new Test();
GLib.Timeout.Add(100, new GLib.TimeoutHandler(t.Tick));
Application.Run();
Gdk.Threads.Leave();
}
// This is our window.
public Test()
{
wnd = new Gtk.Window("Test");
wnd.Destroyed += new EventHandler(wnd_Destroyed);
VBox vbox = new VBox();
label = new Label(counter.ToString());
vbox.PackStart(label, false, false, 0);
Button b = new Button();
b.Label = "mofokr";
b.Clicked += new EventHandler(b_Clicked);
vbox.PackStart(b, false, false, 0);
wnd.Add(vbox);
wnd.ShowAll();
}
void b_Clicked(object sender, EventArgs e)
{
configurationFailed = 1;
showMessage(s);
}
// Timer function.
private bool Tick()
{
Gdk.Threads.Enter();
if (configurationFailed > 0)
{
showMessage(s);
configurationFailed--;
}
label.Text = "" + counter;
counter++;
Gdk.Threads.Leave();
return true;
}
// Show a dialog.
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.WidthRequest = 285;
l.Wrap = true;
sw.AddWithViewport(l);
dlg.VBox.PackStart(sw);
dlg.SetDefaultSize(320, 160);
dlg.ShowAll();
dlg.Run();
dlg.Destroy();
}
// Close program.
void wnd_Destroyed(object sender, EventArgs e)
{
Application.Quit();
}
}
---------------------------------------------------------------------------------
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