1010__author__ = "robertbasic"
1111
1212import base64
13- from PyQt5 .QtWidgets import QTreeWidget , QTreeWidgetItem
13+ from PyQt5 .QtWidgets import (QTreeWidget , QTreeWidgetItem , QDialog ,
14+ QTextEdit , QGridLayout )
1415
1516
1617class PugdebugVariableViewer (QTreeWidget ):
@@ -24,6 +25,20 @@ def __init__(self):
2425 self .setColumnWidth (0 , 250 )
2526 self .setColumnWidth (1 , 150 )
2627
28+ self .itemDoubleClicked .connect (
29+ self .handle_variable_double_clicked
30+ )
31+
32+ def handle_variable_double_clicked (self , item ):
33+ """Handle when a variable is double clicked
34+
35+ If the double clicked item is of string type
36+ show it in a dialog. Allows to inspect long
37+ strings more easier.
38+ """
39+ if item .text (1 ).find ('string' ) > - 1 :
40+ PugdebugVariableDetails (self , item )
41+
2742 def set_variables (self , variables ):
2843 self .clear ()
2944
@@ -39,6 +54,7 @@ def set_variables(self, variables):
3954
4055 def add_variable (self , variable , parent = None ):
4156 type = variable ['type' ]
57+ tooltip = None
4258
4359 if type == 'uninitialized' :
4460 return
@@ -52,6 +68,7 @@ def add_variable(self, variable, parent=None):
5268
5369 if type == 'string' :
5470 type = "%s {%d}" % (type , int (variable ['size' ]))
71+ tooltip = "Double click to inspect"
5572
5673 if 'value' in variable :
5774 value = variable ['value' ]
@@ -79,3 +96,25 @@ def add_variable(self, variable, parent=None):
7996 self .addTopLevelItem (item )
8097 else :
8198 parent .addChild (item )
99+
100+ if tooltip is not None :
101+ item .setToolTip (2 , tooltip )
102+
103+
104+ class PugdebugVariableDetails (QDialog ):
105+
106+ def __init__ (self , parent , item ):
107+ """Dialog to inspect variables in more detail
108+
109+ Show the contents of a variable in a text edit.
110+ """
111+ super (PugdebugVariableDetails , self ).__init__ (parent )
112+
113+ edit = QTextEdit (item .text (2 ))
114+
115+ layout = QGridLayout (self )
116+ layout .addWidget (edit , 0 , 0 , 0 , 0 )
117+
118+ self .setLayout (layout )
119+
120+ self .show ()
0 commit comments