mattercontrol/PrinterControls/PrinterConnections/SetupConnectionWidgetBase.cs

104 lines
3.8 KiB
C#
Raw Normal View History

2015-04-08 15:20:10 -07:00
using MatterHackers.Agg;
2014-01-29 19:09:30 -08:00
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
2014-01-29 19:09:30 -08:00
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.PrinterCommunication;
2016-04-18 11:31:31 -07:00
using MatterHackers.MatterControl.SlicerConfiguration;
2015-04-08 15:20:10 -07:00
using System;
2014-01-29 19:09:30 -08:00
namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
2015-04-08 15:20:10 -07:00
{
public class SetupConnectionWidgetBase : ConnectionWidgetBase
{
//private GuiWidget mainContainer;
protected FlowLayoutWidget headerRow;
protected FlowLayoutWidget contentRow;
protected FlowLayoutWidget footerRow;
protected TextWidget headerLabel;
protected Button cancelButton;
protected TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();
protected LinkButtonFactory linkButtonFactory = new LinkButtonFactory();
2016-04-18 11:31:31 -07:00
public SetupConnectionWidgetBase(ConnectionWizard wizard) : base(wizard)
2015-04-08 15:20:10 -07:00
{
SetDisplayAttributes();
2016-04-18 11:31:31 -07:00
cancelButton = textImageButtonFactory.Generate("Cancel".Localize());
cancelButton.Name = "Setup Connection Cancel Button";
2016-04-18 11:31:31 -07:00
cancelButton.Click += CancelButton_Click;
2015-04-08 15:20:10 -07:00
//Create the main container
GuiWidget mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
mainContainer.AnchorAll();
2014-02-23 21:48:49 -08:00
mainContainer.Padding = new BorderDouble(3, 5, 3, 5);
2015-04-08 15:20:10 -07:00
mainContainer.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
//Create the header row for the widget
headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight);
headerRow.Margin = new BorderDouble(0, 3, 0, 0);
headerRow.Padding = new BorderDouble(0, 3, 0, 3);
headerRow.HAnchor = HAnchor.ParentLeftRight;
{
2016-04-18 11:31:31 -07:00
headerLabel = new TextWidget("3D Printer Setup".Localize(), pointSize: 14);
2015-04-08 15:20:10 -07:00
headerLabel.AutoExpandBoundsToText = true;
2016-04-18 11:31:31 -07:00
headerLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
2015-04-08 15:20:10 -07:00
headerRow.AddChild(headerLabel);
}
//Create the main control container
contentRow = new FlowLayoutWidget(FlowDirection.TopToBottom);
contentRow.Padding = new BorderDouble(5);
contentRow.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
contentRow.HAnchor = HAnchor.ParentLeftRight;
contentRow.VAnchor = VAnchor.ParentBottomTop;
//Create the footer (button) container
footerRow = new FlowLayoutWidget(FlowDirection.LeftToRight);
footerRow.HAnchor = HAnchor.ParentLeft | HAnchor.ParentRight;
footerRow.Margin = new BorderDouble(0, 3);
mainContainer.AddChild(headerRow);
mainContainer.AddChild(contentRow);
mainContainer.AddChild(footerRow);
this.AddChild(mainContainer);
}
protected void SaveAndExit()
{
2016-04-18 11:31:31 -07:00
ActiveSliceSettings.Instance.RunInTransaction(settings =>
{
settings.SetAutoConnect(ActivePrinter.AutoConnect);
settings.SetBaudRate(ActivePrinter.BaudRate);
settings.SetComPort(ActivePrinter.ComPort);
settings.SetDriverType(ActivePrinter.DriverType);
settings.SetId(ActivePrinter.Id);
settings.SetName(ActivePrinter.Name);
2016-04-18 11:31:31 -07:00
});
UiThread.RunOnIdle(connectionWizard.Close);
2015-04-08 15:20:10 -07:00
}
private void SetDisplayAttributes()
{
textImageButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor;
textImageButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryTextColor;
textImageButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryTextColor;
textImageButtonFactory.pressedTextColor = ActiveTheme.Instance.PrimaryTextColor;
2015-04-08 15:20:10 -07:00
textImageButtonFactory.borderWidth = 0;
2014-01-29 19:09:30 -08:00
linkButtonFactory.textColor = ActiveTheme.Instance.PrimaryTextColor;
2015-04-08 15:20:10 -07:00
linkButtonFactory.fontSize = 10;
this.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
this.AnchorAll();
this.Padding = new BorderDouble(0); //To be re-enabled once native borders are turned off
}
private void CancelButton_Click(object sender, EventArgs mouseEvent)
{
PrinterConnectionAndCommunication.Instance.HaltConnectionThread();
2016-04-18 11:31:31 -07:00
UiThread.RunOnIdle(connectionWizard.Close);
2015-04-08 15:20:10 -07:00
}
}
}