-
Notifications
You must be signed in to change notification settings - Fork 7
/
GUIVersion.py
141 lines (116 loc) · 5.7 KB
/
GUIVersion.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
import sys
import re
import os
import threading
from PyQt4 import QtCore, QtGui
import ui_mainWindow
import ui_helpWidget
import ui_aboutWidget
import lknovel
class HelpWidget(QtGui.QDialog, ui_helpWidget.Ui_Dialog):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
self.setFixedSize(380, 200)
self.pushButton.clicked.connect(lambda: self.close())
class AboutWidget(QtGui.QDialog, ui_aboutWidget.Ui_Dialog):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
self.setFixedSize(320, 120)
self.pushButton.clicked.connect(lambda: self.close())
class MainWindow(QtGui.QMainWindow, ui_mainWindow.Ui_MainWindow):
sigWarningMessage = QtCore.pyqtSignal(str, str)
sigInformationMessage = QtCore.pyqtSignal(str, str)
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.setupUi(self)
self.setFixedSize(520, 250)
self.installEventFilter(self)
self.setWindowTitle('lknovel-轻之国度在线轻小说转epub')
self.helpAction = QtGui.QAction('&Help', self)
self.helpAction.setStatusTip('使用说明')
self.aboutAction = QtGui.QAction('&About', self)
self.aboutAction.setStatusTip('关于')
self.menubar.addAction(self.helpAction)
self.menubar.addAction(self.aboutAction)
self.setting = QtCore.QSettings('kk', 'lknovel')
if self.setting.value('savePath'):
self.savePath = self.setting.value('savePath')
else:
self.savePath = os.path.join(os.path.expanduser('~'), 'Desktop')
self.directoryLineEdit.setText(self.savePath)
self.coverPath = ''
self.startButton.clicked.connect(self.createEpub)
self.sigInformationMessage.connect(self.showInformationMessage)
self.sigWarningMessage.connect(self.showWarningMessage)
self.directoryButton.clicked.connect(self.selectSaveDirectory)
self.coverButton.clicked.connect(self.selectCover)
lknovel.SENDER.sigChangeStatus.connect(self.changeStatus)
lknovel.SENDER.sigWarningMessage.connect(self.showWarningMessage)
lknovel.SENDER.sigInformationMessage.connect(self.showInformationMessage)
lknovel.SENDER.sigButton.connect(lambda: self.startButton.setEnabled(True))
self.helpAction.triggered.connect(self.openHelpWidget)
self.aboutAction.triggered.connect(self.openAboutWidget)
def createEpub(self):
urls = self.urlTextEdit.toPlainText().strip()
totalCheck = re.compile(
r'^(((http://lknovel.lightnovel.cn/main/vollist/(\d+).html)|(http://lknovel.lightnovel.cn/main/book/(\d+).html))\s*)+$')
ok = 1
for url in urls.split('\n'):
if not totalCheck.search(url.strip()):
ok = 0
break
if ok:
self.setting.setValue('savePath', self.savePath)
t = threading.Thread(target=lknovel.start,
args=(','.join(urls.split('\n')), self.savePath, self.coverPath))
t.start()
self.startButton.setEnabled(False)
else:
self.sigWarningMessage.emit('网址错误',
'请输入正确的网址,例如:\nhttp://lknovel.lightnovel.cn/main/vollist/726.html\nhttp://lknovel.lightnovel.cn/main/book/2664.html')
def selectSaveDirectory(self):
tempPath = str(QtGui.QFileDialog.getExistingDirectory(self, "选择文件夹", self.savePath))
if tempPath:
self.savePath = tempPath
self.directoryLineEdit.setText(self.savePath)
def selectCover(self):
tempPath = str(
QtGui.QFileDialog.getOpenFileNameAndFilter(self, "选择文件", os.path.join(os.path.expanduser('~'), 'Desktop'),
self.tr('图片文件(*.png *.jpg)'))[0])
if tempPath:
self.coverPath = tempPath
self.coverLineEdit.setText(self.coverPath)
def workDone(self):
self.changeStatus('')
self.sigInformationMessage.emit('完成', 'EPUB已生成')
self.startButton.setEnabled(True)
def openHelpWidget(self):
self.helpWidget = HelpWidget()
self.helpWidget.show()
def openAboutWidget(self):
self.aboutWidget = AboutWidget()
self.aboutWidget.show()
def changeStatus(self, text):
self.statusbar.showMessage(text)
#窗口激活时检测剪贴板 符合url规则自动填充至urlLineEdit
def eventFilter(self, object, event):
if event.type() == QtCore.QEvent.WindowActivate:
clipboardText = QtGui.QApplication.clipboard().text()
totalCheck = re.compile(
r'^(((http://lknovel.lightnovel.cn/main/vollist/(\d+).html)|(http://lknovel.lightnovel.cn/main/book/(\d+).html))\s*)+$')
if totalCheck.search(clipboardText):
self.urlTextEdit.setText(clipboardText)
return False
def showWarningMessage(self, title, content):
QtGui.QMessageBox.warning(self, title, content, buttons=QtGui.QMessageBox.Ok,
defaultButton=QtGui.QMessageBox.NoButton)
def showInformationMessage(self, title, content):
QtGui.QMessageBox.information(self, title, content, buttons=QtGui.QMessageBox.Ok,
defaultButton=QtGui.QMessageBox.NoButton)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
lkMainWidndow = MainWindow()
lkMainWidndow.show()
app.exec_()