diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index b6334ba23..e8c3a01fd 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -1003,7 +1003,8 @@ namespace MatterHackers.MatterControl /// like a bad save or load. /// /// The message to show - public void ShowNotification(string message) + /// The length of time to show the message + public void ShowNotification(string message, double durationSeconds = 5) { foreach(var printer in ActivePrinters) { @@ -1013,6 +1014,23 @@ namespace MatterHackers.MatterControl terminal.WriteLine(message); } } + + // show the message for the time requested + this.Tasks.Execute(message, + null, + (progress, cancellationToken) => + { + var time = UiThread.CurrentTimerMs; + var status = new ProgressStatus(); + while (UiThread.CurrentTimerMs < time + durationSeconds * 1000) + { + Thread.Sleep(30); + status.Progress0To1 = (UiThread.CurrentTimerMs - time) / 1000.0 / durationSeconds; + progress.Report(status); + } + + return Task.CompletedTask; + }); } public void Connection_ErrorReported(object sender, string line) diff --git a/MatterControlLib/PrinterControls/PrinterConnections/SetupStepComPortOne.cs b/MatterControlLib/PrinterControls/PrinterConnections/SetupStepComPortOne.cs index 207b3045a..846b0bb8a 100644 --- a/MatterControlLib/PrinterControls/PrinterConnections/SetupStepComPortOne.cs +++ b/MatterControlLib/PrinterControls/PrinterConnections/SetupStepComPortOne.cs @@ -51,7 +51,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections var elementMargin = new BorderDouble(top: 5); - var printerMessageOne = new TextWidget("MatterControl will now attempt to auto-detect printer.".Localize(), 0, 0, 10) + var printerMessageOne = new TextWidget("MatterControl will now attempt to auto-detect your printer.".Localize(), 0, 0, 10) { TextColor = theme.TextColor, HAnchor = HAnchor.Stretch, @@ -59,7 +59,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections }; container.AddChild(printerMessageOne); - var printerMessageTwo = new TextWidget(string.Format("1.) {0} ({1}).", "Disconnect printer".Localize(), "if currently connected".Localize()), 0, 0, 12) + var printerMessageTwo = new WrappedTextWidget(string.Format("1.) {0} ({1}).", "Unplug printer USB cable from computer".Localize(), "if connected".Localize()), 12) { TextColor = theme.TextColor, HAnchor = HAnchor.Stretch, diff --git a/MatterControlLib/PrinterControls/PrinterConnections/SetupStepComPortTwo.cs b/MatterControlLib/PrinterControls/PrinterConnections/SetupStepComPortTwo.cs index ed2173735..167f92e9e 100644 --- a/MatterControlLib/PrinterControls/PrinterConnections/SetupStepComPortTwo.cs +++ b/MatterControlLib/PrinterControls/PrinterConnections/SetupStepComPortTwo.cs @@ -45,7 +45,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections private GuiWidget nextButton; private GuiWidget connectButton; - private TextWidget printerErrorMessage; + private TextWidget printerConnectionMessage; private PrinterConfig printer; @@ -61,20 +61,39 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections nextButton.Click += (s, e) => Parent.Close(); nextButton.Visible = false; + var connectButtonHasBeenClicked = false; + void CheckOnPorts() + { + string candidatePort = FrostedSerialPort.GetPortNames().Except(startingPortNames).FirstOrDefault(); + if (candidatePort != null) + { + // we found a new added port click the connect button for the user + connectButton.InvokeClick(); + } + else if (!connectButtonHasBeenClicked && this.ActuallyVisibleOnScreen()) + { + // keep checking as long as this is open + UiThread.RunOnIdle(CheckOnPorts, .2); + } + } + + UiThread.RunOnIdle(CheckOnPorts, .2); + connectButton = theme.CreateDialogButton("Connect".Localize()); connectButton.Click += (s, e) => { + connectButtonHasBeenClicked = true; // Select the first port that's in GetPortNames() but not in startingPortNames string candidatePort = FrostedSerialPort.GetPortNames().Except(startingPortNames).FirstOrDefault(); if (candidatePort == null) { - printerErrorMessage.TextColor = Color.Red; - printerErrorMessage.Text = "Oops! Printer could not be detected ".Localize(); + printerConnectionMessage.TextColor = Color.Red; + printerConnectionMessage.Text = "Oops! Printer could not be detected ".Localize(); } else { - printerErrorMessage.TextColor = theme.TextColor; - printerErrorMessage.Text = "Attempting to connect".Localize() + "..."; + printerConnectionMessage.TextColor = theme.TextColor; + printerConnectionMessage.Text = "Attempting to connect".Localize() + "..."; printer.Settings.Helpers.SetComPort(candidatePort); printer.Connection.Connect(); @@ -120,7 +139,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections var elementMargin = new BorderDouble(top: 5); - var printerMessageOne = new TextWidget("MatterControl will now attempt to auto-detect printer.".Localize(), 0, 0, 10) + var printerMessageOne = new TextWidget("MatterControl will now attempt to auto-detect your printer.".Localize(), 0, 0, 10) { Margin = elementMargin, TextColor = theme.TextColor, @@ -128,7 +147,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections }; container.AddChild(printerMessageOne); - var printerMessageFour = new TextWidget(string.Format("1.) {0}.", "Connect printer (make sure it is on)".Localize()), 0, 0, 12) + var printerMessageFour = new TextWidget(string.Format("1.) {0}.", "Plug in printer USB cable and turn printer on".Localize()), 0, 0, 12) { TextColor = theme.TextColor, HAnchor = HAnchor.Stretch, @@ -136,22 +155,14 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections }; container.AddChild(printerMessageFour); - - var printerMessageFive = new TextWidget(string.Format("2.) {0} '{1}'.", "Press".Localize(), "Connect".Localize()), 0, 0, 12) - { - TextColor = theme.TextColor, - HAnchor = HAnchor.Stretch, - Margin = elementMargin - }; - - printerErrorMessage = new TextWidget("", 0, 0, 10) + printerConnectionMessage = new TextWidget("", 0, 0, 10) { AutoExpandBoundsToText = true, TextColor = Color.Red, HAnchor = HAnchor.Stretch, Margin = elementMargin }; - container.AddChild(printerErrorMessage); + container.AddChild(printerConnectionMessage); var removeImage = StaticData.Instance.LoadImage(Path.Combine("Images", "insert usb.png")).SetPreMultiply(); container.AddChild(new ImageWidget(removeImage) @@ -173,16 +184,18 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections { if (printer.Connection.IsConnected) { - printerErrorMessage.TextColor = theme.TextColor; - printerErrorMessage.Text = "Connection succeeded".Localize() + "!"; + printerConnectionMessage.TextColor = theme.TextColor; + printerConnectionMessage.Text = "Connection succeeded".Localize() + "!"; + printerConnectionMessage.TextColor = Color.Red; nextButton.Visible = true; connectButton.Visible = false; - this?.Parent?.Close(); + UiThread.RunOnIdle(() => this?.Parent?.Close(), 1); + ApplicationController.Instance.ShowNotification("Connection succeeded"); } else if (printer.Connection.CommunicationState != CommunicationStates.AttemptingToConnect) { - printerErrorMessage.TextColor = Color.Red; - printerErrorMessage.Text = "Uh-oh! Could not connect to printer.".Localize(); + printerConnectionMessage.TextColor = Color.Red; + printerConnectionMessage.Text = "Uh-oh! Could not connect to printer.".Localize(); connectButton.Visible = true; nextButton.Visible = false; }