public static Printer GetAutoConnectProfile(out bool connectionAvailable) { string[] comportNames = FrostedSerialPort.GetPortNames(); Printer printerToSelect = null; connectionAvailable = false; foreach (Printer printer in Datastore.Instance.dbSQLite.Query <Printer>("SELECT * FROM Printer;")) { if (printer.AutoConnectFlag) { printerToSelect = printer; bool portIsAvailable = comportNames.Contains(printer.ComPort); if (portIsAvailable) { // We found a printer that we can select and connect to. connectionAvailable = true; return(printer); } } } // return a printer we can connect to even though we can't connect return(printerToSelect); }
public SetupStepComPortTwo(ConnectionWindow windowController, GuiWidget containerWindowToClose, PrinterSetupStatus setupPrinterStatus) : base(windowController, containerWindowToClose, setupPrinterStatus) { startingPortNames = FrostedSerialPort.GetPortNames(); contentRow.AddChild(createPrinterConnectionMessageContainer()); { //Construct buttons nextButton = textImageButtonFactory.Generate(LocalizedString.Get("Done")); nextButton.Click += new EventHandler(NextButton_Click); nextButton.Visible = false; connectButton = textImageButtonFactory.Generate(LocalizedString.Get("Connect")); connectButton.Click += new EventHandler(ConnectButton_Click); PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents); GuiWidget hSpacer = new GuiWidget(); hSpacer.HAnchor = HAnchor.ParentLeftRight; //Add buttons to buttonContainer footerRow.AddChild(nextButton); footerRow.AddChild(connectButton); footerRow.AddChild(hSpacer); footerRow.AddChild(cancelButton); } }
void ConnectButton_Click(object sender, EventArgs mouseEvent) { string candidatePort = null; currentPortNames = FrostedSerialPort.GetPortNames(); foreach (string portName in currentPortNames) { if (!startingPortNames.Any(portName.Contains)) { candidatePort = portName; } } if (candidatePort == null) { printerErrorMessage.TextColor = RGBA_Bytes.Red; string printerErrorMessageLabelFull = LocalizedString.Get("Oops! Printer could not be detected "); printerErrorMessage.Text = printerErrorMessageLabelFull; } else { ActivePrinter.ComPort = candidatePort; printerErrorMessage.TextColor = ActiveTheme.Instance.PrimaryTextColor; string printerErrorMessageLabelTwo = LocalizedString.Get("Attempting to connect"); string printerErrorMessageLabelTwoFull = string.Format("{0}...", printerErrorMessageLabelTwo); printerErrorMessage.Text = printerErrorMessageLabelTwoFull; this.ActivePrinter.Commit(); ActivePrinterProfile.Instance.ActivePrinter = this.ActivePrinter; PrinterConnectionAndCommunication.Instance.ConnectToActivePrinter(); connectButton.Visible = false; } }
public static void LoadStartupProfile() { bool portExists = false; string[] comportNames = FrostedSerialPort.GetPortNames(); string lastProfileID = UserSettings.Instance.get("ActiveProfileID"); var startupProfile = LoadProfile(lastProfileID); if (startupProfile != null) { portExists = comportNames.Contains(startupProfile.ComPort()); Instance = startupProfile; if (portExists && startupProfile.DoAutoConnect()) { UiThread.RunOnIdle(() => { //PrinterConnectionAndCommunication.Instance.HaltConnectionThread(); PrinterConnectionAndCommunication.Instance.ConnectToActivePrinter(); }, 2); } } if (Instance == null) { // Load an empty profile with just the MatterHackers base settings from config.json Instance = new SettingsProfile(LoadEmptyProfile()); } }
private void onConnectButton_Click(object sender, EventArgs mouseEvent) { if (ActivePrinterProfile.Instance.ActivePrinter == null) { #if __ANDROID__ SetupWizardWindow.Show(); #else PrinterActionRow.OpenConnectionWindow(true); #endif } else { #if __ANDROID__ if (!FrostedSerialPort.HasPermissionToDevice()) { // Opens the USB device permissions dialog which will call back into our UsbDevice broadcast receiver to connect FrostedSerialPort.RequestPermissionToDevice(); } else #endif { ConnectToActivePrinter(); } } }
protected void CreateSerialPortControls(FlowLayoutWidget comPortContainer, string activePrinterSerialPort) { int portIndex = 0; string[] allPorts = FrostedSerialPort.GetPortNames(); IEnumerable <string> filteredPorts; if (OsInformation.OperatingSystem == OSType.X11) { // A default and naive filter that works well on Ubuntu 14 filteredPorts = allPorts.Where(portName => portName != "/dev/tty" && !linuxDefaultUIFilter.Match(portName).Success); } else { // looks_like_mac -- serialPort.StartsWith("/dev/tty."); looks_like_pc -- serialPort.StartsWith("COM") filteredPorts = allPorts.Where(portName => portName.StartsWith("/dev/tty.") || portName.StartsWith("COM")); } IEnumerable <string> portsToCreate = filteredPorts.Any() ? filteredPorts : allPorts; // Add a radio button for each filtered port foreach (string portName in portsToCreate) { SerialPortIndexRadioButton comPortOption = createComPortOption(portName, activePrinterSerialPort == portName); if (comPortOption.Checked) { printerComPortIsAvailable = true; } SerialPortButtonsList.Add(comPortOption); comPortContainer.AddChild(comPortOption); portIndex++; } // Add a virtual entry for serial ports that were previously configured but are not currently connected if (!printerComPortIsAvailable && activePrinterSerialPort != null) { SerialPortIndexRadioButton comPortOption = createComPortOption(activePrinterSerialPort, true); comPortOption.Enabled = false; comPortContainer.AddChild(comPortOption); SerialPortButtonsList.Add(comPortOption); portIndex++; } //If there are still no com ports show a message to that effect if (portIndex == 0) { TextWidget comPortOption = new TextWidget(LocalizedString.Get("No COM ports available")); comPortOption.Margin = new BorderDouble(3, 6, 5, 6); comPortOption.TextColor = ActiveTheme.Instance.PrimaryTextColor; comPortContainer.AddChild(comPortOption); } }
FlowLayoutWidget GetComPortWidget() { FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.TopToBottom); int portIndex = 0; foreach (string serialPort in FrostedSerialPort.GetPortNames()) { //Filter com port list based on usb type (applies to Mac mostly) bool looks_like_mac = serialPort.StartsWith("/dev/tty."); bool looks_like_pc = serialPort.StartsWith("COM"); if (looks_like_mac || looks_like_pc) { SerialPortIndexRadioButton comPortOption = createComPortOption(serialPort); container.AddChild(comPortOption); portIndex++; } } //If there are no com ports in the filtered list assume we are missing something and show the unfiltered list if (portIndex == 0) { foreach (string serialPort in FrostedSerialPort.GetPortNames()) { SerialPortIndexRadioButton comPortOption = createComPortOption(serialPort); container.AddChild(comPortOption); portIndex++; } } if (!printerComPortIsAvailable && this.ActivePrinter.ComPort != null) { SerialPortIndexRadioButton comPortOption = createComPortOption(this.ActivePrinter.ComPort); comPortOption.Enabled = false; container.AddChild(comPortOption); portIndex++; } //If there are still no com ports show a message to that effect if (portIndex == 0) { TextWidget comPortOption = new TextWidget(LocalizedString.Get("No COM ports available")); comPortOption.Margin = new BorderDouble(3, 6, 5, 6); comPortOption.TextColor = this.subContainerTextColor; container.AddChild(comPortOption); } return(container); }
public PrinterListItemView(Printer printerRecord, ConnectionWindow windowController) : base(printerRecord, windowController) { this.Margin = new BorderDouble(1); this.BackgroundColor = this.defaultBackgroundColor; this.Padding = new BorderDouble(0); this.Name = this.printerRecord.Name + " Profile"; string[] comportNames = FrostedSerialPort.GetPortNames(); bool portIsAvailable = comportNames.Contains(printerRecord.ComPort); printerName = new TextWidget(this.printerRecord.Name); printerName.TextColor = this.defaultTextColor; printerName.HAnchor = HAnchor.ParentLeftRight; printerName.Margin = new BorderDouble(5, 10, 5, 10); string availableText = LocalizedString.Get("Unavailable"); RGBA_Bytes availableColor = new RGBA_Bytes(158, 18, 0); if (portIsAvailable) { availableText = ""; } if (ActivePrinterProfile.Instance.ActivePrinter != null) { int connectedPrinterHash = ActivePrinterProfile.Instance.ActivePrinter.GetHashCode(); int printerOptionHash = printerRecord.GetHashCode(); if (connectedPrinterHash == printerOptionHash) { availableText = PrinterConnectionAndCommunication.Instance.PrinterConnectionStatusVerbose; availableColor = new RGBA_Bytes(0, 95, 107); } } TextWidget availableIndicator = new TextWidget(availableText, pointSize: 10); availableIndicator.TextColor = availableColor; availableIndicator.Padding = new BorderDouble(3, 0, 0, 3); availableIndicator.Margin = new BorderDouble(right: 5); availableIndicator.VAnchor = Agg.UI.VAnchor.ParentCenter; this.AddChild(printerName); this.AddChild(availableIndicator); this.HAnchor = HAnchor.ParentLeftRight; BindHandlers(); }
public SetupStepComPortTwo(PrinterConfig printer) { this.printer = printer; startingPortNames = FrostedSerialPort.GetPortNames(); contentRow.AddChild(createPrinterConnectionMessageContainer()); //Construct buttons nextButton = theme.CreateDialogButton("Done".Localize()); nextButton.Click += (s, e) => Parent.Close(); nextButton.Visible = false; connectButton = theme.CreateDialogButton("Connect".Localize()); connectButton.Click += (s, e) => { // 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(); } else { printerErrorMessage.TextColor = theme.TextColor; printerErrorMessage.Text = "Attempting to connect".Localize() + "..."; printer.Settings.Helpers.SetComPort(candidatePort); printer.Connection.Connect(); connectButton.Visible = false; } }; var backButton = theme.CreateDialogButton("<< Back".Localize()); backButton.Click += (s, e) => { DialogWindow.ChangeToPage(new SetupStepComPortOne(printer)); }; this.AddPageAction(nextButton); this.AddPageAction(backButton); this.AddPageAction(connectButton); // Register listeners printer.Connection.CommunicationStateChanged += Connection_CommunicationStateChanged; }
private void onConnectButton_Click(object sender, EventArgs mouseEvent) { if (ActiveSliceSettings.Instance.PrinterSelected) { #if __ANDROID__ if (!FrostedSerialPort.HasPermissionToDevice()) { // Opens the USB device permissions dialog which will call back into our UsbDevice broadcast receiver to connect FrostedSerialPort.RequestPermissionToDevice(RunTroubleShooting); } else #endif { PrinterConnectionAndCommunication.Instance.HaltConnectionThread(); PrinterConnectionAndCommunication.Instance.ConnectToActivePrinter(true); } } }
private void ConnectButton_Click(object sender, EventArgs mouseEvent) { // Select the first port that's in GetPortNames() but not in startingPortNames string candidatePort = FrostedSerialPort.GetPortNames().Except(startingPortNames).FirstOrDefault(); if (candidatePort == null) { printerErrorMessage.TextColor = RGBA_Bytes.Red; printerErrorMessage.Text = "Oops! Printer could not be detected ".Localize(); } else { printerErrorMessage.TextColor = ActiveTheme.Instance.PrimaryTextColor; printerErrorMessage.Text = "Attempting to connect".Localize() + "..."; ActiveSliceSettings.Instance.SetComPort(candidatePort); PrinterConnectionAndCommunication.Instance.ConnectToActivePrinter(); connectButton.Visible = false; } }
public static DataStorage.Printer GetAutoConnectProfile() { string query = string.Format("SELECT * FROM Printer;"); IEnumerable <Printer> printer_profiles = (IEnumerable <Printer>)Datastore.Instance.dbSQLite.Query <Printer>(query); string[] comportNames = FrostedSerialPort.GetPortNames(); foreach (DataStorage.Printer printer in printer_profiles) { if (printer.AutoConnectFlag) { bool portIsAvailable = comportNames.Contains(printer.ComPort); if (portIsAvailable) { return(printer); } } } return(null); }
protected void CreateSerialPortControls(FlowLayoutWidget comPortContainer, string activePrinterSerialPort) { int portIndex = 0; // Add a radio button for each filtered port foreach (string portName in FrostedSerialPort.GetPortNames()) { SerialPortIndexRadioButton comPortOption = createComPortOption(portName, activePrinterSerialPort == portName); if (comPortOption.Checked) { printerComPortIsAvailable = true; } SerialPortButtonsList.Add(comPortOption); comPortContainer.AddChild(comPortOption); portIndex++; } // Add a virtual entry for serial ports that were previously configured but are not currently connected if (!printerComPortIsAvailable && activePrinterSerialPort != null) { SerialPortIndexRadioButton comPortOption = createComPortOption(activePrinterSerialPort, true); comPortOption.Enabled = false; comPortContainer.AddChild(comPortOption); SerialPortButtonsList.Add(comPortOption); portIndex++; } //If there are still no com ports show a message to that effect if (portIndex == 0) { var comPortOption = new TextWidget("No COM ports available".Localize()) { Margin = new BorderDouble(3, 6, 5, 6), TextColor = theme.TextColor }; comPortContainer.AddChild(comPortOption); } }
public SetupStepComPortTwo() { startingPortNames = FrostedSerialPort.GetPortNames(); contentRow.AddChild(createPrinterConnectionMessageContainer()); { //Construct buttons nextButton = textImageButtonFactory.Generate("Done".Localize()); nextButton.Click += (s, e) => UiThread.RunOnIdle(Parent.Close); nextButton.Visible = false; connectButton = textImageButtonFactory.Generate("Connect".Localize()); connectButton.Click += ConnectButton_Click; PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents); //Add buttons to buttonContainer footerRow.AddChild(nextButton); footerRow.AddChild(connectButton); footerRow.AddChild(new HorizontalSpacer()); footerRow.AddChild(cancelButton); } }
public void UserRequestedConnectToActivePrinter() { if (printer.Settings.PrinterSelected) { listenForConnectFailed = true; connectStartMs = UiThread.CurrentTimerMs; #if __ANDROID__ if (!printer.Settings.GetValue <bool>(SettingsKey.enable_network_printing) && !FrostedSerialPort.HasPermissionToDevice()) { // Opens the USB device permissions dialog which will call back into our UsbDevice broadcast receiver to connect FrostedSerialPort.RequestPermissionToDevice(RunTroubleShooting); } else #endif { printer.Connection.HaltConnectionThread(); printer.Connection.Connect(); } } }
public SetupStepComPortTwo(PrinterConfig printer) { this.printer = printer; startingPortNames = FrostedSerialPort.GetPortNames(); contentRow.AddChild(createPrinterConnectionMessageContainer()); //Construct buttons nextButton = theme.CreateDialogButton("Done".Localize()); nextButton.Click += (s, e) => UiThread.RunOnIdle(Parent.Close); nextButton.Visible = false; connectButton = theme.CreateDialogButton("Connect".Localize()); connectButton.Click += (s, e) => { // 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(); } else { printerErrorMessage.TextColor = ActiveTheme.Instance.PrimaryTextColor; printerErrorMessage.Text = "Attempting to connect".Localize() + "..."; ActiveSliceSettings.Instance.Helpers.SetComPort(candidatePort); printer.Connection.Connect(); connectButton.Visible = false; } }; printer.Connection.CommunicationStateChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents); this.AddPageAction(nextButton); this.AddPageAction(connectButton); }
private void ConnectButton_Click(object sender, EventArgs mouseEvent) { // Select the first port that's in GetPortNames() but not in startingPortNames string candidatePort = FrostedSerialPort.GetPortNames().Except(startingPortNames).FirstOrDefault(); if (candidatePort == null) { printerErrorMessage.TextColor = RGBA_Bytes.Red; string printerErrorMessageLabelFull = LocalizedString.Get("Oops! Printer could not be detected "); printerErrorMessage.Text = printerErrorMessageLabelFull; } else { ActivePrinter.ComPort = candidatePort; printerErrorMessage.TextColor = ActiveTheme.Instance.PrimaryTextColor; string printerErrorMessageLabelTwo = LocalizedString.Get("Attempting to connect"); string printerErrorMessageLabelTwoFull = string.Format("{0}...", printerErrorMessageLabelTwo); printerErrorMessage.Text = printerErrorMessageLabelTwoFull; this.ActivePrinter.Commit(); ActivePrinterProfile.Instance.ActivePrinter = this.ActivePrinter; PrinterConnectionAndCommunication.Instance.ConnectToActivePrinter(); connectButton.Visible = false; } }
private void RebuildMenuItems() { dropdownList.MenuItems.Clear(); foreach (string listItem in FrostedSerialPort.GetPortNames()) { // Add each serial port to the dropdown list MenuItem newItem = dropdownList.AddItem(listItem); // When the given menu item is selected, save its value back into settings newItem.Selected += (sender, e) => { if (sender is MenuItem menuItem) { this.SetValue( menuItem.Text, userInitiated: true); } }; } // Set control text dropdownList.SelectedLabel = this.Value; }
public SetupStepComPortTwo(PrinterConfig printer) { this.printer = printer; startingPortNames = FrostedSerialPort.GetPortNames(); contentRow.AddChild(createPrinterConnectionMessageContainer()); //Construct buttons nextButton = theme.CreateDialogButton("Done".Localize()); 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 foundPort = FrostedSerialPort.GetPortNames().Except(startingPortNames).FirstOrDefault(); if (foundPort == null) { foundPort = FrostedSerialPort.GetPortNames(includeEmulator: false).LastOrDefault(); if (foundPort != null) { // try to connect to the last port found printerConnectionMessage.TextColor = theme.TextColor; printerConnectionMessage.Text = "Attempting to connect to {0}".Localize().FormatWith(foundPort) + "..."; printer.Settings.Helpers.SetComPort(foundPort); printer.Connection.Connect(); connectButton.Visible = false; } else { // no com port was found, attempt to connect to a com port if there is any printerConnectionMessage.TextColor = Color.Red; printerConnectionMessage.Text = "Oops! Printer could not be detected ".Localize(); } } else { printerConnectionMessage.TextColor = theme.TextColor; printerConnectionMessage.Text = "Attempting to connect to {0}".Localize().FormatWith(foundPort) + "..."; printer.Settings.Helpers.SetComPort(foundPort); printer.Connection.Connect(); connectButton.Visible = false; } }; var backButton = theme.CreateDialogButton("<< Back".Localize()); backButton.Click += (s, e) => { DialogWindow.ChangeToPage(new SetupStepComPortOne(printer)); }; this.AddPageAction(nextButton); this.AddPageAction(backButton); this.AddPageAction(connectButton); // Register listeners printer.Connection.CommunicationStateChanged += Connection_CommunicationStateChanged; }
public EditConnectionWidget(ConnectionWindow windowController, GuiWidget containerWindowToClose, Printer activePrinter = null, object state = null) : base(windowController, containerWindowToClose) { textImageButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor; textImageButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryTextColor; textImageButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryTextColor; textImageButtonFactory.pressedTextColor = ActiveTheme.Instance.PrimaryTextColor; textImageButtonFactory.borderWidth = 0; linkButtonFactory.textColor = ActiveTheme.Instance.PrimaryTextColor; linkButtonFactory.fontSize = 8; this.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor; this.AnchorAll(); this.Padding = new BorderDouble(0); //To be re-enabled once native borders are turned off GuiWidget mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom); mainContainer.AnchorAll(); mainContainer.Padding = new BorderDouble(3, 3, 3, 5); mainContainer.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; string headerTitle; if (activePrinter == null) { headerTitle = string.Format("Add a Printer"); this.addNewPrinterFlag = true; this.ActivePrinter = new Printer(); this.ActivePrinter.Name = "Default Printer"; this.ActivePrinter.BaudRate = "250000"; try { this.ActivePrinter.ComPort = FrostedSerialPort.GetPortNames().FirstOrDefault(); } catch (Exception e) { Debug.Print(e.Message); GuiWidget.BreakInDebugger(); //No active COM ports } } else { this.ActivePrinter = activePrinter; string editHeaderTitleTxt = LocalizedString.Get("Edit"); headerTitle = string.Format("{1} - {0}", this.ActivePrinter.Name, editHeaderTitleTxt); if (this.ActivePrinter.BaudRate == null) { this.ActivePrinter.BaudRate = "250000"; } if (this.ActivePrinter.ComPort == null) { try { this.ActivePrinter.ComPort = FrostedSerialPort.GetPortNames().FirstOrDefault(); } catch (Exception e) { Debug.Print(e.Message); GuiWidget.BreakInDebugger(); //No active COM ports } } } FlowLayoutWidget 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; { TextWidget headerLabel = new TextWidget(headerTitle, pointSize: 14); headerLabel.TextColor = this.defaultTextColor; headerRow.AddChild(headerLabel); } ConnectionControlContainer = new FlowLayoutWidget(FlowDirection.TopToBottom); ConnectionControlContainer.Padding = new BorderDouble(5); ConnectionControlContainer.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor; ConnectionControlContainer.HAnchor = HAnchor.ParentLeftRight; { TextWidget printerNameLabel = new TextWidget(LocalizedString.Get("Printer Name"), 0, 0, 10); printerNameLabel.TextColor = this.defaultTextColor; printerNameLabel.HAnchor = HAnchor.ParentLeftRight; printerNameLabel.Margin = new BorderDouble(0, 0, 0, 1); printerNameInput = new MHTextEditWidget(this.ActivePrinter.Name); printerNameInput.HAnchor |= HAnchor.ParentLeftRight; comPortLabelWidget = new FlowLayoutWidget(); Button refreshComPorts = linkButtonFactory.Generate(LocalizedString.Get("(refresh)")); refreshComPorts.Margin = new BorderDouble(left: 5); refreshComPorts.VAnchor = VAnchor.ParentBottom; refreshComPorts.Click += new EventHandler(RefreshComPorts); FlowLayoutWidget comPortContainer = null; #if !__ANDROID__ TextWidget comPortLabel = new TextWidget(LocalizedString.Get("Serial Port"), 0, 0, 10); comPortLabel.TextColor = this.defaultTextColor; comPortLabelWidget.AddChild(comPortLabel); comPortLabelWidget.AddChild(refreshComPorts); comPortLabelWidget.Margin = new BorderDouble(0, 0, 0, 10); comPortLabelWidget.HAnchor = HAnchor.ParentLeftRight; comPortContainer = new FlowLayoutWidget(FlowDirection.TopToBottom); comPortContainer.Margin = new BorderDouble(0); comPortContainer.HAnchor = HAnchor.ParentLeftRight; CreateSerialPortControls(comPortContainer, this.ActivePrinter.ComPort); #endif TextWidget baudRateLabel = new TextWidget(LocalizedString.Get("Baud Rate"), 0, 0, 10); baudRateLabel.TextColor = this.defaultTextColor; baudRateLabel.Margin = new BorderDouble(0, 0, 0, 10); baudRateLabel.HAnchor = HAnchor.ParentLeftRight; baudRateWidget = GetBaudRateWidget(); baudRateWidget.HAnchor = HAnchor.ParentLeftRight; FlowLayoutWidget printerMakeContainer = createPrinterMakeContainer(); FlowLayoutWidget printerModelContainer = createPrinterModelContainer(); enableAutoconnect = new CheckBox(LocalizedString.Get("Auto Connect")); enableAutoconnect.TextColor = ActiveTheme.Instance.PrimaryTextColor; enableAutoconnect.Margin = new BorderDouble(top: 10); enableAutoconnect.HAnchor = HAnchor.ParentLeft; if (this.ActivePrinter.AutoConnectFlag) { enableAutoconnect.Checked = true; } if (state as StateBeforeRefresh != null) { enableAutoconnect.Checked = ((StateBeforeRefresh)state).autoConnect; } SerialPortControl serialPortScroll = new SerialPortControl(); if (comPortContainer != null) { serialPortScroll.AddChild(comPortContainer); } ConnectionControlContainer.VAnchor = VAnchor.ParentBottomTop; ConnectionControlContainer.AddChild(printerNameLabel); ConnectionControlContainer.AddChild(printerNameInput); ConnectionControlContainer.AddChild(printerMakeContainer); ConnectionControlContainer.AddChild(printerModelContainer); ConnectionControlContainer.AddChild(comPortLabelWidget); ConnectionControlContainer.AddChild(serialPortScroll); ConnectionControlContainer.AddChild(baudRateLabel); ConnectionControlContainer.AddChild(baudRateWidget); #if !__ANDROID__ ConnectionControlContainer.AddChild(enableAutoconnect); #endif } FlowLayoutWidget buttonContainer = new FlowLayoutWidget(FlowDirection.LeftToRight); buttonContainer.HAnchor = HAnchor.ParentLeft | HAnchor.ParentRight; //buttonContainer.VAnchor = VAnchor.BottomTop; buttonContainer.Margin = new BorderDouble(0, 5, 0, 3); { //Construct buttons saveButton = textImageButtonFactory.Generate(LocalizedString.Get("Save")); //saveButton.VAnchor = VAnchor.Bottom; cancelButton = textImageButtonFactory.Generate(LocalizedString.Get("Cancel")); //cancelButton.VAnchor = VAnchor.Bottom; cancelButton.Click += new EventHandler(CancelButton_Click); //Add buttons to buttonContainer buttonContainer.AddChild(saveButton); buttonContainer.AddChild(new HorizontalSpacer()); buttonContainer.AddChild(cancelButton); } //mainContainer.AddChild(new PrinterChooser()); mainContainer.AddChild(headerRow); mainContainer.AddChild(ConnectionControlContainer); mainContainer.AddChild(buttonContainer); #if __ANDROID__ this.AddChild(new SoftKeyboardContentOffset(mainContainer, SoftKeyboardContentOffset.AndroidKeyboardOffset)); #else this.AddChild(mainContainer); #endif BindSaveButtonHandlers(); BindBaudRateHandlers(); }
protected void AddChildElements() { addButton = textImageButtonFactory.GenerateTooltipButton("Add".Localize(), StaticData.Instance.LoadIcon("icon_circle_plus.png", 32, 32).InvertLightness()); addButton.ToolTipText = "Add a file to be printed".Localize(); addButton.Margin = new BorderDouble(6, 6, 6, 3); startButton = textImageButtonFactory.GenerateTooltipButton("Print".Localize(), StaticData.Instance.LoadIcon("icon_play_32x32.png", 32, 32).InvertLightness()); startButton.Name = "Start Print Button"; startButton.ToolTipText = "Begin printing the selected item.".Localize(); startButton.Margin = new BorderDouble(6, 6, 6, 3); startButton.Click += onStartButton_Click; configureButton = textImageButtonFactory.GenerateTooltipButton("Finish Setup...".Localize()); configureButton.Name = "Finish Setup Button"; configureButton.ToolTipText = "Run setup configuration for printer.".Localize(); configureButton.Margin = new BorderDouble(6, 6, 6, 3); configureButton.Click += onStartButton_Click; connectButton = textImageButtonFactory.GenerateTooltipButton("Connect".Localize(), StaticData.Instance.LoadIcon("icon_power_32x32.png", 32, 32).InvertLightness()); connectButton.ToolTipText = "Connect to the printer".Localize(); connectButton.Margin = new BorderDouble(6, 6, 6, 3); connectButton.Click += (s, e) => { if (ActiveSliceSettings.Instance.PrinterSelected) { #if __ANDROID__ if (!FrostedSerialPort.HasPermissionToDevice()) { // Opens the USB device permissions dialog which will call back into our UsbDevice broadcast receiver to connect FrostedSerialPort.RequestPermissionToDevice(RunTroubleShooting); } else #endif { PrinterConnectionAndCommunication.Instance.HaltConnectionThread(); PrinterConnectionAndCommunication.Instance.ConnectToActivePrinter(true); } } }; addPrinterButton = textImageButtonFactory.GenerateTooltipButton("Add Printer".Localize()); addPrinterButton.ToolTipText = "Select and add a new printer.".Localize(); addPrinterButton.Margin = new BorderDouble(6, 6, 6, 3); addPrinterButton.Click += (s, e) => { UiThread.RunOnIdle(() => WizardWindow.ShowPrinterSetup(true)); }; selectPrinterButton = textImageButtonFactory.GenerateTooltipButton("Select Printer".Localize()); selectPrinterButton.ToolTipText = "Select an existing printer.".Localize(); selectPrinterButton.Margin = new BorderDouble(6, 6, 6, 3); selectPrinterButton.Click += (s, e) => { WizardWindow.Show <SetupOptionsPage>("/SetupOptions", "Setup Wizard"); }; string resetConnectionButtontText = "Reset".Localize(); string resetConnectionButtonMessage = "Reboots the firmware on the controller".Localize(); resetConnectionButton = textImageButtonFactory.GenerateTooltipButton(resetConnectionButtontText, StaticData.Instance.LoadIcon("e_stop4.png", 32, 32).InvertLightness()); resetConnectionButton.ToolTipText = resetConnectionButtonMessage; resetConnectionButton.ToolTipText = resetConnectionButtonMessage; resetConnectionButton.Margin = new BorderDouble(6, 6, 6, 3); string skipButtonText = "Skip".Localize(); string skipButtonMessage = "Skip the current item and move to the next in queue".Localize(); skipButton = makeButton(skipButtonText, skipButtonMessage); string removeButtonText = "Remove".Localize(); string removeButtonMessage = "Remove current item from queue".Localize(); removeButton = makeButton(removeButtonText, removeButtonMessage); removeButton.Click += onRemoveButton_Click; string pauseButtonText = "Pause".Localize(); string pauseButtonMessage = "Pause the current print".Localize(); pauseButton = makeButton(pauseButtonText, pauseButtonMessage); pauseButton.Click += (s, e) => { PrinterConnectionAndCommunication.Instance.RequestPause(); pauseButton.Enabled = false; }; this.AddChild(pauseButton); allPrintButtons.Add(pauseButton); string cancelCancelButtonText = "Cancel Connect".Localize(); string cancelConnectButtonMessage = "Stop trying to connect to the printer.".Localize(); cancelConnectButton = makeButton(cancelCancelButtonText, cancelConnectButtonMessage); string cancelButtonText = "Cancel".Localize(); string cancelButtonMessage = "Stop the current print".Localize(); cancelButton = makeButton(cancelButtonText, cancelButtonMessage); cancelButton.Name = "Cancel Print Button"; string resumeButtonText = "Resume".Localize(); string resumeButtonMessage = "Resume the current print".Localize(); resumeButton = makeButton(resumeButtonText, resumeButtonMessage); resumeButton.Name = "Resume Button"; resumeButton.Click += (s, e) => { if (PrinterConnectionAndCommunication.Instance.PrinterIsPaused) { PrinterConnectionAndCommunication.Instance.Resume(); } pauseButton.Enabled = true; }; this.AddChild(resumeButton); allPrintButtons.Add(resumeButton); string reprintButtonText = "Print Again".Localize(); string reprintButtonMessage = "Print current item again".Localize(); reprintButton = makeButton(reprintButtonText, reprintButtonMessage); reprintButton.Name = "Print Again Button"; string doneCurrentPartButtonText = "Done".Localize(); string doenCurrentPartButtonMessage = "Move to next print in queue".Localize(); doneWithCurrentPartButton = makeButton(doneCurrentPartButtonText, doenCurrentPartButtonMessage); doneWithCurrentPartButton.Name = "Done Button"; this.Margin = new BorderDouble(0, 0, 10, 0); this.HAnchor = HAnchor.FitToChildren; this.AddChild(connectButton); allPrintButtons.Add(connectButton); this.AddChild(addPrinterButton); allPrintButtons.Add(addPrinterButton); this.AddChild(selectPrinterButton); allPrintButtons.Add(selectPrinterButton); this.AddChild(addButton); allPrintButtons.Add(addButton); this.AddChild(startButton); allPrintButtons.Add(startButton); this.AddChild(configureButton); allPrintButtons.Add(configureButton); this.AddChild(doneWithCurrentPartButton); allPrintButtons.Add(doneWithCurrentPartButton); this.AddChild(skipButton); allPrintButtons.Add(skipButton); this.AddChild(cancelButton); allPrintButtons.Add(cancelButton); this.AddChild(cancelConnectButton); allPrintButtons.Add(cancelConnectButton); this.AddChild(reprintButton); allPrintButtons.Add(reprintButton); this.AddChild(removeButton); allPrintButtons.Add(removeButton); this.AddChild(resetConnectionButton); allPrintButtons.Add(resetConnectionButton); SetButtonStates(); }
private void RefreshStatus() { CriteriaRow.ResetAll(); // Clear the main container contentRow.CloseAllChildren(); // Regen and refresh the troubleshooting criteria var printerNameLabel = new TextWidget(string.Format("{0}:", "Connection Troubleshooting".Localize()), 0, 0, labelFontSize) { TextColor = theme.TextColor, Margin = new BorderDouble(bottom: 10) }; #if __ANDROID__ IUsbSerialPort serialPort = FrostedSerialPort.LoadSerialDriver(null); #if ANDROID7 // Filter out the built-in 002 device and select the first item from the list // On the T7 Android device, there is a non-printer device always registered at usb/002/002 that must be ignored UsbDevice usbPrintDevice = usbManager.DeviceList.Values.Where(d => d.DeviceName != "/dev/bus/usb/002/002").FirstOrDefault(); #else UsbDevice usbPrintDevice = usbManager.DeviceList.Values.FirstOrDefault(); #endif UsbStatus usbStatus = new UsbStatus() { IsDriverLoadable = (serialPort != null), HasUsbDevice = true, HasUsbPermission = false, AnyUsbDeviceExists = usbPrintDevice != null }; if (!usbStatus.IsDriverLoadable) { usbStatus.HasUsbDevice = usbPrintDevice != null; if (usbStatus.HasUsbDevice) { // TODO: Testing specifically for UsbClass.Comm seems fragile but no better alternative exists without more research usbStatus.UsbDetails = new UsbDeviceDetails() { ProductID = usbPrintDevice.ProductId, VendorID = usbPrintDevice.VendorId, DriverClass = usbManager.DeviceList.Values.First().DeviceClass == Android.Hardware.Usb.UsbClass.Comm ? "cdcDriverType" : "ftdiDriverType" }; usbStatus.Summary = string.Format("No USB device definition found. Click the 'Fix' button to add an override for your device ", usbStatus.UsbDetails.VendorID, usbStatus.UsbDetails.ProductID); } } usbStatus.HasUsbPermission = usbStatus.IsDriverLoadable && FrostedSerialPort.HasPermissionToDevice(serialPort); contentRow.AddChild(printerNameLabel); contentRow.AddChild(new CriteriaRow( "USB Connection", "Retry", "No USB device found. Check and reseat cables and try again", usbStatus.AnyUsbDeviceExists, () => UiThread.RunOnIdle(RefreshStatus), theme)); contentRow.AddChild(new CriteriaRow( "USB Driver", "Fix", usbStatus.Summary, usbStatus.IsDriverLoadable, () => { string overridePath = Path.Combine(ApplicationDataStorage.ApplicationUserDataPath, "data", "usboverride.local"); UsbDeviceDetails usbDetails = usbStatus.UsbDetails; File.AppendAllText(overridePath, string.Format("{0},{1},{2}\r\n", usbDetails.VendorID, usbDetails.ProductID, usbDetails.DriverClass)); UiThread.RunOnIdle(() => RefreshStatus()); }, theme)); contentRow.AddChild(new CriteriaRow( "USB Permission", "Request Permission", "Click the 'Request Permission' button to gain Android access rights", usbStatus.HasUsbPermission, () => { if (checkForPermissionTimer == null) { checkForPermissionTimer = new System.Threading.Timer((state) => { if (FrostedSerialPort.HasPermissionToDevice(serialPort)) { UiThread.RunOnIdle(this.RefreshStatus); checkForPermissionTimer.Dispose(); } }, null, 200, 200); } FrostedSerialPort.RequestPermissionToDevice(serialPort); }, theme)); #endif connectToPrinterRow = new CriteriaRow( "Connect to Printer".Localize(), "Connect".Localize(), "Click the 'Connect' button to retry the original connection attempt".Localize(), false, () => printer.Connection.Connect(), theme); contentRow.AddChild(connectToPrinterRow); if (CriteriaRow.ActiveErrorItem != null) { var errorText = new FlowLayoutWidget() { Padding = new BorderDouble(0, 15) }; errorText.AddChild( new TextWidget(CriteriaRow.ActiveErrorItem.ErrorText) { TextColor = theme.PrimaryAccentColor }); contentRow.AddChild(errorText); } }
public EditConnectionWidget(ConnectionWindow windowController, GuiWidget containerWindowToClose, Printer activePrinter = null, object state = null) : base(windowController, containerWindowToClose) { textImageButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor; textImageButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryTextColor; textImageButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryTextColor; textImageButtonFactory.pressedTextColor = ActiveTheme.Instance.PrimaryTextColor; textImageButtonFactory.borderWidth = 0; linkButtonFactory.textColor = ActiveTheme.Instance.PrimaryTextColor; linkButtonFactory.fontSize = 8; this.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor; this.AnchorAll(); this.Padding = new BorderDouble(0); //To be re-enabled once native borders are turned off GuiWidget mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom); mainContainer.AnchorAll(); mainContainer.Padding = new BorderDouble(3, 3, 3, 5); mainContainer.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; string headerTitle; if (activePrinter == null) { headerTitle = string.Format("Add a Printer"); this.addNewPrinterFlag = true; this.ActivePrinter = new Printer(); this.ActivePrinter.Name = "Default Printer"; this.ActivePrinter.BaudRate = "250000"; try { this.ActivePrinter.ComPort = FrostedSerialPort.GetPortNames().FirstOrDefault(); } catch { //No active COM ports } } else { this.ActivePrinter = activePrinter; string editHeaderTitleTxt = LocalizedString.Get("Edit"); headerTitle = string.Format("{1} - {0}", this.ActivePrinter.Name, editHeaderTitleTxt); if (this.ActivePrinter.BaudRate == null) { this.ActivePrinter.BaudRate = "250000"; } if (this.ActivePrinter.ComPort == null) { try { this.ActivePrinter.ComPort = FrostedSerialPort.GetPortNames().FirstOrDefault(); } catch { //No active COM ports } } } FlowLayoutWidget 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; { TextWidget headerLabel = new TextWidget(headerTitle, pointSize: 14); headerLabel.TextColor = this.defaultTextColor; headerRow.AddChild(headerLabel); } ConnectionControlContainer = new FlowLayoutWidget(FlowDirection.TopToBottom); ConnectionControlContainer.Padding = new BorderDouble(5); ConnectionControlContainer.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor; ConnectionControlContainer.HAnchor = HAnchor.ParentLeftRight; { TextWidget printerNameLabel = new TextWidget(LocalizedString.Get("Printer Name"), 0, 0, 10); printerNameLabel.TextColor = this.defaultTextColor; printerNameLabel.HAnchor = HAnchor.ParentLeftRight; printerNameLabel.Margin = new BorderDouble(0, 0, 0, 1); printerNameInput = new MHTextEditWidget(this.ActivePrinter.Name); printerNameInput.HAnchor |= HAnchor.ParentLeftRight; comPortLabelWidget = new FlowLayoutWidget(); Button refreshComPorts = linkButtonFactory.Generate(LocalizedString.Get("(refresh)")); refreshComPorts.Margin = new BorderDouble(left: 5); refreshComPorts.VAnchor = VAnchor.ParentBottom; refreshComPorts.Click += new EventHandler(RefreshComPorts); FlowLayoutWidget comPortContainer = null; #if !__ANDROID__ TextWidget comPortLabel = new TextWidget(LocalizedString.Get("Serial Port"), 0, 0, 10); comPortLabel.TextColor = this.defaultTextColor; comPortLabelWidget.AddChild(comPortLabel); comPortLabelWidget.AddChild(refreshComPorts); comPortLabelWidget.Margin = new BorderDouble(0, 0, 0, 10); comPortLabelWidget.HAnchor = HAnchor.ParentLeftRight; comPortContainer = new FlowLayoutWidget(FlowDirection.TopToBottom); comPortContainer.Margin = new BorderDouble(0); comPortContainer.HAnchor = HAnchor.ParentLeftRight; int portIndex = 0; foreach (string serialPort in FrostedSerialPort.GetPortNames()) { //Filter com port list based on usb type (applies to Mac mostly) bool looks_like_mac = serialPort.StartsWith("/dev/tty."); bool looks_like_pc = serialPort.StartsWith("COM"); if (looks_like_mac || looks_like_pc) { SerialPortIndexRadioButton comPortOption = createComPortOption(serialPort); comPortContainer.AddChild(comPortOption); portIndex++; } } //If there are no com ports in the filtered list assume we are missing something and show the unfiltered list if (portIndex == 0) { foreach (string serialPort in FrostedSerialPort.GetPortNames()) { SerialPortIndexRadioButton comPortOption = createComPortOption(serialPort); comPortContainer.AddChild(comPortOption); portIndex++; } } if (!printerComPortIsAvailable && this.ActivePrinter.ComPort != null) { SerialPortIndexRadioButton comPortOption = createComPortOption(this.ActivePrinter.ComPort); comPortOption.Enabled = false; comPortContainer.AddChild(comPortOption); portIndex++; } //If there are still no com ports show a message to that effect if (portIndex == 0) { TextWidget comPortOption = new TextWidget(LocalizedString.Get("No COM ports available")); comPortOption.Margin = new BorderDouble(3, 6, 5, 6); comPortOption.TextColor = this.subContainerTextColor; comPortContainer.AddChild(comPortOption); } #endif TextWidget baudRateLabel = new TextWidget(LocalizedString.Get("Baud Rate"), 0, 0, 10); baudRateLabel.TextColor = this.defaultTextColor; baudRateLabel.Margin = new BorderDouble(0, 0, 0, 10); baudRateLabel.HAnchor = HAnchor.ParentLeftRight; baudRateWidget = GetBaudRateWidget(); baudRateWidget.HAnchor = HAnchor.ParentLeftRight; FlowLayoutWidget printerMakeContainer = createPrinterMakeContainer(); FlowLayoutWidget printerModelContainer = createPrinterModelContainer(); enableAutoconnect = new CheckBox(LocalizedString.Get("Auto Connect")); enableAutoconnect.TextColor = ActiveTheme.Instance.PrimaryTextColor; enableAutoconnect.Margin = new BorderDouble(top: 10); enableAutoconnect.HAnchor = HAnchor.ParentLeft; if (this.ActivePrinter.AutoConnectFlag) { enableAutoconnect.Checked = true; } if (state as StateBeforeRefresh != null) { enableAutoconnect.Checked = ((StateBeforeRefresh)state).autoConnect; } SerialPortControl serialPortScroll = new SerialPortControl(); if (comPortContainer != null) { serialPortScroll.AddChild(comPortContainer); } ConnectionControlContainer.VAnchor = VAnchor.ParentBottomTop; ConnectionControlContainer.AddChild(printerNameLabel); ConnectionControlContainer.AddChild(printerNameInput); ConnectionControlContainer.AddChild(printerMakeContainer); ConnectionControlContainer.AddChild(printerModelContainer); ConnectionControlContainer.AddChild(comPortLabelWidget); ConnectionControlContainer.AddChild(serialPortScroll); ConnectionControlContainer.AddChild(baudRateLabel); ConnectionControlContainer.AddChild(baudRateWidget); #if !__ANDROID__ ConnectionControlContainer.AddChild(enableAutoconnect); #endif } FlowLayoutWidget buttonContainer = new FlowLayoutWidget(FlowDirection.LeftToRight); buttonContainer.HAnchor = HAnchor.ParentLeft | HAnchor.ParentRight; //buttonContainer.VAnchor = VAnchor.BottomTop; buttonContainer.Margin = new BorderDouble(0, 5, 0, 3); { //Construct buttons saveButton = textImageButtonFactory.Generate(LocalizedString.Get("Save")); //saveButton.VAnchor = VAnchor.Bottom; cancelButton = textImageButtonFactory.Generate(LocalizedString.Get("Cancel")); //cancelButton.VAnchor = VAnchor.Bottom; cancelButton.Click += new EventHandler(CancelButton_Click); //Add buttons to buttonContainer buttonContainer.AddChild(saveButton); buttonContainer.AddChild(new HorizontalSpacer()); buttonContainer.AddChild(cancelButton); } //mainContainer.AddChild(new PrinterChooser()); mainContainer.AddChild(headerRow); mainContainer.AddChild(ConnectionControlContainer); mainContainer.AddChild(buttonContainer); this.AddChild(mainContainer); BindSaveButtonHandlers(); BindBaudRateHandlers(); }