1 # -*- coding: utf-8 -*-
3 from PyQt4.QtCore import *
4 from PyQt4.QtGui import *
6 from decimal import Decimal
8 class MyLineEdit(QLineEdit):
10 def setFrozen(self, b):
14 class AmountEdit(MyLineEdit):
16 def __init__(self, decimal_point, is_int = False, parent=None):
17 QLineEdit.__init__(self, parent)
18 self.decimal_point = decimal_point
19 self.textChanged.connect(self.numbify)
21 self.is_shortcut = False
24 p = self.decimal_point()
26 return "BTC" if p == 8 else "mBTC"
29 x = unicode( self.text() )
32 p = pow(10, self.decimal_point())
33 return int( p * Decimal(x) )
35 def setAmount(self, amount):
36 p = pow(10, self.decimal_point())
37 x = amount / Decimal(p)
40 def paintEvent(self, event):
41 QLineEdit.paintEvent(self, event)
42 if self.decimal_point:
43 panel = QStyleOptionFrameV2()
44 self.initStyleOption(panel)
45 textRect = self.style().subElementRect(QStyle.SE_LineEditContents, panel, self)
46 textRect.adjust(2, 0, -10, 0)
47 painter = QPainter(self)
48 painter.setPen(self.palette().brush(QPalette.Disabled, QPalette.Text).color())
49 painter.drawText(textRect, Qt.AlignRight | Qt.AlignVCenter, self.base_unit())
53 text = unicode(self.text()).strip()
55 self.is_shortcut = True
56 pos = self.cursorPosition()
58 if not self.is_int: chars +='.'
59 s = ''.join([i for i in text if i in chars])
64 s = s[:p] + '.' + s[p:p+8]
66 self.setCursorPosition(pos)