@@ -77,3 +77,42 @@ def simulate_mouse_click(widget, x, y):
7777 widget .event_generate ('<Motion>' , x = x , y = y )
7878 widget .event_generate ('<ButtonPress-1>' , x = x , y = y )
7979 widget .event_generate ('<ButtonRelease-1>' , x = x , y = y )
80+
81+
82+ import _tkinter
83+ tcl_version = tuple (map (int , _tkinter .TCL_VERSION .split ('.' )))
84+
85+ def requires_tcl (* version ):
86+ return unittest .skipUnless (tcl_version >= version ,
87+ 'requires Tcl version >= ' + '.' .join (map (str , version )))
88+
89+ units = {
90+ 'c' : 72 / 2.54 , # centimeters
91+ 'i' : 72 , # inches
92+ 'm' : 72 / 25.4 , # millimeters
93+ 'p' : 1 , # points
94+ }
95+
96+ def pixels_conv (value ):
97+ return float (value [:- 1 ]) * units [value [- 1 :]]
98+
99+ def tcl_obj_eq (actual , expected ):
100+ if actual == expected :
101+ return True
102+ if isinstance (actual , _tkinter .Tcl_Obj ):
103+ if isinstance (expected , str ):
104+ return str (actual ) == expected
105+ if isinstance (actual , tuple ):
106+ if isinstance (expected , tuple ):
107+ return (len (actual ) == len (expected ) and
108+ all (tcl_obj_eq (act , exp )
109+ for act , exp in zip (actual , expected )))
110+ return False
111+
112+ def widget_eq (actual , expected ):
113+ if actual == expected :
114+ return True
115+ if isinstance (actual , (str , tkinter .Widget )):
116+ if isinstance (expected , (str , tkinter .Widget )):
117+ return str (actual ) == str (expected )
118+ return False
0 commit comments