[Gtk-sharp-list] Popup window

Lee Mallabone gnome@fonicmonkey.net
26 Feb 2003 21:18:20 +0000


--=-sjg6XlIxnLPIxUhbAS25
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Wed, 2003-02-26 at 21:00, Jorge De Gante wrote:
> 
> Can someone make an sample application of:
> 
> Gnome Toplevel main window with menu entries
> Popup Window with controls
> The popup window is invoked from the top level by clicking an option of
> the menu

Hi,

Well you're not very specific about what you actually want to do, but the attached code what you described.

I'm lazy so it uses glade for the (very rudimentary) gui. Glade is fantastic, so I find that jusitfies my laziness. :)
You can compile it with:
mcs windows.cs /resource:windows.glade -r gtk-sharp -r glade-sharp

and then run with 'mono windows.exe'

Hope that helps?

Lee.



--=-sjg6XlIxnLPIxUhbAS25
Content-Disposition: attachment; filename=windows.cs
Content-Type: text/plain; name=windows.cs; charset=ANSI_X3.4-1968
Content-Transfer-Encoding: 7bit

using Gtk;
using Glade;

public class Popper
{
	[GladeWidget] private Window window1;
	[GladeWidget] private Window window2;
	
	public Popper()
	{
		Glade.XML windows = new Glade.XML(null, "windows.glade", null, null);
		windows.Autoconnect(this);
		window1.ShowAll();
		window2.Hide();
	}
	
	private void menuItemHandler(object source, System.EventArgs args)
	{
		window2.ShowAll();
	}

	public static void Main(string[] args)
	{
		Application.Init();
		new Popper();
		
		Application.Run();
	}
}

--=-sjg6XlIxnLPIxUhbAS25
Content-Disposition: attachment; filename=windows.glade
Content-Type: application/x-glade; name=windows.glade
Content-Transfer-Encoding: 7bit

<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">

<glade-interface>

<widget class="GtkWindow" id="window1">
  <property name="visible">True</property>
  <property name="title" translatable="yes">window1</property>
  <property name="type">GTK_WINDOW_TOPLEVEL</property>
  <property name="window_position">GTK_WIN_POS_NONE</property>
  <property name="modal">False</property>
  <property name="resizable">True</property>
  <property name="destroy_with_parent">False</property>

  <child>
    <widget class="GtkVBox" id="vbox1">
      <property name="visible">True</property>
      <property name="homogeneous">False</property>
      <property name="spacing">0</property>

      <child>
	<widget class="GtkMenuBar" id="menubar1">
	  <property name="visible">True</property>

	  <child>
	    <widget class="GtkMenuItem" id="menuitem4">
	      <property name="visible">True</property>
	      <property name="label" translatable="yes">_File</property>
	      <property name="use_underline">True</property>

	      <child>
		<widget class="GtkMenu" id="menuitem4_menu">

		  <child>
		    <widget class="GtkImageMenuItem" id="new1">
		      <property name="visible">True</property>
		      <property name="label">gtk-new</property>
		      <property name="use_stock">True</property>
		      <signal name="activate" handler="menuItemHandler" last_modification_time="Wed, 26 Feb 2003 21:08:02 GMT"/>
		    </widget>
		  </child>
		</widget>
	      </child>
	    </widget>
	  </child>
	</widget>
	<packing>
	  <property name="padding">0</property>
	  <property name="expand">False</property>
	  <property name="fill">False</property>
	</packing>
      </child>

      <child>
	<widget class="GtkColorSelection" id="colorselection1">
	  <property name="visible">True</property>
	  <property name="has_opacity_control">True</property>
	  <property name="has_palette">False</property>
	</widget>
	<packing>
	  <property name="padding">0</property>
	  <property name="expand">True</property>
	  <property name="fill">True</property>
	</packing>
      </child>
    </widget>
  </child>
</widget>

<widget class="GtkWindow" id="window2">
  <property name="visible">True</property>
  <property name="title" translatable="yes">Popup window</property>
  <property name="type">GTK_WINDOW_POPUP</property>
  <property name="window_position">GTK_WIN_POS_NONE</property>
  <property name="modal">False</property>
  <property name="resizable">True</property>
  <property name="destroy_with_parent">False</property>

  <child>
    <widget class="GtkVBox" id="vbox2">
      <property name="visible">True</property>
      <property name="homogeneous">False</property>
      <property name="spacing">0</property>

      <child>
	<widget class="GtkLabel" id="label1">
	  <property name="visible">True</property>
	  <property name="label" translatable="yes">This is a popup window!</property>
	  <property name="use_underline">False</property>
	  <property name="use_markup">False</property>
	  <property name="justify">GTK_JUSTIFY_LEFT</property>
	  <property name="wrap">False</property>
	  <property name="selectable">False</property>
	  <property name="xalign">0.5</property>
	  <property name="yalign">0.5</property>
	  <property name="xpad">0</property>
	  <property name="ypad">0</property>
	</widget>
	<packing>
	  <property name="padding">0</property>
	  <property name="expand">False</property>
	  <property name="fill">False</property>
	</packing>
      </child>

      <child>
	<widget class="GtkFontSelection" id="fontselection1">
	  <property name="visible">True</property>
	  <property name="preview_text" translatable="yes">abcdefghijk ABCDEFGHIJK</property>
	</widget>
	<packing>
	  <property name="padding">0</property>
	  <property name="expand">True</property>
	  <property name="fill">True</property>
	</packing>
      </child>
    </widget>
  </child>
</widget>

</glade-interface>

--=-sjg6XlIxnLPIxUhbAS25--