pyobject 1.2.3.2__tar.gz → 1.2.4__tar.gz

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 (43) hide show
  1. {pyobject-1.2.3.2/pyobject.egg-info → pyobject-1.2.4}/PKG-INFO +31 -21
  2. {pyobject-1.2.3.2 → pyobject-1.2.4}/README.rst +29 -18
  3. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/__init__.py +17 -17
  4. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/browser.py +37 -26
  5. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/code_.py +94 -71
  6. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/newtypes.py +0 -4
  7. pyobject-1.2.4/pyobject/pyobj_extension.c +133 -0
  8. pyobject-1.2.4/pyobject/search.py +246 -0
  9. {pyobject-1.2.3.2 → pyobject-1.2.4/pyobject.egg-info}/PKG-INFO +31 -21
  10. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject.egg-info/SOURCES.txt +0 -2
  11. {pyobject-1.2.3.2 → pyobject-1.2.4}/setup.py +3 -2
  12. pyobject-1.2.3.2/LICENSE +0 -674
  13. pyobject-1.2.3.2/MANIFEST.in +0 -3
  14. pyobject-1.2.3.2/pyobject/pyobj_extension.c +0 -107
  15. pyobject-1.2.3.2/pyobject/search.py +0 -144
  16. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/images/back.gif +0 -0
  17. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/images/codeobject.gif +0 -0
  18. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/images/dict.gif +0 -0
  19. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/images/empty_dict.gif +0 -0
  20. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/images/empty_list.gif +0 -0
  21. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/images/empty_tuple.gif +0 -0
  22. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/images/forward.gif +0 -0
  23. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/images/function.gif +0 -0
  24. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/images/list.gif +0 -0
  25. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/images/number.gif +0 -0
  26. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/images/python.gif +0 -0
  27. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/images/python.ico +0 -0
  28. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/images/refresh.gif +0 -0
  29. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/images/string.gif +0 -0
  30. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/images/tuple.gif +0 -0
  31. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/test/__init__.py +0 -0
  32. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/test/pyc_zipper_bz2.py +0 -0
  33. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/test/pyc_zipper_lzma.py +0 -0
  34. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/test/pyc_zipper_zlib.py +0 -0
  35. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/test/pyc_zipper_/264/246/300/355/304/277/302/274.py" +0 -0
  36. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/test/pyc_zipper_/275/366/261/243/273/244/327/326/275/332/302/353.py" +0 -0
  37. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/test/pyc_zipper_/315/321/277/307.py" +0 -0
  38. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/test/test.pyc +0 -0
  39. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/test/testcode.py +0 -0
  40. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject/test//275/342/312/315/306/367/271/330/261/325 (interpreter shutdown).py" +0 -0
  41. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject.egg-info/dependency_links.txt +0 -0
  42. {pyobject-1.2.3.2 → pyobject-1.2.4}/pyobject.egg-info/top_level.txt +0 -0
  43. {pyobject-1.2.3.2 → pyobject-1.2.4}/setup.cfg +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyobject
3
- Version: 1.2.3.2
4
- Summary: 一个提供操作Python底层对象工具的模块。A utility tool with some submodules for operating internal python objects.
3
+ Version: 1.2.4
4
+ Summary: 一个提供操作Python对象底层工具的模块。A utility tool with some submodules for operating internal python objects.
5
5
  Home-page: https://github.com/qfcy/Python/tree/main/pyobject
6
6
  Author: qfcy qq:3076711200
7
7
  Author-email: 3076711200@qq.com
@@ -13,36 +13,35 @@ Classifier: Topic :: Software Development :: Bug Tracking
13
13
  Classifier: Topic :: Software Development :: Debuggers
14
14
  Classifier: Topic :: Software Development :: Testing
15
15
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
- License-File: LICENSE
17
16
 
18
- pyobject - 一个提供操作Python底层对象工具的Python包, 包含一些子模块。A utility tool with some submodules for operating internal python objects.
17
+ pyobject - 一个提供操作Python对象底层工具的Python包, 包含一些子模块。A utility tool with some submodules for operating internal python objects.
19
18
 
20
19
  所包含模块 Included modules:
