forked from hyzyla/InstabotGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccountTable.py
executable file
·153 lines (119 loc) · 5.06 KB
/
accountTable.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
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QColor
from PyQt5.QtWidgets import QTableWidget, QAbstractItemView, QHeaderView, QTableWidgetItem
from multiprocessing.pool import ThreadPool
from account import Account
COLUMNS = {
"KIND": 0,
"NAME": 1,
"STATUS": 2,
"FOLLOWS": 3,
"UNFOLLOWS": 4,
"LIKES": 5,
"COMMENTS": 6,
"FOLLOWER": 7,
"AVERAGE LIKES": 8,
}
class AccountTable(QTableWidget):
def __init__(self, *args, **kwargs):
QTableWidget.__init__(self, 0, 9, *args, **kwargs)
self.configUI()
self.rows = []
def startAll(self):
for row in range(self.rowCount()):
item = self.item(row, COLUMNS["NAME"])
account = item.data(Qt.UserRole)
if account.workingThread.isRunning:
continue
account.startWorking()
def addNewRow(self, account):
firstRow = 0
self.insertRow(firstRow)
self.rows.append(account)
self.setFirstColumn(firstRow, account)
self.updateRow(firstRow)
def setFirstColumn(self, row, account):
name = account.getCredentials()['login']
nameItem = QTableWidgetItem(name)
nameItem.setData(Qt.UserRole, account)
account.setTableAndItem(self, nameItem)
self.setItem(row, COLUMNS['NAME'], nameItem)
def updateRow(self, row: int):
self.setSortingEnabled(False)
# Getting account object from name column
nameItem = self.item(row, COLUMNS['NAME'])
account = nameItem.data(Qt.UserRole)
# Setting all other columns
# Status button
# Kind
kindItem = QTableWidgetItem(account.getKind())
self.setItem(row, COLUMNS['KIND'], kindItem)
# Status
statusItem = QTableWidgetItem(account.status)
statusItem.setTextAlignment(Qt.AlignCenter)
if account.status == "OFF":
statusItem.setForeground(QColor("red"))
elif account.status == "ON":
statusItem.setForeground(QColor("green"))
elif account.status == "Connecting...":
statusItem.setForeground(QColor("orange"))
elif account.status == "Waiting...":
statusItem.setForeground(QColor("blue"))
self.setItem(row, COLUMNS["STATUS"], statusItem)
# Follows done
followDoneItem = QTableWidgetItem('{}'.format(account.followsDoneStat.get()))
self.setItem(row, COLUMNS['FOLLOWS'], followDoneItem)
# unfollow done
unfollowDoneItem = QTableWidgetItem('{}'.format(account.unfollowsDoneStat.get()))
self.setItem(row, COLUMNS['UNFOLLOWS'], unfollowDoneItem)
# likes done
likesDoneItem = QTableWidgetItem('{} {:+}'.format(*account.likesDoneStat.get()))
self.setItem(row, COLUMNS['LIKES'], likesDoneItem)
# likes done
commentsDoneItem = QTableWidgetItem('{} {:+}'.format(*account.commentsDoneStat.get()))
self.setItem(row, COLUMNS['COMMENTS'], commentsDoneItem)
# likes done
followersItem = QTableWidgetItem('{} {:+}'.format(*account.followersStat.get()))
self.setItem(row, COLUMNS['FOLLOWER'], followersItem)
self.sortItems(0)
self.resizeRowsToContents()
def removeCurrent(self):
indexes = self.selectionModel().selectedRows()
for index in reversed(indexes):
item = self.item(index.row(), COLUMNS['NAME'])
account = item.data(Qt.UserRole)
account.waitingThread.cancel()
self.rows.remove(account)
self.removeRow(index.row())
def configUI(self):
self.setAlternatingRowColors(True)
self.setSelectionBehavior(QAbstractItemView.SelectRows)
self.setEditTriggers(QAbstractItemView.NoEditTriggers)
labels = ["KIND", "NAME", "STATUS", "FOLLOWS", "UNFOLLOWS", "LIKES", "COMMENTS",
"FOLLOWER", "AVERAGE LIKES\nPER POST"]
self.setHorizontalHeaderLabels(labels)
self.verticalHeader().setVisible(False)
self.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
self.horizontalHeader().setHighlightSections(False)
self.itemDoubleClicked.connect(self.handleItemDoubleClicked)
self.itemClicked.connect(self.handleItemClicked)
def handleItemClicked(self, item):
row = item.row()
column = item.column()
item = self.item(row, COLUMNS["NAME"])
account = item.data(Qt.UserRole)
if column == 2:
account.handleStatusButtonClicked()
def handleItemDoubleClicked(self, item):
row = item.row()
column = item.column()
item = self.item(row, COLUMNS["NAME"])
account = item.data(Qt.UserRole)
if column in [0, 1]:
account.stopWorking()
dlg = account.settingDialog
if not dlg.exec_():
return
account.startWorking()
self.setFirstColumn(row, account)
self.updateRow(row)