Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
tkinter.test.test_ttk.test_widgets.NotebookTest Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def test_tab_identifiers
def test_add_and_hidden
def test_forget
def test_index
def test_insert
def test_select
def test_tab
def test_tabs
def test_traversal

Public Attributes

 nb
 child1
 child2

Detailed Description

Definition at line 534 of file test_widgets.py.


Member Function Documentation

Definition at line 536 of file test_widgets.py.

00536 
00537     def setUp(self):
00538         support.root_deiconify()
00539         self.nb = ttk.Notebook(padding=0)
00540         self.child1 = ttk.Label()
00541         self.child2 = ttk.Label()
00542         self.nb.add(self.child1, text='a')
00543         self.nb.add(self.child2, text='b')

Here is the caller graph for this function:

Definition at line 544 of file test_widgets.py.

00544 
00545     def tearDown(self):
00546         self.child1.destroy()
00547         self.child2.destroy()
00548         self.nb.destroy()
00549         support.root_withdraw()
00550 

Here is the caller graph for this function:

Definition at line 582 of file test_widgets.py.

00582 
00583     def test_add_and_hidden(self):
00584         self.assertRaises(tkinter.TclError, self.nb.hide, -1)
00585         self.assertRaises(tkinter.TclError, self.nb.hide, 'hi')
00586         self.assertRaises(tkinter.TclError, self.nb.hide, None)
00587         self.assertRaises(tkinter.TclError, self.nb.add, None)
00588         self.assertRaises(tkinter.TclError, self.nb.add, ttk.Label(),
00589             unknown='option')
00590 
00591         tabs = self.nb.tabs()
00592         self.nb.hide(self.child1)
00593         self.nb.add(self.child1)
00594         self.assertEqual(self.nb.tabs(), tabs)
00595 
00596         child = ttk.Label()
00597         self.nb.add(child, text='c')
00598         tabs = self.nb.tabs()
00599 
00600         curr = self.nb.index('current')
00601         # verify that the tab gets readded at its previous position
00602         child2_index = self.nb.index(self.child2)
00603         self.nb.hide(self.child2)
00604         self.nb.add(self.child2)
00605         self.assertEqual(self.nb.tabs(), tabs)
00606         self.assertEqual(self.nb.index(self.child2), child2_index)
00607         self.assertTrue(str(self.child2) == self.nb.tabs()[child2_index])
00608         # but the tab next to it (not hidden) is the one selected now
00609         self.assertEqual(self.nb.index('current'), curr + 1)
00610 

Here is the call graph for this function:

Definition at line 611 of file test_widgets.py.

00611 
00612     def test_forget(self):
00613         self.assertRaises(tkinter.TclError, self.nb.forget, -1)
00614         self.assertRaises(tkinter.TclError, self.nb.forget, 'hi')
00615         self.assertRaises(tkinter.TclError, self.nb.forget, None)
00616 
00617         tabs = self.nb.tabs()
00618         child1_index = self.nb.index(self.child1)
00619         self.nb.forget(self.child1)
00620         self.assertFalse(str(self.child1) in self.nb.tabs())
00621         self.assertEqual(len(tabs) - 1, len(self.nb.tabs()))
00622 
00623         self.nb.add(self.child1)
00624         self.assertEqual(self.nb.index(self.child1), 1)
00625         self.assertFalse(child1_index == self.nb.index(self.child1))
00626 

Here is the call graph for this function:

Definition at line 627 of file test_widgets.py.

00627 
00628     def test_index(self):
00629         self.assertRaises(tkinter.TclError, self.nb.index, -1)
00630         self.assertRaises(tkinter.TclError, self.nb.index, None)
00631 
00632         self.assertTrue(isinstance(self.nb.index('end'), int))
00633         self.assertEqual(self.nb.index(self.child1), 0)
00634         self.assertEqual(self.nb.index(self.child2), 1)
00635         self.assertEqual(self.nb.index('end'), 2)
00636 

Here is the call graph for this function:

Definition at line 637 of file test_widgets.py.

00637 
00638     def test_insert(self):
00639         # moving tabs
00640         tabs = self.nb.tabs()
00641         self.nb.insert(1, tabs[0])
00642         self.assertEqual(self.nb.tabs(), (tabs[1], tabs[0]))
00643         self.nb.insert(self.child1, self.child2)
00644         self.assertEqual(self.nb.tabs(), tabs)
00645         self.nb.insert('end', self.child1)
00646         self.assertEqual(self.nb.tabs(), (tabs[1], tabs[0]))
00647         self.nb.insert('end', 0)
00648         self.assertEqual(self.nb.tabs(), tabs)
00649         # bad moves
00650         self.assertRaises(tkinter.TclError, self.nb.insert, 2, tabs[0])
00651         self.assertRaises(tkinter.TclError, self.nb.insert, -1, tabs[0])
00652 
00653         # new tab
00654         child3 = ttk.Label()
00655         self.nb.insert(1, child3)
00656         self.assertEqual(self.nb.tabs(), (tabs[0], str(child3), tabs[1]))
00657         self.nb.forget(child3)
00658         self.assertEqual(self.nb.tabs(), tabs)
00659         self.nb.insert(self.child1, child3)
00660         self.assertEqual(self.nb.tabs(), (str(child3), ) + tabs)
00661         self.nb.forget(child3)
00662         self.assertRaises(tkinter.TclError, self.nb.insert, 2, child3)
00663         self.assertRaises(tkinter.TclError, self.nb.insert, -1, child3)
00664 
00665         # bad inserts
00666         self.assertRaises(tkinter.TclError, self.nb.insert, 'end', None)
00667         self.assertRaises(tkinter.TclError, self.nb.insert, None, 0)
00668         self.assertRaises(tkinter.TclError, self.nb.insert, None, None)
00669 

