6 """ |
6 """ |
7 Module implementing the variables viewer widget. |
7 Module implementing the variables viewer widget. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt4.QtCore import Qt, QRegExp, qVersion |
10 from PyQt4.QtCore import Qt, QRegExp, qVersion |
11 from PyQt4.QtGui import QTreeWidget, QTreeWidgetItem, QApplication, QAbstractItemView, \ |
11 from PyQt4.QtGui import QTreeWidget, QTreeWidgetItem, QApplication, \ |
12 QMenu |
12 QAbstractItemView, QMenu |
13 from PyQt4.QtGui import QTextDocument # __IGNORE_WARNING__ |
13 from PyQt4.QtGui import QTextDocument # __IGNORE_WARNING__ |
14 |
14 |
15 from E5Gui.E5Application import e5App |
15 from E5Gui.E5Application import e5App |
16 |
16 |
17 from DebugClients.Python3.DebugConfig import ConfigVarTypeStrings |
17 from DebugClients.Python3.DebugConfig import ConfigVarTypeStrings |
74 |
74 |
75 def data(self, column, role): |
75 def data(self, column, role): |
76 """ |
76 """ |
77 Public method to return the data for the requested role. |
77 Public method to return the data for the requested role. |
78 |
78 |
79 This implementation changes the original behavior in a way, that the display |
79 This implementation changes the original behavior in a way, that the |
80 data is returned as the tooltip for column 1. |
80 display data is returned as the tooltip for column 1. |
81 |
81 |
82 @param column column number (integer) |
82 @param column column number (integer) |
83 @param role data role (Qt.ItemDataRole) |
83 @param role data role (Qt.ItemDataRole) |
84 @return requested data |
84 @return requested data |
85 """ |
85 """ |
219 return VariableItem.key(self, column) |
219 return VariableItem.key(self, column) |
220 |
220 |
221 |
221 |
222 class SpecialArrayElementVarItem(SpecialVarItem): |
222 class SpecialArrayElementVarItem(SpecialVarItem): |
223 """ |
223 """ |
224 Class implementing a QTreeWidgetItem that represents a special array variable node. |
224 Class implementing a QTreeWidgetItem that represents a special array |
|
225 variable node. |
225 """ |
226 """ |
226 def __init__(self, parent, dvar, dvalue, dtype, frmnr, scope): |
227 def __init__(self, parent, dvar, dvalue, dtype, frmnr, scope): |
227 """ |
228 """ |
228 Constructor |
229 Constructor |
229 |
230 |
232 @param dvalue value string (string) |
233 @param dvalue value string (string) |
233 @param dtype type string (string) |
234 @param dtype type string (string) |
234 @param frmnr frame number (0 is the current frame) (int) |
235 @param frmnr frame number (0 is the current frame) (int) |
235 @param scope flag indicating global (1) or local (0) variables |
236 @param scope flag indicating global (1) or local (0) variables |
236 """ |
237 """ |
237 SpecialVarItem.__init__(self, parent, dvar, dvalue, dtype, frmnr, scope) |
238 SpecialVarItem.__init__(self, parent, dvar, dvalue, dtype, frmnr, |
|
239 scope) |
238 |
240 |
239 """ |
241 """ |
240 Array elements have numbers as names, but the key must be |
242 Array elements have numbers as names, but the key must be |
241 right justified and zero filled to 6 decimal places. Then |
243 right justified and zero filled to 6 decimal places. Then |
242 element 2 will have a key of '000002' and appear before |
244 element 2 will have a key of '000002' and appear before |
279 @param parent the parent (QWidget) |
281 @param parent the parent (QWidget) |
280 @param scope flag indicating global (1) or local (0) variables |
282 @param scope flag indicating global (1) or local (0) variables |
281 """ |
283 """ |
282 super().__init__(parent) |
284 super().__init__(parent) |
283 |
285 |
284 self.indicators = {'list': '[]', 'tuple': '()', 'dict': '{}', # Python types |
286 self.indicators = {'list': '[]', 'tuple': '()', 'dict': '{}', |
285 'Array': '[]', 'Hash': '{}'} # Ruby types |
287 # Python types |
|
288 'Array': '[]', 'Hash': '{}'} |
|
289 # Ruby types |
286 |
290 |
287 self.rx_class = QRegExp('<.*(instance|object) at 0x.*>') |
291 self.rx_class = QRegExp('<.*(instance|object) at 0x.*>') |
288 self.rx_class2 = QRegExp('class .*') |
292 self.rx_class2 = QRegExp('class .*') |
289 self.rx_class3 = QRegExp('<class .* at 0x.*>') |
293 self.rx_class3 = QRegExp('<class .* at 0x.*>') |
290 self.dvar_rx_class1 = QRegExp(r'<.*(instance|object) at 0x.*>(\[\]|\{\}|\(\))') |
294 self.dvar_rx_class1 = QRegExp( |
|
295 r'<.*(instance|object) at 0x.*>(\[\]|\{\}|\(\))') |
291 self.dvar_rx_class2 = QRegExp(r'<class .* at 0x.*>(\[\]|\{\}|\(\))') |
296 self.dvar_rx_class2 = QRegExp(r'<class .* at 0x.*>(\[\]|\{\}|\(\))') |
292 self.dvar_rx_array_element = QRegExp(r'^\d+$') |
297 self.dvar_rx_array_element = QRegExp(r'^\d+$') |
293 self.dvar_rx_special_array_element = QRegExp(r'^\d+(\[\]|\{\}|\(\))$') |
298 self.dvar_rx_special_array_element = QRegExp(r'^\d+(\[\]|\{\}|\(\))$') |
294 self.rx_nonprintable = QRegExp(r"""(\\x\d\d)+""") |
299 self.rx_nonprintable = QRegExp(r"""(\\x\d\d)+""") |
295 |
300 |
496 QAbstractItemView.PositionAtTop) |
501 QAbstractItemView.PositionAtTop) |
497 else: |
502 else: |
498 self.scrollToItem(citm, QAbstractItemView.PositionAtTop) |
503 self.scrollToItem(citm, QAbstractItemView.PositionAtTop) |
499 self.current = None |
504 self.current = None |
500 elif self.__scrollToItem: |
505 elif self.__scrollToItem: |
501 self.scrollToItem(self.__scrollToItem, QAbstractItemView.PositionAtTop) |
506 self.scrollToItem(self.__scrollToItem, |
|
507 QAbstractItemView.PositionAtTop) |
502 |
508 |
503 self.resortEnabled = resortEnabled |
509 self.resortEnabled = resortEnabled |
504 self.__resort() |
510 self.__resort() |
505 |
511 |
506 def __generateItem(self, parent, dvar, dvalue, dtype, isSpecial=False): |
512 def __generateItem(self, parent, dvar, dvalue, dtype, isSpecial=False): |
509 |
515 |
510 @param parent parent of the item to be generated |
516 @param parent parent of the item to be generated |
511 @param dvar variable name (string) |
517 @param dvar variable name (string) |
512 @param dvalue value string (string) |
518 @param dvalue value string (string) |
513 @param dtype type string (string) |
519 @param dtype type string (string) |
514 @param isSpecial flag indicating that a special node should be generated (boolean) |
520 @param isSpecial flag indicating that a special node should be |
|
521 generated (boolean) |
515 @return The item that was generated (VariableItem). |
522 @return The item that was generated (VariableItem). |
516 """ |
523 """ |
517 if isSpecial and \ |
524 if isSpecial and \ |
518 (self.dvar_rx_class1.exactMatch(dvar) or \ |
525 (self.dvar_rx_class1.exactMatch(dvar) or \ |
519 self.dvar_rx_class2.exactMatch(dvar)): |
526 self.dvar_rx_class2.exactMatch(dvar)): |
591 try: |
598 try: |
592 i = ConfigVarTypeStrings.index(vtype) |
599 i = ConfigVarTypeStrings.index(vtype) |
593 dvtype = self.trUtf8(ConfigVarTypeDispStrings[i]) |
600 dvtype = self.trUtf8(ConfigVarTypeDispStrings[i]) |
594 except ValueError: |
601 except ValueError: |
595 if vtype == 'classobj': |
602 if vtype == 'classobj': |
596 dvtype = self.trUtf8( |
603 dvtype = self.trUtf8(ConfigVarTypeDispStrings[ |
597 ConfigVarTypeDispStrings[ConfigVarTypeStrings.index('instance')]\ |
604 ConfigVarTypeStrings.index('instance')]) |
598 ) |
|
599 else: |
605 else: |
600 dvtype = vtype |
606 dvtype = vtype |
601 return dvtype |
607 return dvtype |
602 |
608 |
603 def mouseDoubleClickEvent(self, mouseEvent): |
609 def mouseDoubleClickEvent(self, mouseEvent): |
604 """ |
610 """ |
605 Protected method of QAbstractItemView. |
611 Protected method of QAbstractItemView. |
606 |
612 |
607 Reimplemented to disable expanding/collapsing |
613 Reimplemented to disable expanding/collapsing of items when |
608 of items when double-clicking. Instead the double-clicked entry is opened. |
614 double-clicking. Instead the double-clicked entry is opened. |
609 |
615 |
610 @param mouseEvent the mouse event object (QMouseEvent) |
616 @param mouseEvent the mouse event object (QMouseEvent) |
611 """ |
617 """ |
612 itm = self.itemAt(mouseEvent.pos()) |
618 itm = self.itemAt(mouseEvent.pos()) |
613 self.__showVariableDetails(itm) |
619 self.__showVariableDetails(itm) |
680 |
686 |
681 def __expandItemSignal(self, parentItem): |
687 def __expandItemSignal(self, parentItem): |
682 """ |
688 """ |
683 Private slot to handle the expanded signal. |
689 Private slot to handle the expanded signal. |
684 |
690 |
685 @param parentItem reference to the item being expanded (QTreeWidgetItem) |
691 @param parentItem reference to the item being expanded |
|
692 (QTreeWidgetItem) |
686 """ |
693 """ |
687 self.expandItem(parentItem) |
694 self.expandItem(parentItem) |
688 self.__scrollToItem = parentItem |
695 self.__scrollToItem = parentItem |
689 |
696 |
690 def expandItem(self, parentItem): |
697 def expandItem(self, parentItem): |
691 """ |
698 """ |
692 Public slot to handle the expanded signal. |
699 Public slot to handle the expanded signal. |
693 |
700 |
694 @param parentItem reference to the item being expanded (QTreeWidgetItem) |
701 @param parentItem reference to the item being expanded |
|
702 (QTreeWidgetItem) |
695 """ |
703 """ |
696 pathlist = self.__buildTreePath(parentItem) |
704 pathlist = self.__buildTreePath(parentItem) |
697 self.openItems.append(pathlist) |
705 self.openItems.append(pathlist) |
698 if parentItem.populated: |
706 if parentItem.populated: |
699 return |
707 return |
706 |
714 |
707 def collapseItem(self, parentItem): |
715 def collapseItem(self, parentItem): |
708 """ |
716 """ |
709 Public slot to handle the collapsed signal. |
717 Public slot to handle the collapsed signal. |
710 |
718 |
711 @param parentItem reference to the item being collapsed (QTreeWidgetItem) |
719 @param parentItem reference to the item being collapsed |
|
720 (QTreeWidgetItem) |
712 """ |
721 """ |
713 pathlist = self.__buildTreePath(parentItem) |
722 pathlist = self.__buildTreePath(parentItem) |
714 self.openItems.remove(pathlist) |
723 self.openItems.remove(pathlist) |
715 |
724 |
716 try: |
725 try: |
721 def __resort(self): |
730 def __resort(self): |
722 """ |
731 """ |
723 Private method to resort the tree. |
732 Private method to resort the tree. |
724 """ |
733 """ |
725 if self.resortEnabled: |
734 if self.resortEnabled: |
726 self.sortItems(self.sortColumn(), self.header().sortIndicatorOrder()) |
735 self.sortItems(self.sortColumn(), |
|
736 self.header().sortIndicatorOrder()) |
727 |
737 |
728 def handleResetUI(self): |
738 def handleResetUI(self): |
729 """ |
739 """ |
730 Public method to reset the VariablesViewer. |
740 Public method to reset the VariablesViewer. |
731 """ |
741 """ |