21
20
  ============================
22
21
 
23
- __init__ - 打印出Python对象的各个属性
22
+ __init__ - 显示和输出Python对象的各个属性值
24
23
 
25
- pyobject.browser - 以图形方式浏览Python对象
24
+ pyobject.browser - 以图形界面浏览Python对象
26
25
 
27
- pyobject.code\_ - Python bytecode的操作工具
26
+ pyobject.code\_ - Python 字节码(bytecode)的操作工具
28
27
 
29
- pyobject.search - 搜索python对象
28
+ pyobject.search - 以一个对象为起点,搜索python对象
30
29
 
31
- pyobject.newtypes - 定义一些新的类型
30
+ pyobject.newtypes - 定义一些新的类型 (实验性)
32
31
 
33
- pyobj_extension(新增) - 操作Python底层对象引用, 以及对象指针的模块, 使用C语言编写
32
+ pyobj_extension(新增) - C扩展模块, 提供操作Python对象底层的函数
34
33
 
35
34
  包含的函数 Functions:
36
35
  =====================
37
36
 
38
- describe(obj, level=0, maxlevel=1, tab=4, verbose=False, file=sys.stdout, mode='w' encoding='utf-8')::
37
+ describe(obj, level=0, maxlevel=1, tab=4, verbose=False, file=sys.stdout)::
39
38
 
40
39
  "描述"一个对象,即打印出对象的各个属性。
41
40
  参数说明:
42
41
  maxlevel:打印对象属性的层数。
43
42
  tab:缩进的空格数,默认为4。
44
43
  verbose:一个布尔值,是否打印出对象的特殊方法(如__init__)。
45
- file:一个类似文件的对象。
44
+ file:一个类似文件的对象,用于打印输出。
46
45
 
47
46
  browse(object, verbose=False, name='obj')::
48
47
 
@@ -85,13 +84,17 @@ search(obj, start, recursions=3)::
85
84
  start:起点对象
86
85
  recursion:递归次数
87
86
 
88
- 新增类: ``pyobject.newtypes.Code``
87
+ 新增类: ``pyobject.Code``
89
88
  ==================================
90
89
 
91
- 用法\: (下面的示例是从doctest中摘取的)::
90
+ 类Code用于包装Python字节码对象(bytecode),提供一个便利操作Python字节码的接口。
91
+
92
+ Python底层的bytecode对象,如func.__code__,是不可变的,鉴于此,Code类提供了一个可变的字节码对象,以及一系列操作字节码的函数,使得操作底层字节码对象变得更容易。
93
+
94
+ 示例用法\: (从模块的doctest中摘取)::
92
95
 
93
96
  >>> def f():print("Hello")
94
- >>> c=Code.fromfunc(f)
97
+ >>> c=Code.fromfunc(f) # 或 c=Code(f.__code__)
95
98
  >>> c.co_consts
96
99
  (None, 'Hello')
97
100
  >>> c.co_consts=(None, 'Hello World!')
@@ -125,27 +128,34 @@ convptr(pointer)::
125
128
  将整数指针转换为Python对象,与id()相反。
126
129
  Convert a integer pointer to a Python object,as a reverse of id().
127
130
 
128
- py_decref(object,n)::
131
+ py_decref(object, n)::
129
132
 
130
133
  将对象的引用计数减小n。Decrease the reference count of an object for n.
131
134
 
132
- py_incref(object,n)::
135
+ py_incref(object, n)::
133
136
 
134
137
  将对象的引用计数增加n。Increase the reference count of an object for n.
135
138
 
136
- *警告: 不恰当地使用上述3个函数可能导致Python崩溃。*
139
+ *警告: 不恰当地使用这3个函数可能导致Python崩溃。*
140
+
141
+ *Warning:Improper use of the three functions above may lead to crashes.*
137
142
 
138
- *Warning:improper using of three functions above may cause Python to crash.*
143
+ list_in(obj, lst)::
139
144
 
140
- 版本:1.2.3
145
+ 判断obj是否在列表或元组lst中。与Python内置的obj in lst调用多次==运算符(__eq__)相比,
146
+ 本函数直接比较对象的指针,提高了效率。
147
+
148
+ 版本:1.2.4
141
149
 