Here is the call graph for this function:

Definition at line 670 of file test_widgets.py.

00670 
00671     def test_select(self):
00672         self.nb.pack()
00673         self.nb.wait_visibility()
00674 
00675         success = []
00676         tab_changed = []
00677 
00678         self.child1.bind('<Unmap>', lambda evt: success.append(True))
00679         self.nb.bind('<<NotebookTabChanged>>',
00680             lambda evt: tab_changed.append(True))
00681 
00682         self.assertEqual(self.nb.select(), str(self.child1))
00683         self.nb.select(self.child2)
00684         self.assertTrue(success)
00685         self.assertEqual(self.nb.select(), str(self.child2))
00686 
00687         self.nb.update()
00688         self.assertTrue(tab_changed)
00689 

Here is the call graph for this function:

Definition at line 690 of file test_widgets.py.

00690 
00691     def test_tab(self):
00692         self.assertRaises(tkinter.TclError, self.nb.tab, -1)
00693         self.assertRaises(tkinter.TclError, self.nb.tab, 'notab')
00694         self.assertRaises(tkinter.TclError, self.nb.tab, None)
00695 
00696         self.assertTrue(isinstance(self.nb.tab(self.child1), dict))
00697         self.assertEqual(self.nb.tab(self.child1, text=None), 'a')
00698         # newer form for querying a single option
00699         self.assertEqual(self.nb.tab(self.child1, 'text'), 'a')
00700         self.nb.tab(self.child1, text='abc')
00701         self.assertEqual(self.nb.tab(self.child1, text=None), 'abc')
00702         self.assertEqual(self.nb.tab(self.child1, 'text'), 'abc')
00703 

Here is the call graph for this function:

Definition at line 551 of file test_widgets.py.

00551 
00552     def test_tab_identifiers(self):
00553         self.nb.forget(0)
00554         self.nb.hide(self.child2)
00555         self.assertRaises(tkinter.TclError, self.nb.tab, self.child1)
00556         self.assertEqual(self.nb.index('end'), 1)
00557         self.nb.add(self.child2)
00558         self.assertEqual(self.nb.index('end'), 1)
00559         self.nb.select(self.child2)
00560 
00561         self.assertTrue(self.nb.tab('current'))
00562         self.nb.add(self.child1, text='a')
00563 
00564         self.nb.pack()
00565         self.nb.wait_visibility()
00566         if sys.platform == 'darwin':
00567             tb_idx = "@20,5"
00568         else:
00569             tb_idx = "@5,5"
00570         self.assertEqual(self.nb.tab(tb_idx), self.nb.tab('current'))
00571 
00572         for i in range(5, 100, 5):
00573             try:
00574                 if self.nb.tab('@%d, 5' % i, text=None) == 'a':
00575                     break
00576             except tkinter.TclError:
00577                 pass
00578 
00579         else:
00580             self.fail("Tab with text 'a' not found")
00581 

Here is the call graph for this function:

Definition at line 704 of file test_widgets.py.

00704 
00705     def test_tabs(self):
00706         self.assertEqual(len(self.nb.tabs()), 2)
00707 
00708         self.nb.forget(self.child1)
00709         self.nb.forget(self.child2)
00710 
00711         self.assertEqual(self.nb.tabs(), ())
00712 

Here is the call graph for this function:

Definition at line 713 of file test_widgets.py.

00713 
00714     def test_traversal(self):
00715         self.nb.pack()
00716         self.nb.wait_visibility()
00717 
00718         self.nb.select(0)
00719 
00720         support.simulate_mouse_click(self.nb, 5, 5)
00721         self.nb.focus_force()
00722         self.nb.event_generate('<Control-Tab>')
00723         self.assertEqual(self.nb.select(), str(self.child2))
00724         self.nb.focus_force()
00725         self.nb.event_generate('<Shift-Control-Tab>')
00726         self.assertEqual(self.nb.select(), str(self.child1))
00727         self.nb.focus_force()
00728         self.nb.event_generate('<Shift-Control-Tab>')
00729         self.assertEqual(self.nb.select(), str(self.child2))
00730 
00731         self.nb.tab(self.child1, text='a', underline=0)
00732         self.nb.enable_traversal()
00733         self.nb.focus_force()
00734         support.simulate_mouse_click(self.nb, 5, 5)
00735         if sys.platform == 'darwin':
00736             self.nb.event_generate('<Option-a>')
00737         else:
00738             self.nb.event_generate('<Alt-a>')
00739         self.assertEqual(self.nb.select(), str(self.child1))
00740 

Here is the call graph for this function:


Member Data Documentation

Definition at line 539 of file test_widgets.py.

Definition at line 540 of file test_widgets.py.

Definition at line 538 of file test_widgets.py.


The documentation for this class was generated from the following file: