Skip to content

Commit 3b374a6

Browse files
authored
Merge pull request #75 from tmontes/window-docstrings
Added docstrings to the Window class.
2 parents 5fc5860 + 4e16387 commit 3b374a6

File tree

1 file changed

+50
-8
lines changed

1 file changed

+50
-8
lines changed

src/aturtle/window.py

+50-8
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,25 @@
1111

1212
class Window:
1313

14+
"""
15+
A Window holding a canvas.
16+
"""
17+
1418
_windows = []
1519

1620
def __init__(self, width=320, height=320, x=None, y=None,
1721
fill_color='white', title='A-Turtle'):
22+
"""
23+
Initialize a Window with the given `width` and `height`, filled in
24+
`fill_color`, with the given `title`.
25+
26+
Positive `x` and `y` values place the Window from the screen's top-
27+
left corner. Negative values place it from the bottom-right corner.
28+
29+
Windows hold a canvas object that automatically sizes up/down on
30+
Window resizes, and keeps its (0, 0) origin at the horizontal and
31+
vertical Window center.
32+
"""
1833

1934
tk_window = tkinter.Tk() if not Window._windows else tkinter.Toplevel()
2035
Window._windows.append(self)
@@ -63,13 +78,18 @@ def __init__(self, width=320, height=320, x=None, y=None,
6378

6479
@property
6580
def x(self):
66-
81+
"""
82+
The Window's horizontal position.
83+
"""
6784
return self._tk_window.winfo_x()
6885

6986

7087
@x.setter
7188
def x(self, value):
72-
89+
"""
90+
Set the Window's horizontal position.
91+
Negative values place the Window from the right of the screen.
92+
"""
7393
if value < 0:
7494
value = self._tk_window.winfo_screenwidth() - self.width + value
7595

@@ -78,13 +98,18 @@ def x(self, value):
7898

7999
@property
80100
def y(self):
81-
101+
"""
102+
The Window's vertical position.
103+
"""
82104
return self._tk_window.winfo_y()
83105

84106

85107
@y.setter
86108
def y(self, value):
87-
109+
"""
110+
Set the Window's vertical position.
111+
Negative values place the Window from the bottom of the screen.
112+
"""
88113
if value < 0:
89114
value = self._tk_window.winfo_screenheight() - self.height + value
90115

@@ -93,25 +118,33 @@ def y(self, value):
93118

94119
@property
95120
def width(self):
96-
121+
"""
122+
The Window width.
123+
"""
97124
return self._tk_window.winfo_width()
98125

99126

100127
@width.setter
101128
def width(self, value):
102-
129+
"""
130+
Set the Window width.
131+
"""
103132
self._tk_window.geometry(f'{value}x{self.height}')
104133

105134

106135
@property
107136
def height(self):
108-
137+
"""
138+
The Window height.
139+
"""
109140
return self._tk_window.winfo_height()
110141

111142

112143
@height.setter
113144
def height(self, value):
114-
145+
"""
146+
Set the Window height.
147+
"""
115148
self._tk_window.geometry(f'{self.width}x{value}')
116149

117150

@@ -237,7 +270,12 @@ def unbind_direct_key(self, keysym=None):
237270

238271

239272
def close(self):
273+
"""
274+
Closes this Window.
240275
276+
Raises RuntimeError if this is the first created Window and there still
277+
are other open Windows.
278+
"""
241279
is_root = self._tk_window is Window._windows[0]._tk_window
242280
if is_root and len(Window._windows) > 1:
243281
raise RuntimeError('Must be last to close.')
@@ -251,7 +289,11 @@ def close(self):
251289

252290
@classmethod
253291
def close_all(cls, strict=True):
292+
"""
293+
Closes all Windows.
254294
295+
Raises RuntimeError if `strict` is true and there are no open Windows.
296+
"""
255297
if not cls._windows:
256298
if strict:
257299
raise RuntimeError('No windows.')

0 commit comments

Comments
 (0)