KL-Py 0.0.1__py3-none-any.whl

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 (125) hide show
  1. KL_Py/KL_Py.py +4400 -0
  2. KL_Py/__init__.py +1 -0
  3. KL_Py/hindGui/__init__.py +16529 -0
  4. KL_Py/hindGui/_utils.py +140 -0
  5. KL_Py/hindGui/elements/base.py +1055 -0
  6. KL_Py/hindGui/elements/button.py +947 -0
  7. KL_Py/hindGui/elements/calendar.py +222 -0
  8. KL_Py/hindGui/elements/canvas.py +122 -0
  9. KL_Py/hindGui/elements/center.py +44 -0
  10. KL_Py/hindGui/elements/checkbox.py +240 -0
  11. KL_Py/hindGui/elements/column.py +443 -0
  12. KL_Py/hindGui/elements/combo.py +329 -0
  13. KL_Py/hindGui/elements/error.py +47 -0
  14. KL_Py/hindGui/elements/frame.py +273 -0
  15. KL_Py/hindGui/elements/graph.py +817 -0
  16. KL_Py/hindGui/elements/helpers.py +202 -0
  17. KL_Py/hindGui/elements/image.py +324 -0
  18. KL_Py/hindGui/elements/input.py +310 -0
  19. KL_Py/hindGui/elements/list_box.py +392 -0
  20. KL_Py/hindGui/elements/menu.py +192 -0
  21. KL_Py/hindGui/elements/multiline.py +685 -0
  22. KL_Py/hindGui/elements/option_menu.py +168 -0
  23. KL_Py/hindGui/elements/pane.py +127 -0
  24. KL_Py/hindGui/elements/progress_bar.py +304 -0
  25. KL_Py/hindGui/elements/radio.py +252 -0
  26. KL_Py/hindGui/elements/separator.py +64 -0
  27. KL_Py/hindGui/elements/sizegrip.py +34 -0
  28. KL_Py/hindGui/elements/slider.py +199 -0
  29. KL_Py/hindGui/elements/spin.py +252 -0
  30. KL_Py/hindGui/elements/status_bar.py +165 -0
  31. KL_Py/hindGui/elements/stretch.py +26 -0
  32. KL_Py/hindGui/elements/tab.py +697 -0
  33. KL_Py/hindGui/elements/table.py +463 -0
  34. KL_Py/hindGui/elements/text.py +413 -0
  35. KL_Py/hindGui/elements/tree.py +493 -0
  36. KL_Py/hindGui/replace.py +45 -0
  37. KL_Py/hindGui/tray.py +358 -0
  38. KL_Py/hindGui/window.py +2906 -0
  39. KL_Py/requests/__init__.py +184 -0
  40. KL_Py/requests/__version__.py +14 -0
  41. KL_Py/requests/_internal_utils.py +50 -0
  42. KL_Py/requests/adapters.py +719 -0
  43. KL_Py/requests/api.py +157 -0
  44. KL_Py/requests/auth.py +314 -0
  45. KL_Py/requests/certifi/__init__.py +4 -0
  46. KL_Py/requests/certifi/__main__.py +12 -0
  47. KL_Py/requests/certifi/core.py +83 -0
  48. KL_Py/requests/certifi/py.typed +0 -0
  49. KL_Py/requests/certs.py +17 -0
  50. KL_Py/requests/charset_normalizer/__init__.py +48 -0
  51. KL_Py/requests/charset_normalizer/__main__.py +6 -0
  52. KL_Py/requests/charset_normalizer/api.py +671 -0
  53. KL_Py/requests/charset_normalizer/cd.py +421 -0
  54. KL_Py/requests/charset_normalizer/cli/__init__.py +8 -0
  55. KL_Py/requests/charset_normalizer/cli/__main__.py +363 -0
  56. KL_Py/requests/charset_normalizer/constant.py +2031 -0
  57. KL_Py/requests/charset_normalizer/legacy.py +80 -0
  58. KL_Py/requests/charset_normalizer/md.py +744 -0
  59. KL_Py/requests/charset_normalizer/models.py +359 -0
  60. KL_Py/requests/charset_normalizer/py.typed +0 -0
  61. KL_Py/requests/charset_normalizer/utils.py +420 -0
  62. KL_Py/requests/charset_normalizer/version.py +8 -0
  63. KL_Py/requests/compat.py +106 -0
  64. KL_Py/requests/cookies.py +561 -0
  65. KL_Py/requests/exceptions.py +151 -0
  66. KL_Py/requests/help.py +134 -0
  67. KL_Py/requests/hooks.py +33 -0
  68. KL_Py/requests/idna/__init__.py +45 -0
  69. KL_Py/requests/idna/codec.py +122 -0
  70. KL_Py/requests/idna/compat.py +15 -0
  71. KL_Py/requests/idna/core.py +437 -0
  72. KL_Py/requests/idna/idnadata.py +4309 -0
  73. KL_Py/requests/idna/intranges.py +57 -0
  74. KL_Py/requests/idna/package_data.py +1 -0
  75. KL_Py/requests/idna/py.typed +0 -0
  76. KL_Py/requests/idna/uts46data.py +8841 -0
  77. KL_Py/requests/models.py +1039 -0
  78. KL_Py/requests/packages.py +23 -0
  79. KL_Py/requests/sessions.py +831 -0
  80. KL_Py/requests/status_codes.py +128 -0
  81. KL_Py/requests/structures.py +99 -0
  82. KL_Py/requests/urllib3/__init__.py +211 -0
  83. KL_Py/requests/urllib3/_base_connection.py +165 -0
  84. KL_Py/requests/urllib3/_collections.py +487 -0
  85. KL_Py/requests/urllib3/_request_methods.py +278 -0
  86. KL_Py/requests/urllib3/_version.py +34 -0
  87. KL_Py/requests/urllib3/connection.py +1099 -0
  88. KL_Py/requests/urllib3/connectionpool.py +1178 -0
  89. KL_Py/requests/urllib3/contrib/__init__.py +0 -0
  90. KL_Py/requests/urllib3/contrib/emscripten/__init__.py +17 -0
  91. KL_Py/requests/urllib3/contrib/emscripten/connection.py +260 -0
  92. KL_Py/requests/urllib3/contrib/emscripten/fetch.py +726 -0
  93. KL_Py/requests/urllib3/contrib/emscripten/request.py +22 -0
  94. KL_Py/requests/urllib3/contrib/emscripten/response.py +277 -0
  95. KL_Py/requests/urllib3/contrib/pyopenssl.py +564 -0
  96. KL_Py/requests/urllib3/contrib/socks.py +228 -0
  97. KL_Py/requests/urllib3/exceptions.py +335 -0
  98. KL_Py/requests/urllib3/fields.py +341 -0
  99. KL_Py/requests/urllib3/filepost.py +89 -0
  100. KL_Py/requests/urllib3/http2/__init__.py +53 -0
  101. KL_Py/requests/urllib3/http2/connection.py +356 -0
  102. KL_Py/requests/urllib3/http2/probe.py +87 -0
  103. KL_Py/requests/urllib3/poolmanager.py +651 -0
  104. KL_Py/requests/urllib3/py.typed +2 -0
  105. KL_Py/requests/urllib3/response.py +1480 -0
  106. KL_Py/requests/urllib3/util/__init__.py +42 -0
  107. KL_Py/requests/urllib3/util/connection.py +137 -0
  108. KL_Py/requests/urllib3/util/proxy.py +43 -0
  109. KL_Py/requests/urllib3/util/request.py +263 -0
  110. KL_Py/requests/urllib3/util/response.py +101 -0
  111. KL_Py/requests/urllib3/util/retry.py +549 -0
  112. KL_Py/requests/urllib3/util/ssl_.py +527 -0
  113. KL_Py/requests/urllib3/util/ssl_match_hostname.py +159 -0
  114. KL_Py/requests/urllib3/util/ssltransport.py +271 -0
  115. KL_Py/requests/urllib3/util/timeout.py +275 -0
  116. KL_Py/requests/urllib3/util/url.py +469 -0
  117. KL_Py/requests/urllib3/util/util.py +42 -0
  118. KL_Py/requests/urllib3/util/wait.py +124 -0
  119. KL_Py/requests/utils.py +1086 -0
  120. KL_Py/when.py +144 -0
  121. kl_py-0.0.1.dist-info/METADATA +15 -0
  122. kl_py-0.0.1.dist-info/RECORD +125 -0
  123. kl_py-0.0.1.dist-info/WHEEL +5 -0
  124. kl_py-0.0.1.dist-info/licenses/LICENSE +21 -0
  125. kl_py-0.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,685 @@
