4
# Licensed under the Apache License, Version 2.0 (the "Apache License")
5
# with the following modification; you may not use this file except in
6
# compliance with the Apache License and the following modification to it:
7
# Section 6. Trademarks. is deleted and replaced with:
9
# 6. Trademarks. This License does not grant permission to use the trade
10
# names, trademarks, service marks, or product names of the Licensor
11
# and its affiliates, except as required to comply with Section 4(c) of
12
# the License and to reproduce the content of the NOTICE file.
14
# You may obtain a copy of the Apache License at
16
# http://www.apache.org/licenses/LICENSE-2.0
18
# Unless required by applicable law or agreed to in writing, software
19
# distributed under the Apache License with the above modification is
20
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
# KIND, either express or implied. See the Apache License for the specific
22
# language governing permissions and limitations under the Apache License.
24
from PySide import QtGui, QtCore
25
from watchWindowUI import Ui_WatchWindow
29
# XXX USD WATCH WINDOW DEACTIVATED
31
separatorColor = QtGui.QColor(255, 255, 255)
32
separatorString = "\n==================================\n"
34
class WatchWindow(QtGui.QDialog):
35
def __init__(self, parent):
36
QtGui.QDialog.__init__(self,parent)
37
self._ui = Ui_WatchWindow()
38
self._ui.setupUi(self)
40
self._boxWithFocus = self._ui.unvaryingEdit
41
self._prevDualScrollVal = 0
44
self._searchString = ""
46
self.addAction(self._ui.actionFind)
47
self.addAction(self._ui.actionFindNext)
48
self.addAction(self._ui.actionFindPrevious)
50
QtCore.QObject.connect(self._ui.doneButton,
51
QtCore.SIGNAL('clicked()'),
53
QtCore.QObject.connect(self,
54
QtCore.SIGNAL('finished(int)'),
55
self._cleanUpAndClose)
56
QtCore.QObject.connect(self._ui.dualScroller,
57
QtCore.SIGNAL('valueChanged(int)'),
58
self._changeBothSliders)
59
QtCore.QObject.connect(self._ui.diffButton,
60
QtCore.SIGNAL('clicked()'),
62
QtCore.QObject.connect(self._ui.actionFind,
63
QtCore.SIGNAL('triggered()'),
65
QtCore.QObject.connect(self._ui.actionFindNext,
66
QtCore.SIGNAL('triggered()'),
68
QtCore.QObject.connect(self._ui.actionFindPrevious,
69
QtCore.SIGNAL('triggered()'),
71
QtCore.QObject.connect(self._ui.varyingEdit,
72
QtCore.SIGNAL('cursorPositionChanged()'),
73
self._varyingCursorChanged)
74
QtCore.QObject.connect(self._ui.unvaryingEdit,
75
QtCore.SIGNAL('cursorPositionChanged()'),
76
self._unvaryingCursorChanged)
78
QtCore.QObject.connect(self._ui.splitter,
79
QtCore.SIGNAL('splitterMoved(int, int)'),
82
#create a timer for saving splitter state only when it stops moving
83
self._splitterTimer = QtCore.QTimer(self)
84
self._splitterTimer.setInterval(500)
85
QtCore.QObject.connect(self._splitterTimer, QtCore.SIGNAL('timeout()'),
86
self._saveSplitterState)
90
def _splitterMoved(self, pos, index):
91
# reset the timer every time the splitter moves
92
# when the splitter stop moving for half a second, save state
93
self._splitterTimer.stop()
94
self._splitterTimer.start()
96
def _saveSplitterState(self):
97
self._parent._settings.setAndSave(
98
watchWindowSplitter = self._ui.splitter.saveState())
99
self._splitterTimer.stop()
101
def _varyingCursorChanged(self):
102
self._boxWithFocus = self._ui.varyingEdit
104
def _unvaryingCursorChanged(self):
105
self._boxWithFocus = self._ui.unvaryingEdit
108
searchString = QtGui.QInputDialog.getText(self, "Find",
109
"Enter search string\nUse Ctrl+G to \"Find Next\"\n" + \
110
"Use Ctrl+Shift+G to \"Find Previous\"")
112
self._searchString = searchString[0]
113
if (not self._boxWithFocus.find(self._searchString)):
114
self._boxWithFocus.moveCursor(QtGui.QTextCursor.Start)
115
self._boxWithFocus.find(self._searchString)
118
if (self._searchString == ""):
120
if (not self._boxWithFocus.find(self._searchString)):
121
self._boxWithFocus.moveCursor(QtGui.QTextCursor.Start)
122
self._boxWithFocus.find(self._searchString)
124
def _findPrevious(self):
125
if (self._searchString == ""):
127
if (not self._boxWithFocus.find(self._searchString,
128
QtGui.QTextDocument.FindBackward)):
129
self._boxWithFocus.moveCursor(QtGui.QTextCursor.End)
130
self._boxWithFocus.find(self._searchString,
131
QtGui.QTextDocument.FindBackward)
135
unvarFile = tempfile.NamedTemporaryFile()
136
unvarFile.write(str(self._ui.unvaryingEdit.toPlainText()))
138
varFile = tempfile.NamedTemporaryFile()
139
varFile.write(str(self._ui.varyingEdit.toPlainText()))
142
os.system("xxdiff %s %s" % (unvarFile.name, varFile.name))
147
def _changeBothSliders(self, val):
148
delta = val - self._prevDualScrollVal
149
self._ui.varyingEdit.verticalScrollBar().setValue(
150
self._ui.varyingEdit.verticalScrollBar().value() + delta)
151
self._ui.unvaryingEdit.verticalScrollBar().setValue(
152
self._ui.unvaryingEdit.verticalScrollBar().value() + delta)
153
self._prevDualScrollVal = val
155
def appendContents(self, s, color = QtGui.QColor(0,0,0)):
156
self._ui.varyingEdit.setTextColor(color)
157
self._ui.varyingEdit.append(s)
159
self._ui.dualScroller.setMaximum(max(
160
self._ui.unvaryingEdit.verticalScrollBar().maximum(),
161
self._ui.varyingEdit.verticalScrollBar().maximum()))
162
self._ui.dualScroller.setPageStep(min(
163
self._ui.unvaryingEdit.verticalScrollBar().pageStep(),
164
self._ui.varyingEdit.verticalScrollBar().pageStep()))
166
self._boxWithFocus = self._ui.varyingEdit
168
def appendUnvaryingContents(self, s, color = QtGui.QColor(0,0,0)):
169
self._ui.unvaryingEdit.setTextColor(color)
170
self._ui.unvaryingEdit.append(s)
172
self._ui.dualScroller.setMaximum(max(
173
self._ui.unvaryingEdit.verticalScrollBar().maximum(),
174
self._ui.varyingEdit.verticalScrollBar().maximum()))
175
self._ui.dualScroller.setPageStep(min(
176
self._ui.unvaryingEdit.verticalScrollBar().pageStep(),
177
self._ui.varyingEdit.verticalScrollBar().pageStep()))
179
self._boxWithFocus = self._ui.unvaryingEdit
181
def appendSeparator(self):
182
self.appendContents(separatorString, separatorColor)
183
self.appendUnvaryingContents(separatorString, separatorColor)
185
def clearContents(self):
186
self._ui.varyingEdit.setText("")
187
self._ui.unvaryingEdit.setText("")
189
def _cleanUpAndClose(self, result):
190
self._parent._ui.actionWatch_Window.setChecked(False)
192
def _resetSettings(self):
193
# restore splitter position
194
splitterpos = self._parent._settings.get('watchWindowSplitter')
195
if not splitterpos is None:
196
self._ui.splitter.restoreState(splitterpos)