loupiottes/DMX-2.0/MainWindow.cs

102 lines
No EOL
2.8 KiB
C#

using System;
using Gtk;
namespace DMX2
{
public partial class MainWindow: Gtk.Window
{
public MainWindow (): base (Gtk.WindowType.Toplevel)
{
Build ();
MajWidgets();
}
protected void MajWidgets ()
{
if (Conduite.Courante != null) {
seqLinAction.Sensitive = circAction.Sensitive = saveAction.Sensitive = saveAsAction.Sensitive = closeAction.Sensitive = true;
openAction.Sensitive = newAction.Sensitive = false;
this.Title = "DMX 2.0 - " + Conduite.Courante.Name;
} else {
seqLinAction.Sensitive = circAction.Sensitive = saveAction.Sensitive = saveAsAction.Sensitive = closeAction.Sensitive = false;
openAction.Sensitive = newAction.Sensitive = true;
this.Title = "DMX 2.0";
}
}
protected void MajCircuits ()
{
// Ajoute une ProgressBar par circuit, met a jour le texte si necessaire
if (vboxCircuits.Children.Length != Conduite.Courante.Circuits.Count) {
foreach (var widget in vboxCircuits.Children)
vboxCircuits.Remove (widget);
foreach (var circuit in Conduite.Courante.Circuits) {
vboxCircuits.PackStart (new ProgressBar (),false,false,0);
}
vboxCircuits.ShowAll ();
}
int i = 0;
foreach (var widget in vboxCircuits.Children) {
var c = Conduite.Courante.Circuits[i++];
ProgressBar pb = (ProgressBar)widget;
pb.Text = i.ToString() + " - " + c.Name;
pb.Fraction = (double) c.ValeurCourante / 255;
pb.HeightRequest = 22;
}
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
protected void OnQuitActionActivated (object sender, EventArgs e)
{
Application.Quit ();
}
protected void OnCircuitsActionActivated (object sender, EventArgs e)
{
GestionCircuits gc= new GestionCircuits(this);
gc.Run();
gc.Destroy();
MajCircuits();
}
protected void OnNewActionActivated (object sender, EventArgs e)
{
var dlg = new Dialog ("Nom ?", this, DialogFlags.Modal); var entry = new Entry ("Conduite sans Nom");
dlg.AddButton (Stock.Ok, ResponseType.Ok).GrabDefault(); dlg.AddButton (Stock.Cancel, ResponseType.Cancel);
dlg.VBox.Add (new Label("Nom de la nouvelle Conduite :")); dlg.VBox.Add (entry); dlg.VBox.ShowAll ();
entry.ActivatesDefault=true;
if ((ResponseType)dlg.Run () == ResponseType.Ok) {
Conduite.Courante = new Conduite ();
Conduite.Courante.Name = entry.Text;
}
MajWidgets();
dlg.Destroy();
}
protected void OnCloseActionActivated (object sender, EventArgs e)
{
Conduite.Courante.Dispose();
Conduite.Courante= null;
MajWidgets();
}
protected void OnSeqLinActionActivated (object sender, EventArgs e)
{
Sequenceur s = new SequenceurLineaire();
Conduite.Courante.AjoutSequenceur(s);
AddSeqUI(s);
}
void AddSeqUI (Sequenceur s)
{
seqUiVbox.Add(s.GetUI());
seqUiVbox.ShowAll();
}
}
}