-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgui.py
More file actions
149 lines (118 loc) · 4.54 KB
/
Copy pathgui.py
File metadata and controls
149 lines (118 loc) · 4.54 KB
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
import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import time
from main import start
from utils import Config
from tracker import end_gui
from shutil import copyfile
class Worker(QThread):
'''
Worker thread
Inherits from QRunnable to handler worker thread setup, signals and wrap-up.
:param callback: The function callback to run on this worker thread. Supplied args and
kwargs will be passed through to the runner.
:type callback: function
:param args: Arguments to pass to the callback function
:param kwargs: Keywords to pass to the callback function
'''
message_signal = pyqtSignal(str)
def __init__(self, fn, fileName, config):
super(Worker, self).__init__()
# Store constructor arguments (re-used for processing)
self.fn = fn
self.fileName = fileName
self.config = config
def run(self):
'''
Initialise the runner function with passed args, kwargs.
'''
self.fn(self.fileName, self.config, self.message_signal.emit)
print ("done here")
class App(QWidget):
def __init__(self):
super().__init__()
self.title = 'SlideCast'
self.config = Config()
self.left = 10
self.top = 10
self.width = 640
self.height = 480
self.threadpool = QThreadPool()
self.initUI()
self.recording = False
self.pdfChosen = False
def initUI(self):
name = QLabel('Name')
pdf = QLabel('PDF Location')
log = QLabel('Log')
self.pdfEdit = QLineEdit()
self.logEdit = QTextEdit()
pdfButton = QPushButton('Choose PDF', self)
pdfButton.setToolTip('Choose PDF for the Recording')
pdfButton.clicked.connect(self.choose_pdf)
self.recordButton = QPushButton('Begin Recording', self)
self.recordButton.setToolTip('Begin Recording')
self.recordButton.clicked.connect(self.record)
self.pdfEdit.setReadOnly(True)
self.logEdit.setReadOnly(True)
grid = QGridLayout()
grid.setSpacing(10)
grid.addWidget(pdf, 1, 0)
grid.addWidget(self.pdfEdit, 1, 1)
grid.addWidget(log, 2, 0)
grid.addWidget(self.logEdit, 2, 1, 1, 1)
grid.addWidget(pdfButton, 3, 0)
grid.addWidget(self.recordButton, 3, 1)
self.setLayout(grid)
self.setGeometry(300, 300, 350, 300)
self.setWindowTitle('SlideCast')
self.show()
@pyqtSlot()
def record(self):
if not self.recording:
if not self.pdfChosen:
QMessageBox.about(self, "PDF Not Chosen", "Choose a PDF first!")
else:
self.recording = True
self.recordButton.setText("Stop Recording")
self.worker = Worker(start, self.fileName, self.config)
self.worker.start()
self.worker.message_signal.connect(self.emit_message)
# self.threadpool.start(self.worker)
else:
self.logEdit.append("finished recording.. Please wait while the file is processed")
end_gui(self.config)
time.sleep(0.1)
self.worker.wait()
self.config = Config()
self.recording = False
self.recordButton.setText("Begin Recording")
self.outputFile = self.saveFileDialog("Save Recording")
if self.outputFile.split(".")[-1] != "sld":
self.outputFile += ".sld"
copyfile("output/recording.sld", self.outputFile)
self.logEdit.clear()
@pyqtSlot(str)
def emit_message(self, message):
self.logEdit.append(message)
@pyqtSlot()
def choose_pdf(self):
self.fileName = self.openFileNameDialog("Choose PDF for recording")
self.pdfEdit.setText(self.fileName)
self.pdfChosen = True
def openFileNameDialog(self, heading):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
fileName, _ = QFileDialog.getOpenFileName(self, heading, "","PDF Files (*.pdf)", options=options)
return fileName
def saveFileDialog(self, heading):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
fileName, _ = QFileDialog.getSaveFileName(self, heading,"","SlideCast Files(*.sld)", options=options)
return fileName
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())