-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.py
More file actions
52 lines (44 loc) · 1.76 KB
/
widget.py
File metadata and controls
52 lines (44 loc) · 1.76 KB
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
import sys
from PySide6.QtWidgets import QApplication, QWidget
from ui_form import Ui_Widget
from Converterz import*
class Widget(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.ui = Ui_Widget()
self.ui.setupUi(self)
# Connect buttons to functions
self.ui.pushButton.clicked.connect(self.button1_clicked)
self.ui.Input1.returnPressed.connect(self.Input1_returned)
def update_line_edit(self,bintext,octtext,hextext,graytext):
self.ui.binout.setText(bintext)
self.ui.octout.setText(octtext)
self.ui.hexout.setText(hextext)
self.ui.grayout.setText(graytext)
def button1_clicked(self):
binary = []
octal=[]
hexa = []
gray = []
Decimal = self.ui.Input1.text()
if (Decimal.lstrip("-")).isnumeric() != 1:
self.update_line_edit("error (NaN)","error (NaN)","error (NaN)","error (NaN)")
else:
if int(Decimal) < 0:
self.update_line_edit("error (Negative)","error (Negative)","error (Negative)","error (Negative)")
else:
x = int(Decimal)
bintext = reverser(convertbinary(x,binary))
octtext = reverser(convertoctal(x,octal))
hextext = reverser(converthexa(x,hexa))
graytext = stringer(convertgray(x,binary,gray))
# graytext = 'work in progress'
self.update_line_edit(str(bintext),str(octtext),str(hextext),str(graytext))
def Input1_returned(self):
self.button1_clicked()
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setStyle("breeze") # Set the Breeze style
widget = Widget()
widget.show()
sys.exit(app.exec())