QTPYGUI 1.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.
QTPYGUI/ __init__.py ADDED
File without changes
@@ -0,0 +1,92 @@
1
+ Copyright © 2017 IBM Corp. with Reserved Font Name "Plex"
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+ -----------------------------------------------------------
8
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
9
+ -----------------------------------------------------------
10
+
11
+ PREAMBLE
12
+ The goals of the Open Font License (OFL) are to stimulate worldwide
13
+ development of collaborative font projects, to support the font creation
14
+ efforts of academic and linguistic communities, and to provide a free and
15
+ open framework in which fonts may be shared and improved in partnership
16
+ with others.
17
+
18
+ The OFL allows the licensed fonts to be used, studied, modified and
19
+ redistributed freely as long as they are not sold by themselves. The
20
+ fonts, including any derivative works, can be bundled, embedded,
21
+ redistributed and/or sold with any software provided that any reserved
22
+ names are not used by derivative works. The fonts and derivatives,
23
+ however, cannot be released under any other type of license. The
24
+ requirement for fonts to remain under this license does not apply
25
+ to any document created using the fonts or their derivatives.
26
+
27
+ DEFINITIONS
28
+ "Font Software" refers to the set of files released by the Copyright
29
+ Holder(s) under this license and clearly marked as such. This may
30
+ include source files, build scripts and documentation.
31
+
32
+ "Reserved Font Name" refers to any names specified as such after the
33
+ copyright statement(s).
34
+
35
+ "Original Version" refers to the collection of Font Software components as
36
+ distributed by the Copyright Holder(s).
37
+
38
+ "Modified Version" refers to any derivative made by adding to, deleting,
39
+ or substituting -- in part or in whole -- any of the components of the
40
+ Original Version, by changing formats or by porting the Font Software to a
41
+ new environment.
42
+
43
+ "Author" refers to any designer, engineer, programmer, technical
44
+ writer or other person who contributed to the Font Software.
45
+
46
+ PERMISSION & CONDITIONS
47
+ Permission is hereby granted, free of charge, to any person obtaining
48
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
49
+ redistribute, and sell modified and unmodified copies of the Font
50
+ Software, subject to the following conditions:
51
+
52
+ 1) Neither the Font Software nor any of its individual components,
53
+ in Original or Modified Versions, may be sold by itself.
54
+
55
+ 2) Original or Modified Versions of the Font Software may be bundled,
56
+ redistributed and/or sold with any software, provided that each copy
57
+ contains the above copyright notice and this license. These can be
58
+ included either as stand-alone text files, human-readable headers or
59
+ in the appropriate machine-readable metadata fields within text or
60
+ binary files as long as those fields can be easily viewed by the user.
61
+
62
+ 3) No Modified Version of the Font Software may use the Reserved Font
63
+ Name(s) unless explicit written permission is granted by the corresponding
64
+ Copyright Holder. This restriction only applies to the primary font name as
65
+ presented to the users.
66
+
67
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
68
+ Software shall not be used to promote, endorse or advertise any
69
+ Modified Version, except to acknowledge the contribution(s) of the
70
+ Copyright Holder(s) and the Author(s) or with their explicit written
71
+ permission.
72
+
73
+ 5) The Font Software, modified or unmodified, in part or in whole,
74
+ must be distributed entirely under this license, and must not be
75
+ distributed under any other license. The requirement for fonts to
76
+ remain under this license does not apply to any document created
77
+ using the Font Software.
78
+
79
+ TERMINATION
80
+ This license becomes null and void if any of the above conditions are
81
+ not met.
82
+
83
+ DISCLAIMER
84
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
85
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
86
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
87
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
88
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
89
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
90
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
91
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
92
+ OTHER DEALINGS IN THE FONT SOFTWARE.
QTPYGUI/auto_doco.py ADDED
@@ -0,0 +1,393 @@
1
+ import ast
2
+ from pathlib import Path
3
+
4
+
5
+ from src.file_utils import File
6
+
7
+
8
+ py_file = Path("../src/qtpygui.py")
9
+ raw_tree = py_file.read_text()
10
+ tree = ast.parse(raw_tree)
11
+ class_dict = {}
12
+
13
+
14
+ def docostring_parser(docstring: str) -> dict:
15
+ doclines = docstring.splitlines()
16
+ parsed_docstring_dict = {"definition": "", "args": [], "returns": []}
17
+
18
+ arg_on = False
19
+ return_on = False
20
+
21
+ definition_line = ""
22
+ arg_definition = ""
23
+ arg_name_base = ""
24
+ args = []
25
+ for docline in doclines:
26
+ if docline.replace(":", "").startswith("Args") or docline.replace(
27
+ ":", ""
28
+ ).startswith("Parameters"):
29
+ arg_on = True
30
+ return_on = False
31
+
32
+ if docline.replace(":", "").startswith("Returns"):
33
+ arg_on = False
34
+ return_on = True
35
+
36
+ if not arg_on and not return_on:
37
+ definition_line += docline + "<br>"
38
+
39
+ if arg_on:
40
+ if ":" in docline:
41
+ args = []
42
+ # args.append(arg_name_base + ":" + arg_definition)
43
+ arg_name_base = docline.split(":")[0].strip()
44
+ arg_definition = docline.split(":")[1].strip()
45
+
46
+ arg_name = arg_name_base
47
+ arg_type = ""
48
+ if "(" and ")" in arg_name_base:
49
+ arg_name = arg_name_base.split("(")[0]
50
+ arg_type = arg_name_base.split("(")[1].replace(")", "")
51
+
52
+ args.append([arg_name, arg_type, arg_definition])
53
+ parsed_docstring_dict["args"].append(args)
54
+ else:
55
+ args[-1][2] += docline
56
+ arg_definition += docline
57
+ if return_on:
58
+ return_type = docline
59
+ return_desc = ""
60
+ if ":" in docline:
61
+ return_type = docline.split(":")[0].strip()
62
+ return_desc = docline.split(":")[1].strip()
63
+
64
+ parsed_docstring_dict["returns"].append((return_type, return_desc))
65
+
66
+ return parsed_docstring_dict
67
+
68
+
69
+ def get_public_instance_variables(node):
70
+ """
71
+ Extracts public instance variables (attributes) from a class definition node.
72
+
73
+ Args:
74
+ node (ast.AST): The class definition node from the parsed AST.
75
+
76
+ Returns:
77
+ list: A list of strings representing the public instance variable names.
78
+ """
79
+ public_vars = []
80
+
81
+ # Look for assignments and directly defined attributes
82
+ for body_node in node.body:
83
+ if isinstance(body_node, (ast.Assign)):
84
+ # Handle assignments within the class body
85
+ # target = body_node.target # Use singular target for AnnAssign
86
+ for x in body_node.targets:
87
+ if isinstance(x, ast.Name):
88
+ print(x.id)
89
+ if x is not None and x.attr is not None and x.attr.startswith("_"):
90
+ print(x.attr)
91
+ public_vars.append(x.attr)
92
+
93
+ # Handle multiple assignments with various value structures
94
+ if isinstance(body_node, ast.Assign) and len(body_node.targets) > 1:
95
+ for i, target in enumerate(body_node.targets):
96
+ if isinstance(target, ast.Attribute) and not target.attr.startswith(
97
+ "_"
98
+ ):
99
+ public_vars.append(target.attr)
100
+ elif isinstance(body_node.value, (ast.Tuple, ast.List)):
101
+ if i < len(body_node.value.elts):
102
+ value_part = body_node.value.elts[i]
103
+ if isinstance(
104
+ value_part, ast.Name
105
+ ): # Simple variable assignment
106
+ public_vars.append(value_part.id)
107
+
108
+ # Check for directly defined attributes
109
+ elif isinstance(body_node, ast.Expr):
110
+ if isinstance(
111
+ body_node.value, ast.Attribute
112
+ ): # Check for attribute definition
113
+ if not body_node.value.attr.startswith(
114
+ "_"
115
+ ): # Public attribute (doesn't start with underscore)
116
+ public_vars.append(body_node.value.attr)
117
+ print(public_vars)
118
+ return public_vars
119
+
120
+
121
+ def get_type(annotation):
122
+ if isinstance(annotation, ast.Name):
123
+ return annotation.id
124
+ elif isinstance(annotation, ast.Attribute):
125
+ return f"{annotation.value.id}.{annotation.attr}"
126
+ elif isinstance(annotation, ast.Call):
127
+ if annotation.func.id == "Union":
128
+ return f"Union[{', '.join(get_type(arg) for arg in annotation.args)}]"
129
+ elif isinstance(annotation, ast.Subscript):
130
+ if isinstance(annotation.slice, ast.Slice):
131
+ slice_info = f"{annotation.value.id}[{get_type(annotation.slice.lower) if annotation.slice.lower else ''}:{get_type(annotation.slice.upper) if annotation.slice.upper else ''}:{get_type(annotation.slice.step) if annotation.slice.step else ''}]"
132
+ return slice_info
133
+ elif isinstance(annotation.slice, ast.Index):
134
+ return f"{annotation.value.id}[{get_type(annotation.slice.value)}]"
135
+ elif isinstance(annotation.slice, ast.ExtSlice):
136
+ dims = [get_type(dim) for dim in annotation.slice.dims]
137
+ return f"{annotation.value.id}[{', '.join(dims)}]"
138
+ else:
139
+ return f"{annotation.value.id}[{get_type(annotation.slice)}]"
140
+ elif isinstance(annotation, ast.Tuple):
141
+ elements = [get_type(elt) for elt in annotation.elts]
142
+ return f"({', '.join(elements)})"
143
+ elif isinstance(annotation, ast.List):
144
+ return f"[{', '.join(get_type(elt) for elt in annotation.elts)}]"
145
+ elif isinstance(annotation, ast.Dict):
146
+ keys = [get_type(key) for key in annotation.keys]
147
+ values = [get_type(value) for value in annotation.values]
148
+ return f"{{{', '.join(f'{k}: {v}' for k, v in zip(keys, values))}}}"
149
+ elif isinstance(annotation, ast.BinOp):
150
+ left_type = get_type(annotation.left)
151
+ right_type = get_type(annotation.right)
152
+ return f"({left_type} {type(annotation.op).__name__} {right_type})"
153
+ elif isinstance(annotation, ast.FunctionType):
154
+ return f"Callable[[{', '.join(get_type(arg) for arg in annotation.args)}], {get_type(annotation.returns)}]"
155
+ elif isinstance(annotation, ast.Constant):
156
+ return str(annotation.value)
157
+ else:
158
+ return str(annotation)
159
+
160
+
161
+ def get_class_methods(node, current_path=[], level=1):
162
+ """
163
+ Recursive function to analyze methods within a class definition node.
164
+
165
+ Args:
166
+ node (ast.AST): The current node in the AST.
167
+
168
+ Returns:
169
+ list: A list of dictionaries containing method information:
170
+ - name (str): Name of the method
171
+ - docstring (str): Docstring of the method (if present)
172
+ - args (list): List of dictionaries for arguments:
173
+ - name (str): Name of the argument
174
+ - type_annotation (str, None): Type annotation (if present)
175
+ - return_type (str, None): Return type annotation (if present)
176
+ """
177
+
178
+ methods = []
179
+ method_info = {}
180
+
181
+ for child in node.body:
182
+ if isinstance(child, ast.FunctionDef):
183
+ method_info = {
184
+ "name": child.name,
185
+ "docstring": ast.get_docstring(child), # Get docstring (if present)
186
+ "args": [],
187
+ "vars": [],
188
+ "return_type": None,
189
+ "path": current_path.copy(),
190
+ }
191
+ method_info["path"].append(node.name) # Add current class to path
192
+
193
+ for arg in child.args.args:
194
+ arg_info = {"name": arg.arg, "type_annotation": None}
195
+
196
+ if (
197
+ hasattr(arg, "annotation") and arg.annotation is not None
198
+ ): # Check for type annotation
199
+ if hasattr(arg.annotation, "id"):
200
+ arg_info["type_annotation"] = (
201
+ arg.annotation.id
202
+ ) # Extract type name
203
+ method_info["args"].append(arg_info)
204
+
205
+ if child.returns: # Check for return type annotation
206
+ method_info["return_type"] = (
207
+ child.returns.id if hasattr(child.returns, "id") else None
208
+ )
209
+ methods.append(method_info)
210
+ elif isinstance(child, ast.AnnAssign):
211
+ # Extract instance variables from dataclass fields
212
+ # if child.target.id != '_USER_DATA':
213
+ # print(f"DBG {child.target.id} On {node.name} ")
214
+ # print(f"DBG {get_type(child.annotation)}")
215
+ print(f"DBG {node.name}, {child.target.id, get_type(child.annotation)}")
216
+
217
+ elif isinstance(child, ast.ClassDef):
218
+ # Recursively search for methods within nested classes
219
+ methods.extend(
220
+ get_class_methods(child, current_path + [node.name], level + 1)
221
+ )
222
+
223
+ return methods
224
+
225
+
226
+ def split_line_by_words(line, max_width=80):
227
+ """
228
+ Splits a line of text into multiple lines, breaking around words
229
+ and ensuring each line is no wider than the specified width.
230
+
231
+ Args:
232
+ line (str): The line of text to split.
233
+ max_width (int, optional): The maximum width of each line. Defaults to 80.
234
+
235
+ Returns:
236
+ list: A list of strings representing the split lines.
237
+ """
238
+
239
+ words = line.split()
240
+ current_line = ""
241
+ split_lines = []
242
+
243
+ for word in words:
244
+ if len(current_line) + len(word) + 1 <= max_width: # Add 1 for space
245
+ current_line += f" {word}" # Prepend space for all except first word
246
+ else:
247
+ split_lines.append(
248
+ current_line.strip()
249
+ ) # Add previous line without trailing space
250
+ current_line = word
251
+
252
+ # Add the last line (if any)
253
+ if current_line:
254
+ split_lines.append(current_line)
255
+
256
+ return split_lines
257
+
258
+
259
+ def write_table_to_file(table_rows: list[str]):
260
+ file_utils = File()
261
+
262
+ doco_path = "./doco"
263
+ if not file_utils.path_exists(doco_path):
264
+ file_utils.make_dir(doco_path)
265
+
266
+ classy_list = []
267
+ classy_name = ""
268
+ for table_row in table_rows:
269
+ if table_row.startswith("###"):
270
+ classy_name = table_row.split("###")[1]
271
+
272
+ classy_list.append(table_row)
273
+
274
+ if classy_list:
275
+ result, message = file_utils.write_list_to_txt_file(
276
+ str_list=classy_list, text_file=f"{doco_path}/{classy_name}.md"
277
+ )
278
+
279
+
280
+ if __name__ == "__main__":
281
+ class_methods = []
282
+
283
+ for node in tree.body:
284
+ if isinstance(node, ast.ClassDef):
285
+ class_methods.append({
286
+ "class_name": node.name,
287
+ "docstring": ast.get_docstring(node, clean=True),
288
+ "methods": get_class_methods(node),
289
+ })
290
+
291
+ for class_info in class_methods:
292
+ if (
293
+ class_info["class_name"].startswith("_")
294
+ and class_info["class_name"].strip() != "_qtpyBase_Control"
295
+ ):
296
+ continue
297
+
298
+ docstring = ""
299
+
300
+ if class_info["docstring"] is not None:
301
+ docstring_list = split_line_by_words(
302
+ class_info["docstring"].replace("\n", "<br>")
303
+ )
304
+
305
+ for string_index, string in enumerate(docstring_list):
306
+ docstring = (
307
+ docstring + string + "<br>"
308
+ if string_index != len(docstring_list) - 1
309
+ and not string.endswith("<br>")
310
+ else docstring + string
311
+ )
312
+
313
+ table_rows = [f"### {class_info['class_name']}", " ", f"{docstring}", " "]
314
+
315
+ for class_key, class_values in class_info.items():
316
+ if class_key == "class_name":
317
+ table_rows.append(
318
+ "| **Method** | **Arguments** | **Type** | **Description** | **Optional** |"
319
+ )
320
+ table_rows.append(
321
+ "|------------|---------------|----------|-----------------|--------------|"
322
+ ) # Separator line
323
+
324
+ if class_key == "methods":
325
+ class_info["methods"].sort(key=lambda x: x["name"])
326
+ for method in class_info["methods"]:
327
+ if (
328
+ method["name"].startswith("_")
329
+ and method["name"].strip() != "init"
330
+ ):
331
+ continue
332
+
333
+ parsed_doc_string = {}
334
+ method_docstring = ""
335
+
336
+ if method["docstring"] is not None:
337
+ parsed_doc_string = docostring_parser(method["docstring"])
338
+ # method_docstring = parsed_doc_string["definition"]
339
+ docstring_list = split_line_by_words(
340
+ parsed_doc_string["definition"].replace("\n", "<br>", 60)
341
+ )
342
+
343
+ for string_index, string in enumerate(docstring_list):
344
+ method_docstring = (
345
+ method_docstring + string + "<br>"
346
+ if string_index != len(docstring_list) - 1
347
+ and not string.endswith("<br>")
348
+ else method_docstring + string
349
+ )
350
+
351
+ return_doc_string = ""
352
+
353
+ for doc_string in parsed_doc_string["returns"]:
354
+ doc_string_type = (
355
+ f"{doc_string[0]}:" if doc_string[0] else ""
356
+ )
357
+ if doc_string[1].strip().strip() and doc_string[1].strip():
358
+ # return_doc_string += f"{doc_string_type} {doc_string[1]}<br>"
359
+ return_doc_string += f"{doc_string[1]}<br>"
360
+
361
+ if return_doc_string:
362
+ if (
363
+ return_doc_string.strip()
364
+ and return_doc_string.strip() != ":"
365
+ ):
366
+ method_docstring += (
367
+ f"<br><b>Returns:</b><br> {return_doc_string}"
368
+ )
369
+
370
+ table_rows.append(
371
+ f"|{method['name']}||{method['return_type']}|{method_docstring}||"
372
+ )
373
+
374
+ if parsed_doc_string:
375
+ # print(parsed_doc_string["args"])
376
+ pass
377
+
378
+ method["args"].sort(key=lambda x: x["name"])
379
+ for arg in method["args"]:
380
+ arg_definition = ""
381
+ if parsed_doc_string:
382
+ for doc_args in parsed_doc_string["args"]:
383
+ for doc_arg in doc_args:
384
+ if (
385
+ arg["name"].strip().lower()
386
+ == doc_arg[0].strip().lower()
387
+ ):
388
+ arg_definition = doc_arg[2]
389
+ table_rows.append(
390
+ f"||{arg['name']}|{arg['type_annotation']}|{arg_definition}||"
391
+ )
392
+
393
+ write_table_to_file(table_rows=table_rows)
QTPYGUI/backspace.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!-- Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) --><path d="M576 64H205.26A63.97 63.97 0 0 0 160 82.75L9.37 233.37c-12.5 12.5-12.5 32.76 0 45.25L160 429.25c12 12 28.28 18.75 45.25 18.75H576c35.35 0 64-28.65 64-64V128c0-35.35-28.65-64-64-64zm-84.69 254.06c6.25 6.25 6.25 16.38 0 22.63l-22.62 22.62c-6.25 6.25-16.38 6.25-22.63 0L384 301.25l-62.06 62.06c-6.25 6.25-16.38 6.25-22.63 0l-22.62-22.62c-6.25-6.25-6.25-16.38 0-22.63L338.75 256l-62.06-62.06c-6.25-6.25-6.25-16.38 0-22.63l22.62-22.62c6.25-6.25 16.38-6.25 22.63 0L384 210.75l62.06-62.06c6.25-6.25 16.38-6.25 22.63 0l22.62 22.62c6.25 6.25 6.25 16.38 0 22.63L429.25 256l62.06 62.06z"/></svg>