PyObjectInterface 0.1.1rc0__py3-none-any.whl → 0.1.1rc2__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.
@@ -11,19 +11,23 @@ def generate_html(poi: PyObjectInterface, font_size=2.5):
11
11
  """
12
12
  buttons = ""
13
13
  for method_name, func_desc in poi.method_dict.items():
14
- stack = poi.base_obj_name + '.' + method_name
15
- onclick = f'call_method("{stack}")'
16
- buttons += f"<button class='nice_button' onclick={onclick}>{method_name}</button>"
17
- for arg_name, default in zip(func_desc.args, func_desc.defaults):
18
- className = 'py_' + stack
19
- elemID = className + '|' + arg_name
20
- buttons += f"<span class='input_label'>{arg_name}</span>"
21
- if len(default) > 0 and default[0] == "'":
22
- default = '"' + default[1:-1] + '"'
23
- buttons += f"<input id='{elemID}' class='{className}' value='{default}'>"
24
- if func_desc.desc is not None:
25
- desc = str(func_desc.desc).strip().replace('\n','<br>')
26
- buttons += f"<p>{desc}</p>"
14
+ if func_desc.builtin_err:
15
+ buttons += f"<p>{method_name} is a builtin method and can't be accessed from WebController</p>"
16
+
17
+ else:
18
+ stack = poi.base_obj_name + '.' + method_name
19
+ onclick = f'call_method("{stack}")'
20
+ buttons += f"<button class='nice_button' onclick={onclick}>{method_name}</button>"
21
+ for arg_name, default in zip(func_desc.args, func_desc.defaults):
22
+ className = 'py_' + stack
23
+ elemID = className + '|' + arg_name
24
+ buttons += f"<span class='input_label'>{arg_name}</span>"
25
+ if len(default) > 0 and default[0] == "'":
26
+ default = '"' + default[1:-1] + '"'
27
+ buttons += f"<input id='{elemID}' class='{className}' value='{default}'>"
28
+ if func_desc.desc is not None:
29
+ desc = str(func_desc.desc).strip().replace('\n','<br>')
30
+ buttons += f"<p>{desc}</p>"
27
31
  buttons += "<br>"
28
32
 
29
33
  attr_table = ""
@@ -1,10 +1,27 @@
1
1
  from typing_extensions import Self
2
2
  import inspect
3
3
 
4
+ # {type: examine_recursively}
5
+ basic_attribute_types = {
6
+ str(type(None)): False, #NoneType
7
+ str(type(True)): False, #bool
8
+ str(type(1)): False, #int
9
+ str(type(1.0)): False, #float
10
+ str(type('1')): False, #str
11
+ str(type([1])): False, #list
12
+ str(type({1:1})): False, #dict
13
+ str(type((1,1))): False, #tuple
14
+ str(type({1})): False, #set
15
+ "<class 'numpy.ndarray'>": False,
16
+ "<class 'pandas.core.frame.DataFrame'>": False,
17
+ "<class 'pandas.core.series.Series'>": False
18
+ }
19
+
4
20
  class FunctionDesc:
5
21
  def __init__(self, func):
6
22
  self.func = func
7
23
  self.desc = func.__doc__
24
+ self.builtin_err = False
8
25
 
9
26
  try:
10
27
  params = inspect.signature(func).parameters
@@ -12,7 +29,7 @@ class FunctionDesc:
12
29
  except ValueError:
13
30
  params = []
14
31
  self.args = []
15
- self.func += ' **builtin (not callable from webcontroller)**'
32
+ self.builtin_err = True
16
33
 
17
34
  self.defaults = []
18
35
  for arg in self.args:
@@ -47,12 +64,14 @@ class PyObjectInterface:
47
64
  all_attrs = [x for x in inspect.getmembers(obj) if x[0][0:1] != '_'] #ignore private
48
65
 
49
66
  for (attr_name, instance) in all_attrs:
67
+ if str(type(instance)) in basic_attribute_types:
68
+ self.attribute_list.append(attr_name)
69
+ if not basic_attribute_types[str(type(instance))]:
70
+ continue #skip the rest of the checks, we don't want to examine this item recursively
71
+
50
72
  if hasattr(instance, '__call__'):
51
73
  self.method_dict[attr_name] = FunctionDesc(instance)
52
74
 
53
- elif isinstance(instance, (int, float, str, bool, list, dict)) or instance is None:
54
- self.attribute_list.append(attr_name)
55
-
56
75
  elif recursion_depth > 0: #stop adding subobjects at recursion depth 0
57
76
  # using .__class__ allows superclassing
58
77
  # noinspection PyTypeChecker
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyObjectInterface
3
- Version: 0.1.1rc0
3
+ Version: 0.1.1rc2
4
4
  Summary: Create a web interface to interact with a class
5
5
  Home-page: https://github.com/RobertJN64/PyObjectInterface
6
6
  Author: Robert Nies
@@ -77,3 +77,29 @@ You can use PyObjectInterface without the WebController.
77
77
  - `flask_app`: return value of flask.Flask()
78
78
  - `recursion_depth = 5`: maximum layers of subobjects to include
79
79
  - `create_private_interface = True`: if `True` creates a `/webcontroller/private` page that includes private methods and attributes
80
+
81
+ ### Modifying Attributes
82
+
83
+ By default, POI treats `NoneType, bool, int, float, str, list, dict, tuple, and set` as primitive types.
84
+ These show up in the attribute table instead of as recursive objects.
85
+
86
+ `numpy.ndarray`, `pandas.DataFrame`, and `pandas.Series` are also treated as primitives.
87
+
88
+ If you would like to customize this behavior, you can modify
89
+ `PyObjectInterface.basic_attribute_types`
90
+
91
+ For example:
92
+ ```python
93
+ from PyObjectInterface import basic_attribute_types
94
+
95
+ class My_Class_A: ...
96
+ class My_Class_B: ...
97
+ class My_Class_C: ...
98
+
99
+ basic_attribute_types[str(type(My_Class_A()))] = False
100
+ basic_attribute_types[str(type(My_Class_B()))] = True
101
+ ```
102
+
103
+ `My_Class_A` will be treated as a primitive and only show up in the attributes table.
104
+ `My_Class_B` will also show up in attributes table, but it still appears in the subobjects section.
105
+ `My_Class_C` will only appear in the subobjects section.
@@ -0,0 +1,10 @@
1
+ PyObjectInterface/WebController.py,sha256=yLiOsR-FE01omdw2DHVQhltMvAhvWus3eP1zPQ2vM34,4034
2
+ PyObjectInterface/__init__.py,sha256=CBCFR8yJkR7WvEjCjUS3n8UoWijvx89ZpF0yrrYMPeE,4496
3
+ PyObjectInterface/web_controller.tpl.html,sha256=KiNOmUGwsyAmkV9yol2X15G6uoAPjf2JHa6tnoCe_kw,2432
4
+ PyObjectInterface/examples/example.py,sha256=QhAcJJnh6LU923TL7MHwYU5keur1hgfn7Elt5nh8c-E,196
5
+ PyObjectInterface/examples/robot.py,sha256=qvDhIwvCtseA0AlEdZbR7RJkpbOMMw0F1C3UWNMs--M,655
6
+ PyObjectInterface-0.1.1rc2.dist-info/LICENSE,sha256=_UXYaTVmtWrJCpKEgCz66EUsoFfLfn0CY4mEmuI5_zA,1054
7
+ PyObjectInterface-0.1.1rc2.dist-info/METADATA,sha256=1OWyXDDw48Gb2ZcVANSyJ6BPs9h97w9L8htvAICEmtA,3459
8
+ PyObjectInterface-0.1.1rc2.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
9
+ PyObjectInterface-0.1.1rc2.dist-info/top_level.txt,sha256=5kOSl8l5D5IGWoWz9nkn_lQispA3D8qyPM9SvIC4LSU,18
10
+ PyObjectInterface-0.1.1rc2.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- PyObjectInterface/WebController.py,sha256=XPDrlcILDvgI7jREzYut7JD2DyNGpvOv4igDdeomPNs,3825
2
- PyObjectInterface/__init__.py,sha256=lSQMPD9qgpRIt4OzhuR6geYjmWmrmZBXl3zoX_mfJiM,3847
3
- PyObjectInterface/web_controller.tpl.html,sha256=KiNOmUGwsyAmkV9yol2X15G6uoAPjf2JHa6tnoCe_kw,2432
4
- PyObjectInterface/examples/example.py,sha256=QhAcJJnh6LU923TL7MHwYU5keur1hgfn7Elt5nh8c-E,196
5
- PyObjectInterface/examples/robot.py,sha256=qvDhIwvCtseA0AlEdZbR7RJkpbOMMw0F1C3UWNMs--M,655
6
- PyObjectInterface-0.1.1rc0.dist-info/LICENSE,sha256=_UXYaTVmtWrJCpKEgCz66EUsoFfLfn0CY4mEmuI5_zA,1054
7
- PyObjectInterface-0.1.1rc0.dist-info/METADATA,sha256=AHlCjSIUfVFzPBoFFVXEDyS6hE9hrJF1BDCkhsXDkbM,2562
8
- PyObjectInterface-0.1.1rc0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
9
- PyObjectInterface-0.1.1rc0.dist-info/top_level.txt,sha256=5kOSl8l5D5IGWoWz9nkn_lQispA3D8qyPM9SvIC4LSU,18
10
- PyObjectInterface-0.1.1rc0.dist-info/RECORD,,