forked from codyswang/notetaking-noah
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
96 lines (81 loc) · 3.28 KB
/
main.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
from stitcher import Stitcher
from quilt2PDF import PDFifier
import sys
import os
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog
from PyQt5 import QtCore, QtGui, QtWidgets, uic
qtcreator_file = "mainwindow.ui" # Enter file here.
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtcreator_file)
class MyWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
self.startButton.clicked.connect(self.openFileNameDialog)
self.nextButton.clicked.connect(self.nextSlide)
self.previousButton.clicked.connect(self.prevSlide)
self.pdfButton.clicked.connect(self.genPDF)
self.quilt = None
self.image_num = 0
def startNoah(self, path):
#data is a string with the text
self.stitcher = Stitcher(path)
self.stitcher.stitch()
self.pdfifier = PDFifier()
self.quilt = self.stitcher.get_quilt()
self.image_num = 0
image_map = QPixmap(self.quilt[0].slide_path)
data = self.fix_text(self.quilt[0].script)
self.slideImage.setPixmap(image_map)
self.textArea.setText('\n'.join(data))
self.repaint()
def nextSlide(self):
if(self.quilt != None):
if(self.image_num < len(self.quilt) - 1):
self.image_num += 1
image_map = QPixmap(self.quilt[self.image_num].slide_path)
self.slideImage.setPixmap(image_map)
data = self.fix_text(self.quilt[self.image_num].script)
self.textArea.setText('\n'.join(data))
self.repaint()
def prevSlide(self):
if(self.quilt != None):
if(self.image_num > 0):
self.image_num -= 1
image_map = QPixmap(self.quilt[self.image_num].slide_path)
self.slideImage.setPixmap(image_map)
data = self.fix_text(self.quilt[self.image_num].script)
self.textArea.setText('\n'.join(data))
self.repaint()
def fix_text(self, script):
first = True
fixed = list()
for segment in script:
new_text = ""
for text in segment:
for word in text:
if(first):
first = False
new_text += word
else:
new_text += (" " + word)
fixed.append(new_text)
return fixed
def openFileNameDialog(self):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
path, _ = QFileDialog.getOpenFileName(self,"QFileDialog.getOpenFileName()", "","All Files (*);;Python Files (*.py)", options=options)
path = os.path.basename(path)
if path:
self.startNoah(path)
def genPDF(self):
print("Generating a pdf...")
if(self.quilt != None):
self.pdfifier.makePDF(self.quilt)
print("Done!")
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = MyWindow()
window.show()
sys.exit(app.exec_())