142
150
  更新日志:
143
151
 
152
+ 2024-8-12(v1.2.4):针对pyobject.code_增加了对3.10及以上版本的支持;进一步优化了search模块的搜索性能,以及一些其他修复和改进。
153
+
144
154
  2024-6-20(v1.2.3):更新了包内test目录下的.pyc文件加壳工具,并更新了pyobject.browser中的对象浏览器,添加了显示列表和字典项,后退、前进、刷新页面,以及新增、编辑和删除项等新特性。
145
155
 
146
156
  2022-7-25(v1.2.2):增加了操作Python底层对象引用, 以及对象指针的C语言模块pyobj_extension。
147
157
 
148
- 2022-2-2(v1.2.0):修复了一些bug,优化了search模块的性能; pyobject.code_中增加了Code类,browser中增加编辑属性功能, 增加了Code类的测试。
158
+ 2022-2-2(v1.2.0):修复了一些bug,优化了search模块的性能; code_中增加了Code类, browser中增加编辑属性功能, 增加了Code类的doctest。
149
159
 
150
160
  源码:见 https://github.com/qfcy/Python/tree/main/pyobject
151
161
 
@@ -1,31 +1,31 @@
1
- pyobject - һ���ṩ����Python�ײ���󹤾ߵ�Python��, ����һЩ��ģ�顣A utility tool with some submodules for operating internal python objects.
1
+ pyobject - һ���ṩ����Python����ײ㹤�ߵ�Python��, ����һЩ��ģ�顣A utility tool with some submodules for operating internal python objects.
2
2
 
3
3
  ������ģ�� Included modules:
4
4
  ============================
5
5
 
6
- __init__ - ��ӡ��Python����ĸ�������
6
+ __init__ - ��ʾ�����Python����ĸ�������ֵ
7
7
 
8
- pyobject.browser - ��ͼ�η�ʽ���Python����
8
+ pyobject.browser - ��ͼ�ν������Python����
9
9
 
10
- pyobject.code\_ - Python bytecode�IJ�������
10
+ pyobject.code\_ - Python �ֽ���(bytecode)�IJ�������
11
11
 
12
- pyobject.search - ����python����
12
+ pyobject.search - ��һ������Ϊ��㣬����python����
13
13
 
14
- pyobject.newtypes - ����һЩ�µ�����
14
+ pyobject.newtypes - ����һЩ�µ����� (ʵ����)
15
15
 
16
- pyobj_extension(����) - ����Python�ײ��������, �Լ�����ָ���ģ��, ʹ��C���Ա�д
16
+ pyobj_extension(����) - C��չģ��, �ṩ����Python����ײ�ĺ���
17
17
 
18
18
  �����ĺ��� Functions:
19
19
  =====================
20
20
 
21
- describe(obj, level=0, maxlevel=1, tab=4, verbose=False, file=sys.stdout, mode='w' encoding='utf-8')::
21
+ describe(obj, level=0, maxlevel=1, tab=4, verbose=False, file=sys.stdout)::
22
22
 
23
23
  "����"һ������,����ӡ������ĸ������ԡ�
24
24
  ����˵��:
25
25
  maxlevel:��ӡ�������ԵIJ�����
26
26
  tab:�����Ŀո���,Ĭ��Ϊ4��
27
27
  verbose:һ������ֵ,�Ƿ��ӡ����������ⷽ��(��__init__)��
28
- file:һ�������ļ��Ķ���
28
+ file:һ�������ļ��Ķ������ڴ�ӡ�����
29
29
 
30
30
  browse(object, verbose=False, name='obj')::
31
31
 
@@ -68,13 +68,17 @@ search(obj, start, recursions=3)::
68
68
  start:������
69
69
  recursion:�ݹ����
70
70
 
71
- ������: ``pyobject.newtypes.Code``
71
+ ������: ``pyobject.Code``
72
72
  ==================================
73
73
 
