Chandra X-Ray Observatory
	(CXC)
Skip to the navigation links
Last modified: November 2016

URL: http://cxc.harvard.edu/chips/ahelp/print_window.html
AHELP for CIAO 4.9 ChIPS v1

print_window

Context: windows

Synopsis

Prints the window to a file or the printer.

Syntax

print_window([id])
print_window([id,] filename)
print_window([id,] filename, attributes)
print_window([id,] attributes)

Description

The function arguments.

Argument Description
id A ChipsId structure identifying the item.
filename If a recognized suffix is included in the filename - namely ".ps", ".eps", ".pdf", ".png", ".jpg", or ".jpeg" - then the corresponding format will be used, otherwise the format attribute will be used.
attributes Configure object properties by giving an attribute string (a space-separated list of key=value pairs), list, dictionary, or a ChIPS object.

The print_window command prints the contents of the window to either a file or the printer. If "filename" is specified, the image is written to a file. If it is not specified, the output is sent to the user's default printer.

Output format

ChIPS can create output in a variety of formats: postscript, encapsulated postscript, PDF, PNG, and JPEG. There are three ways to specify the output format:

  • Including the format as a suffix on the filename: for example "plot.ps", "plot.eps", "plot.pdf", "plot.png", "plot.jpg", or "plot.jpeg".
  • Setting the "format" attribute when you call print_window().
  • Setting the "export.format" preference before you call print_window().

The list above is given in the order that the format is checked for, so

chips> print_window("plot.ps", ["format", "eps"])

will create a postscript format file called "plot.ps", and not an encapsulated format file.

If a filename is given with a suffix that is not recognized, then the output format will be taken from either the format attribute or the export.format preference setting.

The print_window GUI

If the preference "export.printdialog" is set to true, ChIPS will open a printing dialog box when print_window is called. The dialog allows you to decide whether to send the figure to the printer or to a file, and allows you to set all the printing options available in the print_window command (e.g. output format, color scheme, page margins). Unless a filename (with optional path) is specified in the print_window call, the working directory is used as the default location.

chips> print_window("plot.png", ["printdialog", True])

will create a GUI for selecting the export options, with the filename set to plot.png in the current working directory and the format set to PNG (both can be changed from GUI).

chips> print_window(["printdialog", True])

will use a default file name of "untitled1" (or higher if "untitled1" already exists), which can be changed from the GUI.

Setting margins and the output page size

The margins can be specified individually, along with the page orientation (portrait or landscape), the color scheme (e.g. rbg, cmyk), and the file format (e.g. postscript, jpg). A number of standard page sizes are available (e.g. letter, legal).

The size and aspect ratio of the output matches the dimensions of the window. This can be overridden using the pagewidth and pageheight attributes or the pagesize attributes, but only for the postscript and PDF file formats.

The scalewidth and scaleheight attributes scale the image with regard to the print area - either the window dimensions or the pagewidth/pageheight specification. If the image is scaled such that it's larger than the page and "keepaspect" is set to false, the image is clipped. If "keepaspect" is "true", the scaled image maintains the original aspect ratio and is scaled up until one dimension touches the margins.

The units for the margins, width, and height are determined by the "window.units" preference, unless overridden by the pageunits attribute.

Please see the section "Export Preferences" below the examples for a list of the export preferences.

Example 1

chips> print_window()

The contents of the current window are sent to the default printer.

Example 2

chips> print_window(["printdialog", True])

Print the contens of the current window using the print GUI to change the settings such as format type and output file name.

Example 3

chips> print_window("plot")

A postscript version of the current window is created in the file plot.ps.

Example 4

chips> print_window("plot", ["pagesize","letter","fittopage",True])
chips> print_window("plot.png")

A postscript version of the current window is created in the file plot.ps; it has been re-sized to fill a US letter page. The second call to print_window creates a PNG format of the window in the file plot.png; the size of this file is determined by the size of the window being printed, since the pagesize, pagewidth, and fittopage options are only valid for the postscript and PDF outputs.

Example 5

chips> opts = { "clobber": True, "fittopage": True }
chips> opts['pagesize'] = 'letter'
chips> print_window("example.pdf", opts)

Here we use a dictionary, rather than list, to specify the options. The output will be called example.pdf and will overwrite any existing file with that name, since clobber has been set to True.

Example 6

