-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.py
71 lines (57 loc) · 2.41 KB
/
interface.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
from PyQt5.QtWidgets import *
from decimal import Decimal
import data_management
class Gui(QMainWindow):
def __init__(self, app):
super().__init__()
self.app = app
self.resize(600,240)
self.center()
self.setWindowTitle("Foreign Exchange Rates")
#self.setWindowIcon(QIcon("FER.png"))
self.button_update = QPushButton(self)
self.button_update.setText('Update rates')
self.button_update.setToolTip("Push to pull the latest<i> exchange rates</i>.")
self.button_update.resize(self.button_update.sizeHint())
self.button_update.move(25,25)
self.button_update.clicked.connect(app.update_rates)
self.label_rates = QTextEdit(self)
self.label_rates.move(125,26)
self.label_rates.setStyleSheet("font-size: 16px")
self.label_rates.setText('')
self.label_rates.resize(450, 200)
self.base_choice_widget = QComboBox(self)
index = 1
for currency in data_management.CURRENCIES:
self.base_choice_widget.insertItem(index, str(currency))
index += 1
#self.base_choice_widget.insertItem(1,'EUR')
#self.base_choice_widget.insertItem(2,'USD')
#self.base_choice_widget.insertItem(3,'PLN')
self.base_choice_widget.resize(self.base_choice_widget.sizeHint())
self.base_choice_widget.move(25, 65)
self.base_choice_widget.currentIndexChanged.connect(self.send_new_base)
self.show()
def update_rates(self, new_rates, base):
all_rates = list()
for key in sorted(new_rates.keys()):
if key != base:
value = new_rates[key]
all_rates.append("1{}={} {}\n".format(base, value, key))
new_text = str()
for l in all_rates:
new_text += l
self.label_rates.setText(new_text)
def send_new_base(self):
self.app.set_current_base(self.base_choice_widget.currentText())
def center(self):
geometry_of_window = self.frameGeometry()
screen_center = QDesktopWidget().availableGeometry().center()
geometry_of_window.moveCenter(screen_center)
self.move(geometry_of_window.topLeft())
def warn(self, error):
message = "Sorry, some problem occured:\n {}".format(error)
warning_window = QMessageBox()
warning_window.setText(message)
warning_window.exec_()