-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.py
245 lines (170 loc) · 5.69 KB
/
MainWindow.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
import sys
import rTorrentComm
import random
from PyQt4 import QtGui, QtCore
class LoginWindow(QtGui.QWidget):
url = None
username = None
password = None
urlEdit = None
usernameEdit = None
passwordEdit = None
def __init__(self):
super(LoginWindow, self).__init__()
self.initUI()
def initUI(self):
self.url = QtGui.QLabel('RPC URL')
self.username = QtGui.QLabel('Username')
self.password = QtGui.QLabel('Password')
self.urlEdit = QtGui.QLineEdit()
self.usernameEdit = QtGui.QLineEdit()
self.passwordEdit = QtGui.QLineEdit()
self.passwordEdit.setEchoMode(QtGui.QLineEdit.Password)
submit = QtGui.QPushButton('OK')
grid = QtGui.QGridLayout()
grid.setSpacing(5)
grid.addWidget(self.url, 1, 0)
grid.addWidget(self.urlEdit, 1, 1)
grid.addWidget(self.username, 2, 0)
grid.addWidget(self.usernameEdit, 2, 1)
grid.addWidget(self.password, 3, 0)
grid.addWidget(self.passwordEdit, 3, 1)
#Add the submit button
grid.addWidget(submit, 4,1)
self.setLayout(grid)
submit.clicked.connect(self.submitLogin)
self.setGeometry(300, 300, 350, 300)
self.setWindowTitle('pyRtorrent')
self.show()
def submitLogin(self):
print("Pressed OK!")
print(self.urlEdit.text())
print(self.usernameEdit.text())
print(self.passwordEdit.text())
class MainWindow(QtGui.QWidget):
infoPanel = None
def __init__(self):
super(MainWindow, self).__init__()
print("Test")
self.initUI()
def initUI(self):
# Testing hardcoded values
rTorrentComm.setServerInfo("example", "example", "example", True)
rTorrentComm.startServer()
hBox = QtGui.QHBoxLayout()
#Set up the splitter to hold the window
splitter = QtGui.QSplitter(QtCore.Qt.Vertical)
#Set up the information panel
self.infoPanel = InfoPanelView(rTorrentComm.infoPanelModel, self)
self.infoPanel.setFrameShape(QtGui.QFrame.StyledPanel)
#Set up the table
table = QtGui.QTableView(self)
tableModel = rTorrentComm.torrentTable
#For Debug Purposes Only
#tableModel.layoutChanged.connect(self.dataChanged)
table.setModel(tableModel)
table.resizeColumnsToContents()
table.setSortingEnabled(True)
table.setSelectionBehavior(QtGui.QTableView.SelectRows)
table.setItemDelegate(ProgressBarTableViewDelegate())
table.selectionModel().currentRowChanged.connect(self.selectionChanged)
#Add items to the splitter
splitter.addWidget(table)
splitter.addWidget(self.infoPanel)
hBox.addWidget(splitter)
self.setLayout(hBox)
self.setGeometry(300,300,800,600)
self.setWindowTitle("Main")
self.show()
def dataChanged(self):
print("DATA CHANGED!! REFRESH!")
def selectionChanged(self, current, previous):
print("Row changed")
print("New Row: " + str(current.row()))
self.infoPanel.update(current.row())
class InfoPanelView(QtGui.QFrame):
infoPanelModel = None
grid = None
nameLabel = None
downloadedLabel = None
uploadedLabel = None
def __init__(self, infoPanel, parent=None):
super(InfoPanelView, self).__init__(parent)
self.grid = QtGui.QGridLayout()
self.infoPanelModel = infoPanel
# Add the labels
self.grid.addWidget(QtGui.QLabel('Name'), 0, 0)
self.grid.addWidget(QtGui.QLabel('Downloaded'), 1, 0)
self.grid.addWidget(QtGui.QLabel('Uploaded'), 1, 3)
# Add the empy labels for the variable data
# and store them localy
self.nameLabel = QtGui.QLabel('')
self.grid.addWidget(self.nameLabel, 0, 1, 1, 3)
self.downloadedLabel = QtGui.QLabel('')
self.grid.addWidget(self.downloadedLabel, 1, 1)
self.uploadedLabel = QtGui.QLabel('')
self.grid.addWidget(self.uploadedLabel, 1, 4)
# Set the variable data label
self._drawVariableGrids()
# Set the layout
self.setLayout(self.grid)
def update(self, newRow):
self.infoPanelModel.changeActiveRow(newRow)
self._drawVariableGrids()
'''
Set the text for the QLabel objects that represent the data
'''
def _drawVariableGrids(self):
name = self.infoPanelModel.getName()
self.nameLabel.setText(name)
downloaded = self.infoPanelModel.getDownloaded()
self.downloadedLabel.setText(downloaded)
uploaded = self.infoPanelModel.getUploaded()
self.uploadedLabel.setText(uploaded)
'''
The custom painter object for the table to render the progress bar
object correctly. The idea for this was taken from the qt website
examples.
'''
class ProgressBarTableViewDelegate(QtGui.QStyledItemDelegate):
def paint(self, painter, option, index):
self.initStyleOption(option, index)
if index.column() == 2:
progressBar = QtGui.QStyleOptionProgressBar()
progressBar.state = QtGui.QStyle.State_Enabled
progressBar.direction = QtGui.QApplication.layoutDirection()
progressBar.rect = option.rect
progressBar.fontMetrics = QtGui.QApplication.fontMetrics()
progressBar.minimum = 0
progressBar.maximum = 100
progressBar.textAlignment = QtCore.Qt.AlignCenter
progressBar.textVisible = True
progressBar.progress = index.data()
progressBar.text = "%3.1f%s" % (index.data(), "%")
QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_ProgressBar, progressBar, painter)
else:
super(ProgressBarTableViewDelegate, self).paint(painter, option, index)
class ExampleTableModel(QtCore.QAbstractTableModel):
def __init__(self):
super(ExampleTableModel, self).__init__()
def rowCount(self, parent):
return 4
def columnCount(self, parent):
return 4
def data(self, index, role):
return str(random.randint(0,100))
def login():
app = QtGui.QApplication(sys.argv)
login = LoginWindow()
app.exec_()
def main():
#login()
app = QtGui.QApplication(sys.argv)
app.aboutToQuit.connect(closeEvent)
main = MainWindow()
sys.exit(app.exec_())
def closeEvent():
print("Exiting Application, waiting on all threads to finish execution")
rTorrentComm.refreshTimer = -1
if __name__ == '__main__':
main()