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);
            }
        }
        private SerialPortIndexRadioButton createComPortOption(string portName, bool isActivePrinterPort)
        {
            SerialPortIndexRadioButton comPortOption = new SerialPortIndexRadioButton(portName, portName)
            {
                HAnchor   = HAnchor.ParentLeft,
                Margin    = new BorderDouble(3, 3, 5, 3),
                TextColor = ActiveTheme.Instance.PrimaryTextColor,
                Checked   = isActivePrinterPort
            };

            return(comPortOption);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public SerialPortIndexRadioButton createComPortOption(string serialPort)
        {
            //Add formatting here to make port names prettier
            string portName = serialPort;

            SerialPortIndexRadioButton comPortOption = new SerialPortIndexRadioButton(portName, serialPort);

            SerialPortButtonsList.Add(comPortOption);

            comPortOption.Margin    = new BorderDouble(3, 3, 5, 3);
            comPortOption.TextColor = this.subContainerTextColor;

            if (this.ActivePrinter.ComPort == serialPort)
            {
                comPortOption.Checked     = true;
                printerComPortIsAvailable = true;
            }
            return(comPortOption);
        }
        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 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();
        }
		private SerialPortIndexRadioButton createComPortOption(string portName, bool isActivePrinterPort)
		{
			SerialPortIndexRadioButton comPortOption = new SerialPortIndexRadioButton(portName, portName)
			{
				HAnchor = HAnchor.ParentLeft,
				Margin = new BorderDouble(3, 3, 5, 3),
				TextColor = ActiveTheme.Instance.PrimaryTextColor,
				Checked = isActivePrinterPort
			};
			return comPortOption;
		}
        public SerialPortIndexRadioButton createComPortOption(string serialPort)
        {
            //Add formatting here to make port names prettier
            string portName = serialPort;

            SerialPortIndexRadioButton comPortOption = new SerialPortIndexRadioButton(portName, serialPort);
            SerialPortButtonsList.Add(comPortOption);

            comPortOption.Margin = new BorderDouble(3, 3, 5, 3);
            comPortOption.TextColor = this.subContainerTextColor;

            if (this.ActivePrinter.ComPort == serialPort)
            {
                comPortOption.Checked = true;
                printerComPortIsAvailable = true;
            }
            return comPortOption;
        }