-
Notifications
You must be signed in to change notification settings - Fork 0
/
Table.py
158 lines (141 loc) · 8.79 KB
/
Table.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
from PyQt5.QtWidgets import QHeaderView, QDateTimeEdit, QHeaderView, QTableWidget, QTableWidgetItem
from PyQt5 import QtGui, QtCore
from PyQt5.QtCore import Qt, QDateTime
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~ TableView ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class OutcomeTable(QTableWidget):
# +++++++++++++++++++++++++++ __init__ ++++++++++++++++++++++++++++++++
def __init__(self, header, outComeCategory, units, currencyIndex):
QTableWidget.__init__(self)
self._CurrencyIndex = currencyIndex
self._header = header
self._units = units
self._category = outComeCategory
self.setColumnCount(len(self._header))
self.setHorizontalHeaderLabels(self._header)
self.setSortingEnabled(False)
self.setWordWrap(True)
self.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeToContents)
self.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
self.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeToContents)
self.horizontalHeader().setSectionResizeMode(3, QHeaderView.ResizeToContents)
self.horizontalHeader().setSectionResizeMode(4, QHeaderView.ResizeToContents)
self.horizontalHeader().setSectionResizeMode(5, QHeaderView.ResizeToContents)
# +++++++++++++++++++++++++ importEvents ++++++++++++++++++++++++++++++
def importEvents(self, data):
self.setRowCount(0)
TimeStampsIndex = 0
for key in data:
self.rowNumb = self.rowCount()
self.setRowCount(self.rowNumb + len(data[key]))
timeStamp = QDateTimeEdit()
timeStamp.setDisplayFormat("dd.MM.yyyy")
timeStamp.setReadOnly(True)
timeStampCell = QDateTime.currentDateTime()
timeStampCell = QDateTime.fromString(key, "dd.MM.yyyy")
timeStamp.setDateTime(timeStampCell)
self.setCellWidget(TimeStampsIndex, 0, timeStamp)
if len(data[key]) > 1:
self.setSpan(TimeStampsIndex, 0, len(data[key]) , 1)
for row in range(len(data[key])):
cell_0 = QTableWidgetItem('')
cell_0.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
cell_0.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled )
cell_1 = QTableWidgetItem('')
cell_1.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
cell_1.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled )
cell_2 = QTableWidgetItem('')
cell_2.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
cell_2.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled )
cell_3 = QTableWidgetItem('')
cell_3.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
cell_3.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled )
cell_4 = QTableWidgetItem('')
if data[key][row][4]['cell_4']:
cell_4.setIcon(QtGui.QIcon('icon/cash.svg'))
else:
cell_4.setIcon(QtGui.QIcon('icon/card.svg'))
cell_4.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
cell_4.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled )
self.setItem(TimeStampsIndex + row, 1, cell_0)
self.setItem(TimeStampsIndex + row, 2, cell_1)
self.setItem(TimeStampsIndex + row, 3, cell_2)
self.setItem(TimeStampsIndex + row, 4, cell_3)
self.setItem(TimeStampsIndex + row, 5, cell_4)
self.item(TimeStampsIndex + row, 1).setText(data[key][row][0]['cell_0'])
if self._units[data[key][row][1]['cell_1.2']] == "--":
self.item(TimeStampsIndex + row, 2).setText(self._units[data[key][row][1]['cell_1.2']])
else:
self.item(TimeStampsIndex + row, 2).setText(data[key][row][1]['cell_1.1'] + self._units[data[key][row][1]['cell_1.2']])
self.item(TimeStampsIndex + row, 3).setText(self._category[data[key][row][2]['cell_2.1']])
try:
if data[key][row][3]['cell_3.3'] == "--" or data[key][row][3]['cell_3.3'] == "":
self.item(TimeStampsIndex + row, 4).setText("%.2f" % round(float(data[key][row][3]['cell_3.1']), 2) + self._CurrencyIndex[data[key][row][3]['cell_3.2']])
else:
self.item(TimeStampsIndex + row, 4).setText("%.2f" % round(float(data[key][row][3]['cell_3.1']), 2) + self._CurrencyIndex[data[key][row][3]['cell_3.2']] + " ---> " + "%.2f" % round(float(data[key][row][3]['cell_3.3']), 2) + self._CurrencyIndex[data[key][row][3]['cell_3.4']])
except ValueError:
pass
if data[key][row][4]['cell_4']:
self.item(TimeStampsIndex + row, 5).setText("ნაღდი")
else:
self.item(TimeStampsIndex + row, 5).setText("გადარიცხვა")
TimeStampsIndex = TimeStampsIndex + len(data[key])
self.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeToContents)
self.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
self.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeToContents)
self.horizontalHeader().setSectionResizeMode(3, QHeaderView.ResizeToContents)
self.horizontalHeader().setSectionResizeMode(4, QHeaderView.ResizeToContents)
self.horizontalHeader().setSectionResizeMode(5, QHeaderView.ResizeToContents)
self.scrollToBottom()
# ~~~~~~~~~~~~~~~~~~~~~~~~~ IncomeTable ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class IncomeTable(QTableWidget):
# +++++++++++++++++++++++++++ __init__ ++++++++++++++++++++++++++++++++
def __init__(self, header, IncomeSourceCategory, currencyIndex):
QTableWidget.__init__(self)
self._CurrencyIndex = currencyIndex
self._header = header
self._IncomeSourceCategory = IncomeSourceCategory
self.setColumnCount(len(self._header))
self.setHorizontalHeaderLabels(self._header)
self.setSortingEnabled(False)
self.setWordWrap(True)
self.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeToContents)
self.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
self.horizontalHeader().setSectionResizeMode(2, QHeaderView.Stretch)
# +++++++++++++++++++++++++ importEvents ++++++++++++++++++++++++++++++
def importEvents(self, data):
self.setRowCount(0)
TimeStampsIndex = 0
for key in data:
self.rowNumb = self.rowCount()
self.setRowCount(self.rowNumb + len(data[key]))
timeStamp = QDateTimeEdit()
timeStamp.setDisplayFormat("dd.MM.yyyy")
timeStamp.setReadOnly(True)
timeStampCell = QDateTime.currentDateTime()
timeStampCell = QDateTime.fromString(key, "dd.MM.yyyy")
timeStamp.setDateTime(timeStampCell)
self.setCellWidget(TimeStampsIndex, 0, timeStamp)
if len(data[key]) > 1:
self.setSpan(TimeStampsIndex, 0, len(data[key]) , 1)
for row in range(len(data[key])):
cell_0 = QTableWidgetItem('')
cell_0.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
cell_0.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled )
cell_1 = QTableWidgetItem('')
cell_1.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
cell_1.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled )
self.setItem(TimeStampsIndex + row, 1, cell_0)
self.setItem(TimeStampsIndex + row, 2, cell_1)
self.item(TimeStampsIndex + row, 1).setText(self._IncomeSourceCategory[data[key][row][0]['cell_0']])
try:
if len(data[key][row][1]) == 2:
self.item(TimeStampsIndex + row, 2).setText("%.2f" % round(float(data[key][row][1]['cell_1.1']), 2) + self._CurrencyIndex[data[key][row][1]['cell_1.2']])
elif len(data[key][row][1]) == 4:
self.item(TimeStampsIndex + row, 2).setText("%.2f" % round(float(data[key][row][1]['cell_1.1']), 2) + self._CurrencyIndex[data[key][row][1]['cell_1.2']] + " -- კონვერტირდა --> " + "%.2f" % round(float(data[key][row][1]['cell_1.3']), 2) + self._CurrencyIndex[data[key][row][1]['cell_1.4']])
except ValueError:
pass
TimeStampsIndex = TimeStampsIndex + len(data[key])
self.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeToContents)
self.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
self.horizontalHeader().setSectionResizeMode(2, QHeaderView.Stretch)
self.scrollToBottom()