Using the printer prompter
The CwPrinterPrompter allows users to select a printer. The user can configure job attributes for a printer by using a platform- and printer-specific setup dialog. Print job attributes for the selected printer can be retrieved by sending jobAttributes to the CwPrinterPrompter after a printer has been selected. A CwPrinterPrompter from the OS/2 platform is shown in the following diagram.
A printer prompter returns the display name of the selected printer, or nil if no printer is selected. The prompter also returns nil if no printers are available.
The display name returned by the prompter is used to open a connection to the desired printer display by sending openDisplay:; to CwAppContext default. A printer shell can then be created by sending appCreateShell:applicationClass:display:argBlock:; to the CwPrinterShell class.
When a printer prompter returns successfully (the value is not nil), its jobAttributes method answers that with a CgPrintJobAttributes compatible with the selected printer. The job attributes should be used when creating a printer shell by specifying the jobAttributes: resource message in the create argBlock for the shell.
The following sample code shows typical printer prompter use, including opening the selected display, retrieving selected job attributes, and creating a printer shell.
| prompter displayName display jobAttributes printerShell |
prompter := CwPrinterPrompter new.
(displayName := prompter prompt) isNil
ifTrue: [^System message: 'A printer was not selected.'].
(display := CwAppContext default openDisplay: displayName) isNil
ifTrue: [^self error: 'Cannot connect to selected printer.'].
jobAttributes := prompter jobAttributes.
printerShell := CwPrinterShell
appCreateShell: 'print job'
applicationClass: nil
display: display
argBlock: [:w | w jobAttributes: jobAttributes].
Last modified date: 12/21/2017