/usr/share/convertall/unitedit.py is in convertall 0.6.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | #****************************************************************************
# unitedit.py, provides a line edit for unit entry
#
# ConvertAll, a units conversion program
# Copyright (C) 2014, Douglas W. Bell
#
# This is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License, either Version 2 or any later
# version. This program is distributed in the hope that it will be useful,
# but WITTHOUT ANY WARRANTY. See the included LICENSE file for details.
#*****************************************************************************
from PyQt4 import QtCore, QtGui
class UnitEdit(QtGui.QLineEdit):
"""Text line editor for unit entry.
"""
unitChanged = QtCore.pyqtSignal()
currentChanged = QtCore.pyqtSignal()
def __init__(self, unitGroup, parent=None):
QtGui.QLineEdit.__init__(self, parent)
self.unitGroup = unitGroup
self.textEdited.connect(self.updateGroup)
self.cursorPositionChanged.connect(self.updateCurrentUnit)
def unitUpdate(self):
"""Update text from unit group.
"""
newText = self.unitGroup.unitString()
cursorPos = len(newText) - len(self.text()) + self.cursorPosition()
if cursorPos < 0: # cursor set to same distance from right end
cursorPos = 0
self.blockSignals(True)
self.setText(newText)
self.setCursorPosition(cursorPos)
self.blockSignals(False)
self.unitChanged.emit()
def updateGroup(self):
"""Update unit based on edit text change (except spacing change).
"""
if self.text().replace(' ', '') \
!= self.unitGroup.unitString().replace(' ', ''):
self.unitGroup.update(self.text(), self.cursorPosition())
self.currentChanged.emit() # update listView
self.unitUpdate() # replace text with formatted text
def updateCurrentUnit(self):
"""Change current unit based on cursor movement.
"""
self.unitGroup.updateCurrentUnit(self.text(),
self.cursorPosition())
self.currentChanged.emit() # update listView
def keyPressEvent(self, event):
"""Keys for return and up/down.
"""
if event.key() == QtCore.Qt.Key_Up:
self.unitGroup.moveToNext(True)
self.currentChanged.emit() # update listView
self.unitUpdate()
elif event.key() == QtCore.Qt.Key_Down:
self.unitGroup.moveToNext(False)
self.currentChanged.emit() # update listView
self.unitUpdate()
elif event.key() in (QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter):
self.unitGroup.completePartial()
self.currentChanged.emit() # update listView
self.unitUpdate()
else:
QtGui.QLineEdit.keyPressEvent(self, event)
def event(self, event):
"""Catch tab press to complete unit.
"""
if event.type() == QtCore.QEvent.KeyPress and \
event.key() == QtCore.Qt.Key_Tab:
self.unitGroup.completePartial()
self.currentChanged.emit() # update listView
self.unitUpdate()
return QtGui.QLineEdit.event(self, event)
|