Debugger/WatchPointViewer.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 2525
8b507a9a2d40
parent 2988
f53c03574697
child 3058
0a02c433f52d
equal deleted inserted replaced
3056:9986ec0e559a 3057:10516539f238
8 """ 8 """
9 9
10 from __future__ import unicode_literals # __IGNORE_WARNING__ 10 from __future__ import unicode_literals # __IGNORE_WARNING__
11 11
12 from PyQt4.QtCore import Qt, QModelIndex, qVersion 12 from PyQt4.QtCore import Qt, QModelIndex, qVersion
13 from PyQt4.QtGui import QTreeView, QAbstractItemView, QMenu, QSortFilterProxyModel, \ 13 from PyQt4.QtGui import QTreeView, QAbstractItemView, QMenu, \
14 QHeaderView, QItemSelectionModel, QDialog 14 QSortFilterProxyModel, QHeaderView, QItemSelectionModel, QDialog
15 15
16 from E5Gui.E5Application import e5App 16 from E5Gui.E5Application import e5App
17 from E5Gui import E5MessageBox 17 from E5Gui import E5MessageBox
18 18
19 import Utilities 19 import Utilities
21 21
22 class WatchPointViewer(QTreeView): 22 class WatchPointViewer(QTreeView):
23 """ 23 """
24 Class implementing the watch expression viewer widget. 24 Class implementing the watch expression viewer widget.
25 25
26 Watch expressions will be shown with all their details. They can be modified through 26 Watch expressions will be shown with all their details. They can be
27 the context menu of this widget. 27 modified through the context menu of this widget.
28 """ 28 """
29 def __init__(self, parent=None): 29 def __init__(self, parent=None):
30 """ 30 """
31 Constructor 31 Constructor
32 32
53 53
54 def setModel(self, model): 54 def setModel(self, model):
55 """ 55 """
56 Public slot to set the watch expression model. 56 Public slot to set the watch expression model.
57 57
58 @param reference to the watch expression model (WatchPointModel) 58 @param model reference to the watch expression model (WatchPointModel)
59 """ 59 """
60 self.__model = model 60 self.__model = model
61 61
62 self.sortingModel = QSortFilterProxyModel() 62 self.sortingModel = QSortFilterProxyModel()
63 self.sortingModel.setDynamicSortFilter(True) 63 self.sortingModel.setDynamicSortFilter(True)
83 self.__resizeColumns() 83 self.__resizeColumns()
84 self.__resort() 84 self.__resort()
85 85
86 def __resizeColumns(self): 86 def __resizeColumns(self):
87 """ 87 """
88 Private slot to resize the view when items get added, edited or deleted. 88 Private slot to resize the view when items get added, edited or
89 deleted.
89 """ 90 """
90 self.header().resizeSections(QHeaderView.ResizeToContents) 91 self.header().resizeSections(QHeaderView.ResizeToContents)
91 self.header().setStretchLastSection(True) 92 self.header().setStretchLastSection(True)
92 93
93 def __resort(self): 94 def __resort(self):
100 def __toSourceIndex(self, index): 101 def __toSourceIndex(self, index):
101 """ 102 """
102 Private slot to convert an index to a source index. 103 Private slot to convert an index to a source index.
103 104
104 @param index index to be converted (QModelIndex) 105 @param index index to be converted (QModelIndex)
106 @return mapped index (QModelIndex)
105 """ 107 """
106 return self.sortingModel.mapToSource(index) 108 return self.sortingModel.mapToSource(index)
107 109
108 def __fromSourceIndex(self, sindex): 110 def __fromSourceIndex(self, sindex):
109 """ 111 """
110 Private slot to convert a source index to an index. 112 Private slot to convert a source index to an index.
111 113
112 @param sindex source index to be converted (QModelIndex) 114 @param sindex source index to be converted (QModelIndex)
115 @return mapped index (QModelIndex)
113 """ 116 """
114 return self.sortingModel.mapFromSource(sindex) 117 return self.sortingModel.mapFromSource(sindex)
115 118
116 def __setRowSelected(self, index, selected=True): 119 def __setRowSelected(self, index, selected=True):
117 """ 120 """
138 self.menu = QMenu() 141 self.menu = QMenu()
139 self.menu.addAction(self.trUtf8("Add"), self.__addWatchPoint) 142 self.menu.addAction(self.trUtf8("Add"), self.__addWatchPoint)
140 self.menu.addAction(self.trUtf8("Edit..."), self.__editWatchPoint) 143 self.menu.addAction(self.trUtf8("Edit..."), self.__editWatchPoint)
141 self.menu.addSeparator() 144 self.menu.addSeparator()
142 self.menu.addAction(self.trUtf8("Enable"), self.__enableWatchPoint) 145 self.menu.addAction(self.trUtf8("Enable"), self.__enableWatchPoint)
143 self.menu.addAction(self.trUtf8("Enable all"), self.__enableAllWatchPoints) 146 self.menu.addAction(self.trUtf8("Enable all"),
147 self.__enableAllWatchPoints)
144 self.menu.addSeparator() 148 self.menu.addSeparator()
145 self.menu.addAction(self.trUtf8("Disable"), self.__disableWatchPoint) 149 self.menu.addAction(self.trUtf8("Disable"), self.__disableWatchPoint)
146 self.menu.addAction(self.trUtf8("Disable all"), self.__disableAllWatchPoints) 150 self.menu.addAction(self.trUtf8("Disable all"),
151 self.__disableAllWatchPoints)
147 self.menu.addSeparator() 152 self.menu.addSeparator()
148 self.menu.addAction(self.trUtf8("Delete"), self.__deleteWatchPoint) 153 self.menu.addAction(self.trUtf8("Delete"), self.__deleteWatchPoint)
149 self.menu.addAction(self.trUtf8("Delete all"), self.__deleteAllWatchPoints) 154 self.menu.addAction(self.trUtf8("Delete all"),
155 self.__deleteAllWatchPoints)
150 self.menu.addSeparator() 156 self.menu.addSeparator()
151 self.menu.addAction(self.trUtf8("Configure..."), self.__configure) 157 self.menu.addAction(self.trUtf8("Configure..."), self.__configure)
152 158
153 self.backMenuActions = {} 159 self.backMenuActions = {}
154 self.backMenu = QMenu() 160 self.backMenu = QMenu()
155 self.backMenu.addAction(self.trUtf8("Add"), self.__addWatchPoint) 161 self.backMenu.addAction(self.trUtf8("Add"), self.__addWatchPoint)
156 self.backMenuActions["EnableAll"] = \ 162 self.backMenuActions["EnableAll"] = \
157 self.backMenu.addAction(self.trUtf8("Enable all"), 163 self.backMenu.addAction(self.trUtf8("Enable all"),
158 self.__enableAllWatchPoints) 164 self.__enableAllWatchPoints)
159 self.backMenuActions["DisableAll"] = \ 165 self.backMenuActions["DisableAll"] = \
160 self.backMenu.addAction(self.trUtf8("Disable all"), 166 self.backMenu.addAction(self.trUtf8("Disable all"),
161 self.__disableAllWatchPoints) 167 self.__disableAllWatchPoints)
162 self.backMenuActions["DeleteAll"] = \ 168 self.backMenuActions["DeleteAll"] = \
163 self.backMenu.addAction(self.trUtf8("Delete all"), 169 self.backMenu.addAction(self.trUtf8("Delete all"),
164 self.__deleteAllWatchPoints) 170 self.__deleteAllWatchPoints)
165 self.backMenu.addSeparator() 171 self.backMenu.addSeparator()
166 self.backMenu.addAction(self.trUtf8("Configure..."), self.__configure) 172 self.backMenu.addAction(self.trUtf8("Configure..."), self.__configure)
167 self.backMenu.aboutToShow.connect(self.__showBackMenu) 173 self.backMenu.aboutToShow.connect(self.__showBackMenu)
168 174
169 self.multiMenu = QMenu() 175 self.multiMenu = QMenu()
170 self.multiMenu.addAction(self.trUtf8("Add"), self.__addWatchPoint) 176 self.multiMenu.addAction(self.trUtf8("Add"), self.__addWatchPoint)
171 self.multiMenu.addSeparator() 177 self.multiMenu.addSeparator()
172 self.multiMenu.addAction(self.trUtf8("Enable selected"), 178 self.multiMenu.addAction(self.trUtf8("Enable selected"),
173 self.__enableSelectedWatchPoints) 179 self.__enableSelectedWatchPoints)
174 self.multiMenu.addAction(self.trUtf8("Enable all"), self.__enableAllWatchPoints) 180 self.multiMenu.addAction(self.trUtf8("Enable all"),
181 self.__enableAllWatchPoints)
175 self.multiMenu.addSeparator() 182 self.multiMenu.addSeparator()
176 self.multiMenu.addAction(self.trUtf8("Disable selected"), 183 self.multiMenu.addAction(self.trUtf8("Disable selected"),
177 self.__disableSelectedWatchPoints) 184 self.__disableSelectedWatchPoints)
178 self.multiMenu.addAction(self.trUtf8("Disable all"), self.__disableAllWatchPoints) 185 self.multiMenu.addAction(self.trUtf8("Disable all"),
186 self.__disableAllWatchPoints)
179 self.multiMenu.addSeparator() 187 self.multiMenu.addSeparator()
180 self.multiMenu.addAction(self.trUtf8("Delete selected"), 188 self.multiMenu.addAction(self.trUtf8("Delete selected"),
181 self.__deleteSelectedWatchPoints) 189 self.__deleteSelectedWatchPoints)
182 self.multiMenu.addAction(self.trUtf8("Delete all"), self.__deleteAllWatchPoints) 190 self.multiMenu.addAction(self.trUtf8("Delete all"),
191 self.__deleteAllWatchPoints)
183 self.multiMenu.addSeparator() 192 self.multiMenu.addSeparator()
184 self.multiMenu.addAction(self.trUtf8("Configure..."), self.__configure) 193 self.multiMenu.addAction(self.trUtf8("Configure..."), self.__configure)
185 194
186 def __showContextMenu(self, coord): 195 def __showContextMenu(self, coord):
187 """ 196 """
208 Private slot to clear the selection. 217 Private slot to clear the selection.
209 """ 218 """
210 for index in self.selectedIndexes(): 219 for index in self.selectedIndexes():
211 self.__setRowSelected(index, False) 220 self.__setRowSelected(index, False)
212 221
213 def __findDuplicates(self, cond, special, showMessage=False, index=QModelIndex()): 222 def __findDuplicates(self, cond, special, showMessage=False,
223 index=QModelIndex()):
214 """ 224 """
215 Private method to check, if an entry already exists. 225 Private method to check, if an entry already exists.
216 226
217 @param cond condition to check (string) 227 @param cond condition to check (string)
218 @param special special condition to check (string) 228 @param special special condition to check (string)
219 @param showMessage flag indicating a message should be shown, 229 @param showMessage flag indicating a message should be shown,
220 if a duplicate entry is found (boolean) 230 if a duplicate entry is found (boolean)
221 @param index index that should not be considered duplicate (QModelIndex) 231 @param index index that should not be considered duplicate
232 (QModelIndex)
222 @return flag indicating a duplicate entry (boolean) 233 @return flag indicating a duplicate entry (boolean)
223 """ 234 """
224 idx = self.__model.getWatchPointIndex(cond, special) 235 idx = self.__model.getWatchPointIndex(cond, special)
225 duplicate = idx.isValid() and idx.internalPointer() != index.internalPointer() 236 duplicate = idx.isValid() and \
237 idx.internalPointer() != index.internalPointer()
226 if showMessage and duplicate: 238 if showMessage and duplicate:
227 if not special: 239 if not special:
228 msg = self.trUtf8("""<p>A watch expression '<b>{0}</b>'""" 240 msg = self.trUtf8("""<p>A watch expression '<b>{0}</b>'"""
229 """ already exists.</p>""")\ 241 """ already exists.</p>""")\
230 .format(Utilities.html_encode(cond)) 242 .format(Utilities.html_encode(cond))
231 else: 243 else:
232 msg = self.trUtf8("""<p>A watch expression '<b>{0}</b>'""" 244 msg = self.trUtf8(
233 """ for the variable <b>{1}</b> already exists.</p>""")\ 245 """<p>A watch expression '<b>{0}</b>'"""
234 .format(special, Utilities.html_encode(cond)) 246 """ for the variable <b>{1}</b> already exists.</p>""")\
247 .format(special, Utilities.html_encode(cond))
235 E5MessageBox.warning(self, 248 E5MessageBox.warning(self,
236 self.trUtf8("Watch expression already exists"), 249 self.trUtf8("Watch expression already exists"),
237 msg) 250 msg)
238 251
239 return duplicate 252 return duplicate
245 from .EditWatchpointDialog import EditWatchpointDialog 258 from .EditWatchpointDialog import EditWatchpointDialog
246 dlg = EditWatchpointDialog(("", False, True, 0, ""), self) 259 dlg = EditWatchpointDialog(("", False, True, 0, ""), self)
247 if dlg.exec_() == QDialog.Accepted: 260 if dlg.exec_() == QDialog.Accepted:
248 cond, temp, enabled, ignorecount, special = dlg.getData() 261 cond, temp, enabled, ignorecount, special = dlg.getData()
249 if not self.__findDuplicates(cond, special, True): 262 if not self.__findDuplicates(cond, special, True):
250 self.__model.addWatchPoint(cond, special, (temp, enabled, ignorecount)) 263 self.__model.addWatchPoint(cond, special,
264 (temp, enabled, ignorecount))
251 self.__resizeColumns() 265 self.__resizeColumns()
252 self.__resort() 266 self.__resort()
253 267
254 def __doubleClicked(self, index): 268 def __doubleClicked(self, index):
255 """ 269 """
295 309
296 def __setWpEnabled(self, index, enabled): 310 def __setWpEnabled(self, index, enabled):
297 """ 311 """
298 Private method to set the enabled status of a watch expression. 312 Private method to set the enabled status of a watch expression.
299 313
300 @param index index of watch expression to be enabled/disabled (QModelIndex) 314 @param index index of watch expression to be enabled/disabled
315 (QModelIndex)
301 @param enabled flag indicating the enabled status to be set (boolean) 316 @param enabled flag indicating the enabled status to be set (boolean)
302 """ 317 """
303 sindex = self.__toSourceIndex(index) 318 sindex = self.__toSourceIndex(index)
304 if sindex.isValid(): 319 if sindex.isValid():
305 self.__model.setWatchPointEnabledByIndex(sindex, enabled) 320 self.__model.setWatchPointEnabledByIndex(sindex, enabled)
313 self.__resizeColumns() 328 self.__resizeColumns()
314 self.__resort() 329 self.__resort()
315 330
316 def __enableAllWatchPoints(self): 331 def __enableAllWatchPoints(self):
317 """ 332 """
318 Private slot to handle the enable all watch expressions context menu entry. 333 Private slot to handle the enable all watch expressions context menu
334 entry.
319 """ 335 """
320 index = self.model().index(0, 0) 336 index = self.model().index(0, 0)
321 while index.isValid(): 337 while index.isValid():
322 self.__setWpEnabled(index, True) 338 self.__setWpEnabled(index, True)
323 index = self.indexBelow(index) 339 index = self.indexBelow(index)
324 self.__resizeColumns() 340 self.__resizeColumns()
325 self.__resort() 341 self.__resort()
326 342
327 def __enableSelectedWatchPoints(self): 343 def __enableSelectedWatchPoints(self):
328 """ 344 """
329 Private slot to handle the enable selected watch expressions context menu entry. 345 Private slot to handle the enable selected watch expressions context
346 menu entry.
330 """ 347 """
331 for index in self.selectedIndexes(): 348 for index in self.selectedIndexes():
332 if index.column() == 0: 349 if index.column() == 0:
333 self.__setWpEnabled(index, True) 350 self.__setWpEnabled(index, True)
334 self.__resizeColumns() 351 self.__resizeColumns()
343 self.__resizeColumns() 360 self.__resizeColumns()
344 self.__resort() 361 self.__resort()
345 362
346 def __disableAllWatchPoints(self): 363 def __disableAllWatchPoints(self):
347 """ 364 """
348 Private slot to handle the disable all watch expressions context menu entry. 365 Private slot to handle the disable all watch expressions context menu
366 entry.
349 """ 367 """
350 index = self.model().index(0, 0) 368 index = self.model().index(0, 0)
351 while index.isValid(): 369 while index.isValid():
352 self.__setWpEnabled(index, False) 370 self.__setWpEnabled(index, False)
353 index = self.indexBelow(index) 371 index = self.indexBelow(index)
354 self.__resizeColumns() 372 self.__resizeColumns()
355 self.__resort() 373 self.__resort()
356 374
357 def __disableSelectedWatchPoints(self): 375 def __disableSelectedWatchPoints(self):
358 """ 376 """
359 Private slot to handle the disable selected watch expressions context menu entry. 377 Private slot to handle the disable selected watch expressions context
378 menu entry.
360 """ 379 """
361 for index in self.selectedIndexes(): 380 for index in self.selectedIndexes():
362 if index.column() == 0: 381 if index.column() == 0:
363 self.__setWpEnabled(index, False) 382 self.__setWpEnabled(index, False)
364 self.__resizeColumns() 383 self.__resizeColumns()
373 if sindex.isValid(): 392 if sindex.isValid():
374 self.__model.deleteWatchPointByIndex(sindex) 393 self.__model.deleteWatchPointByIndex(sindex)
375 394
376 def __deleteAllWatchPoints(self): 395 def __deleteAllWatchPoints(self):
377 """ 396 """
378 Private slot to handle the delete all watch expressions context menu entry. 397 Private slot to handle the delete all watch expressions context menu
398 entry.
379 """ 399 """
380 self.__model.deleteAll() 400 self.__model.deleteAll()
381 401
382 def __deleteSelectedWatchPoints(self): 402 def __deleteSelectedWatchPoints(self):
383 """ 403 """
384 Private slot to handle the delete selected watch expressions context menu entry. 404 Private slot to handle the delete selected watch expressions context
405 menu entry.
385 """ 406 """
386 idxList = [] 407 idxList = []
387 for index in self.selectedIndexes(): 408 for index in self.selectedIndexes():
388 sindex = self.__toSourceIndex(index) 409 sindex = self.__toSourceIndex(index)
389 if sindex.isValid() and index.column() == 0: 410 if sindex.isValid() and index.column() == 0:
415 436
416 def __configure(self): 437 def __configure(self):
417 """ 438 """
418 Private method to open the configuration dialog. 439 Private method to open the configuration dialog.
419 """ 440 """
420 e5App().getObject("UserInterface").showPreferences("debuggerGeneralPage") 441 e5App().getObject("UserInterface")\
442 .showPreferences("debuggerGeneralPage")

eric ide

mercurial