1010__author__ = "robertbasic"
1111
1212import base64
13- from PyQt5 .QtWidgets import (QTreeWidget , QTreeWidgetItem , QDialog ,
13+
14+ from PyQt5 .QtWidgets import (QTabWidget , QTreeWidget , QTreeWidgetItem , QDialog ,
1415 QTextEdit , QGridLayout )
1516
1617
17- class PugdebugVariableViewer (QTreeWidget ):
18+ class PugdebugVariableViewer (QTabWidget ):
1819
19- def __init__ (self ):
20- super (PugdebugVariableViewer , self ).__init__ ()
20+ variable_tables = {}
2121
22- self . setColumnCount ( 3 )
23- self . setHeaderLabels ([ 'Name' , 'Type' , 'Value' ])
22+ def __init__ ( self ):
23+ """Variable viewer
2424
25- self .setColumnWidth (0 , 250 )
26- self .setColumnWidth (1 , 150 )
25+ Every variable context is displayed in a table,
26+ contexts are displayed in tabs.
27+ """
28+ super (PugdebugVariableViewer , self ).__init__ ()
2729
28- self .itemDoubleClicked .connect (
29- self .handle_variable_double_clicked
30- )
30+ self .setTabsClosable (False )
3131
3232 def handle_variable_double_clicked (self , item ):
3333 """Handle when a variable is double clicked
@@ -40,19 +40,42 @@ def handle_variable_double_clicked(self, item):
4040 PugdebugVariableDetails (self , item )
4141
4242 def set_variables (self , variables ):
43- self .clear ()
43+ for context in variables :
44+ table = self .get_variable_table (context )
45+
46+ table .clear ()
47+
48+ for var in variables [context ]:
49+ self .add_variable (table , var )
50+
51+ def get_variable_table (self , context ):
52+ context_key = context .replace (' ' , '-' ).lower ()
53+
54+ if context_key in self .variable_tables :
55+ table = self .variable_tables [context_key ]
56+ else :
57+ table = QTreeWidget ()
58+ table .setColumnCount (3 )
59+ table .setHeaderLabels (['Name' , 'Type' , 'Value' ])
60+ table .setColumnWidth (0 , 250 )
61+ table .setColumnWidth (1 , 150 )
62+
63+ self .variable_tables [context_key ] = table
64+
65+ if context == 'Locals' :
66+ self .insertTab (0 , table , context )
67+ else :
68+ self .addTab (table , context )
69+
70+ table .itemDoubleClicked .connect (
71+ self .handle_variable_double_clicked
72+ )
4473
45- if 'Locals' in variables :
46- for variable in variables ['Locals' ]:
47- self .add_variable (variable )
74+ self .setCurrentIndex (0 )
4875
49- if 'Superglobals' in variables :
50- item = QTreeWidgetItem (['Superglobals' , '' , '' ])
51- self .addTopLevelItem (item )
52- for variable in variables ['Superglobals' ]:
53- self .add_variable (variable , item )
76+ return table
5477
55- def add_variable (self , variable , parent = None ):
78+ def add_variable (self , table , variable , parent = None ):
5679 type = variable ['type' ]
5780 tooltip = None
5881
@@ -90,10 +113,10 @@ def add_variable(self, variable, parent=None):
90113
91114 if 'variables' in variable :
92115 for subvar in variable ['variables' ]:
93- self .add_variable (subvar , item )
116+ self .add_variable (table , subvar , item )
94117
95118 if parent is None :
96- self .addTopLevelItem (item )
119+ table .addTopLevelItem (item )
97120 else :
98121 parent .addChild (item )
99122
0 commit comments