74
- �÷�\: (�����ʾ���Ǵ�doctest��ժȡ��)::
74
+ ��Code���ڰ�װPython�ֽ������(bytecode)���ṩһ����������Python�ֽ���Ľӿڡ�
75
+
76
+ Python�ײ��bytecode������func.__code__���Dz��ɱ�ģ����ڴˣ�Code���ṩ��һ���ɱ���ֽ�������Լ�һϵ�в����ֽ���ĺ�����ʹ�ò����ײ��ֽ�������ø����ס�
77
+
78
+ ʾ���÷�\: (��ģ���doctest��ժȡ)::
75
79
 
76
80
  >>> def f():print("Hello")
77
- >>> c=Code.fromfunc(f)
81
+ >>> c=Code.fromfunc(f) # �� c=Code(f.__code__)
78
82
  >>> c.co_consts
79
83
  (None, 'Hello')
80
84
  >>> c.co_consts=(None, 'Hello World!')
@@ -108,27 +112,34 @@ convptr(pointer)::
108
112
  ������ָ��ת��ΪPython������id()�෴��
109
113
  Convert a integer pointer to a Python object,as a reverse of id().
110
114
 
111
- py_decref(object,n)::
115
+ py_decref(object, n)::
112
116
 
113
117
  ����������ü�����Сn��Decrease the reference count of an object for n.
114
118
 
115
- py_incref(object,n)::
119
+ py_incref(object, n)::
116
120
 
117
121
  ����������ü�������n��Increase the reference count of an object for n.
118
122
 
119
- *����: ��ǡ����ʹ������3���������ܵ���Python������*
123
+ *����: ��ǡ����ʹ����3���������ܵ���Python������*
124
+
125
+ *Warning:Improper use of the three functions above may lead to crashes.*
120
126
 
121
- *Warning:improper using of three functions above may cause Python to crash.*
127
+ list_in(obj, lst)::
122
128
 
123
- �汾:1.2.3
129
+ �ж�obj�Ƿ����б���Ԫ��lst�С���Python���õ�obj in lst���ö��==�����(__eq__)��ȣ�
130
+ ������ֱ�ӱȽ϶����ָ�룬�����Ч�ʡ�
131
+
132
+ �汾:1.2.4
124
133
 
125
134
  ������־:
126
135
 
136
+ 2024-8-12(v1.2.4):���pyobject.code_�����˶�3.10�����ϰ汾��֧�֣���һ���Ż���searchģ����������ܣ��Լ�һЩ�����޸��͸Ľ���
137
+
127
138
  2024-6-20(v1.2.3):�����˰���testĿ¼�µ�.pyc�ļ��ӿǹ��ߣ���������pyobject.browser�еĶ������������������ʾ�б����ֵ�����ˡ�ǰ����ˢ��ҳ�棬�Լ��������༭��ɾ����������ԡ�
128
139
 
129
140
  2022-7-25(v1.2.2):�����˲���Python�ײ��������, �Լ�����ָ���C����ģ��pyobj_extension��
130
141
 
131
- 2022-2-2(v1.2.0):�޸���һЩbug,�Ż���searchģ�������; pyobject.code_��������Code��,browser�����ӱ༭���Թ���, ������Code��IJ��ԡ�
142
+ 2022-2-2(v1.2.0):�޸���һЩbug,�Ż���searchģ�������; code_��������Code��, browser�����ӱ༭���Թ���, ������Code���doctest��
132
143
 
133
144
  Դ��:�� https://github.com/qfcy/Python/tree/main/pyobject
134
145
 
@@ -1,15 +1,14 @@
1
- """一个提供操作Python底层对象工具的模块。
1
+ """一个提供操作Python对象底层工具的模块。
2
2
  A utility tool with some submodules for operating internal python objects.
3
3
 
