コード例 #1
0
        public static void GoToPrinterSettings(string widgetNameToHighlight)
        {
            if (PrinterConnectionAndCommunication.Instance?.ActivePrinter?.ID != null)
            {
                Task.Run(() =>
                {
                    UiThread.RunOnIdle(() =>
                    {
                        WizardWindow.Show <EditPrinterSettingsPage>("EditSettings", "Edit Printer Settings");

                        EventHandler unregisterEvents = null;
                        ActiveSliceSettings.ActivePrinterChanged.RegisterEvent((s, e) =>
                        {
                            WizardWindow openWindowInternal = WizardWindow.GetSystemWindow("EditSettings");
                            if (openWindowInternal != null)
                            {
                                UiThread.RunOnIdle(() => openWindowInternal.Close());
                            }
                        }, ref unregisterEvents);

                        WizardWindow openWindow = WizardWindow.GetSystemWindow("EditSettings");
                        openWindow.Closed      += (s2, e2) =>
                        {
                            UiThread.RunOnIdle(() => unregisterEvents?.Invoke(s2, null));
                        };
                    });
                });
            }
        }
コード例 #2
0
        private void MergeSettings(string settingsFilePath)
        {
            if (!string.IsNullOrEmpty(settingsFilePath) && File.Exists(settingsFilePath))
            {
                string importType = Path.GetExtension(settingsFilePath).ToLower();
                switch (importType)
                {
                case ProfileManager.ProfileExtension:
                    WizardWindow.ChangeToPage(new SelectPartsOfPrinterToImport(settingsFilePath, ActiveSliceSettings.Instance.UserLayer));
                    break;

                case ".slice":                         // old presets format
                case ".ini":
                    // create a scope for variables
                {
                    var settingsToImport = PrinterSettingsLayer.LoadFromIni(settingsFilePath);

                    bool containsValidSetting = false;
                    var  activeSettings       = ActiveSliceSettings.Instance;

                    foreach (var keyName in PrinterSettings.KnownSettings)
                    {
                        if (activeSettings.Contains(keyName))
                        {
                            containsValidSetting = true;
                            string currentValue = activeSettings.GetValue(keyName).Trim();

                            string newValue;
                            // Compare the value to import to the layer cascade value and only set if different
                            if (settingsToImport.TryGetValue(keyName, out newValue) &&
                                currentValue != newValue)
                            {
                                activeSettings.UserLayer[keyName] = newValue;
                            }
                        }
                    }
                    if (containsValidSetting)
                    {
                        activeSettings.Save();

                        UiThread.RunOnIdle(ApplicationController.Instance.ReloadAdvancedControlsPanel);
                    }
                    else
                    {
                        displayFailedToImportMessage(settingsFilePath);
                    }
                    WizardWindow.Close();
                }
                break;

                default:
                    WizardWindow.Close();
                    // Did not figure out what this file is, let the user know we don't understand it
                    StyledMessageBox.ShowMessageBox(null, "Oops! Unable to recognize settings file '{0}'.".Localize().FormatWith(Path.GetFileName(settingsFilePath)), "Unable to Import".Localize());
                    break;
                }
            }
            Invalidate();
        }
