-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchainsign.py
203 lines (158 loc) · 6.38 KB
/
chainsign.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
# -* encoding: utf-8 *-
import sys
import logging
import traceback
import json
from PySide2 import QtCore, QtWidgets
# This is needed for SVG assets to be loaded on Windows builds!
from PySide2 import QtSvg, QtXml # noqa
from gui import mainwindow, about
from utils import rpcurl_from_config, walk
from workers import VerifyThread, TimestampThread, PublishThread
from models import FileListModel
from updater import UpdateCheckerThread
logging.basicConfig(level=logging.DEBUG)
def qt_excepthook(type, value, tb):
sys.__excepthook__(type, value, tb)
msgbox = QtWidgets.QMessageBox()
msgbox.setInformativeText("Unexpected error occured")
msgbox.setText(str(value))
msgbox.setDetailedText('\n'.join(traceback.format_exception(type, value, tb)))
msgbox.setIcon(QtWidgets.QMessageBox.Critical)
msgbox.exec_()
sys.excepthook = qt_excepthook
class AboutDialog(QtWidgets.QDialog, about.Ui_AboutDialog):
def __init__(self, parent=None):
super(AboutDialog, self).__init__(parent)
self.setupUi(self)
th = UpdateCheckerThread(self)
th.response.connect(self.on_updater_response)
th.start()
def on_updater_response(self, resp):
data = json.loads(resp)
if data is None:
self.updaterLabel.setText("Non-public development release")
elif data.get('error'):
self.updaterLabel.setText(
'<i>An error occured during update check:</i><br />'
'%s' % data.get('error'))
elif data.get('binary_url'):
latest = data.get('latest')
self.updaterLabel.setText(
'New update available: <b>%s</b> <i>(%s)</i><br />'
'<a href="%s">Download update</a> • '
'<a href="%s">Release info</a>' % (
latest.get('tag_name'), latest.get('name'),
data.get('binary_url'), latest.get('html_url')))
else:
self.updaterLabel.setText("No update available")
class MainWindow(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
worker = None
def __init__(self, parent=None, app=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.app = app
self.list_model = FileListModel(self)
self.fileList.setModel(self.list_model)
self.fileList.resizeColumnsToContents()
delete_action = QtWidgets.QAction("Delete", self)
delete_action.triggered.connect(self.on_deleteAction)
self.fileList.addAction(delete_action)
if not rpcurl_from_config('namecoin'):
QtWidgets.QMessageBox.critical(
self,
'No namecoind found',
'Please install and configure Namecoin-Qt first.')
sys.exit(1)
def on_deleteAction(self, checked):
rows = sorted(
set(idx.row() for idx in self.fileList.selectedIndexes()),
reverse=True
)
for r in rows:
self.list_model.delete_row(r)
self.fileList.clearSelection()
@QtCore.Slot()
def on_addDirectoryButton_clicked(self):
directory = QtWidgets.QFileDialog.getExistingDirectory(self)
self.add_files(walk(directory))
@QtCore.Slot()
def on_addFilesButton_clicked(self):
files, choice = QtWidgets.QFileDialog.getOpenFileNames(self)
self.add_files(files)
def add_files(self, files_iter):
"""Adds files from iterator to current work queue"""
files_added = 0
for f in files_iter:
# TODO
self.list_model.add_file(f)
files_added += 1
self.fileList.resizeColumnsToContents()
self.statusBar().showMessage("%d files added." % (files_added,))
@property
def processing(self):
return self.worker and self.worker.isRunning()
def on_worker_finished(self, status):
self.statusBar().showMessage("Worker finished: %s" % (status,))
def on_worker_failed(self, fname, status):
self.list_model.set_status(fname, status)
self.fileList.resizeColumnsToContents()
self.statusBar().showMessage("Worker failed: %s: %s" % (fname, status,))
def on_timestamp_update(self, fname, reg_txid, nonce, digest):
self.list_model.set_registered(fname, reg_txid, nonce, digest)
self.fileList.resizeColumnsToContents()
def on_publish_update(self, fname, txid):
self.list_model.set_published(fname, txid)
self.fileList.resizeColumnsToContents()
def on_verify_update(self, fname, status):
self.list_model.set_status(fname, status)
self.fileList.resizeColumnsToContents()
# Button slots
#
@QtCore.Slot()
def on_verifyButton_clicked(self):
if self.processing:
self.statusBar().showMessage('Work in progress...')
return
self.worker = VerifyThread(self, self.list_model)
self.worker.verifyUpdate.connect(self.on_verify_update)
self.worker.workFailed.connect(self.on_worker_failed)
self.worker.workFinished.connect(self.on_worker_finished)
self.worker.start()
@QtCore.Slot()
def on_timestampButton_clicked(self):
if self.processing:
self.statusBar().showMessage('Work in progress...')
return
self.worker = TimestampThread(self, self.list_model)
self.worker.timestampUpdate.connect(self.on_timestamp_update)
self.worker.workFailed.connect(self.on_worker_failed)
self.worker.workFinished.connect(self.on_worker_finished)
self.worker.start()
@QtCore.Slot()
def on_publishButton_clicked(self):
if self.processing:
self.statusBar().showMessage('Work in progress...')
return
self.worker = PublishThread(self, self.list_model)
self.worker.publishUpdate.connect(self.on_publish_update)
self.worker.workFailed.connect(self.on_worker_failed)
self.worker.workFinished.connect(self.on_worker_finished)
self.worker.start()
#
# Main menu slots
#
@QtCore.Slot()
def on_actionQuit_triggered(self):
"""This handles activation of "Exit" menu action"""
self.app.exit()
@QtCore.Slot()
def on_actionAbout_triggered(self):
AboutDialog(self).exec_()
def main():
app = QtWidgets.QApplication(sys.argv)
window = MainWindow(app=app)
window.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()