
Habe hier in MonoDevelop eine Gtk Anwendung ensprechend angepasst, dass ich sowohl über Session als auch MainWindow untereinander die Methoden abrufen kann. Beide Singleton.
Funktioniert ohne Probleme. Vielleicht hilft es bei meinem Problem, hier nach zu vollziehen was ich meine.
Gibt es auch in Python die Möglichkeit den Sachverhalt genauso nachzubilden?
Main.cs
Code: Alles auswählen
using System;
using Gtk;
namespace GtkApp
{
class MainClass
{
public static void Main (string[] args)
{
Application.Init ();
MainWindow.Instance.Show();
Session.Instance.TestGUI();
Application.Run ();
}
}
}
Code: Alles auswählen
using System;
namespace GtkApp
{
public sealed class Session
{
private static Session instance = new Session();
public static Session Instance {
get {
return instance;
}
}
private Session ()
{
// TODO:
}
public void TestGUI( )
{
MainWindow.Instance.MsgBox("Test GUI");
}
}
}
Code: Alles auswählen
using System;
using Gtk;
public sealed partial class MainWindow: Gtk.Window
{
private static MainWindow instance = new MainWindow();
public static MainWindow Instance {
get {
return instance;
}
}
private MainWindow (): base (Gtk.WindowType.Toplevel)
{
Build ();
}
private void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
public ResponseType MsgBox (string msg)
{
MessageDialog md = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, msg);
md.Title = "Test";
ResponseType tp = (ResponseType)md.Run ();
md.Destroy();
return tp;
}
private void OnButton2Clicked (object sender, EventArgs e)
{
GtkApp.Session.Instance.TestGUI();
}
}