コード例 #3
0
        private void MergeSettings(string settingsFilePath)
        {
            if (!string.IsNullOrEmpty(settingsFilePath) && File.Exists(settingsFilePath))
            {
                string importType = Path.GetExtension(settingsFilePath).ToLower();
                switch (importType)
                {
                case ".printer":
                    WizardWindow.ChangeToPage(new SelectPartsOfPrinterToImport(settingsFilePath, ActiveSliceSettings.Instance.UserLayer));
                    break;

                case ".slice":                         // old presets format
                case ".ini":
                    var    settingsToImport = PrinterSettingsLayer.LoadFromIni(settingsFilePath);
                    string layerHeight;

                    bool isSlic3r = settingsToImport.TryGetValue(SettingsKey.layer_height, out layerHeight);
                    if (isSlic3r)
                    {
                        var activeSettings = ActiveSliceSettings.Instance;

                        foreach (var item in settingsToImport)
                        {
                            // Compare the value to import to the layer cascade value and only set if different
                            string currentValue = activeSettings.GetValue(item.Key, null).Trim();
                            if (currentValue != item.Value)
                            {
                                activeSettings.UserLayer[item.Key] = item.Value;
                            }
                        }

                        activeSettings.SaveChanges();

                        UiThread.RunOnIdle(ApplicationController.Instance.ReloadAdvancedControlsPanel);
                    }
                    else
                    {
                        // looks like a cura file
                        throw new NotImplementedException("need to import from 'cure.ini' files");
                    }
                    WizardWindow.Close();
                    break;

                default:
                    WizardWindow.Close();
                    // Did not figure out what this file is, let the user know we don't understand it
                    StyledMessageBox.ShowMessageBox(null, "Oops! Unable to recognize settings file '{0}'.".Localize().FormatWith(Path.GetFileName(settingsFilePath)), "Unable to Import".Localize());
                    break;
                }
            }
            Invalidate();
        }
コード例 #4
0
        private void ImportSettingsFile(string settingsFilePath)
        {
            WizardWindow.Close();

            switch (importMode)
            {
            case "new":
                ActiveSliceSettings.ImportFromExisting(settingsFilePath);
                break;

            case "merge":
            case "replace":
                ReplaceOrMergeSettings(settingsFilePath);
                break;
            }
        }
コード例 #5
0
        private void exportButton_Click()
        {
            WizardWindow.Close();

            if (matterControlButton.Checked)
            {
                ActiveSliceSettings.Instance.Helpers.ExportAsMatterControlConfig();
            }
            else if (slic3rButton.Checked)
            {
                ActiveSliceSettings.Instance.Helpers.ExportAsSlic3rConfig();
            }
            else if (curaButton.Checked)
            {
                ActiveSliceSettings.Instance.Helpers.ExportAsCuraConfig();
            }
        }
コード例 #6
0
        private void exportButton_Click()
        {
            WizardWindow.Close();

            switch (exportMode)
            {
            case "slic3r":
                ActiveSliceSettings.Instance.ExportAsSlic3rConfig();
                break;

            case "cura":
                ActiveSliceSettings.Instance.ExportAsCuraConfig();
                break;

            case "mattercontrol":
                ActiveSliceSettings.Instance.ExportAsMatterControlConfig();
                break;
            }
        }
コード例 #7
0
        public CopyGuestProfilesToUser()
            : base("Close", "Copy Printers to Account")
        {
            var scrollWindow = new ScrollableWidget()
            {
                AutoScroll = true,
                HAnchor    = HAnchor.ParentLeftRight,
                VAnchor    = VAnchor.ParentBottomTop,
            };

            scrollWindow.ScrollArea.HAnchor = HAnchor.ParentLeftRight;
            contentRow.AddChild(scrollWindow);

            var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.ParentLeftRight,
            };

            scrollWindow.AddChild(container);

            container.AddChild(new WrappedTextWidget(importMessage, textColor: ActiveTheme.Instance.PrimaryTextColor));

            var byCheckbox = new Dictionary <CheckBox, PrinterInfo>();

            var guest = ProfileManager.Load("guest");

            if (guest?.Profiles.Count > 0)
            {
                container.AddChild(new TextWidget("Printers to Copy:".Localize())
                {
                    TextColor = ActiveTheme.Instance.PrimaryTextColor,
                    Margin    = new BorderDouble(0, 3, 0, 15),
                });

                foreach (var printerInfo in guest.Profiles)
                {
                    var checkBox = new CheckBox(printerInfo.Name)
                    {
                        TextColor = ActiveTheme.Instance.PrimaryTextColor,
                        Margin    = new BorderDouble(5, 0, 0, 0),
                        HAnchor   = HAnchor.ParentLeft,
                        Checked   = true,
                    };
                    checkBoxes.Add(checkBox);
                    container.AddChild(checkBox);

                    byCheckbox[checkBox] = printerInfo;
                }
            }

            var syncButton = textImageButtonFactory.Generate("Copy".Localize());

            syncButton.Name   = "CopyProfilesButton";
            syncButton.Click += (s, e) =>
            {
                // do the import
                foreach (var checkBox in checkBoxes)
                {
                    if (checkBox.Checked)
                    {
                        // import the printer
                        var printerInfo = byCheckbox[checkBox];

                        string existingPath = guest.ProfilePath(printerInfo);

                        // PrinterSettings files must actually be copied to the users profile directory
                        if (File.Exists(existingPath))
                        {
                            File.Copy(existingPath, printerInfo.ProfilePath);

                            // Only add if copy succeeds
                            ProfileManager.Instance.Profiles.Add(printerInfo);
                        }
                    }
                }

                guest.Save();

                // Close the window and update the PrintersImported flag
                UiThread.RunOnIdle(() =>
                {
                    WizardWindow.Close();

                    ProfileManager.Instance.PrintersImported = true;
                    ProfileManager.Instance.Save();
                });
            };

            CheckBox rememberChoice = new CheckBox("Don't remind me again".Localize(), ActiveTheme.Instance.PrimaryTextColor);

            contentRow.AddChild(rememberChoice);

            syncButton.Visible   = true;
            cancelButton.Visible = true;

            // Close the window and update the PrintersImported flag
            cancelButton.Click += (s, e) => UiThread.RunOnIdle(() =>
            {
                WizardWindow.Close();
                if (rememberChoice.Checked)
                {
                    ProfileManager.Instance.PrintersImported = true;
                    ProfileManager.Instance.Save();
                }
            });

            //Add buttons to buttonContainer
            footerRow.AddChild(syncButton);
            footerRow.AddChild(new HorizontalSpacer());
            footerRow.AddChild(cancelButton);

            footerRow.Visible = true;
        }
コード例 #8
0
ファイル: WizardPage.cs プロジェクト: IceForgTW/MatterControl
        public WizardPage(string unlocalizedTextForCancelButton = "Cancel", string unlocalizedTextForTitle = "Setup Wizard")
        {
            whiteImageButtonFactory = new TextImageButtonFactory()
            {
                normalFillColor   = RGBA_Bytes.White,
                disabledFillColor = RGBA_Bytes.White,
                fontSize          = 16,
                borderWidth       = 1,

                normalBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200),
                hoverBorderColor  = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200),

                disabledTextColor = RGBA_Bytes.DarkGray,
                hoverTextColor    = ActiveTheme.Instance.PrimaryTextColor,
                normalTextColor   = RGBA_Bytes.Black,
                pressedTextColor  = ActiveTheme.Instance.PrimaryTextColor,
                FixedWidth        = 200
            };

            if (!UserSettings.Instance.IsTouchScreen)
            {
                textImageButtonFactory = new TextImageButtonFactory()
                {
                    normalTextColor   = ActiveTheme.Instance.PrimaryTextColor,
                    hoverTextColor    = ActiveTheme.Instance.PrimaryTextColor,
                    disabledTextColor = ActiveTheme.Instance.PrimaryTextColor,
                    pressedTextColor  = ActiveTheme.Instance.PrimaryTextColor,
                    borderWidth       = 0
                };

                linkButtonFactory.textColor = ActiveTheme.Instance.PrimaryTextColor;
                linkButtonFactory.fontSize  = 10;

                this.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
                this.Padding         = new BorderDouble(0);         //To be re-enabled once native borders are turned off
            }

            this.AnchorAll();

            cancelButton        = textImageButtonFactory.Generate(unlocalizedTextForCancelButton.Localize());
            cancelButton.Name   = unlocalizedTextForCancelButton;
            cancelButton.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() => WizardWindow?.Close());
            };

            // Create the main container
            mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                Padding         = new BorderDouble(12, 12, 12, 0),
                BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor
            };
            mainContainer.AnchorAll();

            // Create the header row for the widget
            headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                Margin  = new BorderDouble(0, 3, 0, 0),
                Padding = new BorderDouble(0, 12),
                HAnchor = HAnchor.ParentLeftRight
            };

            headerLabel = new TextWidget(unlocalizedTextForTitle.Localize(), pointSize: 24, textColor: ActiveTheme.Instance.SecondaryAccentColor)
            {
                AutoExpandBoundsToText = true
            };
            headerRow.AddChild(headerLabel);

            // Create the main control container
            contentRow = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                Padding         = new BorderDouble(10),
                BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor,
                HAnchor         = HAnchor.ParentLeftRight,
                VAnchor         = VAnchor.ParentBottomTop
            };

            // Create the footer (button) container
            footerRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                HAnchor = HAnchor.ParentLeft | HAnchor.ParentRight,
                Margin  = new BorderDouble(0, 6)
            };

            mainContainer.AddChild(headerRow);
            mainContainer.AddChild(contentRow);
            mainContainer.AddChild(footerRow);

            if (!UserSettings.Instance.IsTouchScreen)
            {
                mainContainer.Padding = new BorderDouble(3, 5, 3, 5);
                headerRow.Padding     = new BorderDouble(0, 3, 0, 3);

                headerLabel.PointSize = 14;
                headerLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                contentRow.Padding    = new BorderDouble(5);
                footerRow.Margin      = new BorderDouble(0, 3);
            }

            this.AddChild(mainContainer);
        }