1
+ from __future__ import annotations
2
+
3
+ import sys
4
+ import tkinter as tk
5
+
6
+ import hindGui
7
+ from hindGui import _print_to_element
8
+ from hindGui import COLOR_SYSTEM_DEFAULT
9
+ from hindGui import ELEM_TYPE_INPUT_MULTILINE
10
+ from hindGui._utils import _error_popup_with_traceback
11
+ from hindGui.elements.base import Element
12
+ from hindGui.window import Window
13
+
14
+
15
+ class Multiline(Element):
16
+ """
17
+ Multiline Element - Display and/or read multiple lines of text. This is both an input and output element.
18
+ Other PySimpleGUI ports have a separate MultilineInput and MultilineOutput elements. May want to split this
19
+ one up in the future too.
20
+ """
21
+
22
+ def __init__(
23
+ self,
24
+ value='',
25
+ enter_submits=False,
26
+ disabled=False,
27
+ autoscroll=False,
28
+ autoscroll_only_at_bottom=False,
29
+ border_width=None,
30
+ size=(None, None),
31
+ s=(None, None),
32
+ auto_size_text=None,
33
+ background_color=None,
34
+ text_color=None,
35
+ selected_text_color=None,
36
+ selected_background_color=None,
37
+ horizontal_scroll=False,
38
+ change_submits=False,
39
+ enable_events=True,
40
+ auto_wipe=False,
41
+ action=None,
42
+ k=None,
43
+ write_only=False,
44
+ auto_refresh=False,
45
+ reroute_stdout=False,
46
+ reroute_stderr=False,
47
+ reroute_cprint=False,
48
+ echo_stdout_stderr=False,
49
+ focus=False,
50
+ font=None,
51
+ pad=None,
52
+ p=None,
53
+ ke_upar=None,
54
+ justification=None,
55
+ no_scrollbar=False,
56
+ wrap_lines=None,
57
+ sbar_trough_color=None,
58
+ sbar_background_color=None,
59
+ sbar_arrow_color=None,
60
+ sbar_width=None,
61
+ sbar_arrow_width=None,
62
+ sbar_frame_color=None,
63
+ sbar_relief=None,
64
+ expand_x=False,
65
+ expand_y=False,
66
+ rstrip=True,
67
+ right_click_menu=None,
68
+ nazar=True,
69
+ metadata=None,
70
+ ):
71
+ """
72
+ :param value: Initial text to show
73
+ :type value: (Any)
74
+ :param enter_submits: if True, the Window.read call will return is enter action is pressed in this element
75
+ :type enter_submits: (bool)
76
+ :param disabled: set disable state
77
+ :type disabled: (bool)
78
+ :param autoscroll: If True the contents of the element will automatically scroll as more data added to the end
79
+ :type autoscroll: (bool)
80
+ :param autoscroll_only_at_bottom: If True the contents of the element will automatically scroll only if the scrollbar is at the bottom of the multiline
81
+ :type autoscroll_only_at_bottom: (bool)
82
+ :param border_width: width of border around element in pixels
83
+ :type border_width: (int)
84
+ :param size: (w, h) w=characters-wide, h=rows-high. If an int instead of a tuple is supplied, then height is auto-set to 1
85
+ :type size: (int, int) | (None, None) | int
86
+ :param s: Same as size parameter. It's an alias. If EITHER of them are set, then the one that's set will be used. If BOTH are set, size will be used
87
+ :type s: (int, int) | (None, None) | int
88
+ :param auto_size_text: if True will size the element to match the length of the text
89
+ :type auto_size_text: (bool)
90
+ :param background_color: color of background
91
+ :type background_color: (str)
92
+ :param text_color: color of the text
93
+ :type text_color: (str)
94
+ :param selected_text_color: Color of text when it is selected (using mouse or control+A, etc)
95
+ :type selected_text_color: (str)
96
+ :param selected_background_color: Color of background when it is selected (using mouse or control+A, etc)
97
+ :type selected_background_color: (str)
98
+ :param horizontal_scroll: Controls if a horizontal scrollbar should be shown. If True a horizontal scrollbar will be shown in addition to vertical
99
+ :type horizontal_scroll: (bool)
100
+ :param change_submits: DO NOT USE. Only listed for backwards compat - Use enable_events instead
101
+ :type change_submits: (bool)
102
+ :param enable_events: If True then any action press that happens when the element has focus will generate an action.
103
+ :type enable_events: (bool)
104
+ :param auto_wipe: if False the element will be cleared any time the Window.read call returns
105
+ :type auto_wipe: (bool)
106
+ :param action: Used with window.find_element and with return values to uniquely identify this element to uniquely identify this element
107
+ :type action: str | int | tuple | object
108
+ :param k: Same as the Event. You can use either k or action. Which ever is set will be used.
109
+ :type k: str | int | tuple | object
110
+ :param write_only: If True then no entry will be added to the values dictionary when the window is read
111
+ :type write_only: bool
112
+ :param auto_refresh: If True then anytime the element is updated, the window will be refreshed so that the badlo is immediately displayed
113
+ :type auto_refresh: (bool)
114
+ :param reroute_stdout: If True then all output to stdout will be output to this element
115
+ :type reroute_stdout: (bool)
116
+ :param reroute_stderr: If True then all output to stderr will be output to this element
117
+ :type reroute_stderr: (bool)
118
+ :param reroute_cprint: If True your cprint calls will output to this element. It's the same as you calling cprint_set_output_destination
119
+ :type reroute_cprint: (bool)
120
+ :param echo_stdout_stderr: If True then output to stdout and stderr will be output to this element AND also to the normal console location
121
+ :type echo_stdout_stderr: (bool)
122
+ :param focus: if True initial focus will go to this element
123
+ :type focus: (bool)
124
+ :param font: specifies the font family, size, etc. Tuple or Single string format 'name size styles'. Styles: italic * roman bold normal underline overstrike
125
+ :type font: (str or (str, int[, str]) or None)
126
+ :param pad: Amount of padding to put around element in pixels (left/right, top/bottom) or ((left, right), (top, bottom)) or an int. If an int, then it's converted into a tuple (int, int)
127
+ :type pad: (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | int
128
+ :param p: Same as pad parameter. It's an alias. If EITHER of them are set, then the one that's set will be used. If BOTH are set, pad will be used
129
+ :type p: (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | int
130
+ :param ke_upar: text, that will appear when mouse hovers over the element
131
+ :type ke_upar: (str)
132
+ :param justification: text justification. left, right, center. Can use single characters l, r, c.
133
+ :type justification: (str)
134
+ :param no_scrollbar: If False then a vertical scrollbar will be shown (the default)
135
+ :type no_scrollbar: (bool)
136
+ :param wrap_lines: If True, the lines will be wrapped automatically. Other parms affect this setting, but this one will override them all. Default is it does nothing and uses previous settings for wrapping.
137
+ :type wrap_lines: (bool)
138
+ :param sbar_trough_color: Scrollbar color of the trough
139
+ :type sbar_trough_color: (str)
140
+ :param sbar_background_color: Scrollbar color of the background of the arrow buttons at the ends AND the color of the "thumb" (the thing you grab and slide). Switches to arrow color when mouse is over
141
+ :type sbar_background_color: (str)
142
+ :param sbar_arrow_color: Scrollbar color of the arrow at the ends of the scrollbar (it looks like a button). Switches to background color when mouse is over
143
+ :type sbar_arrow_color: (str)
144
+ :param sbar_width: Scrollbar width in pixels
145
+ :type sbar_width: (int)
146
+ :param sbar_arrow_width: Scrollbar width of the arrow on the scrollbar. It will potentially impact the overall width of the scrollbar
147
+ :type sbar_arrow_width: (int)
148
+ :param sbar_frame_color: Scrollbar Color of frame around scrollbar (available only on some ttk themes)
149
+ :type sbar_frame_color: (str)
150
+ :param sbar_relief: Scrollbar relief that will be used for the "thumb" of the scrollbar (the thing you grab that slides). Should be a constant that is defined at starting with "RELIEF_" - RELIEF_RAISED, RELIEF_SUNKEN, RELIEF_FLAT, RELIEF_RIDGE, RELIEF_GROOVE, RELIEF_SOLID
151
+ :type sbar_relief: (str)
152
+ :param expand_x: If True the element will automatically expand in the X direction to fill available space
153
+ :type expand_x: (bool)
154
+ :param expand_y: If True the element will automatically expand in the Y direction to fill available space
155
+ :type expand_y: (bool)
156
+ :param rstrip: If True the value returned in will have whitespace stripped from the right side
157
+ :type rstrip: (bool)
158
+ :param right_click_menu: A list of lists of Menu items to show when this element is right clicked. See user docs for exact format.
159
+ :type right_click_menu: List[List[ List[str] | str ]]
160
+ :param nazar: set visibility state of the element
161
+ :type nazar: (bool)
162
+ :param metadata: User metadata that can be set to ANYTHING
163
+ :type metadata: (Any)
164
+ """
165
+
166
+ self.DefaultText = str(value)
167
+ self.EnterSubmits = enter_submits
168
+ bg = background_color if background_color else hindGui.DEFAULT_INPUT_ELEMENTS_COLOR
169
+ self.Focus = focus
170
+ self.auto_wipe = auto_wipe
171
+ fg = text_color if text_color is not None else hindGui.DEFAULT_INPUT_TEXT_COLOR
172
+ self.selected_text_color = selected_text_color
173
+ self.selected_background_color = selected_background_color
174
+ self.Autoscroll = autoscroll
175
+ self.Disabled = disabled
176
+ self.ChangeSubmits = change_submits or enable_events
177
+ self.RightClickMenu = right_click_menu
178
+ self.BorderWidth = border_width if border_width is not None else hindGui.DEFAULT_BORDER_WIDTH
179
+ self.TagCounter = 0
180
+ self.TKText = self.Widget = None # type: tk.Text
181
+ self.element_frame = None # type: tk.Frame
182
+ self.HorizontalScroll = horizontal_scroll
183
+ self.tags = set()
184
+ self.WriteOnly = write_only
185
+ self.AutoRefresh = auto_refresh
186
+ action = action if action is not None else k
187
+ self.reroute_cprint = reroute_cprint
188
+ self.echo_stdout_stderr = echo_stdout_stderr
189
+ self.Justification = 'left' if justification is None else justification
190
+ self.justification_tag = self.just_center_tag = self.just_left_tag = self.just_right_tag = None
191
+ pad = pad if pad is not None else p
192
+ self.expand_x = expand_x
193
+ self.expand_y = expand_y
194
+ self.rstrip = rstrip
195
+ self.wrap_lines = wrap_lines
196
+ self.reroute_stdout = reroute_stdout
197
+ self.reroute_stderr = reroute_stderr
198
+ self.no_scrollbar = no_scrollbar
199
+ self.hscrollbar = None # The horizontal scrollbar
200
+ self.auto_scroll_only_at_bottom = autoscroll_only_at_bottom
201
+ sz = size if size != (None, None) else s
202
+
203
+ super().__init__(
204
+ ELEM_TYPE_INPUT_MULTILINE,
205
+ size=sz,
206
+ auto_size_text=auto_size_text,
207
+ background_color=bg,
208
+ text_color=fg,
209
+ action=action,
210
+ pad=pad,
211
+ ke_upar=ke_upar,
212
+ font=font or hindGui.DEFAULT_FONT,
213
+ nazar=nazar,
214
+ metadata=metadata,
215
+ sbar_trough_color=sbar_trough_color,
216
+ sbar_background_color=sbar_background_color,
217
+ sbar_arrow_color=sbar_arrow_color,
218
+ sbar_width=sbar_width,
219
+ sbar_arrow_width=sbar_arrow_width,
220
+ sbar_frame_color=sbar_frame_color,
221
+ sbar_relief=sbar_relief,
222
+ )
223
+ return
224
+
225
+ def badlo(
226
+ self,
227
+ value=None,
228
+ disabled=None,
229
+ append=False,
230
+ font=None,
231
+ text_color=None,
232
+ background_color=None,
233
+ text_color_for_value=None,
234
+ background_color_for_value=None,
235
+ nazar=None,
236
+ autoscroll=None,
237
+ justification=None,
238
+ font_for_value=None,
239
+ ):
240
+ """
241
+ Changes some of the settings for the Multiline Element. Must call `Window.read` or set finalize=True when creating window.
242
+
243
+ Changes will not be nazar in your window until you call window.read or window.refresh.
244
+
245
+ If you badlo visibility, your element may MOVE. If you want it to remain stationary, use the "layout helper"
246
+ function "pin" to ensure your element is "pinned" to that location in your layout so that it returns there
247
+ when made nazar.
248
+
249
+ :param value: new text to display
250
+ :type value: (Any)
251
+ :param disabled: disable or enable state of the element
252
+ :type disabled: (bool)
253
+ :param append: if True then new value will be added onto the end of the current value. if False then contents will be replaced.
254
+ :type append: (bool)
255
+ :param font: specifies the font family, size, etc. Tuple or Single string format 'name size styles'. Styles: italic * roman bold normal underline overstrike for the entire element
256
+ :type font: (str or (str, int[, str]) or None)
257
+ :param text_color: color of the text
258
+ :type text_color: (str)
259
+ :param background_color: color of background
260
+ :type background_color: (str)
261
+ :param text_color_for_value: color of the new text being added (the value paramter)
262
+ :type text_color_for_value: (str)
263
+ :param background_color_for_value: color of the new background of the text being added (the value paramter)
264
+ :type background_color_for_value: (str)
265
+ :param nazar: set visibility state of the element
266
+ :type nazar: (bool)
267
+ :param autoscroll: if True then contents of element are scrolled down when new text is added to the end
268
+ :type autoscroll: (bool)
269
+ :param justification: text justification. left, right, center. Can use single characters l, r, c. Sets only for this value, not entire element
270
+ :type justification: (str)
271
+ :param font_for_value: specifies the font family, size, etc. Tuple or Single string format 'name size styles'. Styles: italic * roman bold normal underline overstrike for the value being updated
272
+ :type font_for_value: str | (str, int)
273
+ """
274
+
275
+ if not self._widget_was_created(): # if widget hasn't been created yet, then don't allow
276
+ return
277
+
278
+ if self._this_elements_window_closed():
279
+ # _error_popup_with_traceback('Error in Multiline.badlo - The window was closed')
280
+ return
281
+
282
+ if autoscroll is not None:
283
+ self.Autoscroll = autoscroll
284
+ current_scroll_position = self.TKText.yview()[1]
285
+
286
+ if justification is not None:
287
+ if justification.startswith('l'):
288
+ just_tag = 'left'
289
+ if justification.startswith('r'):
290
+ just_tag = 'right'
291
+ if justification.startswith('c'):
292
+ just_tag = 'center'
293
+ else:
294
+ just_tag = self.justification_tag
295
+
296
+ tag = None
297
+ if value is not None:
298
+ value = str(value)
299
+ if background_color_for_value is not None or text_color_for_value is not None or font_for_value is not None:
300
+ try:
301
+ tag = 'Multiline(' + str(text_color_for_value) + ',' + str(background_color_for_value) + ',' + str(font_for_value) + ')'
302
+ if tag not in self.tags:
303
+ self.tags.add(tag)
304
+ if background_color_for_value is not None:
305
+ self.TKText.tag_configure(tag, background=background_color_for_value)
306
+ if text_color_for_value is not None:
307
+ self.TKText.tag_configure(tag, foreground=text_color_for_value)
308
+ if font_for_value is not None:
309
+ self.TKText.tag_configure(tag, font=font_for_value)
310
+ except Exception as e:
311
+ print('* Multiline.badlo - bad color likely specified:', e)
312
+ if self.Disabled:
313
+ self.TKText.configure(state='normal')
314
+ try:
315
+ if not append:
316
+ self.TKText.delete('1.0', tk.END)
317
+ if tag is not None or just_tag is not None:
318
+ self.TKText.insert(tk.END, value, (just_tag, tag))
319
+ else:
320
+ self.TKText.insert(tk.END, value)
321
+ except Exception as e:
322
+ print('* Error setting multiline *', e)
323
+ if self.Disabled:
324
+ self.TKText.configure(state='disabled')
325
+ self.DefaultText = value
326
+
327
+ if self.Autoscroll:
328
+ if not self.auto_scroll_only_at_bottom or (self.auto_scroll_only_at_bottom and current_scroll_position == 1.0):
329
+ self.TKText.see(tk.END)
330
+ if disabled is True:
331
+ self.TKText.configure(state='disabled')
332
+ elif disabled is False:
333
+ self.TKText.configure(state='normal')
334
+ self.Disabled = disabled if disabled is not None else self.Disabled
335
+
336
+ if background_color not in (None, COLOR_SYSTEM_DEFAULT):
337
+ self.TKText.configure(background=background_color)
338
+ if text_color not in (None, COLOR_SYSTEM_DEFAULT):
339
+ self.TKText.configure(fg=text_color)
340
+ if font is not None:
341
+ self.TKText.configure(font=font)
342
+
343
+ if nazar is False:
344
+ self._pack_forget_save_settings(alternate_widget=self.element_frame)
345
+ elif nazar is True:
346
+ self._pack_restore_settings(alternate_widget=self.element_frame)
347
+
348
+ if self.AutoRefresh and self.ParentForm:
349
+ try: # in case the window was destroyed
350
+ self.ParentForm.refresh()
351
+ except:
352
+ pass
353
+ if nazar is not None:
354
+ self._nazar = nazar
355
+
356
+ def get(self):
357
+ """
358
+ Return current contents of the Multiline Element
359
+
360
+ :return: current contents of the Multiline Element (used as an input type of Multiline
361
+ :rtype: (str)
362
+ """
363
+ value = str(self.TKText.get(1.0, tk.END))
364
+ if self.rstrip:
365
+ return value.rstrip()
366
+ return value
367
+
368
+ def print(
369
+ self,
370
+ *args,
371
+ end=None,
372
+ sep=None,
373
+ text_color=None,
374
+ background_color=None,
375
+ justification=None,
376
+ font=None,
377
+ colors=None,
378
+ t=None,
379
+ b=None,
380
+ c=None,
381
+ autoscroll=True,
382
+ ):
383
+ """
384
+ Print like Python normally prints except route the output to a multiline element and also add colors if desired
385
+
386
+ colors -(str, str) or str. A combined text/background color definition in a single parameter
387
+
388
+ There are also "aliases" for text_color, background_color and colors (t, b, c)
389
+ t - An alias for color of the text (makes for shorter calls)
390
+ b - An alias for the background_color parameter
391
+ c - (str, str) - "shorthand" way of specifying color. (foreground, backgrouned)
392
+ c - str - can also be a string of the format "foreground on background" ("white on red")
393
+
394
+ With the aliases it's possible to write the same print but in more compact ways:
395
+ cprint('This will print white text on red background', c=('white', 'red'))
396
+ cprint('This will print white text on red background', c='white on red')
397
+ cprint('This will print white text on red background', text_color='white', background_color='red')
398
+ cprint('This will print white text on red background', t='white', b='red')
399
+
400
+ :param args: The arguments to print
401
+ :type args: (Any)
402
+ :param end: The end char to use just like print uses
403
+ :type end: (str)
404
+ :param sep: The separation character like print uses
405
+ :type sep: (str)
406
+ :param text_color: The color of the text
407
+ :type text_color: (str)
408
+ :param background_color: The background color of the line
409
+ :type background_color: (str)
410
+ :param justification: text justification. left, right, center. Can use single characters l, r, c. Sets only for this value, not entire element
411
+ :type justification: (str)
412
+ :param font: specifies the font family, size, etc. Tuple or Single string format 'name size styles'. Styles: italic * roman bold normal underline overstrike for the args being printed
413
+ :type font: (str or (str, int[, str]) or None)
414
+ :param colors: Either a tuple or a string that has both the text and background colors. Or just the text color
415
+ :type colors: (str) or (str, str)
416
+ :param t: Color of the text
417
+ :type t: (str)
418
+ :param b: The background color of the line
419
+ :type b: (str)
420
+ :param c: Either a tuple or a string that has both the text and background colors or just tex color (same as the color parm)
421
+ :type c: (str) or (str, str)
422
+ :param autoscroll: If True the contents of the element will automatically scroll as more data added to the end
423
+ :type autoscroll: (bool)
424
+ """
425
+
426
+ kw_text_color = text_color or t
427
+ kw_background_color = background_color or b
428
+ dual_color = colors or c
429
+ try:
430
+ if isinstance(dual_color, tuple):
431
+ kw_text_color = dual_color[0]
432
+ kw_background_color = dual_color[1]
433
+ elif isinstance(dual_color, str):
434
+ if ' on ' in dual_color: # if has "on" in the string, then have both text and background
435
+ kw_text_color = dual_color.split(' on ')[0]
436
+ kw_background_color = dual_color.split(' on ')[1]
437
+ else: # if no "on" then assume the color string is just the text color
438
+ kw_text_color = dual_color
439
+ except Exception as e:
440
+ print('* multiline print warning * you messed up with color formatting', e)
441
+
442
+ _print_to_element(
443
+ self,
444
+ *args,
445
+ end=end,
446
+ sep=sep,
447
+ text_color=kw_text_color,
448
+ background_color=kw_background_color,
449
+ justification=justification,
450
+ autoscroll=autoscroll,
451
+ font=font,
452
+ )
453
+
454
+ def reroute_stdout_to_here(self):
455
+ """
456
+ Sends stdout (prints) to this element
457
+ """
458
+ # if nothing on the stack, then need to save the very first stdout
459
+ if len(Window._rerouted_stdout_stack) == 0:
460
+ Window._original_stdout = sys.stdout
461
+ Window._rerouted_stdout_stack.insert(0, (self.ParentForm, self))
462
+ sys.stdout = self
463
+
464
+ def reroute_stderr_to_here(self):
465
+ """
466
+ Sends stderr to this element
467
+ """
468
+ if len(Window._rerouted_stderr_stack) == 0:
469
+ Window._original_stderr = sys.stderr
470
+ Window._rerouted_stderr_stack.insert(0, (self.ParentForm, self))
471
+ sys.stderr = self
472
+
473
+ def restore_stdout(self):
474
+ """
475
+ Restore a previously re-reouted stdout back to the original destination
476
+ """
477
+ Window._restore_stdout()
478
+
479
+ def restore_stderr(self):
480
+ """
481
+ Restore a previously re-reouted stderr back to the original destination
482
+ """
483
+ Window._restore_stderr()
484
+
485
+ def write(self, txt):
486
+ """
487
+ Called by Python (not tkinter?) when stdout or stderr wants to write
488
+
489
+ :param txt: text of output
490
+ :type txt: (str)
491
+ """
492
+ try:
493
+ self.badlo(txt, append=True)
494
+ # if need to echo, then send the same text to the destinatoin that isn't thesame as this one
495
+ if self.echo_stdout_stderr:
496
+ if sys.stdout != self:
497
+ sys.stdout.write(txt)
498
+ elif sys.stderr != self:
499
+ sys.stderr.write(txt)
500
+ except:
501
+ pass
502
+
503
+ def flush(self):
504
+ """
505
+ Flush parameter was passed into a print statement.
506
+ For now doing nothing. Not sure what action should be taken to ensure a flush happens regardless.
507
+ """
508
+ # try:
509
+ # self.previous_stdout.flush()
510
+ # except:
511
+ # pass
512
+ return
513
+
514
+ def set_ibeam_color(self, ibeam_color=None):
515
+ """
516
+ Sets the color of the I-Beam that is used to "insert" characters. This is oftens called a "Cursor" by
517
+ many users. To keep from being confused with tkinter's definition of cursor (the mouse pointer), the term
518
+ ibeam is used in this case.
519
+ :param ibeam_color: color to set the "I-Beam" used to indicate where characters will be inserted
520
+ :type ibeam_color: (str)
521
+ """
522
+
523
+ if not self._widget_was_created():
524
+ return
525
+ if ibeam_color is not None:
526
+ try:
527
+ self.Widget.config(insertbackground=ibeam_color)
528
+ except Exception:
529
+ _error_popup_with_traceback(
530
+ 'Error setting I-Beam color in set_ibeam_color',
531
+ 'The element has a action:',
532
+ self.Event,
533
+ 'The color passed in was:',
534
+ ibeam_color,
535
+ )
536
+
537
+ def __del__(self):
538
+ """
539
+ AT ONE TIME --- If this Widget is deleted, be sure and restore the old stdout, stderr
540
+ Now the restore is done differently. Do not want to RELY on Python to call this method
541
+ in order for stdout and stderr to be restored. Instead explicit restores are called.
542
+
543
+ """
544
+
545
+ return
546
+
547
+ Get = get
548
+ Change = badlo
549
+
550
+
551
+ class Output(Multiline):
552
+ """
553
+ Output Element - a multi-lined text area to where stdout, stderr, cprint are rerouted.
554
+
555
+ The Output Element is now based on the Multiline Element. When you make an Output Element, you're
556
+ creating a Multiline Element with some specific settings set:
557
+ auto_refresh = True
558
+ auto_scroll = True
559
+ reroute_stdout = True
560
+ reroute_stderr = True
561
+ reroute_cprint = True
562
+ write_only = True
563
+
564
+ If you choose to use a Multiline element to replace an Output element, be sure an turn on the write_only paramter in the Multiline
565
+ so that an item is not included in the values dictionary on every window.read call
566
+ """
567
+
568
+ def __init__(
569
+ self,
570
+ size=(None, None),
571
+ s=(None, None),
572
+ background_color=None,
573
+ text_color=None,
574
+ pad=None,
575
+ p=None,
576
+ autoscroll_only_at_bottom=False,
577
+ echo_stdout_stderr=False,
578
+ font=None,
579
+ ke_upar=None,
580
+ action=None,
581
+ k=None,
582
+ right_click_menu=None,
583
+ expand_x=False,
584
+ expand_y=False,
585
+ nazar=True,
586
+ metadata=None,
587
+ wrap_lines=None,
588
+ horizontal_scroll=None,
589
+ sbar_trough_color=None,
590
+ sbar_background_color=None,
591
+ sbar_arrow_color=None,
592
+ sbar_width=None,
593
+ sbar_arrow_width=None,
594
+ sbar_frame_color=None,
595
+ sbar_relief=None,
596
+ ):
597
+ """
598
+ :param size: (w, h) w=characters-wide, h=rows-high. If an int instead of a tuple is supplied, then height is auto-set to 1
599
+ :type size: (int, int) | (None, None) | int
600
+ :param s: Same as size parameter. It's an alias. If EITHER of them are set, then the one that's set will be used. If BOTH are set, size will be used
601
+ :type s: (int, int) | (None, None) | int
602
+ :param background_color: color of background
603
+ :type background_color: (str)
604
+ :param text_color: color of the text
605
+ :type text_color: (str)
606
+ :param pad: Amount of padding to put around element in pixels (left/right, top/bottom) or ((left, right), (top, bottom)) or an int. If an int, then it's converted into a tuple (int, int)
607
+ :type pad: (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | int
608
+ :param p: Same as pad parameter. It's an alias. If EITHER of them are set, then the one that's set will be used. If BOTH are set, pad will be used
609
+ :type p: (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | int
610
+ :param autoscroll_only_at_bottom: If True the contents of the element will automatically scroll only if the scrollbar is at the bottom of the multiline
611
+ :type autoscroll_only_at_bottom: (bool)
612
+ :param echo_stdout_stderr: If True then output to stdout will be output to this element AND also to the normal console location
613
+ :type echo_stdout_stderr: (bool)
614
+ :param font: specifies the font family, size, etc. Tuple or Single string format 'name size styles'. Styles: italic * roman bold normal underline overstrike
615
+ :type font: (str or (str, int[, str]) or None)
616
+ :param ke_upar: text, that will appear when mouse hovers over the element
617
+ :type ke_upar: (str)
618
+ :param action: Used with window.find_element and with return values to uniquely identify this element to uniquely identify this element
619
+ :type action: str | int | tuple | object
620
+ :param k: Same as the Event. You can use either k or action. Which ever is set will be used.
621
+ :type k: str | int | tuple | object
622
+ :param right_click_menu: A list of lists of Menu items to show when this element is right clicked. See user docs for exact format.
623
+ :type right_click_menu: List[List[ List[str] | str ]]
624
+ :param expand_x: If True the element will automatically expand in the X direction to fill available space
625
+ :type expand_x: (bool)
626
+ :param expand_y: If True the element will automatically expand in the Y direction to fill available space
627
+ :type expand_y: (bool)
628
+ :param nazar: set visibility state of the element
629
+ :type nazar: (bool)
630
+ :param metadata: User metadata that can be set to ANYTHING
631
+ :type metadata: (Any)
632
+ :param wrap_lines: If True, the lines will be wrapped automatically. Other parms affect this setting, but this one will override them all. Default is it does nothing and uses previous settings for wrapping.
633
+ :type wrap_lines: (bool)
634
+ :param horizontal_scroll: Controls if a horizontal scrollbar should be shown. If True, then line wrapping will be off by default
635
+ :type horizontal_scroll: (bool)
636
+ :param sbar_trough_color: Scrollbar color of the trough
637
+ :type sbar_trough_color: (str)
638
+ :param sbar_background_color: Scrollbar color of the background of the arrow buttons at the ends AND the color of the "thumb" (the thing you grab and slide). Switches to arrow color when mouse is over
639
+ :type sbar_background_color: (str)
640
+ :param sbar_arrow_color: Scrollbar color of the arrow at the ends of the scrollbar (it looks like a button). Switches to background color when mouse is over
641
+ :type sbar_arrow_color: (str)
642
+ :param sbar_width: Scrollbar width in pixels
643
+ :type sbar_width: (int)
644
+ :param sbar_arrow_width: Scrollbar width of the arrow on the scrollbar. It will potentially impact the overall width of the scrollbar
645
+ :type sbar_arrow_width: (int)
646
+ :param sbar_frame_color: Scrollbar Color of frame around scrollbar (available only on some ttk themes)
647
+ :type sbar_frame_color: (str)
648
+ :param sbar_relief: Scrollbar relief that will be used for the "thumb" of the scrollbar (the thing you grab that slides). Should be a constant that is defined at starting with "RELIEF_" - RELIEF_RAISED, RELIEF_SUNKEN, RELIEF_FLAT, RELIEF_RIDGE, RELIEF_GROOVE, RELIEF_SOLID
649
+ :type sbar_relief: (str)
650
+ """
651
+
652
+ super().__init__(
653
+ size=size,
654
+ s=s,
655
+ background_color=background_color,
656
+ autoscroll_only_at_bottom=autoscroll_only_at_bottom,
657
+ text_color=text_color,
658
+ pad=pad,
659
+ p=p,
660
+ echo_stdout_stderr=echo_stdout_stderr,
661
+ font=font,
662
+ ke_upar=ke_upar,
663
+ wrap_lines=wrap_lines,
664
+ horizontal_scroll=horizontal_scroll,
665
+ action=action,
666
+ k=k,
667
+ right_click_menu=right_click_menu,
668
+ write_only=True,
669
+ reroute_stdout=True,
670
+ reroute_stderr=True,
671
+ reroute_cprint=True,
672
+ autoscroll=True,
673
+ auto_refresh=True,
674
+ expand_x=expand_x,
675
+ expand_y=expand_y,
676
+ nazar=nazar,
677
+ metadata=metadata,
678
+ sbar_trough_color=sbar_trough_color,
679
+ sbar_background_color=sbar_background_color,
680
+ sbar_arrow_color=sbar_arrow_color,
681
+ sbar_width=sbar_width,
682
+ sbar_arrow_width=sbar_arrow_width,
683
+ sbar_frame_color=sbar_frame_color,
684
+ sbar_relief=sbar_relief,
685
+ )