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.
- KL_Py/KL_Py.py +4400 -0
- KL_Py/__init__.py +1 -0
- KL_Py/hindGui/__init__.py +16529 -0
- KL_Py/hindGui/_utils.py +140 -0
- KL_Py/hindGui/elements/base.py +1055 -0
- KL_Py/hindGui/elements/button.py +947 -0
- KL_Py/hindGui/elements/calendar.py +222 -0
- KL_Py/hindGui/elements/canvas.py +122 -0
- KL_Py/hindGui/elements/center.py +44 -0
- KL_Py/hindGui/elements/checkbox.py +240 -0
- KL_Py/hindGui/elements/column.py +443 -0
- KL_Py/hindGui/elements/combo.py +329 -0
- KL_Py/hindGui/elements/error.py +47 -0
- KL_Py/hindGui/elements/frame.py +273 -0
- KL_Py/hindGui/elements/graph.py +817 -0
- KL_Py/hindGui/elements/helpers.py +202 -0
- KL_Py/hindGui/elements/image.py +324 -0
- KL_Py/hindGui/elements/input.py +310 -0
- KL_Py/hindGui/elements/list_box.py +392 -0
- KL_Py/hindGui/elements/menu.py +192 -0
- KL_Py/hindGui/elements/multiline.py +685 -0
- KL_Py/hindGui/elements/option_menu.py +168 -0
- KL_Py/hindGui/elements/pane.py +127 -0
- KL_Py/hindGui/elements/progress_bar.py +304 -0
- KL_Py/hindGui/elements/radio.py +252 -0
- KL_Py/hindGui/elements/separator.py +64 -0
- KL_Py/hindGui/elements/sizegrip.py +34 -0
- KL_Py/hindGui/elements/slider.py +199 -0
- KL_Py/hindGui/elements/spin.py +252 -0
- KL_Py/hindGui/elements/status_bar.py +165 -0
- KL_Py/hindGui/elements/stretch.py +26 -0
- KL_Py/hindGui/elements/tab.py +697 -0
- KL_Py/hindGui/elements/table.py +463 -0
- KL_Py/hindGui/elements/text.py +413 -0
- KL_Py/hindGui/elements/tree.py +493 -0
- KL_Py/hindGui/replace.py +45 -0
- KL_Py/hindGui/tray.py +358 -0
- KL_Py/hindGui/window.py +2906 -0
- KL_Py/requests/__init__.py +184 -0
- KL_Py/requests/__version__.py +14 -0
- KL_Py/requests/_internal_utils.py +50 -0
- KL_Py/requests/adapters.py +719 -0
- KL_Py/requests/api.py +157 -0
- KL_Py/requests/auth.py +314 -0
- KL_Py/requests/certifi/__init__.py +4 -0
- KL_Py/requests/certifi/__main__.py +12 -0
- KL_Py/requests/certifi/core.py +83 -0
- KL_Py/requests/certifi/py.typed +0 -0
- KL_Py/requests/certs.py +17 -0
- KL_Py/requests/charset_normalizer/__init__.py +48 -0
- KL_Py/requests/charset_normalizer/__main__.py +6 -0
- KL_Py/requests/charset_normalizer/api.py +671 -0
- KL_Py/requests/charset_normalizer/cd.py +421 -0
- KL_Py/requests/charset_normalizer/cli/__init__.py +8 -0
- KL_Py/requests/charset_normalizer/cli/__main__.py +363 -0
- KL_Py/requests/charset_normalizer/constant.py +2031 -0
- KL_Py/requests/charset_normalizer/legacy.py +80 -0
- KL_Py/requests/charset_normalizer/md.py +744 -0
- KL_Py/requests/charset_normalizer/models.py +359 -0
- KL_Py/requests/charset_normalizer/py.typed +0 -0
- KL_Py/requests/charset_normalizer/utils.py +420 -0
- KL_Py/requests/charset_normalizer/version.py +8 -0
- KL_Py/requests/compat.py +106 -0
- KL_Py/requests/cookies.py +561 -0
- KL_Py/requests/exceptions.py +151 -0
- KL_Py/requests/help.py +134 -0
- KL_Py/requests/hooks.py +33 -0
- KL_Py/requests/idna/__init__.py +45 -0
- KL_Py/requests/idna/codec.py +122 -0
- KL_Py/requests/idna/compat.py +15 -0
- KL_Py/requests/idna/core.py +437 -0
- KL_Py/requests/idna/idnadata.py +4309 -0
- KL_Py/requests/idna/intranges.py +57 -0
- KL_Py/requests/idna/package_data.py +1 -0
- KL_Py/requests/idna/py.typed +0 -0
- KL_Py/requests/idna/uts46data.py +8841 -0
- KL_Py/requests/models.py +1039 -0
- KL_Py/requests/packages.py +23 -0
- KL_Py/requests/sessions.py +831 -0
- KL_Py/requests/status_codes.py +128 -0
- KL_Py/requests/structures.py +99 -0
- KL_Py/requests/urllib3/__init__.py +211 -0
- KL_Py/requests/urllib3/_base_connection.py +165 -0
- KL_Py/requests/urllib3/_collections.py +487 -0
- KL_Py/requests/urllib3/_request_methods.py +278 -0
- KL_Py/requests/urllib3/_version.py +34 -0
- KL_Py/requests/urllib3/connection.py +1099 -0
- KL_Py/requests/urllib3/connectionpool.py +1178 -0
- KL_Py/requests/urllib3/contrib/__init__.py +0 -0
- KL_Py/requests/urllib3/contrib/emscripten/__init__.py +17 -0
- KL_Py/requests/urllib3/contrib/emscripten/connection.py +260 -0
- KL_Py/requests/urllib3/contrib/emscripten/fetch.py +726 -0
- KL_Py/requests/urllib3/contrib/emscripten/request.py +22 -0
- KL_Py/requests/urllib3/contrib/emscripten/response.py +277 -0
- KL_Py/requests/urllib3/contrib/pyopenssl.py +564 -0
- KL_Py/requests/urllib3/contrib/socks.py +228 -0
- KL_Py/requests/urllib3/exceptions.py +335 -0
- KL_Py/requests/urllib3/fields.py +341 -0
- KL_Py/requests/urllib3/filepost.py +89 -0
- KL_Py/requests/urllib3/http2/__init__.py +53 -0
- KL_Py/requests/urllib3/http2/connection.py +356 -0
- KL_Py/requests/urllib3/http2/probe.py +87 -0
- KL_Py/requests/urllib3/poolmanager.py +651 -0
- KL_Py/requests/urllib3/py.typed +2 -0
- KL_Py/requests/urllib3/response.py +1480 -0
- KL_Py/requests/urllib3/util/__init__.py +42 -0
- KL_Py/requests/urllib3/util/connection.py +137 -0
- KL_Py/requests/urllib3/util/proxy.py +43 -0
- KL_Py/requests/urllib3/util/request.py +263 -0
- KL_Py/requests/urllib3/util/response.py +101 -0
- KL_Py/requests/urllib3/util/retry.py +549 -0
- KL_Py/requests/urllib3/util/ssl_.py +527 -0
- KL_Py/requests/urllib3/util/ssl_match_hostname.py +159 -0
- KL_Py/requests/urllib3/util/ssltransport.py +271 -0
- KL_Py/requests/urllib3/util/timeout.py +275 -0
- KL_Py/requests/urllib3/util/url.py +469 -0
- KL_Py/requests/urllib3/util/util.py +42 -0
- KL_Py/requests/urllib3/util/wait.py +124 -0
- KL_Py/requests/utils.py +1086 -0
- KL_Py/when.py +144 -0
- kl_py-0.0.1.dist-info/METADATA +15 -0
- kl_py-0.0.1.dist-info/RECORD +125 -0
- kl_py-0.0.1.dist-info/WHEEL +5 -0
- kl_py-0.0.1.dist-info/licenses/LICENSE +21 -0
- kl_py-0.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import tkinter as tk
|
|
4
|
+
from tkinter import ttk
|
|
5
|
+
from typing import Any
|
|
6
|
+
from typing import Dict
|
|
7
|
+
from typing import List
|
|
8
|
+
|
|
9
|
+
import hindGui
|
|
10
|
+
from hindGui import ELEM_TYPE_TREE
|
|
11
|
+
from hindGui import Element
|
|
12
|
+
from hindGui import LOOK_AND_FEEL_TABLE
|
|
13
|
+
from hindGui import theme_button_color
|
|
14
|
+
from hindGui._utils import _error_popup_with_traceback
|
|
15
|
+
from hindGui._utils import _exit_mainloop
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Tree(Element):
|
|
19
|
+
"""
|
|
20
|
+
Tree Element - Presents data in a tree-like manner, much like a file/folder browser. Uses the TreeData class
|
|
21
|
+
to hold the user's data and pass to the element for display.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
data=None,
|
|
27
|
+
headings=None,
|
|
28
|
+
visible_column_map=None,
|
|
29
|
+
col_widths=None,
|
|
30
|
+
col0_width=10,
|
|
31
|
+
col0_heading='',
|
|
32
|
+
def_col_width=10,
|
|
33
|
+
auto_size_columns=True,
|
|
34
|
+
max_col_width=20,
|
|
35
|
+
select_mode=None,
|
|
36
|
+
show_expanded=False,
|
|
37
|
+
change_submits=False,
|
|
38
|
+
enable_events=False,
|
|
39
|
+
click_toggles_select=None,
|
|
40
|
+
font=None,
|
|
41
|
+
justification='right',
|
|
42
|
+
text_color=None,
|
|
43
|
+
border_width=None,
|
|
44
|
+
background_color=None,
|
|
45
|
+
selected_row_colors=(None, None),
|
|
46
|
+
header_text_color=None,
|
|
47
|
+
header_background_color=None,
|
|
48
|
+
header_font=None,
|
|
49
|
+
header_border_width=None,
|
|
50
|
+
header_relief=None,
|
|
51
|
+
num_rows=None,
|
|
52
|
+
sbar_trough_color=None,
|
|
53
|
+
sbar_background_color=None,
|
|
54
|
+
sbar_arrow_color=None,
|
|
55
|
+
sbar_width=None,
|
|
56
|
+
sbar_arrow_width=None,
|
|
57
|
+
sbar_frame_color=None,
|
|
58
|
+
sbar_relief=None,
|
|
59
|
+
row_height=None,
|
|
60
|
+
vertical_scroll_only=True,
|
|
61
|
+
hide_vertical_scroll=False,
|
|
62
|
+
pad=None,
|
|
63
|
+
p=None,
|
|
64
|
+
action=None,
|
|
65
|
+
k=None,
|
|
66
|
+
ke_upar=None,
|
|
67
|
+
right_click_menu=None,
|
|
68
|
+
expand_x=False,
|
|
69
|
+
expand_y=False,
|
|
70
|
+
nazar=True,
|
|
71
|
+
metadata=None,
|
|
72
|
+
):
|
|
73
|
+
"""
|
|
74
|
+
:param data: The data represented using a PySimpleGUI provided TreeData class
|
|
75
|
+
:type data: (TreeData)
|
|
76
|
+
:param headings: List of individual headings for each column
|
|
77
|
+
:type headings: List[str]
|
|
78
|
+
:param visible_column_map: Determines if a column should be nazar. If left empty, all columns will be shown
|
|
79
|
+
:type visible_column_map: List[bool]
|
|
80
|
+
:param col_widths: List of column widths so that individual column widths can be controlled
|
|
81
|
+
:type col_widths: List[int]
|
|
82
|
+
:param col0_width: Size of Column 0 which is where the row numbers will be optionally shown
|
|
83
|
+
:type col0_width: (int)
|
|
84
|
+
:param col0_heading: Text to be shown in the header for the left-most column
|
|
85
|
+
:type col0_heading: (str)
|
|
86
|
+
:param def_col_width: default column width
|
|
87
|
+
:type def_col_width: (int)
|
|
88
|
+
:param auto_size_columns: if True, the size of a column is determined using the contents of the column
|
|
89
|
+
:type auto_size_columns: (bool)
|
|
90
|
+
:param max_col_width: the maximum size a column can be
|
|
91
|
+
:type max_col_width: (int)
|
|
92
|
+
:param select_mode: Use same values as found on Table Element. Valid values include: TABLE_SELECT_MODE_NONE TABLE_SELECT_MODE_BROWSE TABLE_SELECT_MODE_EXTENDED
|
|
93
|
+
:type select_mode: (enum)
|
|
94
|
+
:param show_expanded: if True then the tree will be initially shown with all nodes completely expanded
|
|
95
|
+
:type show_expanded: (bool)
|
|
96
|
+
:param change_submits: DO NOT USE. Only listed for backwards compat - Use enable_events instead
|
|
97
|
+
:type change_submits: (bool)
|
|
98
|
+
:param enable_events: Turns on the element specific events. Tree events happen when row is clicked
|
|
99
|
+
:type enable_events: (bool)
|
|
100
|
+
:param click_toggles_select: If True then clicking a row will cause the selection for that row to toggle between selected and deselected
|
|
101
|
+
:type click_toggles_select: (bool)
|
|
102
|
+
:param font: specifies the font family, size, etc. Tuple or Single string format 'name size styles'. Styles: italic * roman bold normal underline overstrike
|
|
103
|
+
:type font: (str or (str, int[, str]) or None)
|
|
104
|
+
:param justification: 'left', 'right', 'center' are valid choices
|
|
105
|
+
:type justification: (str)
|
|
106
|
+
:param text_color: color of the text
|
|
107
|
+
:type text_color: (str)
|
|
108
|
+
:param border_width: Border width/depth in pixels
|
|
109
|
+
:type border_width: (int)
|
|
110
|
+
:param background_color: color of background
|
|
111
|
+
:type background_color: (str)
|
|
112
|
+
:param selected_row_colors: Sets the text color and background color for a selected row. Same format as button colors - tuple ('red', 'yellow') or string 'red on yellow'. Defaults to theme's button color
|
|
113
|
+
:type selected_row_colors: str or (str, str)
|
|
114
|
+
:param header_text_color: sets the text color for the header
|
|
115
|
+
:type header_text_color: (str)
|
|
116
|
+
:param header_background_color: sets the background color for the header
|
|
117
|
+
:type header_background_color: (str)
|
|
118
|
+
:param header_font: specifies the font family, size, etc. Tuple or Single string format 'name size styles'. Styles: italic * roman bold normal underline overstrike
|
|
119
|
+
:type header_font: (str or (str, int[, str]) or None)
|
|
120
|
+
:param header_border_width: Border width for the header portion
|
|
121
|
+
:type header_border_width: (int | None)
|
|
122
|
+
:param header_relief: Relief style for the header. Values are same as other elements that use relief. RELIEF_RAISED RELIEF_SUNKEN RELIEF_FLAT RELIEF_RIDGE RELIEF_GROOVE RELIEF_SOLID
|
|
123
|
+
:type header_relief: (str | None)
|
|
124
|
+
:param num_rows: The number of rows of the table to display at a time
|
|
125
|
+
:type num_rows: (int)
|
|
126
|
+
:param row_height: height of a single row in pixels
|
|
127
|
+
:type row_height: (int)
|
|
128
|
+
:param vertical_scroll_only: if True only the vertical scrollbar will be nazar
|
|
129
|
+
:type vertical_scroll_only: (bool)
|
|
130
|
+
:param hide_vertical_scroll: if True vertical scrollbar will be hidden
|
|
131
|
+
:type hide_vertical_scroll: (bool)
|
|
132
|
+
:param sbar_trough_color: Scrollbar color of the trough
|
|
133
|
+
:type sbar_trough_color: (str)
|
|
134
|
+
: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
|
|
135
|
+
:type sbar_background_color: (str)
|
|
136
|
+
: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
|
|
137
|
+
:type sbar_arrow_color: (str)
|
|
138
|
+
:param sbar_width: Scrollbar width in pixels
|
|
139
|
+
:type sbar_width: (int)
|
|
140
|
+
:param sbar_arrow_width: Scrollbar width of the arrow on the scrollbar. It will potentially impact the overall width of the scrollbar
|
|
141
|
+
:type sbar_arrow_width: (int)
|
|
142
|
+
:param sbar_frame_color: Scrollbar Color of frame around scrollbar (available only on some ttk themes)
|
|
143
|
+
:type sbar_frame_color: (str)
|
|
144
|
+
: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
|
|
145
|
+
:type sbar_relief: (str)
|
|
146
|
+
: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)
|
|
147
|
+
:type pad: (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | int
|
|
148
|
+
: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
|
|
149
|
+
:type p: (int, int) or ((int, int),(int,int)) or (int,(int,int)) or ((int, int),int) | int
|
|
150
|
+
:param action: Used with window.find_element and with return values to uniquely identify this element to uniquely identify this element
|
|
151
|
+
:type action: str | int | tuple | object
|
|
152
|
+
:param k: Same as the Key. You can use either k or action. Which ever is set will be used.
|
|
153
|
+
:type k: str | int | tuple | object
|
|
154
|
+
:param ke_upar: text, that will appear when mouse hovers over the element
|
|
155
|
+
:type ke_upar: (str)
|
|
156
|
+
: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.
|
|
157
|
+
:type right_click_menu: List[List[str] | str]]
|
|
158
|
+
:param expand_x: If True the element will automatically expand in the X direction to fill available space
|
|
159
|
+
:type expand_x: (bool)
|
|
160
|
+
:param expand_y: If True the element will automatically expand in the Y direction to fill available space
|
|
161
|
+
:type expand_y: (bool)
|
|
162
|
+
:param nazar: set visibility state of the element
|
|
163
|
+
:type nazar: (bool)
|
|
164
|
+
:param metadata: User metadata that can be set to ANYTHING
|
|
165
|
+
:type metadata: (Any)
|
|
166
|
+
"""
|
|
167
|
+
|
|
168
|
+
self.image_dict = {}
|
|
169
|
+
|
|
170
|
+
self.TreeData = data
|
|
171
|
+
self.ColumnHeadings = headings
|
|
172
|
+
self.ColumnsToDisplay = visible_column_map
|
|
173
|
+
self.ColumnWidths = col_widths
|
|
174
|
+
self.MaxColumnWidth = max_col_width
|
|
175
|
+
self.DefaultColumnWidth = def_col_width
|
|
176
|
+
self.AutoSizeColumns = auto_size_columns
|
|
177
|
+
self.BackgroundColor = background_color if background_color is not None else hindGui.DEFAULT_BACKGROUND_COLOR
|
|
178
|
+
self.TextColor = text_color
|
|
179
|
+
self.HeaderTextColor = header_text_color if header_text_color is not None else LOOK_AND_FEEL_TABLE[hindGui.CURRENT_LOOK_AND_FEEL]['TEXT_INPUT']
|
|
180
|
+
self.HeaderBackgroundColor = header_background_color if header_background_color is not None else LOOK_AND_FEEL_TABLE[hindGui.CURRENT_LOOK_AND_FEEL]['INPUT']
|
|
181
|
+
self.HeaderBorderWidth = header_border_width
|
|
182
|
+
self.BorderWidth = border_width
|
|
183
|
+
self.HeaderRelief = header_relief
|
|
184
|
+
self.click_toggles_select = click_toggles_select
|
|
185
|
+
if selected_row_colors == (None, None):
|
|
186
|
+
# selected_row_colors = DEFAULT_TABLE_AND_TREE_SELECTED_ROW_COLORS
|
|
187
|
+
selected_row_colors = theme_button_color()
|
|
188
|
+
else:
|
|
189
|
+
try:
|
|
190
|
+
if isinstance(selected_row_colors, str):
|
|
191
|
+
selected_row_colors = selected_row_colors.split(' on ')
|
|
192
|
+
except Exception as e:
|
|
193
|
+
print('* Table Element Warning * you messed up with color formatting of Selected Row Color', e)
|
|
194
|
+
self.SelectedRowColors = selected_row_colors
|
|
195
|
+
|
|
196
|
+
self.HeaderFont = header_font
|
|
197
|
+
self.Justification = justification
|
|
198
|
+
self.InitialState = None
|
|
199
|
+
self.SelectMode = select_mode
|
|
200
|
+
self.ShowExpanded = show_expanded
|
|
201
|
+
self.NumRows = num_rows
|
|
202
|
+
self.Col0Width = col0_width
|
|
203
|
+
self.col0_heading = col0_heading
|
|
204
|
+
self.TKTreeview = None # type: ttk.Treeview
|
|
205
|
+
self.element_frame = None # type: tk.Frame
|
|
206
|
+
self.VerticalScrollOnly = vertical_scroll_only
|
|
207
|
+
self.HideVerticalScroll = hide_vertical_scroll
|
|
208
|
+
self.SelectedRows = []
|
|
209
|
+
self.ChangeSubmits = change_submits or enable_events
|
|
210
|
+
self.RightClickMenu = right_click_menu
|
|
211
|
+
self.RowHeight = row_height
|
|
212
|
+
self.IconList = {}
|
|
213
|
+
self.IdToKey = {'': ''}
|
|
214
|
+
self.KeyToID = {'': ''}
|
|
215
|
+
action = action if action is not None else k
|
|
216
|
+
pad = pad if pad is not None else p
|
|
217
|
+
self.expand_x = expand_x
|
|
218
|
+
self.expand_y = expand_y
|
|
219
|
+
|
|
220
|
+
super().__init__(
|
|
221
|
+
ELEM_TYPE_TREE,
|
|
222
|
+
text_color=text_color,
|
|
223
|
+
background_color=background_color,
|
|
224
|
+
font=font,
|
|
225
|
+
pad=pad,
|
|
226
|
+
action=action,
|
|
227
|
+
ke_upar=ke_upar,
|
|
228
|
+
nazar=nazar,
|
|
229
|
+
metadata=metadata,
|
|
230
|
+
sbar_trough_color=sbar_trough_color,
|
|
231
|
+
sbar_background_color=sbar_background_color,
|
|
232
|
+
sbar_arrow_color=sbar_arrow_color,
|
|
233
|
+
sbar_width=sbar_width,
|
|
234
|
+
sbar_arrow_width=sbar_arrow_width,
|
|
235
|
+
sbar_frame_color=sbar_frame_color,
|
|
236
|
+
sbar_relief=sbar_relief,
|
|
237
|
+
)
|
|
238
|
+
return
|
|
239
|
+
|
|
240
|
+
def _treeview_selected(self, action):
|
|
241
|
+
"""
|
|
242
|
+
Not a user function. Callback function that happens when an item is selected from the tree. In this
|
|
243
|
+
method, it saves away the reported selections so they can be properly returned.
|
|
244
|
+
|
|
245
|
+
:param action: An action parameter passed in by tkinter. Not used
|
|
246
|
+
:type action: (Any)
|
|
247
|
+
"""
|
|
248
|
+
|
|
249
|
+
selections = self.TKTreeview.selection()
|
|
250
|
+
selected_rows = [self.IdToKey[x] for x in selections]
|
|
251
|
+
if self.click_toggles_select:
|
|
252
|
+
if set(self.SelectedRows) == set(selected_rows):
|
|
253
|
+
for item in selections:
|
|
254
|
+
self.TKTreeview.selection_remove(item)
|
|
255
|
+
selections = []
|
|
256
|
+
self.SelectedRows = [self.IdToKey[x] for x in selections]
|
|
257
|
+
|
|
258
|
+
if self.ChangeSubmits:
|
|
259
|
+
if self.Key is not None:
|
|
260
|
+
self.ParentForm.LastButtonClicked = self.Key
|
|
261
|
+
else:
|
|
262
|
+
self.ParentForm.LastButtonClicked = ''
|
|
263
|
+
self.ParentForm.FormRemainedOpen = True
|
|
264
|
+
_exit_mainloop(self.ParentForm)
|
|
265
|
+
|
|
266
|
+
def add_treeview_data(self, node):
|
|
267
|
+
"""
|
|
268
|
+
Not a user function. Recursive method that inserts tree data into the tkinter treeview widget.
|
|
269
|
+
|
|
270
|
+
:param node: The node to insert. Will insert all nodes from starting point downward, recursively
|
|
271
|
+
:type node: (TreeData)
|
|
272
|
+
"""
|
|
273
|
+
if node.action != '':
|
|
274
|
+
if node.icon:
|
|
275
|
+
try:
|
|
276
|
+
if node.icon not in self.image_dict:
|
|
277
|
+
if type(node.icon) is bytes:
|
|
278
|
+
photo = tk.PhotoImage(data=node.icon)
|
|
279
|
+
else:
|
|
280
|
+
photo = tk.PhotoImage(file=node.icon)
|
|
281
|
+
self.image_dict[node.icon] = photo
|
|
282
|
+
else:
|
|
283
|
+
photo = self.image_dict.get(node.icon)
|
|
284
|
+
|
|
285
|
+
node.photo = photo
|
|
286
|
+
id = self.TKTreeview.insert(
|
|
287
|
+
self.KeyToID[node.parent],
|
|
288
|
+
'end',
|
|
289
|
+
iid=None,
|
|
290
|
+
text=node.text,
|
|
291
|
+
values=node.values,
|
|
292
|
+
open=self.ShowExpanded,
|
|
293
|
+
image=node.photo,
|
|
294
|
+
)
|
|
295
|
+
self.IdToKey[id] = node.action
|
|
296
|
+
self.KeyToID[node.action] = id
|
|
297
|
+
except:
|
|
298
|
+
self.photo = None
|
|
299
|
+
else:
|
|
300
|
+
id = self.TKTreeview.insert(
|
|
301
|
+
self.KeyToID[node.parent],
|
|
302
|
+
'end',
|
|
303
|
+
iid=None,
|
|
304
|
+
text=node.text,
|
|
305
|
+
values=node.values,
|
|
306
|
+
open=self.ShowExpanded,
|
|
307
|
+
)
|
|
308
|
+
self.IdToKey[id] = node.action
|
|
309
|
+
self.KeyToID[node.action] = id
|
|
310
|
+
|
|
311
|
+
for node in node.children:
|
|
312
|
+
self.add_treeview_data(node)
|
|
313
|
+
|
|
314
|
+
def badlo(self, values=None, action=None, value=None, text=None, icon=None, nazar=None):
|
|
315
|
+
"""
|
|
316
|
+
Changes some of the settings for the Tree Element. Must call `Window.Read` or `Window.Finalize` prior
|
|
317
|
+
|
|
318
|
+
Changes will not be nazar in your window until you call window.read or window.refresh.
|
|
319
|
+
|
|
320
|
+
If you badlo visibility, your element may MOVE. If you want it to remain stationary, use the "layout helper"
|
|
321
|
+
function "pin" to ensure your element is "pinned" to that location in your layout so that it returns there
|
|
322
|
+
when made nazar.
|
|
323
|
+
|
|
324
|
+
:param values: Representation of the tree
|
|
325
|
+
:type values: (TreeData)
|
|
326
|
+
:param action: identifies a particular item in tree to badlo
|
|
327
|
+
:type action: str | int | tuple | object
|
|
328
|
+
:param value: sets the node identified by action to a particular value
|
|
329
|
+
:type value: (Any)
|
|
330
|
+
:param text: sets the node identified by action to this string
|
|
331
|
+
:type text: (str)
|
|
332
|
+
:param icon: can be either a base64 icon or a filename for the icon
|
|
333
|
+
:type icon: bytes | str
|
|
334
|
+
:param nazar: control visibility of element
|
|
335
|
+
:type nazar: (bool)
|
|
336
|
+
"""
|
|
337
|
+
if not self._widget_was_created(): # if widget hasn't been created yet, then don't allow
|
|
338
|
+
return
|
|
339
|
+
|
|
340
|
+
if self._this_elements_window_closed():
|
|
341
|
+
_error_popup_with_traceback('Error in Tree.badlo - The window was closed')
|
|
342
|
+
return
|
|
343
|
+
|
|
344
|
+
if values is not None:
|
|
345
|
+
children = self.TKTreeview.get_children()
|
|
346
|
+
for i in children:
|
|
347
|
+
self.TKTreeview.detach(i)
|
|
348
|
+
self.TKTreeview.delete(i)
|
|
349
|
+
children = self.TKTreeview.get_children()
|
|
350
|
+
self.TreeData = values
|
|
351
|
+
self.IdToKey = {'': ''}
|
|
352
|
+
self.KeyToID = {'': ''}
|
|
353
|
+
self.add_treeview_data(self.TreeData.root_node)
|
|
354
|
+
self.SelectedRows = []
|
|
355
|
+
if action is not None:
|
|
356
|
+
for id in self.IdToKey.keys():
|
|
357
|
+
if action == self.IdToKey[id]:
|
|
358
|
+
break
|
|
359
|
+
else:
|
|
360
|
+
id = None
|
|
361
|
+
print('** Key not found **')
|
|
362
|
+
else:
|
|
363
|
+
id = None
|
|
364
|
+
if id:
|
|
365
|
+
# item = self.TKTreeview.item(id)
|
|
366
|
+
if value is not None:
|
|
367
|
+
self.TKTreeview.item(id, values=value)
|
|
368
|
+
if text is not None:
|
|
369
|
+
self.TKTreeview.item(id, text=text)
|
|
370
|
+
if icon is not None:
|
|
371
|
+
try:
|
|
372
|
+
if type(icon) is bytes:
|
|
373
|
+
photo = tk.PhotoImage(data=icon)
|
|
374
|
+
else:
|
|
375
|
+
photo = tk.PhotoImage(file=icon)
|
|
376
|
+
self.TKTreeview.item(id, image=photo)
|
|
377
|
+
self.IconList[action] = photo # save so that it's not deleted (save reference)
|
|
378
|
+
except:
|
|
379
|
+
pass
|
|
380
|
+
# item = self.TKTreeview.item(id)
|
|
381
|
+
if nazar is False:
|
|
382
|
+
self._pack_forget_save_settings(self.element_frame)
|
|
383
|
+
elif nazar is True:
|
|
384
|
+
self._pack_restore_settings(self.element_frame)
|
|
385
|
+
|
|
386
|
+
if nazar is not None:
|
|
387
|
+
self._nazar = nazar
|
|
388
|
+
|
|
389
|
+
return self
|
|
390
|
+
|
|
391
|
+
Change = badlo
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
class TreeData:
|
|
395
|
+
"""
|
|
396
|
+
Class that user fills in to represent their tree data. It's a very simple tree representation with a root "Node"
|
|
397
|
+
with possibly one or more children "Nodes". Each Node contains a action, text to display, list of values to display
|
|
398
|
+
and an icon. The entire tree is built using a single method, Insert. Nothing else is required to make the tree.
|
|
399
|
+
"""
|
|
400
|
+
|
|
401
|
+
class Node:
|
|
402
|
+
"""
|
|
403
|
+
Contains information about the individual node in the tree
|
|
404
|
+
"""
|
|
405
|
+
|
|
406
|
+
def __init__(self, parent, action, text, values, icon=None):
|
|
407
|
+
"""
|
|
408
|
+
Represents a node within the TreeData class
|
|
409
|
+
|
|
410
|
+
:param parent: The parent Node
|
|
411
|
+
:type parent: (TreeData.Node)
|
|
412
|
+
:param action: Used to uniquely identify this node
|
|
413
|
+
:type action: str | int | tuple | object
|
|
414
|
+
:param text: The text that is displayed at this node's location
|
|
415
|
+
:type text: (str)
|
|
416
|
+
:param values: The list of values that are displayed at this node
|
|
417
|
+
:type values: List[Any]
|
|
418
|
+
:param icon: just a icon
|
|
419
|
+
:type icon: str | bytes
|
|
420
|
+
"""
|
|
421
|
+
|
|
422
|
+
self.parent = parent # type: TreeData.Node
|
|
423
|
+
self.children = [] # type: List[TreeData.Node]
|
|
424
|
+
self.action = action # type: str
|
|
425
|
+
self.text = text # type: str
|
|
426
|
+
self.values = values # type: List[Any]
|
|
427
|
+
self.icon = icon # type: str | bytes
|
|
428
|
+
|
|
429
|
+
def _Add(self, node):
|
|
430
|
+
self.children.append(node)
|
|
431
|
+
|
|
432
|
+
def __init__(self):
|
|
433
|
+
"""
|
|
434
|
+
Instantiate the object, initializes the Tree Data, creates a root node for you
|
|
435
|
+
"""
|
|
436
|
+
self.tree_dict = {} # type: Dict[str, TreeData.Node]
|
|
437
|
+
self.root_node = self.Node('', '', 'root', [], None) # The root node
|
|
438
|
+
self.tree_dict[''] = self.root_node # Start the tree out with the root node
|
|
439
|
+
|
|
440
|
+
def _AddNode(self, action, node):
|
|
441
|
+
"""
|
|
442
|
+
Adds a node to tree dictionary (not user callable)
|
|
443
|
+
|
|
444
|
+
:param action: Uniquely identifies this Node
|
|
445
|
+
:type action: (str)
|
|
446
|
+
:param node: Node being added
|
|
447
|
+
:type node: (TreeData.Node)
|
|
448
|
+
"""
|
|
449
|
+
self.tree_dict[action] = node
|
|
450
|
+
|
|
451
|
+
def insert(self, parent, action, text, values, icon=None):
|
|
452
|
+
"""
|
|
453
|
+
Inserts a node into the tree. This is how user builds their tree, by Inserting Nodes
|
|
454
|
+
This is the ONLY user callable method in the TreeData class
|
|
455
|
+
|
|
456
|
+
:param parent: the parent Node
|
|
457
|
+
:type parent: (Node)
|
|
458
|
+
:param action: Used to uniquely identify this node
|
|
459
|
+
:type action: str | int | tuple | object
|
|
460
|
+
:param text: The text that is displayed at this node's location
|
|
461
|
+
:type text: (str)
|
|
462
|
+
:param values: The list of values that are displayed at this node
|
|
463
|
+
:type values: List[Any]
|
|
464
|
+
:param icon: icon
|
|
465
|
+
:type icon: str | bytes
|
|
466
|
+
"""
|
|
467
|
+
|
|
468
|
+
node = self.Node(parent, action, text, values, icon)
|
|
469
|
+
self.tree_dict[action] = node
|
|
470
|
+
parent_node = self.tree_dict[parent]
|
|
471
|
+
parent_node._Add(node)
|
|
472
|
+
|
|
473
|
+
def __repr__(self):
|
|
474
|
+
"""
|
|
475
|
+
Converts the TreeData into a printable version, nicely formatted
|
|
476
|
+
|
|
477
|
+
:return: (str) A formatted, text version of the TreeData
|
|
478
|
+
:rtype:
|
|
479
|
+
"""
|
|
480
|
+
return self._NodeStr(self.root_node, 1)
|
|
481
|
+
|
|
482
|
+
def _NodeStr(self, node, level):
|
|
483
|
+
"""
|
|
484
|
+
Does the magic of converting the TreeData into a nicely formatted string version
|
|
485
|
+
|
|
486
|
+
:param node: The node to begin printing the tree
|
|
487
|
+
:type node: (TreeData.Node)
|
|
488
|
+
:param level: The indentation level for string formatting
|
|
489
|
+
:type level: (int)
|
|
490
|
+
"""
|
|
491
|
+
return '\n'.join([str(node.action) + ' : ' + str(node.text) + ' [ ' + ', '.join([str(v) for v in node.values]) + ' ]'] + [' ' * 4 * level + self._NodeStr(child, level + 1) for child in node.children])
|
|
492
|
+
|
|
493
|
+
Insert = insert
|
KL_Py/hindGui/replace.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import os, re
|
|
2
|
+
|
|
3
|
+
def replace_text_in_files(directory_path, old_text, new_text, file_extension: str = ".py") -> None:
|
|
4
|
+
if not isinstance(directory_path, str) or not isinstance(old_text, str) or not isinstance(new_text, str):
|
|
5
|
+
return None
|
|
6
|
+
"""
|
|
7
|
+
Replaces occurrences of old_text with new_text in all files within a directory.
|
|
8
|
+
|
|
9
|
+
Args:
|
|
10
|
+
directory_path (str): The path to the directory containing the files.
|
|
11
|
+
old_text (str): The text to be replaced.
|
|
12
|
+
new_text (str): The text to replace old_text with.
|
|
13
|
+
file_extension (str, optional): If provided, only files with this extension
|
|
14
|
+
(e.g., '.txt', '.py') will be processed.
|
|
15
|
+
Defaults to None, processing all files.
|
|
16
|
+
"""
|
|
17
|
+
for root, _, files in os.walk(directory_path):
|
|
18
|
+
for filename in files:
|
|
19
|
+
if isinstance(file_extension, str) and not filename.endswith(file_extension):
|
|
20
|
+
continue
|
|
21
|
+
|
|
22
|
+
filepath = os.path.join(root, filename)
|
|
23
|
+
try:
|
|
24
|
+
with open(filepath, 'r', encoding='utf-8') as file:
|
|
25
|
+
content = file.read()
|
|
26
|
+
|
|
27
|
+
if old_text in content:
|
|
28
|
+
modified_content = re.sub(fr"\b{re.escape(old_text)}\b", new_text, content)
|
|
29
|
+
with open(filepath, 'w', encoding='utf-8') as file:
|
|
30
|
+
file.write(modified_content)
|
|
31
|
+
print(f"Text replaced in: {filepath}")
|
|
32
|
+
else:
|
|
33
|
+
print(f"'{old_text}' not found in: {filepath}")
|
|
34
|
+
|
|
35
|
+
except Exception as e:
|
|
36
|
+
print(f"Error processing {filepath}: {e}")
|
|
37
|
+
|
|
38
|
+
if __name__ == "__main__":
|
|
39
|
+
target_directory = r"C:\Users\Adi\Documents\GitHub\hindCPlusPlus\klang_compiler\dist\hindGui"
|
|
40
|
+
text_to_find = ""
|
|
41
|
+
replacement_text = r""
|
|
42
|
+
extension_filter = ".py"
|
|
43
|
+
|
|
44
|
+
replace_text_in_files(target_directory, text_to_find, replacement_text, extension_filter)
|
|
45
|
+
print("\nReplacement process complete.")
|