|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2003 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to edit breakpoint properties. |
|
8 """ |
|
9 |
|
10 import os.path |
|
11 |
|
12 from PyQt4.QtCore import * |
|
13 from PyQt4.QtGui import * |
|
14 |
|
15 from E4Gui.E4Completers import E4FileCompleter |
|
16 |
|
17 from Ui_EditBreakpointDialog import Ui_EditBreakpointDialog |
|
18 |
|
19 import Utilities |
|
20 |
|
21 class EditBreakpointDialog(QDialog, Ui_EditBreakpointDialog): |
|
22 """ |
|
23 Class implementing a dialog to edit breakpoint properties. |
|
24 """ |
|
25 def __init__(self, id, properties, condHistory, parent = None, name = None, |
|
26 modal = False, addMode = False, filenameHistory = None): |
|
27 """ |
|
28 Constructor |
|
29 |
|
30 @param id id of the breakpoint (tuple) |
|
31 (filename, linenumber) |
|
32 @param properties properties for the breakpoint (tuple) |
|
33 (condition, temporary flag, enabled flag, ignore count) |
|
34 @param condHistory the list of conditionals history (list of strings) |
|
35 @param parent the parent of this dialog |
|
36 @param name the widget name of this dialog |
|
37 @param modal flag indicating a modal dialog |
|
38 """ |
|
39 QDialog.__init__(self,parent) |
|
40 self.setupUi(self) |
|
41 if name: |
|
42 self.setObjectName(name) |
|
43 self.setModal(modal) |
|
44 |
|
45 self.okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
|
46 self.filenameCompleter = E4FileCompleter(self.filenameCombo) |
|
47 |
|
48 fn, lineno = id |
|
49 |
|
50 if not addMode: |
|
51 cond, temp, enabled, count = properties |
|
52 |
|
53 # set the filename |
|
54 if fn is not None: |
|
55 self.filenameCombo.setEditText(fn) |
|
56 |
|
57 # set the line number |
|
58 self.linenoSpinBox.setValue(lineno) |
|
59 |
|
60 # set the condition |
|
61 if cond is None: |
|
62 cond = '' |
|
63 try: |
|
64 curr = condHistory.index(cond) |
|
65 except ValueError: |
|
66 condHistory.insert(0, cond) |
|
67 curr = 0 |
|
68 self.conditionCombo.addItems(condHistory) |
|
69 self.conditionCombo.setCurrentIndex(curr) |
|
70 |
|
71 # set the ignore count |
|
72 self.ignoreSpinBox.setValue(count) |
|
73 |
|
74 # set the checkboxes |
|
75 self.temporaryCheckBox.setChecked(temp) |
|
76 self.enabledCheckBox.setChecked(enabled) |
|
77 |
|
78 self.filenameCombo.setEnabled(False) |
|
79 self.fileButton.setEnabled(False) |
|
80 self.linenoSpinBox.setEnabled(False) |
|
81 self.conditionCombo.setFocus() |
|
82 else: |
|
83 self.setWindowTitle(self.trUtf8("Add Breakpoint")) |
|
84 # set the filename |
|
85 if fn is None: |
|
86 fn = "" |
|
87 try: |
|
88 curr = filenameHistory.index(fn) |
|
89 except ValueError: |
|
90 filenameHistory.insert(0, fn) |
|
91 curr = 0 |
|
92 self.filenameCombo.addItems(filenameHistory) |
|
93 self.filenameCombo.setCurrentIndex(curr) |
|
94 |
|
95 # set the condition |
|
96 cond = '' |
|
97 try: |
|
98 curr = condHistory.index(cond) |
|
99 except ValueError: |
|
100 condHistory.insert(0, cond) |
|
101 curr = 0 |
|
102 self.conditionCombo.addItems(condHistory) |
|
103 self.conditionCombo.setCurrentIndex(curr) |
|
104 |
|
105 if not fn: |
|
106 self.okButton.setEnabled(False) |
|
107 |
|
108 @pyqtSlot() |
|
109 def on_fileButton_clicked(self): |
|
110 """ |
|
111 Private slot to select a file via a file selection dialog. |
|
112 """ |
|
113 file = QFileDialog.getOpenFileName(\ |
|
114 self, |
|
115 self.trUtf8("Select filename of the breakpoint"), |
|
116 self.filenameCombo.currentText(), |
|
117 "") |
|
118 |
|
119 if file: |
|
120 self.filenameCombo.setEditText(Utilities.toNativeSeparators(file)) |
|
121 |
|
122 def on_filenameCombo_editTextChanged(self, fn): |
|
123 """ |
|
124 Private slot to handle the change of the filename. |
|
125 |
|
126 @param fn text of the filename edit (string) |
|
127 """ |
|
128 if not fn: |
|
129 self.okButton.setEnabled(False) |
|
130 else: |
|
131 self.okButton.setEnabled(True) |
|
132 |
|
133 def getData(self): |
|
134 """ |
|
135 Public method to retrieve the entered data. |
|
136 |
|
137 @return a tuple containing the breakpoints new properties |
|
138 (condition, temporary flag, enabled flag, ignore count) |
|
139 """ |
|
140 return (self.conditionCombo.currentText(), |
|
141 self.temporaryCheckBox.isChecked(), |
|
142 self.enabledCheckBox.isChecked(), self.ignoreSpinBox.value()) |
|
143 |
|
144 def getAddData(self): |
|
145 """ |
|
146 Public method to retrieve the entered data for an add. |
|
147 |
|
148 @return a tuple containing the new breakpoints properties |
|
149 (filename, lineno, condition, temporary flag, enabled flag, ignore count) |
|
150 """ |
|
151 fn = self.filenameCombo.currentText() |
|
152 if not fn: |
|
153 fn = None |
|
154 else: |
|
155 fn = os.path.expanduser(os.path.expandvars(fn)) |
|
156 |
|
157 return (fn, self.linenoSpinBox.value(), |
|
158 self.conditionCombo.currentText(), |
|
159 self.temporaryCheckBox.isChecked(), self.enabledCheckBox.isChecked(), |
|
160 self.ignoreSpinBox.value()) |