Skip to content

Commit f62f08d

Browse files
committed
reorganize imports of QtGui and more
1 parent 70d1020 commit f62f08d

File tree

1 file changed

+96
-85
lines changed

1 file changed

+96
-85
lines changed

kindlecomicconverter/KCC_gui.py

+96-85
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@
1616
# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
1717
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1818
# PERFORMANCE OF THIS SOFTWARE.
19+
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
20+
QMetaObject, QObject, QPoint, QRect,
21+
QSize, QTime, QUrl, Qt, Signal, QIODeviceBase, QEvent, QThread, QSettings)
22+
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
23+
QFont, QFontDatabase, QGradient, QIcon,
24+
QImage, QKeySequence, QLinearGradient, QPainter,
25+
QPalette, QPixmap, QRadialGradient, QTransform, QDesktopServices)
26+
from PySide6.QtWidgets import (QAbstractItemView, QApplication, QCheckBox, QComboBox,
27+
QGridLayout, QHBoxLayout, QLabel, QLineEdit,
28+
QListWidget, QListWidgetItem, QMainWindow, QProgressBar,
29+
QPushButton, QSizePolicy, QSlider, QSpinBox,
30+
QStatusBar, QWidget, QApplication, QSystemTrayIcon, QFileDialog, QMessageBox, QDialog)
31+
from PySide6.QtNetwork import (QLocalSocket, QLocalServer)
32+
1933
import os
2034
import re
2135
import sys
@@ -25,9 +39,6 @@
2539
from subprocess import STDOUT, PIPE
2640

2741
import requests
28-
# noinspection PyUnresolvedReferences
29-
from PySide6 import QtGui, QtCore, QtWidgets, QtNetwork
30-
from PySide6.QtCore import Qt
3142
from xml.sax.saxutils import escape
3243
from psutil import Process
3344
from copy import copy
@@ -44,18 +55,18 @@
4455
from . import KCC_ui_editor
4556

4657

47-
class QApplicationMessaging(QtWidgets.QApplication):
48-
messageFromOtherInstance = QtCore.Signal(bytes)
58+
class QApplicationMessaging(QApplication):
59+
messageFromOtherInstance = Signal(bytes)
4960

5061
def __init__(self, argv):
51-
QtWidgets.QApplication.__init__(self, argv)
62+
QApplication.__init__(self, argv)
5263
self._key = 'KCC'
5364
self._timeout = 1000
5465
self._locked = False
55-
socket = QtNetwork.QLocalSocket(self)
56-
socket.connectToServer(self._key, QtCore.QIODeviceBase.OpenModeFlag.WriteOnly)
66+
socket = QLocalSocket(self)
67+
socket.connectToServer(self._key, QIODeviceBase.OpenModeFlag.WriteOnly)
5768
if not socket.waitForConnected(self._timeout):
58-
self._server = QtNetwork.QLocalServer(self)
69+
self._server = QLocalServer(self)
5970
self._server.newConnection.connect(self.handleMessage)
6071
self._server.listen(self._key)
6172
else:
@@ -67,11 +78,11 @@ def __del__(self):
6778
self._server.close()
6879

6980
def event(self, e):
70-
if e.type() == QtCore.QEvent.Type.FileOpen:
81+
if e.type() == QEvent.Type.FileOpen:
7182
self.messageFromOtherInstance.emit(bytes(e.file(), 'UTF-8'))
7283
return True
7384
else:
74-
return QtWidgets.QApplication.event(self, e)
85+
return QApplication.event(self, e)
7586

7687
def isRunning(self):
7788
return self._locked
@@ -82,56 +93,56 @@ def handleMessage(self):
8293
self.messageFromOtherInstance.emit(socket.readAll().data())
8394

8495
def sendMessage(self, message):
85-
socket = QtNetwork.QLocalSocket(self)
86-
socket.connectToServer(self._key, QtCore.QIODeviceBase.OpenModeFlag.WriteOnly)
96+
socket = QLocalSocket(self)
97+
socket.connectToServer(self._key, QIODeviceBase.OpenModeFlag.WriteOnly)
8798
socket.waitForConnected(self._timeout)
8899
socket.write(bytes(message, 'UTF-8'))
89100
socket.waitForBytesWritten(self._timeout)
90101
socket.disconnectFromServer()
91102

