1 | n/a | import unittest |
---|
2 | n/a | import re |
---|
3 | n/a | import tkinter |
---|
4 | n/a | from tkinter import TclError |
---|
5 | n/a | from test.support import requires |
---|
6 | n/a | |
---|
7 | n/a | from tkinter.test.support import pixels_conv, tcl_version, requires_tcl |
---|
8 | n/a | from tkinter.test.widget_tests import AbstractWidgetTest |
---|
9 | n/a | |
---|
10 | n/a | requires('gui') |
---|
11 | n/a | |
---|
12 | n/a | |
---|
13 | n/a | class PackTest(AbstractWidgetTest, unittest.TestCase): |
---|
14 | n/a | |
---|
15 | n/a | test_keys = None |
---|
16 | n/a | |
---|
17 | n/a | def create2(self): |
---|
18 | n/a | pack = tkinter.Toplevel(self.root, name='pack') |
---|
19 | n/a | pack.wm_geometry('300x200+0+0') |
---|
20 | n/a | pack.wm_minsize(1, 1) |
---|
21 | n/a | a = tkinter.Frame(pack, name='a', width=20, height=40, bg='red') |
---|
22 | n/a | b = tkinter.Frame(pack, name='b', width=50, height=30, bg='blue') |
---|
23 | n/a | c = tkinter.Frame(pack, name='c', width=80, height=80, bg='green') |
---|
24 | n/a | d = tkinter.Frame(pack, name='d', width=40, height=30, bg='yellow') |
---|
25 | n/a | return pack, a, b, c, d |
---|
26 | n/a | |
---|
27 | n/a | def test_pack_configure_after(self): |
---|
28 | n/a | pack, a, b, c, d = self.create2() |
---|
29 | n/a | with self.assertRaisesRegex(TclError, 'window "%s" isn\'t packed' % b): |
---|
30 | n/a | a.pack_configure(after=b) |
---|
31 | n/a | with self.assertRaisesRegex(TclError, 'bad window path name ".foo"'): |
---|
32 | n/a | a.pack_configure(after='.foo') |
---|
33 | n/a | a.pack_configure(side='top') |
---|
34 | n/a | b.pack_configure(side='top') |
---|
35 | n/a | c.pack_configure(side='top') |
---|
36 | n/a | d.pack_configure(side='top') |
---|
37 | n/a | self.assertEqual(pack.pack_slaves(), [a, b, c, d]) |
---|
38 | n/a | a.pack_configure(after=b) |
---|
39 | n/a | self.assertEqual(pack.pack_slaves(), [b, a, c, d]) |
---|
40 | n/a | a.pack_configure(after=a) |
---|
41 | n/a | self.assertEqual(pack.pack_slaves(), [b, a, c, d]) |
---|
42 | n/a | |
---|
43 | n/a | def test_pack_configure_anchor(self): |
---|
44 | n/a | pack, a, b, c, d = self.create2() |
---|
45 | n/a | def check(anchor, geom): |
---|
46 | n/a | a.pack_configure(side='top', ipadx=5, padx=10, ipady=15, pady=20, |
---|
47 | n/a | expand=True, anchor=anchor) |
---|
48 | n/a | self.root.update() |
---|
49 | n/a | self.assertEqual(a.winfo_geometry(), geom) |
---|
50 | n/a | check('n', '30x70+135+20') |
---|
51 | n/a | check('ne', '30x70+260+20') |
---|
52 | n/a | check('e', '30x70+260+65') |
---|
53 | n/a | check('se', '30x70+260+110') |
---|
54 | n/a | check('s', '30x70+135+110') |
---|
55 | n/a | check('sw', '30x70+10+110') |
---|
56 | n/a | check('w', '30x70+10+65') |
---|
57 | n/a | check('nw', '30x70+10+20') |
---|
58 | n/a | check('center', '30x70+135+65') |
---|
59 | n/a | |
---|
60 | n/a | def test_pack_configure_before(self): |
---|
61 | n/a | pack, a, b, c, d = self.create2() |
---|
62 | n/a | with self.assertRaisesRegex(TclError, 'window "%s" isn\'t packed' % b): |
---|
63 | n/a | a.pack_configure(before=b) |
---|
64 | n/a | with self.assertRaisesRegex(TclError, 'bad window path name ".foo"'): |
---|
65 | n/a | a.pack_configure(before='.foo') |
---|
66 | n/a | a.pack_configure(side='top') |
---|
67 | n/a | b.pack_configure(side='top') |
---|
68 | n/a | c.pack_configure(side='top') |
---|
69 | n/a | d.pack_configure(side='top') |
---|
70 | n/a | self.assertEqual(pack.pack_slaves(), [a, b, c, d]) |
---|
71 | n/a | a.pack_configure(before=d) |
---|
72 | n/a | self.assertEqual(pack.pack_slaves(), [b, c, a, d]) |
---|
73 | n/a | a.pack_configure(before=a) |
---|
74 | n/a | self.assertEqual(pack.pack_slaves(), [b, c, a, d]) |
---|
75 | n/a | |
---|
76 | n/a | def test_pack_configure_expand(self): |
---|
77 | n/a | pack, a, b, c, d = self.create2() |
---|
78 | n/a | def check(*geoms): |
---|
79 | n/a | self.root.update() |
---|
80 | n/a | self.assertEqual(a.winfo_geometry(), geoms[0]) |
---|
81 | n/a | self.assertEqual(b.winfo_geometry(), geoms[1]) |
---|
82 | n/a | self.assertEqual(c.winfo_geometry(), geoms[2]) |
---|
83 | n/a | self.assertEqual(d.winfo_geometry(), geoms[3]) |
---|
84 | n/a | a.pack_configure(side='left') |
---|
85 | n/a | b.pack_configure(side='top') |
---|
86 | n/a | c.pack_configure(side='right') |
---|
87 | n/a | d.pack_configure(side='bottom') |
---|
88 | n/a | check('20x40+0+80', '50x30+135+0', '80x80+220+75', '40x30+100+170') |
---|
89 | n/a | a.pack_configure(side='left', expand='yes') |
---|
90 | n/a | b.pack_configure(side='top', expand='on') |
---|
91 | n/a | c.pack_configure(side='right', expand=True) |
---|
92 | n/a | d.pack_configure(side='bottom', expand=1) |
---|
93 | n/a | check('20x40+40+80', '50x30+175+35', '80x80+180+110', '40x30+100+135') |
---|
94 | n/a | a.pack_configure(side='left', expand='yes', fill='both') |
---|
95 | n/a | b.pack_configure(side='top', expand='on', fill='both') |
---|
96 | n/a | c.pack_configure(side='right', expand=True, fill='both') |
---|
97 | n/a | d.pack_configure(side='bottom', expand=1, fill='both') |
---|
98 | n/a | check('100x200+0+0', '200x100+100+0', '160x100+140+100', '40x100+100+100') |
---|
99 | n/a | |
---|
100 | n/a | def test_pack_configure_in(self): |
---|
101 | n/a | pack, a, b, c, d = self.create2() |
---|
102 | n/a | a.pack_configure(side='top') |
---|
103 | n/a | b.pack_configure(side='top') |
---|
104 | n/a | c.pack_configure(side='top') |
---|
105 | n/a | d.pack_configure(side='top') |
---|
106 | n/a | a.pack_configure(in_=pack) |
---|
107 | n/a | self.assertEqual(pack.pack_slaves(), [b, c, d, a]) |
---|
108 | n/a | a.pack_configure(in_=c) |
---|
109 | n/a | self.assertEqual(pack.pack_slaves(), [b, c, d]) |
---|
110 | n/a | self.assertEqual(c.pack_slaves(), [a]) |
---|
111 | n/a | with self.assertRaisesRegex(TclError, |
---|
112 | n/a | 'can\'t pack %s inside itself' % (a,)): |
---|
113 | n/a | a.pack_configure(in_=a) |
---|
114 | n/a | with self.assertRaisesRegex(TclError, 'bad window path name ".foo"'): |
---|
115 | n/a | a.pack_configure(in_='.foo') |
---|
116 | n/a | |
---|
117 | n/a | def test_pack_configure_padx_ipadx_fill(self): |
---|
118 | n/a | pack, a, b, c, d = self.create2() |
---|
119 | n/a | def check(geom1, geom2, **kwargs): |
---|
120 | n/a | a.pack_forget() |
---|
121 | n/a | b.pack_forget() |
---|
122 | n/a | a.pack_configure(**kwargs) |
---|
123 | n/a | b.pack_configure(expand=True, fill='both') |
---|
124 | n/a | self.root.update() |
---|
125 | n/a | self.assertEqual(a.winfo_geometry(), geom1) |
---|
126 | n/a | self.assertEqual(b.winfo_geometry(), geom2) |
---|
127 | n/a | check('20x40+260+80', '240x200+0+0', side='right', padx=20) |
---|
128 | n/a | check('20x40+250+80', '240x200+0+0', side='right', padx=(10, 30)) |
---|
129 | n/a | check('60x40+240+80', '240x200+0+0', side='right', ipadx=20) |
---|
130 | n/a | check('30x40+260+80', '250x200+0+0', side='right', ipadx=5, padx=10) |
---|
131 | n/a | check('20x40+260+80', '240x200+0+0', side='right', padx=20, fill='x') |
---|
132 | n/a | check('20x40+249+80', '240x200+0+0', |
---|
133 | n/a | side='right', padx=(9, 31), fill='x') |
---|
134 | n/a | check('60x40+240+80', '240x200+0+0', side='right', ipadx=20, fill='x') |
---|
135 | n/a | check('30x40+260+80', '250x200+0+0', |
---|
136 | n/a | side='right', ipadx=5, padx=10, fill='x') |
---|
137 | n/a | check('30x40+255+80', '250x200+0+0', |
---|
138 | n/a | side='right', ipadx=5, padx=(5, 15), fill='x') |
---|
139 | n/a | check('20x40+140+0', '300x160+0+40', side='top', padx=20) |
---|
140 | n/a | check('20x40+120+0', '300x160+0+40', side='top', padx=(0, 40)) |
---|
141 | n/a | check('60x40+120+0', '300x160+0+40', side='top', ipadx=20) |
---|
142 | n/a | check('30x40+135+0', '300x160+0+40', side='top', ipadx=5, padx=10) |
---|
143 | n/a | check('30x40+130+0', '300x160+0+40', side='top', ipadx=5, padx=(5, 15)) |
---|
144 | n/a | check('260x40+20+0', '300x160+0+40', side='top', padx=20, fill='x') |
---|
145 | n/a | check('260x40+25+0', '300x160+0+40', |
---|
146 | n/a | side='top', padx=(25, 15), fill='x') |
---|
147 | n/a | check('300x40+0+0', '300x160+0+40', side='top', ipadx=20, fill='x') |
---|
148 | n/a | check('280x40+10+0', '300x160+0+40', |
---|
149 | n/a | side='top', ipadx=5, padx=10, fill='x') |
---|
150 | n/a | check('280x40+5+0', '300x160+0+40', |
---|
151 | n/a | side='top', ipadx=5, padx=(5, 15), fill='x') |
---|
152 | n/a | a.pack_configure(padx='1c') |
---|
153 | n/a | self.assertEqual(a.pack_info()['padx'], |
---|
154 | n/a | self._str(pack.winfo_pixels('1c'))) |
---|
155 | n/a | a.pack_configure(ipadx='1c') |
---|
156 | n/a | self.assertEqual(a.pack_info()['ipadx'], |
---|
157 | n/a | self._str(pack.winfo_pixels('1c'))) |
---|
158 | n/a | |
---|
159 | n/a | def test_pack_configure_pady_ipady_fill(self): |
---|
160 | n/a | pack, a, b, c, d = self.create2() |
---|
161 | n/a | def check(geom1, geom2, **kwargs): |
---|
162 | n/a | a.pack_forget() |
---|
163 | n/a | b.pack_forget() |
---|
164 | n/a | a.pack_configure(**kwargs) |
---|
165 | n/a | b.pack_configure(expand=True, fill='both') |
---|
166 | n/a | self.root.update() |
---|
167 | n/a | self.assertEqual(a.winfo_geometry(), geom1) |
---|
168 | n/a | self.assertEqual(b.winfo_geometry(), geom2) |
---|
169 | n/a | check('20x40+280+80', '280x200+0+0', side='right', pady=20) |
---|
170 | n/a | check('20x40+280+70', '280x200+0+0', side='right', pady=(10, 30)) |
---|
171 | n/a | check('20x80+280+60', '280x200+0+0', side='right', ipady=20) |
---|
172 | n/a | check('20x50+280+75', '280x200+0+0', side='right', ipady=5, pady=10) |
---|
173 | n/a | check('20x40+280+80', '280x200+0+0', side='right', pady=20, fill='x') |
---|
174 | n/a | check('20x40+280+69', '280x200+0+0', |
---|
175 | n/a | side='right', pady=(9, 31), fill='x') |
---|
176 | n/a | check('20x80+280+60', '280x200+0+0', side='right', ipady=20, fill='x') |
---|
177 | n/a | check('20x50+280+75', '280x200+0+0', |
---|
178 | n/a | side='right', ipady=5, pady=10, fill='x') |
---|
179 | n/a | check('20x50+280+70', '280x200+0+0', |
---|
180 | n/a | side='right', ipady=5, pady=(5, 15), fill='x') |
---|
181 | n/a | check('20x40+140+20', '300x120+0+80', side='top', pady=20) |
---|
182 | n/a | check('20x40+140+0', '300x120+0+80', side='top', pady=(0, 40)) |
---|
183 | n/a | check('20x80+140+0', '300x120+0+80', side='top', ipady=20) |
---|
184 | n/a | check('20x50+140+10', '300x130+0+70', side='top', ipady=5, pady=10) |
---|
185 | n/a | check('20x50+140+5', '300x130+0+70', side='top', ipady=5, pady=(5, 15)) |
---|
186 | n/a | check('300x40+0+20', '300x120+0+80', side='top', pady=20, fill='x') |
---|
187 | n/a | check('300x40+0+25', '300x120+0+80', |
---|
188 | n/a | side='top', pady=(25, 15), fill='x') |
---|
189 | n/a | check('300x80+0+0', '300x120+0+80', side='top', ipady=20, fill='x') |
---|
190 | n/a | check('300x50+0+10', '300x130+0+70', |
---|
191 | n/a | side='top', ipady=5, pady=10, fill='x') |
---|
192 | n/a | check('300x50+0+5', '300x130+0+70', |
---|
193 | n/a | side='top', ipady=5, pady=(5, 15), fill='x') |
---|
194 | n/a | a.pack_configure(pady='1c') |
---|
195 | n/a | self.assertEqual(a.pack_info()['pady'], |
---|
196 | n/a | self._str(pack.winfo_pixels('1c'))) |
---|
197 | n/a | a.pack_configure(ipady='1c') |
---|
198 | n/a | self.assertEqual(a.pack_info()['ipady'], |
---|
199 | n/a | self._str(pack.winfo_pixels('1c'))) |
---|
200 | n/a | |
---|
201 | n/a | def test_pack_configure_side(self): |
---|
202 | n/a | pack, a, b, c, d = self.create2() |
---|
203 | n/a | def check(side, geom1, geom2): |
---|
204 | n/a | a.pack_configure(side=side) |
---|
205 | n/a | self.assertEqual(a.pack_info()['side'], side) |
---|
206 | n/a | b.pack_configure(expand=True, fill='both') |
---|
207 | n/a | self.root.update() |
---|
208 | n/a | self.assertEqual(a.winfo_geometry(), geom1) |
---|
209 | n/a | self.assertEqual(b.winfo_geometry(), geom2) |
---|
210 | n/a | check('top', '20x40+140+0', '300x160+0+40') |
---|
211 | n/a | check('bottom', '20x40+140+160', '300x160+0+0') |
---|
212 | n/a | check('left', '20x40+0+80', '280x200+20+0') |
---|
213 | n/a | check('right', '20x40+280+80', '280x200+0+0') |
---|
214 | n/a | |
---|
215 | n/a | def test_pack_forget(self): |
---|
216 | n/a | pack, a, b, c, d = self.create2() |
---|
217 | n/a | a.pack_configure() |
---|
218 | n/a | b.pack_configure() |
---|
219 | n/a | c.pack_configure() |
---|
220 | n/a | self.assertEqual(pack.pack_slaves(), [a, b, c]) |
---|
221 | n/a | b.pack_forget() |
---|
222 | n/a | self.assertEqual(pack.pack_slaves(), [a, c]) |
---|
223 | n/a | b.pack_forget() |
---|
224 | n/a | self.assertEqual(pack.pack_slaves(), [a, c]) |
---|
225 | n/a | d.pack_forget() |
---|
226 | n/a | |
---|
227 | n/a | def test_pack_info(self): |
---|
228 | n/a | pack, a, b, c, d = self.create2() |
---|
229 | n/a | with self.assertRaisesRegex(TclError, 'window "%s" isn\'t packed' % a): |
---|
230 | n/a | a.pack_info() |
---|
231 | n/a | a.pack_configure() |
---|
232 | n/a | b.pack_configure(side='right', in_=a, anchor='s', expand=True, fill='x', |
---|
233 | n/a | ipadx=5, padx=10, ipady=2, pady=(5, 15)) |
---|
234 | n/a | info = a.pack_info() |
---|
235 | n/a | self.assertIsInstance(info, dict) |
---|
236 | n/a | self.assertEqual(info['anchor'], 'center') |
---|
237 | n/a | self.assertEqual(info['expand'], self._str(0)) |
---|
238 | n/a | self.assertEqual(info['fill'], 'none') |
---|
239 | n/a | self.assertEqual(info['in'], pack) |
---|
240 | n/a | self.assertEqual(info['ipadx'], self._str(0)) |
---|
241 | n/a | self.assertEqual(info['ipady'], self._str(0)) |
---|
242 | n/a | self.assertEqual(info['padx'], self._str(0)) |
---|
243 | n/a | self.assertEqual(info['pady'], self._str(0)) |
---|
244 | n/a | self.assertEqual(info['side'], 'top') |
---|
245 | n/a | info = b.pack_info() |
---|
246 | n/a | self.assertIsInstance(info, dict) |
---|
247 | n/a | self.assertEqual(info['anchor'], 's') |
---|
248 | n/a | self.assertEqual(info['expand'], self._str(1)) |
---|
249 | n/a | self.assertEqual(info['fill'], 'x') |
---|
250 | n/a | self.assertEqual(info['in'], a) |
---|
251 | n/a | self.assertEqual(info['ipadx'], self._str(5)) |
---|
252 | n/a | self.assertEqual(info['ipady'], self._str(2)) |
---|
253 | n/a | self.assertEqual(info['padx'], self._str(10)) |
---|
254 | n/a | self.assertEqual(info['pady'], self._str((5, 15))) |
---|
255 | n/a | self.assertEqual(info['side'], 'right') |
---|
256 | n/a | |
---|
257 | n/a | def test_pack_propagate(self): |
---|
258 | n/a | pack, a, b, c, d = self.create2() |
---|
259 | n/a | pack.configure(width=300, height=200) |
---|
260 | n/a | a.pack_configure() |
---|
261 | n/a | pack.pack_propagate(False) |
---|
262 | n/a | self.root.update() |
---|
263 | n/a | self.assertEqual(pack.winfo_reqwidth(), 300) |
---|
264 | n/a | self.assertEqual(pack.winfo_reqheight(), 200) |
---|
265 | n/a | pack.pack_propagate(True) |
---|
266 | n/a | self.root.update() |
---|
267 | n/a | self.assertEqual(pack.winfo_reqwidth(), 20) |
---|
268 | n/a | self.assertEqual(pack.winfo_reqheight(), 40) |
---|
269 | n/a | |
---|
270 | n/a | def test_pack_slaves(self): |
---|
271 | n/a | pack, a, b, c, d = self.create2() |
---|
272 | n/a | self.assertEqual(pack.pack_slaves(), []) |
---|
273 | n/a | a.pack_configure() |
---|
274 | n/a | self.assertEqual(pack.pack_slaves(), [a]) |
---|
275 | n/a | b.pack_configure() |
---|
276 | n/a | self.assertEqual(pack.pack_slaves(), [a, b]) |
---|
277 | n/a | |
---|
278 | n/a | |
---|
279 | n/a | class PlaceTest(AbstractWidgetTest, unittest.TestCase): |
---|
280 | n/a | |
---|
281 | n/a | test_keys = None |
---|
282 | n/a | |
---|
283 | n/a | def create2(self): |
---|
284 | n/a | t = tkinter.Toplevel(self.root, width=300, height=200, bd=0) |
---|
285 | n/a | t.wm_geometry('300x200+0+0') |
---|
286 | n/a | f = tkinter.Frame(t, width=154, height=84, bd=2, relief='raised') |
---|
287 | n/a | f.place_configure(x=48, y=38) |
---|
288 | n/a | f2 = tkinter.Frame(t, width=30, height=60, bd=2, relief='raised') |
---|
289 | n/a | self.root.update() |
---|
290 | n/a | return t, f, f2 |
---|
291 | n/a | |
---|
292 | n/a | def test_place_configure_in(self): |
---|
293 | n/a | t, f, f2 = self.create2() |
---|
294 | n/a | self.assertEqual(f2.winfo_manager(), '') |
---|
295 | n/a | with self.assertRaisesRegex(TclError, "can't place %s relative to " |
---|
296 | n/a | "itself" % re.escape(str(f2))): |
---|
297 | n/a | f2.place_configure(in_=f2) |
---|
298 | n/a | if tcl_version >= (8, 5): |
---|
299 | n/a | self.assertEqual(f2.winfo_manager(), '') |
---|
300 | n/a | with self.assertRaisesRegex(TclError, 'bad window path name'): |
---|
301 | n/a | f2.place_configure(in_='spam') |
---|
302 | n/a | f2.place_configure(in_=f) |
---|
303 | n/a | self.assertEqual(f2.winfo_manager(), 'place') |
---|
304 | n/a | |
---|
305 | n/a | def test_place_configure_x(self): |
---|
306 | n/a | t, f, f2 = self.create2() |
---|
307 | n/a | f2.place_configure(in_=f) |
---|
308 | n/a | self.assertEqual(f2.place_info()['x'], '0') |
---|
309 | n/a | self.root.update() |
---|
310 | n/a | self.assertEqual(f2.winfo_x(), 50) |
---|
311 | n/a | f2.place_configure(x=100) |
---|
312 | n/a | self.assertEqual(f2.place_info()['x'], '100') |
---|
313 | n/a | self.root.update() |
---|
314 | n/a | self.assertEqual(f2.winfo_x(), 150) |
---|
315 | n/a | f2.place_configure(x=-10, relx=1) |
---|
316 | n/a | self.assertEqual(f2.place_info()['x'], '-10') |
---|
317 | n/a | self.root.update() |
---|
318 | n/a | self.assertEqual(f2.winfo_x(), 190) |
---|
319 | n/a | with self.assertRaisesRegex(TclError, 'bad screen distance "spam"'): |
---|
320 | n/a | f2.place_configure(in_=f, x='spam') |
---|
321 | n/a | |
---|
322 | n/a | def test_place_configure_y(self): |
---|
323 | n/a | t, f, f2 = self.create2() |
---|
324 | n/a | f2.place_configure(in_=f) |
---|
325 | n/a | self.assertEqual(f2.place_info()['y'], '0') |
---|
326 | n/a | self.root.update() |
---|
327 | n/a | self.assertEqual(f2.winfo_y(), 40) |
---|
328 | n/a | f2.place_configure(y=50) |
---|
329 | n/a | self.assertEqual(f2.place_info()['y'], '50') |
---|
330 | n/a | self.root.update() |
---|
331 | n/a | self.assertEqual(f2.winfo_y(), 90) |
---|
332 | n/a | f2.place_configure(y=-10, rely=1) |
---|
333 | n/a | self.assertEqual(f2.place_info()['y'], '-10') |
---|
334 | n/a | self.root.update() |
---|
335 | n/a | self.assertEqual(f2.winfo_y(), 110) |
---|
336 | n/a | with self.assertRaisesRegex(TclError, 'bad screen distance "spam"'): |
---|
337 | n/a | f2.place_configure(in_=f, y='spam') |
---|
338 | n/a | |
---|
339 | n/a | def test_place_configure_relx(self): |
---|
340 | n/a | t, f, f2 = self.create2() |
---|
341 | n/a | f2.place_configure(in_=f) |
---|
342 | n/a | self.assertEqual(f2.place_info()['relx'], '0') |
---|
343 | n/a | self.root.update() |
---|
344 | n/a | self.assertEqual(f2.winfo_x(), 50) |
---|
345 | n/a | f2.place_configure(relx=0.5) |
---|
346 | n/a | self.assertEqual(f2.place_info()['relx'], '0.5') |
---|
347 | n/a | self.root.update() |
---|
348 | n/a | self.assertEqual(f2.winfo_x(), 125) |
---|
349 | n/a | f2.place_configure(relx=1) |
---|
350 | n/a | self.assertEqual(f2.place_info()['relx'], '1') |
---|
351 | n/a | self.root.update() |
---|
352 | n/a | self.assertEqual(f2.winfo_x(), 200) |
---|
353 | n/a | with self.assertRaisesRegex(TclError, 'expected floating-point number ' |
---|
354 | n/a | 'but got "spam"'): |
---|
355 | n/a | f2.place_configure(in_=f, relx='spam') |
---|
356 | n/a | |
---|
357 | n/a | def test_place_configure_rely(self): |
---|
358 | n/a | t, f, f2 = self.create2() |
---|
359 | n/a | f2.place_configure(in_=f) |
---|
360 | n/a | self.assertEqual(f2.place_info()['rely'], '0') |
---|
361 | n/a | self.root.update() |
---|
362 | n/a | self.assertEqual(f2.winfo_y(), 40) |
---|
363 | n/a | f2.place_configure(rely=0.5) |
---|
364 | n/a | self.assertEqual(f2.place_info()['rely'], '0.5') |
---|
365 | n/a | self.root.update() |
---|
366 | n/a | self.assertEqual(f2.winfo_y(), 80) |
---|
367 | n/a | f2.place_configure(rely=1) |
---|
368 | n/a | self.assertEqual(f2.place_info()['rely'], '1') |
---|
369 | n/a | self.root.update() |
---|
370 | n/a | self.assertEqual(f2.winfo_y(), 120) |
---|
371 | n/a | with self.assertRaisesRegex(TclError, 'expected floating-point number ' |
---|
372 | n/a | 'but got "spam"'): |
---|
373 | n/a | f2.place_configure(in_=f, rely='spam') |
---|
374 | n/a | |
---|
375 | n/a | def test_place_configure_anchor(self): |
---|
376 | n/a | f = tkinter.Frame(self.root) |
---|
377 | n/a | with self.assertRaisesRegex(TclError, 'bad anchor "j"'): |
---|
378 | n/a | f.place_configure(anchor='j') |
---|
379 | n/a | with self.assertRaisesRegex(TclError, 'ambiguous anchor ""'): |
---|
380 | n/a | f.place_configure(anchor='') |
---|
381 | n/a | for value in 'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw', 'center': |
---|
382 | n/a | f.place_configure(anchor=value) |
---|
383 | n/a | self.assertEqual(f.place_info()['anchor'], value) |
---|
384 | n/a | |
---|
385 | n/a | def test_place_configure_width(self): |
---|
386 | n/a | t, f, f2 = self.create2() |
---|
387 | n/a | f2.place_configure(in_=f, width=120) |
---|
388 | n/a | self.root.update() |
---|
389 | n/a | self.assertEqual(f2.winfo_width(), 120) |
---|
390 | n/a | f2.place_configure(width='') |
---|
391 | n/a | self.root.update() |
---|
392 | n/a | self.assertEqual(f2.winfo_width(), 30) |
---|
393 | n/a | with self.assertRaisesRegex(TclError, 'bad screen distance "abcd"'): |
---|
394 | n/a | f2.place_configure(width='abcd') |
---|
395 | n/a | |
---|
396 | n/a | def test_place_configure_height(self): |
---|
397 | n/a | t, f, f2 = self.create2() |
---|
398 | n/a | f2.place_configure(in_=f, height=120) |
---|
399 | n/a | self.root.update() |
---|
400 | n/a | self.assertEqual(f2.winfo_height(), 120) |
---|
401 | n/a | f2.place_configure(height='') |
---|
402 | n/a | self.root.update() |
---|
403 | n/a | self.assertEqual(f2.winfo_height(), 60) |
---|
404 | n/a | with self.assertRaisesRegex(TclError, 'bad screen distance "abcd"'): |
---|
405 | n/a | f2.place_configure(height='abcd') |
---|
406 | n/a | |
---|
407 | n/a | def test_place_configure_relwidth(self): |
---|
408 | n/a | t, f, f2 = self.create2() |
---|
409 | n/a | f2.place_configure(in_=f, relwidth=0.5) |
---|
410 | n/a | self.root.update() |
---|
411 | n/a | self.assertEqual(f2.winfo_width(), 75) |
---|
412 | n/a | f2.place_configure(relwidth='') |
---|
413 | n/a | self.root.update() |
---|
414 | n/a | self.assertEqual(f2.winfo_width(), 30) |
---|
415 | n/a | with self.assertRaisesRegex(TclError, 'expected floating-point number ' |
---|
416 | n/a | 'but got "abcd"'): |
---|
417 | n/a | f2.place_configure(relwidth='abcd') |
---|
418 | n/a | |
---|
419 | n/a | def test_place_configure_relheight(self): |
---|
420 | n/a | t, f, f2 = self.create2() |
---|
421 | n/a | f2.place_configure(in_=f, relheight=0.5) |
---|
422 | n/a | self.root.update() |
---|
423 | n/a | self.assertEqual(f2.winfo_height(), 40) |
---|
424 | n/a | f2.place_configure(relheight='') |
---|
425 | n/a | self.root.update() |
---|
426 | n/a | self.assertEqual(f2.winfo_height(), 60) |
---|
427 | n/a | with self.assertRaisesRegex(TclError, 'expected floating-point number ' |
---|
428 | n/a | 'but got "abcd"'): |
---|
429 | n/a | f2.place_configure(relheight='abcd') |
---|
430 | n/a | |
---|
431 | n/a | def test_place_configure_bordermode(self): |
---|
432 | n/a | f = tkinter.Frame(self.root) |
---|
433 | n/a | with self.assertRaisesRegex(TclError, 'bad bordermode "j"'): |
---|
434 | n/a | f.place_configure(bordermode='j') |
---|
435 | n/a | with self.assertRaisesRegex(TclError, 'ambiguous bordermode ""'): |
---|
436 | n/a | f.place_configure(bordermode='') |
---|
437 | n/a | for value in 'inside', 'outside', 'ignore': |
---|
438 | n/a | f.place_configure(bordermode=value) |
---|
439 | n/a | self.assertEqual(f.place_info()['bordermode'], value) |
---|
440 | n/a | |
---|
441 | n/a | def test_place_forget(self): |
---|
442 | n/a | foo = tkinter.Frame(self.root) |
---|
443 | n/a | foo.place_configure(width=50, height=50) |
---|
444 | n/a | self.root.update() |
---|
445 | n/a | foo.place_forget() |
---|
446 | n/a | self.root.update() |
---|
447 | n/a | self.assertFalse(foo.winfo_ismapped()) |
---|
448 | n/a | with self.assertRaises(TypeError): |
---|
449 | n/a | foo.place_forget(0) |
---|
450 | n/a | |
---|
451 | n/a | def test_place_info(self): |
---|
452 | n/a | t, f, f2 = self.create2() |
---|
453 | n/a | f2.place_configure(in_=f, x=1, y=2, width=3, height=4, |
---|
454 | n/a | relx=0.1, rely=0.2, relwidth=0.3, relheight=0.4, |
---|
455 | n/a | anchor='se', bordermode='outside') |
---|
456 | n/a | info = f2.place_info() |
---|
457 | n/a | self.assertIsInstance(info, dict) |
---|
458 | n/a | self.assertEqual(info['x'], '1') |
---|
459 | n/a | self.assertEqual(info['y'], '2') |
---|
460 | n/a | self.assertEqual(info['width'], '3') |
---|
461 | n/a | self.assertEqual(info['height'], '4') |
---|
462 | n/a | self.assertEqual(info['relx'], '0.1') |
---|
463 | n/a | self.assertEqual(info['rely'], '0.2') |
---|
464 | n/a | self.assertEqual(info['relwidth'], '0.3') |
---|
465 | n/a | self.assertEqual(info['relheight'], '0.4') |
---|
466 | n/a | self.assertEqual(info['anchor'], 'se') |
---|
467 | n/a | self.assertEqual(info['bordermode'], 'outside') |
---|
468 | n/a | self.assertEqual(info['x'], '1') |
---|
469 | n/a | self.assertEqual(info['x'], '1') |
---|
470 | n/a | with self.assertRaises(TypeError): |
---|
471 | n/a | f2.place_info(0) |
---|
472 | n/a | |
---|
473 | n/a | def test_place_slaves(self): |
---|
474 | n/a | foo = tkinter.Frame(self.root) |
---|
475 | n/a | bar = tkinter.Frame(self.root) |
---|
476 | n/a | self.assertEqual(foo.place_slaves(), []) |
---|
477 | n/a | bar.place_configure(in_=foo) |
---|
478 | n/a | self.assertEqual(foo.place_slaves(), [bar]) |
---|
479 | n/a | with self.assertRaises(TypeError): |
---|
480 | n/a | foo.place_slaves(0) |
---|
481 | n/a | |
---|
482 | n/a | |
---|
483 | n/a | class GridTest(AbstractWidgetTest, unittest.TestCase): |
---|
484 | n/a | |
---|
485 | n/a | test_keys = None |
---|
486 | n/a | |
---|
487 | n/a | def tearDown(self): |
---|
488 | n/a | cols, rows = self.root.grid_size() |
---|
489 | n/a | for i in range(cols + 1): |
---|
490 | n/a | self.root.grid_columnconfigure(i, weight=0, minsize=0, pad=0, uniform='') |
---|
491 | n/a | for i in range(rows + 1): |
---|
492 | n/a | self.root.grid_rowconfigure(i, weight=0, minsize=0, pad=0, uniform='') |
---|
493 | n/a | self.root.grid_propagate(1) |
---|
494 | n/a | if tcl_version >= (8, 5): |
---|
495 | n/a | self.root.grid_anchor('nw') |
---|
496 | n/a | super().tearDown() |
---|
497 | n/a | |
---|
498 | n/a | def test_grid_configure(self): |
---|
499 | n/a | b = tkinter.Button(self.root) |
---|
500 | n/a | self.assertEqual(b.grid_info(), {}) |
---|
501 | n/a | b.grid_configure() |
---|
502 | n/a | self.assertEqual(b.grid_info()['in'], self.root) |
---|
503 | n/a | self.assertEqual(b.grid_info()['column'], self._str(0)) |
---|
504 | n/a | self.assertEqual(b.grid_info()['row'], self._str(0)) |
---|
505 | n/a | b.grid_configure({'column': 1}, row=2) |
---|
506 | n/a | self.assertEqual(b.grid_info()['column'], self._str(1)) |
---|
507 | n/a | self.assertEqual(b.grid_info()['row'], self._str(2)) |
---|
508 | n/a | |
---|
509 | n/a | def test_grid_configure_column(self): |
---|
510 | n/a | b = tkinter.Button(self.root) |
---|
511 | n/a | with self.assertRaisesRegex(TclError, 'bad column value "-1": ' |
---|
512 | n/a | 'must be a non-negative integer'): |
---|
513 | n/a | b.grid_configure(column=-1) |
---|
514 | n/a | b.grid_configure(column=2) |
---|
515 | n/a | self.assertEqual(b.grid_info()['column'], self._str(2)) |
---|
516 | n/a | |
---|
517 | n/a | def test_grid_configure_columnspan(self): |
---|
518 | n/a | b = tkinter.Button(self.root) |
---|
519 | n/a | with self.assertRaisesRegex(TclError, 'bad columnspan value "0": ' |
---|
520 | n/a | 'must be a positive integer'): |
---|
521 | n/a | b.grid_configure(columnspan=0) |
---|
522 | n/a | b.grid_configure(columnspan=2) |
---|
523 | n/a | self.assertEqual(b.grid_info()['columnspan'], self._str(2)) |
---|
524 | n/a | |
---|
525 | n/a | def test_grid_configure_in(self): |
---|
526 | n/a | f = tkinter.Frame(self.root) |
---|
527 | n/a | b = tkinter.Button(self.root) |
---|
528 | n/a | self.assertEqual(b.grid_info(), {}) |
---|
529 | n/a | b.grid_configure() |
---|
530 | n/a | self.assertEqual(b.grid_info()['in'], self.root) |
---|
531 | n/a | b.grid_configure(in_=f) |
---|
532 | n/a | self.assertEqual(b.grid_info()['in'], f) |
---|
533 | n/a | b.grid_configure({'in': self.root}) |
---|
534 | n/a | self.assertEqual(b.grid_info()['in'], self.root) |
---|
535 | n/a | |
---|
536 | n/a | def test_grid_configure_ipadx(self): |
---|
537 | n/a | b = tkinter.Button(self.root) |
---|
538 | n/a | with self.assertRaisesRegex(TclError, 'bad ipadx value "-1": ' |
---|
539 | n/a | 'must be positive screen distance'): |
---|
540 | n/a | b.grid_configure(ipadx=-1) |
---|
541 | n/a | b.grid_configure(ipadx=1) |
---|
542 | n/a | self.assertEqual(b.grid_info()['ipadx'], self._str(1)) |
---|
543 | n/a | b.grid_configure(ipadx='.5c') |
---|
544 | n/a | self.assertEqual(b.grid_info()['ipadx'], |
---|
545 | n/a | self._str(round(pixels_conv('.5c') * self.scaling))) |
---|
546 | n/a | |
---|
547 | n/a | def test_grid_configure_ipady(self): |
---|
548 | n/a | b = tkinter.Button(self.root) |
---|
549 | n/a | with self.assertRaisesRegex(TclError, 'bad ipady value "-1": ' |
---|
550 | n/a | 'must be positive screen distance'): |
---|
551 | n/a | b.grid_configure(ipady=-1) |
---|
552 | n/a | b.grid_configure(ipady=1) |
---|
553 | n/a | self.assertEqual(b.grid_info()['ipady'], self._str(1)) |
---|
554 | n/a | b.grid_configure(ipady='.5c') |
---|
555 | n/a | self.assertEqual(b.grid_info()['ipady'], |
---|
556 | n/a | self._str(round(pixels_conv('.5c') * self.scaling))) |
---|
557 | n/a | |
---|
558 | n/a | def test_grid_configure_padx(self): |
---|
559 | n/a | b = tkinter.Button(self.root) |
---|
560 | n/a | with self.assertRaisesRegex(TclError, 'bad pad value "-1": ' |
---|
561 | n/a | 'must be positive screen distance'): |
---|
562 | n/a | b.grid_configure(padx=-1) |
---|
563 | n/a | b.grid_configure(padx=1) |
---|
564 | n/a | self.assertEqual(b.grid_info()['padx'], self._str(1)) |
---|
565 | n/a | b.grid_configure(padx=(10, 5)) |
---|
566 | n/a | self.assertEqual(b.grid_info()['padx'], self._str((10, 5))) |
---|
567 | n/a | b.grid_configure(padx='.5c') |
---|
568 | n/a | self.assertEqual(b.grid_info()['padx'], |
---|
569 | n/a | self._str(round(pixels_conv('.5c') * self.scaling))) |
---|
570 | n/a | |
---|
571 | n/a | def test_grid_configure_pady(self): |
---|
572 | n/a | b = tkinter.Button(self.root) |
---|
573 | n/a | with self.assertRaisesRegex(TclError, 'bad pad value "-1": ' |
---|
574 | n/a | 'must be positive screen distance'): |
---|
575 | n/a | b.grid_configure(pady=-1) |
---|
576 | n/a | b.grid_configure(pady=1) |
---|
577 | n/a | self.assertEqual(b.grid_info()['pady'], self._str(1)) |
---|
578 | n/a | b.grid_configure(pady=(10, 5)) |
---|
579 | n/a | self.assertEqual(b.grid_info()['pady'], self._str((10, 5))) |
---|
580 | n/a | b.grid_configure(pady='.5c') |
---|
581 | n/a | self.assertEqual(b.grid_info()['pady'], |
---|
582 | n/a | self._str(round(pixels_conv('.5c') * self.scaling))) |
---|
583 | n/a | |
---|
584 | n/a | def test_grid_configure_row(self): |
---|
585 | n/a | b = tkinter.Button(self.root) |
---|
586 | n/a | with self.assertRaisesRegex(TclError, 'bad (row|grid) value "-1": ' |
---|
587 | n/a | 'must be a non-negative integer'): |
---|
588 | n/a | b.grid_configure(row=-1) |
---|
589 | n/a | b.grid_configure(row=2) |
---|
590 | n/a | self.assertEqual(b.grid_info()['row'], self._str(2)) |
---|
591 | n/a | |
---|
592 | n/a | def test_grid_configure_rownspan(self): |
---|
593 | n/a | b = tkinter.Button(self.root) |
---|
594 | n/a | with self.assertRaisesRegex(TclError, 'bad rowspan value "0": ' |
---|
595 | n/a | 'must be a positive integer'): |
---|
596 | n/a | b.grid_configure(rowspan=0) |
---|
597 | n/a | b.grid_configure(rowspan=2) |
---|
598 | n/a | self.assertEqual(b.grid_info()['rowspan'], self._str(2)) |
---|
599 | n/a | |
---|
600 | n/a | def test_grid_configure_sticky(self): |
---|
601 | n/a | f = tkinter.Frame(self.root, bg='red') |
---|
602 | n/a | with self.assertRaisesRegex(TclError, 'bad stickyness value "glue"'): |
---|
603 | n/a | f.grid_configure(sticky='glue') |
---|
604 | n/a | f.grid_configure(sticky='ne') |
---|
605 | n/a | self.assertEqual(f.grid_info()['sticky'], 'ne') |
---|
606 | n/a | f.grid_configure(sticky='n,s,e,w') |
---|
607 | n/a | self.assertEqual(f.grid_info()['sticky'], 'nesw') |
---|
608 | n/a | |
---|
609 | n/a | def test_grid_columnconfigure(self): |
---|
610 | n/a | with self.assertRaises(TypeError): |
---|
611 | n/a | self.root.grid_columnconfigure() |
---|
612 | n/a | self.assertEqual(self.root.grid_columnconfigure(0), |
---|
613 | n/a | {'minsize': 0, 'pad': 0, 'uniform': None, 'weight': 0}) |
---|
614 | n/a | with self.assertRaisesRegex(TclError, 'bad option "-foo"'): |
---|
615 | n/a | self.root.grid_columnconfigure(0, 'foo') |
---|
616 | n/a | self.root.grid_columnconfigure((0, 3), weight=2) |
---|
617 | n/a | with self.assertRaisesRegex(TclError, |
---|
618 | n/a | 'must specify a single element on retrieval'): |
---|
619 | n/a | self.root.grid_columnconfigure((0, 3)) |
---|
620 | n/a | b = tkinter.Button(self.root) |
---|
621 | n/a | b.grid_configure(column=0, row=0) |
---|
622 | n/a | if tcl_version >= (8, 5): |
---|
623 | n/a | self.root.grid_columnconfigure('all', weight=3) |
---|
624 | n/a | with self.assertRaisesRegex(TclError, 'expected integer but got "all"'): |
---|
625 | n/a | self.root.grid_columnconfigure('all') |
---|
626 | n/a | self.assertEqual(self.root.grid_columnconfigure(0, 'weight'), 3) |
---|
627 | n/a | self.assertEqual(self.root.grid_columnconfigure(3, 'weight'), 2) |
---|
628 | n/a | self.assertEqual(self.root.grid_columnconfigure(265, 'weight'), 0) |
---|
629 | n/a | if tcl_version >= (8, 5): |
---|
630 | n/a | self.root.grid_columnconfigure(b, weight=4) |
---|
631 | n/a | self.assertEqual(self.root.grid_columnconfigure(0, 'weight'), 4) |
---|
632 | n/a | |
---|
633 | n/a | def test_grid_columnconfigure_minsize(self): |
---|
634 | n/a | with self.assertRaisesRegex(TclError, 'bad screen distance "foo"'): |
---|
635 | n/a | self.root.grid_columnconfigure(0, minsize='foo') |
---|
636 | n/a | self.root.grid_columnconfigure(0, minsize=10) |
---|
637 | n/a | self.assertEqual(self.root.grid_columnconfigure(0, 'minsize'), 10) |
---|
638 | n/a | self.assertEqual(self.root.grid_columnconfigure(0)['minsize'], 10) |
---|
639 | n/a | |
---|
640 | n/a | def test_grid_columnconfigure_weight(self): |
---|
641 | n/a | with self.assertRaisesRegex(TclError, 'expected integer but got "bad"'): |
---|
642 | n/a | self.root.grid_columnconfigure(0, weight='bad') |
---|
643 | n/a | with self.assertRaisesRegex(TclError, 'invalid arg "-weight": ' |
---|
644 | n/a | 'should be non-negative'): |
---|
645 | n/a | self.root.grid_columnconfigure(0, weight=-3) |
---|
646 | n/a | self.root.grid_columnconfigure(0, weight=3) |
---|
647 | n/a | self.assertEqual(self.root.grid_columnconfigure(0, 'weight'), 3) |
---|
648 | n/a | self.assertEqual(self.root.grid_columnconfigure(0)['weight'], 3) |
---|
649 | n/a | |
---|
650 | n/a | def test_grid_columnconfigure_pad(self): |
---|
651 | n/a | with self.assertRaisesRegex(TclError, 'bad screen distance "foo"'): |
---|
652 | n/a | self.root.grid_columnconfigure(0, pad='foo') |
---|
653 | n/a | with self.assertRaisesRegex(TclError, 'invalid arg "-pad": ' |
---|
654 | n/a | 'should be non-negative'): |
---|
655 | n/a | self.root.grid_columnconfigure(0, pad=-3) |
---|
656 | n/a | self.root.grid_columnconfigure(0, pad=3) |
---|
657 | n/a | self.assertEqual(self.root.grid_columnconfigure(0, 'pad'), 3) |
---|
658 | n/a | self.assertEqual(self.root.grid_columnconfigure(0)['pad'], 3) |
---|
659 | n/a | |
---|
660 | n/a | def test_grid_columnconfigure_uniform(self): |
---|
661 | n/a | self.root.grid_columnconfigure(0, uniform='foo') |
---|
662 | n/a | self.assertEqual(self.root.grid_columnconfigure(0, 'uniform'), 'foo') |
---|
663 | n/a | self.assertEqual(self.root.grid_columnconfigure(0)['uniform'], 'foo') |
---|
664 | n/a | |
---|
665 | n/a | def test_grid_rowconfigure(self): |
---|
666 | n/a | with self.assertRaises(TypeError): |
---|
667 | n/a | self.root.grid_rowconfigure() |
---|
668 | n/a | self.assertEqual(self.root.grid_rowconfigure(0), |
---|
669 | n/a | {'minsize': 0, 'pad': 0, 'uniform': None, 'weight': 0}) |
---|
670 | n/a | with self.assertRaisesRegex(TclError, 'bad option "-foo"'): |
---|
671 | n/a | self.root.grid_rowconfigure(0, 'foo') |
---|
672 | n/a | self.root.grid_rowconfigure((0, 3), weight=2) |
---|
673 | n/a | with self.assertRaisesRegex(TclError, |
---|
674 | n/a | 'must specify a single element on retrieval'): |
---|
675 | n/a | self.root.grid_rowconfigure((0, 3)) |
---|
676 | n/a | b = tkinter.Button(self.root) |
---|
677 | n/a | b.grid_configure(column=0, row=0) |
---|
678 | n/a | if tcl_version >= (8, 5): |
---|
679 | n/a | self.root.grid_rowconfigure('all', weight=3) |
---|
680 | n/a | with self.assertRaisesRegex(TclError, 'expected integer but got "all"'): |
---|
681 | n/a | self.root.grid_rowconfigure('all') |
---|
682 | n/a | self.assertEqual(self.root.grid_rowconfigure(0, 'weight'), 3) |
---|
683 | n/a | self.assertEqual(self.root.grid_rowconfigure(3, 'weight'), 2) |
---|
684 | n/a | self.assertEqual(self.root.grid_rowconfigure(265, 'weight'), 0) |
---|
685 | n/a | if tcl_version >= (8, 5): |
---|
686 | n/a | self.root.grid_rowconfigure(b, weight=4) |
---|
687 | n/a | self.assertEqual(self.root.grid_rowconfigure(0, 'weight'), 4) |
---|
688 | n/a | |
---|
689 | n/a | def test_grid_rowconfigure_minsize(self): |
---|
690 | n/a | with self.assertRaisesRegex(TclError, 'bad screen distance "foo"'): |
---|
691 | n/a | self.root.grid_rowconfigure(0, minsize='foo') |
---|
692 | n/a | self.root.grid_rowconfigure(0, minsize=10) |
---|
693 | n/a | self.assertEqual(self.root.grid_rowconfigure(0, 'minsize'), 10) |
---|
694 | n/a | self.assertEqual(self.root.grid_rowconfigure(0)['minsize'], 10) |
---|
695 | n/a | |
---|
696 | n/a | def test_grid_rowconfigure_weight(self): |
---|
697 | n/a | with self.assertRaisesRegex(TclError, 'expected integer but got "bad"'): |
---|
698 | n/a | self.root.grid_rowconfigure(0, weight='bad') |
---|
699 | n/a | with self.assertRaisesRegex(TclError, 'invalid arg "-weight": ' |
---|
700 | n/a | 'should be non-negative'): |
---|
701 | n/a | self.root.grid_rowconfigure(0, weight=-3) |
---|
702 | n/a | self.root.grid_rowconfigure(0, weight=3) |
---|
703 | n/a | self.assertEqual(self.root.grid_rowconfigure(0, 'weight'), 3) |
---|
704 | n/a | self.assertEqual(self.root.grid_rowconfigure(0)['weight'], 3) |
---|
705 | n/a | |
---|
706 | n/a | def test_grid_rowconfigure_pad(self): |
---|
707 | n/a | with self.assertRaisesRegex(TclError, 'bad screen distance "foo"'): |
---|
708 | n/a | self.root.grid_rowconfigure(0, pad='foo') |
---|
709 | n/a | with self.assertRaisesRegex(TclError, 'invalid arg "-pad": ' |
---|
710 | n/a | 'should be non-negative'): |
---|
711 | n/a | self.root.grid_rowconfigure(0, pad=-3) |
---|
712 | n/a | self.root.grid_rowconfigure(0, pad=3) |
---|
713 | n/a | self.assertEqual(self.root.grid_rowconfigure(0, 'pad'), 3) |
---|
714 | n/a | self.assertEqual(self.root.grid_rowconfigure(0)['pad'], 3) |
---|
715 | n/a | |
---|
716 | n/a | def test_grid_rowconfigure_uniform(self): |
---|
717 | n/a | self.root.grid_rowconfigure(0, uniform='foo') |
---|
718 | n/a | self.assertEqual(self.root.grid_rowconfigure(0, 'uniform'), 'foo') |
---|
719 | n/a | self.assertEqual(self.root.grid_rowconfigure(0)['uniform'], 'foo') |
---|
720 | n/a | |
---|
721 | n/a | def test_grid_forget(self): |
---|
722 | n/a | b = tkinter.Button(self.root) |
---|
723 | n/a | c = tkinter.Button(self.root) |
---|
724 | n/a | b.grid_configure(row=2, column=2, rowspan=2, columnspan=2, |
---|
725 | n/a | padx=3, pady=4, sticky='ns') |
---|
726 | n/a | self.assertEqual(self.root.grid_slaves(), [b]) |
---|
727 | n/a | b.grid_forget() |
---|
728 | n/a | c.grid_forget() |
---|
729 | n/a | self.assertEqual(self.root.grid_slaves(), []) |
---|
730 | n/a | self.assertEqual(b.grid_info(), {}) |
---|
731 | n/a | b.grid_configure(row=0, column=0) |
---|
732 | n/a | info = b.grid_info() |
---|
733 | n/a | self.assertEqual(info['row'], self._str(0)) |
---|
734 | n/a | self.assertEqual(info['column'], self._str(0)) |
---|
735 | n/a | self.assertEqual(info['rowspan'], self._str(1)) |
---|
736 | n/a | self.assertEqual(info['columnspan'], self._str(1)) |
---|
737 | n/a | self.assertEqual(info['padx'], self._str(0)) |
---|
738 | n/a | self.assertEqual(info['pady'], self._str(0)) |
---|
739 | n/a | self.assertEqual(info['sticky'], '') |
---|
740 | n/a | |
---|
741 | n/a | def test_grid_remove(self): |
---|
742 | n/a | b = tkinter.Button(self.root) |
---|
743 | n/a | c = tkinter.Button(self.root) |
---|
744 | n/a | b.grid_configure(row=2, column=2, rowspan=2, columnspan=2, |
---|
745 | n/a | padx=3, pady=4, sticky='ns') |
---|
746 | n/a | self.assertEqual(self.root.grid_slaves(), [b]) |
---|
747 | n/a | b.grid_remove() |
---|
748 | n/a | c.grid_remove() |
---|
749 | n/a | self.assertEqual(self.root.grid_slaves(), []) |
---|
750 | n/a | self.assertEqual(b.grid_info(), {}) |
---|
751 | n/a | b.grid_configure(row=0, column=0) |
---|
752 | n/a | info = b.grid_info() |
---|
753 | n/a | self.assertEqual(info['row'], self._str(0)) |
---|
754 | n/a | self.assertEqual(info['column'], self._str(0)) |
---|
755 | n/a | self.assertEqual(info['rowspan'], self._str(2)) |
---|
756 | n/a | self.assertEqual(info['columnspan'], self._str(2)) |
---|
757 | n/a | self.assertEqual(info['padx'], self._str(3)) |
---|
758 | n/a | self.assertEqual(info['pady'], self._str(4)) |
---|
759 | n/a | self.assertEqual(info['sticky'], 'ns') |
---|
760 | n/a | |
---|
761 | n/a | def test_grid_info(self): |
---|
762 | n/a | b = tkinter.Button(self.root) |
---|
763 | n/a | self.assertEqual(b.grid_info(), {}) |
---|
764 | n/a | b.grid_configure(row=2, column=2, rowspan=2, columnspan=2, |
---|
765 | n/a | padx=3, pady=4, sticky='ns') |
---|
766 | n/a | info = b.grid_info() |
---|
767 | n/a | self.assertIsInstance(info, dict) |
---|
768 | n/a | self.assertEqual(info['in'], self.root) |
---|
769 | n/a | self.assertEqual(info['row'], self._str(2)) |
---|
770 | n/a | self.assertEqual(info['column'], self._str(2)) |
---|
771 | n/a | self.assertEqual(info['rowspan'], self._str(2)) |
---|
772 | n/a | self.assertEqual(info['columnspan'], self._str(2)) |
---|
773 | n/a | self.assertEqual(info['padx'], self._str(3)) |
---|
774 | n/a | self.assertEqual(info['pady'], self._str(4)) |
---|
775 | n/a | self.assertEqual(info['sticky'], 'ns') |
---|
776 | n/a | |
---|
777 | n/a | @requires_tcl(8, 5) |
---|
778 | n/a | def test_grid_anchor(self): |
---|
779 | n/a | with self.assertRaisesRegex(TclError, 'bad anchor "x"'): |
---|
780 | n/a | self.root.grid_anchor('x') |
---|
781 | n/a | with self.assertRaisesRegex(TclError, 'ambiguous anchor ""'): |
---|
782 | n/a | self.root.grid_anchor('') |
---|
783 | n/a | with self.assertRaises(TypeError): |
---|
784 | n/a | self.root.grid_anchor('se', 'nw') |
---|
785 | n/a | self.root.grid_anchor('se') |
---|
786 | n/a | self.assertEqual(self.root.tk.call('grid', 'anchor', self.root), 'se') |
---|
787 | n/a | |
---|
788 | n/a | def test_grid_bbox(self): |
---|
789 | n/a | self.assertEqual(self.root.grid_bbox(), (0, 0, 0, 0)) |
---|
790 | n/a | self.assertEqual(self.root.grid_bbox(0, 0), (0, 0, 0, 0)) |
---|
791 | n/a | self.assertEqual(self.root.grid_bbox(0, 0, 1, 1), (0, 0, 0, 0)) |
---|
792 | n/a | with self.assertRaisesRegex(TclError, 'expected integer but got "x"'): |
---|
793 | n/a | self.root.grid_bbox('x', 0) |
---|
794 | n/a | with self.assertRaisesRegex(TclError, 'expected integer but got "x"'): |
---|
795 | n/a | self.root.grid_bbox(0, 'x') |
---|
796 | n/a | with self.assertRaisesRegex(TclError, 'expected integer but got "x"'): |
---|
797 | n/a | self.root.grid_bbox(0, 0, 'x', 0) |
---|
798 | n/a | with self.assertRaisesRegex(TclError, 'expected integer but got "x"'): |
---|
799 | n/a | self.root.grid_bbox(0, 0, 0, 'x') |
---|
800 | n/a | with self.assertRaises(TypeError): |
---|
801 | n/a | self.root.grid_bbox(0, 0, 0, 0, 0) |
---|
802 | n/a | t = self.root |
---|
803 | n/a | # de-maximize |
---|
804 | n/a | t.wm_geometry('1x1+0+0') |
---|
805 | n/a | t.wm_geometry('') |
---|
806 | n/a | f1 = tkinter.Frame(t, width=75, height=75, bg='red') |
---|
807 | n/a | f2 = tkinter.Frame(t, width=90, height=90, bg='blue') |
---|
808 | n/a | f1.grid_configure(row=0, column=0) |
---|
809 | n/a | f2.grid_configure(row=1, column=1) |
---|
810 | n/a | self.root.update() |
---|
811 | n/a | self.assertEqual(t.grid_bbox(), (0, 0, 165, 165)) |
---|
812 | n/a | self.assertEqual(t.grid_bbox(0, 0), (0, 0, 75, 75)) |
---|
813 | n/a | self.assertEqual(t.grid_bbox(0, 0, 1, 1), (0, 0, 165, 165)) |
---|
814 | n/a | self.assertEqual(t.grid_bbox(1, 1), (75, 75, 90, 90)) |
---|
815 | n/a | self.assertEqual(t.grid_bbox(10, 10, 0, 0), (0, 0, 165, 165)) |
---|
816 | n/a | self.assertEqual(t.grid_bbox(-2, -2, -1, -1), (0, 0, 0, 0)) |
---|
817 | n/a | self.assertEqual(t.grid_bbox(10, 10, 12, 12), (165, 165, 0, 0)) |
---|
818 | n/a | |
---|
819 | n/a | def test_grid_location(self): |
---|
820 | n/a | with self.assertRaises(TypeError): |
---|
821 | n/a | self.root.grid_location() |
---|
822 | n/a | with self.assertRaises(TypeError): |
---|
823 | n/a | self.root.grid_location(0) |
---|
824 | n/a | with self.assertRaises(TypeError): |
---|
825 | n/a | self.root.grid_location(0, 0, 0) |
---|
826 | n/a | with self.assertRaisesRegex(TclError, 'bad screen distance "x"'): |
---|
827 | n/a | self.root.grid_location('x', 'y') |
---|
828 | n/a | with self.assertRaisesRegex(TclError, 'bad screen distance "y"'): |
---|
829 | n/a | self.root.grid_location('1c', 'y') |
---|
830 | n/a | t = self.root |
---|
831 | n/a | # de-maximize |
---|
832 | n/a | t.wm_geometry('1x1+0+0') |
---|
833 | n/a | t.wm_geometry('') |
---|
834 | n/a | f = tkinter.Frame(t, width=200, height=100, |
---|
835 | n/a | highlightthickness=0, bg='red') |
---|
836 | n/a | self.assertEqual(f.grid_location(10, 10), (-1, -1)) |
---|
837 | n/a | f.grid_configure() |
---|
838 | n/a | self.root.update() |
---|
839 | n/a | self.assertEqual(t.grid_location(-10, -10), (-1, -1)) |
---|
840 | n/a | self.assertEqual(t.grid_location(-10, 0), (-1, 0)) |
---|
841 | n/a | self.assertEqual(t.grid_location(-1, 0), (-1, 0)) |
---|
842 | n/a | self.assertEqual(t.grid_location(0, -10), (0, -1)) |
---|
843 | n/a | self.assertEqual(t.grid_location(0, -1), (0, -1)) |
---|
844 | n/a | self.assertEqual(t.grid_location(0, 0), (0, 0)) |
---|
845 | n/a | self.assertEqual(t.grid_location(200, 0), (0, 0)) |
---|
846 | n/a | self.assertEqual(t.grid_location(201, 0), (1, 0)) |
---|
847 | n/a | self.assertEqual(t.grid_location(0, 100), (0, 0)) |
---|
848 | n/a | self.assertEqual(t.grid_location(0, 101), (0, 1)) |
---|
849 | n/a | self.assertEqual(t.grid_location(201, 101), (1, 1)) |
---|
850 | n/a | |
---|
851 | n/a | def test_grid_propagate(self): |
---|
852 | n/a | self.assertEqual(self.root.grid_propagate(), True) |
---|
853 | n/a | with self.assertRaises(TypeError): |
---|
854 | n/a | self.root.grid_propagate(False, False) |
---|
855 | n/a | self.root.grid_propagate(False) |
---|
856 | n/a | self.assertFalse(self.root.grid_propagate()) |
---|
857 | n/a | f = tkinter.Frame(self.root, width=100, height=100, bg='red') |
---|
858 | n/a | f.grid_configure(row=0, column=0) |
---|
859 | n/a | self.root.update() |
---|
860 | n/a | self.assertEqual(f.winfo_width(), 100) |
---|
861 | n/a | self.assertEqual(f.winfo_height(), 100) |
---|
862 | n/a | f.grid_propagate(False) |
---|
863 | n/a | g = tkinter.Frame(self.root, width=75, height=85, bg='green') |
---|
864 | n/a | g.grid_configure(in_=f, row=0, column=0) |
---|
865 | n/a | self.root.update() |
---|
866 | n/a | self.assertEqual(f.winfo_width(), 100) |
---|
867 | n/a | self.assertEqual(f.winfo_height(), 100) |
---|
868 | n/a | f.grid_propagate(True) |
---|
869 | n/a | self.root.update() |
---|
870 | n/a | self.assertEqual(f.winfo_width(), 75) |
---|
871 | n/a | self.assertEqual(f.winfo_height(), 85) |
---|
872 | n/a | |
---|
873 | n/a | def test_grid_size(self): |
---|
874 | n/a | with self.assertRaises(TypeError): |
---|
875 | n/a | self.root.grid_size(0) |
---|
876 | n/a | self.assertEqual(self.root.grid_size(), (0, 0)) |
---|
877 | n/a | f = tkinter.Scale(self.root) |
---|
878 | n/a | f.grid_configure(row=0, column=0) |
---|
879 | n/a | self.assertEqual(self.root.grid_size(), (1, 1)) |
---|
880 | n/a | f.grid_configure(row=4, column=5) |
---|
881 | n/a | self.assertEqual(self.root.grid_size(), (6, 5)) |
---|
882 | n/a | |
---|
883 | n/a | def test_grid_slaves(self): |
---|
884 | n/a | self.assertEqual(self.root.grid_slaves(), []) |
---|
885 | n/a | a = tkinter.Label(self.root) |
---|
886 | n/a | a.grid_configure(row=0, column=1) |
---|
887 | n/a | b = tkinter.Label(self.root) |
---|
888 | n/a | b.grid_configure(row=1, column=0) |
---|
889 | n/a | c = tkinter.Label(self.root) |
---|
890 | n/a | c.grid_configure(row=1, column=1) |
---|
891 | n/a | d = tkinter.Label(self.root) |
---|
892 | n/a | d.grid_configure(row=1, column=1) |
---|
893 | n/a | self.assertEqual(self.root.grid_slaves(), [d, c, b, a]) |
---|
894 | n/a | self.assertEqual(self.root.grid_slaves(row=0), [a]) |
---|
895 | n/a | self.assertEqual(self.root.grid_slaves(row=1), [d, c, b]) |
---|
896 | n/a | self.assertEqual(self.root.grid_slaves(column=0), [b]) |
---|
897 | n/a | self.assertEqual(self.root.grid_slaves(column=1), [d, c, a]) |
---|
898 | n/a | self.assertEqual(self.root.grid_slaves(row=1, column=1), [d, c]) |
---|
899 | n/a | |
---|
900 | n/a | |
---|
901 | n/a | tests_gui = ( |
---|
902 | n/a | PackTest, PlaceTest, GridTest, |
---|
903 | n/a | ) |
---|
904 | n/a | |
---|
905 | n/a | if __name__ == '__main__': |
---|
906 | n/a | unittest.main() |
---|