eric6/Debugger/VariablesFilterDialog.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2002 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the variables filter dialog.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import Qt
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QListWidgetItem
14
15 from Debugger.Config import ConfigVarTypeDispStrings, ConfigVarTypeFilters
16 import Preferences
17
18 from .Ui_VariablesFilterDialog import Ui_VariablesFilterDialog
19
20
21 class VariablesFilterDialog(QDialog, Ui_VariablesFilterDialog):
22 """
23 Class implementing the variables filter dialog.
24
25 It opens a dialog window for the configuration of the variables type
26 filter to be applied during a debugging session.
27 """
28 def __init__(self, parent=None, name=None, modal=False):
29 """
30 Constructor
31
32 @param parent parent widget of this dialog (QWidget)
33 @param name name of this dialog (string)
34 @param modal flag to indicate a modal dialog (boolean)
35 """
36 super(VariablesFilterDialog, self).__init__(parent)
37 if name:
38 self.setObjectName(name)
39 self.setModal(modal)
40 self.setupUi(self)
41
42 self.defaultButton = self.buttonBox.addButton(
43 self.tr("Save Default"), QDialogButtonBox.ActionRole)
44
45 #populate the list widgets and set the default selection
46 for widget in self.localsList, self.globalsList:
47 for varType, varTypeStr in ConfigVarTypeDispStrings.items():
48 itm = QListWidgetItem(self.tr(varTypeStr), widget)
49 itm.setData(Qt.UserRole, ConfigVarTypeFilters[varType])
50 itm.setFlags(Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
51 itm.setCheckState(Qt.Unchecked)
52 widget.addItem(itm)
53
54 lDefaultFilter, gDefaultFilter = Preferences.getVarFilters()
55 self.setSelection(lDefaultFilter, gDefaultFilter)
56
57 def getSelection(self):
58 """
59 Public slot to retrieve the current selections.
60
61 @return A tuple of lists of integer values. The first list is the
62 locals variables filter, the second the globals variables filter.
63 """
64 lList = []
65 for row in range(self.localsList.count()):
66 itm = self.localsList.item(row)
67 if itm.checkState() == Qt.Unchecked:
68 lList.append(itm.data(Qt.UserRole))
69
70 gList = []
71 for row in range(self.globalsList.count()):
72 itm = self.globalsList.item(row)
73 if itm.checkState() == Qt.Unchecked:
74 gList.append(itm.data(Qt.UserRole))
75 return (lList, gList)
76
77 def setSelection(self, lList, gList):
78 """
79 Public slot to set the current selection.
80
81 @param lList local variables filter (list of int)
82 @param gList global variables filter (list of int)
83 """
84 for row in range(self.localsList.count()):
85 itm = self.localsList.item(row)
86 if itm.data(Qt.UserRole) in lList:
87 itm.setCheckState(Qt.Unchecked)
88 else:
89 itm.setCheckState(Qt.Checked)
90
91 for row in range(self.globalsList.count()):
92 itm = self.globalsList.item(row)
93 if itm.data(Qt.UserRole) in gList:
94 itm.setCheckState(Qt.Unchecked)
95 else:
96 itm.setCheckState(Qt.Checked)
97
98 def on_buttonBox_clicked(self, button):
99 """
100 Private slot called by a button of the button box clicked.
101
102 @param button button that was clicked (QAbstractButton)
103 """
104 if button == self.defaultButton:
105 Preferences.setVarFilters(self.getSelection())

eric ide

mercurial