55Classes
66=======
77
8- ``MSSBase `` is the parent's class for every OS implementation.
9-
10-
118GNU/Linux
129---------
1310
@@ -21,12 +18,12 @@ GNU/Linux
2118
2219 GNU/Linux initializations.
2320
21+ .. method :: grab(monitor) -> ScreenShot
2422
25- .. method :: get_pixels(monitor) -> bytes
26-
27- :exception ScreenshotError: When color depth is not 32 (rare).
23+ :exception ScreenShotError: When color depth is not 32 (rare).
24+ :rtype: ScreenShot
2825
29- See :attr: `mss.base.MSSBase.get_pixels ` for details.
26+ See :attr: `mss.base.MSSBase.grab ` for details.
3027
3128
3229Methods
@@ -36,104 +33,159 @@ Methods
3633
3734.. class :: MSSBase
3835
39- .. method :: bgra_to_rgb(raw) -> bytes
36+ The parent's class for every OS implementation.
4037
41- :param bytearray raw: raw data containing BGRA values.
38+ .. method :: grab(monitor) -> ScreenShot
4239
43- It converts pixels values from BGRA to RGB.
44- This is the method called to populate :attr: `image ` into :attr: `get_pixels `.
40+ :param dict monitor: monitor's informations.
41+ :exception NotImplementedError: Subclasses need to implement this.
42+ :rtype: ScreenShot
4543
44+ Retrieve screen pixels for a given monitor.
4645
47- .. method :: enum_display_monitors(force=False ) -> list(dict)
46+ .. method :: save(mon=1, output='screenshot.png', callback=None ) -> generator
4847
49- :param bool force: force rescan of monitors informations.
50- :exception NotImplementedError: Subclasses need to implement this.
48+ :param int mon: the monitor's number.
49+ :param str output: the output's file name. ``%d ``, if present, will be replaced by the monitor number.
50+ :param callable callback: callback called before saving the screenshot to a file. Takes the ``output `` argument as parameter.
51+ :return generator: Created file(s).
5152
52- Get positions of one or more monitors.
53- If the monitor has rotation, you have to deal with it inside this method.
53+ Grab a screenshot and save it to a file.
5454
55- This method has to fill :attr: ` monitors ` with all informations and use it as a cache:
55+ .. method :: shot() -> str
5656
57- - ``monitors[0] `` is a dict of all monitors together;
58- - ``monitors[N] `` is a dict of the monitor N (with N > 0).
57+ :return str: The created file.
5958
60- Each monitor is a dict with::
59+ Helper to save the screenshot of the first monitor, by default.
60+ You can pass the same arguments as for ``save ``.
6161
62- {
63- 'left': the x-coordinate of the upper-left corner,
64- 'top': the y-coordinate of the upper-left corner,
65- 'width': the width,
66- 'height': the height
67- }
62+ .. class :: ScreenShot
6863
64+ Screen shot object.
6965
70- .. method :: get_pixels(monitor) -> bytes
66+ .. note ::
7167
72- :param dict monitor: monitor's informations generated by :attr: ` enum_display_monitors() `.
73- :exception NotImplementedError: Subclasses need to implement this .
68+ A better name would have been * Image *, but to prevent collisions
69+ with `` PIL.Image ``, it has been decided to use * ScreenShot * .
7470
75- Retrieve screen pixels for a given monitor.
76- This method has to define :attr: `width ` and :attr: `height `.
77- It stocks pixels data into :attr: `image ` (RGB) and returns it.
71+ .. classmethod :: from_size(cls, data, width, height) -> ScreenShot
7872
73+ :param bytearray data: raw BGRA pixels retrieved by ctype
74+ OS independent implementations.
75+ :param int width: the monitor's width.
76+ :param int height: the monitor's height.
77+ :rtype: ScreenShot
7978
80- .. method :: save(mon=0, output='monitor-%d.png', callback=None) -> generator
79+ Instanciate a new class given only screenshot's data and size.
8180
82- :param int mon: the monitor's number.
83- :param str output: the output's file name. ``%d ``, if present, will be replaced by the monitor number.
84- :param callable callback: callback called before saving the screenshot to a file. Takes the ``output `` argument as parameter.
81+ .. method :: pixels(coord_x, coord_y) -> Tuple[int, int, int]
82+
83+ :param int coord_x: The x coordinate.
84+ :param int coord_y: The y coordinate.
85+ :rtype: Tuple[int, int, int]
8586
86- Grab a screenshot and save it to a file. This is a generator which returns created files .
87+ Get the pixel value at the given position .
8788
89+ .. module :: mss.tools
8890
89- .. method :: to_png(data, output) -> None
91+ .. method :: to_png(data, size, output) -> None
9092
91- :param bytes data: raw pixels (RGBRGB...RGB) fom :attr: `get_pixels() `.
92- :param str output: output's file name.
93- :exception ScreenshotError: On error when writing ``data `` to ``output ``.
93+ :param bytes data: RGBRGB...RGB data.
94+ :param tuple size: The (width, height) pair.
95+ :param str output: output's file name.
96+ :exception ScreenShotError: On error when writing ``data `` to ``output ``.
9497
95- Dump data to the image file. Pure Python PNG implementation.
98+ Dump data to the image file. Pure Python PNG implementation.
9699
97100
98- Attributes
101+ Properties
99102==========
100103
101104.. class :: MSSBase
102105
103- .. attribute :: image
106+ .. attribute :: monitors
104107
105- :getter: Raw pixels of a monitor .
106- :setter: See :attr: ` get_pixels `.
107- :type: bytes
108+ Positions of all monitors .
109+ If the monitor has rotation, you have to deal with it
110+ inside this method.
108111
112+ This method has to fill ``self._monitors `` with all informations
113+ and use it as a cache:
109114
110- .. attribute :: monitors
115+ - ``self._monitors[0] `` is a dict of all monitors together
116+ - ``self._monitors[N] `` is a dict of the monitor N (with N > 0)
111117
112- :getter: The list of all monitors.
113- :setter: See :attr: `enum_display_monitors() `.
114- :type: list(dict)
118+ Each monitor is a dict with:
115119
120+ - ``left ``: the x-coordinate of the upper-left corner
121+ - ``top ``: the y-coordinate of the upper-left corner
122+ - ``width ``: the width
123+ - ``height ``: the height
116124
117- .. attribute :: width
125+ :type: List[Dict[str, int]]
126+
127+ .. class :: ScreenShot
128+
129+ .. attribute :: __array_interface__()
130+
131+ Numpy array interface support. It uses raw data in BGRA form.
132+
133+ :type: Dict[str, Any]
118134
119- :getter: Width of a monitor.
120- :setter: See :attr: `get_pixels() `.
135+ .. attribute :: pos
136+
137+ The screen shot's coodinates.
138+
139+ :type: NamedTuple
140+
141+ .. attribute :: top
142+
143+ The screen shot's top coodinate.
144+
145+ :type: int
146+
147+ .. attribute :: left
148+
149+ The screen shot's left coodinate.
121150 :type: int
122151
152+ .. attribute :: size
153+
154+ The screen shot's size.
155+
156+ :type: NamedTuple
157+
158+ .. attribute :: width
159+
160+ The screen shot's width.
161+
162+ :type: int
123163
124164 .. attribute :: height
125165
126- :getter: Height of a monitor .
127- :setter: See :attr: ` get_pixels() `.
166+ The screen shot's height .
167+
128168 :type: int
129169
170+ .. attribute :: pixels
171+
172+ List of RGB tuples.
173+
174+ :type: List[Tuple[int, int, int]]
175+
176+ .. attribute :: rgb
177+
178+ Computed RGB values from the BGRA raw pixels.
179+
180+ :type: bytes
181+
130182
131183Exception
132184=========
133185
134186.. module :: mss.exception
135187
136- .. exception :: ScreenshotError
188+ .. exception :: ScreenShotError
137189
138190 Base class for MSS exceptions.
139191
0 commit comments