-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkuscalc.py
54 lines (51 loc) · 1.69 KB
/
linkuscalc.py
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
import sys
from mathfunctions import toBinary, toTernary
from PyQt4 import QtGui
from math import sqrt
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
self.wie=4
def initUI(self):
inw=QtGui.QLineEdit(self)
inw.move(130,80)
self.lbl=QtGui.QLabel(self)
self.lbl.move(130,120)
inw.textChanged[str].connect(self.onInput)
combo = QtGui.QComboBox(self)
combo.move(10, 80)
combo.addItem("toBinary")
combo.addItem("toTernary")
combo.addItem("fromBinary")
combo.addItem("fromTernary")
combo.activated[str].connect(self.onTypeSwitch)
self.setWindowTitle("Very simple GUI 2,3 <--> 10 integer base converter")
self.resize(400, 230)
self.center()
self.show()
def onTypeSwitch(self, item):
if item=='fromBinary': self.wie=2
elif item=='fromTernary': self.wie=3
elif item=='toBinary': self.wie=4
else: self.wie=5
def onInput(self, text):
try:
if text=='': self.lbl.setText('')
elif self.wie==4: self.lbl.setText(toBinary(text))
elif self.wie==5: self.lbl.setText(toTernary(text))
else: self.lbl.setText(str(int(text, self.wie)))
except ValueError:
self.lbl.setText("Value Error!")
self.lbl.adjustSize()
def center(self):
qr=self.frameGeometry()
cp = QtGui.QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def main():
app=QtGui.QApplication(sys.argv)
GUI=Example()
sys.exit(app.exec())
if __name__ == '__main__':
main()