2009-01-28 10:41:10 -04:00
|
|
|
import unittest
|
|
|
|
import tkinter
|
|
|
|
from tkinter import ttk
|
2013-11-02 05:41:48 -03:00
|
|
|
from test.support import requires
|
2011-06-28 03:12:20 -03:00
|
|
|
import sys
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
import tkinter.test.support as support
|
2013-11-02 05:41:48 -03:00
|
|
|
from tkinter.test.test_ttk.test_functions import MockTclObj
|
|
|
|
from tkinter.test.support import tcl_version
|
|
|
|
from tkinter.test.widget_tests import (add_standard_options, noconv,
|
|
|
|
AbstractWidgetTest, StandardOptionsTests, IntegerSizeTests, PixelSizeTests)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
requires('gui')
|
|
|
|
|
2013-11-02 05:41:48 -03:00
|
|
|
|
|
|
|
class StandardTtkOptionsTests(StandardOptionsTests):
|
|
|
|
|
|
|
|
def test_class(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.assertEqual(widget['class'], '')
|
|
|
|
errmsg='attempt to change read-only option'
|
|
|
|
if tcl_version < (8, 6):
|
|
|
|
errmsg='Attempt to change read-only option'
|
|
|
|
self.checkInvalidParam(widget, 'class', 'Foo', errmsg=errmsg)
|
|
|
|
widget2 = self.create(class_='Foo')
|
|
|
|
self.assertEqual(widget2['class'], 'Foo')
|
|
|
|
|
|
|
|
def test_padding(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkParam(widget, 'padding', 0, expected=('0',))
|
|
|
|
self.checkParam(widget, 'padding', 5, expected=('5',))
|
|
|
|
self.checkParam(widget, 'padding', (5, 6), expected=('5', '6'))
|
|
|
|
self.checkParam(widget, 'padding', (5, 6, 7),
|
|
|
|
expected=('5', '6', '7'))
|
|
|
|
self.checkParam(widget, 'padding', (5, 6, 7, 8),
|
|
|
|
expected=('5', '6', '7', '8'))
|
|
|
|
self.checkParam(widget, 'padding', ('5p', '6p', '7p', '8p'))
|
|
|
|
self.checkParam(widget, 'padding', (), expected='')
|
|
|
|
|
|
|
|
def test_style(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.assertEqual(widget['style'], '')
|
|
|
|
errmsg = 'Layout Foo not found'
|
|
|
|
if hasattr(self, 'default_orient'):
|
|
|
|
errmsg = ('Layout %s.Foo not found' %
|
|
|
|
getattr(self, 'default_orient').title())
|
|
|
|
self.checkInvalidParam(widget, 'style', 'Foo',
|
|
|
|
errmsg=errmsg)
|
|
|
|
widget2 = self.create(class_='Foo')
|
|
|
|
self.assertEqual(widget2['class'], 'Foo')
|
|
|
|
# XXX
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2009-01-28 10:41:10 -04:00
|
|
|
class WidgetTest(unittest.TestCase):
|
|
|
|
"""Tests methods available in every ttk widget."""
|
|
|
|
|
|
|
|
def setUp(self):
|
2009-02-01 21:02:20 -04:00
|
|
|
support.root_deiconify()
|
2010-09-26 13:36:33 -03:00
|
|
|
self.widget = ttk.Button(width=0, text="Text")
|
2009-01-28 10:41:10 -04:00
|
|
|
self.widget.pack()
|
|
|
|
self.widget.wait_visibility()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.widget.destroy()
|
2009-02-01 21:02:20 -04:00
|
|
|
support.root_withdraw()
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_identify(self):
|
|
|
|
self.widget.update_idletasks()
|
2010-09-26 13:36:33 -03:00
|
|
|
self.assertEqual(self.widget.identify(
|
|
|
|
int(self.widget.winfo_width() / 2),
|
|
|
|
int(self.widget.winfo_height() / 2)
|
|
|
|
), "label")
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.widget.identify(-1, -1), "")
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.widget.identify, None, 5)
|
|
|
|
self.assertRaises(tkinter.TclError, self.widget.identify, 5, None)
|
|
|
|
self.assertRaises(tkinter.TclError, self.widget.identify, 5, '')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_widget_state(self):
|
|
|
|
# XXX not sure about the portability of all these tests
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.widget.state(), ())
|
|
|
|
self.assertEqual(self.widget.instate(['!disabled']), True)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# changing from !disabled to disabled
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.widget.state(['disabled']), ('!disabled', ))
|
2009-01-28 10:41:10 -04:00
|
|
|
# no state change
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.widget.state(['disabled']), ())
|
2009-01-28 10:41:10 -04:00
|
|
|
# change back to !disable but also active
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.widget.state(['!disabled', 'active']),
|
2009-01-28 10:41:10 -04:00
|
|
|
('!active', 'disabled'))
|
|
|
|
# no state changes, again
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.widget.state(['!disabled', 'active']), ())
|
|
|
|
self.assertEqual(self.widget.state(['active', '!disabled']), ())
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
def test_cb(arg1, **kw):
|
|
|
|
return arg1, kw
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.widget.instate(['!disabled'],
|
2009-01-28 10:41:10 -04:00
|
|
|
test_cb, "hi", **{"msg": "there"}),
|
|
|
|
('hi', {'msg': 'there'}))
|
|
|
|
|
|
|
|
# attempt to set invalid statespec
|
|
|
|
currstate = self.widget.state()
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.widget.instate,
|
2009-01-28 10:41:10 -04:00
|
|
|
['badstate'])
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.widget.instate,
|
2009-01-28 10:41:10 -04:00
|
|
|
['disabled', 'badstate'])
|
|
|
|
# verify that widget didn't change its state
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(currstate, self.widget.state())
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# ensuring that passing None as state doesn't modify current state
|
|
|
|
self.widget.state(['active', '!disabled'])
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.widget.state(), ('active', ))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
2013-11-02 05:41:48 -03:00
|
|
|
class AbstractToplevelTest(AbstractWidgetTest, PixelSizeTests):
|
|
|
|
_conv_pixels = noconv
|
|
|
|
|
|
|
|
|
|
|
|
@add_standard_options(StandardTtkOptionsTests)
|
|
|
|
class FrameTest(AbstractToplevelTest, unittest.TestCase):
|
|
|
|
OPTIONS = (
|
|
|
|
'borderwidth', 'class', 'cursor', 'height',
|
|
|
|
'padding', 'relief', 'style', 'takefocus',
|
|
|
|
'width',
|
|
|
|
)
|
|
|
|
|
|
|
|
def _create(self, **kwargs):
|
|
|
|
return ttk.Frame(self.root, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
@add_standard_options(StandardTtkOptionsTests)
|
|
|
|
class LabelFrameTest(AbstractToplevelTest, unittest.TestCase):
|
|
|
|
OPTIONS = (
|
|
|
|
'borderwidth', 'class', 'cursor', 'height',
|
|
|
|
'labelanchor', 'labelwidget',
|
|
|
|
'padding', 'relief', 'style', 'takefocus',
|
|
|
|
'text', 'underline', 'width',
|
|
|
|
)
|
|
|
|
|
|
|
|
def _create(self, **kwargs):
|
|
|
|
return ttk.LabelFrame(self.root, **kwargs)
|
|
|
|
|
|
|
|
def test_labelanchor(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkEnumParam(widget, 'labelanchor',
|
|
|
|
'e', 'en', 'es', 'n', 'ne', 'nw', 's', 'se', 'sw', 'w', 'wn', 'ws',
|
|
|
|
errmsg='Bad label anchor specification {}')
|
|
|
|
self.checkInvalidParam(widget, 'labelanchor', 'center')
|
|
|
|
|
|
|
|
def test_labelwidget(self):
|
|
|
|
widget = self.create()
|
|
|
|
label = ttk.Label(self.root, text='Mupp', name='foo')
|
|
|
|
self.checkParam(widget, 'labelwidget', label, expected='.foo')
|
|
|
|
label.destroy()
|
|
|
|
|
|
|
|
|
|
|
|
class AbstractLabelTest(AbstractWidgetTest):
|
|
|
|
|
|
|
|
def checkImageParam(self, widget, name):
|
|
|
|
image = tkinter.PhotoImage('image1')
|
|
|
|
image2 = tkinter.PhotoImage('image2')
|
|
|
|
self.checkParam(widget, name, image, expected=('image1',))
|
|
|
|
self.checkParam(widget, name, 'image1', expected=('image1',))
|
|
|
|
self.checkParam(widget, name, (image,), expected=('image1',))
|
|
|
|
self.checkParam(widget, name, (image, 'active', image2),
|
|
|
|
expected=('image1', 'active', 'image2'))
|
|
|
|
self.checkParam(widget, name, 'image1 active image2',
|
|
|
|
expected=('image1', 'active', 'image2'))
|
|
|
|
self.checkInvalidParam(widget, name, 'spam',
|
|
|
|
errmsg='image "spam" doesn\'t exist')
|
|
|
|
|
|
|
|
def test_compound(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkEnumParam(widget, 'compound',
|
|
|
|
'none', 'text', 'image', 'center',
|
|
|
|
'top', 'bottom', 'left', 'right')
|
|
|
|
|
|
|
|
def test_state(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkParams(widget, 'state', 'active', 'disabled', 'normal')
|
|
|
|
|
|
|
|
def test_width(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkParams(widget, 'width', 402, -402, 0)
|
|
|
|
|
|
|
|
|
|
|
|
@add_standard_options(StandardTtkOptionsTests)
|
|
|
|
class LabelTest(AbstractLabelTest, unittest.TestCase):
|
|
|
|
OPTIONS = (
|
|
|
|
'anchor', 'background',
|
|
|
|
'class', 'compound', 'cursor', 'font', 'foreground',
|
|
|
|
'image', 'justify', 'padding', 'relief', 'state', 'style',
|
|
|
|
'takefocus', 'text', 'textvariable',
|
|
|
|
'underline', 'width', 'wraplength',
|
|
|
|
)
|
|
|
|
_conv_pixels = noconv
|
|
|
|
|
|
|
|
def _create(self, **kwargs):
|
|
|
|
return ttk.Label(self.root, **kwargs)
|
|
|
|
|
|
|
|
def test_font(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkParam(widget, 'font',
|
|
|
|
'-Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*')
|
|
|
|
|
|
|
|
|
|
|
|
@add_standard_options(StandardTtkOptionsTests)
|
|
|
|
class ButtonTest(AbstractLabelTest, unittest.TestCase):
|
|
|
|
OPTIONS = (
|
|
|
|
'class', 'command', 'compound', 'cursor', 'default',
|
|
|
|
'image', 'state', 'style', 'takefocus', 'text', 'textvariable',
|
|
|
|
'underline', 'width',
|
|
|
|
)
|
|
|
|
|
|
|
|
def _create(self, **kwargs):
|
|
|
|
return ttk.Button(self.root, **kwargs)
|
|
|
|
|
|
|
|
def test_default(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkEnumParam(widget, 'default', 'normal', 'active', 'disabled')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
def test_invoke(self):
|
|
|
|
success = []
|
|
|
|
btn = ttk.Button(command=lambda: success.append(1))
|
|
|
|
btn.invoke()
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(success)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
2013-11-02 05:41:48 -03:00
|
|
|
@add_standard_options(StandardTtkOptionsTests)
|
|
|
|
class CheckbuttonTest(AbstractLabelTest, unittest.TestCase):
|
|
|
|
OPTIONS = (
|
|
|
|
'class', 'command', 'compound', 'cursor',
|
|
|
|
'image',
|
|
|
|
'offvalue', 'onvalue',
|
|
|
|
'state', 'style',
|
|
|
|
'takefocus', 'text', 'textvariable',
|
|
|
|
'underline', 'variable', 'width',
|
|
|
|
)
|
|
|
|
|
|
|
|
def _create(self, **kwargs):
|
|
|
|
return ttk.Checkbutton(self.root, **kwargs)
|
|
|
|
|
|
|
|
def test_offvalue(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkParams(widget, 'offvalue', 1, 2.3, '', 'any string')
|
|
|
|
|
|
|
|
def test_onvalue(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkParams(widget, 'onvalue', 1, 2.3, '', 'any string')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
def test_invoke(self):
|
|
|
|
success = []
|
|
|
|
def cb_test():
|
|
|
|
success.append(1)
|
|
|
|
return "cb test called"
|
|
|
|
|
|
|
|
cbtn = ttk.Checkbutton(command=cb_test)
|
|
|
|
# the variable automatically created by ttk.Checkbutton is actually
|
|
|
|
# undefined till we invoke the Checkbutton
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(cbtn.state(), ('alternate', ))
|
|
|
|
self.assertRaises(tkinter.TclError, cbtn.tk.globalgetvar,
|
2009-01-28 10:41:10 -04:00
|
|
|
cbtn['variable'])
|
|
|
|
|
|
|
|
res = cbtn.invoke()
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(res, "cb test called")
|
|
|
|
self.assertEqual(cbtn['onvalue'],
|
2009-01-28 10:41:10 -04:00
|
|
|
cbtn.tk.globalgetvar(cbtn['variable']))
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(success)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
cbtn['command'] = ''
|
|
|
|
res = cbtn.invoke()
|
2013-11-02 05:41:48 -03:00
|
|
|
self.assertFalse(str(res))
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertFalse(len(success) > 1)
|
|
|
|
self.assertEqual(cbtn['offvalue'],
|
2009-01-28 10:41:10 -04:00
|
|
|
cbtn.tk.globalgetvar(cbtn['variable']))
|
|
|
|
|
|
|
|
|
2013-11-02 05:41:48 -03:00
|
|
|
@add_standard_options(IntegerSizeTests, StandardTtkOptionsTests)
|
|
|
|
class ComboboxTest(AbstractWidgetTest, unittest.TestCase):
|
|
|
|
OPTIONS = (
|
|
|
|
'class', 'cursor', 'exportselection', 'height',
|
|
|
|
'justify', 'postcommand', 'state', 'style',
|
|
|
|
'takefocus', 'textvariable', 'values', 'width',
|
|
|
|
)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
def setUp(self):
|
2013-11-02 05:41:48 -03:00
|
|
|
super().setUp()
|
2009-02-01 21:02:20 -04:00
|
|
|
support.root_deiconify()
|
2013-11-02 05:41:48 -03:00
|
|
|
self.combo = self.create()
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.combo.destroy()
|
2009-02-01 21:02:20 -04:00
|
|
|
support.root_withdraw()
|
2013-11-02 05:41:48 -03:00
|
|
|
super().tearDown()
|
|
|
|
|
|
|
|
def _create(self, **kwargs):
|
|
|
|
return ttk.Combobox(self.root, **kwargs)
|
|
|
|
|
|
|
|
def test_height(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkParams(widget, 'height', 100, 101.2, 102.6, -100, 0, '1i')
|
|
|
|
|
|
|
|
def test_state(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkParams(widget, 'state', 'active', 'disabled', 'normal')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
def _show_drop_down_listbox(self):
|
|
|
|
width = self.combo.winfo_width()
|
|
|
|
self.combo.event_generate('<ButtonPress-1>', x=width - 5, y=5)
|
|
|
|
self.combo.event_generate('<ButtonRelease-1>', x=width - 5, y=5)
|
|
|
|
self.combo.update_idletasks()
|
|
|
|
|
|
|
|
|
|
|
|
def test_virtual_event(self):
|
|
|
|
success = []
|
|
|
|
|
|
|
|
self.combo['values'] = [1]
|
|
|
|
self.combo.bind('<<ComboboxSelected>>',
|
|
|
|
lambda evt: success.append(True))
|
|
|
|
self.combo.pack()
|
|
|
|
self.combo.wait_visibility()
|
|
|
|
|
|
|
|
height = self.combo.winfo_height()
|
|
|
|
self._show_drop_down_listbox()
|
|
|
|
self.combo.update()
|
|
|
|
self.combo.event_generate('<Return>')
|
|
|
|
self.combo.update()
|
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(success)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_postcommand(self):
|
|
|
|
success = []
|
|
|
|
|
|
|
|
self.combo['postcommand'] = lambda: success.append(True)
|
|
|
|
self.combo.pack()
|
|
|
|
self.combo.wait_visibility()
|
|
|
|
|
|
|
|
self._show_drop_down_listbox()
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(success)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# testing postcommand removal
|
|
|
|
self.combo['postcommand'] = ''
|
|
|
|
self._show_drop_down_listbox()
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(len(success), 1)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_values(self):
|
|
|
|
def check_get_current(getval, currval):
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.combo.get(), getval)
|
|
|
|
self.assertEqual(self.combo.current(), currval)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2013-11-02 05:41:48 -03:00
|
|
|
self.assertEqual(self.combo['values'],
|
|
|
|
() if tcl_version < (8, 5) else '')
|
2009-01-28 10:41:10 -04:00
|
|
|
check_get_current('', -1)
|
|
|
|
|
2013-11-02 05:41:48 -03:00
|
|
|
self.checkParam(self.combo, 'values', 'mon tue wed thur',
|
|
|
|
expected=('mon', 'tue', 'wed', 'thur'))
|
|
|
|
self.checkParam(self.combo, 'values', ('mon', 'tue', 'wed', 'thur'))
|
|
|
|
self.checkParam(self.combo, 'values', (42, 3.14, '', 'any string'))
|
|
|
|
self.checkParam(self.combo, 'values', '', expected=())
|
|
|
|
|
2009-01-28 10:41:10 -04:00
|
|
|
self.combo['values'] = ['a', 1, 'c']
|
|
|
|
|
|
|
|
self.combo.set('c')
|
|
|
|
check_get_current('c', 2)
|
|
|
|
|
|
|
|
self.combo.current(0)
|
|
|
|
check_get_current('a', 0)
|
|
|
|
|
|
|
|
self.combo.set('d')
|
|
|
|
check_get_current('d', -1)
|
|
|
|
|
|
|
|
# testing values with empty string
|
|
|
|
self.combo.set('')
|
|
|
|
self.combo['values'] = (1, 2, '', 3)
|
|
|
|
check_get_current('', 2)
|
|
|
|
|
|
|
|
# testing values with empty string set through configure
|
|
|
|
self.combo.configure(values=[1, '', 2])
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.combo['values'], ('1', '', '2'))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2013-01-15 11:56:08 -04:00
|
|
|
# testing values with spaces
|
|
|
|
self.combo['values'] = ['a b', 'a\tb', 'a\nb']
|
|
|
|
self.assertEqual(self.combo['values'], ('a b', 'a\tb', 'a\nb'))
|
|
|
|
|
|
|
|
# testing values with special characters
|
|
|
|
self.combo['values'] = [r'a\tb', '"a"', '} {']
|
|
|
|
self.assertEqual(self.combo['values'], (r'a\tb', '"a"', '} {'))
|
|
|
|
|
2009-01-28 10:41:10 -04:00
|
|
|
# out of range
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.combo.current,
|
2009-01-28 10:41:10 -04:00
|
|
|
len(self.combo['values']))
|
|
|
|
# it expects an integer (or something that can be converted to int)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.combo.current, '')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# testing creating combobox with empty string in values
|
|
|
|
combo2 = ttk.Combobox(values=[1, 2, ''])
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(combo2['values'], ('1', '2', ''))
|
2009-01-28 10:41:10 -04:00
|
|
|
combo2.destroy()
|
|
|
|
|
|
|
|
|
2013-11-02 05:41:48 -03:00
|
|
|
@add_standard_options(IntegerSizeTests, StandardTtkOptionsTests)
|
|
|
|
class EntryTest(AbstractWidgetTest, unittest.TestCase):
|
|
|
|
OPTIONS = (
|
|
|
|
'background', 'class', 'cursor',
|
|
|
|
'exportselection', 'font',
|
|
|
|
'invalidcommand', 'justify',
|
|
|
|
'show', 'state', 'style', 'takefocus', 'textvariable',
|
|
|
|
'validate', 'validatecommand', 'width', 'xscrollcommand',
|
|
|
|
)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
def setUp(self):
|
2013-11-02 05:41:48 -03:00
|
|
|
super().setUp()
|
2009-02-01 21:02:20 -04:00
|
|
|
support.root_deiconify()
|
2013-11-02 05:41:48 -03:00
|
|
|
self.entry = self.create()
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.entry.destroy()
|
2009-02-01 21:02:20 -04:00
|
|
|
support.root_withdraw()
|
2013-11-02 05:41:48 -03:00
|
|
|
super().tearDown()
|
|
|
|
|
|
|
|
def _create(self, **kwargs):
|
|
|
|
return ttk.Entry(self.root, **kwargs)
|
|
|
|
|
|
|
|
def test_invalidcommand(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkCommandParam(widget, 'invalidcommand')
|
|
|
|
|
|
|
|
def test_show(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkParam(widget, 'show', '*')
|
|
|
|
self.checkParam(widget, 'show', '')
|
|
|
|
self.checkParam(widget, 'show', ' ')
|
|
|
|
|
|
|
|
def test_state(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkParams(widget, 'state',
|
|
|
|
'disabled', 'normal', 'readonly')
|
|
|
|
|
|
|
|
def test_validate(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkEnumParam(widget, 'validate',
|
|
|
|
'all', 'key', 'focus', 'focusin', 'focusout', 'none')
|
|
|
|
|
|
|
|
def test_validatecommand(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkCommandParam(widget, 'validatecommand')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_bbox(self):
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(len(self.entry.bbox(0)), 4)
|
2009-01-28 10:41:10 -04:00
|
|
|
for item in self.entry.bbox(0):
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(isinstance(item, int))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.entry.bbox, 'noindex')
|
|
|
|
self.assertRaises(tkinter.TclError, self.entry.bbox, None)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_identify(self):
|
|
|
|
self.entry.pack()
|
|
|
|
self.entry.wait_visibility()
|
|
|
|
self.entry.update_idletasks()
|
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.entry.identify(5, 5), "textarea")
|
|
|
|
self.assertEqual(self.entry.identify(-1, -1), "")
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.entry.identify, None, 5)
|
|
|
|
self.assertRaises(tkinter.TclError, self.entry.identify, 5, None)
|
|
|
|
self.assertRaises(tkinter.TclError, self.entry.identify, 5, '')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_validation_options(self):
|
|
|
|
success = []
|
|
|
|
test_invalid = lambda: success.append(True)
|
|
|
|
|
|
|
|
self.entry['validate'] = 'none'
|
|
|
|
self.entry['validatecommand'] = lambda: False
|
|
|
|
|
|
|
|
self.entry['invalidcommand'] = test_invalid
|
|
|
|
self.entry.validate()
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(success)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.entry['invalidcommand'] = ''
|
|
|
|
self.entry.validate()
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(len(success), 1)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.entry['invalidcommand'] = test_invalid
|
|
|
|
self.entry['validatecommand'] = lambda: True
|
|
|
|
self.entry.validate()
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(len(success), 1)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.entry['validatecommand'] = ''
|
|
|
|
self.entry.validate()
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(len(success), 1)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.entry['validatecommand'] = True
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.entry.validate)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_validation(self):
|
|
|
|
validation = []
|
|
|
|
def validate(to_insert):
|
|
|
|
if not 'a' <= to_insert.lower() <= 'z':
|
|
|
|
validation.append(False)
|
|
|
|
return False
|
|
|
|
validation.append(True)
|
|
|
|
return True
|
|
|
|
|
|
|
|
self.entry['validate'] = 'key'
|
|
|
|
self.entry['validatecommand'] = self.entry.register(validate), '%S'
|
|
|
|
|
|
|
|
self.entry.insert('end', 1)
|
|
|
|
self.entry.insert('end', 'a')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(validation, [False, True])
|
|
|
|
self.assertEqual(self.entry.get(), 'a')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_revalidation(self):
|
|
|
|
def validate(content):
|
|
|
|
for letter in content:
|
|
|
|
if not 'a' <= letter.lower() <= 'z':
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
self.entry['validatecommand'] = self.entry.register(validate), '%P'
|
|
|
|
|
|
|
|
self.entry.insert('end', 'avocado')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.entry.validate(), True)
|
|
|
|
self.assertEqual(self.entry.state(), ())
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.entry.delete(0, 'end')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.entry.get(), '')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.entry.insert('end', 'a1b')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.entry.validate(), False)
|
|
|
|
self.assertEqual(self.entry.state(), ('invalid', ))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.entry.delete(1)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.entry.validate(), True)
|
|
|
|
self.assertEqual(self.entry.state(), ())
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
2013-11-02 05:41:48 -03:00
|
|
|
@add_standard_options(IntegerSizeTests, StandardTtkOptionsTests)
|
|
|
|
class PanedWindowTest(AbstractWidgetTest, unittest.TestCase):
|
|
|
|
OPTIONS = (
|
|
|
|
'class', 'cursor', 'height',
|
|
|
|
'orient', 'style', 'takefocus', 'width',
|
|
|
|
)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
def setUp(self):
|
2013-11-02 05:41:48 -03:00
|
|
|
super().setUp()
|
2009-02-01 21:02:20 -04:00
|
|
|
support.root_deiconify()
|
2013-11-02 05:41:48 -03:00
|
|
|
self.paned = self.create()
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.paned.destroy()
|
2009-02-01 21:02:20 -04:00
|
|
|
support.root_withdraw()
|
2013-11-02 05:41:48 -03:00
|
|
|
super().tearDown()
|
|
|
|
|
|
|
|
def _create(self, **kwargs):
|
|
|
|
return ttk.PanedWindow(self.root, **kwargs)
|
|
|
|
|
|
|
|
def test_orient(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.assertEqual(str(widget['orient']), 'vertical')
|
|
|
|
errmsg='attempt to change read-only option'
|
|
|
|
if tcl_version < (8, 6):
|
|
|
|
errmsg='Attempt to change read-only option'
|
|
|
|
self.checkInvalidParam(widget, 'orient', 'horizontal',
|
|
|
|
errmsg=errmsg)
|
|
|
|
widget2 = self.create(orient='horizontal')
|
|
|
|
self.assertEqual(str(widget2['orient']), 'horizontal')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
def test_add(self):
|
|
|
|
# attempt to add a child that is not a direct child of the paned window
|
|
|
|
label = ttk.Label(self.paned)
|
|
|
|
child = ttk.Label(label)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.paned.add, child)
|
2009-01-28 10:41:10 -04:00
|
|
|
label.destroy()
|
|
|
|
child.destroy()
|
|
|
|
# another attempt
|
|
|
|
label = ttk.Label()
|
|
|
|
child = ttk.Label(label)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.paned.add, child)
|
2009-01-28 10:41:10 -04:00
|
|
|
child.destroy()
|
|
|
|
label.destroy()
|
|
|
|
|
|
|
|
good_child = ttk.Label()
|
|
|
|
self.paned.add(good_child)
|
|
|
|
# re-adding a child is not accepted
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.paned.add, good_child)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
other_child = ttk.Label(self.paned)
|
|
|
|
self.paned.add(other_child)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.paned.pane(0), self.paned.pane(1))
|
|
|
|
self.assertRaises(tkinter.TclError, self.paned.pane, 2)
|
2009-01-28 10:41:10 -04:00
|
|
|
good_child.destroy()
|
|
|
|
other_child.destroy()
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.paned.pane, 0)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_forget(self):
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.paned.forget, None)
|
|
|
|
self.assertRaises(tkinter.TclError, self.paned.forget, 0)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.paned.add(ttk.Label())
|
|
|
|
self.paned.forget(0)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.paned.forget, 0)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_insert(self):
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.paned.insert, None, 0)
|
|
|
|
self.assertRaises(tkinter.TclError, self.paned.insert, 0, None)
|
|
|
|
self.assertRaises(tkinter.TclError, self.paned.insert, 0, 0)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
child = ttk.Label()
|
|
|
|
child2 = ttk.Label()
|
|
|
|
child3 = ttk.Label()
|
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.paned.insert, 0, child)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.paned.insert('end', child2)
|
|
|
|
self.paned.insert(0, child)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.paned.panes(), (str(child), str(child2)))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.paned.insert(0, child2)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.paned.panes(), (str(child2), str(child)))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.paned.insert('end', child3)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.paned.panes(),
|
2009-01-28 10:41:10 -04:00
|
|
|
(str(child2), str(child), str(child3)))
|
|
|
|
|
|
|
|
# reinserting a child should move it to its current position
|
|
|
|
panes = self.paned.panes()
|
|
|
|
self.paned.insert('end', child3)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(panes, self.paned.panes())
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# moving child3 to child2 position should result in child2 ending up
|
|
|
|
# in previous child position and child ending up in previous child3
|
|
|
|
# position
|
|
|
|
self.paned.insert(child2, child3)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.paned.panes(),
|
2009-01-28 10:41:10 -04:00
|
|
|
(str(child3), str(child2), str(child)))
|
|
|
|
|
|
|
|
|
|
|
|
def test_pane(self):
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.paned.pane, 0)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
child = ttk.Label()
|
|
|
|
self.paned.add(child)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(isinstance(self.paned.pane(0), dict))
|
|
|
|
self.assertEqual(self.paned.pane(0, weight=None), 0)
|
2009-01-28 10:41:10 -04:00
|
|
|
# newer form for querying a single option
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.paned.pane(0, 'weight'), 0)
|
|
|
|
self.assertEqual(self.paned.pane(0), self.paned.pane(str(child)))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.paned.pane, 0,
|
2009-01-28 10:41:10 -04:00
|
|
|
badoption='somevalue')
|
|
|
|
|
|
|
|
|
|
|
|
def test_sashpos(self):
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.paned.sashpos, None)
|
|
|
|
self.assertRaises(tkinter.TclError, self.paned.sashpos, '')
|
|
|
|
self.assertRaises(tkinter.TclError, self.paned.sashpos, 0)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
child = ttk.Label(self.paned, text='a')
|
|
|
|
self.paned.add(child, weight=1)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.paned.sashpos, 0)
|
2009-01-28 10:41:10 -04:00
|
|
|
child2 = ttk.Label(self.paned, text='b')
|
|
|
|
self.paned.add(child2)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.paned.sashpos, 1)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.paned.pack(expand=True, fill='both')
|
|
|
|
self.paned.wait_visibility()
|
|
|
|
|
|
|
|
curr_pos = self.paned.sashpos(0)
|
|
|
|
self.paned.sashpos(0, 1000)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(curr_pos != self.paned.sashpos(0))
|
|
|
|
self.assertTrue(isinstance(self.paned.sashpos(0), int))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
2013-11-02 05:41:48 -03:00
|
|
|
@add_standard_options(StandardTtkOptionsTests)
|
|
|
|
class RadiobuttonTest(AbstractLabelTest, unittest.TestCase):
|
|
|
|
OPTIONS = (
|
|
|
|
'class', 'command', 'compound', 'cursor',
|
|
|
|
'image',
|
|
|
|
'state', 'style',
|
|
|
|
'takefocus', 'text', 'textvariable',
|
|
|
|
'underline', 'value', 'variable', 'width',
|
|
|
|
)
|
|
|
|
|
|
|
|
def _create(self, **kwargs):
|
|
|
|
return ttk.Radiobutton(self.root, **kwargs)
|
|
|
|
|
|
|
|
def test_value(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkParams(widget, 'value', 1, 2.3, '', 'any string')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
def test_invoke(self):
|
|
|
|
success = []
|
|
|
|
def cb_test():
|
|
|
|
success.append(1)
|
|
|
|
return "cb test called"
|
|
|
|
|
|
|
|
myvar = tkinter.IntVar()
|
|
|
|
cbtn = ttk.Radiobutton(command=cb_test, variable=myvar, value=0)
|
|
|
|
cbtn2 = ttk.Radiobutton(command=cb_test, variable=myvar, value=1)
|
|
|
|
|
|
|
|
res = cbtn.invoke()
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(res, "cb test called")
|
|
|
|
self.assertEqual(cbtn['value'], myvar.get())
|
|
|
|
self.assertEqual(myvar.get(),
|
2009-01-28 10:41:10 -04:00
|
|
|
cbtn.tk.globalgetvar(cbtn['variable']))
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(success)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
cbtn2['command'] = ''
|
|
|
|
res = cbtn2.invoke()
|
2013-08-22 11:51:58 -03:00
|
|
|
self.assertEqual(str(res), '')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertFalse(len(success) > 1)
|
|
|
|
self.assertEqual(cbtn2['value'], myvar.get())
|
|
|
|
self.assertEqual(myvar.get(),
|
2009-01-28 10:41:10 -04:00
|
|
|
cbtn.tk.globalgetvar(cbtn['variable']))
|
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(str(cbtn['variable']), str(cbtn2['variable']))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
2013-11-02 05:41:48 -03:00
|
|
|
class MenubuttonTest(AbstractLabelTest, unittest.TestCase):
|
|
|
|
OPTIONS = (
|
|
|
|
'class', 'compound', 'cursor', 'direction',
|
|
|
|
'image', 'menu', 'state', 'style',
|
|
|
|
'takefocus', 'text', 'textvariable',
|
|
|
|
'underline', 'width',
|
|
|
|
)
|
|
|
|
|
|
|
|
def _create(self, **kwargs):
|
|
|
|
return ttk.Menubutton(self.root, **kwargs)
|
|
|
|
|
|
|
|
def test_direction(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkEnumParam(widget, 'direction',
|
|
|
|
'above', 'below', 'left', 'right', 'flush')
|
|
|
|
|
|
|
|
def test_menu(self):
|
|
|
|
widget = self.create()
|
|
|
|
menu = tkinter.Menu(widget, name='menu')
|
|
|
|
self.checkParam(widget, 'menu', menu, conv=str)
|
|
|
|
menu.destroy()
|
|
|
|
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2013-11-02 05:41:48 -03:00
|
|
|
@add_standard_options(StandardTtkOptionsTests)
|
|
|
|
class ScaleTest(AbstractWidgetTest, unittest.TestCase):
|
|
|
|
OPTIONS = (
|
|
|
|
'class', 'command', 'cursor', 'from', 'length',
|
|
|
|
'orient', 'style', 'takefocus', 'to', 'value', 'variable',
|
|
|
|
)
|
|
|
|
_conv_pixels = noconv
|
|
|
|
default_orient = 'horizontal'
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
def setUp(self):
|
2013-11-02 05:41:48 -03:00
|
|
|
super().setUp()
|
2009-02-01 21:02:20 -04:00
|
|
|
support.root_deiconify()
|
2013-11-02 05:41:48 -03:00
|
|
|
self.scale = self.create()
|
2009-01-28 10:41:10 -04:00
|
|
|
self.scale.pack()
|
|
|
|
self.scale.update()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.scale.destroy()
|
2009-02-01 21:02:20 -04:00
|
|
|
support.root_withdraw()
|
2013-11-02 05:41:48 -03:00
|
|
|
super().tearDown()
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2013-11-02 05:41:48 -03:00
|
|
|
def _create(self, **kwargs):
|
|
|
|
return ttk.Scale(self.root, **kwargs)
|
|
|
|
|
|
|
|
def test_from(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkFloatParam(widget, 'from', 100, 14.9, 15.1, conv=False)
|
|
|
|
|
|
|
|
def test_length(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkPixelsParam(widget, 'length', 130, 131.2, 135.6, '5i')
|
|
|
|
|
|
|
|
def test_to(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkFloatParam(widget, 'to', 300, 14.9, 15.1, -10, conv=False)
|
|
|
|
|
|
|
|
def test_value(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkFloatParam(widget, 'value', 300, 14.9, 15.1, -10, conv=False)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
def test_custom_event(self):
|
|
|
|
failure = [1, 1, 1] # will need to be empty
|
|
|
|
|
|
|
|
funcid = self.scale.bind('<<RangeChanged>>', lambda evt: failure.pop())
|
|
|
|
|
|
|
|
self.scale['from'] = 10
|
|
|
|
self.scale['from_'] = 10
|
|
|
|
self.scale['to'] = 3
|
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertFalse(failure)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
failure = [1, 1, 1]
|
|
|
|
self.scale.configure(from_=2, to=5)
|
|
|
|
self.scale.configure(from_=0, to=-2)
|
|
|
|
self.scale.configure(to=10)
|
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertFalse(failure)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_get(self):
|
|
|
|
scale_width = self.scale.winfo_width()
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.scale.get(scale_width, 0), self.scale['to'])
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.scale.get(0, 0), self.scale['from'])
|
|
|
|
self.assertEqual(self.scale.get(), self.scale['value'])
|
2009-01-28 10:41:10 -04:00
|
|
|
self.scale['value'] = 30
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.scale.get(), self.scale['value'])
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.scale.get, '', 0)
|
|
|
|
self.assertRaises(tkinter.TclError, self.scale.get, 0, '')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_set(self):
|
|
|
|
# set restricts the max/min values according to the current range
|
|
|
|
max = self.scale['to']
|
|
|
|
new_max = max + 10
|
|
|
|
self.scale.set(new_max)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.scale.get(), max)
|
2009-01-28 10:41:10 -04:00
|
|
|
min = self.scale['from']
|
|
|
|
self.scale.set(min - 1)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.scale.get(), min)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# changing directly the variable doesn't impose this limitation tho
|
|
|
|
var = tkinter.DoubleVar()
|
|
|
|
self.scale['variable'] = var
|
|
|
|
var.set(max + 5)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.scale.get(), var.get())
|
|
|
|
self.assertEqual(self.scale.get(), max + 5)
|
2009-01-28 10:41:10 -04:00
|
|
|
del var
|
|
|
|
|
|
|
|
# the same happens with the value option
|
|
|
|
self.scale['value'] = max + 10
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.scale.get(), max + 10)
|
|
|
|
self.assertEqual(self.scale.get(), self.scale['value'])
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# nevertheless, note that the max/min values we can get specifying
|
|
|
|
# x, y coords are the ones according to the current range
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.scale.get(0, 0), min)
|
|
|
|
self.assertEqual(self.scale.get(self.scale.winfo_width(), 0), max)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.scale.set, None)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
2013-11-02 05:41:48 -03:00
|
|
|
@add_standard_options(StandardTtkOptionsTests)
|
|
|
|
class ProgressbarTest(AbstractWidgetTest, unittest.TestCase):
|
|
|
|
OPTIONS = (
|
|
|
|
'class', 'cursor', 'orient', 'length',
|
|
|
|
'mode', 'maximum', 'phase',
|
|
|
|
'style', 'takefocus', 'value', 'variable',
|
|
|
|
)
|
|
|
|
_conv_pixels = noconv
|
|
|
|
default_orient = 'horizontal'
|
|
|
|
|
|
|
|
def _create(self, **kwargs):
|
|
|
|
return ttk.Progressbar(self.root, **kwargs)
|
|
|
|
|
|
|
|
def test_length(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkPixelsParam(widget, 'length', 100.1, 56.7, '2i')
|
|
|
|
|
|
|
|
def test_maximum(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkFloatParam(widget, 'maximum', 150.2, 77.7, 0, -10, conv=False)
|
|
|
|
|
|
|
|
def test_mode(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkEnumParam(widget, 'mode', 'determinate', 'indeterminate')
|
|
|
|
|
|
|
|
def test_phase(self):
|
|
|
|
# XXX
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_value(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkFloatParam(widget, 'value', 150.2, 77.7, 0, -10,
|
|
|
|
conv=False)
|
|
|
|
|
|
|
|
|
|
|
|
@unittest.skipIf(sys.platform == 'darwin',
|
|
|
|
'ttk.Scrollbar is special on MacOSX')
|
|
|
|
@add_standard_options(StandardTtkOptionsTests)
|
|
|
|
class ScrollbarTest(AbstractWidgetTest, unittest.TestCase):
|
|
|
|
OPTIONS = (
|
|
|
|
'class', 'command', 'cursor', 'orient', 'style', 'takefocus',
|
|
|
|
)
|
|
|
|
default_orient = 'vertical'
|
|
|
|
|
|
|
|
def _create(self, **kwargs):
|
|
|
|
return ttk.Scrollbar(self.root, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
@add_standard_options(IntegerSizeTests, StandardTtkOptionsTests)
|
|
|
|
class NotebookTest(AbstractWidgetTest, unittest.TestCase):
|
|
|
|
OPTIONS = (
|
|
|
|
'class', 'cursor', 'height', 'padding', 'style', 'takefocus',
|
|
|
|
)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
def setUp(self):
|
2013-11-02 05:41:48 -03:00
|
|
|
super().setUp()
|
2009-02-01 21:02:20 -04:00
|
|
|
support.root_deiconify()
|
2013-11-02 05:41:48 -03:00
|
|
|
self.nb = self.create(padding=0)
|
2009-01-28 10:41:10 -04:00
|
|
|
self.child1 = ttk.Label()
|
|
|
|
self.child2 = ttk.Label()
|
|
|
|
self.nb.add(self.child1, text='a')
|
|
|
|
self.nb.add(self.child2, text='b')
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.child1.destroy()
|
|
|
|
self.child2.destroy()
|
|
|
|
self.nb.destroy()
|
2009-02-01 21:02:20 -04:00
|
|
|
support.root_withdraw()
|
2013-11-02 05:41:48 -03:00
|
|
|
super().tearDown()
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2013-11-02 05:41:48 -03:00
|
|
|
def _create(self, **kwargs):
|
|
|
|
return ttk.Notebook(self.root, **kwargs)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
def test_tab_identifiers(self):
|
|
|
|
self.nb.forget(0)
|
|
|
|
self.nb.hide(self.child2)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.nb.tab, self.child1)
|
|
|
|
self.assertEqual(self.nb.index('end'), 1)
|
2009-01-28 10:41:10 -04:00
|
|
|
self.nb.add(self.child2)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.index('end'), 1)
|
2009-01-28 10:41:10 -04:00
|
|
|
self.nb.select(self.child2)
|
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(self.nb.tab('current'))
|
2009-01-28 10:41:10 -04:00
|
|
|
self.nb.add(self.child1, text='a')
|
|
|
|
|
|
|
|
self.nb.pack()
|
|
|
|
self.nb.wait_visibility()
|
2011-06-28 03:12:20 -03:00
|
|
|
if sys.platform == 'darwin':
|
|
|
|
tb_idx = "@20,5"
|
|
|
|
else:
|
|
|
|
tb_idx = "@5,5"
|
|
|
|
self.assertEqual(self.nb.tab(tb_idx), self.nb.tab('current'))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
for i in range(5, 100, 5):
|
2011-06-28 03:12:20 -03:00
|
|
|
try:
|
|
|
|
if self.nb.tab('@%d, 5' % i, text=None) == 'a':
|
|
|
|
break
|
|
|
|
except tkinter.TclError:
|
|
|
|
pass
|
|
|
|
|
2009-01-28 10:41:10 -04:00
|
|
|
else:
|
|
|
|
self.fail("Tab with text 'a' not found")
|
|
|
|
|
|
|
|
|
|
|
|
def test_add_and_hidden(self):
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.nb.hide, -1)
|
|
|
|
self.assertRaises(tkinter.TclError, self.nb.hide, 'hi')
|
|
|
|
self.assertRaises(tkinter.TclError, self.nb.hide, None)
|
|
|
|
self.assertRaises(tkinter.TclError, self.nb.add, None)
|
|
|
|
self.assertRaises(tkinter.TclError, self.nb.add, ttk.Label(),
|
2009-01-28 10:41:10 -04:00
|
|
|
unknown='option')
|
|
|
|
|
|
|
|
tabs = self.nb.tabs()
|
|
|
|
self.nb.hide(self.child1)
|
|
|
|
self.nb.add(self.child1)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.tabs(), tabs)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
child = ttk.Label()
|
|
|
|
self.nb.add(child, text='c')
|
|
|
|
tabs = self.nb.tabs()
|
|
|
|
|
|
|
|
curr = self.nb.index('current')
|
|
|
|
# verify that the tab gets readded at its previous position
|
|
|
|
child2_index = self.nb.index(self.child2)
|
|
|
|
self.nb.hide(self.child2)
|
|
|
|
self.nb.add(self.child2)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.tabs(), tabs)
|
|
|
|
self.assertEqual(self.nb.index(self.child2), child2_index)
|
|
|
|
self.assertTrue(str(self.child2) == self.nb.tabs()[child2_index])
|
2009-01-28 10:41:10 -04:00
|
|
|
# but the tab next to it (not hidden) is the one selected now
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.index('current'), curr + 1)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_forget(self):
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.nb.forget, -1)
|
|
|
|
self.assertRaises(tkinter.TclError, self.nb.forget, 'hi')
|
|
|
|
self.assertRaises(tkinter.TclError, self.nb.forget, None)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
tabs = self.nb.tabs()
|
|
|
|
child1_index = self.nb.index(self.child1)
|
|
|
|
self.nb.forget(self.child1)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertFalse(str(self.child1) in self.nb.tabs())
|
|
|
|
self.assertEqual(len(tabs) - 1, len(self.nb.tabs()))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.nb.add(self.child1)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.index(self.child1), 1)
|
|
|
|
self.assertFalse(child1_index == self.nb.index(self.child1))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_index(self):
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.nb.index, -1)
|
|
|
|
self.assertRaises(tkinter.TclError, self.nb.index, None)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(isinstance(self.nb.index('end'), int))
|
|
|
|
self.assertEqual(self.nb.index(self.child1), 0)
|
|
|
|
self.assertEqual(self.nb.index(self.child2), 1)
|
|
|
|
self.assertEqual(self.nb.index('end'), 2)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_insert(self):
|
|
|
|
# moving tabs
|
|
|
|
tabs = self.nb.tabs()
|
|
|
|
self.nb.insert(1, tabs[0])
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.tabs(), (tabs[1], tabs[0]))
|
2009-01-28 10:41:10 -04:00
|
|
|
self.nb.insert(self.child1, self.child2)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.tabs(), tabs)
|
2009-01-28 10:41:10 -04:00
|
|
|
self.nb.insert('end', self.child1)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.tabs(), (tabs[1], tabs[0]))
|
2009-01-28 10:41:10 -04:00
|
|
|
self.nb.insert('end', 0)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.tabs(), tabs)
|
2009-01-28 10:41:10 -04:00
|
|
|
# bad moves
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.nb.insert, 2, tabs[0])
|
|
|
|
self.assertRaises(tkinter.TclError, self.nb.insert, -1, tabs[0])
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# new tab
|
|
|
|
child3 = ttk.Label()
|
|
|
|
self.nb.insert(1, child3)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.tabs(), (tabs[0], str(child3), tabs[1]))
|
2009-01-28 10:41:10 -04:00
|
|
|
self.nb.forget(child3)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.tabs(), tabs)
|
2009-01-28 10:41:10 -04:00
|
|
|
self.nb.insert(self.child1, child3)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.tabs(), (str(child3), ) + tabs)
|
2009-01-28 10:41:10 -04:00
|
|
|
self.nb.forget(child3)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.nb.insert, 2, child3)
|
|
|
|
self.assertRaises(tkinter.TclError, self.nb.insert, -1, child3)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# bad inserts
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.nb.insert, 'end', None)
|
|
|
|
self.assertRaises(tkinter.TclError, self.nb.insert, None, 0)
|
|
|
|
self.assertRaises(tkinter.TclError, self.nb.insert, None, None)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_select(self):
|
|
|
|
self.nb.pack()
|
|
|
|
self.nb.wait_visibility()
|
|
|
|
|
|
|
|
success = []
|
|
|
|
tab_changed = []
|
|
|
|
|
|
|
|
self.child1.bind('<Unmap>', lambda evt: success.append(True))
|
|
|
|
self.nb.bind('<<NotebookTabChanged>>',
|
|
|
|
lambda evt: tab_changed.append(True))
|
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.select(), str(self.child1))
|
2009-01-28 10:41:10 -04:00
|
|
|
self.nb.select(self.child2)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(success)
|
|
|
|
self.assertEqual(self.nb.select(), str(self.child2))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.nb.update()
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(tab_changed)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_tab(self):
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.nb.tab, -1)
|
|
|
|
self.assertRaises(tkinter.TclError, self.nb.tab, 'notab')
|
|
|
|
self.assertRaises(tkinter.TclError, self.nb.tab, None)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(isinstance(self.nb.tab(self.child1), dict))
|
|
|
|
self.assertEqual(self.nb.tab(self.child1, text=None), 'a')
|
2009-01-28 10:41:10 -04:00
|
|
|
# newer form for querying a single option
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.tab(self.child1, 'text'), 'a')
|
2009-01-28 10:41:10 -04:00
|
|
|
self.nb.tab(self.child1, text='abc')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.tab(self.child1, text=None), 'abc')
|
|
|
|
self.assertEqual(self.nb.tab(self.child1, 'text'), 'abc')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_tabs(self):
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(len(self.nb.tabs()), 2)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.nb.forget(self.child1)
|
|
|
|
self.nb.forget(self.child2)
|
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.tabs(), ())
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_traversal(self):
|
|
|
|
self.nb.pack()
|
|
|
|
self.nb.wait_visibility()
|
|
|
|
|
|
|
|
self.nb.select(0)
|
|
|
|
|
|
|
|
support.simulate_mouse_click(self.nb, 5, 5)
|
2010-04-11 19:04:51 -03:00
|
|
|
self.nb.focus_force()
|
2009-01-28 10:41:10 -04:00
|
|
|
self.nb.event_generate('<Control-Tab>')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.select(), str(self.child2))
|
2010-04-11 19:04:51 -03:00
|
|
|
self.nb.focus_force()
|
2009-01-28 10:41:10 -04:00
|
|
|
self.nb.event_generate('<Shift-Control-Tab>')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.select(), str(self.child1))
|
2010-04-11 19:04:51 -03:00
|
|
|
self.nb.focus_force()
|
2009-01-28 10:41:10 -04:00
|
|
|
self.nb.event_generate('<Shift-Control-Tab>')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.select(), str(self.child2))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.nb.tab(self.child1, text='a', underline=0)
|
|
|
|
self.nb.enable_traversal()
|
2010-04-11 19:04:51 -03:00
|
|
|
self.nb.focus_force()
|
2010-09-26 13:36:33 -03:00
|
|
|
support.simulate_mouse_click(self.nb, 5, 5)
|
2011-06-28 03:12:20 -03:00
|
|
|
if sys.platform == 'darwin':
|
|
|
|
self.nb.event_generate('<Option-a>')
|
|
|
|
else:
|
|
|
|
self.nb.event_generate('<Alt-a>')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.nb.select(), str(self.child1))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
2013-11-02 05:41:48 -03:00
|
|
|
@add_standard_options(StandardTtkOptionsTests)
|
|
|
|
class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
|
|
|
|
OPTIONS = (
|
|
|
|
'class', 'columns', 'cursor', 'displaycolumns',
|
|
|
|
'height', 'padding', 'selectmode', 'show',
|
|
|
|
'style', 'takefocus', 'xscrollcommand', 'yscrollcommand',
|
|
|
|
)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
def setUp(self):
|
2013-11-02 05:41:48 -03:00
|
|
|
super().setUp()
|
2009-02-01 21:02:20 -04:00
|
|
|
support.root_deiconify()
|
2013-11-02 05:41:48 -03:00
|
|
|
self.tv = self.create(padding=0)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.tv.destroy()
|
2009-02-01 21:02:20 -04:00
|
|
|
support.root_withdraw()
|
2013-11-02 05:41:48 -03:00
|
|
|
super().tearDown()
|
|
|
|
|
|
|
|
def _create(self, **kwargs):
|
|
|
|
return ttk.Treeview(self.root, **kwargs)
|
|
|
|
|
|
|
|
def test_columns(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkParam(widget, 'columns', 'a b c',
|
|
|
|
expected=('a', 'b', 'c'))
|
|
|
|
self.checkParam(widget, 'columns', ('a', 'b', 'c'))
|
|
|
|
self.checkParam(widget, 'columns', ())
|
|
|
|
|
|
|
|
def test_displaycolumns(self):
|
|
|
|
widget = self.create()
|
|
|
|
widget['columns'] = ('a', 'b', 'c')
|
|
|
|
self.checkParam(widget, 'displaycolumns', 'b a c',
|
|
|
|
expected=('b', 'a', 'c'))
|
|
|
|
self.checkParam(widget, 'displaycolumns', ('b', 'a', 'c'))
|
|
|
|
self.checkParam(widget, 'displaycolumns', '#all',
|
|
|
|
expected=('#all',))
|
|
|
|
self.checkParam(widget, 'displaycolumns', (2, 1, 0))
|
|
|
|
self.checkInvalidParam(widget, 'displaycolumns', ('a', 'b', 'd'),
|
|
|
|
errmsg='Invalid column index d')
|
|
|
|
self.checkInvalidParam(widget, 'displaycolumns', (1, 2, 3),
|
|
|
|
errmsg='Column index 3 out of bounds')
|
|
|
|
self.checkInvalidParam(widget, 'displaycolumns', (1, -2),
|
|
|
|
errmsg='Column index -2 out of bounds')
|
|
|
|
|
|
|
|
def test_height(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkPixelsParam(widget, 'height', 100, -100, 0, '3c', conv=False)
|
|
|
|
self.checkPixelsParam(widget, 'height', 101.2, 102.6, conv=noconv)
|
|
|
|
|
|
|
|
def test_selectmode(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkEnumParam(widget, 'selectmode',
|
|
|
|
'none', 'browse', 'extended')
|
|
|
|
|
|
|
|
def test_show(self):
|
|
|
|
widget = self.create()
|
|
|
|
self.checkParam(widget, 'show', 'tree headings',
|
|
|
|
expected=('tree', 'headings'))
|
|
|
|
self.checkParam(widget, 'show', ('tree', 'headings'))
|
|
|
|
self.checkParam(widget, 'show', ('headings', 'tree'))
|
|
|
|
self.checkParam(widget, 'show', 'tree', expected=('tree',))
|
|
|
|
self.checkParam(widget, 'show', 'headings', expected=('headings',))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
def test_bbox(self):
|
|
|
|
self.tv.pack()
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.bbox(''), '')
|
2009-01-28 10:41:10 -04:00
|
|
|
self.tv.wait_visibility()
|
|
|
|
self.tv.update()
|
|
|
|
|
|
|
|
item_id = self.tv.insert('', 'end')
|
|
|
|
children = self.tv.get_children()
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(children)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
bbox = self.tv.bbox(children[0])
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(len(bbox), 4)
|
|
|
|
self.assertTrue(isinstance(bbox, tuple))
|
2009-01-28 10:41:10 -04:00
|
|
|
for item in bbox:
|
|
|
|
if not isinstance(item, int):
|
|
|
|
self.fail("Invalid bounding box: %s" % bbox)
|
|
|
|
break
|
|
|
|
|
|
|
|
# compare width in bboxes
|
|
|
|
self.tv['columns'] = ['test']
|
|
|
|
self.tv.column('test', width=50)
|
|
|
|
bbox_column0 = self.tv.bbox(children[0], 0)
|
|
|
|
root_width = self.tv.column('#0', width=None)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(bbox_column0[0], bbox[0] + root_width)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# verify that bbox of a closed item is the empty string
|
|
|
|
child1 = self.tv.insert(item_id, 'end')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.bbox(child1), '')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_children(self):
|
|
|
|
# no children yet, should get an empty tuple
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.get_children(), ())
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
item_id = self.tv.insert('', 'end')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(isinstance(self.tv.get_children(), tuple))
|
|
|
|
self.assertEqual(self.tv.get_children()[0], item_id)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# add item_id and child3 as children of child2
|
|
|
|
child2 = self.tv.insert('', 'end')
|
|
|
|
child3 = self.tv.insert('', 'end')
|
|
|
|
self.tv.set_children(child2, item_id, child3)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.get_children(child2), (item_id, child3))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# child3 has child2 as parent, thus trying to set child2 as a children
|
|
|
|
# of child3 should result in an error
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError,
|
2009-01-28 10:41:10 -04:00
|
|
|
self.tv.set_children, child3, child2)
|
|
|
|
|
|
|
|
# remove child2 children
|
|
|
|
self.tv.set_children(child2)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.get_children(child2), ())
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# remove root's children
|
|
|
|
self.tv.set_children('')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.get_children(), ())
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_column(self):
|
|
|
|
# return a dict with all options/values
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(isinstance(self.tv.column('#0'), dict))
|
2009-01-28 10:41:10 -04:00
|
|
|
# return a single value of the given option
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(isinstance(self.tv.column('#0', width=None), int))
|
2009-01-28 10:41:10 -04:00
|
|
|
# set a new value for an option
|
|
|
|
self.tv.column('#0', width=10)
|
|
|
|
# testing new way to get option value
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.column('#0', 'width'), 10)
|
|
|
|
self.assertEqual(self.tv.column('#0', width=None), 10)
|
2009-01-28 10:41:10 -04:00
|
|
|
# check read-only option
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.tv.column, '#0', id='X')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.tv.column, 'invalid')
|
2009-01-28 10:41:10 -04:00
|
|
|
invalid_kws = [
|
|
|
|
{'unknown_option': 'some value'}, {'stretch': 'wrong'},
|
|
|
|
{'anchor': 'wrong'}, {'width': 'wrong'}, {'minwidth': 'wrong'}
|
|
|
|
]
|
|
|
|
for kw in invalid_kws:
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.tv.column, '#0',
|
2009-01-28 10:41:10 -04:00
|
|
|
**kw)
|
|
|
|
|
|
|
|
|
|
|
|
def test_delete(self):
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.tv.delete, '#0')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
item_id = self.tv.insert('', 'end')
|
|
|
|
item2 = self.tv.insert(item_id, 'end')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.get_children(), (item_id, ))
|
|
|
|
self.assertEqual(self.tv.get_children(item_id), (item2, ))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.tv.delete(item_id)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertFalse(self.tv.get_children())
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# reattach should fail
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError,
|
2009-01-28 10:41:10 -04:00
|
|
|
self.tv.reattach, item_id, '', 'end')
|
|
|
|
|
|
|
|
# test multiple item delete
|
|
|
|
item1 = self.tv.insert('', 'end')
|
|
|
|
item2 = self.tv.insert('', 'end')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.get_children(), (item1, item2))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.tv.delete(item1, item2)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertFalse(self.tv.get_children())
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_detach_reattach(self):
|
|
|
|
item_id = self.tv.insert('', 'end')
|
|
|
|
item2 = self.tv.insert(item_id, 'end')
|
|
|
|
|
|
|
|
# calling detach without items is valid, although it does nothing
|
|
|
|
prev = self.tv.get_children()
|
|
|
|
self.tv.detach() # this should do nothing
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(prev, self.tv.get_children())
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.get_children(), (item_id, ))
|
|
|
|
self.assertEqual(self.tv.get_children(item_id), (item2, ))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# detach item with children
|
|
|
|
self.tv.detach(item_id)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertFalse(self.tv.get_children())
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# reattach item with children
|
|
|
|
self.tv.reattach(item_id, '', 'end')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.get_children(), (item_id, ))
|
|
|
|
self.assertEqual(self.tv.get_children(item_id), (item2, ))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# move a children to the root
|
|
|
|
self.tv.move(item2, '', 'end')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.get_children(), (item_id, item2))
|
|
|
|
self.assertEqual(self.tv.get_children(item_id), ())
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# bad values
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError,
|
2009-02-21 16:59:32 -04:00
|
|
|
self.tv.reattach, 'nonexistent', '', 'end')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError,
|
2009-02-21 16:59:32 -04:00
|
|
|
self.tv.detach, 'nonexistent')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError,
|
2009-01-28 10:41:10 -04:00
|
|
|
self.tv.reattach, item2, 'otherparent', 'end')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError,
|
2009-01-28 10:41:10 -04:00
|
|
|
self.tv.reattach, item2, '', 'invalid')
|
|
|
|
|
|
|
|
# multiple detach
|
|
|
|
self.tv.detach(item_id, item2)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.get_children(), ())
|
|
|
|
self.assertEqual(self.tv.get_children(item_id), ())
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_exists(self):
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.exists('something'), False)
|
|
|
|
self.assertEqual(self.tv.exists(''), True)
|
|
|
|
self.assertEqual(self.tv.exists({}), False)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# the following will make a tk.call equivalent to
|
|
|
|
# tk.call(treeview, "exists") which should result in an error
|
|
|
|
# in the tcl interpreter since tk requires an item.
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.tv.exists, None)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_focus(self):
|
|
|
|
# nothing is focused right now
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.focus(), '')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
item1 = self.tv.insert('', 'end')
|
|
|
|
self.tv.focus(item1)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.focus(), item1)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.tv.delete(item1)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.focus(), '')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2009-02-21 16:59:32 -04:00
|
|
|
# try focusing inexistent item
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.tv.focus, 'hi')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_heading(self):
|
|
|
|
# check a dict is returned
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(isinstance(self.tv.heading('#0'), dict))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# check a value is returned
|
|
|
|
self.tv.heading('#0', text='hi')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.heading('#0', 'text'), 'hi')
|
|
|
|
self.assertEqual(self.tv.heading('#0', text=None), 'hi')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# invalid option
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.tv.heading, '#0',
|
2009-01-28 10:41:10 -04:00
|
|
|
background=None)
|
|
|
|
# invalid value
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.tv.heading, '#0',
|
2009-01-28 10:41:10 -04:00
|
|
|
anchor=1)
|
|
|
|
|
|
|
|
def test_heading_callback(self):
|
|
|
|
def simulate_heading_click(x, y):
|
|
|
|
support.simulate_mouse_click(self.tv, x, y)
|
2013-11-02 05:54:31 -03:00
|
|
|
self.tv.update()
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
success = [] # no success for now
|
|
|
|
|
|
|
|
self.tv.pack()
|
|
|
|
self.tv.wait_visibility()
|
|
|
|
self.tv.heading('#0', command=lambda: success.append(True))
|
|
|
|
self.tv.column('#0', width=100)
|
|
|
|
self.tv.update()
|
|
|
|
|
|
|
|
# assuming that the coords (5, 5) fall into heading #0
|
|
|
|
simulate_heading_click(5, 5)
|
|
|
|
if not success:
|
|
|
|
self.fail("The command associated to the treeview heading wasn't "
|
|
|
|
"invoked.")
|
|
|
|
|
|
|
|
success = []
|
|
|
|
commands = self.tv.master._tclCommands
|
|
|
|
self.tv.heading('#0', command=str(self.tv.heading('#0', command=None)))
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(commands, self.tv.master._tclCommands)
|
2009-01-28 10:41:10 -04:00
|
|
|
simulate_heading_click(5, 5)
|
|
|
|
if not success:
|
|
|
|
self.fail("The command associated to the treeview heading wasn't "
|
|
|
|
"invoked.")
|
|
|
|
|
|
|
|
# XXX The following raises an error in a tcl interpreter, but not in
|
|
|
|
# Python
|
|
|
|
#self.tv.heading('#0', command='I dont exist')
|
|
|
|
#simulate_heading_click(5, 5)
|
|
|
|
|
|
|
|
|
|
|
|
def test_index(self):
|
|
|
|
# item 'what' doesn't exist
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.tv.index, 'what')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.index(''), 0)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
item1 = self.tv.insert('', 'end')
|
|
|
|
item2 = self.tv.insert('', 'end')
|
|
|
|
c1 = self.tv.insert(item1, 'end')
|
|
|
|
c2 = self.tv.insert(item1, 'end')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.index(item1), 0)
|
|
|
|
self.assertEqual(self.tv.index(c1), 0)
|
|
|
|
self.assertEqual(self.tv.index(c2), 1)
|
|
|
|
self.assertEqual(self.tv.index(item2), 1)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.tv.move(item2, '', 0)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.index(item2), 0)
|
|
|
|
self.assertEqual(self.tv.index(item1), 1)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# check that index still works even after its parent and siblings
|
|
|
|
# have been detached
|
|
|
|
self.tv.detach(item1)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.index(c2), 1)
|
2009-01-28 10:41:10 -04:00
|
|
|
self.tv.detach(c1)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.index(c2), 0)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# but it fails after item has been deleted
|
|
|
|
self.tv.delete(item1)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.tv.index, c2)
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_insert_item(self):
|
|
|
|
# parent 'none' doesn't exist
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.tv.insert, 'none', 'end')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# open values
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.tv.insert, '', 'end',
|
2009-01-28 10:41:10 -04:00
|
|
|
open='')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.tv.insert, '', 'end',
|
2009-01-28 10:41:10 -04:00
|
|
|
open='please')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertFalse(self.tv.delete(self.tv.insert('', 'end', open=True)))
|
|
|
|
self.assertFalse(self.tv.delete(self.tv.insert('', 'end', open=False)))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# invalid index
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.tv.insert, '', 'middle')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# trying to duplicate item id is invalid
|
|
|
|
itemid = self.tv.insert('', 'end', 'first-item')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(itemid, 'first-item')
|
|
|
|
self.assertRaises(tkinter.TclError, self.tv.insert, '', 'end',
|
2009-01-28 10:41:10 -04:00
|
|
|
'first-item')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.tv.insert, '', 'end',
|
2009-01-28 10:41:10 -04:00
|
|
|
MockTclObj('first-item'))
|
|
|
|
|
|
|
|
# unicode values
|
|
|
|
value = '\xe1ba'
|
|
|
|
item = self.tv.insert('', 'end', values=(value, ))
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.item(item, 'values'), (value, ))
|
|
|
|
self.assertEqual(self.tv.item(item, values=None), (value, ))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.tv.item(item, values=list(self.tv.item(item, values=None)))
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.item(item, values=None), (value, ))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(isinstance(self.tv.item(item), dict))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# erase item values
|
|
|
|
self.tv.item(item, values='')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertFalse(self.tv.item(item, values=None))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# item tags
|
|
|
|
item = self.tv.insert('', 'end', tags=[1, 2, value])
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.item(item, tags=None), ('1', '2', value))
|
2009-01-28 10:41:10 -04:00
|
|
|
self.tv.item(item, tags=[])
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertFalse(self.tv.item(item, tags=None))
|
2009-01-28 10:41:10 -04:00
|
|
|
self.tv.item(item, tags=(1, 2))
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.item(item, tags=None), ('1', '2'))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
# values with spaces
|
|
|
|
item = self.tv.insert('', 'end', values=('a b c',
|
|
|
|
'%s %s' % (value, value)))
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.item(item, values=None),
|
2009-01-28 10:41:10 -04:00
|
|
|
('a b c', '%s %s' % (value, value)))
|
|
|
|
|
|
|
|
# text
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.item(
|
2009-01-28 10:41:10 -04:00
|
|
|
self.tv.insert('', 'end', text="Label here"), text=None),
|
|
|
|
"Label here")
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.item(
|
2009-01-28 10:41:10 -04:00
|
|
|
self.tv.insert('', 'end', text=value), text=None),
|
|
|
|
value)
|
|
|
|
|
|
|
|
|
|
|
|
def test_set(self):
|
|
|
|
self.tv['columns'] = ['A', 'B']
|
|
|
|
item = self.tv.insert('', 'end', values=['a', 'b'])
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.set(item), {'A': 'a', 'B': 'b'})
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.tv.set(item, 'B', 'a')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.item(item, values=None), ('a', 'a'))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.tv['columns'] = ['B']
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.set(item), {'B': 'a'})
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.tv.set(item, 'B', 'b')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.set(item, column='B'), 'b')
|
|
|
|
self.assertEqual(self.tv.item(item, values=None), ('b', 'a'))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
self.tv.set(item, 'B', 123)
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(self.tv.set(item, 'B'), 123)
|
|
|
|
self.assertEqual(self.tv.item(item, values=None), (123, 'a'))
|
|
|
|
self.assertEqual(self.tv.set(item), {'B': 123})
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2009-02-21 16:59:32 -04:00
|
|
|
# inexistent column
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.tv.set, item, 'A')
|
|
|
|
self.assertRaises(tkinter.TclError, self.tv.set, item, 'A', 'b')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
2009-02-21 16:59:32 -04:00
|
|
|
# inexistent item
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(tkinter.TclError, self.tv.set, 'notme')
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_tag_bind(self):
|
|
|
|
events = []
|
|
|
|
item1 = self.tv.insert('', 'end', tags=['call'])
|
|
|
|
item2 = self.tv.insert('', 'end', tags=['call'])
|
|
|
|
self.tv.tag_bind('call', '<ButtonPress-1>',
|
|
|
|
lambda evt: events.append(1))
|
|
|
|
self.tv.tag_bind('call', '<ButtonRelease-1>',
|
|
|
|
lambda evt: events.append(2))
|
|
|
|
|
|
|
|
self.tv.pack()
|
|
|
|
self.tv.wait_visibility()
|
|
|
|
self.tv.update()
|
|
|
|
|
|
|
|
pos_y = set()
|
|
|
|
found = set()
|
|
|
|
for i in range(0, 100, 10):
|
|
|
|
if len(found) == 2: # item1 and item2 already found
|
|
|
|
break
|
|
|
|
item_id = self.tv.identify_row(i)
|
|
|
|
if item_id and item_id not in found:
|
|
|
|
pos_y.add(i)
|
|
|
|
found.add(item_id)
|
|
|
|
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(len(pos_y), 2) # item1 and item2 y pos
|
2009-01-28 10:41:10 -04:00
|
|
|
for y in pos_y:
|
|
|
|
support.simulate_mouse_click(self.tv, 0, y)
|
|
|
|
|
|
|
|
# by now there should be 4 things in the events list, since each
|
|
|
|
# item had a bind for two events that were simulated above
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(len(events), 4)
|
2009-01-28 10:41:10 -04:00
|
|
|
for evt in zip(events[::2], events[1::2]):
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertEqual(evt, (1, 2))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_tag_configure(self):
|
|
|
|
# Just testing parameter passing for now
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertRaises(TypeError, self.tv.tag_configure)
|
|
|
|
self.assertRaises(tkinter.TclError, self.tv.tag_configure,
|
2009-01-28 10:41:10 -04:00
|
|
|
'test', sky='blue')
|
|
|
|
self.tv.tag_configure('test', foreground='blue')
|
2010-04-11 19:04:51 -03:00
|
|
|
self.assertEqual(str(self.tv.tag_configure('test', 'foreground')),
|
2009-01-28 10:41:10 -04:00
|
|
|
'blue')
|
2010-04-11 19:04:51 -03:00
|
|
|
self.assertEqual(str(self.tv.tag_configure('test', foreground=None)),
|
2009-01-28 10:41:10 -04:00
|
|
|
'blue')
|
2009-06-30 20:06:06 -03:00
|
|
|
self.assertTrue(isinstance(self.tv.tag_configure('test'), dict))
|
2009-01-28 10:41:10 -04:00
|
|
|
|
|
|
|
|
2013-11-02 05:41:48 -03:00
|
|
|
@add_standard_options(StandardTtkOptionsTests)
|
|
|
|
class SeparatorTest(AbstractWidgetTest, unittest.TestCase):
|
|
|
|
OPTIONS = (
|
|
|
|
'class', 'cursor', 'orient', 'style', 'takefocus',
|
|
|
|
# 'state'?
|
|
|
|
)
|
|
|
|
default_orient = 'horizontal'
|
|
|
|
|
|
|
|
def _create(self, **kwargs):
|
|
|
|
return ttk.Separator(self.root, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
@add_standard_options(StandardTtkOptionsTests)
|
|
|
|
class SizegripTest(AbstractWidgetTest, unittest.TestCase):
|
|
|
|
OPTIONS = (
|
|
|
|
'class', 'cursor', 'style', 'takefocus',
|
|
|
|
# 'state'?
|
|
|
|
)
|
|
|
|
|
|
|
|
def _create(self, **kwargs):
|
|
|
|
return ttk.Sizegrip(self.root, **kwargs)
|
|
|
|
|
2009-01-28 10:41:10 -04:00
|
|
|
tests_gui = (
|
2013-11-02 05:41:48 -03:00
|
|
|
ButtonTest, CheckbuttonTest, ComboboxTest, EntryTest,
|
|
|
|
FrameTest, LabelFrameTest, LabelTest, MenubuttonTest,
|
|
|
|
NotebookTest, PanedWindowTest, ProgressbarTest,
|
|
|
|
RadiobuttonTest, ScaleTest, ScrollbarTest, SeparatorTest,
|
|
|
|
SizegripTest, TreeviewTest, WidgetTest,
|
2009-01-28 10:41:10 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2013-11-02 05:41:48 -03:00
|
|
|
unittest.main()
|