static void PrintMain() { var dispatcher = Dispatcher.CurrentDispatcher; var context = new DispatcherSynchronizationContext(dispatcher); SynchronizationContext.SetSynchronizationContext(context); var printerSelector = PrinterSelector <IAsyncPrinter> .FromLocalServer <IAsyncPrinter>( q => new AsyncPrinter(q) ); var printingController = new PrintingController(printerSelector); var mainWindow = new PrintingControllerWindow() { DataContext = printingController }; mainWindow.Closed += (sender, e) => { printerSelector.Dispose(); dispatcher.InvokeShutdown(); }; mainWindow.Show(); Dispatcher.Run(); }
public PrinterSelectorDialogViewModel() { printingProvider = Main.PrintingProvider; PrinterSelector = printingProvider.PrinterSelector; SelectedPrinterIndex = PrinterSelector.ObserveProperty(p => p.SelectedPrinter) .Select(x => PrinterSelector.Printers.IndexOf(x)).ToReactiveProperty(); PaperSizes = PrintingProvider.PaperSizes; PaperOrientations = PrintingProvider.PaperOrientations; PaperSizeIndex = printingProvider.ObserveProperty(p => p.PaperSize) .Select(x => PrintingProvider.PaperSizes.IndexOf(x)).ToReactiveProperty(); PaperOrientationIndex = printingProvider.ObserveProperty(p => p.PaperOrientation) .Select(x => PrintingProvider.PaperOrientations.IndexOf(x)).ToReactiveProperty(); PaperSizeIndex.ObserveProperty(x => x.Value) .Subscribe(i => printingProvider.PaperSize = PrintingProvider.PaperSizes[i]); PaperOrientationIndex.ObserveProperty(x => x.Value).Subscribe(i => printingProvider.PaperOrientation = PrintingProvider.PaperOrientations[i]); PrintCommand = new ReactiveCommand(); PrintCommand.Subscribe(Print); CancelCommand = new ReactiveCommand(); CancelCommand.Subscribe(() => IsShowDialog = false); ShowDialogCommand = new ReactiveCommand(); ShowDialogCommand.Subscribe(() => IsShowDialog = true); }
PrintPreviewer( TPrintable printable, Func <TPrintable, Size, IEnumerable> paginate, PrinterSelector <IPrinter> printerSelector ) { this.printable = printable; this.paginate = paginate; PrinterSelector = printerSelector; PreviewCommand = new DelegateCommand(UpdatePreview); PrintCommand = new DelegateCommand(Print); }
public PrintingController(PrinterSelector <IAsyncPrinter> printerSelector) { PrinterSelector = printerSelector; CancelCommand = new DelegateCommand( () => { var cts = CurrentCts; if (cts != null) { CurrentCts = null; cts.Cancel(); } }, () => CurrentCts != null ); PrintCommand = new DelegateCommand( async() => { var printable = new OrderFormPage(); var pageSize = new Size(793.7, 1122.52); var printer = PrinterSelector.SelectedPrinterOrNull; if (printer == null) { return; } var cts = new CancellationTokenSource(); CurrentCts = cts; try { var paginator = new DataGridPrintablePaginator <Order>(); var pages = paginator.Paginate(printable, pageSize); await printer.PrintAsync(pages, pageSize, cts.Token); } finally { CurrentCts = null; } }, () => CurrentCts == null ); }
public SampleControl() { InitializeComponent(); var previewer = new PrintPreviewer <OrderFormPage>( new OrderFormPage(), new DataGridPrintablePaginator <Order>().Paginate, PrinterSelector <IPrinter> .FromLocalServer <IPrinter>(q => new Printer(q)) ); DataContext = previewer; Loaded += (sender, e) => { previewer.UpdatePreview(); }; }
protected void AddChildElements() { actionBarButtonFactory.invertImageLocation = false; actionBarButtonFactory.borderWidth = 1; if (ActiveTheme.Instance.IsDarkTheme) { actionBarButtonFactory.normalBorderColor = new RGBA_Bytes(77, 77, 77); } else { actionBarButtonFactory.normalBorderColor = new RGBA_Bytes(190, 190, 190); } actionBarButtonFactory.hoverBorderColor = new RGBA_Bytes(128, 128, 128); // connect and disconnect buttons { connectPrinterButton = actionBarButtonFactory.Generate("Connect".Localize().ToUpper(), "icon_power_32x32.png"); connectPrinterButton.Name = "Connect to printer button"; connectPrinterButton.ToolTipText = "Connect to the currently selected printer".Localize(); connectPrinterButton.Margin = new BorderDouble(6, 0, 3, 3); connectPrinterButton.VAnchor = VAnchor.ParentTop; connectPrinterButton.Cursor = Cursors.Hand; connectPrinterButton.Click += (s, e) => { Button buttonClicked = ((Button)s); if (buttonClicked.Enabled) { if (ActiveSliceSettings.Instance.PrinterSelected) { UserRequestedConnectToActivePrinter(); } } }; disconnectPrinterButton = actionBarButtonFactory.Generate("Disconnect".Localize().ToUpper(), "icon_power_32x32.png"); disconnectPrinterButton.Name = "Disconnect from printer button"; disconnectPrinterButton.ToolTipText = "Disconnect from current printer".Localize(); disconnectPrinterButton.Margin = new BorderDouble(6, 0, 3, 3); disconnectPrinterButton.VAnchor = VAnchor.ParentTop; disconnectPrinterButton.Cursor = Cursors.Hand; disconnectPrinterButton.Click += (s, e) => UiThread.RunOnIdle(OnIdleDisconnect); actionBarButtonFactory.invertImageLocation = true; this.AddChild(connectPrinterButton); this.AddChild(disconnectPrinterButton); } // printer selector and edit button { GuiWidget container = new GuiWidget() { HAnchor = HAnchor.ParentLeftRight, VAnchor = VAnchor.FitToChildren, }; FlowLayoutWidget printerSelectorAndEditButton = new FlowLayoutWidget() { HAnchor = HAnchor.ParentLeftRight, }; printerSelector = new PrinterSelector() { HAnchor = HAnchor.ParentLeftRight, Cursor = Cursors.Hand, Margin = new BorderDouble(0, 6, 0, 3) }; printerSelector.AddPrinter += (s, e) => WizardWindow.ShowPrinterSetup(true); // make sure the control can get smaller but maintains its height printerSelector.MinimumSize = new Vector2(0, connectPrinterButton.MinimumSize.y); printerSelectorAndEditButton.AddChild(printerSelector); editPrinterButton = TextImageButtonFactory.GetThemedEditButton(); editPrinterButton.Name = "Edit Printer Button"; editPrinterButton.VAnchor = VAnchor.ParentCenter; editPrinterButton.Click += UiNavigation.OpenEditPrinterWizard_Click; printerSelectorAndEditButton.AddChild(editPrinterButton); container.AddChild(printerSelectorAndEditButton); printerSelectorAndEditOverlay = new GuiWidget() { HAnchor = HAnchor.ParentLeftRight, VAnchor = VAnchor.ParentBottomTop, Selectable = false, }; container.AddChild(printerSelectorAndEditOverlay); this.AddChild(container); } // reset connection button { string resetConnectionText = "Reset\nConnection".Localize().ToUpper(); Button resetConnectionButton = actionBarButtonFactory.Generate(resetConnectionText, "e_stop4.png"); resetConnectionButton.Margin = new BorderDouble(6, 0, 3, 3); this.AddChild(resetConnectionButton); resetConnectionButton.Click += new EventHandler((s,e) => PrinterConnectionAndCommunication.Instance.RebootBoard()); resetConnectionButton.Visible = ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.show_reset_connection); ActiveSliceSettings.SettingChanged.RegisterEvent((sender, e) => { StringEventArgs stringEvent = e as StringEventArgs; if (stringEvent != null) { if (stringEvent.Data == SettingsKey.show_reset_connection) { resetConnectionButton.Visible = ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.show_reset_connection); } } }, ref unregisterEvents); } // Bind connect button states to active printer state this.SetConnectionButtonVisibleState(); PrinterConnectionAndCommunication.Instance.EnableChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents); PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents); }
protected void AddChildElements() { actionBarButtonFactory.invertImageLocation = false; actionBarButtonFactory.borderWidth = 1; if (ActiveTheme.Instance.IsDarkTheme) { actionBarButtonFactory.normalBorderColor = new RGBA_Bytes(77, 77, 77); } else { actionBarButtonFactory.normalBorderColor = new RGBA_Bytes(190, 190, 190); } actionBarButtonFactory.hoverBorderColor = new RGBA_Bytes(128, 128, 128); // connect and disconnect buttons { connectPrinterButton = actionBarButtonFactory.Generate("Connect".Localize().ToUpper(), "icon_power_32x32.png"); connectPrinterButton.Name = "Connect to printer button"; connectPrinterButton.ToolTipText = "Connect to the currently selected printer".Localize(); connectPrinterButton.Margin = new BorderDouble(6, 0, 3, 3); connectPrinterButton.VAnchor = VAnchor.ParentTop; connectPrinterButton.Cursor = Cursors.Hand; connectPrinterButton.Click += (s, e) => { Button buttonClicked = ((Button)s); if (buttonClicked.Enabled) { if (ActiveSliceSettings.Instance.PrinterSelected) { UserRequestedConnectToActivePrinter(); } } }; disconnectPrinterButton = actionBarButtonFactory.Generate("Disconnect".Localize().ToUpper(), "icon_power_32x32.png"); disconnectPrinterButton.ToolTipText = "Disconnect from current printer".Localize(); disconnectPrinterButton.Margin = new BorderDouble(6, 0, 3, 3); disconnectPrinterButton.VAnchor = VAnchor.ParentTop; disconnectPrinterButton.Cursor = Cursors.Hand; disconnectPrinterButton.Click += (s, e) => UiThread.RunOnIdle(OnIdleDisconnect); actionBarButtonFactory.invertImageLocation = true; this.AddChild(connectPrinterButton); this.AddChild(disconnectPrinterButton); } // printer selector and edit button { GuiWidget container = new GuiWidget() { HAnchor = HAnchor.ParentLeftRight, VAnchor = VAnchor.FitToChildren, }; FlowLayoutWidget printerSelectorAndEditButton = new FlowLayoutWidget() { HAnchor = HAnchor.ParentLeftRight, }; printerSelector = new PrinterSelector() { HAnchor = HAnchor.ParentLeftRight, Cursor = Cursors.Hand, Margin = new BorderDouble(0, 6, 0, 3) }; printerSelector.AddPrinter += (s, e) => WizardWindow.ShowPrinterSetup(true); // make sure the control can get smaller but maintains its height printerSelector.MinimumSize = new Vector2(0, connectPrinterButton.MinimumSize.y); printerSelectorAndEditButton.AddChild(printerSelector); editPrinterButton = TextImageButtonFactory.GetThemedEditButton(); editPrinterButton.Name = "Edit Printer Button"; editPrinterButton.VAnchor = VAnchor.ParentCenter; editPrinterButton.Click += UiNavigation.OpenEditPrinterWizard_Click; printerSelectorAndEditButton.AddChild(editPrinterButton); container.AddChild(printerSelectorAndEditButton); printerSelectorAndEditOverlay = new GuiWidget() { HAnchor = HAnchor.ParentLeftRight, VAnchor = VAnchor.ParentBottomTop, Selectable = false, }; container.AddChild(printerSelectorAndEditOverlay); this.AddChild(container); } // reset connection button { string resetConnectionText = "Reset\nConnection".Localize().ToUpper(); Button resetConnectionButton = actionBarButtonFactory.Generate(resetConnectionText, "e_stop4.png"); resetConnectionButton.Margin = new BorderDouble(6, 0, 3, 3); this.AddChild(resetConnectionButton); resetConnectionButton.Click += new EventHandler((s, e) => PrinterConnectionAndCommunication.Instance.RebootBoard()); resetConnectionButton.Visible = ActiveSliceSettings.Instance.GetValue <bool>(SettingsKey.show_reset_connection); SliceSettingsWidget.SettingChanged.RegisterEvent((sender, e) => { StringEventArgs stringEvent = e as StringEventArgs; if (stringEvent != null) { if (stringEvent.Data == SettingsKey.show_reset_connection) { resetConnectionButton.Visible = ActiveSliceSettings.Instance.GetValue <bool>(SettingsKey.show_reset_connection); } } }, ref unregisterEvents); } // Bind connect button states to active printer state this.SetConnectionButtonVisibleState(); ActiveSliceSettings.ActivePrinterChanged.RegisterEvent(onActivePrinterChanged, ref unregisterEvents); PrinterConnectionAndCommunication.Instance.EnableChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents); PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents); }
public PrinterBar(PartPreviewContent partPreviewContent, PrinterInfo printerInfo, ThemeConfig theme) : base(printerInfo?.Name ?? "", theme) { headingBar.CloseAllChildren(); headingBar.AddChild(printerSelector = new PrinterSelector(theme) { VAnchor = VAnchor.Fit, HAnchor = HAnchor.Absolute, Border = 0, MinimumSize = Vector2.Zero, Width = 200, BackgroundColor = theme.MinimalShade }); printerSelector.SelectionChanged += (s, e) => { this.RebuildPlateOptions(partPreviewContent, theme); }; var forcedHeight = printerSelector.Height; // add in the create printer button var createPrinter = new IconButton(AggContext.StaticData.LoadIcon("md-add-circle_18.png", 18, 18, theme.InvertIcons), theme) { Name = "Create Printer", VAnchor = VAnchor.Center, Margin = theme.ButtonSpacing.Clone(left: theme.ButtonSpacing.Right), ToolTipText = "Create Printer".Localize(), Height = forcedHeight, Width = forcedHeight }; createPrinter.Click += (s, e) => { UiThread.RunOnIdle(() => { //simpleTabs.RemoveTab(simpleTabs.ActiveTab); if (ApplicationController.Instance.ActivePrinter.Connection.PrinterIsPrinting || ApplicationController.Instance.ActivePrinter.Connection.PrinterIsPaused) { StyledMessageBox.ShowMessageBox("Please wait until the print has finished and try again.".Localize(), "Can't add printers while printing".Localize()); } else { DialogWindow.Show(PrinterSetup.GetBestStartPage(PrinterSetup.StartPageOptions.ShowMakeModel)); } }); }; headingBar.AddChild(createPrinter); // add in the import printer button var importPrinter = new IconButton(AggContext.StaticData.LoadIcon("md-import_18.png", 18, 18, theme.InvertIcons), theme) { VAnchor = VAnchor.Center, Margin = theme.ButtonSpacing, ToolTipText = "Import Printer".Localize(), Height = forcedHeight, Width = forcedHeight }; importPrinter.Click += (s, e) => { UiThread.RunOnIdle(() => { AggContext.FileDialogs.OpenFileDialog( new OpenFileDialogParams( "settings files|*.ini;*.printer;*.slice"), (result) => { if (!string.IsNullOrEmpty(result.FileName) && File.Exists(result.FileName)) { //simpleTabs.RemoveTab(simpleTabs.ActiveTab); if (ProfileManager.ImportFromExisting(result.FileName)) { string importPrinterSuccessMessage = "You have successfully imported a new printer profile. You can find '{0}' in your list of available printers.".Localize(); DialogWindow.Show( new ImportSucceeded( importPrinterSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(result.FileName)))); } else { StyledMessageBox.ShowMessageBox("Oops! Settings file '{0}' did not contain any settings we could import.".Localize().FormatWith(Path.GetFileName(result.FileName)), "Unable to Import".Localize()); } } }); }); }; headingBar.AddChild(importPrinter); this.printerInfo = printerInfo; this.RebuildPlateOptions(partPreviewContent, theme); // Rebuild on change ProfileManager.ProfilesListChanged.RegisterEvent((s, e) => { this.RebuildPlateOptions(partPreviewContent, theme); }, ref unregisterEvents); }
protected override void AddChildElements() { actionBarButtonFactory.invertImageLocation = false; actionBarButtonFactory.borderWidth = 1; if (ActiveTheme.Instance.IsDarkTheme) { actionBarButtonFactory.normalBorderColor = new RGBA_Bytes(77, 77, 77); } else { actionBarButtonFactory.normalBorderColor = new RGBA_Bytes(190, 190, 190); } actionBarButtonFactory.hoverBorderColor = new RGBA_Bytes(128, 128, 128); string connectString = "Connect".Localize().ToUpper(); connectPrinterButton = actionBarButtonFactory.Generate(connectString, "icon_power_32x32.png"); connectPrinterButton.ToolTipText = "Connect to the currently selected printer".Localize(); if (ApplicationController.Instance.WidescreenMode) { connectPrinterButton.Margin = new BorderDouble(0, 0, 3, 3); } else { connectPrinterButton.Margin = new BorderDouble(6, 0, 3, 3); } connectPrinterButton.VAnchor = VAnchor.ParentTop; connectPrinterButton.Cursor = Cursors.Hand; string disconnectString = "Disconnect".Localize().ToUpper(); disconnectPrinterButton = actionBarButtonFactory.Generate(disconnectString, "icon_power_32x32.png"); disconnectPrinterButton.ToolTipText = "Disconnect from current printer".Localize(); if (ApplicationController.Instance.WidescreenMode) { disconnectPrinterButton.Margin = new BorderDouble(0, 0, 3, 3); } else { disconnectPrinterButton.Margin = new BorderDouble(6, 0, 3, 3); } disconnectPrinterButton.VAnchor = VAnchor.ParentTop; disconnectPrinterButton.Cursor = Cursors.Hand; string resetConnectionText = "Reset\nConnection".Localize().ToUpper(); resetConnectionButton = actionBarButtonFactory.Generate(resetConnectionText, "e_stop4.png"); if (ApplicationController.Instance.WidescreenMode) { resetConnectionButton.Margin = new BorderDouble(0, 0, 3, 3); } else { resetConnectionButton.Margin = new BorderDouble(6, 0, 3, 3); } // Bind connect button states to active printer state this.SetConnectionButtonVisibleState(); actionBarButtonFactory.invertImageLocation = true; this.AddChild(connectPrinterButton); this.AddChild(disconnectPrinterButton); FlowLayoutWidget printerSelectorAndEditButton = new FlowLayoutWidget() { HAnchor = HAnchor.ParentLeftRight, }; int rightMarginForWideScreenMode = ApplicationController.Instance.WidescreenMode ? 6 : 0; printerSelector = new PrinterSelector() { HAnchor = HAnchor.ParentLeftRight, Cursor = Cursors.Hand, Margin = new BorderDouble(0, 6, rightMarginForWideScreenMode, 3) }; printerSelector.AddPrinter += (s, e) => WizardWindow.Show(); printerSelector.MinimumSize = new Vector2(printerSelector.MinimumSize.x, connectPrinterButton.MinimumSize.y); printerSelectorAndEditButton.AddChild(printerSelector); Button editButton = TextImageButtonFactory.GetThemedEditButton(); editButton.VAnchor = VAnchor.ParentCenter; editButton.Click += UiNavigation.GoToEditPrinter_Click; printerSelectorAndEditButton.AddChild(editButton); this.AddChild(printerSelectorAndEditButton); this.AddChild(resetConnectionButton); }
public void Dispose() { PrinterSelector.Dispose(); }