92103

93-
class QMainWindowKCC(QtWidgets.QMainWindow):
94-
progressBarTick = QtCore.Signal(str)
95-
modeConvert = QtCore.Signal(int)
96-
addMessage = QtCore.Signal(str, str, bool)
97-
addTrayMessage = QtCore.Signal(str, str)
98-
showDialog = QtCore.Signal(str, str)
99-
hideProgressBar = QtCore.Signal()
100-
forceShutdown = QtCore.Signal()
104+
class QMainWindowKCC(QMainWindow):
105+
progressBarTick = Signal(str)
106+
modeConvert = Signal(int)
107+
addMessage = Signal(str, str, bool)
108+
addTrayMessage = Signal(str, str)
109+
showDialog = Signal(str, str)
110+
hideProgressBar = Signal()
111+
forceShutdown = Signal()
101112

102113

103114
class Icons:
104115
def __init__(self):
105-
self.deviceKindle = QtGui.QIcon()
106-
self.deviceKindle.addPixmap(QtGui.QPixmap(":/Devices/icons/Kindle.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
107-
self.deviceKobo = QtGui.QIcon()
108-
self.deviceKobo.addPixmap(QtGui.QPixmap(":/Devices/icons/Kobo.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
109-
self.deviceRmk = QtGui.QIcon()
110-
self.deviceRmk.addPixmap(QtGui.QPixmap(":/Devices/icons/Rmk.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
111-
self.deviceOther = QtGui.QIcon()
112-
self.deviceOther.addPixmap(QtGui.QPixmap(":/Devices/icons/Other.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
113-
114-
self.MOBIFormat = QtGui.QIcon()
115-
self.MOBIFormat.addPixmap(QtGui.QPixmap(":/Formats/icons/MOBI.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
116-
self.CBZFormat = QtGui.QIcon()
117-
self.CBZFormat.addPixmap(QtGui.QPixmap(":/Formats/icons/CBZ.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
118-
self.EPUBFormat = QtGui.QIcon()
119-
self.EPUBFormat.addPixmap(QtGui.QPixmap(":/Formats/icons/EPUB.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
120-
121-
self.info = QtGui.QIcon()
122-
self.info.addPixmap(QtGui.QPixmap(":/Status/icons/info.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
123-
self.warning = QtGui.QIcon()
124-
self.warning.addPixmap(QtGui.QPixmap(":/Status/icons/warning.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
125-
self.error = QtGui.QIcon()
126-
self.error.addPixmap(QtGui.QPixmap(":/Status/icons/error.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
127-
128-
self.programIcon = QtGui.QIcon()
129-
self.programIcon.addPixmap(QtGui.QPixmap(":/Icon/icons/comic2ebook.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
130-
131-
132-
class VersionThread(QtCore.QThread):
116+
self.deviceKindle = QIcon()
117+
self.deviceKindle.addPixmap(QPixmap(":/Devices/icons/Kindle.png"), QIcon.Mode.Normal, QIcon.State.Off)
118+
self.deviceKobo = QIcon()
119+
self.deviceKobo.addPixmap(QPixmap(":/Devices/icons/Kobo.png"), QIcon.Mode.Normal, QIcon.State.Off)
120+
self.deviceRmk = QIcon()
121+
self.deviceRmk.addPixmap(QPixmap(":/Devices/icons/Rmk.png"), QIcon.Mode.Normal, QIcon.State.Off)
122+
self.deviceOther = QIcon()
123+
self.deviceOther.addPixmap(QPixmap(":/Devices/icons/Other.png"), QIcon.Mode.Normal, QIcon.State.Off)
124+
125+
self.MOBIFormat = QIcon()
126+
self.MOBIFormat.addPixmap(QPixmap(":/Formats/icons/MOBI.png"), QIcon.Mode.Normal, QIcon.State.Off)
127+
self.CBZFormat = QIcon()
128+
self.CBZFormat.addPixmap(QPixmap(":/Formats/icons/CBZ.png"), QIcon.Mode.Normal, QIcon.State.Off)
129+
self.EPUBFormat = QIcon()
130+
self.EPUBFormat.addPixmap(QPixmap(":/Formats/icons/EPUB.png"), QIcon.Mode.Normal, QIcon.State.Off)
131+
132+
self.info = QIcon()
133+
self.info.addPixmap(QPixmap(":/Status/icons/info.png"), QIcon.Mode.Normal, QIcon.State.Off)
134+
self.warning = QIcon()
135+
self.warning.addPixmap(QPixmap(":/Status/icons/warning.png"), QIcon.Mode.Normal, QIcon.State.Off)
136+
self.error = QIcon()
137+
self.error.addPixmap(QPixmap(":/Status/icons/error.png"), QIcon.Mode.Normal, QIcon.State.Off)
138+
139+
self.programIcon = QIcon()
140+
self.programIcon.addPixmap(QPixmap(":/Icon/icons/comic2ebook.png"), QIcon.Mode.Normal, QIcon.State.Off)
141+
142+
143+
class VersionThread(QThread):
133144
def __init__(self):
134-
QtCore.QThread.__init__(self)
145+
QThread.__init__(self)
135146
self.newVersion = ''
136147
self.md5 = ''
137148
self.barProgress = 0
@@ -160,9 +171,9 @@ def setAnswer(self, dialoganswer):
160171
self.answer = dialoganswer
161172

162173

163-
class ProgressThread(QtCore.QThread):
174+
class ProgressThread(QThread):
164175
def __init__(self):
165-
QtCore.QThread.__init__(self)
176+
QThread.__init__(self)
166177
self.running = False
167178
self.content = None
168179
self.progress = 0
@@ -184,9 +195,9 @@ def stop(self):
184195
self.running = False
185196

186197

187-
class WorkerThread(QtCore.QThread):
198+
class WorkerThread(QThread):
188199
def __init__(self):
189-
QtCore.QThread.__init__(self)
200+
QThread.__init__(self)
190201
self.conversionAlive = False
191202
self.errors = False
192203
self.kindlegenErrorCode = [0]
@@ -435,7 +446,7 @@ def run(self):
435446
MW.modeConvert.emit(1)
436447

437448

438-
class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
449+
class SystemTrayIcon(QSystemTrayIcon):
439450
def __init__(self):
440451
super().__init__()
441452
if self.isSystemTrayAvailable():
@@ -448,7 +459,7 @@ def catchClicks(self):
448459
MW.activateWindow()
449460

450461
def addTrayMessage(self, message, icon):
451-
icon = getattr(QtWidgets.QSystemTrayIcon.MessageIcon, icon)
462+
icon = getattr(QSystemTrayIcon.MessageIcon, icon)
452463
if self.supportsMessages() and not MW.isActiveWindow():
453464
self.showMessage('Kindle Comic Converter', message, icon)
454465

@@ -458,7 +469,7 @@ def selectDir(self):
458469
if self.needClean:
459470
self.needClean = False
460471
GUI.jobList.clear()
461-
dname = QtWidgets.QFileDialog.getExistingDirectory(MW, 'Select directory', self.lastPath)
472+
dname = QFileDialog.getExistingDirectory(MW, 'Select directory', self.lastPath)
462473
if dname != '':
463474
if sys.platform.startswith('win'):
464475
dname = dname.replace('/', '\\')
@@ -471,10 +482,10 @@ def selectFile(self):
471482
self.needClean = False
472483
GUI.jobList.clear()
473484
if self.tar or self.sevenzip:
474-
fnames = QtWidgets.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath,
485+
fnames = QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath,
475486
'Comic (*.cbz *.cbr *.cb7 *.zip *.rar *.7z *.pdf);;All (*.*)')
476487
else:
477-
fnames = QtWidgets.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath,
488+
fnames = QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath,
478489
'Comic (*.pdf);;All (*.*)')
479490
for fname in fnames[0]:
480491
if fname != '':
@@ -486,16 +497,16 @@ def selectFile(self):
486497

487498
def selectFileMetaEditor(self):
488499
sname = ''
489-
if QtWidgets.QApplication.keyboardModifiers() == QtCore.Qt.ShiftModifier:
490-
dname = QtWidgets.QFileDialog.getExistingDirectory(MW, 'Select directory', self.lastPath)
500+
if QApplication.keyboardModifiers() == Qt.ShiftModifier:
501+
dname = QFileDialog.getExistingDirectory(MW, 'Select directory', self.lastPath)
491502
if dname != '':
492503
sname = os.path.join(dname, 'ComicInfo.xml')
493504
if sys.platform.startswith('win'):
494505
sname = sname.replace('/', '\\')
495506
self.lastPath = os.path.abspath(sname)
496507
else:
497508
if self.sevenzip:
498-
fname = QtWidgets.QFileDialog.getOpenFileName(MW, 'Select file', self.lastPath,
509+
fname = QFileDialog.getOpenFileName(MW, 'Select file', self.lastPath,
499510
'Comic (*.cbz *.cbr *.cb7)')
500511
else:
501512
fname = ['']
@@ -524,7 +535,7 @@ def clearJobs(self):
524535

525536
def openWiki(self):
526537
# noinspection PyCallByClass
527-
QtGui.QDesktopServices.openUrl(QtCore.QUrl('https://github.com/ciromattia/kcc/wiki'))
538+
QDesktopServices.openUrl(QUrl('https://github.com/ciromattia/kcc/wiki'))
528539

529540
def modeChange(self, mode):
530541
if mode == 1:
@@ -559,16 +570,16 @@ def modeConvert(self, enable):
559570
if enable == 1:
560571
self.conversionAlive = False
561572
self.worker.sync()
562-
icon = QtGui.QIcon()
563-
icon.addPixmap(QtGui.QPixmap(":/Other/icons/convert.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
573+
icon = QIcon()
574+
icon.addPixmap(QPixmap(":/Other/icons/convert.png"), QIcon.Mode.Normal, QIcon.State.Off)
564575
GUI.convertButton.setIcon(icon)
565576
GUI.convertButton.setText('Convert')
566577
GUI.centralWidget.setAcceptDrops(True)
567578
elif enable == 0:
568579
self.conversionAlive = True
569580
self.worker.sync()
570-
icon = QtGui.QIcon()
571-
icon.addPixmap(QtGui.QPixmap(":/Other/icons/clear.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
581+
icon = QIcon()
582+
icon.addPixmap(QPixmap(":/Other/icons/clear.png"), QIcon.Mode.Normal, QIcon.State.Off)
572583
GUI.convertButton.setIcon(icon)
573584
GUI.convertButton.setText('Abort')
574585
GUI.centralWidget.setAcceptDrops(False)
@@ -684,27 +695,27 @@ def stripTags(self, html):
684695
def addMessage(self, message, icon, replace=False):
685696
if icon != '':
686697
icon = getattr(self.icons, icon)
687-
item = QtWidgets.QListWidgetItem(icon, ' ' + self.stripTags(message))
698+
item = QListWidgetItem(icon, ' ' + self.stripTags(message))
688699
else:
689-
item = QtWidgets.QListWidgetItem(' ' + self.stripTags(message))
700+
item = QListWidgetItem(' ' + self.stripTags(message))
690701
if replace:
691702
GUI.jobList.takeItem(GUI.jobList.count() - 1)
692703
# Due to lack of HTML support in QListWidgetItem we overlay text field with QLabel
693704
# We still fill original text field with transparent content to trigger creation of horizontal scrollbar
694-
item.setForeground(QtGui.QColor('transparent'))
695-
label = QtWidgets.QLabel(message)
705+
item.setForeground(QColor('transparent'))
706+
label = QLabel(message)
696707
label.setOpenExternalLinks(True)
697708
GUI.jobList.addItem(item)
698709
GUI.jobList.setItemWidget(item, label)
699710
GUI.jobList.scrollToBottom()
700711

701712
def showDialog(self, message, kind):
702713
if kind == 'error':
703-
QtWidgets.QMessageBox.critical(MW, 'KCC - Error', message, QtWidgets.QMessageBox.StandardButton.Ok)
714+
QMessageBox.critical(MW, 'KCC - Error', message, QMessageBox.StandardButton.Ok)
704715
elif kind == 'question':
705-
GUI.versionCheck.setAnswer(QtWidgets.QMessageBox.question(MW, 'KCC - Question', message,
706-
QtWidgets.QMessageBox.Yes,
707-
QtWidgets.QMessageBox.No))
716+
GUI.versionCheck.setAnswer(QMessageBox.question(MW, 'KCC - Question', message,
717+
QMessageBox.Yes,
718+
QMessageBox.No))
708719

709720
def updateProgressbar(self, command):
710721
if command == 'tick':
@@ -728,8 +739,8 @@ def convertStart(self):
728739
self.conversionAlive = False
729740
self.worker.sync()
730741
else:
731-
if QtWidgets.QApplication.keyboardModifiers() == QtCore.Qt.KeyboardModifier.ShiftModifier:
732-
dname = QtWidgets.QFileDialog.getExistingDirectory(MW, 'Select output directory', self.lastPath)
742+
if QApplication.keyboardModifiers() == Qt.KeyboardModifier.ShiftModifier:
743+
dname = QFileDialog.getExistingDirectory(MW, 'Select output directory', self.lastPath)
733744
if dname != '':
734745
if sys.platform.startswith('win'):
735746
dname = dname.replace('/', '\\')
@@ -874,7 +885,7 @@ def __init__(self, kccapp, kccwindow):
874885
self.setupUi(MW)
875886
self.editor = KCCGUI_MetaEditor()
876887
self.icons = Icons()
877-
self.settings = QtCore.QSettings('ciromattia', 'kcc')
888+
self.settings = QSettings('ciromattia', 'kcc')
878889
self.settingsVersion = self.settings.value('settingsVersion', '', type=str)
879890
self.lastPath = self.settings.value('lastPath', '', type=str)
880891
self.lastDevice = self.settings.value('lastDevice', 0, type=int)
@@ -907,7 +918,7 @@ def __init__(self, kccapp, kccwindow):
907918
elif sys.platform.startswith('darwin'):
908919
for element in ['editorButton', 'wikiButton', 'directoryButton', 'clearButton', 'fileButton', 'deviceBox',
909920
'convertButton', 'formatBox']:
910-
getattr(GUI, element).setMinimumSize(QtCore.QSize(0, 0))
921+
getattr(GUI, element).setMinimumSize(QSize(0, 0))
911922
GUI.gridLayout.setContentsMargins(-1, -1, -1, -1)
912923
for element in ['gridLayout_2', 'gridLayout_3', 'gridLayout_4', 'horizontalLayout', 'horizontalLayout_2']:
913924
getattr(GUI, element).setContentsMargins(-1, 0, -1, 0)
@@ -1050,11 +1061,11 @@ def __init__(self, kccapp, kccwindow):
10501061
"Kobo Mini/Touch",
10511062
]
10521063

1053-
statusBarLabel = QtWidgets.QLabel('<b><a href="https://kcc.iosphe.re/">HOMEPAGE</a> - <a href="https://github.'
1064+
statusBarLabel = QLabel('<b><a href="https://kcc.iosphe.re/">HOMEPAGE</a> - <a href="https://github.'
10541065
'com/ciromattia/kcc/blob/master/README.md#issues--new-features--donations">DO'
10551066
'NATE</a> - <a href="http://www.mobileread.com/forums/showthread.php?t=207461'
10561067
'">FORUM</a></b>')
1057-
statusBarLabel.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
1068+
statusBarLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
10581069
statusBarLabel.setOpenExternalLinks(True)
10591070
GUI.statusBar.addPermanentWidget(statusBarLabel, 1)
10601071

@@ -1218,15 +1229,15 @@ def cleanData(self, s):
12181229
return escape(s.strip())
12191230

12201231
def __init__(self):
1221-
self.ui = QtWidgets.QDialog()
1232+
self.ui = QDialog()
12221233
self.parser = None
12231234
self.setupUi(self.ui)
1224-
self.ui.setWindowFlags(self.ui.windowFlags() & ~QtCore.Qt.WindowType.WindowContextHelpButtonHint)
1235+
self.ui.setWindowFlags(self.ui.windowFlags() & ~Qt.WindowType.WindowContextHelpButtonHint)
12251236
self.okButton.clicked.connect(self.saveData)
12261237
self.cancelButton.clicked.connect(self.ui.close)
12271238
if sys.platform.startswith('linux'):
12281239
self.ui.resize(450, 260)
1229-
self.ui.setMinimumSize(QtCore.QSize(450, 260))
1240+
self.ui.setMinimumSize(QSize(450, 260))
12301241
elif sys.platform.startswith('darwin'):
12311242
self.ui.resize(450, 310)
1232-
self.ui.setMinimumSize(QtCore.QSize(450, 310))
1243+
self.ui.setMinimumSize(QSize(450, 310))

0 commit comments

Comments
 (0)