public void AddNotesMenu(PopupMenu popupMenu, IEnumerable<PrintTask> printTasks, Action notesChanged)
		{
			var addNote = popupMenu.CreateMenuItem(string.IsNullOrEmpty(printTask.Note) ? "Add Note...".Localize() : "Edit Note...".Localize());
			addNote.Enabled = printTasks.Any();
			addNote.Click += (s, e) =>
			{
				var inputBoxPage = new InputBoxPage(
					"Print History Note".Localize(),
					"",
					printTask.Note ?? "",
					"Enter Note Here".Localize(),
					string.IsNullOrEmpty(printTask.Note) ? "Add Note".Localize() : "Update".Localize(),
					(newNote) =>
					{
						printTask.Note = newNote;
						printTask.CommitAndPushToServer();
						popupMenu.Unfocus();
						notesChanged();
					})
				{
					AllowEmpty = true,
				};

				inputBoxPage.ContentRow.AddChild(CreateDefaultOptions(inputBoxPage.TextEditWidget, theme, null), 0);

				DialogWindow.Show(inputBoxPage);

				inputBoxPage.Parent.Height += 40 * GuiWidget.DeviceScale;
			};
		}
Example #2
0
        public static void CheckIfNeedToRecoverPrint(PrinterConfig printer)
        {
            string printRecoveryWarningMessage = "WARNING: In order to perform print recovery, your printer must move down to reach its home position.\nIf your print is too large, part of your printer may collide with it when moving down.\nMake sure it is safe to perform this operation before proceeding.".Localize();

            PrintTask lastPrint = PrintHistoryData.Instance.GetHistoryForPrinter(printer.Settings.ID.GetHashCode()).FirstOrDefault();

            if (lastPrint != null)
            {
                if (RecoveryAvailable(printer))
                {
                    bool safeHomingDirection = printer.Settings.GetValue <bool>(SettingsKey.z_homes_to_max);

                    StyledMessageBox.ShowMessageBox(
                        (messageBoxResponse) =>
                    {
                        if (messageBoxResponse)
                        {
                            UiThread.RunOnIdle(async() =>
                            {
                                if (printer.Connection.CommunicationState == CommunicationStates.Connected)
                                {
                                    printer.Connection.CommunicationState = CommunicationStates.PreparingToPrint;
                                    await printer.Connection.StartPrint(lastPrint.PrintingGCodeFileName, lastPrint);
                                    ApplicationController.Instance.MonitorPrintTask(printer);
                                }
                            });
                        }
                        else                                 // the recovery has been canceled
                        {
                            lastPrint.PrintingGCodeFileName = null;
                            lastPrint.CommitAndPushToServer();
                        }
                    },
                        "It appears your last print failed to complete.\n\nWould your like to attempt to recover from the last know position?".Localize()
                        + (safeHomingDirection ? "" : "\n\n" + printRecoveryWarningMessage),
                        "Recover Last Print".Localize() + " - " + printer.Settings.GetValue(SettingsKey.printer_name),
                        StyledMessageBox.MessageType.YES_NO,
                        "Recover Print".Localize(),
                        "Cancel".Localize(),
                        instanceIndex: lastPrint.Id);
                }
            }
        }
			public CollectPrintDetailsPage(string windowTitle,
				PrinterConfig printer,
				string topMarkDown,
				string descriptionMarkdown,
				PrintTask printTask,
				bool collectQuality)
				: base("Close".Localize())
			{
				this.WindowTitle = windowTitle;
				this.HeaderText = printer.Settings.GetValue(SettingsKey.printer_name) + ": " + windowTitle;
				this.WindowSize = new Vector2(500 * GuiWidget.DeviceScale, 440 * GuiWidget.DeviceScale);

				var scrollable = new ScrollableWidget(autoScroll: true)
				{
					HAnchor = HAnchor.Stretch,
					VAnchor = VAnchor.Stretch,
					Margin = new BorderDouble(bottom: 10),
				};

				scrollable.ScrollArea.HAnchor = HAnchor.Stretch;
				scrollable.ScrollArea.VAnchor = VAnchor.Fit;
				contentRow.AddChild(scrollable);

				var topToBottom = scrollable.AddChild(new FlowLayoutWidget(FlowDirection.TopToBottom)
				{
					HAnchor = HAnchor.Stretch
				});

				topToBottom.AddChild(new MarkdownWidget(theme, false)
				{
					Markdown = topMarkDown,
				});

				var reasonSection = new FlowLayoutWidget(FlowDirection.TopToBottom)
				{
					HAnchor = HAnchor.Stretch,
					Visible = !collectQuality
				};

				if (collectQuality)
				{
					var qualityInput = GetQualityWidget(theme,
						printTask,
						() =>
						{
							reasonSection.Visible = printTask.PrintQuality == 0;
							this.Descendants<ScrollableWidget>().First().ScrollPositionFromTop = new Vector2(0, 0);
						},
						16);
					qualityInput.Margin = new BorderDouble(5, 0);
					qualityInput.HAnchor = HAnchor.Left;
					topToBottom.AddChild(qualityInput);
				}

				topToBottom.AddChild(reasonSection);

				// Adds text box and check box to the above container
				var emptyText = "What went wrong?".Localize();
				var initialValue = printTask.Note ?? "";
				textEditWidget = new MHTextEditWidget(initialValue, theme, pixelWidth: 300, messageWhenEmptyAndNotSelected: emptyText)
				{
					Name = "InputBoxPage TextEditWidget",
					HAnchor = HAnchor.Stretch,
					Margin = new BorderDouble(5),
				};

				textEditWidget.ActualTextEditWidget.EditComplete += (s, e) =>
				{
					printTask.Note = textEditWidget.Text;
					printTask.CommitAndPushToServer();
				};

				var dropDownList = CreateDefaultOptions(textEditWidget, theme, () =>
				{
					// Delay this so we wait for the text to be updated
					UiThread.RunOnIdle(() =>
					{
						printTask.Note = textEditWidget.Text;
						printTask.CommitAndPushToServer();
					});
				});
				dropDownList.Margin = new BorderDouble(5, 0);
				dropDownList.HAnchor |= HAnchor.Left;
				reasonSection.AddChild(dropDownList);
				reasonSection.AddChild(textEditWidget);

				topToBottom.AddChild(new HorizontalLine(theme.BorderColor40)
				{
					Margin = new BorderDouble(0, 5)
				});

				topToBottom.AddChild(new MarkdownWidget(theme, false)
				{
					Markdown = descriptionMarkdown,
				});

				var collectHistoryHidden = UserSettings.Instance.get(UserSettingsKey.CollectPrintHistoryData) == "false";
				if (!collectHistoryHidden)
				{
					UiThread.RunOnIdle(() =>
					{
						DialogWindow.Show(this, printTask.Id);
						// this will cause a layout that fixes a display issue
						scrollable.ScrollArea.BoundsChanged += (s, e) =>
						{
							scrollable.ScrollPositionFromTop = new Vector2(0, 0);
						};

						scrollable.ScrollPositionFromTop = new Vector2(0, 0);
					});
				}

				if (printer != null)
				{
					var printAgainButton = PrintPopupMenu.CreateStartPrintButton("Print Again", printer, theme, out _);
					printAgainButton.Click += (s, e) => this.DialogWindow?.ClosePage();
					AddPageAction(printAgainButton);
				}
			}
		public static GuiWidget GetQualityWidget(ThemeConfig theme, PrintTask printTask, Action clicked, double buttonFontSize)
		{
			var content = new FlowLayoutWidget()
			{
				HAnchor = HAnchor.Fit | HAnchor.Stretch
			};
			var siblings = new List<GuiWidget>();

			var textWidget = new TextWidget("Print Quality".Localize() + ":", pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
			{
				VAnchor = VAnchor.Center
			};

			content.AddChild(textWidget);

			var size = (int)(buttonFontSize * GuiWidget.DeviceScale);

			var star = StaticData.Instance.LoadIcon("star.png", size, size).SetToColor(theme.TextColor);
			var openStar = StaticData.Instance.LoadIcon("open_star.png", size, size).SetToColor(theme.TextColor);
			var failure = StaticData.Instance.LoadIcon("failure.png", size, size).SetToColor(theme.TextColor);

			content.AddChild(new GuiWidget(size, 1));

			content.MouseLeaveBounds += (s, e) =>
			{
				SetStarState(theme, siblings, printTask);
			};

			for (int i = 0; i < QualityNames.Length; i++)
			{
				var buttonIndex = i;
				GuiWidget buttonContent;
				if (i == 0)
				{
					buttonContent = new ImageWidget(failure);
				}
				else
				{
					buttonContent = new GuiWidget()
					{
						HAnchor = HAnchor.Fit,
						VAnchor = VAnchor.Fit
					};
					buttonContent.AddChild(new ImageWidget(openStar)
					{
						Name = "open"
					});
					buttonContent.AddChild(new ImageWidget(star)
					{
						Name = "closed",
						Visible = false
					});
				}

				var button = new RadioButton(buttonContent)
				{
					Enabled = printTask.PrintComplete,
					Checked = printTask.QualityWasSet && printTask.PrintQuality == i,
					ToolTipText = QualityNames[i],
					Margin = 0,
					Padding = 5,
					HAnchor = HAnchor.Fit,
					VAnchor = VAnchor.Fit,
				};

				button.MouseEnterBounds += (s, e) =>
				{
					// set the correct filled stars for the hover
					for (int j = 0; j < siblings.Count; j++)
					{
						var open = siblings[j].Descendants().Where(d => d.Name == "open").FirstOrDefault();
						var closed = siblings[j].Descendants().Where(d => d.Name == "closed").FirstOrDefault();

						if (j == 0)
						{
							if (buttonIndex == 0)
							{
								siblings[j].BackgroundColor = theme.AccentMimimalOverlay;
							}
							else
							{
								siblings[j].BackgroundColor = Color.Transparent;
							}
						}
						else if (j <= buttonIndex)
						{
							siblings[j].BackgroundColor = theme.AccentMimimalOverlay;
						}
						else
						{
							siblings[j].BackgroundColor = Color.Transparent;
						}

						if (j <= buttonIndex)
						{
							if (open != null)
							{
								open.Visible = false;
								closed.Visible = true;
							}
						}
						else
						{
							if (open != null)
							{
								open.Visible = true;
								closed.Visible = false;
							}
						}
					}
				};

				siblings.Add(button);

				button.SiblingRadioButtonList = siblings;

				content.AddChild(button);

				button.Click += (s, e) =>
				{
					printTask.PrintQuality = siblings.IndexOf((GuiWidget)s);
					printTask.QualityWasSet = true;
					printTask.CommitAndPushToServer();
					clicked();
				};
			}

			SetStarState(theme, siblings, printTask);

			return content;
		}