Merge pull request #4523 from jlewin/master

New searchable Add Printer Wizard
This commit is contained in:
johnlewin 2019-05-14 15:58:57 -07:00 committed by GitHub
commit 00a22e5cc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 486 additions and 211 deletions

View file

@ -49,12 +49,14 @@ namespace MatterHackers.MatterControl.CustomWidgets
private ImageWidget imageWidget;
private bool isDirty;
public TreeNode(ThemeConfig theme, bool useIcon = true)
public TreeNode(ThemeConfig theme, bool useIcon = true, TreeNode nodeParent = null)
: base(FlowDirection.TopToBottom)
{
this.HAnchor = HAnchor.Fit | HAnchor.Left;
this.VAnchor = VAnchor.Fit;
this.NodeParent = nodeParent;
this.TitleBar = new FlowLayoutWidget();
this.TitleBar.Click += (s, e) =>
{

View file

@ -0,0 +1,407 @@
/*
Copyright (c) 2019, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.ImageProcessing;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.SettingsManagement;
using MatterHackers.MatterControl.SlicerConfiguration;
namespace MatterHackers.MatterControl.PrintLibrary
{
public class AddPrinterWidget : FlowLayoutWidget
{
private SectionWidget nameSection;
private SearchInputBox searchBox;
private TreeView treeView;
private FlowLayoutWidget rootColumn;
private MHTextEditWidget printerNameInput;
private bool usingDefaultName = true;
private ThemeConfig theme;
private TextButton nextButton;
public AddPrinterWidget(ThemeConfig theme, TextButton nextButton)
: base(FlowDirection.TopToBottom)
{
this.theme = theme;
this.nextButton = nextButton;
this.ExistingPrinterNames = ProfileManager.Instance.ActiveProfiles.Select(p => p.Name).ToList();
this.Name = "AddPrinterWidget";
this.TreeLoaded = false;
var searchIcon = AggContext.StaticData.LoadIcon("icon_search_24x24.png", 16, 16, theme.InvertIcons).AjustAlpha(0.3);
searchBox = new SearchInputBox(theme)
{
Name = "Search",
HAnchor = HAnchor.Stretch,
Margin = new BorderDouble(bottom: 4),
};
searchBox.ResetButton.Visible = false;
var searchInput = searchBox.searchInput;
searchInput.BeforeDraw += (s, e) =>
{
if (!searchBox.ResetButton.Visible)
{
e.Graphics2D.Render(
searchIcon,
searchInput.Width - searchIcon.Width - 5,
searchInput.LocalBounds.Bottom + searchInput.Height / 2 - searchIcon.Height / 2);
}
};
searchBox.ResetButton.Click += (s, e) =>
{
this.ClearSearch();
};
searchBox.searchInput.ActualTextEditWidget.TextChanged += (s, e) =>
{
if (string.IsNullOrWhiteSpace(searchBox.Text))
{
this.ClearSearch();
}
else
{
this.PerformSearch();
}
};
this.AddChild(searchBox);
var horizontalSplitter = new Splitter()
{
SplitterDistance = Math.Max(UserSettings.Instance.LibraryViewWidth, 20),
SplitterSize = theme.SplitterWidth,
SplitterBackground = theme.SplitterBackground
};
horizontalSplitter.AnchorAll();
horizontalSplitter.DistanceChanged += (s, e) =>
{
UserSettings.Instance.LibraryViewWidth = Math.Max(horizontalSplitter.SplitterDistance, 20);
};
this.AddChild(horizontalSplitter);
treeView = new TreeView(theme)
{
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Stretch,
};
treeView.AfterSelect += async (s, e) =>
{
nameSection.Enabled = treeView.SelectedNode != null;
this.ClearError();
this.PrinterNameError.Visible = false;
if (nameSection.Enabled
&& treeView.SelectedNode.Tag != null)
{
UiThread.RunOnIdle(() =>
{
if (usingDefaultName
&& treeView.SelectedNode != null)
{
string printerName = treeView.SelectedNode.Tag.ToString();
printerNameInput.Text = agg_basics.GetNonCollidingName(printerName, this.ExistingPrinterNames);
SelectedPrinter = treeView.SelectedNode.Tag as MakeModelInfo;
nextButton.Enabled = treeView.SelectedNode != null
&& !string.IsNullOrWhiteSpace(printerNameInput.Text);
}
});
}
else
{
nextButton.Enabled = false;
}
};
horizontalSplitter.Panel1.AddChild(treeView);
rootColumn = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
HAnchor = HAnchor.Fit,
VAnchor = VAnchor.Fit,
Margin = new BorderDouble(left: 2)
};
treeView.AddChild(rootColumn);
UiThread.RunOnIdle(() =>
{
foreach (var oem in OemSettings.Instance.OemProfiles.OrderBy(o => o.Key))
{
var rootNode = this.CreateTreeNode(oem);
rootNode.Expandable = true;
rootNode.TreeView = treeView;
rootNode.Load += (s, e) =>
{
rootNode.Image = OemSettings.Instance.GetIcon(oem.Key);
// Push to children
foreach (var child in rootNode.Nodes)
{
child.Image = rootNode.Image;
}
};
rootColumn.AddChild(rootNode);
}
this.TreeLoaded = true;
});
var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
HAnchor = HAnchor.Stretch,
Margin = new BorderDouble(theme.DefaultContainerPadding).Clone(top: 0)
};
nameSection = new SectionWidget("New Printer Name".Localize(), container, theme, expandingContent: false)
{
HAnchor = HAnchor.Stretch,
Padding = theme.ToolbarPadding,
Enabled = false
};
theme.ApplyBoxStyle(nameSection);
nameSection.BackgroundColor = theme.MinimalShade;
nameSection.Margin = new BorderDouble(top: theme.DefaultContainerPadding);
horizontalSplitter.Panel2.Padding = theme.DefaultContainerPadding;
var panel2Column = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Stretch
};
panel2Column.AddChild(new TextWidget("Select a printer to continue".Localize(), pointSize: theme.DefaultFontSize, textColor: theme.TextColor));
panel2Column.AddChild(nameSection);
panel2Column.AddChild(PrinterNameError = new TextWidget("", 0, 0, 10)
{
TextColor = Color.Red,
HAnchor = HAnchor.Stretch,
Margin = new BorderDouble(top: 3)
});
horizontalSplitter.Panel2.AddChild(panel2Column);
printerNameInput = new MHTextEditWidget("", theme)
{
HAnchor = HAnchor.Stretch,
};
printerNameInput.ActualTextEditWidget.EditComplete += (s, e) =>
{
this.ValidateControls();
this.usingDefaultName = false;
};
container.AddChild(printerNameInput);
}
public IReadOnlyList<string> ExistingPrinterNames { get; private set; }
public TextWidget PrinterNameError { get; private set; }
public bool ValidateControls()
{
bool selectionValid = this.SelectedPrinter is AddPrinterWidget.MakeModelInfo selectedPrinter;
if (!selectionValid)
{
this.SetError("Invalid printer selection".Localize());
}
string printerName = this.NewPrinterName;
bool nameValid = !string.IsNullOrWhiteSpace(printerName);
if (!nameValid)
{
this.SetError("Printer name cannot be blank".Localize());
}
bool nameIsUnique = !this.ExistingPrinterNames.Any(p => p.Equals(printerName, StringComparison.OrdinalIgnoreCase));
if (!nameIsUnique)
{
this.SetError("Printer name already exists".Localize());
}
bool allValid = selectionValid
&& nameValid
&& nameIsUnique;
nextButton.Enabled = allValid;
if (allValid)
{
this.ClearError();
}
return allValid;
}
internal void SetError(string errorMessage)
{
this.PrinterNameError.Text = errorMessage;
this.PrinterNameError.Visible = true;
}
private void ClearError()
{
this.PrinterNameError.Text = "";
this.PrinterNameError.Visible = true;
}
private TreeNode CreateTreeNode(KeyValuePair<string, Dictionary<string, PublicDevice>> make)
{
var treeNode = new TreeNode(theme)
{
Text = make.Key,
};
foreach (var printer in make.Value.OrderBy(p => p.Key))
{
treeNode.Nodes.Add(new TreeNode(theme, nodeParent: treeNode)
{
Text = printer.Key,
Name = $"Node{make.Key}{printer.Key}",
Tag = new MakeModelInfo()
{
Make = make.Key,
Model = printer.Key
}
});
}
return treeNode;
}
private void PerformSearch()
{
var matches = new List<TreeNode>();
Console.WriteLine("Filter for: " + searchBox.Text);
foreach (var rootNode in rootColumn.Children.OfType<TreeNode>())
{
FilterTree(rootNode, searchBox.Text, false, matches);
}
if (matches.Count == 1)
{
treeView.SelectedNode = matches.First();
}
else
{
treeView.SelectedNode = null;
}
searchBox.ResetButton.Visible = true;
}
private void ClearSearch()
{
foreach (var rootNode in rootColumn.Children.OfType<TreeNode>())
{
ResetTree(rootNode);
}
searchBox.Text = "";
searchBox.ResetButton.Visible = false;
treeView.SelectedNode = null;
}
private void FilterTree(TreeNode context, string filter, bool parentVisible, List<TreeNode> matches)
{
bool hasFilterText = context.Text.IndexOf(filter, StringComparison.OrdinalIgnoreCase) != -1;
context.Visible = hasFilterText || parentVisible;
if (context.Visible
&& context.NodeParent != null)
{
context.NodeParent.Visible = true;
context.NodeParent.Expanded = true;
}
if (context.NodeParent != null
&& hasFilterText)
{
matches.Add(context);
}
foreach (var child in context.Nodes)
{
FilterTree(child, filter, hasFilterText, matches);
}
}
private void ResetTree(TreeNode context)
{
context.Visible = true;
context.Expanded = false;
foreach (var child in context.Nodes)
{
ResetTree(child);
}
}
public MakeModelInfo SelectedPrinter { get; private set; }
public string NewPrinterName => printerNameInput.Text;
public bool TreeLoaded { get; private set; }
public class MakeModelInfo
{
public string Make { get; set; }
public string Model { get; set; }
public override string ToString() => $"{Make} {Model}";
}
}
}

View file

@ -303,7 +303,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
SetIsActive = (value) => printer.ViewState.ControlsVisible = value
},
new NamedBoolAction()
{
{
Title = "Show Terminal".Localize(),
Action = () => { },
GetIsActive = () => printer.ViewState.TerminalVisible,
@ -343,6 +343,20 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
Icon = AggContext.StaticData.LoadIcon("cube_export.png", 16, 16, theme.InvertIcons),
},
new ActionSeparator(),
new NamedAction()
{
Title = "Calibrate Printer".Localize(),
Action = () => UiThread.RunOnIdle(() =>
{
UiThread.RunOnIdle(() =>
{
DialogWindow.Show(new PrinterCalibrationWizard(printer, theme));
});
}),
Icon = AggContext.StaticData.LoadIcon("fa-cog_16.png", theme.InvertIcons)
},
new ActionSeparator(),
new NamedAction()
{
Title = "Restore Settings".Localize(),

View file

@ -28,12 +28,12 @@ either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.SettingsManagement;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.PrintLibrary;
using MatterHackers.MatterControl.SlicerConfiguration;
namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
@ -41,85 +41,39 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
// Normally step one of the setup process
public class SetupStepMakeModelName : DialogPage
{
private FlowLayoutWidget printerModelContainer;
private FlowLayoutWidget printerMakeContainer;
private MHTextEditWidget printerNameInput;
private TextWidget printerNameError;
private GuiWidget nextButton;
private TextButton nextButton;
private AddPrinterWidget printerPanel;
private bool usingDefaultName;
private static BorderDouble elementMargin = new BorderDouble(top: 3);
private BoundDropList printerManufacturerSelector;
private BoundDropList printerModelSelector;
private string activeMake;
private string activeModel;
private string activeName;
private RadioButton createPrinterRadioButton = null;
private RadioButton signInRadioButton;
public SetupStepMakeModelName()
{
bool userIsLoggedIn = !ApplicationController.GuestUserActive?.Invoke() ?? false;
this.HeaderText = this.WindowTitle = "Printer Setup".Localize();
this.WindowSize = new VectorMath.Vector2(800, 600);
var addPrinterColumn = new FlowLayoutWidget(FlowDirection.TopToBottom)
contentRow.BackgroundColor = theme.SectionBackgroundColor;
nextButton = theme.CreateDialogButton("Next".Localize());
printerPanel = new AddPrinterWidget(theme, nextButton)
{
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Fit,
VAnchor = VAnchor.Stretch
};
printerManufacturerSelector = new BoundDropList(string.Format("- {0} -", "Select Make".Localize()), theme, maxHeight: 200)
{
HAnchor = HAnchor.Stretch,
Margin = elementMargin,
Name = "Select Make",
ListSource = OemSettings.Instance.AllOems,
TabStop = true
};
printerManufacturerSelector.SelectionChanged += ManufacturerDropList_SelectionChanged;
printerMakeContainer = CreateSelectionContainer(
"Make".Localize() + ":",
"Select the printer manufacturer".Localize(),
printerManufacturerSelector);
printerModelSelector = new BoundDropList(string.Format("- {0} -", "Select Model".Localize()), theme, maxHeight: 200)
{
Name = "Select Model",
HAnchor = HAnchor.Stretch,
Margin = elementMargin,
TabStop = true
};
printerModelSelector.SelectionChanged += ModelDropList_SelectionChanged;
printerModelContainer = CreateSelectionContainer(
"Model".Localize() + ":",
"Select the printer model".Localize(),
printerModelSelector);
// Add inputs to main container
addPrinterColumn.AddChild(printerMakeContainer);
addPrinterColumn.AddChild(printerModelContainer);
addPrinterColumn.AddChild(CreatePrinterNameContainer());
RadioButton signInRadioButton = null;
if (userIsLoggedIn)
{
contentRow.AddChild(addPrinterColumn);
contentRow.AddChild(printerPanel);
}
else
{
contentRow.Padding = 10;
addPrinterColumn.Margin = new BorderDouble(28, 15, 15, 5);
contentRow.Padding = theme.DefaultContainerPadding;
printerPanel.Margin = new BorderDouble(left: 15, top: theme.DefaultContainerPadding);
var commonMargin = new BorderDouble(4, 2);
@ -145,14 +99,13 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
createPrinterRadioButton.CheckedStateChanged += (s, e) =>
{
addPrinterColumn.Enabled = createPrinterRadioButton.Checked;
printerPanel.Enabled = createPrinterRadioButton.Checked;
this.SetElementVisibility();
};
contentRow.AddChild(addPrinterColumn);
contentRow.AddChild(printerPanel);
}
nextButton = theme.CreateDialogButton("Next".Localize());
nextButton.Name = "Next Button";
nextButton.Click += (s, e) => UiThread.RunOnIdle(async () =>
{
@ -168,14 +121,14 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
}
else
{
bool controlsValid = this.ValidateControls();
if (controlsValid)
bool controlsValid = printerPanel.ValidateControls();
if (controlsValid
&& printerPanel.SelectedPrinter is AddPrinterWidget.MakeModelInfo selectedPrinter)
{
var printer = await ProfileManager.CreatePrinterAsync(activeMake, activeModel, activeName);
var printer = await ProfileManager.CreatePrinterAsync(selectedPrinter.Make, selectedPrinter.Model, printerPanel.NewPrinterName);
if (printer == null)
{
this.printerNameError.Text = "Error creating profile".Localize();
this.printerNameError.Visible = true;
printerPanel.SetError("Error creating profile".Localize());
return;
}
@ -191,53 +144,13 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
usingDefaultName = true;
if (printerManufacturerSelector.MenuItems.Count == 1)
{
printerManufacturerSelector.SelectedIndex = 0;
}
SetElementVisibility();
}
private void SetElementVisibility()
{
nextButton.Enabled = createPrinterRadioButton == null
|| !createPrinterRadioButton.Checked
|| (createPrinterRadioButton.Checked && (activeModel != null && this.activeMake != null));
}
private FlowLayoutWidget CreatePrinterNameContainer()
{
TextWidget printerNameLabel = new TextWidget("Name".Localize() + ":", 0, 0, 12)
{
TextColor = theme.TextColor,
HAnchor = HAnchor.Stretch,
Margin = new BorderDouble(0, 4, 0, 1)
};
printerNameInput = new MHTextEditWidget("", theme)
{
HAnchor = HAnchor.Stretch,
};
printerNameInput.KeyPressed += (s, e) => this.usingDefaultName = false;
printerNameError = new TextWidget("", 0, 0, 10)
{
TextColor = theme.TextColor,
HAnchor = HAnchor.Stretch,
Margin = new BorderDouble(top: 3)
};
var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
Margin = new BorderDouble(0, 5),
HAnchor = HAnchor.Stretch
};
container.AddChild(printerNameLabel);
container.AddChild(printerNameInput);
container.AddChild(printerNameError);
return container;
nextButton.Enabled = signInRadioButton?.Checked == true
|| printerPanel.SelectedPrinter != null;
}
private FlowLayoutWidget CreateSelectionContainer(string labelText, string validationMessage, DropDownList selector)
@ -273,74 +186,5 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
return container;
}
private void ManufacturerDropList_SelectionChanged(object sender, EventArgs e)
{
activeMake = ((DropDownList)sender).SelectedValue;
activeModel = null;
// Select the dictionary containing the printerName->printerToken mappings for the current OEM
Dictionary<string, PublicDevice> printers;
if (!OemSettings.Instance.OemProfiles.TryGetValue(activeMake, out printers))
{
// Fall back to an empty dictionary if no match
printers = new Dictionary<string, PublicDevice>();
}
// Models - sort dictionary results by key and assign to .ListSource
printerModelSelector.ListSource = printers.OrderBy(p => p.Key).Select(p => new KeyValuePair<string, string>(p.Key, p.Value.ProfileToken)).ToList();
if (printerModelSelector.MenuItems.Count == 1)
{
printerModelSelector.SelectedIndex = 0;
}
contentRow.Invalidate();
SetElementVisibility();
}
private void ModelDropList_SelectionChanged(object sender, EventArgs e)
{
UiThread.RunOnIdle(() =>
{
DropDownList dropList = (DropDownList)sender;
activeModel = dropList.SelectedLabel;
SetElementVisibility();
if (usingDefaultName)
{
// Use ManufacturerDropList.SelectedLabel instead of activeMake to ensure the mapped Unicode values are picked up
string mappedMakeText = printerManufacturerSelector.SelectedLabel;
var existingPrinterNames = ProfileManager.Instance.ActiveProfiles.Select(p => p.Name);
printerNameInput.Text = agg_basics.GetNonCollidingName($"{mappedMakeText} {activeModel}", existingPrinterNames);
}
});
}
private bool ValidateControls()
{
if (!string.IsNullOrEmpty(printerNameInput.Text))
{
activeName = printerNameInput.Text;
if (this.activeMake == null || activeModel == null)
{
return false;
}
else
{
return true;
}
}
else
{
this.printerNameError.TextColor = Color.Red;
this.printerNameError.Text = "Printer name cannot be blank".Localize();
this.printerNameError.Visible = true;
return false;
}
}
}
}

View file

@ -17,7 +17,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MatterControl.Tests</RootNamespace>
<AssemblyName>MatterControl.Tests</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<TargetFrameworkProfile />

View file

@ -47,6 +47,7 @@ using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.PrinterCommunication.Io;
using MatterHackers.MatterControl.PrinterControls.PrinterConnections;
using MatterHackers.MatterControl.PrintLibrary;
using MatterHackers.MatterControl.SettingsManagement;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.PrinterEmulator;
@ -132,6 +133,23 @@ namespace MatterHackers.MatterControl.Tests.Automation
testRunner.Delay(.2);
}
public static void WaitForPage(this AutomationRunner testRunner, string headerText)
{
// Helper methods
bool HeaderExists(string text)
{
var header = testRunner.GetWidgetByName("HeaderRow", out _);
var textWidget = header.Children<TextWidget>().FirstOrDefault();
return textWidget?.Text.StartsWith(text) ?? false;
}
testRunner.WaitFor(() => HeaderExists(headerText));
Assert.IsTrue(HeaderExists(headerText), "Expected page not found: " + headerText);
}
public static string PathToExportGcodeFolder
{
get => TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "ExportedGcode", runName);
@ -340,7 +358,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
testRunner.EnsureWelcomePageClosed();
// Click 'Add Printer' if not on screen
if (!testRunner.NameExists("Select Make", 0.2))
if (!testRunner.NameExists("AddPrinterWidget", 0.2))
{
if (!testRunner.NameExists("Create Printer", 0.2))
{
@ -361,18 +379,23 @@ namespace MatterHackers.MatterControl.Tests.Automation
}
}
testRunner.ClickByName("Select Make");
testRunner.WaitFor(() => testRunner.ChildExists<PopupWidget>());
testRunner.Type(make);
testRunner.Type("{Enter}");
testRunner.WaitFor(() => !testRunner.ChildExists<PopupWidget>());
// Wait for the tree to load before filtering
testRunner.WaitFor(() =>
{
var widget = testRunner.GetWidgetByName("AddPrinterWidget", out _) as AddPrinterWidget;
return widget.TreeLoaded;
});
testRunner.ClickByName("Select Model");
testRunner.WaitFor(() => testRunner.ChildExists<PopupWidget>());
// Apply filter
testRunner.ClickByName("Search");
testRunner.Type(model);
testRunner.Type("{Enter}");
testRunner.WaitFor(() => !testRunner.ChildExists<PopupWidget>());
// Click printer node
testRunner.Delay();
testRunner.ClickByName($"Node{make}{model}");
// Continue to next page
testRunner.ClickByName("Next Button");
testRunner.Delay();
@ -946,24 +969,9 @@ namespace MatterHackers.MatterControl.Tests.Automation
public static void Complete9StepLeveling(this AutomationRunner testRunner, int numUpClicks = 1)
{
// Helper methods
bool headerExists(string headerText)
{
var header = testRunner.GetWidgetByName("HeaderRow", out _);
var textWidget = header.Children<TextWidget>().FirstOrDefault();
return textWidget?.Text.StartsWith(headerText) ?? false;
}
void waitForPage(string headerText)
{
testRunner.WaitFor(() => headerExists(headerText));
Assert.IsTrue(headerExists(headerText), "Expected page not found: " + headerText);
}
void waitForPageAndAdvance(string headerText)
{
waitForPage(headerText);
testRunner.WaitForPage(headerText);
testRunner.ClickByName("Next Button");
}
@ -979,20 +987,20 @@ namespace MatterHackers.MatterControl.Tests.Automation
{
var section = (i * 3) + 1;
waitForPage($"Step {section} of 9");
testRunner.WaitForPage($"Step {section} of 9");
for (int j = 0; j < numUpClicks; j++)
{
testRunner.Delay();
testRunner.ClickByName("Move Z positive");
}
waitForPage($"Step {section} of 9");
testRunner.WaitForPage($"Step {section} of 9");
testRunner.ClickByName("Next Button");
waitForPage($"Step {section + 1} of 9");
testRunner.WaitForPage($"Step {section + 1} of 9");
testRunner.ClickByName("Next Button");
waitForPage($"Step {section + 2} of 9");
testRunner.WaitForPage($"Step {section + 2} of 9");
testRunner.ClickByName("Next Button");
}