chips> add_window("id=FirstWindow")
...
chips> add_window("id=Window2")
...
chips> id = ChipsId()
chips> id.window = "FirstWindow"
chips> print_window(id)

Two windows are created; the second window is current after it is created. The id.window command sets the window value of the ChipsId structure to the first window, which is then sent directly to the user's default printer.

Example 7

chips> add_window("id=MyWindow1")
...
chips> add_window()
...
chips> print_window("plot1.eps")

Two windows are created; the second window is current after it is created. That window is then printed to an EPS file named "plot1.eps".

Example 8

chips> x = np.arange(-5, 5, 0.1)
chips> y = np.sin(x)
chips> add_window(["id", "ns", "smoothing", False])
chips> add_window(["id", "sm", "smoothing", True])
chips> current_window("all")
chips> add_curve(x, y, ["symbol.style", "none"])
chips> current_window("ns")
chips> print_window("nosmooth.png")
chips> print_window("nosmooth.ps")
chips> current_window("sm")
chips> print_window("smooth.png")
chips> print_window("smooth.ps")

The same plot is created with the window.smoothing attribute set to False and then True. This affects the display both on-screen and in the bitmap outputs created by print_window().

Export Preferences

The attributes associated with export are given in the following table. All values can be changed using the print_window() command. To change the export preference settings prepend "export." to the attribute name.

Attribute Description Options Default
bottommargin size of the bottom margin numerical value, with the units taken from the window.units or pageunits setting. 0.2
clobber Overwrite an existing file? see the Booleans section of "ahelp chipsopt" false
colorscheme indicates the color specification scheme rgb|cmyk|cmyksep|greyscale|grayscale rgb
dpi What resolution should be used when displaying images, in dots per inch. Non-negative integer 150
fittopage Fits the image to the page size; aspect ratio is controlled by the "keepaspect" attribute see the Booleans section of "ahelp chipsopt" false
fonts should the font be written to the printer, if the image is going to the printer see the Booleans section of "ahelp chipsopt" true
format (only used if not included as part of the file name) export file format ps|eps|pdf|png|jpg|jpeg ps
keepaspect Maintain aspect ratio of the image while fitting to the page? see the Booleans section of "ahelp chipsopt" true
leftmargin size of the left margin numerical value, with the units taken from the window.units or pageunits setting. 0.2
orientation page layout orientation landscape|portrait portrait
pageheight height of the saved file image (PS and PDF formats only). This value overrides the window dimensions, and the units are taken from the window.units setting unless overridden by export.pageunits numerical value 0.0
pagesize print size (PS and PDF formats only) letter|legal|executive|A3|A4|A5 letter
pageunits Units of measure of the pagesize (PS and PDF formats only) inches|cm|mm|pixels inches
pagewidth width of the saved file image (PS and PDF formats only). This value overrides the window dimensions, and the units taken from the window.units setting unless overridden by export.pageunits numerical value 0.0
printdialog if true, ChIPS will open a GUI for selecting the export option when print_window is called see the Booleans section of "ahelp chipsopt" false
printmethod This setting is to support users with ATI Gallium display drivers who see displays being flipped by print_window. In this case, change the preference to xoffscreen. One of framebuffer, xoffscreen, or none. framebuffer
rightmargin size of the right margin numerical value, with the units taken from the window.units or pageunits setting. 0.2
scaleheight Factor for scaling the height value Floating point percentage value 0.0
scalewidth Factor for scaling the width value Floating point percentage value 0.0
topmargin size of the top margin numerical value, with the units taken from the window.units or pageunits setting. 0.2

Flipped plots

If print_window creates flipped plots and you have an ATI Gallium display driver, change the export.printmethod from its default value of framebuffer to xoffscreen; e.g.

chips> set_preference("export.printmethod", "xoffscreen")

or change the value in your ~/.chipsrc file.

Bugs

See the bugs pages on the ChIPS website for an up-to-date listing of known bugs.

See Also

utilities
clear
windows
add_window, current_window, deiconify_window, delete_window, get_window, iconify_window, set_window

Last modified: November 2016
Smithsonian Institute Smithsonian Institute

The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory. 60 Garden Street, Cambridge, MA 02138 USA.   Email:   cxchelp@head.cfa.harvard.edu Smithsonian Institution, Copyright © 1998-2017. All rights reserved.