4
4
  """
5
-
6
5
  import sys
7
6
  from warnings import warn
8
7
  from pprint import pprint
9
8
 
10
9
  __email__="3076711200@qq.com"
11
10
  __author__="qfcy qq:3076711200"
12
- __version__="1.2.3"
11
+ __version__="1.2.4"
13
12
 
14
13
  _ignore_names=["__builtins__","__doc__"]
15
14
  __all__=["objectname","bases","describe","desc"]
@@ -39,7 +38,7 @@ tab:缩进的空格数,默认为4。'''
39
38
  print(*obj.__bases__,sep=',')
40
39
  for cls in obj.__bases__:
41
40
  bases(cls,level,tab)
42
-
41
+
43
42
 
44
43
  def _shortrepr(obj,maxlength=150):
45
44
  result=repr(obj)
@@ -57,14 +56,15 @@ def _shortrepr(obj,maxlength=150):
57
56
  ## value=getattr(obj,attr)
58
57
  ## pprint("{}:{}".format(attr,value),**kwargs)
59
58
  ## if needhelp:help(value)
60
- def describe(obj,level=0,maxlevel=1,tab=4,verbose=False,file=sys.stdout):
59
+ def describe(obj,level=0,maxlevel=1,tab=4,verbose=False,file=None):
61
60
  '''"描述"一个对象,即打印出对象的各个属性。
62
61
  参数说明:
63
62
  maxlevel:打印对象属性的层数。
64
63
  tab:缩进的空格数,默认为4。
65
64
  verbose:一个布尔值,是否打印出对象的特殊方法(如__init__)。
66
- file:一个类似文件的对象。
65
+ file:一个类似文件的对象,用于打印输出。
67
66
  '''
67
+ if file is None:file=sys.stdout
68
68
  if level==maxlevel:
69
69
  result=repr(obj)
70
70
  if result.startswith('[') or result.startswith('{'):pprint(result)
@@ -89,25 +89,25 @@ file:一个类似文件的对象。
89
89
  print("<AttributeError!>",end='',file=file)
90
90
 
91
91
  desc=describe #别名
92
- # 导入其他模块中的函数和类
92
+ # 导入其他子模块中的函数和类
93
93
  try:
94
- from .browser import browse
94
+ from pyobject.browser import browse
95
95
  __all__.append("browse")
96
- # (ImportError,SystemError): 修复Python 3.4bug
97
- except (ImportError,SystemError):warn("Failed to import module .browser .")
96
+ # SystemError: 修复Python 3.4下的bug
97
+ except (ImportError,SystemError):warn("Failed to import module pyobject.browser.")
98
98
  try:
99
- from .search import make_list,search #,test_make_list,test_search
100
- __all__.extend(["make_list","search"])
99
+ from pyobject.search import make_list,make_iter,search #,test_make_list,test_search
100
+ __all__.extend(["make_list","make_iter","search"])
101
101
  # 同上
102
- except (ImportError,SystemError):warn("Failed to import module .search .")
102
+ except (ImportError,SystemError):warn("Failed to import pyobject.search.")
103
103
 
104
104
  try:
105
- from .code_ import Code
105
+ from pyobject.code_ import Code
106
106
  __all__.append("Code")
107
- except (ImportError,SystemError):warn("Failed to import module .code.")
107
+ except (ImportError,SystemError):warn("Failed to import pyobject.code_.")
108
108
  try:
109
109
  from pyobj_extension import *
110
- __all__.extend(["convptr","py_incref","py_decref"])
110
+ __all__.extend(["convptr","py_incref","py_decref","list_in"])
111
111
  except ImportError:warn("Failed to import module pyobj_extension.")
112
112
 
113
113
  def test():
@@ -119,4 +119,4 @@ def test():
119
119
  return 1
120
120
  else:return 0
121
121
 
122
- if __name__=="__main__":test()
122
+ if __name__=="__main__":sys.exit(test())
@@ -5,11 +5,10 @@ import tkinter.ttk as ttk
5
5
  import tkinter.messagebox as msgbox
6
6
  import tkinter.simpledialog as simpledialog
7
7
  from inspect import isfunction,ismethod,isgeneratorfunction,isgenerator,iscode
8
- try: from . import objectname,_shortrepr
9
- # ImportError,SystemError: 修复Python 3.4中的bug
10
- except (ImportError,SystemError):from __init__ import objectname,_shortrepr
8
+ try:from pyobject import objectname,_shortrepr
9
+ except ImportError:from __init__ import objectname,_shortrepr
11
10
 
12
- _IMAGE_PATH=(os.path.split(__file__)[0]+"\\images")
11
+ _IMAGE_PATH=os.path.join(os.path.split(__file__)[0],"images")
13
12
 
14
13
  def isfunc(obj):
15
14
  # 判断一个对象是否为函数或方法
@@ -18,8 +17,11 @@ def isfunc(obj):
18
17
  func_types=[types.LambdaType,types.BuiltinFunctionType,
19
18
  types.BuiltinMethodType,typing.WrapperDescriptorType,
20
19
  typing.MethodWrapperType,typing.MethodDescriptorType]
21
- if sys.version_info.minor>=7: # Python 3.7及以上
22
- func_types.append(types.ClassMethodDescriptorType)
20
+ if sys.version_info.minor>=7:
21
+ ClassMethodDescriptorType=types.ClassMethodDescriptorType
22
+ else: # 3.7之前的旧版本
23
+ ClassMethodDescriptorType=type(dict.__dict__['fromkeys'])
24
+ func_types.append(ClassMethodDescriptorType)
23
25
  for type in func_types:
24
26
  if isinstance(obj,type):
25
27
  return True
@@ -67,7 +69,7 @@ class ObjectBrowser():
67
69
 
68
70
  self.master.title(self.title)
69
71
  try:
70
- self.master.iconbitmap(_IMAGE_PATH+r"\python.ico")
72
+ self.master.iconbitmap(os.path.join(_IMAGE_PATH,"python.ico"))
71
73
  except tk.TclError:pass
72
74
  self.load_image()
73
75
  self.create_widgets()
@@ -97,7 +99,9 @@ class ObjectBrowser():
97
99
 
98
100
  self.functions_tag=self.tvw.insert('',index=0,text="函数、方法")
99
101
  self.attributes_tag=self.tvw.insert('',index=1,text="属性")
102
+ self.tvw.item(self.attributes_tag,open=True) # 展开项
100
103
  self.classes_tag=self.tvw.insert('',index=2,text="类")
104
+ self.tvw.item(self.classes_tag,open=True)
101
105
  self.lst_tag=self.tvw.insert('',index=3,text="列表数据")
102
106
  self.dict_tag=self.tvw.insert('',index=4,text="字典数据")
103
107
  editor = ttk.Labelframe(self.master, text='编辑值',
@@ -118,33 +122,33 @@ class ObjectBrowser():
118
122
  def load_image(self):
119
123
  # 加载images文件夹下的图片
120
124
  self.back_image=tk.PhotoImage(master=self.master,
121
- file=_IMAGE_PATH+r"\back.gif")
125
+ file=os.path.join(_IMAGE_PATH,"back.gif"))
122
126
  self.forward_image=tk.PhotoImage(master=self.master,
123
- file=_IMAGE_PATH+r"\forward.gif")
127
+ file=os.path.join(_IMAGE_PATH,"forward.gif"))
124
128
  self.refresh_image=tk.PhotoImage(master=self.master,
125
- file=_IMAGE_PATH+r"\refresh.gif")
129
+ file=os.path.join(_IMAGE_PATH,"refresh.gif"))
126
130
  self.obj_image=tk.PhotoImage(master=self.master,
127
- file=_IMAGE_PATH+r"\python.gif")
131
+ file=os.path.join(_IMAGE_PATH,"python.gif"))
128
132
  self.num_image=tk.PhotoImage(master=self.master,
129
- file=_IMAGE_PATH+r"\number.gif")
133
+ file=os.path.join(_IMAGE_PATH,"number.gif"))
130
134
  self.str_image=tk.PhotoImage(master=self.master,
131
- file=_IMAGE_PATH+r"\string.gif")
135
+ file=os.path.join(_IMAGE_PATH,"string.gif"))
132
136
  self.list_image=tk.PhotoImage(master=self.master,
133
- file=_IMAGE_PATH+r"\list.gif")
137
+ file=os.path.join(_IMAGE_PATH,"list.gif"))
134
138
  self.empty_list_image=tk.PhotoImage(master=self.master,
135
- file=_IMAGE_PATH+r"\empty_list.gif")
139
+ file=os.path.join(_IMAGE_PATH,"empty_list.gif"))
136
140
  self.tuple_image=tk.PhotoImage(master=self.master,
137
- file=_IMAGE_PATH+r"\tuple.gif")
141
+ file=os.path.join(_IMAGE_PATH,"tuple.gif"))
138
142
  self.empty_tuple_image=tk.PhotoImage(master=self.master,
139
- file=_IMAGE_PATH+r"\empty_tuple.gif")
143
+ file=os.path.join(_IMAGE_PATH,"empty_tuple.gif"))
140
144
  self.dict_image=tk.PhotoImage(master=self.master,
141
- file=_IMAGE_PATH+r"\dict.gif")
145
+ file=os.path.join(_IMAGE_PATH,"dict.gif"))
142
146
  self.empty_dict_image=tk.PhotoImage(master=self.master,
143
- file=_IMAGE_PATH+r"\empty_dict.gif")
147
+ file=os.path.join(_IMAGE_PATH,"empty_dict.gif"))
144
148
  self.func_image=tk.PhotoImage(master=self.master,
145
- file=_IMAGE_PATH+r"\function.gif")
149
+ file=os.path.join(_IMAGE_PATH,"function.gif"))
146
150
  self.code_image=tk.PhotoImage(master=self.master,
147
- file=_IMAGE_PATH+r"\codeobject.gif")
151
+ file=os.path.join(_IMAGE_PATH,"codeobject.gif"))
148
152
  def clear(self):
149
153
  # 清除Treeview的数据
150
154
  for root in self.tvw.get_children(""): # 获取根项
@@ -191,7 +195,7 @@ class ObjectBrowser():
191
195
  text=attr, image=image,
192
196
  values=(value,)) # values从第二列开始
193
197
  except Exception as error: # 显示错误消息
194
- value='<{}!>'.format(type(error).__name__)
198
+ value='<{}: {}>'.format(type(error).__name__,str(error))
195
199
  self.tvw.insert(self.attributes_tag, tk.END,
196
200
  text=attr, image=self.obj_image,
197
201
  values=(value,),tags=("error",))
@@ -202,7 +206,7 @@ class ObjectBrowser():
202
206
  text="__bases__", image=self._get_image(bases),
203
207
  values=(repr(bases),))
204
208
  # 添加列表数据
205
- if isinstance(obj,list) or isinstance(obj,tuple):
209
+ if isinstance(obj,(list,tuple)):
206
210
  for i in range(len(obj)):
207
211
  index=str(i)
208
212
  try:
@@ -252,7 +256,14 @@ class ObjectBrowser():
252
256
  else:
253
257
  parent=self.tvw.parent(selection[0])
254
258
  if parent:
255
- value_str=self.tvw.item(selection[0])["values"][0]
259
+ #value_str=self.tvw.item(selection[0])["values"][0] # 现已弃用,由于使用了_shortrepr()
260
+ attr=self.tvw.item(selection)["text"]
261
+ if parent==self.dict_tag:
262
+ value_str=repr(self.obj[eval(attr)])
263
+ elif parent==self.lst_tag:
264
+ value_str=repr(self.obj[int(attr)])
265
+ else:
266
+ value_str=repr(getattr(self.obj,attr))
256
267
  self.editor.delete(0,tk.END)
257
268
  self.editor.insert(0,value_str)
258
269
  if parent==self.lst_tag and isinstance(self.obj,tuple):
@@ -355,7 +366,7 @@ class ObjectBrowser():
355
366
  # 对象的属性可能有改变,重新获取对象的属性
356
367
  scope={self.rootobj_name:self.root_obj} # 获取第一个浏览的根对象及其名称
357
368
  object=eval(path,scope)
358
- except Exception:
369
+ except Exception: # 默认使用新获取的对象,只有出错时,才使用旧的对象
359
370
  object=obj
360
371
  else:object=obj
361
372
  self.browse(object,path)
@@ -368,7 +379,7 @@ class ObjectBrowser():
368
379
  self.history_index+=1
369
380
  self.navigate_history()
370
381
 
371
- def browse(object,verbose=False,name="obj",
382
+ def browse(object,verbose=True,name="obj",
372
383
  mainloop=True,multi_window=False,refresh_history=True,
373
384
  root_obj=None,rootobj_name=None):
374
385
  """以图形界面浏览一个Python对象。