Refactored PrinterActionRow
made show_reset_connection a SettingsKey Made the show_reset_connection less expensive to change
This commit is contained in:
parent
f366736a46
commit
a3c0cdcea5
5 changed files with 99 additions and 95 deletions
|
|
@ -362,7 +362,7 @@ namespace MatterHackers.MatterControl.ActionBar
|
|||
}
|
||||
|
||||
if (PrinterConnectionAndCommunication.Instance.PrinterIsConnected
|
||||
&& ActiveSliceSettings.Instance.GetValue<bool>("show_reset_connection")
|
||||
&& ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.show_reset_connection)
|
||||
&& UserSettings.Instance.IsTouchScreen)
|
||||
{
|
||||
this.activePrintButtons.Add(resetConnectionButton);
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ namespace MatterHackers.MatterControl.ActionBar
|
|||
private string disconnectAndCancelMessage = "Disconnect and cancel the current print?".Localize();
|
||||
private string disconnectAndCancelTitle = "WARNING: Disconnecting will cancel the print.".Localize();
|
||||
private Button disconnectPrinterButton;
|
||||
private Button resetConnectionButton;
|
||||
private PrinterSelector printerSelector;
|
||||
|
||||
private event EventHandler unregisterEvents;
|
||||
|
|
@ -84,89 +83,115 @@ namespace MatterHackers.MatterControl.ActionBar
|
|||
}
|
||||
actionBarButtonFactory.hoverBorderColor = new RGBA_Bytes(128, 128, 128);
|
||||
|
||||
string connectString = "Connect".Localize().ToUpper();
|
||||
connectPrinterButton = actionBarButtonFactory.Generate(connectString, "icon_power_32x32.png");
|
||||
connectPrinterButton.ToolTipText = "Connect to the currently selected printer".Localize();
|
||||
if (ApplicationController.Instance.WidescreenMode)
|
||||
// connect and disconnect buttons
|
||||
{
|
||||
connectPrinterButton.Margin = new BorderDouble(0, 0, 3, 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
connectPrinterButton.Margin = new BorderDouble(6, 0, 3, 3);
|
||||
}
|
||||
connectPrinterButton.VAnchor = VAnchor.ParentTop;
|
||||
connectPrinterButton.Cursor = Cursors.Hand;
|
||||
string connectString = "Connect".Localize().ToUpper();
|
||||
connectPrinterButton = actionBarButtonFactory.Generate(connectString, "icon_power_32x32.png");
|
||||
connectPrinterButton.ToolTipText = "Connect to the currently selected printer".Localize();
|
||||
if (ApplicationController.Instance.WidescreenMode)
|
||||
{
|
||||
connectPrinterButton.Margin = new BorderDouble(0, 0, 3, 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
connectPrinterButton.Margin = new BorderDouble(6, 0, 3, 3);
|
||||
}
|
||||
connectPrinterButton.VAnchor = VAnchor.ParentTop;
|
||||
connectPrinterButton.Cursor = Cursors.Hand;
|
||||
connectPrinterButton.Click += (s, e) =>
|
||||
{
|
||||
Button buttonClicked = ((Button)s);
|
||||
if (buttonClicked.Enabled)
|
||||
{
|
||||
if (ActiveSliceSettings.Instance.PrinterSelected)
|
||||
{
|
||||
ConnectToActivePrinter(null, null);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
string disconnectString = "Disconnect".Localize().ToUpper();
|
||||
disconnectPrinterButton = actionBarButtonFactory.Generate(disconnectString, "icon_power_32x32.png");
|
||||
disconnectPrinterButton.ToolTipText = "Disconnect from current printer".Localize();
|
||||
if (ApplicationController.Instance.WidescreenMode)
|
||||
{
|
||||
disconnectPrinterButton.Margin = new BorderDouble(0, 0, 3, 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
disconnectPrinterButton.Margin = new BorderDouble(6, 0, 3, 3);
|
||||
}
|
||||
disconnectPrinterButton.VAnchor = VAnchor.ParentTop;
|
||||
disconnectPrinterButton.Cursor = Cursors.Hand;
|
||||
string disconnectString = "Disconnect".Localize().ToUpper();
|
||||
disconnectPrinterButton = actionBarButtonFactory.Generate(disconnectString, "icon_power_32x32.png");
|
||||
disconnectPrinterButton.ToolTipText = "Disconnect from current printer".Localize();
|
||||
if (ApplicationController.Instance.WidescreenMode)
|
||||
{
|
||||
disconnectPrinterButton.Margin = new BorderDouble(0, 0, 3, 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
disconnectPrinterButton.Margin = new BorderDouble(6, 0, 3, 3);
|
||||
}
|
||||
disconnectPrinterButton.VAnchor = VAnchor.ParentTop;
|
||||
disconnectPrinterButton.Cursor = Cursors.Hand;
|
||||
disconnectPrinterButton.Click += (s, e) => UiThread.RunOnIdle(OnIdleDisconnect);
|
||||
|
||||
string resetConnectionText = "Reset\nConnection".Localize().ToUpper();
|
||||
resetConnectionButton = actionBarButtonFactory.Generate(resetConnectionText, "e_stop4.png");
|
||||
if (ApplicationController.Instance.WidescreenMode)
|
||||
{
|
||||
resetConnectionButton.Margin = new BorderDouble(0, 0, 3, 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
resetConnectionButton.Margin = new BorderDouble(6, 0, 3, 3);
|
||||
// Bind connect button states to active printer state
|
||||
this.SetConnectionButtonVisibleState();
|
||||
|
||||
actionBarButtonFactory.invertImageLocation = true;
|
||||
|
||||
this.AddChild(connectPrinterButton);
|
||||
this.AddChild(disconnectPrinterButton);
|
||||
}
|
||||
|
||||
// Bind connect button states to active printer state
|
||||
this.SetConnectionButtonVisibleState();
|
||||
|
||||
actionBarButtonFactory.invertImageLocation = true;
|
||||
|
||||
this.AddChild(connectPrinterButton);
|
||||
this.AddChild(disconnectPrinterButton);
|
||||
|
||||
FlowLayoutWidget printerSelectorAndEditButton = new FlowLayoutWidget()
|
||||
// printer selector and edit button
|
||||
{
|
||||
HAnchor = HAnchor.ParentLeftRight,
|
||||
};
|
||||
FlowLayoutWidget printerSelectorAndEditButton = new FlowLayoutWidget()
|
||||
{
|
||||
HAnchor = HAnchor.ParentLeftRight,
|
||||
};
|
||||
|
||||
int rightMarginForWideScreenMode = ApplicationController.Instance.WidescreenMode ? 6 : 0;
|
||||
printerSelector = new PrinterSelector()
|
||||
int rightMarginForWideScreenMode = ApplicationController.Instance.WidescreenMode ? 6 : 0;
|
||||
printerSelector = new PrinterSelector()
|
||||
{
|
||||
HAnchor = HAnchor.ParentLeftRight,
|
||||
Cursor = Cursors.Hand,
|
||||
Margin = new BorderDouble(0, 6, rightMarginForWideScreenMode, 3)
|
||||
};
|
||||
printerSelector.AddPrinter += (s, e) => WizardWindow.ShowPrinterSetup();
|
||||
// make sure the control can get smaller but maintains its height
|
||||
printerSelector.MinimumSize = new Vector2(0, connectPrinterButton.MinimumSize.y);
|
||||
printerSelectorAndEditButton.AddChild(printerSelector);
|
||||
|
||||
Button editButton = TextImageButtonFactory.GetThemedEditButton();
|
||||
editButton.VAnchor = VAnchor.ParentCenter;
|
||||
editButton.Click += UiNavigation.GoToEditPrinter_Click;
|
||||
printerSelectorAndEditButton.AddChild(editButton);
|
||||
this.AddChild(printerSelectorAndEditButton);
|
||||
}
|
||||
|
||||
// reset connection button
|
||||
{
|
||||
HAnchor = HAnchor.ParentLeftRight,
|
||||
Cursor = Cursors.Hand,
|
||||
Margin = new BorderDouble(0, 6, rightMarginForWideScreenMode, 3)
|
||||
};
|
||||
printerSelector.AddPrinter += (s, e) => WizardWindow.ShowPrinterSetup();
|
||||
printerSelector.MinimumSize = new Vector2(printerSelector.MinimumSize.x, connectPrinterButton.MinimumSize.y);
|
||||
printerSelectorAndEditButton.AddChild(printerSelector);
|
||||
string resetConnectionText = "Reset\nConnection".Localize().ToUpper();
|
||||
Button resetConnectionButton = actionBarButtonFactory.Generate(resetConnectionText, "e_stop4.png");
|
||||
if (ApplicationController.Instance.WidescreenMode)
|
||||
{
|
||||
resetConnectionButton.Margin = new BorderDouble(0, 0, 3, 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
resetConnectionButton.Margin = new BorderDouble(6, 0, 3, 3);
|
||||
}
|
||||
this.AddChild(resetConnectionButton);
|
||||
|
||||
Button editButton = TextImageButtonFactory.GetThemedEditButton();
|
||||
editButton.VAnchor = VAnchor.ParentCenter;
|
||||
editButton.Click += UiNavigation.GoToEditPrinter_Click;
|
||||
printerSelectorAndEditButton.AddChild(editButton);
|
||||
this.AddChild(printerSelectorAndEditButton);
|
||||
resetConnectionButton.Click += new EventHandler((s,e) => PrinterConnectionAndCommunication.Instance.RebootBoard());
|
||||
|
||||
this.AddChild(resetConnectionButton);
|
||||
}
|
||||
SliceSettingsWidget.SettingChanged.RegisterEvent((sender, e) =>
|
||||
{
|
||||
StringEventArgs stringEvent = e as StringEventArgs;
|
||||
if (stringEvent != null)
|
||||
{
|
||||
if (stringEvent.Data == SettingsKey.show_reset_connection)
|
||||
{
|
||||
resetConnectionButton.Visible = ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.show_reset_connection);
|
||||
}
|
||||
}
|
||||
}, ref unregisterEvents);
|
||||
}
|
||||
|
||||
protected override void AddHandlers()
|
||||
{
|
||||
ActiveSliceSettings.ActivePrinterChanged.RegisterEvent(onActivePrinterChanged, ref unregisterEvents);
|
||||
PrinterConnectionAndCommunication.Instance.EnableChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents);
|
||||
PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents);
|
||||
|
||||
connectPrinterButton.Click += new EventHandler(onConnectButton_Click);
|
||||
disconnectPrinterButton.Click += new EventHandler(onDisconnectButtonClick);
|
||||
resetConnectionButton.Click += new EventHandler(resetConnectionButton_Click);
|
||||
|
||||
base.AddHandlers();
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
|
|
@ -212,23 +237,6 @@ namespace MatterHackers.MatterControl.ActionBar
|
|||
}
|
||||
}
|
||||
|
||||
private void onConnectButton_Click(object sender, EventArgs mouseEvent)
|
||||
{
|
||||
Button buttonClicked = ((Button)sender);
|
||||
if (buttonClicked.Enabled)
|
||||
{
|
||||
if (ActiveSliceSettings.Instance.PrinterSelected)
|
||||
{
|
||||
ConnectToActivePrinter(null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onDisconnectButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
UiThread.RunOnIdle(OnIdleDisconnect);
|
||||
}
|
||||
|
||||
private void OnIdleDisconnect()
|
||||
{
|
||||
if (PrinterConnectionAndCommunication.Instance.PrinterIsPrinting)
|
||||
|
|
@ -252,10 +260,6 @@ namespace MatterHackers.MatterControl.ActionBar
|
|||
OpenConnectionWindow();
|
||||
}
|
||||
|
||||
private void resetConnectionButton_Click(object sender, EventArgs mouseEvent)
|
||||
{
|
||||
PrinterConnectionAndCommunication.Instance.RebootBoard();
|
||||
}
|
||||
private void SetConnectionButtonVisibleState()
|
||||
{
|
||||
if (PrinterConnectionAndCommunication.Instance.PrinterIsConnected)
|
||||
|
|
@ -274,7 +278,6 @@ namespace MatterHackers.MatterControl.ActionBar
|
|||
// Ensure connect buttons are locked while long running processes are executing to prevent duplicate calls into said actions
|
||||
connectPrinterButton.Enabled = communicationState != PrinterConnectionAndCommunication.CommunicationStates.AttemptingToConnect;
|
||||
disconnectPrinterButton.Enabled = communicationState != PrinterConnectionAndCommunication.CommunicationStates.Disconnecting;
|
||||
resetConnectionButton.Visible = ActiveSliceSettings.Instance.GetValue<bool>("show_reset_connection");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -83,6 +83,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
public const string windows_driver = nameof(windows_driver);
|
||||
public const string z_homes_to_max = nameof(z_homes_to_max);
|
||||
public const string active_theme_index = nameof(active_theme_index);
|
||||
public const string show_reset_connection = nameof(show_reset_connection);
|
||||
public const string start_gcode = nameof(start_gcode);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
"heat_extruder_before_homing",
|
||||
"include_firmware_updater",
|
||||
"layer_to_pause",
|
||||
"show_reset_connection",
|
||||
SettingsKey.show_reset_connection,
|
||||
SettingsKey.make,
|
||||
SettingsKey.model,
|
||||
|
||||
|
|
|
|||
|
|
@ -936,7 +936,7 @@
|
|||
"ShowIfSet": null,
|
||||
"ResetAtEndOfPrint": false,
|
||||
"DefaultValue": "0",
|
||||
"ReloadUiWhenChanged": true
|
||||
"ReloadUiWhenChanged": false
|
||||
},
|
||||
{
|
||||
"QuickMenuSettings": [ ],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue