-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdocxToPDFWGUI.py
75 lines (54 loc) · 1.61 KB
/
docxToPDFWGUI.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
import sys, os
from PyQt5.QtWidgets import QApplication, QMainWindow, QListWidget, QListWidgetItem, QPushButton
from PyQt5.QtCore import Qt, QUrl
from docx2pdf import convert
def ConvertDocxToPDF(links):
for i in links:
s1 = str(i).replace("/", "\\\\")
s2 = s1.replace("docx", "pdf")
convert(s1, s2)
class ListboxWidget(QListWidget):
def __init__(self, parent = None):
super().__init__(parent)
self.setAcceptDrops(True)
self.resize(600, 600)
def dragEnterEvent(self, event):
if event.mimeData().hasUrls:
event.accept()
else:
event.ignore()
def dragMoveEvent(self, event):
if event.mimeData().hasUrls():
event.setDropAction(Qt.CopyAction)
event.accept()
else:
event.ignore()
def dropEvent(self, event):
if event.mimeData().hasUrls():
event.setDropAction(Qt.CopyAction)
event.accept()
links = []
for url in event.mimeData().urls():
if url.isLocalFile():
links.append(str(url.toLocalFile()))
else:
links.append(str(url.toString()))
self.addItems(links)
ConvertDocxToPDF(links)
else:
event.ignore()
class AppDemo(QMainWindow):
def __init__(self):
super().__init__()
self.resize(1200, 600)
self.lstbox_view = ListboxWidget(self)
self.btn = QPushButton('Get Value', self)
self.btn.setGeometry(850, 400, 200, 50)
self.btn.clicked.connect(lambda :print(self.getSelectedItem()))
def getSelectedItem(self):
item = QListWidgetItem(self.lstbox_view.currentItem())
return item.text()
app = QApplication(sys.argv)
demo = AppDemo()
demo.show()
sys.exit(app.exec_())