1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
<html>
<title>scrap - Pygame Documentation</title>
<body bgcolor=#aaeebb text=#000000 link=#331111 vlink=#331111>
<table cellpadding=0 cellspacing=0 border=0 style='border: 3px solid black;' width='100%'>
<tr>
<td bgcolor='#c2fc20' style='padding: 6px;' align=center valign=center><a href='http://www.pygame.org/'><img src='../pygame_tiny.gif' border=0 width=200 height=60></a><br><b>pygame documentation</b></td>
<td bgcolor='#6aee28' style='border-left: 3px solid black; padding: 6px;' align=center valign=center>
||
<a href=http://www.pygame.org>Pygame Home</a> ||
<a href=../index.html>Help Contents</a> ||
<a href=index.html>Reference Index</a> ||
<br> <br>
<a href="camera.html">Camera</a> ||
<a href="cdrom.html">Cdrom</a> ||
<a href="color.html">Color</a> ||
<a href="cursors.html">Cursors</a> ||
<a href="display.html">Display</a> ||
<a href="draw.html">Draw</a> ||
<a href="event.html">Event</a> ||
<a href="examples.html">Examples</a> ||
<a href="font.html">Font</a> ||
<a href="gfxdraw.html">Gfxdraw</a> ||
<a href="image.html">Image</a> ||
<a href="joystick.html">Joystick</a> ||
<a href="key.html">Key</a> ||
<a href="locals.html">Locals</a> ||
<a href="mask.html">Mask</a> ||
<a href="midi.html">Midi</a> ||
<a href="mixer.html">Mixer</a> ||
<a href="mouse.html">Mouse</a> ||
<a href="movie.html">Movie</a> ||
<a href="music.html">Music</a> ||
<a href="overlay.html">Overlay</a> ||
<a href="pixelarray.html">Pixelarray</a> ||
<a href="pygame.html">Pygame</a> ||
<a href="rect.html">Rect</a> ||
<a href="scrap.html">Scrap</a> ||
<a href="sndarray.html">Sndarray</a> ||
<a href="sprite.html">Sprite</a> ||
<a href="surface.html">Surface</a> ||
<a href="surfarray.html">Surfarray</a> ||
<a href="tests.html">Tests</a> ||
<a href="time.html">Time</a> ||
<a href="transform.html">Transform</a>
</td></tr></table>
<br>
<a name="pygame.scrap">
<big><b>pygame.scrap</big></b><br><ul>
<i>pygame module for clipboard support.</i><br>
<ul><small><table>
<tr><td><a href="scrap.html#pygame.scrap.init">pygame.scrap.init</a> - <font size=-1>Initializes the scrap module.</font></td><td>Initializes the scrap module.</td></tr>
<tr><td><a href="scrap.html#pygame.scrap.get">pygame.scrap.get</a> - <font size=-1>Gets the data for the specified type from the clipboard.</font></td><td>Gets the data for the specified type from the clipboard.</td></tr>
<tr><td><a href="scrap.html#pygame.scrap.get_types">pygame.scrap.get_types</a> - <font size=-1>Gets a list of the available clipboard types.</font></td><td>Gets a list of the available clipboard types.</td></tr>
<tr><td><a href="scrap.html#pygame.scrap.put">pygame.scrap.put</a> - <font size=-1>Places data into the clipboard.</font></td><td>Places data into the clipboard.</td></tr>
<tr><td><a href="scrap.html#pygame.scrap.contains">pygame.scrap.contains</a> - <font size=-1>Checks, whether a certain type is available in the clipboard.</font></td><td>Checks, whether a certain type is available in the clipboard.</td></tr>
<tr><td><a href="scrap.html#pygame.scrap.lost">pygame.scrap.lost</a> - <font size=-1>Checks whether the clipboard is currently owned by the application.</font></td><td>Checks whether the clipboard is currently owned by the application.</td></tr>
<tr><td><a href="scrap.html#pygame.scrap.set_mode">pygame.scrap.set_mode</a> - <font size=-1>Sets the clipboard access mode.</font></td><td>Sets the clipboard access mode.</td></tr>
</table></small></ul>
<p><tt>EXPERIMENTAL!:</tt> meaning this api may change, or dissapear in later pygame releases. If you use this, your code will break with the next pygame release. </p>
<p>The scrap module is for getting and putting stuff from the clipboard. So you can copy and paste things between pygame, and other application types. It defines some basic own data types </p>
<pre> SCRAP_PPM
SCRAP_PBM
SCRAP_BMP
SCRAP_TEXT
</pre><p>to be placed into the clipboard and allows to use define own clipboard types. <tt>SCRAP_PPM</tt>, <tt>SCRAP_PBM</tt> and <tt>SCRAP_BMP</tt> are suitable for surface buffers to be shared with other applications, while <tt>SCRAP_TEXT</tt> is an alias for the plain text clipboard type. </p>
<p>The <tt>SCRAP_*</tt> types refer to the following <tt>MIME</tt> types and register those as well as the default operating system type for this type of data: </p>
<pre> SCRAP_TEXT text/plain for plain text
SCRAP_PBM image/pbm for PBM encoded image data
SCRAP_PPM image/ppm for PPM encoded image data
SCRAP_BMP image/bmp for BMP encoded image data
</pre><p>Depending on the platform additional types are automatically registered when data is placed into the clipboard to guarantee a consistent sharing behaviour with other applications. The following listed types can be used as string to be passed to the respective <tt>pygame.scrap</tt> module functions. </p>
<p>For Windows platforms, the additional types are supported automatically and resolve to their internal definitions: </p>
<pre> text/plain;charset=utf-8 for UTF-8 encoded text
audio/wav for WAV encoded audio
image/tiff for TIFF encoded image data
</pre><p>For <tt>X11</tt> platforms, the additional types are supported automatically and resolve to their internal definitions: </p>
<pre> UTF8_STRING for UTF-8 encoded text
text/plain;charset=utf-8 for UTF-8 encoded text
COMPOUND_TEXT for COMPOUND text
</pre><p>As stated before you can define own types for the clipboard, those however might not be usable by other applications. Thus data pasted into the clipboard using </p>
<pre> pygame.scrap.put ("own_data", data)
</pre><p>can only be used by applications, which query the clipboard for the "own_data" type. </p>
<p>New in pygame <tt>1.8</tt>. Only works for Windows, <tt>X11</tt> and Mac <tt>OS</tt> <tt>X</tt> so far. On Mac <tt>OSX</tt> only text works at the moment - other types will be supported in the next release. </p>
<!--COMMENTS:pygame.scrap--> <br>
<a name="pygame.scrap.init">
<big><b>pygame.scrap.init</big></b><br><ul>
<i>Initializes the scrap module.</i><br>
<tt>scrap.init () -> None</tt><br>
<p>Tries to initialize the scrap module and raises an exception, if it fails. Note that this module requires a set display surface, so you have to make sure, you acquired one earlier using <tt><a href="display.html#pygame.display.set_mode">pygame.display.set_mode</a> - <font size=-1>initialize a window or screen for display</font></tt>. </p>
<!--COMMENTS:pygame.scrap.init--> <br>
<br></ul>
<a name="pygame.scrap.get">
<big><b>pygame.scrap.get</big></b><br><ul>
<i>Gets the data for the specified type from the clipboard.</i><br>
<tt>scrap.get (type) -> string</tt><br>
<p>Returns the data for the specified type from the clipboard. The data is returned as string and might need further processing. If no data for the passed type is available, None is returned. </p>
<pre> text = pygame.scrap.get (SCRAP_TEXT)
if text:
# Do stuff with it.
else:
print "There does not seem to be text in the clipboard."
</pre>
<!--COMMENTS:pygame.scrap.get--> <br>
<br></ul>
<a name="pygame.scrap.get_types">
<big><b>pygame.scrap.get_types</big></b><br><ul>
<i>Gets a list of the available clipboard types.</i><br>
<tt>scrap.get_types () -> list</tt><br>
<p>Gets a list of strings with the identifiers for the available clipboard types. Each identifier can be used in the <tt>scrap.get()</tt> method to get the clipboard content of the specific type. If there is no data in the clipboard, an empty list is returned. </p>
<pre> types = pygame.scrap.get_types ()
for t in types:
if "text" in t:
# There is some content with the word "text" in it. It's
# possibly text, so print it.
print pygame.scrap.get (t)
</pre>
<!--COMMENTS:pygame.scrap.get_types--> <br>
<br></ul>
<a name="pygame.scrap.put">
<big><b>pygame.scrap.put</big></b><br><ul>
<i>Places data into the clipboard.</i><br>
<tt>scrap.put(type, data) -> None</tt><br>
<p>Places data for a specific clipboard type into the clipboard. The data must be a string buffer. The type is a string identifying the type of data placed into the clipboard. This can be one of the native <tt>SCRAP_PBM</tt>, <tt>SCRAP_PPM</tt>, <tt>SCRAP_BMP</tt> or <tt>SCRAP_TEXT</tt> values or an own string identifier. </p>
<p>The method raises an exception, if the content could not be placed into the clipboard. </p>
<pre> fp = open ("example.bmp", "rb")
pygame.scrap.put (SCRAP_BMP, fp.read ())
fp.close ()
# Now you can acquire the image data from the clipboard in other
# applications.
pygame.scrap.put (SCRAP_TEXT, "A text to copy")
pygame.scrap.put ("Plain text", "A text to copy")
</pre>
<!--COMMENTS:pygame.scrap.put--> <br>
<br></ul>
<a name="pygame.scrap.contains">
<big><b>pygame.scrap.contains</big></b><br><ul>
<i>Checks, whether a certain type is available in the clipboard.</i><br>
<tt>scrap.contains (type) -> bool</tt><br>
<p>Returns True, if data for the passed type is available in the clipboard, False otherwise. </p>
<pre> if pygame.scrap.contains (SCRAP_TEXT):
print "There is text in the clipboard."
if pygame.scrap.contains ("own_data_type"):
print "There is stuff in the clipboard."
</pre>
<!--COMMENTS:pygame.scrap.contains--> <br>
<br></ul>
<a name="pygame.scrap.lost">
<big><b>pygame.scrap.lost</big></b><br><ul>
<i>Checks whether the clipboard is currently owned by the application.</i><br>
<tt>scrap.lost() -> bool</tt><br>
<p>Returns True, if the clipboard is currently owned by the pygame application, False otherwise. </p>
<pre> if pygame.scrap.lost ():
print "No content from me anymore. The clipboard is used by someone else."
</pre>
<!--COMMENTS:pygame.scrap.lost--> <br>
<br></ul>
<a name="pygame.scrap.set_mode">
<big><b>pygame.scrap.set_mode</big></b><br><ul>
<i>Sets the clipboard access mode.</i><br>
<tt>scrap.set_mode(mode) -> None</tt><br>
<p>Sets the access mode for the clipboard. This is only of interest for <tt>X11</tt> environments, where clipboard modes for mouse selections <tt>(SRAP_SELECTION)</tt> and the clipboard <tt>(SCRAP_CLIPBOARD)</tt> are available. Setting the mode to <tt>SCRAP_SELECTION</tt> in other environments will not cause any difference. </p>
<p>If a value different from <tt>SCRAP_CLIPBOARD</tt> or <tt>SCRAP_SELECTION</tt> is passed, a ValueError will be raised. </p>
<!--COMMENTS:pygame.scrap.set_mode--> <br>
<br></ul>
<br></ul>
</body></html>
|