コード例 #9
0
        public CopyGuestProfilesToUser(Action afterProfilesImported)
            : base("Cancel", "Select Printers to Sync")
        {
            var scrollWindow = new ScrollableWidget()
            {
                AutoScroll = true,
                HAnchor    = HAnchor.ParentLeftRight,
                VAnchor    = VAnchor.ParentBottomTop,
            };

            scrollWindow.ScrollArea.HAnchor = HAnchor.ParentLeftRight;
            contentRow.AddChild(scrollWindow);

            var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.ParentLeftRight,
            };

            scrollWindow.AddChild(container);

            container.AddChild(new WrappedTextWidget(importMessage, textColor: ActiveTheme.Instance.PrimaryTextColor));

            var byCheckbox = new Dictionary <CheckBox, PrinterInfo>();

            var guestProfileManager = ProfileManager.LoadGuestDB();

            if (guestProfileManager?.Profiles.Count > 0)
            {
                container.AddChild(new TextWidget("Printers to Sync:".Localize())
                {
                    TextColor = ActiveTheme.Instance.PrimaryTextColor,
                    Margin    = new BorderDouble(0, 3, 0, 15),
                });

                foreach (var printerInfo in guestProfileManager.Profiles)
                {
                    var checkBox = new CheckBox(printerInfo.Name)
                    {
                        TextColor = ActiveTheme.Instance.PrimaryTextColor,
                        Margin    = new BorderDouble(5, 0, 0, 0),
                        HAnchor   = HAnchor.ParentLeft,
                        Checked   = true,
                    };
                    checkBoxes.Add(checkBox);
                    container.AddChild(checkBox);

                    byCheckbox[checkBox] = printerInfo;
                }
            }

            var syncButton = textImageButtonFactory.Generate("Sync".Localize());

            syncButton.Click += (s, e) =>
            {
                // do the import
                foreach (var checkBox in checkBoxes)
                {
                    if (checkBox.Checked)
                    {
                        // import the printer
                        var printerInfo = byCheckbox[checkBox];

                        ProfileManager.Instance.Profiles.Add(printerInfo);
                        guestProfileManager.Profiles.Remove(printerInfo);
                    }
                }

                guestProfileManager.Save();

                // close the window
                UiThread.RunOnIdle(() =>
                {
                    WizardWindow.Close();

                    // Call back into the original source
                    afterProfilesImported();
                });
            };

            syncButton.Visible   = true;
            cancelButton.Visible = true;

            cancelButton.Click += (s, e) => UiThread.RunOnIdle(WizardWindow.Close);

            //Add buttons to buttonContainer
            footerRow.AddChild(syncButton);
            footerRow.AddChild(new HorizontalSpacer());
            footerRow.AddChild(cancelButton);

            footerRow.Visible = true;
        }