@simplexai/localmodels-darwin-arm64 0.1.0-dev.31.build.gitb5579b4b26f273bf03468c6aedf61b327fa6c245 → 0.1.0-dev.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (583) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +10 -582
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/{simplex_localmodels-0.1.0.dev31.dist-info → simplex_localmodels-0.1.0.dev32.dist-info}/METADATA +1 -1
  5. package/modules/{simplex_localmodels-0.1.0.dev31.dist-info → simplex_localmodels-0.1.0.dev32.dist-info}/RECORD +7 -7
  6. package/package.json +1 -1
  7. package/tool.json +1 -1
  8. package/python/bin/2to3 +0 -7
  9. package/python/bin/2to3-3.12 +0 -7
  10. package/python/bin/idle3 +0 -7
  11. package/python/bin/idle3.12 +0 -7
  12. package/python/bin/pip +0 -8
  13. package/python/bin/pip3 +0 -8
  14. package/python/bin/pip3.12 +0 -8
  15. package/python/bin/pydoc3 +0 -7
  16. package/python/bin/pydoc3.12 +0 -7
  17. package/python/bin/python +0 -0
  18. package/python/bin/python3 +0 -0
  19. package/python/bin/python3-config +0 -76
  20. package/python/bin/python3.12-config +0 -76
  21. package/python/include/python3.12/Python.h +0 -109
  22. package/python/include/python3.12/abstract.h +0 -899
  23. package/python/include/python3.12/bltinmodule.h +0 -14
  24. package/python/include/python3.12/boolobject.h +0 -42
  25. package/python/include/python3.12/bytearrayobject.h +0 -44
  26. package/python/include/python3.12/bytesobject.h +0 -69
  27. package/python/include/python3.12/ceval.h +0 -168
  28. package/python/include/python3.12/codecs.h +0 -248
  29. package/python/include/python3.12/compile.h +0 -22
  30. package/python/include/python3.12/complexobject.h +0 -30
  31. package/python/include/python3.12/cpython/abstract.h +0 -206
  32. package/python/include/python3.12/cpython/bytearrayobject.h +0 -34
  33. package/python/include/python3.12/cpython/bytesobject.h +0 -133
  34. package/python/include/python3.12/cpython/cellobject.h +0 -44
  35. package/python/include/python3.12/cpython/ceval.h +0 -35
  36. package/python/include/python3.12/cpython/classobject.h +0 -71
  37. package/python/include/python3.12/cpython/code.h +0 -389
  38. package/python/include/python3.12/cpython/compile.h +0 -69
  39. package/python/include/python3.12/cpython/complexobject.h +0 -44
  40. package/python/include/python3.12/cpython/context.h +0 -78
  41. package/python/include/python3.12/cpython/descrobject.h +0 -64
  42. package/python/include/python3.12/cpython/dictobject.h +0 -118
  43. package/python/include/python3.12/cpython/fileobject.h +0 -19
  44. package/python/include/python3.12/cpython/fileutils.h +0 -8
  45. package/python/include/python3.12/cpython/floatobject.h +0 -27
  46. package/python/include/python3.12/cpython/frameobject.h +0 -29
  47. package/python/include/python3.12/cpython/funcobject.h +0 -190
  48. package/python/include/python3.12/cpython/genobject.h +0 -89
  49. package/python/include/python3.12/cpython/import.h +0 -46
  50. package/python/include/python3.12/cpython/initconfig.h +0 -256
  51. package/python/include/python3.12/cpython/interpreteridobject.h +0 -11
  52. package/python/include/python3.12/cpython/listobject.h +0 -47
  53. package/python/include/python3.12/cpython/longintrepr.h +0 -133
  54. package/python/include/python3.12/cpython/longobject.h +0 -100
  55. package/python/include/python3.12/cpython/memoryobject.h +0 -52
  56. package/python/include/python3.12/cpython/methodobject.h +0 -66
  57. package/python/include/python3.12/cpython/modsupport.h +0 -109
  58. package/python/include/python3.12/cpython/object.h +0 -575
  59. package/python/include/python3.12/cpython/objimpl.h +0 -95
  60. package/python/include/python3.12/cpython/odictobject.h +0 -43
  61. package/python/include/python3.12/cpython/picklebufobject.h +0 -31
  62. package/python/include/python3.12/cpython/pthread_stubs.h +0 -88
  63. package/python/include/python3.12/cpython/pyctype.h +0 -39
  64. package/python/include/python3.12/cpython/pydebug.h +0 -38
  65. package/python/include/python3.12/cpython/pyerrors.h +0 -178
  66. package/python/include/python3.12/cpython/pyfpe.h +0 -15
  67. package/python/include/python3.12/cpython/pyframe.h +0 -35
  68. package/python/include/python3.12/cpython/pylifecycle.h +0 -111
  69. package/python/include/python3.12/cpython/pymem.h +0 -98
  70. package/python/include/python3.12/cpython/pystate.h +0 -456
  71. package/python/include/python3.12/cpython/pythonrun.h +0 -121
  72. package/python/include/python3.12/cpython/pythread.h +0 -42
  73. package/python/include/python3.12/cpython/pytime.h +0 -331
  74. package/python/include/python3.12/cpython/setobject.h +0 -72
  75. package/python/include/python3.12/cpython/sysmodule.h +0 -16
  76. package/python/include/python3.12/cpython/traceback.h +0 -16
  77. package/python/include/python3.12/cpython/tupleobject.h +0 -39
  78. package/python/include/python3.12/cpython/unicodeobject.h +0 -976
  79. package/python/include/python3.12/cpython/warnings.h +0 -20
  80. package/python/include/python3.12/cpython/weakrefobject.h +0 -56
  81. package/python/include/python3.12/datetime.h +0 -267
  82. package/python/include/python3.12/descrobject.h +0 -100
  83. package/python/include/python3.12/dictobject.h +0 -97
  84. package/python/include/python3.12/dynamic_annotations.h +0 -499
  85. package/python/include/python3.12/enumobject.h +0 -17
  86. package/python/include/python3.12/errcode.h +0 -38
  87. package/python/include/python3.12/exports.h +0 -36
  88. package/python/include/python3.12/fileobject.h +0 -49
  89. package/python/include/python3.12/fileutils.h +0 -26
  90. package/python/include/python3.12/floatobject.h +0 -54
  91. package/python/include/python3.12/frameobject.h +0 -20
  92. package/python/include/python3.12/genericaliasobject.h +0 -14
  93. package/python/include/python3.12/import.h +0 -98
  94. package/python/include/python3.12/internal/pycore_abstract.h +0 -25
  95. package/python/include/python3.12/internal/pycore_asdl.h +0 -112
  96. package/python/include/python3.12/internal/pycore_ast.h +0 -922
  97. package/python/include/python3.12/internal/pycore_ast_state.h +0 -265
  98. package/python/include/python3.12/internal/pycore_atexit.h +0 -57
  99. package/python/include/python3.12/internal/pycore_atomic.h +0 -557
  100. package/python/include/python3.12/internal/pycore_atomic_funcs.h +0 -94
  101. package/python/include/python3.12/internal/pycore_bitutils.h +0 -186
  102. package/python/include/python3.12/internal/pycore_blocks_output_buffer.h +0 -317
  103. package/python/include/python3.12/internal/pycore_bytes_methods.h +0 -73
  104. package/python/include/python3.12/internal/pycore_bytesobject.h +0 -47
  105. package/python/include/python3.12/internal/pycore_call.h +0 -133
  106. package/python/include/python3.12/internal/pycore_ceval.h +0 -164
  107. package/python/include/python3.12/internal/pycore_ceval_state.h +0 -103
  108. package/python/include/python3.12/internal/pycore_code.h +0 -496
  109. package/python/include/python3.12/internal/pycore_compile.h +0 -118
  110. package/python/include/python3.12/internal/pycore_condvar.h +0 -99
  111. package/python/include/python3.12/internal/pycore_context.h +0 -71
  112. package/python/include/python3.12/internal/pycore_descrobject.h +0 -26
  113. package/python/include/python3.12/internal/pycore_dict.h +0 -199
  114. package/python/include/python3.12/internal/pycore_dict_state.h +0 -50
  115. package/python/include/python3.12/internal/pycore_dtoa.h +0 -69
  116. package/python/include/python3.12/internal/pycore_emscripten_signal.h +0 -25
  117. package/python/include/python3.12/internal/pycore_exceptions.h +0 -37
  118. package/python/include/python3.12/internal/pycore_faulthandler.h +0 -99
  119. package/python/include/python3.12/internal/pycore_fileutils.h +0 -292
  120. package/python/include/python3.12/internal/pycore_fileutils_windows.h +0 -98
  121. package/python/include/python3.12/internal/pycore_floatobject.h +0 -71
  122. package/python/include/python3.12/internal/pycore_flowgraph.h +0 -120
  123. package/python/include/python3.12/internal/pycore_format.h +0 -27
  124. package/python/include/python3.12/internal/pycore_frame.h +0 -283
  125. package/python/include/python3.12/internal/pycore_function.h +0 -26
  126. package/python/include/python3.12/internal/pycore_gc.h +0 -211
  127. package/python/include/python3.12/internal/pycore_genobject.h +0 -49
  128. package/python/include/python3.12/internal/pycore_getopt.h +0 -22
  129. package/python/include/python3.12/internal/pycore_gil.h +0 -50
  130. package/python/include/python3.12/internal/pycore_global_objects.h +0 -105
  131. package/python/include/python3.12/internal/pycore_global_objects_fini_generated.h +0 -1517
  132. package/python/include/python3.12/internal/pycore_global_strings.h +0 -777
  133. package/python/include/python3.12/internal/pycore_hamt.h +0 -134
  134. package/python/include/python3.12/internal/pycore_hashtable.h +0 -149
  135. package/python/include/python3.12/internal/pycore_import.h +0 -183
  136. package/python/include/python3.12/internal/pycore_initconfig.h +0 -179
  137. package/python/include/python3.12/internal/pycore_instruments.h +0 -106
  138. package/python/include/python3.12/internal/pycore_interp.h +0 -275
  139. package/python/include/python3.12/internal/pycore_intrinsics.h +0 -32
  140. package/python/include/python3.12/internal/pycore_list.h +0 -83
  141. package/python/include/python3.12/internal/pycore_long.h +0 -258
  142. package/python/include/python3.12/internal/pycore_memoryobject.h +0 -18
  143. package/python/include/python3.12/internal/pycore_moduleobject.h +0 -45
  144. package/python/include/python3.12/internal/pycore_namespace.h +0 -20
  145. package/python/include/python3.12/internal/pycore_object.h +0 -455
  146. package/python/include/python3.12/internal/pycore_object_state.h +0 -42
  147. package/python/include/python3.12/internal/pycore_obmalloc.h +0 -700
  148. package/python/include/python3.12/internal/pycore_obmalloc_init.h +0 -73
  149. package/python/include/python3.12/internal/pycore_opcode.h +0 -587
  150. package/python/include/python3.12/internal/pycore_opcode_utils.h +0 -92
  151. package/python/include/python3.12/internal/pycore_parser.h +0 -66
  152. package/python/include/python3.12/internal/pycore_pathconfig.h +0 -24
  153. package/python/include/python3.12/internal/pycore_pyarena.h +0 -64
  154. package/python/include/python3.12/internal/pycore_pyerrors.h +0 -129
  155. package/python/include/python3.12/internal/pycore_pyhash.h +0 -40
  156. package/python/include/python3.12/internal/pycore_pylifecycle.h +0 -99
  157. package/python/include/python3.12/internal/pycore_pymath.h +0 -205
  158. package/python/include/python3.12/internal/pycore_pymem.h +0 -98
  159. package/python/include/python3.12/internal/pycore_pymem_init.h +0 -85
  160. package/python/include/python3.12/internal/pycore_pystate.h +0 -180
  161. package/python/include/python3.12/internal/pycore_pythread.h +0 -81
  162. package/python/include/python3.12/internal/pycore_range.h +0 -21
  163. package/python/include/python3.12/internal/pycore_runtime.h +0 -235
  164. package/python/include/python3.12/internal/pycore_runtime_init.h +0 -188
  165. package/python/include/python3.12/internal/pycore_runtime_init_generated.h +0 -1511
  166. package/python/include/python3.12/internal/pycore_signal.h +0 -98
  167. package/python/include/python3.12/internal/pycore_sliceobject.h +0 -22
  168. package/python/include/python3.12/internal/pycore_strhex.h +0 -36
  169. package/python/include/python3.12/internal/pycore_structseq.h +0 -39
  170. package/python/include/python3.12/internal/pycore_symtable.h +0 -160
  171. package/python/include/python3.12/internal/pycore_sysmodule.h +0 -34
  172. package/python/include/python3.12/internal/pycore_time.h +0 -25
  173. package/python/include/python3.12/internal/pycore_token.h +0 -108
  174. package/python/include/python3.12/internal/pycore_traceback.h +0 -101
  175. package/python/include/python3.12/internal/pycore_tracemalloc.h +0 -123
  176. package/python/include/python3.12/internal/pycore_tuple.h +0 -79
  177. package/python/include/python3.12/internal/pycore_typeobject.h +0 -151
  178. package/python/include/python3.12/internal/pycore_typevarobject.h +0 -24
  179. package/python/include/python3.12/internal/pycore_ucnhash.h +0 -34
  180. package/python/include/python3.12/internal/pycore_unicodeobject.h +0 -86
  181. package/python/include/python3.12/internal/pycore_unicodeobject_generated.h +0 -2832
  182. package/python/include/python3.12/internal/pycore_unionobject.h +0 -23
  183. package/python/include/python3.12/internal/pycore_warnings.h +0 -29
  184. package/python/include/python3.12/interpreteridobject.h +0 -17
  185. package/python/include/python3.12/intrcheck.h +0 -30
  186. package/python/include/python3.12/iterobject.h +0 -27
  187. package/python/include/python3.12/listobject.h +0 -52
  188. package/python/include/python3.12/longobject.h +0 -108
  189. package/python/include/python3.12/marshal.h +0 -31
  190. package/python/include/python3.12/memoryobject.h +0 -34
  191. package/python/include/python3.12/methodobject.h +0 -132
  192. package/python/include/python3.12/modsupport.h +0 -168
  193. package/python/include/python3.12/moduleobject.h +0 -119
  194. package/python/include/python3.12/object.h +0 -993
  195. package/python/include/python3.12/objimpl.h +0 -234
  196. package/python/include/python3.12/opcode.h +0 -271
  197. package/python/include/python3.12/osdefs.h +0 -51
  198. package/python/include/python3.12/osmodule.h +0 -17
  199. package/python/include/python3.12/patchlevel.h +0 -35
  200. package/python/include/python3.12/py_curses.h +0 -99
  201. package/python/include/python3.12/pybuffer.h +0 -145
  202. package/python/include/python3.12/pycapsule.h +0 -59
  203. package/python/include/python3.12/pyconfig.h +0 -1943
  204. package/python/include/python3.12/pydtrace.h +0 -59
  205. package/python/include/python3.12/pyerrors.h +0 -337
  206. package/python/include/python3.12/pyexpat.h +0 -70
  207. package/python/include/python3.12/pyframe.h +0 -26
  208. package/python/include/python3.12/pyhash.h +0 -146
  209. package/python/include/python3.12/pylifecycle.h +0 -78
  210. package/python/include/python3.12/pymacconfig.h +0 -99
  211. package/python/include/python3.12/pymacro.h +0 -172
  212. package/python/include/python3.12/pymath.h +0 -62
  213. package/python/include/python3.12/pymem.h +0 -104
  214. package/python/include/python3.12/pyport.h +0 -782
  215. package/python/include/python3.12/pystate.h +0 -132
  216. package/python/include/python3.12/pystats.h +0 -110
  217. package/python/include/python3.12/pystrcmp.h +0 -23
  218. package/python/include/python3.12/pystrtod.h +0 -46
  219. package/python/include/python3.12/pythonrun.h +0 -49
  220. package/python/include/python3.12/pythread.h +0 -135
  221. package/python/include/python3.12/pytypedefs.h +0 -30
  222. package/python/include/python3.12/rangeobject.h +0 -27
  223. package/python/include/python3.12/setobject.h +0 -49
  224. package/python/include/python3.12/sliceobject.h +0 -65
  225. package/python/include/python3.12/structmember.h +0 -56
  226. package/python/include/python3.12/structseq.h +0 -49
  227. package/python/include/python3.12/sysmodule.h +0 -54
  228. package/python/include/python3.12/traceback.h +0 -26
  229. package/python/include/python3.12/tracemalloc.h +0 -77
  230. package/python/include/python3.12/tupleobject.h +0 -46
  231. package/python/include/python3.12/typeslots.h +0 -88
  232. package/python/include/python3.12/unicodeobject.h +0 -1020
  233. package/python/include/python3.12/warnings.h +0 -45
  234. package/python/include/python3.12/weakrefobject.h +0 -42
  235. package/python/lib/itcl4.3.8/itcl.tcl +0 -151
  236. package/python/lib/itcl4.3.8/itclConfig.sh +0 -67
  237. package/python/lib/itcl4.3.8/itclHullCmds.tcl +0 -562
  238. package/python/lib/itcl4.3.8/itclWidget.tcl +0 -447
  239. package/python/lib/itcl4.3.8/libitcl4.3.8.dylib +0 -0
  240. package/python/lib/itcl4.3.8/libitclstub.a +0 -0
  241. package/python/lib/itcl4.3.8/libitclstub4.3.8.a +0 -0
  242. package/python/lib/itcl4.3.8/libtcl9itcl4.3.8.dylib +0 -0
  243. package/python/lib/itcl4.3.8/pkgIndex.tcl +0 -14
  244. package/python/lib/libpython3.12.dylib +0 -0
  245. package/python/lib/libtcl9.0.dylib +0 -0
  246. package/python/lib/libtcl9tk9.0.dylib +0 -0
  247. package/python/lib/pkgconfig/python-3.12-embed.pc +0 -13
  248. package/python/lib/pkgconfig/python-3.12.pc +0 -13
  249. package/python/lib/pkgconfig/python3-embed.pc +0 -13
  250. package/python/lib/pkgconfig/python3.pc +0 -13
  251. package/python/lib/python3.12/config-3.12-darwin/Makefile +0 -3273
  252. package/python/lib/python3.12/config-3.12-darwin/Setup +0 -303
  253. package/python/lib/python3.12/config-3.12-darwin/Setup.bootstrap +0 -36
  254. package/python/lib/python3.12/config-3.12-darwin/Setup.local +0 -19
  255. package/python/lib/python3.12/config-3.12-darwin/Setup.stdlib +0 -183
  256. package/python/lib/python3.12/config-3.12-darwin/config.c +0 -246
  257. package/python/lib/python3.12/config-3.12-darwin/config.c.in +0 -71
  258. package/python/lib/python3.12/config-3.12-darwin/install-sh +0 -541
  259. package/python/lib/python3.12/config-3.12-darwin/makesetup +0 -353
  260. package/python/lib/python3.12/config-3.12-darwin/python-config.py +0 -76
  261. package/python/lib/python3.12/config-3.12-darwin/python.o +0 -0
  262. package/python/lib/python3.12/idlelib/CREDITS.txt +0 -47
  263. package/python/lib/python3.12/idlelib/ChangeLog +0 -1591
  264. package/python/lib/python3.12/idlelib/HISTORY.txt +0 -296
  265. package/python/lib/python3.12/idlelib/Icons/README.txt +0 -51
  266. package/python/lib/python3.12/idlelib/Icons/folder.gif +0 -0
  267. package/python/lib/python3.12/idlelib/Icons/idle.ico +0 -0
  268. package/python/lib/python3.12/idlelib/Icons/idle_16.gif +0 -0
  269. package/python/lib/python3.12/idlelib/Icons/idle_16.png +0 -0
  270. package/python/lib/python3.12/idlelib/Icons/idle_256.png +0 -0
  271. package/python/lib/python3.12/idlelib/Icons/idle_32.gif +0 -0
  272. package/python/lib/python3.12/idlelib/Icons/idle_32.png +0 -0
  273. package/python/lib/python3.12/idlelib/Icons/idle_48.gif +0 -0
  274. package/python/lib/python3.12/idlelib/Icons/idle_48.png +0 -0
  275. package/python/lib/python3.12/idlelib/Icons/minusnode.gif +0 -0
  276. package/python/lib/python3.12/idlelib/Icons/openfolder.gif +0 -0
  277. package/python/lib/python3.12/idlelib/Icons/plusnode.gif +0 -0
  278. package/python/lib/python3.12/idlelib/Icons/python.gif +0 -0
  279. package/python/lib/python3.12/idlelib/Icons/tk.gif +0 -0
  280. package/python/lib/python3.12/idlelib/NEWS2x.txt +0 -660
  281. package/python/lib/python3.12/idlelib/News3.txt +0 -1390
  282. package/python/lib/python3.12/idlelib/README.txt +0 -290
  283. package/python/lib/python3.12/idlelib/TODO.txt +0 -210
  284. package/python/lib/python3.12/idlelib/__init__.py +0 -10
  285. package/python/lib/python3.12/idlelib/__main__.py +0 -7
  286. package/python/lib/python3.12/idlelib/autocomplete.py +0 -228
  287. package/python/lib/python3.12/idlelib/autocomplete_w.py +0 -498
  288. package/python/lib/python3.12/idlelib/autoexpand.py +0 -96
  289. package/python/lib/python3.12/idlelib/browser.py +0 -260
  290. package/python/lib/python3.12/idlelib/calltip.py +0 -205
  291. package/python/lib/python3.12/idlelib/calltip_w.py +0 -202
  292. package/python/lib/python3.12/idlelib/codecontext.py +0 -270
  293. package/python/lib/python3.12/idlelib/colorizer.py +0 -384
  294. package/python/lib/python3.12/idlelib/config-extensions.def +0 -62
  295. package/python/lib/python3.12/idlelib/config-highlight.def +0 -105
  296. package/python/lib/python3.12/idlelib/config-keys.def +0 -309
  297. package/python/lib/python3.12/idlelib/config-main.def +0 -93
  298. package/python/lib/python3.12/idlelib/config.py +0 -917
  299. package/python/lib/python3.12/idlelib/config_key.py +0 -354
  300. package/python/lib/python3.12/idlelib/configdialog.py +0 -2408
  301. package/python/lib/python3.12/idlelib/debugger.py +0 -602
  302. package/python/lib/python3.12/idlelib/debugger_r.py +0 -390
  303. package/python/lib/python3.12/idlelib/debugobj.py +0 -146
  304. package/python/lib/python3.12/idlelib/debugobj_r.py +0 -41
  305. package/python/lib/python3.12/idlelib/delegator.py +0 -34
  306. package/python/lib/python3.12/idlelib/dynoption.py +0 -57
  307. package/python/lib/python3.12/idlelib/editor.py +0 -1767
  308. package/python/lib/python3.12/idlelib/extend.txt +0 -83
  309. package/python/lib/python3.12/idlelib/filelist.py +0 -132
  310. package/python/lib/python3.12/idlelib/format.py +0 -426
  311. package/python/lib/python3.12/idlelib/grep.py +0 -223
  312. package/python/lib/python3.12/idlelib/help.html +0 -805
  313. package/python/lib/python3.12/idlelib/help.py +0 -297
  314. package/python/lib/python3.12/idlelib/help_about.py +0 -211
  315. package/python/lib/python3.12/idlelib/history.py +0 -106
  316. package/python/lib/python3.12/idlelib/hyperparser.py +0 -312
  317. package/python/lib/python3.12/idlelib/idle.bat +0 -4
  318. package/python/lib/python3.12/idlelib/idle.py +0 -14
  319. package/python/lib/python3.12/idlelib/idle.pyw +0 -17
  320. package/python/lib/python3.12/idlelib/iomenu.py +0 -441
  321. package/python/lib/python3.12/idlelib/macosx.py +0 -278
  322. package/python/lib/python3.12/idlelib/mainmenu.py +0 -126
  323. package/python/lib/python3.12/idlelib/multicall.py +0 -451
  324. package/python/lib/python3.12/idlelib/outwin.py +0 -188
  325. package/python/lib/python3.12/idlelib/parenmatch.py +0 -183
  326. package/python/lib/python3.12/idlelib/pathbrowser.py +0 -107
  327. package/python/lib/python3.12/idlelib/percolator.py +0 -120
  328. package/python/lib/python3.12/idlelib/pyparse.py +0 -589
  329. package/python/lib/python3.12/idlelib/pyshell.py +0 -1694
  330. package/python/lib/python3.12/idlelib/query.py +0 -392
  331. package/python/lib/python3.12/idlelib/redirector.py +0 -173
  332. package/python/lib/python3.12/idlelib/replace.py +0 -300
  333. package/python/lib/python3.12/idlelib/rpc.py +0 -635
  334. package/python/lib/python3.12/idlelib/run.py +0 -646
  335. package/python/lib/python3.12/idlelib/runscript.py +0 -213
  336. package/python/lib/python3.12/idlelib/scrolledlist.py +0 -151
  337. package/python/lib/python3.12/idlelib/search.py +0 -165
  338. package/python/lib/python3.12/idlelib/searchbase.py +0 -210
  339. package/python/lib/python3.12/idlelib/searchengine.py +0 -235
  340. package/python/lib/python3.12/idlelib/sidebar.py +0 -544
  341. package/python/lib/python3.12/idlelib/squeezer.py +0 -345
  342. package/python/lib/python3.12/idlelib/stackviewer.py +0 -134
  343. package/python/lib/python3.12/idlelib/statusbar.py +0 -52
  344. package/python/lib/python3.12/idlelib/textview.py +0 -193
  345. package/python/lib/python3.12/idlelib/tooltip.py +0 -190
  346. package/python/lib/python3.12/idlelib/tree.py +0 -509
  347. package/python/lib/python3.12/idlelib/undo.py +0 -367
  348. package/python/lib/python3.12/idlelib/util.py +0 -37
  349. package/python/lib/python3.12/idlelib/window.py +0 -98
  350. package/python/lib/python3.12/idlelib/zoomheight.py +0 -124
  351. package/python/lib/python3.12/idlelib/zzdummy.py +0 -73
  352. package/python/lib/python3.12/lib-dynload/_tkinter.cpython-312-darwin.so +0 -0
  353. package/python/lib/python3.12/tkinter/__init__.py +0 -4682
  354. package/python/lib/python3.12/tkinter/__main__.py +0 -7
  355. package/python/lib/python3.12/tkinter/colorchooser.py +0 -86
  356. package/python/lib/python3.12/tkinter/commondialog.py +0 -53
  357. package/python/lib/python3.12/tkinter/constants.py +0 -110
  358. package/python/lib/python3.12/tkinter/dialog.py +0 -49
  359. package/python/lib/python3.12/tkinter/dnd.py +0 -324
  360. package/python/lib/python3.12/tkinter/filedialog.py +0 -492
  361. package/python/lib/python3.12/tkinter/font.py +0 -239
  362. package/python/lib/python3.12/tkinter/messagebox.py +0 -146
  363. package/python/lib/python3.12/tkinter/scrolledtext.py +0 -56
  364. package/python/lib/python3.12/tkinter/simpledialog.py +0 -441
  365. package/python/lib/python3.12/tkinter/tix.py +0 -1948
  366. package/python/lib/python3.12/tkinter/ttk.py +0 -1640
  367. package/python/lib/python3.12/turtle.py +0 -4207
  368. package/python/lib/python3.12/turtledemo/__init__.py +0 -14
  369. package/python/lib/python3.12/turtledemo/__main__.py +0 -404
  370. package/python/lib/python3.12/turtledemo/bytedesign.py +0 -161
  371. package/python/lib/python3.12/turtledemo/chaos.py +0 -59
  372. package/python/lib/python3.12/turtledemo/clock.py +0 -138
  373. package/python/lib/python3.12/turtledemo/colormixer.py +0 -58
  374. package/python/lib/python3.12/turtledemo/forest.py +0 -108
  375. package/python/lib/python3.12/turtledemo/fractalcurves.py +0 -138
  376. package/python/lib/python3.12/turtledemo/lindenmayer.py +0 -119
  377. package/python/lib/python3.12/turtledemo/minimal_hanoi.py +0 -79
  378. package/python/lib/python3.12/turtledemo/nim.py +0 -226
  379. package/python/lib/python3.12/turtledemo/paint.py +0 -54
  380. package/python/lib/python3.12/turtledemo/peace.py +0 -61
  381. package/python/lib/python3.12/turtledemo/penrose.py +0 -175
  382. package/python/lib/python3.12/turtledemo/planet_and_moon.py +0 -111
  383. package/python/lib/python3.12/turtledemo/rosette.py +0 -65
  384. package/python/lib/python3.12/turtledemo/round_dance.py +0 -86
  385. package/python/lib/python3.12/turtledemo/sorting_animate.py +0 -204
  386. package/python/lib/python3.12/turtledemo/tree.py +0 -62
  387. package/python/lib/python3.12/turtledemo/turtle.cfg +0 -10
  388. package/python/lib/python3.12/turtledemo/two_canvases.py +0 -54
  389. package/python/lib/python3.12/turtledemo/yinyang.py +0 -49
  390. package/python/lib/tcl9/9.0/http-2.10.2.tm +0 -5451
  391. package/python/lib/tcl9/9.0/msgcat-1.7.1.tm +0 -1349
  392. package/python/lib/tcl9/9.0/platform/shell-1.1.4.tm +0 -241
  393. package/python/lib/tcl9/9.0/platform-1.1.0.tm +0 -442
  394. package/python/lib/tcl9/9.0/tcltest-2.5.11.tm +0 -3600
  395. package/python/lib/tcl9.0/auto.tcl +0 -710
  396. package/python/lib/tcl9.0/clock.tcl +0 -2110
  397. package/python/lib/tcl9.0/cookiejar0.2/cookiejar.tcl +0 -746
  398. package/python/lib/tcl9.0/cookiejar0.2/idna.tcl +0 -292
  399. package/python/lib/tcl9.0/cookiejar0.2/pkgIndex.tcl +0 -3
  400. package/python/lib/tcl9.0/cookiejar0.2/public_suffix_list.dat.gz +0 -0
  401. package/python/lib/tcl9.0/encoding/ascii.enc +0 -20
  402. package/python/lib/tcl9.0/encoding/big5.enc +0 -1516
  403. package/python/lib/tcl9.0/encoding/cns11643.enc +0 -1584
  404. package/python/lib/tcl9.0/encoding/cp1250.enc +0 -20
  405. package/python/lib/tcl9.0/encoding/cp1251.enc +0 -20
  406. package/python/lib/tcl9.0/encoding/cp1252.enc +0 -20
  407. package/python/lib/tcl9.0/encoding/cp1253.enc +0 -20
  408. package/python/lib/tcl9.0/encoding/cp1254.enc +0 -20
  409. package/python/lib/tcl9.0/encoding/cp1255.enc +0 -20
  410. package/python/lib/tcl9.0/encoding/cp1256.enc +0 -20
  411. package/python/lib/tcl9.0/encoding/cp1257.enc +0 -20
  412. package/python/lib/tcl9.0/encoding/cp1258.enc +0 -20
  413. package/python/lib/tcl9.0/encoding/cp165.enc +0 -20
  414. package/python/lib/tcl9.0/encoding/cp437.enc +0 -20
  415. package/python/lib/tcl9.0/encoding/cp737.enc +0 -20
  416. package/python/lib/tcl9.0/encoding/cp775.enc +0 -20
  417. package/python/lib/tcl9.0/encoding/cp850.enc +0 -20
  418. package/python/lib/tcl9.0/encoding/cp852.enc +0 -20
  419. package/python/lib/tcl9.0/encoding/cp855.enc +0 -20
  420. package/python/lib/tcl9.0/encoding/cp857.enc +0 -20
  421. package/python/lib/tcl9.0/encoding/cp860.enc +0 -20
  422. package/python/lib/tcl9.0/encoding/cp861.enc +0 -20
  423. package/python/lib/tcl9.0/encoding/cp862.enc +0 -20
  424. package/python/lib/tcl9.0/encoding/cp863.enc +0 -20
  425. package/python/lib/tcl9.0/encoding/cp864.enc +0 -20
  426. package/python/lib/tcl9.0/encoding/cp865.enc +0 -20
  427. package/python/lib/tcl9.0/encoding/cp866.enc +0 -20
  428. package/python/lib/tcl9.0/encoding/cp869.enc +0 -20
  429. package/python/lib/tcl9.0/encoding/cp874.enc +0 -20
  430. package/python/lib/tcl9.0/encoding/cp932.enc +0 -801
  431. package/python/lib/tcl9.0/encoding/cp936.enc +0 -2162
  432. package/python/lib/tcl9.0/encoding/cp949.enc +0 -2128
  433. package/python/lib/tcl9.0/encoding/cp950.enc +0 -1499
  434. package/python/lib/tcl9.0/encoding/dingbats.enc +0 -20
  435. package/python/lib/tcl9.0/encoding/ebcdic.enc +0 -20
  436. package/python/lib/tcl9.0/encoding/euc-cn.enc +0 -1397
  437. package/python/lib/tcl9.0/encoding/euc-jp.enc +0 -1353
  438. package/python/lib/tcl9.0/encoding/euc-kr.enc +0 -1533
  439. package/python/lib/tcl9.0/encoding/gb12345.enc +0 -1414
  440. package/python/lib/tcl9.0/encoding/gb1988.enc +0 -20
  441. package/python/lib/tcl9.0/encoding/gb2312-raw.enc +0 -1380
  442. package/python/lib/tcl9.0/encoding/gb2312.enc +0 -1397
  443. package/python/lib/tcl9.0/encoding/iso2022-jp.enc +0 -12
  444. package/python/lib/tcl9.0/encoding/iso2022-kr.enc +0 -7
  445. package/python/lib/tcl9.0/encoding/iso2022.enc +0 -14
  446. package/python/lib/tcl9.0/encoding/iso8859-1.enc +0 -20
  447. package/python/lib/tcl9.0/encoding/iso8859-10.enc +0 -20
  448. package/python/lib/tcl9.0/encoding/iso8859-11.enc +0 -20
  449. package/python/lib/tcl9.0/encoding/iso8859-13.enc +0 -20
  450. package/python/lib/tcl9.0/encoding/iso8859-14.enc +0 -20
  451. package/python/lib/tcl9.0/encoding/iso8859-15.enc +0 -20
  452. package/python/lib/tcl9.0/encoding/iso8859-16.enc +0 -20
  453. package/python/lib/tcl9.0/encoding/iso8859-2.enc +0 -20
  454. package/python/lib/tcl9.0/encoding/iso8859-3.enc +0 -20
  455. package/python/lib/tcl9.0/encoding/iso8859-4.enc +0 -20
  456. package/python/lib/tcl9.0/encoding/iso8859-5.enc +0 -20
  457. package/python/lib/tcl9.0/encoding/iso8859-6.enc +0 -20
  458. package/python/lib/tcl9.0/encoding/iso8859-7.enc +0 -20
  459. package/python/lib/tcl9.0/encoding/iso8859-8.enc +0 -20
  460. package/python/lib/tcl9.0/encoding/iso8859-9.enc +0 -20
  461. package/python/lib/tcl9.0/encoding/jis0201.enc +0 -20
  462. package/python/lib/tcl9.0/encoding/jis0208.enc +0 -1319
  463. package/python/lib/tcl9.0/encoding/jis0212.enc +0 -1159
  464. package/python/lib/tcl9.0/encoding/koi8-r.enc +0 -20
  465. package/python/lib/tcl9.0/encoding/koi8-ru.enc +0 -20
  466. package/python/lib/tcl9.0/encoding/koi8-t.enc +0 -20
  467. package/python/lib/tcl9.0/encoding/koi8-u.enc +0 -20
  468. package/python/lib/tcl9.0/encoding/ksc5601.enc +0 -1516
  469. package/python/lib/tcl9.0/encoding/macCentEuro.enc +0 -20
  470. package/python/lib/tcl9.0/encoding/macCroatian.enc +0 -20
  471. package/python/lib/tcl9.0/encoding/macCyrillic.enc +0 -20
  472. package/python/lib/tcl9.0/encoding/macDingbats.enc +0 -20
  473. package/python/lib/tcl9.0/encoding/macGreek.enc +0 -20
  474. package/python/lib/tcl9.0/encoding/macIceland.enc +0 -20
  475. package/python/lib/tcl9.0/encoding/macJapan.enc +0 -785
  476. package/python/lib/tcl9.0/encoding/macRoman.enc +0 -20
  477. package/python/lib/tcl9.0/encoding/macRomania.enc +0 -20
  478. package/python/lib/tcl9.0/encoding/macThai.enc +0 -20
  479. package/python/lib/tcl9.0/encoding/macTurkish.enc +0 -20
  480. package/python/lib/tcl9.0/encoding/macUkraine.enc +0 -20
  481. package/python/lib/tcl9.0/encoding/shiftjis.enc +0 -690
  482. package/python/lib/tcl9.0/encoding/symbol.enc +0 -20
  483. package/python/lib/tcl9.0/encoding/tis-620.enc +0 -20
  484. package/python/lib/tcl9.0/foreachline.tcl +0 -25
  485. package/python/lib/tcl9.0/history.tcl +0 -335
  486. package/python/lib/tcl9.0/icu.tcl +0 -145
  487. package/python/lib/tcl9.0/init.tcl +0 -772
  488. package/python/lib/tcl9.0/install.tcl +0 -274
  489. package/python/lib/tcl9.0/opt0.4/optparse.tcl +0 -1060
  490. package/python/lib/tcl9.0/opt0.4/pkgIndex.tcl +0 -12
  491. package/python/lib/tcl9.0/package.tcl +0 -776
  492. package/python/lib/tcl9.0/parray.tcl +0 -28
  493. package/python/lib/tcl9.0/readfile.tcl +0 -23
  494. package/python/lib/tcl9.0/safe.tcl +0 -1459
  495. package/python/lib/tcl9.0/tclAppInit.c +0 -183
  496. package/python/lib/tcl9.0/tclIndex +0 -112
  497. package/python/lib/tcl9.0/tm.tcl +0 -378
  498. package/python/lib/tcl9.0/word.tcl +0 -155
  499. package/python/lib/tcl9.0/writefile.tcl +0 -37
  500. package/python/lib/thread3.0.6/libtcl9thread3.0.6.dylib +0 -0
  501. package/python/lib/thread3.0.6/libthread3.0.6.dylib +0 -0
  502. package/python/lib/thread3.0.6/pkgIndex.tcl +0 -52
  503. package/python/lib/thread3.0.6/ttrace.tcl +0 -943
  504. package/python/lib/tk9.0/bgerror.tcl +0 -282
  505. package/python/lib/tk9.0/button.tcl +0 -782
  506. package/python/lib/tk9.0/choosedir.tcl +0 -310
  507. package/python/lib/tk9.0/clrpick.tcl +0 -696
  508. package/python/lib/tk9.0/comdlg.tcl +0 -322
  509. package/python/lib/tk9.0/console.tcl +0 -1148
  510. package/python/lib/tk9.0/dialog.tcl +0 -175
  511. package/python/lib/tk9.0/entry.tcl +0 -721
  512. package/python/lib/tk9.0/focus.tcl +0 -178
  513. package/python/lib/tk9.0/fontchooser.tcl +0 -512
  514. package/python/lib/tk9.0/iconbadges.tcl +0 -253
  515. package/python/lib/tk9.0/iconlist.tcl +0 -705
  516. package/python/lib/tk9.0/icons.tcl +0 -54
  517. package/python/lib/tk9.0/images/README +0 -7
  518. package/python/lib/tk9.0/images/logo.eps +0 -2091
  519. package/python/lib/tk9.0/images/logo100.gif +0 -0
  520. package/python/lib/tk9.0/images/logo64.gif +0 -0
  521. package/python/lib/tk9.0/images/logoLarge.gif +0 -0
  522. package/python/lib/tk9.0/images/logoMed.gif +0 -0
  523. package/python/lib/tk9.0/images/pwrdLogo.eps +0 -1897
  524. package/python/lib/tk9.0/images/pwrdLogo100.gif +0 -0
  525. package/python/lib/tk9.0/images/pwrdLogo150.gif +0 -0
  526. package/python/lib/tk9.0/images/pwrdLogo175.gif +0 -0
  527. package/python/lib/tk9.0/images/pwrdLogo200.gif +0 -0
  528. package/python/lib/tk9.0/images/pwrdLogo75.gif +0 -0
  529. package/python/lib/tk9.0/images/tai-ku.gif +0 -0
  530. package/python/lib/tk9.0/listbox.tcl +0 -522
  531. package/python/lib/tk9.0/megawidget.tcl +0 -297
  532. package/python/lib/tk9.0/menu.tcl +0 -1376
  533. package/python/lib/tk9.0/mkpsenc.tcl +0 -1488
  534. package/python/lib/tk9.0/msgbox.tcl +0 -454
  535. package/python/lib/tk9.0/optMenu.tcl +0 -43
  536. package/python/lib/tk9.0/palette.tcl +0 -283
  537. package/python/lib/tk9.0/panedwindow.tcl +0 -194
  538. package/python/lib/tk9.0/pkgIndex.tcl +0 -3
  539. package/python/lib/tk9.0/print.tcl +0 -1460
  540. package/python/lib/tk9.0/safetk.tcl +0 -262
  541. package/python/lib/tk9.0/scale.tcl +0 -299
  542. package/python/lib/tk9.0/scaling.tcl +0 -232
  543. package/python/lib/tk9.0/scrlbar.tcl +0 -506
  544. package/python/lib/tk9.0/spinbox.tcl +0 -590
  545. package/python/lib/tk9.0/systray.tcl +0 -483
  546. package/python/lib/tk9.0/tclIndex +0 -252
  547. package/python/lib/tk9.0/tearoff.tcl +0 -155
  548. package/python/lib/tk9.0/text.tcl +0 -1295
  549. package/python/lib/tk9.0/tk.tcl +0 -853
  550. package/python/lib/tk9.0/tkAppInit.c +0 -200
  551. package/python/lib/tk9.0/tkfbox.tcl +0 -1251
  552. package/python/lib/tk9.0/ttk/altTheme.tcl +0 -158
  553. package/python/lib/tk9.0/ttk/aquaTheme.tcl +0 -254
  554. package/python/lib/tk9.0/ttk/button.tcl +0 -83
  555. package/python/lib/tk9.0/ttk/clamTheme.tcl +0 -200
  556. package/python/lib/tk9.0/ttk/classicTheme.tcl +0 -165
  557. package/python/lib/tk9.0/ttk/combobox.tcl +0 -555
  558. package/python/lib/tk9.0/ttk/cursors.tcl +0 -205
  559. package/python/lib/tk9.0/ttk/defaults.tcl +0 -250
  560. package/python/lib/tk9.0/ttk/entry.tcl +0 -678
  561. package/python/lib/tk9.0/ttk/fonts.tcl +0 -152
  562. package/python/lib/tk9.0/ttk/menubutton.tcl +0 -237
  563. package/python/lib/tk9.0/ttk/notebook.tcl +0 -261
  564. package/python/lib/tk9.0/ttk/panedwindow.tcl +0 -89
  565. package/python/lib/tk9.0/ttk/progress.tcl +0 -55
  566. package/python/lib/tk9.0/ttk/scale.tcl +0 -94
  567. package/python/lib/tk9.0/ttk/scrollbar.tcl +0 -119
  568. package/python/lib/tk9.0/ttk/sizegrip.tcl +0 -102
  569. package/python/lib/tk9.0/ttk/spinbox.tcl +0 -204
  570. package/python/lib/tk9.0/ttk/treeview.tcl +0 -464
  571. package/python/lib/tk9.0/ttk/ttk.tcl +0 -220
  572. package/python/lib/tk9.0/ttk/utils.tcl +0 -317
  573. package/python/lib/tk9.0/ttk/vistaTheme.tcl +0 -260
  574. package/python/lib/tk9.0/ttk/winTheme.tcl +0 -123
  575. package/python/lib/tk9.0/ttk/xpTheme.tcl +0 -99
  576. package/python/lib/tk9.0/xmfbox.tcl +0 -982
  577. package/python/share/man/man1/python.1 +0 -630
  578. package/python/share/man/man1/python3.1 +0 -630
  579. package/python/share/man/man1/python3.12.1 +0 -630
  580. /package/modules/{simplex_localmodels-0.1.0.dev31.dist-info → simplex_localmodels-0.1.0.dev32.dist-info}/WHEEL +0 -0
  581. /package/modules/{simplex_localmodels-0.1.0.dev31.dist-info → simplex_localmodels-0.1.0.dev32.dist-info}/entry_points.txt +0 -0
  582. /package/modules/{simplex_localmodels-0.1.0.dev31.dist-info → simplex_localmodels-0.1.0.dev32.dist-info}/licenses/NOTICE +0 -0
  583. /package/modules/{simplex_localmodels-0.1.0.dev31.dist-info → simplex_localmodels-0.1.0.dev32.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -1,4682 +0,0 @@
1
- """Wrapper functions for Tcl/Tk.
2
-
3
- Tkinter provides classes which allow the display, positioning and
4
- control of widgets. Toplevel widgets are Tk and Toplevel. Other
5
- widgets are Frame, Label, Entry, Text, Canvas, Button, Radiobutton,
6
- Checkbutton, Scale, Listbox, Scrollbar, OptionMenu, Spinbox
7
- LabelFrame and PanedWindow.
8
-
9
- Properties of the widgets are specified with keyword arguments.
10
- Keyword arguments have the same name as the corresponding resource
11
- under Tk.
12
-
13
- Widgets are positioned with one of the geometry managers Place, Pack
14
- or Grid. These managers can be called with methods place, pack, grid
15
- available in every Widget.
16
-
17
- Actions are bound to events by resources (e.g. keyword argument
18
- command) or with the method bind.
19
-
20
- Example (Hello, World):
21
- import tkinter
22
- from tkinter.constants import *
23
- tk = tkinter.Tk()
24
- frame = tkinter.Frame(tk, relief=RIDGE, borderwidth=2)
25
- frame.pack(fill=BOTH,expand=1)
26
- label = tkinter.Label(frame, text="Hello, World")
27
- label.pack(fill=X, expand=1)
28
- button = tkinter.Button(frame,text="Exit",command=tk.destroy)
29
- button.pack(side=BOTTOM)
30
- tk.mainloop()
31
- """
32
-
33
- import collections
34
- import enum
35
- import sys
36
- import types
37
-
38
- import _tkinter # If this fails your Python may not be configured for Tk
39
- TclError = _tkinter.TclError
40
- from tkinter.constants import *
41
- import re
42
-
43
- wantobjects = 1
44
- _debug = False # set to True to print executed Tcl/Tk commands
45
-
46
- TkVersion = float(_tkinter.TK_VERSION)
47
- TclVersion = float(_tkinter.TCL_VERSION)
48
-
49
- READABLE = _tkinter.READABLE
50
- WRITABLE = _tkinter.WRITABLE
51
- EXCEPTION = _tkinter.EXCEPTION
52
-
53
-
54
- _magic_re = re.compile(r'([\\{}])')
55
- _space_re = re.compile(r'([\s])', re.ASCII)
56
-
57
-
58
- def _join(value):
59
- """Internal function."""
60
- return ' '.join(map(_stringify, value))
61
-
62
-
63
- def _stringify(value):
64
- """Internal function."""
65
- if isinstance(value, (list, tuple)):
66
- if len(value) == 1:
67
- value = _stringify(value[0])
68
- if _magic_re.search(value):
69
- value = '{%s}' % value
70
- else:
71
- value = '{%s}' % _join(value)
72
- else:
73
- if isinstance(value, bytes):
74
- value = str(value, 'latin1')
75
- else:
76
- value = str(value)
77
- if not value:
78
- value = '{}'
79
- elif _magic_re.search(value):
80
- # add '\' before special characters and spaces
81
- value = _magic_re.sub(r'\\\1', value)
82
- value = value.replace('\n', r'\n')
83
- value = _space_re.sub(r'\\\1', value)
84
- if value[0] == '"':
85
- value = '\\' + value
86
- elif value[0] == '"' or _space_re.search(value):
87
- value = '{%s}' % value
88
- return value
89
-
90
-
91
- def _flatten(seq):
92
- """Internal function."""
93
- res = ()
94
- for item in seq:
95
- if isinstance(item, (tuple, list)):
96
- res = res + _flatten(item)
97
- elif item is not None:
98
- res = res + (item,)
99
- return res
100
-
101
-
102
- try: _flatten = _tkinter._flatten
103
- except AttributeError: pass
104
-
105
-
106
- def _cnfmerge(cnfs):
107
- """Internal function."""
108
- if isinstance(cnfs, dict):
109
- return cnfs
110
- elif isinstance(cnfs, (type(None), str)):
111
- return cnfs
112
- else:
113
- cnf = {}
114
- for c in _flatten(cnfs):
115
- try:
116
- cnf.update(c)
117
- except (AttributeError, TypeError) as msg:
118
- print("_cnfmerge: fallback due to:", msg)
119
- for k, v in c.items():
120
- cnf[k] = v
121
- return cnf
122
-
123
-
124
- try: _cnfmerge = _tkinter._cnfmerge
125
- except AttributeError: pass
126
-
127
-
128
- def _splitdict(tk, v, cut_minus=True, conv=None):
129
- """Return a properly formatted dict built from Tcl list pairs.
130
-
131
- If cut_minus is True, the supposed '-' prefix will be removed from
132
- keys. If conv is specified, it is used to convert values.
133
-
134
- Tcl list is expected to contain an even number of elements.
135
- """
136
- t = tk.splitlist(v)
137
- if len(t) % 2:
138
- raise RuntimeError('Tcl list representing a dict is expected '
139
- 'to contain an even number of elements')
140
- it = iter(t)
141
- dict = {}
142
- for key, value in zip(it, it):
143
- key = str(key)
144
- if cut_minus and key[0] == '-':
145
- key = key[1:]
146
- if conv:
147
- value = conv(value)
148
- dict[key] = value
149
- return dict
150
-
151
- class _VersionInfoType(collections.namedtuple('_VersionInfoType',
152
- ('major', 'minor', 'micro', 'releaselevel', 'serial'))):
153
- def __str__(self):
154
- if self.releaselevel == 'final':
155
- return f'{self.major}.{self.minor}.{self.micro}'
156
- else:
157
- return f'{self.major}.{self.minor}{self.releaselevel[0]}{self.serial}'
158
-
159
- def _parse_version(version):
160
- import re
161
- m = re.fullmatch(r'(\d+)\.(\d+)([ab.])(\d+)', version)
162
- major, minor, releaselevel, serial = m.groups()
163
- major, minor, serial = int(major), int(minor), int(serial)
164
- if releaselevel == '.':
165
- micro = serial
166
- serial = 0
167
- releaselevel = 'final'
168
- else:
169
- micro = 0
170
- releaselevel = {'a': 'alpha', 'b': 'beta'}[releaselevel]
171
- return _VersionInfoType(major, minor, micro, releaselevel, serial)
172
-
173
-
174
- @enum._simple_enum(enum.StrEnum)
175
- class EventType:
176
- KeyPress = '2'
177
- Key = KeyPress
178
- KeyRelease = '3'
179
- ButtonPress = '4'
180
- Button = ButtonPress
181
- ButtonRelease = '5'
182
- Motion = '6'
183
- Enter = '7'
184
- Leave = '8'
185
- FocusIn = '9'
186
- FocusOut = '10'
187
- Keymap = '11' # undocumented
188
- Expose = '12'
189
- GraphicsExpose = '13' # undocumented
190
- NoExpose = '14' # undocumented
191
- Visibility = '15'
192
- Create = '16'
193
- Destroy = '17'
194
- Unmap = '18'
195
- Map = '19'
196
- MapRequest = '20'
197
- Reparent = '21'
198
- Configure = '22'
199
- ConfigureRequest = '23'
200
- Gravity = '24'
201
- ResizeRequest = '25'
202
- Circulate = '26'
203
- CirculateRequest = '27'
204
- Property = '28'
205
- SelectionClear = '29' # undocumented
206
- SelectionRequest = '30' # undocumented
207
- Selection = '31' # undocumented
208
- Colormap = '32'
209
- ClientMessage = '33' # undocumented
210
- Mapping = '34' # undocumented
211
- VirtualEvent = '35' # undocumented
212
- Activate = '36'
213
- Deactivate = '37'
214
- MouseWheel = '38'
215
-
216
-
217
- class Event:
218
- """Container for the properties of an event.
219
-
220
- Instances of this type are generated if one of the following events occurs:
221
-
222
- KeyPress, KeyRelease - for keyboard events
223
- ButtonPress, ButtonRelease, Motion, Enter, Leave, MouseWheel - for mouse events
224
- Visibility, Unmap, Map, Expose, FocusIn, FocusOut, Circulate,
225
- Colormap, Gravity, Reparent, Property, Destroy, Activate,
226
- Deactivate - for window events.
227
-
228
- If a callback function for one of these events is registered
229
- using bind, bind_all, bind_class, or tag_bind, the callback is
230
- called with an Event as first argument. It will have the
231
- following attributes (in braces are the event types for which
232
- the attribute is valid):
233
-
234
- serial - serial number of event
235
- num - mouse button pressed (ButtonPress, ButtonRelease)
236
- focus - whether the window has the focus (Enter, Leave)
237
- height - height of the exposed window (Configure, Expose)
238
- width - width of the exposed window (Configure, Expose)
239
- keycode - keycode of the pressed key (KeyPress, KeyRelease)
240
- state - state of the event as a number (ButtonPress, ButtonRelease,
241
- Enter, KeyPress, KeyRelease,
242
- Leave, Motion)
243
- state - state as a string (Visibility)
244
- time - when the event occurred
245
- x - x-position of the mouse
246
- y - y-position of the mouse
247
- x_root - x-position of the mouse on the screen
248
- (ButtonPress, ButtonRelease, KeyPress, KeyRelease, Motion)
249
- y_root - y-position of the mouse on the screen
250
- (ButtonPress, ButtonRelease, KeyPress, KeyRelease, Motion)
251
- char - pressed character (KeyPress, KeyRelease)
252
- send_event - see X/Windows documentation
253
- keysym - keysym of the event as a string (KeyPress, KeyRelease)
254
- keysym_num - keysym of the event as a number (KeyPress, KeyRelease)
255
- type - type of the event as a number
256
- widget - widget in which the event occurred
257
- delta - delta of wheel movement (MouseWheel)
258
- """
259
-
260
- def __repr__(self):
261
- attrs = {k: v for k, v in self.__dict__.items() if v != '??'}
262
- if not self.char:
263
- del attrs['char']
264
- elif self.char != '??':
265
- attrs['char'] = repr(self.char)
266
- if not getattr(self, 'send_event', True):
267
- del attrs['send_event']
268
- if self.state == 0:
269
- del attrs['state']
270
- elif isinstance(self.state, int):
271
- state = self.state
272
- mods = ('Shift', 'Lock', 'Control',
273
- 'Mod1', 'Mod2', 'Mod3', 'Mod4', 'Mod5',
274
- 'Button1', 'Button2', 'Button3', 'Button4', 'Button5')
275
- s = []
276
- for i, n in enumerate(mods):
277
- if state & (1 << i):
278
- s.append(n)
279
- state = state & ~((1<< len(mods)) - 1)
280
- if state or not s:
281
- s.append(hex(state))
282
- attrs['state'] = '|'.join(s)
283
- if self.delta == 0:
284
- del attrs['delta']
285
- # widget usually is known
286
- # serial and time are not very interesting
287
- # keysym_num duplicates keysym
288
- # x_root and y_root mostly duplicate x and y
289
- keys = ('send_event',
290
- 'state', 'keysym', 'keycode', 'char',
291
- 'num', 'delta', 'focus',
292
- 'x', 'y', 'width', 'height')
293
- return '<%s event%s>' % (
294
- getattr(self.type, 'name', self.type),
295
- ''.join(' %s=%s' % (k, attrs[k]) for k in keys if k in attrs)
296
- )
297
-
298
-
299
- _support_default_root = True
300
- _default_root = None
301
-
302
-
303
- def NoDefaultRoot():
304
- """Inhibit setting of default root window.
305
-
306
- Call this function to inhibit that the first instance of
307
- Tk is used for windows without an explicit parent window.
308
- """
309
- global _support_default_root, _default_root
310
- _support_default_root = False
311
- # Delete, so any use of _default_root will immediately raise an exception.
312
- # Rebind before deletion, so repeated calls will not fail.
313
- _default_root = None
314
- del _default_root
315
-
316
-
317
- def _get_default_root(what=None):
318
- if not _support_default_root:
319
- raise RuntimeError("No master specified and tkinter is "
320
- "configured to not support default root")
321
- if _default_root is None:
322
- if what:
323
- raise RuntimeError(f"Too early to {what}: no default root window")
324
- root = Tk()
325
- assert _default_root is root
326
- return _default_root
327
-
328
-
329
- def _get_temp_root():
330
- global _support_default_root
331
- if not _support_default_root:
332
- raise RuntimeError("No master specified and tkinter is "
333
- "configured to not support default root")
334
- root = _default_root
335
- if root is None:
336
- assert _support_default_root
337
- _support_default_root = False
338
- root = Tk()
339
- _support_default_root = True
340
- assert _default_root is None
341
- root.withdraw()
342
- root._temporary = True
343
- return root
344
-
345
-
346
- def _destroy_temp_root(master):
347
- if getattr(master, '_temporary', False):
348
- try:
349
- master.destroy()
350
- except TclError:
351
- pass
352
-
353
-
354
- def _tkerror(err):
355
- """Internal function."""
356
- pass
357
-
358
-
359
- def _exit(code=0):
360
- """Internal function. Calling it will raise the exception SystemExit."""
361
- try:
362
- code = int(code)
363
- except ValueError:
364
- pass
365
- raise SystemExit(code)
366
-
367
-
368
- _varnum = 0
369
-
370
-
371
- class Variable:
372
- """Class to define value holders for e.g. buttons.
373
-
374
- Subclasses StringVar, IntVar, DoubleVar, BooleanVar are specializations
375
- that constrain the type of the value returned from get()."""
376
- _default = ""
377
- _tk = None
378
- _tclCommands = None
379
-
380
- def __init__(self, master=None, value=None, name=None):
381
- """Construct a variable
382
-
383
- MASTER can be given as master widget.
384
- VALUE is an optional value (defaults to "")
385
- NAME is an optional Tcl name (defaults to PY_VARnum).
386
-
387
- If NAME matches an existing variable and VALUE is omitted
388
- then the existing value is retained.
389
- """
390
- # check for type of NAME parameter to override weird error message
391
- # raised from Modules/_tkinter.c:SetVar like:
392
- # TypeError: setvar() takes exactly 3 arguments (2 given)
393
- if name is not None and not isinstance(name, str):
394
- raise TypeError("name must be a string")
395
- global _varnum
396
- if master is None:
397
- master = _get_default_root('create variable')
398
- self._root = master._root()
399
- self._tk = master.tk
400
- if name:
401
- self._name = name
402
- else:
403
- self._name = 'PY_VAR' + repr(_varnum)
404
- _varnum += 1
405
- if value is not None:
406
- self.initialize(value)
407
- elif not self._tk.getboolean(self._tk.call("info", "exists", self._name)):
408
- self.initialize(self._default)
409
-
410
- def __del__(self):
411
- """Unset the variable in Tcl."""
412
- if self._tk is None:
413
- return
414
- if self._tk.getboolean(self._tk.call("info", "exists", self._name)):
415
- self._tk.globalunsetvar(self._name)
416
- if self._tclCommands is not None:
417
- for name in self._tclCommands:
418
- self._tk.deletecommand(name)
419
- self._tclCommands = None
420
-
421
- def __str__(self):
422
- """Return the name of the variable in Tcl."""
423
- return self._name
424
-
425
- def set(self, value):
426
- """Set the variable to VALUE."""
427
- return self._tk.globalsetvar(self._name, value)
428
-
429
- initialize = set
430
-
431
- def get(self):
432
- """Return value of variable."""
433
- return self._tk.globalgetvar(self._name)
434
-
435
- def _register(self, callback):
436
- f = CallWrapper(callback, None, self._root).__call__
437
- cbname = repr(id(f))
438
- try:
439
- callback = callback.__func__
440
- except AttributeError:
441
- pass
442
- try:
443
- cbname = cbname + callback.__name__
444
- except AttributeError:
445
- pass
446
- self._tk.createcommand(cbname, f)
447
- if self._tclCommands is None:
448
- self._tclCommands = []
449
- self._tclCommands.append(cbname)
450
- return cbname
451
-
452
- def trace_add(self, mode, callback):
453
- """Define a trace callback for the variable.
454
-
455
- Mode is one of "read", "write", "unset", or a list or tuple of
456
- such strings.
457
- Callback must be a function which is called when the variable is
458
- read, written or unset.
459
-
460
- Return the name of the callback.
461
- """
462
- cbname = self._register(callback)
463
- self._tk.call('trace', 'add', 'variable',
464
- self._name, mode, (cbname,))
465
- return cbname
466
-
467
- def trace_remove(self, mode, cbname):
468
- """Delete the trace callback for a variable.
469
-
470
- Mode is one of "read", "write", "unset" or a list or tuple of
471
- such strings. Must be same as were specified in trace_add().
472
- cbname is the name of the callback returned from trace_add().
473
- """
474
- self._tk.call('trace', 'remove', 'variable',
475
- self._name, mode, cbname)
476
- for m, ca in self.trace_info():
477
- if self._tk.splitlist(ca)[0] == cbname:
478
- break
479
- else:
480
- self._tk.deletecommand(cbname)
481
- try:
482
- self._tclCommands.remove(cbname)
483
- except ValueError:
484
- pass
485
-
486
- def trace_info(self):
487
- """Return all trace callback information."""
488
- splitlist = self._tk.splitlist
489
- return [(splitlist(k), v) for k, v in map(splitlist,
490
- splitlist(self._tk.call('trace', 'info', 'variable', self._name)))]
491
-
492
- def trace_variable(self, mode, callback):
493
- """Define a trace callback for the variable.
494
-
495
- MODE is one of "r", "w", "u" for read, write, undefine.
496
- CALLBACK must be a function which is called when
497
- the variable is read, written or undefined.
498
-
499
- Return the name of the callback.
500
-
501
- This deprecated method wraps a deprecated Tcl method that will
502
- likely be removed in the future. Use trace_add() instead.
503
- """
504
- # TODO: Add deprecation warning
505
- cbname = self._register(callback)
506
- self._tk.call("trace", "variable", self._name, mode, cbname)
507
- return cbname
508
-
509
- trace = trace_variable
510
-
511
- def trace_vdelete(self, mode, cbname):
512
- """Delete the trace callback for a variable.
513
-
514
- MODE is one of "r", "w", "u" for read, write, undefine.
515
- CBNAME is the name of the callback returned from trace_variable or trace.
516
-
517
- This deprecated method wraps a deprecated Tcl method that will
518
- likely be removed in the future. Use trace_remove() instead.
519
- """
520
- # TODO: Add deprecation warning
521
- self._tk.call("trace", "vdelete", self._name, mode, cbname)
522
- cbname = self._tk.splitlist(cbname)[0]
523
- for m, ca in self.trace_info():
524
- if self._tk.splitlist(ca)[0] == cbname:
525
- break
526
- else:
527
- self._tk.deletecommand(cbname)
528
- try:
529
- self._tclCommands.remove(cbname)
530
- except ValueError:
531
- pass
532
-
533
- def trace_vinfo(self):
534
- """Return all trace callback information.
535
-
536
- This deprecated method wraps a deprecated Tcl method that will
537
- likely be removed in the future. Use trace_info() instead.
538
- """
539
- # TODO: Add deprecation warning
540
- return [self._tk.splitlist(x) for x in self._tk.splitlist(
541
- self._tk.call("trace", "vinfo", self._name))]
542
-
543
- def __eq__(self, other):
544
- if not isinstance(other, Variable):
545
- return NotImplemented
546
- return (self._name == other._name
547
- and self.__class__.__name__ == other.__class__.__name__
548
- and self._tk == other._tk)
549
-
550
-
551
- class StringVar(Variable):
552
- """Value holder for strings variables."""
553
- _default = ""
554
-
555
- def __init__(self, master=None, value=None, name=None):
556
- """Construct a string variable.
557
-
558
- MASTER can be given as master widget.
559
- VALUE is an optional value (defaults to "")
560
- NAME is an optional Tcl name (defaults to PY_VARnum).
561
-
562
- If NAME matches an existing variable and VALUE is omitted
563
- then the existing value is retained.
564
- """
565
- Variable.__init__(self, master, value, name)
566
-
567
- def get(self):
568
- """Return value of variable as string."""
569
- value = self._tk.globalgetvar(self._name)
570
- if isinstance(value, str):
571
- return value
572
- return str(value)
573
-
574
-
575
- class IntVar(Variable):
576
- """Value holder for integer variables."""
577
- _default = 0
578
-
579
- def __init__(self, master=None, value=None, name=None):
580
- """Construct an integer variable.
581
-
582
- MASTER can be given as master widget.
583
- VALUE is an optional value (defaults to 0)
584
- NAME is an optional Tcl name (defaults to PY_VARnum).
585
-
586
- If NAME matches an existing variable and VALUE is omitted
587
- then the existing value is retained.
588
- """
589
- Variable.__init__(self, master, value, name)
590
-
591
- def get(self):
592
- """Return the value of the variable as an integer."""
593
- value = self._tk.globalgetvar(self._name)
594
- try:
595
- return self._tk.getint(value)
596
- except (TypeError, TclError):
597
- return int(self._tk.getdouble(value))
598
-
599
-
600
- class DoubleVar(Variable):
601
- """Value holder for float variables."""
602
- _default = 0.0
603
-
604
- def __init__(self, master=None, value=None, name=None):
605
- """Construct a float variable.
606
-
607
- MASTER can be given as master widget.
608
- VALUE is an optional value (defaults to 0.0)
609
- NAME is an optional Tcl name (defaults to PY_VARnum).
610
-
611
- If NAME matches an existing variable and VALUE is omitted
612
- then the existing value is retained.
613
- """
614
- Variable.__init__(self, master, value, name)
615
-
616
- def get(self):
617
- """Return the value of the variable as a float."""
618
- return self._tk.getdouble(self._tk.globalgetvar(self._name))
619
-
620
-
621
- class BooleanVar(Variable):
622
- """Value holder for boolean variables."""
623
- _default = False
624
-
625
- def __init__(self, master=None, value=None, name=None):
626
- """Construct a boolean variable.
627
-
628
- MASTER can be given as master widget.
629
- VALUE is an optional value (defaults to False)
630
- NAME is an optional Tcl name (defaults to PY_VARnum).
631
-
632
- If NAME matches an existing variable and VALUE is omitted
633
- then the existing value is retained.
634
- """
635
- Variable.__init__(self, master, value, name)
636
-
637
- def set(self, value):
638
- """Set the variable to VALUE."""
639
- return self._tk.globalsetvar(self._name, self._tk.getboolean(value))
640
-
641
- initialize = set
642
-
643
- def get(self):
644
- """Return the value of the variable as a bool."""
645
- try:
646
- return self._tk.getboolean(self._tk.globalgetvar(self._name))
647
- except TclError:
648
- raise ValueError("invalid literal for getboolean()")
649
-
650
-
651
- def mainloop(n=0):
652
- """Run the main loop of Tcl."""
653
- _get_default_root('run the main loop').tk.mainloop(n)
654
-
655
-
656
- getint = int
657
-
658
- getdouble = float
659
-
660
-
661
- def getboolean(s):
662
- """Convert Tcl object to True or False."""
663
- try:
664
- return _get_default_root('use getboolean()').tk.getboolean(s)
665
- except TclError:
666
- raise ValueError("invalid literal for getboolean()")
667
-
668
-
669
- # Methods defined on both toplevel and interior widgets
670
-
671
- class Misc:
672
- """Internal class.
673
-
674
- Base class which defines methods common for interior widgets."""
675
-
676
- # used for generating child widget names
677
- _last_child_ids = None
678
-
679
- # XXX font command?
680
- _tclCommands = None
681
-
682
- def destroy(self):
683
- """Internal function.
684
-
685
- Delete all Tcl commands created for
686
- this widget in the Tcl interpreter."""
687
- if self._tclCommands is not None:
688
- for name in self._tclCommands:
689
- self.tk.deletecommand(name)
690
- self._tclCommands = None
691
-
692
- def deletecommand(self, name):
693
- """Internal function.
694
-
695
- Delete the Tcl command provided in NAME."""
696
- self.tk.deletecommand(name)
697
- try:
698
- self._tclCommands.remove(name)
699
- except ValueError:
700
- pass
701
-
702
- def tk_strictMotif(self, boolean=None):
703
- """Set Tcl internal variable, whether the look and feel
704
- should adhere to Motif.
705
-
706
- A parameter of 1 means adhere to Motif (e.g. no color
707
- change if mouse passes over slider).
708
- Returns the set value."""
709
- return self.tk.getboolean(self.tk.call(
710
- 'set', 'tk_strictMotif', boolean))
711
-
712
- def tk_bisque(self):
713
- """Change the color scheme to light brown as used in Tk 3.6 and before."""
714
- self.tk.call('tk_bisque')
715
-
716
- def tk_setPalette(self, *args, **kw):
717
- """Set a new color scheme for all widget elements.
718
-
719
- A single color as argument will cause that all colors of Tk
720
- widget elements are derived from this.
721
- Alternatively several keyword parameters and its associated
722
- colors can be given. The following keywords are valid:
723
- activeBackground, foreground, selectColor,
724
- activeForeground, highlightBackground, selectBackground,
725
- background, highlightColor, selectForeground,
726
- disabledForeground, insertBackground, troughColor."""
727
- self.tk.call(('tk_setPalette',)
728
- + _flatten(args) + _flatten(list(kw.items())))
729
-
730
- def wait_variable(self, name='PY_VAR'):
731
- """Wait until the variable is modified.
732
-
733
- A parameter of type IntVar, StringVar, DoubleVar or
734
- BooleanVar must be given."""
735
- self.tk.call('tkwait', 'variable', name)
736
- waitvar = wait_variable # XXX b/w compat
737
-
738
- def wait_window(self, window=None):
739
- """Wait until a WIDGET is destroyed.
740
-
741
- If no parameter is given self is used."""
742
- if window is None:
743
- window = self
744
- self.tk.call('tkwait', 'window', window._w)
745
-
746
- def wait_visibility(self, window=None):
747
- """Wait until the visibility of a WIDGET changes
748
- (e.g. it appears).
749
-
750
- If no parameter is given self is used."""
751
- if window is None:
752
- window = self
753
- self.tk.call('tkwait', 'visibility', window._w)
754
-
755
- def setvar(self, name='PY_VAR', value='1'):
756
- """Set Tcl variable NAME to VALUE."""
757
- self.tk.setvar(name, value)
758
-
759
- def getvar(self, name='PY_VAR'):
760
- """Return value of Tcl variable NAME."""
761
- return self.tk.getvar(name)
762
-
763
- def getint(self, s):
764
- try:
765
- return self.tk.getint(s)
766
- except TclError as exc:
767
- raise ValueError(str(exc))
768
-
769
- def getdouble(self, s):
770
- try:
771
- return self.tk.getdouble(s)
772
- except TclError as exc:
773
- raise ValueError(str(exc))
774
-
775
- def getboolean(self, s):
776
- """Return a boolean value for Tcl boolean values true and false given as parameter."""
777
- try:
778
- return self.tk.getboolean(s)
779
- except TclError:
780
- raise ValueError("invalid literal for getboolean()")
781
-
782
- def focus_set(self):
783
- """Direct input focus to this widget.
784
-
785
- If the application currently does not have the focus
786
- this widget will get the focus if the application gets
787
- the focus through the window manager."""
788
- self.tk.call('focus', self._w)
789
- focus = focus_set # XXX b/w compat?
790
-
791
- def focus_force(self):
792
- """Direct input focus to this widget even if the
793
- application does not have the focus. Use with
794
- caution!"""
795
- self.tk.call('focus', '-force', self._w)
796
-
797
- def focus_get(self):
798
- """Return the widget which has currently the focus in the
799
- application.
800
-
801
- Use focus_displayof to allow working with several
802
- displays. Return None if application does not have
803
- the focus."""
804
- name = self.tk.call('focus')
805
- if name == 'none' or not name: return None
806
- return self._nametowidget(name)
807
-
808
- def focus_displayof(self):
809
- """Return the widget which has currently the focus on the
810
- display where this widget is located.
811
-
812
- Return None if the application does not have the focus."""
813
- name = self.tk.call('focus', '-displayof', self._w)
814
- if name == 'none' or not name: return None
815
- return self._nametowidget(name)
816
-
817
- def focus_lastfor(self):
818
- """Return the widget which would have the focus if top level
819
- for this widget gets the focus from the window manager."""
820
- name = self.tk.call('focus', '-lastfor', self._w)
821
- if name == 'none' or not name: return None
822
- return self._nametowidget(name)
823
-
824
- def tk_focusFollowsMouse(self):
825
- """The widget under mouse will get automatically focus. Can not
826
- be disabled easily."""
827
- self.tk.call('tk_focusFollowsMouse')
828
-
829
- def tk_focusNext(self):
830
- """Return the next widget in the focus order which follows
831
- widget which has currently the focus.
832
-
833
- The focus order first goes to the next child, then to
834
- the children of the child recursively and then to the
835
- next sibling which is higher in the stacking order. A
836
- widget is omitted if it has the takefocus resource set
837
- to 0."""
838
- name = self.tk.call('tk_focusNext', self._w)
839
- if not name: return None
840
- return self._nametowidget(name)
841
-
842
- def tk_focusPrev(self):
843
- """Return previous widget in the focus order. See tk_focusNext for details."""
844
- name = self.tk.call('tk_focusPrev', self._w)
845
- if not name: return None
846
- return self._nametowidget(name)
847
-
848
- def after(self, ms, func=None, *args):
849
- """Call function once after given time.
850
-
851
- MS specifies the time in milliseconds. FUNC gives the
852
- function which shall be called. Additional parameters
853
- are given as parameters to the function call. Return
854
- identifier to cancel scheduling with after_cancel."""
855
- if func is None:
856
- # I'd rather use time.sleep(ms*0.001)
857
- self.tk.call('after', ms)
858
- return None
859
- else:
860
- def callit():
861
- try:
862
- func(*args)
863
- finally:
864
- try:
865
- self.deletecommand(name)
866
- except TclError:
867
- pass
868
- try:
869
- callit.__name__ = func.__name__
870
- except AttributeError:
871
- # Required for callable classes (bpo-44404)
872
- callit.__name__ = type(func).__name__
873
- name = self._register(callit)
874
- return self.tk.call('after', ms, name)
875
-
876
- def after_idle(self, func, *args):
877
- """Call FUNC once if the Tcl main loop has no event to
878
- process.
879
-
880
- Return an identifier to cancel the scheduling with
881
- after_cancel."""
882
- return self.after('idle', func, *args)
883
-
884
- def after_cancel(self, id):
885
- """Cancel scheduling of function identified with ID.
886
-
887
- Identifier returned by after or after_idle must be
888
- given as first parameter.
889
- """
890
- if not id:
891
- raise ValueError('id must be a valid identifier returned from '
892
- 'after or after_idle')
893
- try:
894
- data = self.tk.call('after', 'info', id)
895
- script = self.tk.splitlist(data)[0]
896
- self.deletecommand(script)
897
- except TclError:
898
- pass
899
- self.tk.call('after', 'cancel', id)
900
-
901
- def bell(self, displayof=0):
902
- """Ring a display's bell."""
903
- self.tk.call(('bell',) + self._displayof(displayof))
904
-
905
- # Clipboard handling:
906
- def clipboard_get(self, **kw):
907
- """Retrieve data from the clipboard on window's display.
908
-
909
- The window keyword defaults to the root window of the Tkinter
910
- application.
911
-
912
- The type keyword specifies the form in which the data is
913
- to be returned and should be an atom name such as STRING
914
- or FILE_NAME. Type defaults to STRING, except on X11, where the default
915
- is to try UTF8_STRING and fall back to STRING.
916
-
917
- This command is equivalent to:
918
-
919
- selection_get(CLIPBOARD)
920
- """
921
- if 'type' not in kw and self._windowingsystem == 'x11':
922
- try:
923
- kw['type'] = 'UTF8_STRING'
924
- return self.tk.call(('clipboard', 'get') + self._options(kw))
925
- except TclError:
926
- del kw['type']
927
- return self.tk.call(('clipboard', 'get') + self._options(kw))
928
-
929
- def clipboard_clear(self, **kw):
930
- """Clear the data in the Tk clipboard.
931
-
932
- A widget specified for the optional displayof keyword
933
- argument specifies the target display."""
934
- if 'displayof' not in kw: kw['displayof'] = self._w
935
- self.tk.call(('clipboard', 'clear') + self._options(kw))
936
-
937
- def clipboard_append(self, string, **kw):
938
- """Append STRING to the Tk clipboard.
939
-
940
- A widget specified at the optional displayof keyword
941
- argument specifies the target display. The clipboard
942
- can be retrieved with selection_get."""
943
- if 'displayof' not in kw: kw['displayof'] = self._w
944
- self.tk.call(('clipboard', 'append') + self._options(kw)
945
- + ('--', string))
946
- # XXX grab current w/o window argument
947
-
948
- def grab_current(self):
949
- """Return widget which has currently the grab in this application
950
- or None."""
951
- name = self.tk.call('grab', 'current', self._w)
952
- if not name: return None
953
- return self._nametowidget(name)
954
-
955
- def grab_release(self):
956
- """Release grab for this widget if currently set."""
957
- self.tk.call('grab', 'release', self._w)
958
-
959
- def grab_set(self):
960
- """Set grab for this widget.
961
-
962
- A grab directs all events to this and descendant
963
- widgets in the application."""
964
- self.tk.call('grab', 'set', self._w)
965
-
966
- def grab_set_global(self):
967
- """Set global grab for this widget.
968
-
969
- A global grab directs all events to this and
970
- descendant widgets on the display. Use with caution -
971
- other applications do not get events anymore."""
972
- self.tk.call('grab', 'set', '-global', self._w)
973
-
974
- def grab_status(self):
975
- """Return None, "local" or "global" if this widget has
976
- no, a local or a global grab."""
977
- status = self.tk.call('grab', 'status', self._w)
978
- if status == 'none': status = None
979
- return status
980
-
981
- def option_add(self, pattern, value, priority = None):
982
- """Set a VALUE (second parameter) for an option
983
- PATTERN (first parameter).
984
-
985
- An optional third parameter gives the numeric priority
986
- (defaults to 80)."""
987
- self.tk.call('option', 'add', pattern, value, priority)
988
-
989
- def option_clear(self):
990
- """Clear the option database.
991
-
992
- It will be reloaded if option_add is called."""
993
- self.tk.call('option', 'clear')
994
-
995
- def option_get(self, name, className):
996
- """Return the value for an option NAME for this widget
997
- with CLASSNAME.
998
-
999
- Values with higher priority override lower values."""
1000
- return self.tk.call('option', 'get', self._w, name, className)
1001
-
1002
- def option_readfile(self, fileName, priority = None):
1003
- """Read file FILENAME into the option database.
1004
-
1005
- An optional second parameter gives the numeric
1006
- priority."""
1007
- self.tk.call('option', 'readfile', fileName, priority)
1008
-
1009
- def selection_clear(self, **kw):
1010
- """Clear the current X selection."""
1011
- if 'displayof' not in kw: kw['displayof'] = self._w
1012
- self.tk.call(('selection', 'clear') + self._options(kw))
1013
-
1014
- def selection_get(self, **kw):
1015
- """Return the contents of the current X selection.
1016
-
1017
- A keyword parameter selection specifies the name of
1018
- the selection and defaults to PRIMARY. A keyword
1019
- parameter displayof specifies a widget on the display
1020
- to use. A keyword parameter type specifies the form of data to be
1021
- fetched, defaulting to STRING except on X11, where UTF8_STRING is tried
1022
- before STRING."""
1023
- if 'displayof' not in kw: kw['displayof'] = self._w
1024
- if 'type' not in kw and self._windowingsystem == 'x11':
1025
- try:
1026
- kw['type'] = 'UTF8_STRING'
1027
- return self.tk.call(('selection', 'get') + self._options(kw))
1028
- except TclError:
1029
- del kw['type']
1030
- return self.tk.call(('selection', 'get') + self._options(kw))
1031
-
1032
- def selection_handle(self, command, **kw):
1033
- """Specify a function COMMAND to call if the X
1034
- selection owned by this widget is queried by another
1035
- application.
1036
-
1037
- This function must return the contents of the
1038
- selection. The function will be called with the
1039
- arguments OFFSET and LENGTH which allows the chunking
1040
- of very long selections. The following keyword
1041
- parameters can be provided:
1042
- selection - name of the selection (default PRIMARY),
1043
- type - type of the selection (e.g. STRING, FILE_NAME)."""
1044
- name = self._register(command)
1045
- self.tk.call(('selection', 'handle') + self._options(kw)
1046
- + (self._w, name))
1047
-
1048
- def selection_own(self, **kw):
1049
- """Become owner of X selection.
1050
-
1051
- A keyword parameter selection specifies the name of
1052
- the selection (default PRIMARY)."""
1053
- self.tk.call(('selection', 'own') +
1054
- self._options(kw) + (self._w,))
1055
-
1056
- def selection_own_get(self, **kw):
1057
- """Return owner of X selection.
1058
-
1059
- The following keyword parameter can
1060
- be provided:
1061
- selection - name of the selection (default PRIMARY),
1062
- type - type of the selection (e.g. STRING, FILE_NAME)."""
1063
- if 'displayof' not in kw: kw['displayof'] = self._w
1064
- name = self.tk.call(('selection', 'own') + self._options(kw))
1065
- if not name: return None
1066
- return self._nametowidget(name)
1067
-
1068
- def send(self, interp, cmd, *args):
1069
- """Send Tcl command CMD to different interpreter INTERP to be executed."""
1070
- return self.tk.call(('send', interp, cmd) + args)
1071
-
1072
- def lower(self, belowThis=None):
1073
- """Lower this widget in the stacking order."""
1074
- self.tk.call('lower', self._w, belowThis)
1075
-
1076
- def tkraise(self, aboveThis=None):
1077
- """Raise this widget in the stacking order."""
1078
- self.tk.call('raise', self._w, aboveThis)
1079
-
1080
- lift = tkraise
1081
-
1082
- def info_patchlevel(self):
1083
- """Returns the exact version of the Tcl library."""
1084
- patchlevel = self.tk.call('info', 'patchlevel')
1085
- return _parse_version(patchlevel)
1086
-
1087
- def winfo_atom(self, name, displayof=0):
1088
- """Return integer which represents atom NAME."""
1089
- args = ('winfo', 'atom') + self._displayof(displayof) + (name,)
1090
- return self.tk.getint(self.tk.call(args))
1091
-
1092
- def winfo_atomname(self, id, displayof=0):
1093
- """Return name of atom with identifier ID."""
1094
- args = ('winfo', 'atomname') \
1095
- + self._displayof(displayof) + (id,)
1096
- return self.tk.call(args)
1097
-
1098
- def winfo_cells(self):
1099
- """Return number of cells in the colormap for this widget."""
1100
- return self.tk.getint(
1101
- self.tk.call('winfo', 'cells', self._w))
1102
-
1103
- def winfo_children(self):
1104
- """Return a list of all widgets which are children of this widget."""
1105
- result = []
1106
- for child in self.tk.splitlist(
1107
- self.tk.call('winfo', 'children', self._w)):
1108
- try:
1109
- # Tcl sometimes returns extra windows, e.g. for
1110
- # menus; those need to be skipped
1111
- result.append(self._nametowidget(child))
1112
- except KeyError:
1113
- pass
1114
- return result
1115
-
1116
- def winfo_class(self):
1117
- """Return window class name of this widget."""
1118
- return self.tk.call('winfo', 'class', self._w)
1119
-
1120
- def winfo_colormapfull(self):
1121
- """Return True if at the last color request the colormap was full."""
1122
- return self.tk.getboolean(
1123
- self.tk.call('winfo', 'colormapfull', self._w))
1124
-
1125
- def winfo_containing(self, rootX, rootY, displayof=0):
1126
- """Return the widget which is at the root coordinates ROOTX, ROOTY."""
1127
- args = ('winfo', 'containing') \
1128
- + self._displayof(displayof) + (rootX, rootY)
1129
- name = self.tk.call(args)
1130
- if not name: return None
1131
- return self._nametowidget(name)
1132
-
1133
- def winfo_depth(self):
1134
- """Return the number of bits per pixel."""
1135
- return self.tk.getint(self.tk.call('winfo', 'depth', self._w))
1136
-
1137
- def winfo_exists(self):
1138
- """Return true if this widget exists."""
1139
- return self.tk.getint(
1140
- self.tk.call('winfo', 'exists', self._w))
1141
-
1142
- def winfo_fpixels(self, number):
1143
- """Return the number of pixels for the given distance NUMBER
1144
- (e.g. "3c") as float."""
1145
- return self.tk.getdouble(self.tk.call(
1146
- 'winfo', 'fpixels', self._w, number))
1147
-
1148
- def winfo_geometry(self):
1149
- """Return geometry string for this widget in the form "widthxheight+X+Y"."""
1150
- return self.tk.call('winfo', 'geometry', self._w)
1151
-
1152
- def winfo_height(self):
1153
- """Return height of this widget."""
1154
- return self.tk.getint(
1155
- self.tk.call('winfo', 'height', self._w))
1156
-
1157
- def winfo_id(self):
1158
- """Return identifier ID for this widget."""
1159
- return int(self.tk.call('winfo', 'id', self._w), 0)
1160
-
1161
- def winfo_interps(self, displayof=0):
1162
- """Return the name of all Tcl interpreters for this display."""
1163
- args = ('winfo', 'interps') + self._displayof(displayof)
1164
- return self.tk.splitlist(self.tk.call(args))
1165
-
1166
- def winfo_ismapped(self):
1167
- """Return true if this widget is mapped."""
1168
- return self.tk.getint(
1169
- self.tk.call('winfo', 'ismapped', self._w))
1170
-
1171
- def winfo_manager(self):
1172
- """Return the window manager name for this widget."""
1173
- return self.tk.call('winfo', 'manager', self._w)
1174
-
1175
- def winfo_name(self):
1176
- """Return the name of this widget."""
1177
- return self.tk.call('winfo', 'name', self._w)
1178
-
1179
- def winfo_parent(self):
1180
- """Return the name of the parent of this widget."""
1181
- return self.tk.call('winfo', 'parent', self._w)
1182
-
1183
- def winfo_pathname(self, id, displayof=0):
1184
- """Return the pathname of the widget given by ID."""
1185
- if isinstance(id, int):
1186
- id = hex(id)
1187
- args = ('winfo', 'pathname') \
1188
- + self._displayof(displayof) + (id,)
1189
- return self.tk.call(args)
1190
-
1191
- def winfo_pixels(self, number):
1192
- """Rounded integer value of winfo_fpixels."""
1193
- return self.tk.getint(
1194
- self.tk.call('winfo', 'pixels', self._w, number))
1195
-
1196
- def winfo_pointerx(self):
1197
- """Return the x coordinate of the pointer on the root window."""
1198
- return self.tk.getint(
1199
- self.tk.call('winfo', 'pointerx', self._w))
1200
-
1201
- def winfo_pointerxy(self):
1202
- """Return a tuple of x and y coordinates of the pointer on the root window."""
1203
- return self._getints(
1204
- self.tk.call('winfo', 'pointerxy', self._w))
1205
-
1206
- def winfo_pointery(self):
1207
- """Return the y coordinate of the pointer on the root window."""
1208
- return self.tk.getint(
1209
- self.tk.call('winfo', 'pointery', self._w))
1210
-
1211
- def winfo_reqheight(self):
1212
- """Return requested height of this widget."""
1213
- return self.tk.getint(
1214
- self.tk.call('winfo', 'reqheight', self._w))
1215
-
1216
- def winfo_reqwidth(self):
1217
- """Return requested width of this widget."""
1218
- return self.tk.getint(
1219
- self.tk.call('winfo', 'reqwidth', self._w))
1220
-
1221
- def winfo_rgb(self, color):
1222
- """Return a tuple of integer RGB values in range(65536) for color in this widget."""
1223
- return self._getints(
1224
- self.tk.call('winfo', 'rgb', self._w, color))
1225
-
1226
- def winfo_rootx(self):
1227
- """Return x coordinate of upper left corner of this widget on the
1228
- root window."""
1229
- return self.tk.getint(
1230
- self.tk.call('winfo', 'rootx', self._w))
1231
-
1232
- def winfo_rooty(self):
1233
- """Return y coordinate of upper left corner of this widget on the
1234
- root window."""
1235
- return self.tk.getint(
1236
- self.tk.call('winfo', 'rooty', self._w))
1237
-
1238
- def winfo_screen(self):
1239
- """Return the screen name of this widget."""
1240
- return self.tk.call('winfo', 'screen', self._w)
1241
-
1242
- def winfo_screencells(self):
1243
- """Return the number of the cells in the colormap of the screen
1244
- of this widget."""
1245
- return self.tk.getint(
1246
- self.tk.call('winfo', 'screencells', self._w))
1247
-
1248
- def winfo_screendepth(self):
1249
- """Return the number of bits per pixel of the root window of the
1250
- screen of this widget."""
1251
- return self.tk.getint(
1252
- self.tk.call('winfo', 'screendepth', self._w))
1253
-
1254
- def winfo_screenheight(self):
1255
- """Return the number of pixels of the height of the screen of this widget
1256
- in pixel."""
1257
- return self.tk.getint(
1258
- self.tk.call('winfo', 'screenheight', self._w))
1259
-
1260
- def winfo_screenmmheight(self):
1261
- """Return the number of pixels of the height of the screen of
1262
- this widget in mm."""
1263
- return self.tk.getint(
1264
- self.tk.call('winfo', 'screenmmheight', self._w))
1265
-
1266
- def winfo_screenmmwidth(self):
1267
- """Return the number of pixels of the width of the screen of
1268
- this widget in mm."""
1269
- return self.tk.getint(
1270
- self.tk.call('winfo', 'screenmmwidth', self._w))
1271
-
1272
- def winfo_screenvisual(self):
1273
- """Return one of the strings directcolor, grayscale, pseudocolor,
1274
- staticcolor, staticgray, or truecolor for the default
1275
- colormodel of this screen."""
1276
- return self.tk.call('winfo', 'screenvisual', self._w)
1277
-
1278
- def winfo_screenwidth(self):
1279
- """Return the number of pixels of the width of the screen of
1280
- this widget in pixel."""
1281
- return self.tk.getint(
1282
- self.tk.call('winfo', 'screenwidth', self._w))
1283
-
1284
- def winfo_server(self):
1285
- """Return information of the X-Server of the screen of this widget in
1286
- the form "XmajorRminor vendor vendorVersion"."""
1287
- return self.tk.call('winfo', 'server', self._w)
1288
-
1289
- def winfo_toplevel(self):
1290
- """Return the toplevel widget of this widget."""
1291
- return self._nametowidget(self.tk.call(
1292
- 'winfo', 'toplevel', self._w))
1293
-
1294
- def winfo_viewable(self):
1295
- """Return true if the widget and all its higher ancestors are mapped."""
1296
- return self.tk.getint(
1297
- self.tk.call('winfo', 'viewable', self._w))
1298
-
1299
- def winfo_visual(self):
1300
- """Return one of the strings directcolor, grayscale, pseudocolor,
1301
- staticcolor, staticgray, or truecolor for the
1302
- colormodel of this widget."""
1303
- return self.tk.call('winfo', 'visual', self._w)
1304
-
1305
- def winfo_visualid(self):
1306
- """Return the X identifier for the visual for this widget."""
1307
- return self.tk.call('winfo', 'visualid', self._w)
1308
-
1309
- def winfo_visualsavailable(self, includeids=False):
1310
- """Return a list of all visuals available for the screen
1311
- of this widget.
1312
-
1313
- Each item in the list consists of a visual name (see winfo_visual), a
1314
- depth and if includeids is true is given also the X identifier."""
1315
- data = self.tk.call('winfo', 'visualsavailable', self._w,
1316
- 'includeids' if includeids else None)
1317
- data = [self.tk.splitlist(x) for x in self.tk.splitlist(data)]
1318
- return [self.__winfo_parseitem(x) for x in data]
1319
-
1320
- def __winfo_parseitem(self, t):
1321
- """Internal function."""
1322
- return t[:1] + tuple(map(self.__winfo_getint, t[1:]))
1323
-
1324
- def __winfo_getint(self, x):
1325
- """Internal function."""
1326
- return int(x, 0)
1327
-
1328
- def winfo_vrootheight(self):
1329
- """Return the height of the virtual root window associated with this
1330
- widget in pixels. If there is no virtual root window return the
1331
- height of the screen."""
1332
- return self.tk.getint(
1333
- self.tk.call('winfo', 'vrootheight', self._w))
1334
-
1335
- def winfo_vrootwidth(self):
1336
- """Return the width of the virtual root window associated with this
1337
- widget in pixel. If there is no virtual root window return the
1338
- width of the screen."""
1339
- return self.tk.getint(
1340
- self.tk.call('winfo', 'vrootwidth', self._w))
1341
-
1342
- def winfo_vrootx(self):
1343
- """Return the x offset of the virtual root relative to the root
1344
- window of the screen of this widget."""
1345
- return self.tk.getint(
1346
- self.tk.call('winfo', 'vrootx', self._w))
1347
-
1348
- def winfo_vrooty(self):
1349
- """Return the y offset of the virtual root relative to the root
1350
- window of the screen of this widget."""
1351
- return self.tk.getint(
1352
- self.tk.call('winfo', 'vrooty', self._w))
1353
-
1354
- def winfo_width(self):
1355
- """Return the width of this widget."""
1356
- return self.tk.getint(
1357
- self.tk.call('winfo', 'width', self._w))
1358
-
1359
- def winfo_x(self):
1360
- """Return the x coordinate of the upper left corner of this widget
1361
- in the parent."""
1362
- return self.tk.getint(
1363
- self.tk.call('winfo', 'x', self._w))
1364
-
1365
- def winfo_y(self):
1366
- """Return the y coordinate of the upper left corner of this widget
1367
- in the parent."""
1368
- return self.tk.getint(
1369
- self.tk.call('winfo', 'y', self._w))
1370
-
1371
- def update(self):
1372
- """Enter event loop until all pending events have been processed by Tcl."""
1373
- self.tk.call('update')
1374
-
1375
- def update_idletasks(self):
1376
- """Enter event loop until all idle callbacks have been called. This
1377
- will update the display of windows but not process events caused by
1378
- the user."""
1379
- self.tk.call('update', 'idletasks')
1380
-
1381
- def bindtags(self, tagList=None):
1382
- """Set or get the list of bindtags for this widget.
1383
-
1384
- With no argument return the list of all bindtags associated with
1385
- this widget. With a list of strings as argument the bindtags are
1386
- set to this list. The bindtags determine in which order events are
1387
- processed (see bind)."""
1388
- if tagList is None:
1389
- return self.tk.splitlist(
1390
- self.tk.call('bindtags', self._w))
1391
- else:
1392
- self.tk.call('bindtags', self._w, tagList)
1393
-
1394
- def _bind(self, what, sequence, func, add, needcleanup=1):
1395
- """Internal function."""
1396
- if isinstance(func, str):
1397
- self.tk.call(what + (sequence, func))
1398
- elif func:
1399
- funcid = self._register(func, self._substitute,
1400
- needcleanup)
1401
- cmd = ('%sif {"[%s %s]" == "break"} break\n'
1402
- %
1403
- (add and '+' or '',
1404
- funcid, self._subst_format_str))
1405
- self.tk.call(what + (sequence, cmd))
1406
- return funcid
1407
- elif sequence:
1408
- return self.tk.call(what + (sequence,))
1409
- else:
1410
- return self.tk.splitlist(self.tk.call(what))
1411
-
1412
- def bind(self, sequence=None, func=None, add=None):
1413
- """Bind to this widget at event SEQUENCE a call to function FUNC.
1414
-
1415
- SEQUENCE is a string of concatenated event
1416
- patterns. An event pattern is of the form
1417
- <MODIFIER-MODIFIER-TYPE-DETAIL> where MODIFIER is one
1418
- of Control, Mod2, M2, Shift, Mod3, M3, Lock, Mod4, M4,
1419
- Button1, B1, Mod5, M5 Button2, B2, Meta, M, Button3,
1420
- B3, Alt, Button4, B4, Double, Button5, B5 Triple,
1421
- Mod1, M1. TYPE is one of Activate, Enter, Map,
1422
- ButtonPress, Button, Expose, Motion, ButtonRelease
1423
- FocusIn, MouseWheel, Circulate, FocusOut, Property,
1424
- Colormap, Gravity Reparent, Configure, KeyPress, Key,
1425
- Unmap, Deactivate, KeyRelease Visibility, Destroy,
1426
- Leave and DETAIL is the button number for ButtonPress,
1427
- ButtonRelease and DETAIL is the Keysym for KeyPress and
1428
- KeyRelease. Examples are
1429
- <Control-Button-1> for pressing Control and mouse button 1 or
1430
- <Alt-A> for pressing A and the Alt key (KeyPress can be omitted).
1431
- An event pattern can also be a virtual event of the form
1432
- <<AString>> where AString can be arbitrary. This
1433
- event can be generated by event_generate.
1434
- If events are concatenated they must appear shortly
1435
- after each other.
1436
-
1437
- FUNC will be called if the event sequence occurs with an
1438
- instance of Event as argument. If the return value of FUNC is
1439
- "break" no further bound function is invoked.
1440
-
1441
- An additional boolean parameter ADD specifies whether FUNC will
1442
- be called additionally to the other bound function or whether
1443
- it will replace the previous function.
1444
-
1445
- Bind will return an identifier to allow deletion of the bound function with
1446
- unbind without memory leak.
1447
-
1448
- If FUNC or SEQUENCE is omitted the bound function or list
1449
- of bound events are returned."""
1450
-
1451
- return self._bind(('bind', self._w), sequence, func, add)
1452
-
1453
- def unbind(self, sequence, funcid=None):
1454
- """Unbind for this widget the event SEQUENCE.
1455
-
1456
- If FUNCID is given, only unbind the function identified with FUNCID
1457
- and also delete the corresponding Tcl command.
1458
-
1459
- Otherwise destroy the current binding for SEQUENCE, leaving SEQUENCE
1460
- unbound.
1461
- """
1462
- self._unbind(('bind', self._w, sequence), funcid)
1463
-
1464
- def _unbind(self, what, funcid=None):
1465
- if funcid is None:
1466
- self.tk.call(*what, '')
1467
- else:
1468
- lines = self.tk.call(what).split('\n')
1469
- prefix = f'if {{"[{funcid} '
1470
- keep = '\n'.join(line for line in lines
1471
- if not line.startswith(prefix))
1472
- if not keep.strip():
1473
- keep = ''
1474
- self.tk.call(*what, keep)
1475
- self.deletecommand(funcid)
1476
-
1477
- def bind_all(self, sequence=None, func=None, add=None):
1478
- """Bind to all widgets at an event SEQUENCE a call to function FUNC.
1479
- An additional boolean parameter ADD specifies whether FUNC will
1480
- be called additionally to the other bound function or whether
1481
- it will replace the previous function. See bind for the return value."""
1482
- return self._root()._bind(('bind', 'all'), sequence, func, add, True)
1483
-
1484
- def unbind_all(self, sequence):
1485
- """Unbind for all widgets for event SEQUENCE all functions."""
1486
- self._root()._unbind(('bind', 'all', sequence))
1487
-
1488
- def bind_class(self, className, sequence=None, func=None, add=None):
1489
- """Bind to widgets with bindtag CLASSNAME at event
1490
- SEQUENCE a call of function FUNC. An additional
1491
- boolean parameter ADD specifies whether FUNC will be
1492
- called additionally to the other bound function or
1493
- whether it will replace the previous function. See bind for
1494
- the return value."""
1495
-
1496
- return self._root()._bind(('bind', className), sequence, func, add, True)
1497
-
1498
- def unbind_class(self, className, sequence):
1499
- """Unbind for all widgets with bindtag CLASSNAME for event SEQUENCE
1500
- all functions."""
1501
- self._root()._unbind(('bind', className, sequence))
1502
-
1503
- def mainloop(self, n=0):
1504
- """Call the mainloop of Tk."""
1505
- self.tk.mainloop(n)
1506
-
1507
- def quit(self):
1508
- """Quit the Tcl interpreter. All widgets will be destroyed."""
1509
- self.tk.quit()
1510
-
1511
- def _getints(self, string):
1512
- """Internal function."""
1513
- if string:
1514
- return tuple(map(self.tk.getint, self.tk.splitlist(string)))
1515
-
1516
- def _getdoubles(self, string):
1517
- """Internal function."""
1518
- if string:
1519
- return tuple(map(self.tk.getdouble, self.tk.splitlist(string)))
1520
-
1521
- def _getboolean(self, string):
1522
- """Internal function."""
1523
- if string:
1524
- return self.tk.getboolean(string)
1525
-
1526
- def _displayof(self, displayof):
1527
- """Internal function."""
1528
- if displayof:
1529
- return ('-displayof', displayof)
1530
- if displayof is None:
1531
- return ('-displayof', self._w)
1532
- return ()
1533
-
1534
- @property
1535
- def _windowingsystem(self):
1536
- """Internal function."""
1537
- try:
1538
- return self._root()._windowingsystem_cached
1539
- except AttributeError:
1540
- ws = self._root()._windowingsystem_cached = \
1541
- self.tk.call('tk', 'windowingsystem')
1542
- return ws
1543
-
1544
- def _options(self, cnf, kw = None):
1545
- """Internal function."""
1546
- if kw:
1547
- cnf = _cnfmerge((cnf, kw))
1548
- else:
1549
- cnf = _cnfmerge(cnf)
1550
- res = ()
1551
- for k, v in cnf.items():
1552
- if v is not None:
1553
- if k[-1] == '_': k = k[:-1]
1554
- if callable(v):
1555
- v = self._register(v)
1556
- elif isinstance(v, (tuple, list)):
1557
- nv = []
1558
- for item in v:
1559
- if isinstance(item, int):
1560
- nv.append(str(item))
1561
- elif isinstance(item, str):
1562
- nv.append(_stringify(item))
1563
- else:
1564
- break
1565
- else:
1566
- v = ' '.join(nv)
1567
- res = res + ('-'+k, v)
1568
- return res
1569
-
1570
- def nametowidget(self, name):
1571
- """Return the Tkinter instance of a widget identified by
1572
- its Tcl name NAME."""
1573
- name = str(name).split('.')
1574
- w = self
1575
-
1576
- if not name[0]:
1577
- w = w._root()
1578
- name = name[1:]
1579
-
1580
- for n in name:
1581
- if not n:
1582
- break
1583
- w = w.children[n]
1584
-
1585
- return w
1586
-
1587
- _nametowidget = nametowidget
1588
-
1589
- def _register(self, func, subst=None, needcleanup=1):
1590
- """Return a newly created Tcl function. If this
1591
- function is called, the Python function FUNC will
1592
- be executed. An optional function SUBST can
1593
- be given which will be executed before FUNC."""
1594
- f = CallWrapper(func, subst, self).__call__
1595
- name = repr(id(f))
1596
- try:
1597
- func = func.__func__
1598
- except AttributeError:
1599
- pass
1600
- try:
1601
- name = name + func.__name__
1602
- except AttributeError:
1603
- pass
1604
- self.tk.createcommand(name, f)
1605
- if needcleanup:
1606
- if self._tclCommands is None:
1607
- self._tclCommands = []
1608
- self._tclCommands.append(name)
1609
- return name
1610
-
1611
- register = _register
1612
-
1613
- def _root(self):
1614
- """Internal function."""
1615
- w = self
1616
- while w.master is not None: w = w.master
1617
- return w
1618
- _subst_format = ('%#', '%b', '%f', '%h', '%k',
1619
- '%s', '%t', '%w', '%x', '%y',
1620
- '%A', '%E', '%K', '%N', '%W', '%T', '%X', '%Y', '%D')
1621
- _subst_format_str = " ".join(_subst_format)
1622
-
1623
- def _substitute(self, *args):
1624
- """Internal function."""
1625
- if len(args) != len(self._subst_format): return args
1626
- getboolean = self.tk.getboolean
1627
-
1628
- getint = self.tk.getint
1629
- def getint_event(s):
1630
- """Tk changed behavior in 8.4.2, returning "??" rather more often."""
1631
- try:
1632
- return getint(s)
1633
- except (ValueError, TclError):
1634
- return s
1635
-
1636
- nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y, D = args
1637
- # Missing: (a, c, d, m, o, v, B, R)
1638
- e = Event()
1639
- # serial field: valid for all events
1640
- # number of button: ButtonPress and ButtonRelease events only
1641
- # height field: Configure, ConfigureRequest, Create,
1642
- # ResizeRequest, and Expose events only
1643
- # keycode field: KeyPress and KeyRelease events only
1644
- # time field: "valid for events that contain a time field"
1645
- # width field: Configure, ConfigureRequest, Create, ResizeRequest,
1646
- # and Expose events only
1647
- # x field: "valid for events that contain an x field"
1648
- # y field: "valid for events that contain a y field"
1649
- # keysym as decimal: KeyPress and KeyRelease events only
1650
- # x_root, y_root fields: ButtonPress, ButtonRelease, KeyPress,
1651
- # KeyRelease, and Motion events
1652
- e.serial = getint(nsign)
1653
- e.num = getint_event(b)
1654
- try: e.focus = getboolean(f)
1655
- except TclError: pass
1656
- e.height = getint_event(h)
1657
- e.keycode = getint_event(k)
1658
- e.state = getint_event(s)
1659
- e.time = getint_event(t)
1660
- e.width = getint_event(w)
1661
- e.x = getint_event(x)
1662
- e.y = getint_event(y)
1663
- e.char = A
1664
- try: e.send_event = getboolean(E)
1665
- except TclError: pass
1666
- e.keysym = K
1667
- e.keysym_num = getint_event(N)
1668
- try:
1669
- e.type = EventType(T)
1670
- except ValueError:
1671
- e.type = T
1672
- try:
1673
- e.widget = self._nametowidget(W)
1674
- except KeyError:
1675
- e.widget = W
1676
- e.x_root = getint_event(X)
1677
- e.y_root = getint_event(Y)
1678
- try:
1679
- e.delta = getint(D)
1680
- except (ValueError, TclError):
1681
- e.delta = 0
1682
- return (e,)
1683
-
1684
- def _report_exception(self):
1685
- """Internal function."""
1686
- exc, val, tb = sys.exc_info()
1687
- root = self._root()
1688
- root.report_callback_exception(exc, val, tb)
1689
-
1690
- def _getconfigure(self, *args):
1691
- """Call Tcl configure command and return the result as a dict."""
1692
- cnf = {}
1693
- for x in self.tk.splitlist(self.tk.call(*args)):
1694
- x = self.tk.splitlist(x)
1695
- cnf[x[0][1:]] = (x[0][1:],) + x[1:]
1696
- return cnf
1697
-
1698
- def _getconfigure1(self, *args):
1699
- x = self.tk.splitlist(self.tk.call(*args))
1700
- return (x[0][1:],) + x[1:]
1701
-
1702
- def _configure(self, cmd, cnf, kw):
1703
- """Internal function."""
1704
- if kw:
1705
- cnf = _cnfmerge((cnf, kw))
1706
- elif cnf:
1707
- cnf = _cnfmerge(cnf)
1708
- if cnf is None:
1709
- return self._getconfigure(_flatten((self._w, cmd)))
1710
- if isinstance(cnf, str):
1711
- return self._getconfigure1(_flatten((self._w, cmd, '-'+cnf)))
1712
- self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
1713
- # These used to be defined in Widget:
1714
-
1715
- def configure(self, cnf=None, **kw):
1716
- """Configure resources of a widget.
1717
-
1718
- The values for resources are specified as keyword
1719
- arguments. To get an overview about
1720
- the allowed keyword arguments call the method keys.
1721
- """
1722
- return self._configure('configure', cnf, kw)
1723
-
1724
- config = configure
1725
-
1726
- def cget(self, key):
1727
- """Return the resource value for a KEY given as string."""
1728
- return self.tk.call(self._w, 'cget', '-' + key)
1729
-
1730
- __getitem__ = cget
1731
-
1732
- def __setitem__(self, key, value):
1733
- self.configure({key: value})
1734
-
1735
- def keys(self):
1736
- """Return a list of all resource names of this widget."""
1737
- splitlist = self.tk.splitlist
1738
- return [splitlist(x)[0][1:] for x in
1739
- splitlist(self.tk.call(self._w, 'configure'))]
1740
-
1741
- def __str__(self):
1742
- """Return the window path name of this widget."""
1743
- return self._w
1744
-
1745
- def __repr__(self):
1746
- return '<%s.%s object %s>' % (
1747
- self.__class__.__module__, self.__class__.__qualname__, self._w)
1748
-
1749
- # Pack methods that apply to the master
1750
- _noarg_ = ['_noarg_']
1751
-
1752
- def pack_propagate(self, flag=_noarg_):
1753
- """Set or get the status for propagation of geometry information.
1754
-
1755
- A boolean argument specifies whether the geometry information
1756
- of the slaves will determine the size of this widget. If no argument
1757
- is given the current setting will be returned.
1758
- """
1759
- if flag is Misc._noarg_:
1760
- return self._getboolean(self.tk.call(
1761
- 'pack', 'propagate', self._w))
1762
- else:
1763
- self.tk.call('pack', 'propagate', self._w, flag)
1764
-
1765
- propagate = pack_propagate
1766
-
1767
- def pack_slaves(self):
1768
- """Return a list of all slaves of this widget
1769
- in its packing order."""
1770
- return [self._nametowidget(x) for x in
1771
- self.tk.splitlist(
1772
- self.tk.call('pack', 'slaves', self._w))]
1773
-
1774
- slaves = pack_slaves
1775
-
1776
- # Place method that applies to the master
1777
- def place_slaves(self):
1778
- """Return a list of all slaves of this widget
1779
- in its packing order."""
1780
- return [self._nametowidget(x) for x in
1781
- self.tk.splitlist(
1782
- self.tk.call(
1783
- 'place', 'slaves', self._w))]
1784
-
1785
- # Grid methods that apply to the master
1786
-
1787
- def grid_anchor(self, anchor=None): # new in Tk 8.5
1788
- """The anchor value controls how to place the grid within the
1789
- master when no row/column has any weight.
1790
-
1791
- The default anchor is nw."""
1792
- self.tk.call('grid', 'anchor', self._w, anchor)
1793
-
1794
- anchor = grid_anchor
1795
-
1796
- def grid_bbox(self, column=None, row=None, col2=None, row2=None):
1797
- """Return a tuple of integer coordinates for the bounding
1798
- box of this widget controlled by the geometry manager grid.
1799
-
1800
- If COLUMN, ROW is given the bounding box applies from
1801
- the cell with row and column 0 to the specified
1802
- cell. If COL2 and ROW2 are given the bounding box
1803
- starts at that cell.
1804
-
1805
- The returned integers specify the offset of the upper left
1806
- corner in the master widget and the width and height.
1807
- """
1808
- args = ('grid', 'bbox', self._w)
1809
- if column is not None and row is not None:
1810
- args = args + (column, row)
1811
- if col2 is not None and row2 is not None:
1812
- args = args + (col2, row2)
1813
- return self._getints(self.tk.call(*args)) or None
1814
-
1815
- bbox = grid_bbox
1816
-
1817
- def _gridconvvalue(self, value):
1818
- if isinstance(value, (str, _tkinter.Tcl_Obj)):
1819
- try:
1820
- svalue = str(value)
1821
- if not svalue:
1822
- return None
1823
- elif '.' in svalue:
1824
- return self.tk.getdouble(svalue)
1825
- else:
1826
- return self.tk.getint(svalue)
1827
- except (ValueError, TclError):
1828
- pass
1829
- return value
1830
-
1831
- def _grid_configure(self, command, index, cnf, kw):
1832
- """Internal function."""
1833
- if isinstance(cnf, str) and not kw:
1834
- if cnf[-1:] == '_':
1835
- cnf = cnf[:-1]
1836
- if cnf[:1] != '-':
1837
- cnf = '-'+cnf
1838
- options = (cnf,)
1839
- else:
1840
- options = self._options(cnf, kw)
1841
- if not options:
1842
- return _splitdict(
1843
- self.tk,
1844
- self.tk.call('grid', command, self._w, index),
1845
- conv=self._gridconvvalue)
1846
- res = self.tk.call(
1847
- ('grid', command, self._w, index)
1848
- + options)
1849
- if len(options) == 1:
1850
- return self._gridconvvalue(res)
1851
-
1852
- def grid_columnconfigure(self, index, cnf={}, **kw):
1853
- """Configure column INDEX of a grid.
1854
-
1855
- Valid resources are minsize (minimum size of the column),
1856
- weight (how much does additional space propagate to this column)
1857
- and pad (how much space to let additionally)."""
1858
- return self._grid_configure('columnconfigure', index, cnf, kw)
1859
-
1860
- columnconfigure = grid_columnconfigure
1861
-
1862
- def grid_location(self, x, y):
1863
- """Return a tuple of column and row which identify the cell
1864
- at which the pixel at position X and Y inside the master
1865
- widget is located."""
1866
- return self._getints(
1867
- self.tk.call(
1868
- 'grid', 'location', self._w, x, y)) or None
1869
-
1870
- def grid_propagate(self, flag=_noarg_):
1871
- """Set or get the status for propagation of geometry information.
1872
-
1873
- A boolean argument specifies whether the geometry information
1874
- of the slaves will determine the size of this widget. If no argument
1875
- is given, the current setting will be returned.
1876
- """
1877
- if flag is Misc._noarg_:
1878
- return self._getboolean(self.tk.call(
1879
- 'grid', 'propagate', self._w))
1880
- else:
1881
- self.tk.call('grid', 'propagate', self._w, flag)
1882
-
1883
- def grid_rowconfigure(self, index, cnf={}, **kw):
1884
- """Configure row INDEX of a grid.
1885
-
1886
- Valid resources are minsize (minimum size of the row),
1887
- weight (how much does additional space propagate to this row)
1888
- and pad (how much space to let additionally)."""
1889
- return self._grid_configure('rowconfigure', index, cnf, kw)
1890
-
1891
- rowconfigure = grid_rowconfigure
1892
-
1893
- def grid_size(self):
1894
- """Return a tuple of the number of column and rows in the grid."""
1895
- return self._getints(
1896
- self.tk.call('grid', 'size', self._w)) or None
1897
-
1898
- size = grid_size
1899
-
1900
- def grid_slaves(self, row=None, column=None):
1901
- """Return a list of all slaves of this widget
1902
- in its packing order."""
1903
- args = ()
1904
- if row is not None:
1905
- args = args + ('-row', row)
1906
- if column is not None:
1907
- args = args + ('-column', column)
1908
- return [self._nametowidget(x) for x in
1909
- self.tk.splitlist(self.tk.call(
1910
- ('grid', 'slaves', self._w) + args))]
1911
-
1912
- # Support for the "event" command, new in Tk 4.2.
1913
- # By Case Roole.
1914
-
1915
- def event_add(self, virtual, *sequences):
1916
- """Bind a virtual event VIRTUAL (of the form <<Name>>)
1917
- to an event SEQUENCE such that the virtual event is triggered
1918
- whenever SEQUENCE occurs."""
1919
- args = ('event', 'add', virtual) + sequences
1920
- self.tk.call(args)
1921
-
1922
- def event_delete(self, virtual, *sequences):
1923
- """Unbind a virtual event VIRTUAL from SEQUENCE."""
1924
- args = ('event', 'delete', virtual) + sequences
1925
- self.tk.call(args)
1926
-
1927
- def event_generate(self, sequence, **kw):
1928
- """Generate an event SEQUENCE. Additional
1929
- keyword arguments specify parameter of the event
1930
- (e.g. x, y, rootx, rooty)."""
1931
- args = ('event', 'generate', self._w, sequence)
1932
- for k, v in kw.items():
1933
- args = args + ('-%s' % k, str(v))
1934
- self.tk.call(args)
1935
-
1936
- def event_info(self, virtual=None):
1937
- """Return a list of all virtual events or the information
1938
- about the SEQUENCE bound to the virtual event VIRTUAL."""
1939
- return self.tk.splitlist(
1940
- self.tk.call('event', 'info', virtual))
1941
-
1942
- # Image related commands
1943
-
1944
- def image_names(self):
1945
- """Return a list of all existing image names."""
1946
- return self.tk.splitlist(self.tk.call('image', 'names'))
1947
-
1948
- def image_types(self):
1949
- """Return a list of all available image types (e.g. photo bitmap)."""
1950
- return self.tk.splitlist(self.tk.call('image', 'types'))
1951
-
1952
-
1953
- class CallWrapper:
1954
- """Internal class. Stores function to call when some user
1955
- defined Tcl function is called e.g. after an event occurred."""
1956
-
1957
- def __init__(self, func, subst, widget):
1958
- """Store FUNC, SUBST and WIDGET as members."""
1959
- self.func = func
1960
- self.subst = subst
1961
- self.widget = widget
1962
-
1963
- def __call__(self, *args):
1964
- """Apply first function SUBST to arguments, than FUNC."""
1965
- try:
1966
- if self.subst:
1967
- args = self.subst(*args)
1968
- return self.func(*args)
1969
- except SystemExit:
1970
- raise
1971
- except:
1972
- self.widget._report_exception()
1973
-
1974
-
1975
- class XView:
1976
- """Mix-in class for querying and changing the horizontal position
1977
- of a widget's window."""
1978
-
1979
- def xview(self, *args):
1980
- """Query and change the horizontal position of the view."""
1981
- res = self.tk.call(self._w, 'xview', *args)
1982
- if not args:
1983
- return self._getdoubles(res)
1984
-
1985
- def xview_moveto(self, fraction):
1986
- """Adjusts the view in the window so that FRACTION of the
1987
- total width of the canvas is off-screen to the left."""
1988
- self.tk.call(self._w, 'xview', 'moveto', fraction)
1989
-
1990
- def xview_scroll(self, number, what):
1991
- """Shift the x-view according to NUMBER which is measured in "units"
1992
- or "pages" (WHAT)."""
1993
- self.tk.call(self._w, 'xview', 'scroll', number, what)
1994
-
1995
-
1996
- class YView:
1997
- """Mix-in class for querying and changing the vertical position
1998
- of a widget's window."""
1999
-
2000
- def yview(self, *args):
2001
- """Query and change the vertical position of the view."""
2002
- res = self.tk.call(self._w, 'yview', *args)
2003
- if not args:
2004
- return self._getdoubles(res)
2005
-
2006
- def yview_moveto(self, fraction):
2007
- """Adjusts the view in the window so that FRACTION of the
2008
- total height of the canvas is off-screen to the top."""
2009
- self.tk.call(self._w, 'yview', 'moveto', fraction)
2010
-
2011
- def yview_scroll(self, number, what):
2012
- """Shift the y-view according to NUMBER which is measured in
2013
- "units" or "pages" (WHAT)."""
2014
- self.tk.call(self._w, 'yview', 'scroll', number, what)
2015
-
2016
-
2017
- class Wm:
2018
- """Provides functions for the communication with the window manager."""
2019
-
2020
- def wm_aspect(self,
2021
- minNumer=None, minDenom=None,
2022
- maxNumer=None, maxDenom=None):
2023
- """Instruct the window manager to set the aspect ratio (width/height)
2024
- of this widget to be between MINNUMER/MINDENOM and MAXNUMER/MAXDENOM. Return a tuple
2025
- of the actual values if no argument is given."""
2026
- return self._getints(
2027
- self.tk.call('wm', 'aspect', self._w,
2028
- minNumer, minDenom,
2029
- maxNumer, maxDenom))
2030
-
2031
- aspect = wm_aspect
2032
-
2033
- def wm_attributes(self, *args):
2034
- """This subcommand returns or sets platform specific attributes
2035
-
2036
- The first form returns a list of the platform specific flags and
2037
- their values. The second form returns the value for the specific
2038
- option. The third form sets one or more of the values. The values
2039
- are as follows:
2040
-
2041
- On Windows, -disabled gets or sets whether the window is in a
2042
- disabled state. -toolwindow gets or sets the style of the window
2043
- to toolwindow (as defined in the MSDN). -topmost gets or sets
2044
- whether this is a topmost window (displays above all other
2045
- windows).
2046
-
2047
- On Macintosh, XXXXX
2048
-
2049
- On Unix, there are currently no special attribute values.
2050
- """
2051
- args = ('wm', 'attributes', self._w) + args
2052
- return self.tk.call(args)
2053
-
2054
- attributes = wm_attributes
2055
-
2056
- def wm_client(self, name=None):
2057
- """Store NAME in WM_CLIENT_MACHINE property of this widget. Return
2058
- current value."""
2059
- return self.tk.call('wm', 'client', self._w, name)
2060
-
2061
- client = wm_client
2062
-
2063
- def wm_colormapwindows(self, *wlist):
2064
- """Store list of window names (WLIST) into WM_COLORMAPWINDOWS property
2065
- of this widget. This list contains windows whose colormaps differ from their
2066
- parents. Return current list of widgets if WLIST is empty."""
2067
- if len(wlist) > 1:
2068
- wlist = (wlist,) # Tk needs a list of windows here
2069
- args = ('wm', 'colormapwindows', self._w) + wlist
2070
- if wlist:
2071
- self.tk.call(args)
2072
- else:
2073
- return [self._nametowidget(x)
2074
- for x in self.tk.splitlist(self.tk.call(args))]
2075
-
2076
- colormapwindows = wm_colormapwindows
2077
-
2078
- def wm_command(self, value=None):
2079
- """Store VALUE in WM_COMMAND property. It is the command
2080
- which shall be used to invoke the application. Return current
2081
- command if VALUE is None."""
2082
- return self.tk.call('wm', 'command', self._w, value)
2083
-
2084
- command = wm_command
2085
-
2086
- def wm_deiconify(self):
2087
- """Deiconify this widget. If it was never mapped it will not be mapped.
2088
- On Windows it will raise this widget and give it the focus."""
2089
- return self.tk.call('wm', 'deiconify', self._w)
2090
-
2091
- deiconify = wm_deiconify
2092
-
2093
- def wm_focusmodel(self, model=None):
2094
- """Set focus model to MODEL. "active" means that this widget will claim
2095
- the focus itself, "passive" means that the window manager shall give
2096
- the focus. Return current focus model if MODEL is None."""
2097
- return self.tk.call('wm', 'focusmodel', self._w, model)
2098
-
2099
- focusmodel = wm_focusmodel
2100
-
2101
- def wm_forget(self, window): # new in Tk 8.5
2102
- """The window will be unmapped from the screen and will no longer
2103
- be managed by wm. toplevel windows will be treated like frame
2104
- windows once they are no longer managed by wm, however, the menu
2105
- option configuration will be remembered and the menus will return
2106
- once the widget is managed again."""
2107
- self.tk.call('wm', 'forget', window)
2108
-
2109
- forget = wm_forget
2110
-
2111
- def wm_frame(self):
2112
- """Return identifier for decorative frame of this widget if present."""
2113
- return self.tk.call('wm', 'frame', self._w)
2114
-
2115
- frame = wm_frame
2116
-
2117
- def wm_geometry(self, newGeometry=None):
2118
- """Set geometry to NEWGEOMETRY of the form =widthxheight+x+y. Return
2119
- current value if None is given."""
2120
- return self.tk.call('wm', 'geometry', self._w, newGeometry)
2121
-
2122
- geometry = wm_geometry
2123
-
2124
- def wm_grid(self,
2125
- baseWidth=None, baseHeight=None,
2126
- widthInc=None, heightInc=None):
2127
- """Instruct the window manager that this widget shall only be
2128
- resized on grid boundaries. WIDTHINC and HEIGHTINC are the width and
2129
- height of a grid unit in pixels. BASEWIDTH and BASEHEIGHT are the
2130
- number of grid units requested in Tk_GeometryRequest."""
2131
- return self._getints(self.tk.call(
2132
- 'wm', 'grid', self._w,
2133
- baseWidth, baseHeight, widthInc, heightInc))
2134
-
2135
- grid = wm_grid
2136
-
2137
- def wm_group(self, pathName=None):
2138
- """Set the group leader widgets for related widgets to PATHNAME. Return
2139
- the group leader of this widget if None is given."""
2140
- return self.tk.call('wm', 'group', self._w, pathName)
2141
-
2142
- group = wm_group
2143
-
2144
- def wm_iconbitmap(self, bitmap=None, default=None):
2145
- """Set bitmap for the iconified widget to BITMAP. Return
2146
- the bitmap if None is given.
2147
-
2148
- Under Windows, the DEFAULT parameter can be used to set the icon
2149
- for the widget and any descendants that don't have an icon set
2150
- explicitly. DEFAULT can be the relative path to a .ico file
2151
- (example: root.iconbitmap(default='myicon.ico') ). See Tk
2152
- documentation for more information."""
2153
- if default is not None:
2154
- return self.tk.call('wm', 'iconbitmap', self._w, '-default', default)
2155
- else:
2156
- return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
2157
-
2158
- iconbitmap = wm_iconbitmap
2159
-
2160
- def wm_iconify(self):
2161
- """Display widget as icon."""
2162
- return self.tk.call('wm', 'iconify', self._w)
2163
-
2164
- iconify = wm_iconify
2165
-
2166
- def wm_iconmask(self, bitmap=None):
2167
- """Set mask for the icon bitmap of this widget. Return the
2168
- mask if None is given."""
2169
- return self.tk.call('wm', 'iconmask', self._w, bitmap)
2170
-
2171
- iconmask = wm_iconmask
2172
-
2173
- def wm_iconname(self, newName=None):
2174
- """Set the name of the icon for this widget. Return the name if
2175
- None is given."""
2176
- return self.tk.call('wm', 'iconname', self._w, newName)
2177
-
2178
- iconname = wm_iconname
2179
-
2180
- def wm_iconphoto(self, default=False, *args): # new in Tk 8.5
2181
- """Sets the titlebar icon for this window based on the named photo
2182
- images passed through args. If default is True, this is applied to
2183
- all future created toplevels as well.
2184
-
2185
- The data in the images is taken as a snapshot at the time of
2186
- invocation. If the images are later changed, this is not reflected
2187
- to the titlebar icons. Multiple images are accepted to allow
2188
- different images sizes to be provided. The window manager may scale
2189
- provided icons to an appropriate size.
2190
-
2191
- On Windows, the images are packed into a Windows icon structure.
2192
- This will override an icon specified to wm_iconbitmap, and vice
2193
- versa.
2194
-
2195
- On X, the images are arranged into the _NET_WM_ICON X property,
2196
- which most modern window managers support. An icon specified by
2197
- wm_iconbitmap may exist simultaneously.
2198
-
2199
- On Macintosh, this currently does nothing."""
2200
- if default:
2201
- self.tk.call('wm', 'iconphoto', self._w, "-default", *args)
2202
- else:
2203
- self.tk.call('wm', 'iconphoto', self._w, *args)
2204
-
2205
- iconphoto = wm_iconphoto
2206
-
2207
- def wm_iconposition(self, x=None, y=None):
2208
- """Set the position of the icon of this widget to X and Y. Return
2209
- a tuple of the current values of X and X if None is given."""
2210
- return self._getints(self.tk.call(
2211
- 'wm', 'iconposition', self._w, x, y))
2212
-
2213
- iconposition = wm_iconposition
2214
-
2215
- def wm_iconwindow(self, pathName=None):
2216
- """Set widget PATHNAME to be displayed instead of icon. Return the current
2217
- value if None is given."""
2218
- return self.tk.call('wm', 'iconwindow', self._w, pathName)
2219
-
2220
- iconwindow = wm_iconwindow
2221
-
2222
- def wm_manage(self, widget): # new in Tk 8.5
2223
- """The widget specified will become a stand alone top-level window.
2224
- The window will be decorated with the window managers title bar,
2225
- etc."""
2226
- self.tk.call('wm', 'manage', widget)
2227
-
2228
- manage = wm_manage
2229
-
2230
- def wm_maxsize(self, width=None, height=None):
2231
- """Set max WIDTH and HEIGHT for this widget. If the window is gridded
2232
- the values are given in grid units. Return the current values if None
2233
- is given."""
2234
- return self._getints(self.tk.call(
2235
- 'wm', 'maxsize', self._w, width, height))
2236
-
2237
- maxsize = wm_maxsize
2238
-
2239
- def wm_minsize(self, width=None, height=None):
2240
- """Set min WIDTH and HEIGHT for this widget. If the window is gridded
2241
- the values are given in grid units. Return the current values if None
2242
- is given."""
2243
- return self._getints(self.tk.call(
2244
- 'wm', 'minsize', self._w, width, height))
2245
-
2246
- minsize = wm_minsize
2247
-
2248
- def wm_overrideredirect(self, boolean=None):
2249
- """Instruct the window manager to ignore this widget
2250
- if BOOLEAN is given with 1. Return the current value if None
2251
- is given."""
2252
- return self._getboolean(self.tk.call(
2253
- 'wm', 'overrideredirect', self._w, boolean))
2254
-
2255
- overrideredirect = wm_overrideredirect
2256
-
2257
- def wm_positionfrom(self, who=None):
2258
- """Instruct the window manager that the position of this widget shall
2259
- be defined by the user if WHO is "user", and by its own policy if WHO is
2260
- "program"."""
2261
- return self.tk.call('wm', 'positionfrom', self._w, who)
2262
-
2263
- positionfrom = wm_positionfrom
2264
-
2265
- def wm_protocol(self, name=None, func=None):
2266
- """Bind function FUNC to command NAME for this widget.
2267
- Return the function bound to NAME if None is given. NAME could be
2268
- e.g. "WM_SAVE_YOURSELF" or "WM_DELETE_WINDOW"."""
2269
- if callable(func):
2270
- command = self._register(func)
2271
- else:
2272
- command = func
2273
- return self.tk.call(
2274
- 'wm', 'protocol', self._w, name, command)
2275
-
2276
- protocol = wm_protocol
2277
-
2278
- def wm_resizable(self, width=None, height=None):
2279
- """Instruct the window manager whether this width can be resized
2280
- in WIDTH or HEIGHT. Both values are boolean values."""
2281
- return self.tk.call('wm', 'resizable', self._w, width, height)
2282
-
2283
- resizable = wm_resizable
2284
-
2285
- def wm_sizefrom(self, who=None):
2286
- """Instruct the window manager that the size of this widget shall
2287
- be defined by the user if WHO is "user", and by its own policy if WHO is
2288
- "program"."""
2289
- return self.tk.call('wm', 'sizefrom', self._w, who)
2290
-
2291
- sizefrom = wm_sizefrom
2292
-
2293
- def wm_state(self, newstate=None):
2294
- """Query or set the state of this widget as one of normal, icon,
2295
- iconic (see wm_iconwindow), withdrawn, or zoomed (Windows only)."""
2296
- return self.tk.call('wm', 'state', self._w, newstate)
2297
-
2298
- state = wm_state
2299
-
2300
- def wm_title(self, string=None):
2301
- """Set the title of this widget."""
2302
- return self.tk.call('wm', 'title', self._w, string)
2303
-
2304
- title = wm_title
2305
-
2306
- def wm_transient(self, master=None):
2307
- """Instruct the window manager that this widget is transient
2308
- with regard to widget MASTER."""
2309
- return self.tk.call('wm', 'transient', self._w, master)
2310
-
2311
- transient = wm_transient
2312
-
2313
- def wm_withdraw(self):
2314
- """Withdraw this widget from the screen such that it is unmapped
2315
- and forgotten by the window manager. Re-draw it with wm_deiconify."""
2316
- return self.tk.call('wm', 'withdraw', self._w)
2317
-
2318
- withdraw = wm_withdraw
2319
-
2320
-
2321
- class Tk(Misc, Wm):
2322
- """Toplevel widget of Tk which represents mostly the main window
2323
- of an application. It has an associated Tcl interpreter."""
2324
- _w = '.'
2325
-
2326
- def __init__(self, screenName=None, baseName=None, className='Tk',
2327
- useTk=True, sync=False, use=None):
2328
- """Return a new top level widget on screen SCREENNAME. A new Tcl interpreter will
2329
- be created. BASENAME will be used for the identification of the profile file (see
2330
- readprofile).
2331
- It is constructed from sys.argv[0] without extensions if None is given. CLASSNAME
2332
- is the name of the widget class."""
2333
- self.master = None
2334
- self.children = {}
2335
- self._tkloaded = False
2336
- # to avoid recursions in the getattr code in case of failure, we
2337
- # ensure that self.tk is always _something_.
2338
- self.tk = None
2339
- if baseName is None:
2340
- import os
2341
- baseName = os.path.basename(sys.argv[0])
2342
- baseName, ext = os.path.splitext(baseName)
2343
- if ext not in ('.py', '.pyc'):
2344
- baseName = baseName + ext
2345
- interactive = False
2346
- self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
2347
- if _debug:
2348
- self.tk.settrace(_print_command)
2349
- if useTk:
2350
- self._loadtk()
2351
- if not sys.flags.ignore_environment:
2352
- # Issue #16248: Honor the -E flag to avoid code injection.
2353
- self.readprofile(baseName, className)
2354
-
2355
- def loadtk(self):
2356
- if not self._tkloaded:
2357
- self.tk.loadtk()
2358
- self._loadtk()
2359
-
2360
- def _loadtk(self):
2361
- self._tkloaded = True
2362
- global _default_root
2363
- # Version sanity checks
2364
- tk_version = self.tk.getvar('tk_version')
2365
- if tk_version != _tkinter.TK_VERSION:
2366
- raise RuntimeError("tk.h version (%s) doesn't match libtk.a version (%s)"
2367
- % (_tkinter.TK_VERSION, tk_version))
2368
- # Under unknown circumstances, tcl_version gets coerced to float
2369
- tcl_version = str(self.tk.getvar('tcl_version'))
2370
- if tcl_version != _tkinter.TCL_VERSION:
2371
- raise RuntimeError("tcl.h version (%s) doesn't match libtcl.a version (%s)" \
2372
- % (_tkinter.TCL_VERSION, tcl_version))
2373
- # Create and register the tkerror and exit commands
2374
- # We need to inline parts of _register here, _ register
2375
- # would register differently-named commands.
2376
- if self._tclCommands is None:
2377
- self._tclCommands = []
2378
- self.tk.createcommand('tkerror', _tkerror)
2379
- self.tk.createcommand('exit', _exit)
2380
- self._tclCommands.append('tkerror')
2381
- self._tclCommands.append('exit')
2382
- if _support_default_root and _default_root is None:
2383
- _default_root = self
2384
- self.protocol("WM_DELETE_WINDOW", self.destroy)
2385
-
2386
- def destroy(self):
2387
- """Destroy this and all descendants widgets. This will
2388
- end the application of this Tcl interpreter."""
2389
- for c in list(self.children.values()): c.destroy()
2390
- self.tk.call('destroy', self._w)
2391
- Misc.destroy(self)
2392
- global _default_root
2393
- if _support_default_root and _default_root is self:
2394
- _default_root = None
2395
-
2396
- def readprofile(self, baseName, className):
2397
- """Internal function. It reads .BASENAME.tcl and .CLASSNAME.tcl into
2398
- the Tcl Interpreter and calls exec on the contents of .BASENAME.py and
2399
- .CLASSNAME.py if such a file exists in the home directory."""
2400
- import os
2401
- if 'HOME' in os.environ: home = os.environ['HOME']
2402
- else: home = os.curdir
2403
- class_tcl = os.path.join(home, '.%s.tcl' % className)
2404
- class_py = os.path.join(home, '.%s.py' % className)
2405
- base_tcl = os.path.join(home, '.%s.tcl' % baseName)
2406
- base_py = os.path.join(home, '.%s.py' % baseName)
2407
- dir = {'self': self}
2408
- exec('from tkinter import *', dir)
2409
- if os.path.isfile(class_tcl):
2410
- self.tk.call('source', class_tcl)
2411
- if os.path.isfile(class_py):
2412
- exec(open(class_py).read(), dir)
2413
- if os.path.isfile(base_tcl):
2414
- self.tk.call('source', base_tcl)
2415
- if os.path.isfile(base_py):
2416
- exec(open(base_py).read(), dir)
2417
-
2418
- def report_callback_exception(self, exc, val, tb):
2419
- """Report callback exception on sys.stderr.
2420
-
2421
- Applications may want to override this internal function, and
2422
- should when sys.stderr is None."""
2423
- import traceback
2424
- print("Exception in Tkinter callback", file=sys.stderr)
2425
- sys.last_exc = val
2426
- sys.last_type = exc
2427
- sys.last_value = val
2428
- sys.last_traceback = tb
2429
- traceback.print_exception(exc, val, tb)
2430
-
2431
- def __getattr__(self, attr):
2432
- "Delegate attribute access to the interpreter object"
2433
- return getattr(self.tk, attr)
2434
-
2435
-
2436
- def _print_command(cmd, *, file=sys.stderr):
2437
- # Print executed Tcl/Tk commands.
2438
- assert isinstance(cmd, tuple)
2439
- cmd = _join(cmd)
2440
- print(cmd, file=file)
2441
-
2442
-
2443
- # Ideally, the classes Pack, Place and Grid disappear, the
2444
- # pack/place/grid methods are defined on the Widget class, and
2445
- # everybody uses w.pack_whatever(...) instead of Pack.whatever(w,
2446
- # ...), with pack(), place() and grid() being short for
2447
- # pack_configure(), place_configure() and grid_columnconfigure(), and
2448
- # forget() being short for pack_forget(). As a practical matter, I'm
2449
- # afraid that there is too much code out there that may be using the
2450
- # Pack, Place or Grid class, so I leave them intact -- but only as
2451
- # backwards compatibility features. Also note that those methods that
2452
- # take a master as argument (e.g. pack_propagate) have been moved to
2453
- # the Misc class (which now incorporates all methods common between
2454
- # toplevel and interior widgets). Again, for compatibility, these are
2455
- # copied into the Pack, Place or Grid class.
2456
-
2457
-
2458
- def Tcl(screenName=None, baseName=None, className='Tk', useTk=False):
2459
- return Tk(screenName, baseName, className, useTk)
2460
-
2461
-
2462
- class Pack:
2463
- """Geometry manager Pack.
2464
-
2465
- Base class to use the methods pack_* in every widget."""
2466
-
2467
- def pack_configure(self, cnf={}, **kw):
2468
- """Pack a widget in the parent widget. Use as options:
2469
- after=widget - pack it after you have packed widget
2470
- anchor=NSEW (or subset) - position widget according to
2471
- given direction
2472
- before=widget - pack it before you will pack widget
2473
- expand=bool - expand widget if parent size grows
2474
- fill=NONE or X or Y or BOTH - fill widget if widget grows
2475
- in=master - use master to contain this widget
2476
- in_=master - see 'in' option description
2477
- ipadx=amount - add internal padding in x direction
2478
- ipady=amount - add internal padding in y direction
2479
- padx=amount - add padding in x direction
2480
- pady=amount - add padding in y direction
2481
- side=TOP or BOTTOM or LEFT or RIGHT - where to add this widget.
2482
- """
2483
- self.tk.call(
2484
- ('pack', 'configure', self._w)
2485
- + self._options(cnf, kw))
2486
-
2487
- pack = configure = config = pack_configure
2488
-
2489
- def pack_forget(self):
2490
- """Unmap this widget and do not use it for the packing order."""
2491
- self.tk.call('pack', 'forget', self._w)
2492
-
2493
- forget = pack_forget
2494
-
2495
- def pack_info(self):
2496
- """Return information about the packing options
2497
- for this widget."""
2498
- d = _splitdict(self.tk, self.tk.call('pack', 'info', self._w))
2499
- if 'in' in d:
2500
- d['in'] = self.nametowidget(d['in'])
2501
- return d
2502
-
2503
- info = pack_info
2504
- propagate = pack_propagate = Misc.pack_propagate
2505
- slaves = pack_slaves = Misc.pack_slaves
2506
-
2507
-
2508
- class Place:
2509
- """Geometry manager Place.
2510
-
2511
- Base class to use the methods place_* in every widget."""
2512
-
2513
- def place_configure(self, cnf={}, **kw):
2514
- """Place a widget in the parent widget. Use as options:
2515
- in=master - master relative to which the widget is placed
2516
- in_=master - see 'in' option description
2517
- x=amount - locate anchor of this widget at position x of master
2518
- y=amount - locate anchor of this widget at position y of master
2519
- relx=amount - locate anchor of this widget between 0.0 and 1.0
2520
- relative to width of master (1.0 is right edge)
2521
- rely=amount - locate anchor of this widget between 0.0 and 1.0
2522
- relative to height of master (1.0 is bottom edge)
2523
- anchor=NSEW (or subset) - position anchor according to given direction
2524
- width=amount - width of this widget in pixel
2525
- height=amount - height of this widget in pixel
2526
- relwidth=amount - width of this widget between 0.0 and 1.0
2527
- relative to width of master (1.0 is the same width
2528
- as the master)
2529
- relheight=amount - height of this widget between 0.0 and 1.0
2530
- relative to height of master (1.0 is the same
2531
- height as the master)
2532
- bordermode="inside" or "outside" - whether to take border width of
2533
- master widget into account
2534
- """
2535
- self.tk.call(
2536
- ('place', 'configure', self._w)
2537
- + self._options(cnf, kw))
2538
-
2539
- place = configure = config = place_configure
2540
-
2541
- def place_forget(self):
2542
- """Unmap this widget."""
2543
- self.tk.call('place', 'forget', self._w)
2544
-
2545
- forget = place_forget
2546
-
2547
- def place_info(self):
2548
- """Return information about the placing options
2549
- for this widget."""
2550
- d = _splitdict(self.tk, self.tk.call('place', 'info', self._w))
2551
- if 'in' in d:
2552
- d['in'] = self.nametowidget(d['in'])
2553
- return d
2554
-
2555
- info = place_info
2556
- slaves = place_slaves = Misc.place_slaves
2557
-
2558
-
2559
- class Grid:
2560
- """Geometry manager Grid.
2561
-
2562
- Base class to use the methods grid_* in every widget."""
2563
- # Thanks to Masazumi Yoshikawa (yosikawa@isi.edu)
2564
-
2565
- def grid_configure(self, cnf={}, **kw):
2566
- """Position a widget in the parent widget in a grid. Use as options:
2567
- column=number - use cell identified with given column (starting with 0)
2568
- columnspan=number - this widget will span several columns
2569
- in=master - use master to contain this widget
2570
- in_=master - see 'in' option description
2571
- ipadx=amount - add internal padding in x direction
2572
- ipady=amount - add internal padding in y direction
2573
- padx=amount - add padding in x direction
2574
- pady=amount - add padding in y direction
2575
- row=number - use cell identified with given row (starting with 0)
2576
- rowspan=number - this widget will span several rows
2577
- sticky=NSEW - if cell is larger on which sides will this
2578
- widget stick to the cell boundary
2579
- """
2580
- self.tk.call(
2581
- ('grid', 'configure', self._w)
2582
- + self._options(cnf, kw))
2583
-
2584
- grid = configure = config = grid_configure
2585
- bbox = grid_bbox = Misc.grid_bbox
2586
- columnconfigure = grid_columnconfigure = Misc.grid_columnconfigure
2587
-
2588
- def grid_forget(self):
2589
- """Unmap this widget."""
2590
- self.tk.call('grid', 'forget', self._w)
2591
-
2592
- forget = grid_forget
2593
-
2594
- def grid_remove(self):
2595
- """Unmap this widget but remember the grid options."""
2596
- self.tk.call('grid', 'remove', self._w)
2597
-
2598
- def grid_info(self):
2599
- """Return information about the options
2600
- for positioning this widget in a grid."""
2601
- d = _splitdict(self.tk, self.tk.call('grid', 'info', self._w))
2602
- if 'in' in d:
2603
- d['in'] = self.nametowidget(d['in'])
2604
- return d
2605
-
2606
- info = grid_info
2607
- location = grid_location = Misc.grid_location
2608
- propagate = grid_propagate = Misc.grid_propagate
2609
- rowconfigure = grid_rowconfigure = Misc.grid_rowconfigure
2610
- size = grid_size = Misc.grid_size
2611
- slaves = grid_slaves = Misc.grid_slaves
2612
-
2613
-
2614
- class BaseWidget(Misc):
2615
- """Internal class."""
2616
-
2617
- def _setup(self, master, cnf):
2618
- """Internal function. Sets up information about children."""
2619
- if master is None:
2620
- master = _get_default_root()
2621
- self.master = master
2622
- self.tk = master.tk
2623
- name = None
2624
- if 'name' in cnf:
2625
- name = cnf['name']
2626
- del cnf['name']
2627
- if not name:
2628
- name = self.__class__.__name__.lower()
2629
- if name[-1].isdigit():
2630
- name += "!" # Avoid duplication when calculating names below
2631
- if master._last_child_ids is None:
2632
- master._last_child_ids = {}
2633
- count = master._last_child_ids.get(name, 0) + 1
2634
- master._last_child_ids[name] = count
2635
- if count == 1:
2636
- name = '!%s' % (name,)
2637
- else:
2638
- name = '!%s%d' % (name, count)
2639
- self._name = name
2640
- if master._w=='.':
2641
- self._w = '.' + name
2642
- else:
2643
- self._w = master._w + '.' + name
2644
- self.children = {}
2645
- if self._name in self.master.children:
2646
- self.master.children[self._name].destroy()
2647
- self.master.children[self._name] = self
2648
-
2649
- def __init__(self, master, widgetName, cnf={}, kw={}, extra=()):
2650
- """Construct a widget with the parent widget MASTER, a name WIDGETNAME
2651
- and appropriate options."""
2652
- if kw:
2653
- cnf = _cnfmerge((cnf, kw))
2654
- self.widgetName = widgetName
2655
- self._setup(master, cnf)
2656
- if self._tclCommands is None:
2657
- self._tclCommands = []
2658
- classes = [(k, v) for k, v in cnf.items() if isinstance(k, type)]
2659
- for k, v in classes:
2660
- del cnf[k]
2661
- self.tk.call(
2662
- (widgetName, self._w) + extra + self._options(cnf))
2663
- for k, v in classes:
2664
- k.configure(self, v)
2665
-
2666
- def destroy(self):
2667
- """Destroy this and all descendants widgets."""
2668
- for c in list(self.children.values()): c.destroy()
2669
- self.tk.call('destroy', self._w)
2670
- if self._name in self.master.children:
2671
- del self.master.children[self._name]
2672
- Misc.destroy(self)
2673
-
2674
- def _do(self, name, args=()):
2675
- # XXX Obsolete -- better use self.tk.call directly!
2676
- return self.tk.call((self._w, name) + args)
2677
-
2678
-
2679
- class Widget(BaseWidget, Pack, Place, Grid):
2680
- """Internal class.
2681
-
2682
- Base class for a widget which can be positioned with the geometry managers
2683
- Pack, Place or Grid."""
2684
- pass
2685
-
2686
-
2687
- class Toplevel(BaseWidget, Wm):
2688
- """Toplevel widget, e.g. for dialogs."""
2689
-
2690
- def __init__(self, master=None, cnf={}, **kw):
2691
- """Construct a toplevel widget with the parent MASTER.
2692
-
2693
- Valid resource names: background, bd, bg, borderwidth, class,
2694
- colormap, container, cursor, height, highlightbackground,
2695
- highlightcolor, highlightthickness, menu, relief, screen, takefocus,
2696
- use, visual, width."""
2697
- if kw:
2698
- cnf = _cnfmerge((cnf, kw))
2699
- extra = ()
2700
- for wmkey in ['screen', 'class_', 'class', 'visual',
2701
- 'colormap']:
2702
- if wmkey in cnf:
2703
- val = cnf[wmkey]
2704
- # TBD: a hack needed because some keys
2705
- # are not valid as keyword arguments
2706
- if wmkey[-1] == '_': opt = '-'+wmkey[:-1]
2707
- else: opt = '-'+wmkey
2708
- extra = extra + (opt, val)
2709
- del cnf[wmkey]
2710
- BaseWidget.__init__(self, master, 'toplevel', cnf, {}, extra)
2711
- root = self._root()
2712
- self.iconname(root.iconname())
2713
- self.title(root.title())
2714
- self.protocol("WM_DELETE_WINDOW", self.destroy)
2715
-
2716
-
2717
- class Button(Widget):
2718
- """Button widget."""
2719
-
2720
- def __init__(self, master=None, cnf={}, **kw):
2721
- """Construct a button widget with the parent MASTER.
2722
-
2723
- STANDARD OPTIONS
2724
-
2725
- activebackground, activeforeground, anchor,
2726
- background, bitmap, borderwidth, cursor,
2727
- disabledforeground, font, foreground
2728
- highlightbackground, highlightcolor,
2729
- highlightthickness, image, justify,
2730
- padx, pady, relief, repeatdelay,
2731
- repeatinterval, takefocus, text,
2732
- textvariable, underline, wraplength
2733
-
2734
- WIDGET-SPECIFIC OPTIONS
2735
-
2736
- command, compound, default, height,
2737
- overrelief, state, width
2738
- """
2739
- Widget.__init__(self, master, 'button', cnf, kw)
2740
-
2741
- def flash(self):
2742
- """Flash the button.
2743
-
2744
- This is accomplished by redisplaying
2745
- the button several times, alternating between active and
2746
- normal colors. At the end of the flash the button is left
2747
- in the same normal/active state as when the command was
2748
- invoked. This command is ignored if the button's state is
2749
- disabled.
2750
- """
2751
- self.tk.call(self._w, 'flash')
2752
-
2753
- def invoke(self):
2754
- """Invoke the command associated with the button.
2755
-
2756
- The return value is the return value from the command,
2757
- or an empty string if there is no command associated with
2758
- the button. This command is ignored if the button's state
2759
- is disabled.
2760
- """
2761
- return self.tk.call(self._w, 'invoke')
2762
-
2763
-
2764
- class Canvas(Widget, XView, YView):
2765
- """Canvas widget to display graphical elements like lines or text."""
2766
-
2767
- def __init__(self, master=None, cnf={}, **kw):
2768
- """Construct a canvas widget with the parent MASTER.
2769
-
2770
- Valid resource names: background, bd, bg, borderwidth, closeenough,
2771
- confine, cursor, height, highlightbackground, highlightcolor,
2772
- highlightthickness, insertbackground, insertborderwidth,
2773
- insertofftime, insertontime, insertwidth, offset, relief,
2774
- scrollregion, selectbackground, selectborderwidth, selectforeground,
2775
- state, takefocus, width, xscrollcommand, xscrollincrement,
2776
- yscrollcommand, yscrollincrement."""
2777
- Widget.__init__(self, master, 'canvas', cnf, kw)
2778
-
2779
- def addtag(self, *args):
2780
- """Internal function."""
2781
- self.tk.call((self._w, 'addtag') + args)
2782
-
2783
- def addtag_above(self, newtag, tagOrId):
2784
- """Add tag NEWTAG to all items above TAGORID."""
2785
- self.addtag(newtag, 'above', tagOrId)
2786
-
2787
- def addtag_all(self, newtag):
2788
- """Add tag NEWTAG to all items."""
2789
- self.addtag(newtag, 'all')
2790
-
2791
- def addtag_below(self, newtag, tagOrId):
2792
- """Add tag NEWTAG to all items below TAGORID."""
2793
- self.addtag(newtag, 'below', tagOrId)
2794
-
2795
- def addtag_closest(self, newtag, x, y, halo=None, start=None):
2796
- """Add tag NEWTAG to item which is closest to pixel at X, Y.
2797
- If several match take the top-most.
2798
- All items closer than HALO are considered overlapping (all are
2799
- closest). If START is specified the next below this tag is taken."""
2800
- self.addtag(newtag, 'closest', x, y, halo, start)
2801
-
2802
- def addtag_enclosed(self, newtag, x1, y1, x2, y2):
2803
- """Add tag NEWTAG to all items in the rectangle defined
2804
- by X1,Y1,X2,Y2."""
2805
- self.addtag(newtag, 'enclosed', x1, y1, x2, y2)
2806
-
2807
- def addtag_overlapping(self, newtag, x1, y1, x2, y2):
2808
- """Add tag NEWTAG to all items which overlap the rectangle
2809
- defined by X1,Y1,X2,Y2."""
2810
- self.addtag(newtag, 'overlapping', x1, y1, x2, y2)
2811
-
2812
- def addtag_withtag(self, newtag, tagOrId):
2813
- """Add tag NEWTAG to all items with TAGORID."""
2814
- self.addtag(newtag, 'withtag', tagOrId)
2815
-
2816
- def bbox(self, *args):
2817
- """Return a tuple of X1,Y1,X2,Y2 coordinates for a rectangle
2818
- which encloses all items with tags specified as arguments."""
2819
- return self._getints(
2820
- self.tk.call((self._w, 'bbox') + args)) or None
2821
-
2822
- def tag_unbind(self, tagOrId, sequence, funcid=None):
2823
- """Unbind for all items with TAGORID for event SEQUENCE the
2824
- function identified with FUNCID."""
2825
- self._unbind((self._w, 'bind', tagOrId, sequence), funcid)
2826
-
2827
- def tag_bind(self, tagOrId, sequence=None, func=None, add=None):
2828
- """Bind to all items with TAGORID at event SEQUENCE a call to function FUNC.
2829
-
2830
- An additional boolean parameter ADD specifies whether FUNC will be
2831
- called additionally to the other bound function or whether it will
2832
- replace the previous function. See bind for the return value."""
2833
- return self._bind((self._w, 'bind', tagOrId),
2834
- sequence, func, add)
2835
-
2836
- def canvasx(self, screenx, gridspacing=None):
2837
- """Return the canvas x coordinate of pixel position SCREENX rounded
2838
- to nearest multiple of GRIDSPACING units."""
2839
- return self.tk.getdouble(self.tk.call(
2840
- self._w, 'canvasx', screenx, gridspacing))
2841
-
2842
- def canvasy(self, screeny, gridspacing=None):
2843
- """Return the canvas y coordinate of pixel position SCREENY rounded
2844
- to nearest multiple of GRIDSPACING units."""
2845
- return self.tk.getdouble(self.tk.call(
2846
- self._w, 'canvasy', screeny, gridspacing))
2847
-
2848
- def coords(self, *args):
2849
- """Return a list of coordinates for the item given in ARGS."""
2850
- args = _flatten(args)
2851
- return [self.tk.getdouble(x) for x in
2852
- self.tk.splitlist(
2853
- self.tk.call((self._w, 'coords') + args))]
2854
-
2855
- def _create(self, itemType, args, kw): # Args: (val, val, ..., cnf={})
2856
- """Internal function."""
2857
- args = _flatten(args)
2858
- cnf = args[-1]
2859
- if isinstance(cnf, (dict, tuple)):
2860
- args = args[:-1]
2861
- else:
2862
- cnf = {}
2863
- return self.tk.getint(self.tk.call(
2864
- self._w, 'create', itemType,
2865
- *(args + self._options(cnf, kw))))
2866
-
2867
- def create_arc(self, *args, **kw):
2868
- """Create arc shaped region with coordinates x1,y1,x2,y2."""
2869
- return self._create('arc', args, kw)
2870
-
2871
- def create_bitmap(self, *args, **kw):
2872
- """Create bitmap with coordinates x1,y1."""
2873
- return self._create('bitmap', args, kw)
2874
-
2875
- def create_image(self, *args, **kw):
2876
- """Create image item with coordinates x1,y1."""
2877
- return self._create('image', args, kw)
2878
-
2879
- def create_line(self, *args, **kw):
2880
- """Create line with coordinates x1,y1,...,xn,yn."""
2881
- return self._create('line', args, kw)
2882
-
2883
- def create_oval(self, *args, **kw):
2884
- """Create oval with coordinates x1,y1,x2,y2."""
2885
- return self._create('oval', args, kw)
2886
-
2887
- def create_polygon(self, *args, **kw):
2888
- """Create polygon with coordinates x1,y1,...,xn,yn."""
2889
- return self._create('polygon', args, kw)
2890
-
2891
- def create_rectangle(self, *args, **kw):
2892
- """Create rectangle with coordinates x1,y1,x2,y2."""
2893
- return self._create('rectangle', args, kw)
2894
-
2895
- def create_text(self, *args, **kw):
2896
- """Create text with coordinates x1,y1."""
2897
- return self._create('text', args, kw)
2898
-
2899
- def create_window(self, *args, **kw):
2900
- """Create window with coordinates x1,y1,x2,y2."""
2901
- return self._create('window', args, kw)
2902
-
2903
- def dchars(self, *args):
2904
- """Delete characters of text items identified by tag or id in ARGS (possibly
2905
- several times) from FIRST to LAST character (including)."""
2906
- self.tk.call((self._w, 'dchars') + args)
2907
-
2908
- def delete(self, *args):
2909
- """Delete items identified by all tag or ids contained in ARGS."""
2910
- self.tk.call((self._w, 'delete') + args)
2911
-
2912
- def dtag(self, *args):
2913
- """Delete tag or id given as last arguments in ARGS from items
2914
- identified by first argument in ARGS."""
2915
- self.tk.call((self._w, 'dtag') + args)
2916
-
2917
- def find(self, *args):
2918
- """Internal function."""
2919
- return self._getints(
2920
- self.tk.call((self._w, 'find') + args)) or ()
2921
-
2922
- def find_above(self, tagOrId):
2923
- """Return items above TAGORID."""
2924
- return self.find('above', tagOrId)
2925
-
2926
- def find_all(self):
2927
- """Return all items."""
2928
- return self.find('all')
2929
-
2930
- def find_below(self, tagOrId):
2931
- """Return all items below TAGORID."""
2932
- return self.find('below', tagOrId)
2933
-
2934
- def find_closest(self, x, y, halo=None, start=None):
2935
- """Return item which is closest to pixel at X, Y.
2936
- If several match take the top-most.
2937
- All items closer than HALO are considered overlapping (all are
2938
- closest). If START is specified the next below this tag is taken."""
2939
- return self.find('closest', x, y, halo, start)
2940
-
2941
- def find_enclosed(self, x1, y1, x2, y2):
2942
- """Return all items in rectangle defined
2943
- by X1,Y1,X2,Y2."""
2944
- return self.find('enclosed', x1, y1, x2, y2)
2945
-
2946
- def find_overlapping(self, x1, y1, x2, y2):
2947
- """Return all items which overlap the rectangle
2948
- defined by X1,Y1,X2,Y2."""
2949
- return self.find('overlapping', x1, y1, x2, y2)
2950
-
2951
- def find_withtag(self, tagOrId):
2952
- """Return all items with TAGORID."""
2953
- return self.find('withtag', tagOrId)
2954
-
2955
- def focus(self, *args):
2956
- """Set focus to the first item specified in ARGS."""
2957
- return self.tk.call((self._w, 'focus') + args)
2958
-
2959
- def gettags(self, *args):
2960
- """Return tags associated with the first item specified in ARGS."""
2961
- return self.tk.splitlist(
2962
- self.tk.call((self._w, 'gettags') + args))
2963
-
2964
- def icursor(self, *args):
2965
- """Set cursor at position POS in the item identified by TAGORID.
2966
- In ARGS TAGORID must be first."""
2967
- self.tk.call((self._w, 'icursor') + args)
2968
-
2969
- def index(self, *args):
2970
- """Return position of cursor as integer in item specified in ARGS."""
2971
- return self.tk.getint(self.tk.call((self._w, 'index') + args))
2972
-
2973
- def insert(self, *args):
2974
- """Insert TEXT in item TAGORID at position POS. ARGS must
2975
- be TAGORID POS TEXT."""
2976
- self.tk.call((self._w, 'insert') + args)
2977
-
2978
- def itemcget(self, tagOrId, option):
2979
- """Return the resource value for an OPTION for item TAGORID."""
2980
- return self.tk.call(
2981
- (self._w, 'itemcget') + (tagOrId, '-'+option))
2982
-
2983
- def itemconfigure(self, tagOrId, cnf=None, **kw):
2984
- """Configure resources of an item TAGORID.
2985
-
2986
- The values for resources are specified as keyword
2987
- arguments. To get an overview about
2988
- the allowed keyword arguments call the method without arguments.
2989
- """
2990
- return self._configure(('itemconfigure', tagOrId), cnf, kw)
2991
-
2992
- itemconfig = itemconfigure
2993
-
2994
- # lower, tkraise/lift hide Misc.lower, Misc.tkraise/lift,
2995
- # so the preferred name for them is tag_lower, tag_raise
2996
- # (similar to tag_bind, and similar to the Text widget);
2997
- # unfortunately can't delete the old ones yet (maybe in 1.6)
2998
- def tag_lower(self, *args):
2999
- """Lower an item TAGORID given in ARGS
3000
- (optional below another item)."""
3001
- self.tk.call((self._w, 'lower') + args)
3002
-
3003
- lower = tag_lower
3004
-
3005
- def move(self, *args):
3006
- """Move an item TAGORID given in ARGS."""
3007
- self.tk.call((self._w, 'move') + args)
3008
-
3009
- def moveto(self, tagOrId, x='', y=''):
3010
- """Move the items given by TAGORID in the canvas coordinate
3011
- space so that the first coordinate pair of the bottommost
3012
- item with tag TAGORID is located at position (X,Y).
3013
- X and Y may be the empty string, in which case the
3014
- corresponding coordinate will be unchanged. All items matching
3015
- TAGORID remain in the same positions relative to each other."""
3016
- self.tk.call(self._w, 'moveto', tagOrId, x, y)
3017
-
3018
- def postscript(self, cnf={}, **kw):
3019
- """Print the contents of the canvas to a postscript
3020
- file. Valid options: colormap, colormode, file, fontmap,
3021
- height, pageanchor, pageheight, pagewidth, pagex, pagey,
3022
- rotate, width, x, y."""
3023
- return self.tk.call((self._w, 'postscript') +
3024
- self._options(cnf, kw))
3025
-
3026
- def tag_raise(self, *args):
3027
- """Raise an item TAGORID given in ARGS
3028
- (optional above another item)."""
3029
- self.tk.call((self._w, 'raise') + args)
3030
-
3031
- lift = tkraise = tag_raise
3032
-
3033
- def scale(self, *args):
3034
- """Scale item TAGORID with XORIGIN, YORIGIN, XSCALE, YSCALE."""
3035
- self.tk.call((self._w, 'scale') + args)
3036
-
3037
- def scan_mark(self, x, y):
3038
- """Remember the current X, Y coordinates."""
3039
- self.tk.call(self._w, 'scan', 'mark', x, y)
3040
-
3041
- def scan_dragto(self, x, y, gain=10):
3042
- """Adjust the view of the canvas to GAIN times the
3043
- difference between X and Y and the coordinates given in
3044
- scan_mark."""
3045
- self.tk.call(self._w, 'scan', 'dragto', x, y, gain)
3046
-
3047
- def select_adjust(self, tagOrId, index):
3048
- """Adjust the end of the selection near the cursor of an item TAGORID to index."""
3049
- self.tk.call(self._w, 'select', 'adjust', tagOrId, index)
3050
-
3051
- def select_clear(self):
3052
- """Clear the selection if it is in this widget."""
3053
- self.tk.call(self._w, 'select', 'clear')
3054
-
3055
- def select_from(self, tagOrId, index):
3056
- """Set the fixed end of a selection in item TAGORID to INDEX."""
3057
- self.tk.call(self._w, 'select', 'from', tagOrId, index)
3058
-
3059
- def select_item(self):
3060
- """Return the item which has the selection."""
3061
- return self.tk.call(self._w, 'select', 'item') or None
3062
-
3063
- def select_to(self, tagOrId, index):
3064
- """Set the variable end of a selection in item TAGORID to INDEX."""
3065
- self.tk.call(self._w, 'select', 'to', tagOrId, index)
3066
-
3067
- def type(self, tagOrId):
3068
- """Return the type of the item TAGORID."""
3069
- return self.tk.call(self._w, 'type', tagOrId) or None
3070
-
3071
-
3072
- _checkbutton_count = 0
3073
-
3074
- class Checkbutton(Widget):
3075
- """Checkbutton widget which is either in on- or off-state."""
3076
-
3077
- def __init__(self, master=None, cnf={}, **kw):
3078
- """Construct a checkbutton widget with the parent MASTER.
3079
-
3080
- Valid resource names: activebackground, activeforeground, anchor,
3081
- background, bd, bg, bitmap, borderwidth, command, cursor,
3082
- disabledforeground, fg, font, foreground, height,
3083
- highlightbackground, highlightcolor, highlightthickness, image,
3084
- indicatoron, justify, offvalue, onvalue, padx, pady, relief,
3085
- selectcolor, selectimage, state, takefocus, text, textvariable,
3086
- underline, variable, width, wraplength."""
3087
- Widget.__init__(self, master, 'checkbutton', cnf, kw)
3088
-
3089
- def _setup(self, master, cnf):
3090
- # Because Checkbutton defaults to a variable with the same name as
3091
- # the widget, Checkbutton default names must be globally unique,
3092
- # not just unique within the parent widget.
3093
- if not cnf.get('name'):
3094
- global _checkbutton_count
3095
- name = self.__class__.__name__.lower()
3096
- _checkbutton_count += 1
3097
- # To avoid collisions with ttk.Checkbutton, use the different
3098
- # name template.
3099
- cnf['name'] = f'!{name}-{_checkbutton_count}'
3100
- super()._setup(master, cnf)
3101
-
3102
- def deselect(self):
3103
- """Put the button in off-state."""
3104
- self.tk.call(self._w, 'deselect')
3105
-
3106
- def flash(self):
3107
- """Flash the button."""
3108
- self.tk.call(self._w, 'flash')
3109
-
3110
- def invoke(self):
3111
- """Toggle the button and invoke a command if given as resource."""
3112
- return self.tk.call(self._w, 'invoke')
3113
-
3114
- def select(self):
3115
- """Put the button in on-state."""
3116
- self.tk.call(self._w, 'select')
3117
-
3118
- def toggle(self):
3119
- """Toggle the button."""
3120
- self.tk.call(self._w, 'toggle')
3121
-
3122
-
3123
- class Entry(Widget, XView):
3124
- """Entry widget which allows displaying simple text."""
3125
-
3126
- def __init__(self, master=None, cnf={}, **kw):
3127
- """Construct an entry widget with the parent MASTER.
3128
-
3129
- Valid resource names: background, bd, bg, borderwidth, cursor,
3130
- exportselection, fg, font, foreground, highlightbackground,
3131
- highlightcolor, highlightthickness, insertbackground,
3132
- insertborderwidth, insertofftime, insertontime, insertwidth,
3133
- invalidcommand, invcmd, justify, relief, selectbackground,
3134
- selectborderwidth, selectforeground, show, state, takefocus,
3135
- textvariable, validate, validatecommand, vcmd, width,
3136
- xscrollcommand."""
3137
- Widget.__init__(self, master, 'entry', cnf, kw)
3138
-
3139
- def delete(self, first, last=None):
3140
- """Delete text from FIRST to LAST (not included)."""
3141
- self.tk.call(self._w, 'delete', first, last)
3142
-
3143
- def get(self):
3144
- """Return the text."""
3145
- return self.tk.call(self._w, 'get')
3146
-
3147
- def icursor(self, index):
3148
- """Insert cursor at INDEX."""
3149
- self.tk.call(self._w, 'icursor', index)
3150
-
3151
- def index(self, index):
3152
- """Return position of cursor."""
3153
- return self.tk.getint(self.tk.call(
3154
- self._w, 'index', index))
3155
-
3156
- def insert(self, index, string):
3157
- """Insert STRING at INDEX."""
3158
- self.tk.call(self._w, 'insert', index, string)
3159
-
3160
- def scan_mark(self, x):
3161
- """Remember the current X, Y coordinates."""
3162
- self.tk.call(self._w, 'scan', 'mark', x)
3163
-
3164
- def scan_dragto(self, x):
3165
- """Adjust the view of the canvas to 10 times the
3166
- difference between X and Y and the coordinates given in
3167
- scan_mark."""
3168
- self.tk.call(self._w, 'scan', 'dragto', x)
3169
-
3170
- def selection_adjust(self, index):
3171
- """Adjust the end of the selection near the cursor to INDEX."""
3172
- self.tk.call(self._w, 'selection', 'adjust', index)
3173
-
3174
- select_adjust = selection_adjust
3175
-
3176
- def selection_clear(self):
3177
- """Clear the selection if it is in this widget."""
3178
- self.tk.call(self._w, 'selection', 'clear')
3179
-
3180
- select_clear = selection_clear
3181
-
3182
- def selection_from(self, index):
3183
- """Set the fixed end of a selection to INDEX."""
3184
- self.tk.call(self._w, 'selection', 'from', index)
3185
-
3186
- select_from = selection_from
3187
-
3188
- def selection_present(self):
3189
- """Return True if there are characters selected in the entry, False
3190
- otherwise."""
3191
- return self.tk.getboolean(
3192
- self.tk.call(self._w, 'selection', 'present'))
3193
-
3194
- select_present = selection_present
3195
-
3196
- def selection_range(self, start, end):
3197
- """Set the selection from START to END (not included)."""
3198
- self.tk.call(self._w, 'selection', 'range', start, end)
3199
-
3200
- select_range = selection_range
3201
-
3202
- def selection_to(self, index):
3203
- """Set the variable end of a selection to INDEX."""
3204
- self.tk.call(self._w, 'selection', 'to', index)
3205
-
3206
- select_to = selection_to
3207
-
3208
-
3209
- class Frame(Widget):
3210
- """Frame widget which may contain other widgets and can have a 3D border."""
3211
-
3212
- def __init__(self, master=None, cnf={}, **kw):
3213
- """Construct a frame widget with the parent MASTER.
3214
-
3215
- Valid resource names: background, bd, bg, borderwidth, class,
3216
- colormap, container, cursor, height, highlightbackground,
3217
- highlightcolor, highlightthickness, relief, takefocus, visual, width."""
3218
- cnf = _cnfmerge((cnf, kw))
3219
- extra = ()
3220
- if 'class_' in cnf:
3221
- extra = ('-class', cnf['class_'])
3222
- del cnf['class_']
3223
- elif 'class' in cnf:
3224
- extra = ('-class', cnf['class'])
3225
- del cnf['class']
3226
- Widget.__init__(self, master, 'frame', cnf, {}, extra)
3227
-
3228
-
3229
- class Label(Widget):
3230
- """Label widget which can display text and bitmaps."""
3231
-
3232
- def __init__(self, master=None, cnf={}, **kw):
3233
- """Construct a label widget with the parent MASTER.
3234
-
3235
- STANDARD OPTIONS
3236
-
3237
- activebackground, activeforeground, anchor,
3238
- background, bitmap, borderwidth, cursor,
3239
- disabledforeground, font, foreground,
3240
- highlightbackground, highlightcolor,
3241
- highlightthickness, image, justify,
3242
- padx, pady, relief, takefocus, text,
3243
- textvariable, underline, wraplength
3244
-
3245
- WIDGET-SPECIFIC OPTIONS
3246
-
3247
- height, state, width
3248
-
3249
- """
3250
- Widget.__init__(self, master, 'label', cnf, kw)
3251
-
3252
-
3253
- class Listbox(Widget, XView, YView):
3254
- """Listbox widget which can display a list of strings."""
3255
-
3256
- def __init__(self, master=None, cnf={}, **kw):
3257
- """Construct a listbox widget with the parent MASTER.
3258
-
3259
- Valid resource names: background, bd, bg, borderwidth, cursor,
3260
- exportselection, fg, font, foreground, height, highlightbackground,
3261
- highlightcolor, highlightthickness, relief, selectbackground,
3262
- selectborderwidth, selectforeground, selectmode, setgrid, takefocus,
3263
- width, xscrollcommand, yscrollcommand, listvariable."""
3264
- Widget.__init__(self, master, 'listbox', cnf, kw)
3265
-
3266
- def activate(self, index):
3267
- """Activate item identified by INDEX."""
3268
- self.tk.call(self._w, 'activate', index)
3269
-
3270
- def bbox(self, index):
3271
- """Return a tuple of X1,Y1,X2,Y2 coordinates for a rectangle
3272
- which encloses the item identified by the given index."""
3273
- return self._getints(self.tk.call(self._w, 'bbox', index)) or None
3274
-
3275
- def curselection(self):
3276
- """Return the indices of currently selected item."""
3277
- return self._getints(self.tk.call(self._w, 'curselection')) or ()
3278
-
3279
- def delete(self, first, last=None):
3280
- """Delete items from FIRST to LAST (included)."""
3281
- self.tk.call(self._w, 'delete', first, last)
3282
-
3283
- def get(self, first, last=None):
3284
- """Get list of items from FIRST to LAST (included)."""
3285
- if last is not None:
3286
- return self.tk.splitlist(self.tk.call(
3287
- self._w, 'get', first, last))
3288
- else:
3289
- return self.tk.call(self._w, 'get', first)
3290
-
3291
- def index(self, index):
3292
- """Return index of item identified with INDEX."""
3293
- i = self.tk.call(self._w, 'index', index)
3294
- if i == 'none': return None
3295
- return self.tk.getint(i)
3296
-
3297
- def insert(self, index, *elements):
3298
- """Insert ELEMENTS at INDEX."""
3299
- self.tk.call((self._w, 'insert', index) + elements)
3300
-
3301
- def nearest(self, y):
3302
- """Get index of item which is nearest to y coordinate Y."""
3303
- return self.tk.getint(self.tk.call(
3304
- self._w, 'nearest', y))
3305
-
3306
- def scan_mark(self, x, y):
3307
- """Remember the current X, Y coordinates."""
3308
- self.tk.call(self._w, 'scan', 'mark', x, y)
3309
-
3310
- def scan_dragto(self, x, y):
3311
- """Adjust the view of the listbox to 10 times the
3312
- difference between X and Y and the coordinates given in
3313
- scan_mark."""
3314
- self.tk.call(self._w, 'scan', 'dragto', x, y)
3315
-
3316
- def see(self, index):
3317
- """Scroll such that INDEX is visible."""
3318
- self.tk.call(self._w, 'see', index)
3319
-
3320
- def selection_anchor(self, index):
3321
- """Set the fixed end oft the selection to INDEX."""
3322
- self.tk.call(self._w, 'selection', 'anchor', index)
3323
-
3324
- select_anchor = selection_anchor
3325
-
3326
- def selection_clear(self, first, last=None):
3327
- """Clear the selection from FIRST to LAST (included)."""
3328
- self.tk.call(self._w,
3329
- 'selection', 'clear', first, last)
3330
-
3331
- select_clear = selection_clear
3332
-
3333
- def selection_includes(self, index):
3334
- """Return True if INDEX is part of the selection."""
3335
- return self.tk.getboolean(self.tk.call(
3336
- self._w, 'selection', 'includes', index))
3337
-
3338
- select_includes = selection_includes
3339
-
3340
- def selection_set(self, first, last=None):
3341
- """Set the selection from FIRST to LAST (included) without
3342
- changing the currently selected elements."""
3343
- self.tk.call(self._w, 'selection', 'set', first, last)
3344
-
3345
- select_set = selection_set
3346
-
3347
- def size(self):
3348
- """Return the number of elements in the listbox."""
3349
- return self.tk.getint(self.tk.call(self._w, 'size'))
3350
-
3351
- def itemcget(self, index, option):
3352
- """Return the resource value for an ITEM and an OPTION."""
3353
- return self.tk.call(
3354
- (self._w, 'itemcget') + (index, '-'+option))
3355
-
3356
- def itemconfigure(self, index, cnf=None, **kw):
3357
- """Configure resources of an ITEM.
3358
-
3359
- The values for resources are specified as keyword arguments.
3360
- To get an overview about the allowed keyword arguments
3361
- call the method without arguments.
3362
- Valid resource names: background, bg, foreground, fg,
3363
- selectbackground, selectforeground."""
3364
- return self._configure(('itemconfigure', index), cnf, kw)
3365
-
3366
- itemconfig = itemconfigure
3367
-
3368
-
3369
- class Menu(Widget):
3370
- """Menu widget which allows displaying menu bars, pull-down menus and pop-up menus."""
3371
-
3372
- def __init__(self, master=None, cnf={}, **kw):
3373
- """Construct menu widget with the parent MASTER.
3374
-
3375
- Valid resource names: activebackground, activeborderwidth,
3376
- activeforeground, background, bd, bg, borderwidth, cursor,
3377
- disabledforeground, fg, font, foreground, postcommand, relief,
3378
- selectcolor, takefocus, tearoff, tearoffcommand, title, type."""
3379
- Widget.__init__(self, master, 'menu', cnf, kw)
3380
-
3381
- def tk_popup(self, x, y, entry=""):
3382
- """Post the menu at position X,Y with entry ENTRY."""
3383
- self.tk.call('tk_popup', self._w, x, y, entry)
3384
-
3385
- def activate(self, index):
3386
- """Activate entry at INDEX."""
3387
- self.tk.call(self._w, 'activate', index)
3388
-
3389
- def add(self, itemType, cnf={}, **kw):
3390
- """Internal function."""
3391
- self.tk.call((self._w, 'add', itemType) +
3392
- self._options(cnf, kw))
3393
-
3394
- def add_cascade(self, cnf={}, **kw):
3395
- """Add hierarchical menu item."""
3396
- self.add('cascade', cnf or kw)
3397
-
3398
- def add_checkbutton(self, cnf={}, **kw):
3399
- """Add checkbutton menu item."""
3400
- self.add('checkbutton', cnf or kw)
3401
-
3402
- def add_command(self, cnf={}, **kw):
3403
- """Add command menu item."""
3404
- self.add('command', cnf or kw)
3405
-
3406
- def add_radiobutton(self, cnf={}, **kw):
3407
- """Add radio menu item."""
3408
- self.add('radiobutton', cnf or kw)
3409
-
3410
- def add_separator(self, cnf={}, **kw):
3411
- """Add separator."""
3412
- self.add('separator', cnf or kw)
3413
-
3414
- def insert(self, index, itemType, cnf={}, **kw):
3415
- """Internal function."""
3416
- self.tk.call((self._w, 'insert', index, itemType) +
3417
- self._options(cnf, kw))
3418
-
3419
- def insert_cascade(self, index, cnf={}, **kw):
3420
- """Add hierarchical menu item at INDEX."""
3421
- self.insert(index, 'cascade', cnf or kw)
3422
-
3423
- def insert_checkbutton(self, index, cnf={}, **kw):
3424
- """Add checkbutton menu item at INDEX."""
3425
- self.insert(index, 'checkbutton', cnf or kw)
3426
-
3427
- def insert_command(self, index, cnf={}, **kw):
3428
- """Add command menu item at INDEX."""
3429
- self.insert(index, 'command', cnf or kw)
3430
-
3431
- def insert_radiobutton(self, index, cnf={}, **kw):
3432
- """Add radio menu item at INDEX."""
3433
- self.insert(index, 'radiobutton', cnf or kw)
3434
-
3435
- def insert_separator(self, index, cnf={}, **kw):
3436
- """Add separator at INDEX."""
3437
- self.insert(index, 'separator', cnf or kw)
3438
-
3439
- def delete(self, index1, index2=None):
3440
- """Delete menu items between INDEX1 and INDEX2 (included)."""
3441
- if index2 is None:
3442
- index2 = index1
3443
-
3444
- num_index1, num_index2 = self.index(index1), self.index(index2)
3445
- if (num_index1 is None) or (num_index2 is None):
3446
- num_index1, num_index2 = 0, -1
3447
-
3448
- for i in range(num_index1, num_index2 + 1):
3449
- if 'command' in self.entryconfig(i):
3450
- c = str(self.entrycget(i, 'command'))
3451
- if c:
3452
- self.deletecommand(c)
3453
- self.tk.call(self._w, 'delete', index1, index2)
3454
-
3455
- def entrycget(self, index, option):
3456
- """Return the resource value of a menu item for OPTION at INDEX."""
3457
- return self.tk.call(self._w, 'entrycget', index, '-' + option)
3458
-
3459
- def entryconfigure(self, index, cnf=None, **kw):
3460
- """Configure a menu item at INDEX."""
3461
- return self._configure(('entryconfigure', index), cnf, kw)
3462
-
3463
- entryconfig = entryconfigure
3464
-
3465
- def index(self, index):
3466
- """Return the index of a menu item identified by INDEX."""
3467
- i = self.tk.call(self._w, 'index', index)
3468
- return None if i in ('', 'none') else self.tk.getint(i) # GH-103685.
3469
-
3470
- def invoke(self, index):
3471
- """Invoke a menu item identified by INDEX and execute
3472
- the associated command."""
3473
- return self.tk.call(self._w, 'invoke', index)
3474
-
3475
- def post(self, x, y):
3476
- """Display a menu at position X,Y."""
3477
- self.tk.call(self._w, 'post', x, y)
3478
-
3479
- def type(self, index):
3480
- """Return the type of the menu item at INDEX."""
3481
- return self.tk.call(self._w, 'type', index)
3482
-
3483
- def unpost(self):
3484
- """Unmap a menu."""
3485
- self.tk.call(self._w, 'unpost')
3486
-
3487
- def xposition(self, index): # new in Tk 8.5
3488
- """Return the x-position of the leftmost pixel of the menu item
3489
- at INDEX."""
3490
- return self.tk.getint(self.tk.call(self._w, 'xposition', index))
3491
-
3492
- def yposition(self, index):
3493
- """Return the y-position of the topmost pixel of the menu item at INDEX."""
3494
- return self.tk.getint(self.tk.call(
3495
- self._w, 'yposition', index))
3496
-
3497
-
3498
- class Menubutton(Widget):
3499
- """Menubutton widget, obsolete since Tk8.0."""
3500
-
3501
- def __init__(self, master=None, cnf={}, **kw):
3502
- Widget.__init__(self, master, 'menubutton', cnf, kw)
3503
-
3504
-
3505
- class Message(Widget):
3506
- """Message widget to display multiline text. Obsolete since Label does it too."""
3507
-
3508
- def __init__(self, master=None, cnf={}, **kw):
3509
- Widget.__init__(self, master, 'message', cnf, kw)
3510
-
3511
-
3512
- class Radiobutton(Widget):
3513
- """Radiobutton widget which shows only one of several buttons in on-state."""
3514
-
3515
- def __init__(self, master=None, cnf={}, **kw):
3516
- """Construct a radiobutton widget with the parent MASTER.
3517
-
3518
- Valid resource names: activebackground, activeforeground, anchor,
3519
- background, bd, bg, bitmap, borderwidth, command, cursor,
3520
- disabledforeground, fg, font, foreground, height,
3521
- highlightbackground, highlightcolor, highlightthickness, image,
3522
- indicatoron, justify, padx, pady, relief, selectcolor, selectimage,
3523
- state, takefocus, text, textvariable, underline, value, variable,
3524
- width, wraplength."""
3525
- Widget.__init__(self, master, 'radiobutton', cnf, kw)
3526
-
3527
- def deselect(self):
3528
- """Put the button in off-state."""
3529
-
3530
- self.tk.call(self._w, 'deselect')
3531
-
3532
- def flash(self):
3533
- """Flash the button."""
3534
- self.tk.call(self._w, 'flash')
3535
-
3536
- def invoke(self):
3537
- """Toggle the button and invoke a command if given as resource."""
3538
- return self.tk.call(self._w, 'invoke')
3539
-
3540
- def select(self):
3541
- """Put the button in on-state."""
3542
- self.tk.call(self._w, 'select')
3543
-
3544
-
3545
- class Scale(Widget):
3546
- """Scale widget which can display a numerical scale."""
3547
-
3548
- def __init__(self, master=None, cnf={}, **kw):
3549
- """Construct a scale widget with the parent MASTER.
3550
-
3551
- Valid resource names: activebackground, background, bigincrement, bd,
3552
- bg, borderwidth, command, cursor, digits, fg, font, foreground, from,
3553
- highlightbackground, highlightcolor, highlightthickness, label,
3554
- length, orient, relief, repeatdelay, repeatinterval, resolution,
3555
- showvalue, sliderlength, sliderrelief, state, takefocus,
3556
- tickinterval, to, troughcolor, variable, width."""
3557
- Widget.__init__(self, master, 'scale', cnf, kw)
3558
-
3559
- def get(self):
3560
- """Get the current value as integer or float."""
3561
- value = self.tk.call(self._w, 'get')
3562
- try:
3563
- return self.tk.getint(value)
3564
- except (ValueError, TypeError, TclError):
3565
- return self.tk.getdouble(value)
3566
-
3567
- def set(self, value):
3568
- """Set the value to VALUE."""
3569
- self.tk.call(self._w, 'set', value)
3570
-
3571
- def coords(self, value=None):
3572
- """Return a tuple (X,Y) of the point along the centerline of the
3573
- trough that corresponds to VALUE or the current value if None is
3574
- given."""
3575
-
3576
- return self._getints(self.tk.call(self._w, 'coords', value))
3577
-
3578
- def identify(self, x, y):
3579
- """Return where the point X,Y lies. Valid return values are "slider",
3580
- "though1" and "though2"."""
3581
- return self.tk.call(self._w, 'identify', x, y)
3582
-
3583
-
3584
- class Scrollbar(Widget):
3585
- """Scrollbar widget which displays a slider at a certain position."""
3586
-
3587
- def __init__(self, master=None, cnf={}, **kw):
3588
- """Construct a scrollbar widget with the parent MASTER.
3589
-
3590
- Valid resource names: activebackground, activerelief,
3591
- background, bd, bg, borderwidth, command, cursor,
3592
- elementborderwidth, highlightbackground,
3593
- highlightcolor, highlightthickness, jump, orient,
3594
- relief, repeatdelay, repeatinterval, takefocus,
3595
- troughcolor, width."""
3596
- Widget.__init__(self, master, 'scrollbar', cnf, kw)
3597
-
3598
- def activate(self, index=None):
3599
- """Marks the element indicated by index as active.
3600
- The only index values understood by this method are "arrow1",
3601
- "slider", or "arrow2". If any other value is specified then no
3602
- element of the scrollbar will be active. If index is not specified,
3603
- the method returns the name of the element that is currently active,
3604
- or None if no element is active."""
3605
- return self.tk.call(self._w, 'activate', index) or None
3606
-
3607
- def delta(self, deltax, deltay):
3608
- """Return the fractional change of the scrollbar setting if it
3609
- would be moved by DELTAX or DELTAY pixels."""
3610
- return self.tk.getdouble(
3611
- self.tk.call(self._w, 'delta', deltax, deltay))
3612
-
3613
- def fraction(self, x, y):
3614
- """Return the fractional value which corresponds to a slider
3615
- position of X,Y."""
3616
- return self.tk.getdouble(self.tk.call(self._w, 'fraction', x, y))
3617
-
3618
- def identify(self, x, y):
3619
- """Return the element under position X,Y as one of
3620
- "arrow1","slider","arrow2" or ""."""
3621
- return self.tk.call(self._w, 'identify', x, y)
3622
-
3623
- def get(self):
3624
- """Return the current fractional values (upper and lower end)
3625
- of the slider position."""
3626
- return self._getdoubles(self.tk.call(self._w, 'get'))
3627
-
3628
- def set(self, first, last):
3629
- """Set the fractional values of the slider position (upper and
3630
- lower ends as value between 0 and 1)."""
3631
- self.tk.call(self._w, 'set', first, last)
3632
-
3633
-
3634
- class Text(Widget, XView, YView):
3635
- """Text widget which can display text in various forms."""
3636
-
3637
- def __init__(self, master=None, cnf={}, **kw):
3638
- """Construct a text widget with the parent MASTER.
3639
-
3640
- STANDARD OPTIONS
3641
-
3642
- background, borderwidth, cursor,
3643
- exportselection, font, foreground,
3644
- highlightbackground, highlightcolor,
3645
- highlightthickness, insertbackground,
3646
- insertborderwidth, insertofftime,
3647
- insertontime, insertwidth, padx, pady,
3648
- relief, selectbackground,
3649
- selectborderwidth, selectforeground,
3650
- setgrid, takefocus,
3651
- xscrollcommand, yscrollcommand,
3652
-
3653
- WIDGET-SPECIFIC OPTIONS
3654
-
3655
- autoseparators, height, maxundo,
3656
- spacing1, spacing2, spacing3,
3657
- state, tabs, undo, width, wrap,
3658
-
3659
- """
3660
- Widget.__init__(self, master, 'text', cnf, kw)
3661
-
3662
- def bbox(self, index):
3663
- """Return a tuple of (x,y,width,height) which gives the bounding
3664
- box of the visible part of the character at the given index."""
3665
- return self._getints(
3666
- self.tk.call(self._w, 'bbox', index)) or None
3667
-
3668
- def compare(self, index1, op, index2):
3669
- """Return whether between index INDEX1 and index INDEX2 the
3670
- relation OP is satisfied. OP is one of <, <=, ==, >=, >, or !=."""
3671
- return self.tk.getboolean(self.tk.call(
3672
- self._w, 'compare', index1, op, index2))
3673
-
3674
- def count(self, index1, index2, *args): # new in Tk 8.5
3675
- """Counts the number of relevant things between the two indices.
3676
- If index1 is after index2, the result will be a negative number
3677
- (and this holds for each of the possible options).
3678
-
3679
- The actual items which are counted depends on the options given by
3680
- args. The result is a list of integers, one for the result of each
3681
- counting option given. Valid counting options are "chars",
3682
- "displaychars", "displayindices", "displaylines", "indices",
3683
- "lines", "xpixels" and "ypixels". There is an additional possible
3684
- option "update", which if given then all subsequent options ensure
3685
- that any possible out of date information is recalculated."""
3686
- args = ['-%s' % arg for arg in args]
3687
- args += [index1, index2]
3688
- res = self.tk.call(self._w, 'count', *args) or None
3689
- if res is not None and len(args) <= 3:
3690
- return (res, )
3691
- else:
3692
- return res
3693
-
3694
- def debug(self, boolean=None):
3695
- """Turn on the internal consistency checks of the B-Tree inside the text
3696
- widget according to BOOLEAN."""
3697
- if boolean is None:
3698
- return self.tk.getboolean(self.tk.call(self._w, 'debug'))
3699
- self.tk.call(self._w, 'debug', boolean)
3700
-
3701
- def delete(self, index1, index2=None):
3702
- """Delete the characters between INDEX1 and INDEX2 (not included)."""
3703
- self.tk.call(self._w, 'delete', index1, index2)
3704
-
3705
- def dlineinfo(self, index):
3706
- """Return tuple (x,y,width,height,baseline) giving the bounding box
3707
- and baseline position of the visible part of the line containing
3708
- the character at INDEX."""
3709
- return self._getints(self.tk.call(self._w, 'dlineinfo', index))
3710
-
3711
- def dump(self, index1, index2=None, command=None, **kw):
3712
- """Return the contents of the widget between index1 and index2.
3713
-
3714
- The type of contents returned in filtered based on the keyword
3715
- parameters; if 'all', 'image', 'mark', 'tag', 'text', or 'window' are
3716
- given and true, then the corresponding items are returned. The result
3717
- is a list of triples of the form (key, value, index). If none of the
3718
- keywords are true then 'all' is used by default.
3719
-
3720
- If the 'command' argument is given, it is called once for each element
3721
- of the list of triples, with the values of each triple serving as the
3722
- arguments to the function. In this case the list is not returned."""
3723
- args = []
3724
- func_name = None
3725
- result = None
3726
- if not command:
3727
- # Never call the dump command without the -command flag, since the
3728
- # output could involve Tcl quoting and would be a pain to parse
3729
- # right. Instead just set the command to build a list of triples
3730
- # as if we had done the parsing.
3731
- result = []
3732
- def append_triple(key, value, index, result=result):
3733
- result.append((key, value, index))
3734
- command = append_triple
3735
- try:
3736
- if not isinstance(command, str):
3737
- func_name = command = self._register(command)
3738
- args += ["-command", command]
3739
- for key in kw:
3740
- if kw[key]: args.append("-" + key)
3741
- args.append(index1)
3742
- if index2:
3743
- args.append(index2)
3744
- self.tk.call(self._w, "dump", *args)
3745
- return result
3746
- finally:
3747
- if func_name:
3748
- self.deletecommand(func_name)
3749
-
3750
- ## new in tk8.4
3751
- def edit(self, *args):
3752
- """Internal method
3753
-
3754
- This method controls the undo mechanism and
3755
- the modified flag. The exact behavior of the
3756
- command depends on the option argument that
3757
- follows the edit argument. The following forms
3758
- of the command are currently supported:
3759
-
3760
- edit_modified, edit_redo, edit_reset, edit_separator
3761
- and edit_undo
3762
-
3763
- """
3764
- return self.tk.call(self._w, 'edit', *args)
3765
-
3766
- def edit_modified(self, arg=None):
3767
- """Get or Set the modified flag
3768
-
3769
- If arg is not specified, returns the modified
3770
- flag of the widget. The insert, delete, edit undo and
3771
- edit redo commands or the user can set or clear the
3772
- modified flag. If boolean is specified, sets the
3773
- modified flag of the widget to arg.
3774
- """
3775
- return self.edit("modified", arg)
3776
-
3777
- def edit_redo(self):
3778
- """Redo the last undone edit
3779
-
3780
- When the undo option is true, reapplies the last
3781
- undone edits provided no other edits were done since
3782
- then. Generates an error when the redo stack is empty.
3783
- Does nothing when the undo option is false.
3784
- """
3785
- return self.edit("redo")
3786
-
3787
- def edit_reset(self):
3788
- """Clears the undo and redo stacks
3789
- """
3790
- return self.edit("reset")
3791
-
3792
- def edit_separator(self):
3793
- """Inserts a separator (boundary) on the undo stack.
3794
-
3795
- Does nothing when the undo option is false
3796
- """
3797
- return self.edit("separator")
3798
-
3799
- def edit_undo(self):
3800
- """Undoes the last edit action
3801
-
3802
- If the undo option is true. An edit action is defined
3803
- as all the insert and delete commands that are recorded
3804
- on the undo stack in between two separators. Generates
3805
- an error when the undo stack is empty. Does nothing
3806
- when the undo option is false
3807
- """
3808
- return self.edit("undo")
3809
-
3810
- def get(self, index1, index2=None):
3811
- """Return the text from INDEX1 to INDEX2 (not included)."""
3812
- return self.tk.call(self._w, 'get', index1, index2)
3813
- # (Image commands are new in 8.0)
3814
-
3815
- def image_cget(self, index, option):
3816
- """Return the value of OPTION of an embedded image at INDEX."""
3817
- if option[:1] != "-":
3818
- option = "-" + option
3819
- if option[-1:] == "_":
3820
- option = option[:-1]
3821
- return self.tk.call(self._w, "image", "cget", index, option)
3822
-
3823
- def image_configure(self, index, cnf=None, **kw):
3824
- """Configure an embedded image at INDEX."""
3825
- return self._configure(('image', 'configure', index), cnf, kw)
3826
-
3827
- def image_create(self, index, cnf={}, **kw):
3828
- """Create an embedded image at INDEX."""
3829
- return self.tk.call(
3830
- self._w, "image", "create", index,
3831
- *self._options(cnf, kw))
3832
-
3833
- def image_names(self):
3834
- """Return all names of embedded images in this widget."""
3835
- return self.tk.call(self._w, "image", "names")
3836
-
3837
- def index(self, index):
3838
- """Return the index in the form line.char for INDEX."""
3839
- return str(self.tk.call(self._w, 'index', index))
3840
-
3841
- def insert(self, index, chars, *args):
3842
- """Insert CHARS before the characters at INDEX. An additional
3843
- tag can be given in ARGS. Additional CHARS and tags can follow in ARGS."""
3844
- self.tk.call((self._w, 'insert', index, chars) + args)
3845
-
3846
- def mark_gravity(self, markName, direction=None):
3847
- """Change the gravity of a mark MARKNAME to DIRECTION (LEFT or RIGHT).
3848
- Return the current value if None is given for DIRECTION."""
3849
- return self.tk.call(
3850
- (self._w, 'mark', 'gravity', markName, direction))
3851
-
3852
- def mark_names(self):
3853
- """Return all mark names."""
3854
- return self.tk.splitlist(self.tk.call(
3855
- self._w, 'mark', 'names'))
3856
-
3857
- def mark_set(self, markName, index):
3858
- """Set mark MARKNAME before the character at INDEX."""
3859
- self.tk.call(self._w, 'mark', 'set', markName, index)
3860
-
3861
- def mark_unset(self, *markNames):
3862
- """Delete all marks in MARKNAMES."""
3863
- self.tk.call((self._w, 'mark', 'unset') + markNames)
3864
-
3865
- def mark_next(self, index):
3866
- """Return the name of the next mark after INDEX."""
3867
- return self.tk.call(self._w, 'mark', 'next', index) or None
3868
-
3869
- def mark_previous(self, index):
3870
- """Return the name of the previous mark before INDEX."""
3871
- return self.tk.call(self._w, 'mark', 'previous', index) or None
3872
-
3873
- def peer_create(self, newPathName, cnf={}, **kw): # new in Tk 8.5
3874
- """Creates a peer text widget with the given newPathName, and any
3875
- optional standard configuration options. By default the peer will
3876
- have the same start and end line as the parent widget, but
3877
- these can be overridden with the standard configuration options."""
3878
- self.tk.call(self._w, 'peer', 'create', newPathName,
3879
- *self._options(cnf, kw))
3880
-
3881
- def peer_names(self): # new in Tk 8.5
3882
- """Returns a list of peers of this widget (this does not include
3883
- the widget itself)."""
3884
- return self.tk.splitlist(self.tk.call(self._w, 'peer', 'names'))
3885
-
3886
- def replace(self, index1, index2, chars, *args): # new in Tk 8.5
3887
- """Replaces the range of characters between index1 and index2 with
3888
- the given characters and tags specified by args.
3889
-
3890
- See the method insert for some more information about args, and the
3891
- method delete for information about the indices."""
3892
- self.tk.call(self._w, 'replace', index1, index2, chars, *args)
3893
-
3894
- def scan_mark(self, x, y):
3895
- """Remember the current X, Y coordinates."""
3896
- self.tk.call(self._w, 'scan', 'mark', x, y)
3897
-
3898
- def scan_dragto(self, x, y):
3899
- """Adjust the view of the text to 10 times the
3900
- difference between X and Y and the coordinates given in
3901
- scan_mark."""
3902
- self.tk.call(self._w, 'scan', 'dragto', x, y)
3903
-
3904
- def search(self, pattern, index, stopindex=None,
3905
- forwards=None, backwards=None, exact=None,
3906
- regexp=None, nocase=None, count=None, elide=None):
3907
- """Search PATTERN beginning from INDEX until STOPINDEX.
3908
- Return the index of the first character of a match or an
3909
- empty string."""
3910
- args = [self._w, 'search']
3911
- if forwards: args.append('-forwards')
3912
- if backwards: args.append('-backwards')
3913
- if exact: args.append('-exact')
3914
- if regexp: args.append('-regexp')
3915
- if nocase: args.append('-nocase')
3916
- if elide: args.append('-elide')
3917
- if count: args.append('-count'); args.append(count)
3918
- if pattern and pattern[0] == '-': args.append('--')
3919
- args.append(pattern)
3920
- args.append(index)
3921
- if stopindex: args.append(stopindex)
3922
- return str(self.tk.call(tuple(args)))
3923
-
3924
- def see(self, index):
3925
- """Scroll such that the character at INDEX is visible."""
3926
- self.tk.call(self._w, 'see', index)
3927
-
3928
- def tag_add(self, tagName, index1, *args):
3929
- """Add tag TAGNAME to all characters between INDEX1 and index2 in ARGS.
3930
- Additional pairs of indices may follow in ARGS."""
3931
- self.tk.call(
3932
- (self._w, 'tag', 'add', tagName, index1) + args)
3933
-
3934
- def tag_unbind(self, tagName, sequence, funcid=None):
3935
- """Unbind for all characters with TAGNAME for event SEQUENCE the
3936
- function identified with FUNCID."""
3937
- return self._unbind((self._w, 'tag', 'bind', tagName, sequence), funcid)
3938
-
3939
- def tag_bind(self, tagName, sequence, func, add=None):
3940
- """Bind to all characters with TAGNAME at event SEQUENCE a call to function FUNC.
3941
-
3942
- An additional boolean parameter ADD specifies whether FUNC will be
3943
- called additionally to the other bound function or whether it will
3944
- replace the previous function. See bind for the return value."""
3945
- return self._bind((self._w, 'tag', 'bind', tagName),
3946
- sequence, func, add)
3947
-
3948
- def _tag_bind(self, tagName, sequence=None, func=None, add=None):
3949
- # For tests only
3950
- return self._bind((self._w, 'tag', 'bind', tagName),
3951
- sequence, func, add)
3952
-
3953
- def tag_cget(self, tagName, option):
3954
- """Return the value of OPTION for tag TAGNAME."""
3955
- if option[:1] != '-':
3956
- option = '-' + option
3957
- if option[-1:] == '_':
3958
- option = option[:-1]
3959
- return self.tk.call(self._w, 'tag', 'cget', tagName, option)
3960
-
3961
- def tag_configure(self, tagName, cnf=None, **kw):
3962
- """Configure a tag TAGNAME."""
3963
- return self._configure(('tag', 'configure', tagName), cnf, kw)
3964
-
3965
- tag_config = tag_configure
3966
-
3967
- def tag_delete(self, *tagNames):
3968
- """Delete all tags in TAGNAMES."""
3969
- self.tk.call((self._w, 'tag', 'delete') + tagNames)
3970
-
3971
- def tag_lower(self, tagName, belowThis=None):
3972
- """Change the priority of tag TAGNAME such that it is lower
3973
- than the priority of BELOWTHIS."""
3974
- self.tk.call(self._w, 'tag', 'lower', tagName, belowThis)
3975
-
3976
- def tag_names(self, index=None):
3977
- """Return a list of all tag names."""
3978
- return self.tk.splitlist(
3979
- self.tk.call(self._w, 'tag', 'names', index))
3980
-
3981
- def tag_nextrange(self, tagName, index1, index2=None):
3982
- """Return a list of start and end index for the first sequence of
3983
- characters between INDEX1 and INDEX2 which all have tag TAGNAME.
3984
- The text is searched forward from INDEX1."""
3985
- return self.tk.splitlist(self.tk.call(
3986
- self._w, 'tag', 'nextrange', tagName, index1, index2))
3987
-
3988
- def tag_prevrange(self, tagName, index1, index2=None):
3989
- """Return a list of start and end index for the first sequence of
3990
- characters between INDEX1 and INDEX2 which all have tag TAGNAME.
3991
- The text is searched backwards from INDEX1."""
3992
- return self.tk.splitlist(self.tk.call(
3993
- self._w, 'tag', 'prevrange', tagName, index1, index2))
3994
-
3995
- def tag_raise(self, tagName, aboveThis=None):
3996
- """Change the priority of tag TAGNAME such that it is higher
3997
- than the priority of ABOVETHIS."""
3998
- self.tk.call(
3999
- self._w, 'tag', 'raise', tagName, aboveThis)
4000
-
4001
- def tag_ranges(self, tagName):
4002
- """Return a list of ranges of text which have tag TAGNAME."""
4003
- return self.tk.splitlist(self.tk.call(
4004
- self._w, 'tag', 'ranges', tagName))
4005
-
4006
- def tag_remove(self, tagName, index1, index2=None):
4007
- """Remove tag TAGNAME from all characters between INDEX1 and INDEX2."""
4008
- self.tk.call(
4009
- self._w, 'tag', 'remove', tagName, index1, index2)
4010
-
4011
- def window_cget(self, index, option):
4012
- """Return the value of OPTION of an embedded window at INDEX."""
4013
- if option[:1] != '-':
4014
- option = '-' + option
4015
- if option[-1:] == '_':
4016
- option = option[:-1]
4017
- return self.tk.call(self._w, 'window', 'cget', index, option)
4018
-
4019
- def window_configure(self, index, cnf=None, **kw):
4020
- """Configure an embedded window at INDEX."""
4021
- return self._configure(('window', 'configure', index), cnf, kw)
4022
-
4023
- window_config = window_configure
4024
-
4025
- def window_create(self, index, cnf={}, **kw):
4026
- """Create a window at INDEX."""
4027
- self.tk.call(
4028
- (self._w, 'window', 'create', index)
4029
- + self._options(cnf, kw))
4030
-
4031
- def window_names(self):
4032
- """Return all names of embedded windows in this widget."""
4033
- return self.tk.splitlist(
4034
- self.tk.call(self._w, 'window', 'names'))
4035
-
4036
- def yview_pickplace(self, *what):
4037
- """Obsolete function, use see."""
4038
- self.tk.call((self._w, 'yview', '-pickplace') + what)
4039
-
4040
-
4041
- class _setit:
4042
- """Internal class. It wraps the command in the widget OptionMenu."""
4043
-
4044
- def __init__(self, var, value, callback=None):
4045
- self.__value = value
4046
- self.__var = var
4047
- self.__callback = callback
4048
-
4049
- def __call__(self, *args):
4050
- self.__var.set(self.__value)
4051
- if self.__callback is not None:
4052
- self.__callback(self.__value, *args)
4053
-
4054
-
4055
- class OptionMenu(Menubutton):
4056
- """OptionMenu which allows the user to select a value from a menu."""
4057
-
4058
- def __init__(self, master, variable, value, *values, **kwargs):
4059
- """Construct an optionmenu widget with the parent MASTER, with
4060
- the resource textvariable set to VARIABLE, the initially selected
4061
- value VALUE, the other menu values VALUES and an additional
4062
- keyword argument command."""
4063
- kw = {"borderwidth": 2, "textvariable": variable,
4064
- "indicatoron": 1, "relief": RAISED, "anchor": "c",
4065
- "highlightthickness": 2}
4066
- Widget.__init__(self, master, "menubutton", kw)
4067
- self.widgetName = 'tk_optionMenu'
4068
- menu = self.__menu = Menu(self, name="menu", tearoff=0)
4069
- self.menuname = menu._w
4070
- # 'command' is the only supported keyword
4071
- callback = kwargs.get('command')
4072
- if 'command' in kwargs:
4073
- del kwargs['command']
4074
- if kwargs:
4075
- raise TclError('unknown option -'+next(iter(kwargs)))
4076
- menu.add_command(label=value,
4077
- command=_setit(variable, value, callback))
4078
- for v in values:
4079
- menu.add_command(label=v,
4080
- command=_setit(variable, v, callback))
4081
- self["menu"] = menu
4082
-
4083
- def __getitem__(self, name):
4084
- if name == 'menu':
4085
- return self.__menu
4086
- return Widget.__getitem__(self, name)
4087
-
4088
- def destroy(self):
4089
- """Destroy this widget and the associated menu."""
4090
- Menubutton.destroy(self)
4091
- self.__menu = None
4092
-
4093
-
4094
- class Image:
4095
- """Base class for images."""
4096
- _last_id = 0
4097
-
4098
- def __init__(self, imgtype, name=None, cnf={}, master=None, **kw):
4099
- self.name = None
4100
- if master is None:
4101
- master = _get_default_root('create image')
4102
- self.tk = getattr(master, 'tk', master)
4103
- if not name:
4104
- Image._last_id += 1
4105
- name = "pyimage%r" % (Image._last_id,) # tk itself would use image<x>
4106
- if kw and cnf: cnf = _cnfmerge((cnf, kw))
4107
- elif kw: cnf = kw
4108
- options = ()
4109
- for k, v in cnf.items():
4110
- options = options + ('-'+k, v)
4111
- self.tk.call(('image', 'create', imgtype, name,) + options)
4112
- self.name = name
4113
-
4114
- def __str__(self): return self.name
4115
-
4116
- def __del__(self):
4117
- if self.name:
4118
- try:
4119
- self.tk.call('image', 'delete', self.name)
4120
- except TclError:
4121
- # May happen if the root was destroyed
4122
- pass
4123
-
4124
- def __setitem__(self, key, value):
4125
- self.tk.call(self.name, 'configure', '-'+key, value)
4126
-
4127
- def __getitem__(self, key):
4128
- return self.tk.call(self.name, 'configure', '-'+key)
4129
-
4130
- def configure(self, **kw):
4131
- """Configure the image."""
4132
- res = ()
4133
- for k, v in _cnfmerge(kw).items():
4134
- if v is not None:
4135
- if k[-1] == '_': k = k[:-1]
4136
- res = res + ('-'+k, v)
4137
- self.tk.call((self.name, 'config') + res)
4138
-
4139
- config = configure
4140
-
4141
- def height(self):
4142
- """Return the height of the image."""
4143
- return self.tk.getint(
4144
- self.tk.call('image', 'height', self.name))
4145
-
4146
- def type(self):
4147
- """Return the type of the image, e.g. "photo" or "bitmap"."""
4148
- return self.tk.call('image', 'type', self.name)
4149
-
4150
- def width(self):
4151
- """Return the width of the image."""
4152
- return self.tk.getint(
4153
- self.tk.call('image', 'width', self.name))
4154
-
4155
-
4156
- class PhotoImage(Image):
4157
- """Widget which can display images in PGM, PPM, GIF, PNG format."""
4158
-
4159
- def __init__(self, name=None, cnf={}, master=None, **kw):
4160
- """Create an image with NAME.
4161
-
4162
- Valid resource names: data, format, file, gamma, height, palette,
4163
- width."""
4164
- Image.__init__(self, 'photo', name, cnf, master, **kw)
4165
-
4166
- def blank(self):
4167
- """Display a transparent image."""
4168
- self.tk.call(self.name, 'blank')
4169
-
4170
- def cget(self, option):
4171
- """Return the value of OPTION."""
4172
- return self.tk.call(self.name, 'cget', '-' + option)
4173
- # XXX config
4174
-
4175
- def __getitem__(self, key):
4176
- return self.tk.call(self.name, 'cget', '-' + key)
4177
- # XXX copy -from, -to, ...?
4178
-
4179
- def copy(self):
4180
- """Return a new PhotoImage with the same image as this widget."""
4181
- destImage = PhotoImage(master=self.tk)
4182
- self.tk.call(destImage, 'copy', self.name)
4183
- return destImage
4184
-
4185
- def zoom(self, x, y=''):
4186
- """Return a new PhotoImage with the same image as this widget
4187
- but zoom it with a factor of x in the X direction and y in the Y
4188
- direction. If y is not given, the default value is the same as x.
4189
- """
4190
- destImage = PhotoImage(master=self.tk)
4191
- if y=='': y=x
4192
- self.tk.call(destImage, 'copy', self.name, '-zoom',x,y)
4193
- return destImage
4194
-
4195
- def subsample(self, x, y=''):
4196
- """Return a new PhotoImage based on the same image as this widget
4197
- but use only every Xth or Yth pixel. If y is not given, the
4198
- default value is the same as x.
4199
- """
4200
- destImage = PhotoImage(master=self.tk)
4201
- if y=='': y=x
4202
- self.tk.call(destImage, 'copy', self.name, '-subsample',x,y)
4203
- return destImage
4204
-
4205
- def get(self, x, y):
4206
- """Return the color (red, green, blue) of the pixel at X,Y."""
4207
- return self.tk.call(self.name, 'get', x, y)
4208
-
4209
- def put(self, data, to=None):
4210
- """Put row formatted colors to image starting from
4211
- position TO, e.g. image.put("{red green} {blue yellow}", to=(4,6))"""
4212
- args = (self.name, 'put', data)
4213
- if to:
4214
- if to[0] == '-to':
4215
- to = to[1:]
4216
- args = args + ('-to',) + tuple(to)
4217
- self.tk.call(args)
4218
- # XXX read
4219
-
4220
- def write(self, filename, format=None, from_coords=None):
4221
- """Write image to file FILENAME in FORMAT starting from
4222
- position FROM_COORDS."""
4223
- args = (self.name, 'write', filename)
4224
- if format:
4225
- args = args + ('-format', format)
4226
- if from_coords:
4227
- args = args + ('-from',) + tuple(from_coords)
4228
- self.tk.call(args)
4229
-
4230
- def transparency_get(self, x, y):
4231
- """Return True if the pixel at x,y is transparent."""
4232
- return self.tk.getboolean(self.tk.call(
4233
- self.name, 'transparency', 'get', x, y))
4234
-
4235
- def transparency_set(self, x, y, boolean):
4236
- """Set the transparency of the pixel at x,y."""
4237
- self.tk.call(self.name, 'transparency', 'set', x, y, boolean)
4238
-
4239
-
4240
- class BitmapImage(Image):
4241
- """Widget which can display images in XBM format."""
4242
-
4243
- def __init__(self, name=None, cnf={}, master=None, **kw):
4244
- """Create a bitmap with NAME.
4245
-
4246
- Valid resource names: background, data, file, foreground, maskdata, maskfile."""
4247
- Image.__init__(self, 'bitmap', name, cnf, master, **kw)
4248
-
4249
-
4250
- def image_names():
4251
- tk = _get_default_root('use image_names()').tk
4252
- return tk.splitlist(tk.call('image', 'names'))
4253
-
4254
-
4255
- def image_types():
4256
- tk = _get_default_root('use image_types()').tk
4257
- return tk.splitlist(tk.call('image', 'types'))
4258
-
4259
-
4260
- class Spinbox(Widget, XView):
4261
- """spinbox widget."""
4262
-
4263
- def __init__(self, master=None, cnf={}, **kw):
4264
- """Construct a spinbox widget with the parent MASTER.
4265
-
4266
- STANDARD OPTIONS
4267
-
4268
- activebackground, background, borderwidth,
4269
- cursor, exportselection, font, foreground,
4270
- highlightbackground, highlightcolor,
4271
- highlightthickness, insertbackground,
4272
- insertborderwidth, insertofftime,
4273
- insertontime, insertwidth, justify, relief,
4274
- repeatdelay, repeatinterval,
4275
- selectbackground, selectborderwidth
4276
- selectforeground, takefocus, textvariable
4277
- xscrollcommand.
4278
-
4279
- WIDGET-SPECIFIC OPTIONS
4280
-
4281
- buttonbackground, buttoncursor,
4282
- buttondownrelief, buttonuprelief,
4283
- command, disabledbackground,
4284
- disabledforeground, format, from,
4285
- invalidcommand, increment,
4286
- readonlybackground, state, to,
4287
- validate, validatecommand values,
4288
- width, wrap,
4289
- """
4290
- Widget.__init__(self, master, 'spinbox', cnf, kw)
4291
-
4292
- def bbox(self, index):
4293
- """Return a tuple of X1,Y1,X2,Y2 coordinates for a
4294
- rectangle which encloses the character given by index.
4295
-
4296
- The first two elements of the list give the x and y
4297
- coordinates of the upper-left corner of the screen
4298
- area covered by the character (in pixels relative
4299
- to the widget) and the last two elements give the
4300
- width and height of the character, in pixels. The
4301
- bounding box may refer to a region outside the
4302
- visible area of the window.
4303
- """
4304
- return self._getints(self.tk.call(self._w, 'bbox', index)) or None
4305
-
4306
- def delete(self, first, last=None):
4307
- """Delete one or more elements of the spinbox.
4308
-
4309
- First is the index of the first character to delete,
4310
- and last is the index of the character just after
4311
- the last one to delete. If last isn't specified it
4312
- defaults to first+1, i.e. a single character is
4313
- deleted. This command returns an empty string.
4314
- """
4315
- return self.tk.call(self._w, 'delete', first, last)
4316
-
4317
- def get(self):
4318
- """Returns the spinbox's string"""
4319
- return self.tk.call(self._w, 'get')
4320
-
4321
- def icursor(self, index):
4322
- """Alter the position of the insertion cursor.
4323
-
4324
- The insertion cursor will be displayed just before
4325
- the character given by index. Returns an empty string
4326
- """
4327
- return self.tk.call(self._w, 'icursor', index)
4328
-
4329
- def identify(self, x, y):
4330
- """Returns the name of the widget at position x, y
4331
-
4332
- Return value is one of: none, buttondown, buttonup, entry
4333
- """
4334
- return self.tk.call(self._w, 'identify', x, y)
4335
-
4336
- def index(self, index):
4337
- """Returns the numerical index corresponding to index
4338
- """
4339
- return self.tk.call(self._w, 'index', index)
4340
-
4341
- def insert(self, index, s):
4342
- """Insert string s at index
4343
-
4344
- Returns an empty string.
4345
- """
4346
- return self.tk.call(self._w, 'insert', index, s)
4347
-
4348
- def invoke(self, element):
4349
- """Causes the specified element to be invoked
4350
-
4351
- The element could be buttondown or buttonup
4352
- triggering the action associated with it.
4353
- """
4354
- return self.tk.call(self._w, 'invoke', element)
4355
-
4356
- def scan(self, *args):
4357
- """Internal function."""
4358
- return self._getints(
4359
- self.tk.call((self._w, 'scan') + args)) or ()
4360
-
4361
- def scan_mark(self, x):
4362
- """Records x and the current view in the spinbox window;
4363
-
4364
- used in conjunction with later scan dragto commands.
4365
- Typically this command is associated with a mouse button
4366
- press in the widget. It returns an empty string.
4367
- """
4368
- return self.scan("mark", x)
4369
-
4370
- def scan_dragto(self, x):
4371
- """Compute the difference between the given x argument
4372
- and the x argument to the last scan mark command
4373
-
4374
- It then adjusts the view left or right by 10 times the
4375
- difference in x-coordinates. This command is typically
4376
- associated with mouse motion events in the widget, to
4377
- produce the effect of dragging the spinbox at high speed
4378
- through the window. The return value is an empty string.
4379
- """
4380
- return self.scan("dragto", x)
4381
-
4382
- def selection(self, *args):
4383
- """Internal function."""
4384
- return self._getints(
4385
- self.tk.call((self._w, 'selection') + args)) or ()
4386
-
4387
- def selection_adjust(self, index):
4388
- """Locate the end of the selection nearest to the character
4389
- given by index,
4390
-
4391
- Then adjust that end of the selection to be at index
4392
- (i.e including but not going beyond index). The other
4393
- end of the selection is made the anchor point for future
4394
- select to commands. If the selection isn't currently in
4395
- the spinbox, then a new selection is created to include
4396
- the characters between index and the most recent selection
4397
- anchor point, inclusive.
4398
- """
4399
- return self.selection("adjust", index)
4400
-
4401
- def selection_clear(self):
4402
- """Clear the selection
4403
-
4404
- If the selection isn't in this widget then the
4405
- command has no effect.
4406
- """
4407
- return self.selection("clear")
4408
-
4409
- def selection_element(self, element=None):
4410
- """Sets or gets the currently selected element.
4411
-
4412
- If a spinbutton element is specified, it will be
4413
- displayed depressed.
4414
- """
4415
- return self.tk.call(self._w, 'selection', 'element', element)
4416
-
4417
- def selection_from(self, index):
4418
- """Set the fixed end of a selection to INDEX."""
4419
- self.selection('from', index)
4420
-
4421
- def selection_present(self):
4422
- """Return True if there are characters selected in the spinbox, False
4423
- otherwise."""
4424
- return self.tk.getboolean(
4425
- self.tk.call(self._w, 'selection', 'present'))
4426
-
4427
- def selection_range(self, start, end):
4428
- """Set the selection from START to END (not included)."""
4429
- self.selection('range', start, end)
4430
-
4431
- def selection_to(self, index):
4432
- """Set the variable end of a selection to INDEX."""
4433
- self.selection('to', index)
4434
-
4435
- ###########################################################################
4436
-
4437
-
4438
- class LabelFrame(Widget):
4439
- """labelframe widget."""
4440
-
4441
- def __init__(self, master=None, cnf={}, **kw):
4442
- """Construct a labelframe widget with the parent MASTER.
4443
-
4444
- STANDARD OPTIONS
4445
-
4446
- borderwidth, cursor, font, foreground,
4447
- highlightbackground, highlightcolor,
4448
- highlightthickness, padx, pady, relief,
4449
- takefocus, text
4450
-
4451
- WIDGET-SPECIFIC OPTIONS
4452
-
4453
- background, class, colormap, container,
4454
- height, labelanchor, labelwidget,
4455
- visual, width
4456
- """
4457
- Widget.__init__(self, master, 'labelframe', cnf, kw)
4458
-
4459
- ########################################################################
4460
-
4461
-
4462
- class PanedWindow(Widget):
4463
- """panedwindow widget."""
4464
-
4465
- def __init__(self, master=None, cnf={}, **kw):
4466
- """Construct a panedwindow widget with the parent MASTER.
4467
-
4468
- STANDARD OPTIONS
4469
-
4470
- background, borderwidth, cursor, height,
4471
- orient, relief, width
4472
-
4473
- WIDGET-SPECIFIC OPTIONS
4474
-
4475
- handlepad, handlesize, opaqueresize,
4476
- sashcursor, sashpad, sashrelief,
4477
- sashwidth, showhandle,
4478
- """
4479
- Widget.__init__(self, master, 'panedwindow', cnf, kw)
4480
-
4481
- def add(self, child, **kw):
4482
- """Add a child widget to the panedwindow in a new pane.
4483
-
4484
- The child argument is the name of the child widget
4485
- followed by pairs of arguments that specify how to
4486
- manage the windows. The possible options and values
4487
- are the ones accepted by the paneconfigure method.
4488
- """
4489
- self.tk.call((self._w, 'add', child) + self._options(kw))
4490
-
4491
- def remove(self, child):
4492
- """Remove the pane containing child from the panedwindow
4493
-
4494
- All geometry management options for child will be forgotten.
4495
- """
4496
- self.tk.call(self._w, 'forget', child)
4497
-
4498
- forget = remove
4499
-
4500
- def identify(self, x, y):
4501
- """Identify the panedwindow component at point x, y
4502
-
4503
- If the point is over a sash or a sash handle, the result
4504
- is a two element list containing the index of the sash or
4505
- handle, and a word indicating whether it is over a sash
4506
- or a handle, such as {0 sash} or {2 handle}. If the point
4507
- is over any other part of the panedwindow, the result is
4508
- an empty list.
4509
- """
4510
- return self.tk.call(self._w, 'identify', x, y)
4511
-
4512
- def proxy(self, *args):
4513
- """Internal function."""
4514
- return self._getints(
4515
- self.tk.call((self._w, 'proxy') + args)) or ()
4516
-
4517
- def proxy_coord(self):
4518
- """Return the x and y pair of the most recent proxy location
4519
- """
4520
- return self.proxy("coord")
4521
-
4522
- def proxy_forget(self):
4523
- """Remove the proxy from the display.
4524
- """
4525
- return self.proxy("forget")
4526
-
4527
- def proxy_place(self, x, y):
4528
- """Place the proxy at the given x and y coordinates.
4529
- """
4530
- return self.proxy("place", x, y)
4531
-
4532
- def sash(self, *args):
4533
- """Internal function."""
4534
- return self._getints(
4535
- self.tk.call((self._w, 'sash') + args)) or ()
4536
-
4537
- def sash_coord(self, index):
4538
- """Return the current x and y pair for the sash given by index.
4539
-
4540
- Index must be an integer between 0 and 1 less than the
4541
- number of panes in the panedwindow. The coordinates given are
4542
- those of the top left corner of the region containing the sash.
4543
- pathName sash dragto index x y This command computes the
4544
- difference between the given coordinates and the coordinates
4545
- given to the last sash coord command for the given sash. It then
4546
- moves that sash the computed difference. The return value is the
4547
- empty string.
4548
- """
4549
- return self.sash("coord", index)
4550
-
4551
- def sash_mark(self, index):
4552
- """Records x and y for the sash given by index;
4553
-
4554
- Used in conjunction with later dragto commands to move the sash.
4555
- """
4556
- return self.sash("mark", index)
4557
-
4558
- def sash_place(self, index, x, y):
4559
- """Place the sash given by index at the given coordinates
4560
- """
4561
- return self.sash("place", index, x, y)
4562
-
4563
- def panecget(self, child, option):
4564
- """Query a management option for window.
4565
-
4566
- Option may be any value allowed by the paneconfigure subcommand
4567
- """
4568
- return self.tk.call(
4569
- (self._w, 'panecget') + (child, '-'+option))
4570
-
4571
- def paneconfigure(self, tagOrId, cnf=None, **kw):
4572
- """Query or modify the management options for window.
4573
-
4574
- If no option is specified, returns a list describing all
4575
- of the available options for pathName. If option is
4576
- specified with no value, then the command returns a list
4577
- describing the one named option (this list will be identical
4578
- to the corresponding sublist of the value returned if no
4579
- option is specified). If one or more option-value pairs are
4580
- specified, then the command modifies the given widget
4581
- option(s) to have the given value(s); in this case the
4582
- command returns an empty string. The following options
4583
- are supported:
4584
-
4585
- after window
4586
- Insert the window after the window specified. window
4587
- should be the name of a window already managed by pathName.
4588
- before window
4589
- Insert the window before the window specified. window
4590
- should be the name of a window already managed by pathName.
4591
- height size
4592
- Specify a height for the window. The height will be the
4593
- outer dimension of the window including its border, if
4594
- any. If size is an empty string, or if -height is not
4595
- specified, then the height requested internally by the
4596
- window will be used initially; the height may later be
4597
- adjusted by the movement of sashes in the panedwindow.
4598
- Size may be any value accepted by Tk_GetPixels.
4599
- minsize n
4600
- Specifies that the size of the window cannot be made
4601
- less than n. This constraint only affects the size of
4602
- the widget in the paned dimension -- the x dimension
4603
- for horizontal panedwindows, the y dimension for
4604
- vertical panedwindows. May be any value accepted by
4605
- Tk_GetPixels.
4606
- padx n
4607
- Specifies a non-negative value indicating how much
4608
- extra space to leave on each side of the window in
4609
- the X-direction. The value may have any of the forms
4610
- accepted by Tk_GetPixels.
4611
- pady n
4612
- Specifies a non-negative value indicating how much
4613
- extra space to leave on each side of the window in
4614
- the Y-direction. The value may have any of the forms
4615
- accepted by Tk_GetPixels.
4616
- sticky style
4617
- If a window's pane is larger than the requested
4618
- dimensions of the window, this option may be used
4619
- to position (or stretch) the window within its pane.
4620
- Style is a string that contains zero or more of the
4621
- characters n, s, e or w. The string can optionally
4622
- contains spaces or commas, but they are ignored. Each
4623
- letter refers to a side (north, south, east, or west)
4624
- that the window will "stick" to. If both n and s
4625
- (or e and w) are specified, the window will be
4626
- stretched to fill the entire height (or width) of
4627
- its cavity.
4628
- width size
4629
- Specify a width for the window. The width will be
4630
- the outer dimension of the window including its
4631
- border, if any. If size is an empty string, or
4632
- if -width is not specified, then the width requested
4633
- internally by the window will be used initially; the
4634
- width may later be adjusted by the movement of sashes
4635
- in the panedwindow. Size may be any value accepted by
4636
- Tk_GetPixels.
4637
-
4638
- """
4639
- if cnf is None and not kw:
4640
- return self._getconfigure(self._w, 'paneconfigure', tagOrId)
4641
- if isinstance(cnf, str) and not kw:
4642
- return self._getconfigure1(
4643
- self._w, 'paneconfigure', tagOrId, '-'+cnf)
4644
- self.tk.call((self._w, 'paneconfigure', tagOrId) +
4645
- self._options(cnf, kw))
4646
-
4647
- paneconfig = paneconfigure
4648
-
4649
- def panes(self):
4650
- """Returns an ordered list of the child panes."""
4651
- return self.tk.splitlist(self.tk.call(self._w, 'panes'))
4652
-
4653
- # Test:
4654
-
4655
-
4656
- def _test():
4657
- root = Tk()
4658
- text = "This is Tcl/Tk %s" % root.globalgetvar('tk_patchLevel')
4659
- text += "\nThis should be a cedilla: \xe7"
4660
- label = Label(root, text=text)
4661
- label.pack()
4662
- test = Button(root, text="Click me!",
4663
- command=lambda root=root: root.test.configure(
4664
- text="[%s]" % root.test['text']))
4665
- test.pack()
4666
- root.test = test
4667
- quit = Button(root, text="QUIT", command=root.destroy)
4668
- quit.pack()
4669
- # The following three commands are needed so the window pops
4670
- # up on top on Windows...
4671
- root.iconify()
4672
- root.update()
4673
- root.deiconify()
4674
- root.mainloop()
4675
-
4676
-
4677
- __all__ = [name for name, obj in globals().items()
4678
- if not name.startswith('_') and not isinstance(obj, types.ModuleType)
4679
- and name not in {'wantobjects'}]
4680
-
4681
- if __name__ == '__main__':
4682
- _test()