16
16
# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
17
17
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18
18
# 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
+
19
33
import os
20
34
import re
21
35
import sys
25
39
from subprocess import STDOUT , PIPE
26
40
27
41
import requests
28
- # noinspection PyUnresolvedReferences
29
- from PySide6 import QtGui , QtCore , QtWidgets , QtNetwork
30
- from PySide6 .QtCore import Qt
31
42
from xml .sax .saxutils import escape
32
43
from psutil import Process
33
44
from copy import copy
44
55
from . import KCC_ui_editor
45
56
46
57
47
- class QApplicationMessaging (QtWidgets . QApplication ):
48
- messageFromOtherInstance = QtCore . Signal (bytes )
58
+ class QApplicationMessaging (QApplication ):
59
+ messageFromOtherInstance = Signal (bytes )
49
60
50
61
def __init__ (self , argv ):
51
- QtWidgets . QApplication .__init__ (self , argv )
62
+ QApplication .__init__ (self , argv )
52
63
self ._key = 'KCC'
53
64
self ._timeout = 1000
54
65
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 )
57
68
if not socket .waitForConnected (self ._timeout ):
58
- self ._server = QtNetwork . QLocalServer (self )
69
+ self ._server = QLocalServer (self )
59
70
self ._server .newConnection .connect (self .handleMessage )
60
71
self ._server .listen (self ._key )
61
72
else :
@@ -67,11 +78,11 @@ def __del__(self):
67
78
self ._server .close ()
68
79
69
80
def event (self , e ):
70
- if e .type () == QtCore . QEvent .Type .FileOpen :
81
+ if e .type () == QEvent .Type .FileOpen :
71
82
self .messageFromOtherInstance .emit (bytes (e .file (), 'UTF-8' ))
72
83
return True
73
84
else :
74
- return QtWidgets . QApplication .event (self , e )
85
+ return QApplication .event (self , e )
75
86
76
87
def isRunning (self ):
77
88
return self ._locked
@@ -82,56 +93,56 @@ def handleMessage(self):
82
93
self .messageFromOtherInstance .emit (socket .readAll ().data ())
83
94
84
95
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 )
87
98
socket .waitForConnected (self ._timeout )
88
99
socket .write (bytes (message , 'UTF-8' ))
89
100
socket .waitForBytesWritten (self ._timeout )
90
101
socket .disconnectFromServer ()
91
102
92
103
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 ()
101
112
102
113
103
114
class Icons :
104
115
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 ):
133
144
def __init__ (self ):
134
- QtCore . QThread .__init__ (self )
145
+ QThread .__init__ (self )
135
146
self .newVersion = ''
136
147
self .md5 = ''
137
148
self .barProgress = 0
@@ -160,9 +171,9 @@ def setAnswer(self, dialoganswer):
160
171
self .answer = dialoganswer
161
172
162
173
163
- class ProgressThread (QtCore . QThread ):
174
+ class ProgressThread (QThread ):
164
175
def __init__ (self ):
165
- QtCore . QThread .__init__ (self )
176
+ QThread .__init__ (self )
166
177
self .running = False
167
178
self .content = None
168
179
self .progress = 0
@@ -184,9 +195,9 @@ def stop(self):
184
195
self .running = False
185
196
186
197
187
- class WorkerThread (QtCore . QThread ):
198
+ class WorkerThread (QThread ):
188
199
def __init__ (self ):
189
- QtCore . QThread .__init__ (self )
200
+ QThread .__init__ (self )
190
201
self .conversionAlive = False
191
202
self .errors = False
192
203
self .kindlegenErrorCode = [0 ]
@@ -435,7 +446,7 @@ def run(self):
435
446
MW .modeConvert .emit (1 )
436
447
437
448
438
- class SystemTrayIcon (QtWidgets . QSystemTrayIcon ):
449
+ class SystemTrayIcon (QSystemTrayIcon ):
439
450
def __init__ (self ):
440
451
super ().__init__ ()
441
452
if self .isSystemTrayAvailable ():
@@ -448,7 +459,7 @@ def catchClicks(self):
448
459
MW .activateWindow ()
449
460
450
461
def addTrayMessage (self , message , icon ):
451
- icon = getattr (QtWidgets . QSystemTrayIcon .MessageIcon , icon )
462
+ icon = getattr (QSystemTrayIcon .MessageIcon , icon )
452
463
if self .supportsMessages () and not MW .isActiveWindow ():
453
464
self .showMessage ('Kindle Comic Converter' , message , icon )
454
465
@@ -458,7 +469,7 @@ def selectDir(self):
458
469
if self .needClean :
459
470
self .needClean = False
460
471
GUI .jobList .clear ()
461
- dname = QtWidgets . QFileDialog .getExistingDirectory (MW , 'Select directory' , self .lastPath )
472
+ dname = QFileDialog .getExistingDirectory (MW , 'Select directory' , self .lastPath )
462
473
if dname != '' :
463
474
if sys .platform .startswith ('win' ):
464
475
dname = dname .replace ('/' , '\\ ' )
@@ -471,10 +482,10 @@ def selectFile(self):
471
482
self .needClean = False
472
483
GUI .jobList .clear ()
473
484
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 ,
475
486
'Comic (*.cbz *.cbr *.cb7 *.zip *.rar *.7z *.pdf);;All (*.*)' )
476
487
else :
477
- fnames = QtWidgets . QFileDialog .getOpenFileNames (MW , 'Select file' , self .lastPath ,
488
+ fnames = QFileDialog .getOpenFileNames (MW , 'Select file' , self .lastPath ,
478
489
'Comic (*.pdf);;All (*.*)' )
479
490
for fname in fnames [0 ]:
480
491
if fname != '' :
@@ -486,16 +497,16 @@ def selectFile(self):
486
497
487
498
def selectFileMetaEditor (self ):
488
499
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 )
491
502
if dname != '' :
492
503
sname = os .path .join (dname , 'ComicInfo.xml' )
493
504
if sys .platform .startswith ('win' ):
494
505
sname = sname .replace ('/' , '\\ ' )
495
506
self .lastPath = os .path .abspath (sname )
496
507
else :
497
508
if self .sevenzip :
498
- fname = QtWidgets . QFileDialog .getOpenFileName (MW , 'Select file' , self .lastPath ,
509
+ fname = QFileDialog .getOpenFileName (MW , 'Select file' , self .lastPath ,
499
510
'Comic (*.cbz *.cbr *.cb7)' )
500
511
else :
501
512
fname = ['' ]
@@ -524,7 +535,7 @@ def clearJobs(self):
524
535
525
536
def openWiki (self ):
526
537
# noinspection PyCallByClass
527
- QtGui . QDesktopServices .openUrl (QtCore . QUrl ('https://github.com/ciromattia/kcc/wiki' ))
538
+ QDesktopServices .openUrl (QUrl ('https://github.com/ciromattia/kcc/wiki' ))
528
539
529
540
def modeChange (self , mode ):
530
541
if mode == 1 :
@@ -559,16 +570,16 @@ def modeConvert(self, enable):
559
570
if enable == 1 :
560
571
self .conversionAlive = False
561
572
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 )
564
575
GUI .convertButton .setIcon (icon )
565
576
GUI .convertButton .setText ('Convert' )
566
577
GUI .centralWidget .setAcceptDrops (True )
567
578
elif enable == 0 :
568
579
self .conversionAlive = True
569
580
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 )
572
583
GUI .convertButton .setIcon (icon )
573
584
GUI .convertButton .setText ('Abort' )
574
585
GUI .centralWidget .setAcceptDrops (False )
@@ -684,27 +695,27 @@ def stripTags(self, html):
684
695
def addMessage (self , message , icon , replace = False ):
685
696
if icon != '' :
686
697
icon = getattr (self .icons , icon )
687
- item = QtWidgets . QListWidgetItem (icon , ' ' + self .stripTags (message ))
698
+ item = QListWidgetItem (icon , ' ' + self .stripTags (message ))
688
699
else :
689
- item = QtWidgets . QListWidgetItem (' ' + self .stripTags (message ))
700
+ item = QListWidgetItem (' ' + self .stripTags (message ))
690
701
if replace :
691
702
GUI .jobList .takeItem (GUI .jobList .count () - 1 )
692
703
# Due to lack of HTML support in QListWidgetItem we overlay text field with QLabel
693
704
# 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 )
696
707
label .setOpenExternalLinks (True )
697
708
GUI .jobList .addItem (item )
698
709
GUI .jobList .setItemWidget (item , label )
699
710
GUI .jobList .scrollToBottom ()
700
711
701
712
def showDialog (self , message , kind ):
702
713
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 )
704
715
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 ))
708
719
709
720
def updateProgressbar (self , command ):
710
721
if command == 'tick' :
@@ -728,8 +739,8 @@ def convertStart(self):
728
739
self .conversionAlive = False
729
740
self .worker .sync ()
730
741
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 )
733
744
if dname != '' :
734
745
if sys .platform .startswith ('win' ):
735
746
dname = dname .replace ('/' , '\\ ' )
@@ -874,7 +885,7 @@ def __init__(self, kccapp, kccwindow):
874
885
self .setupUi (MW )
875
886
self .editor = KCCGUI_MetaEditor ()
876
887
self .icons = Icons ()
877
- self .settings = QtCore . QSettings ('ciromattia' , 'kcc' )
888
+ self .settings = QSettings ('ciromattia' , 'kcc' )
878
889
self .settingsVersion = self .settings .value ('settingsVersion' , '' , type = str )
879
890
self .lastPath = self .settings .value ('lastPath' , '' , type = str )
880
891
self .lastDevice = self .settings .value ('lastDevice' , 0 , type = int )
@@ -907,7 +918,7 @@ def __init__(self, kccapp, kccwindow):
907
918
elif sys .platform .startswith ('darwin' ):
908
919
for element in ['editorButton' , 'wikiButton' , 'directoryButton' , 'clearButton' , 'fileButton' , 'deviceBox' ,
909
920
'convertButton' , 'formatBox' ]:
910
- getattr (GUI , element ).setMinimumSize (QtCore . QSize (0 , 0 ))
921
+ getattr (GUI , element ).setMinimumSize (QSize (0 , 0 ))
911
922
GUI .gridLayout .setContentsMargins (- 1 , - 1 , - 1 , - 1 )
912
923
for element in ['gridLayout_2' , 'gridLayout_3' , 'gridLayout_4' , 'horizontalLayout' , 'horizontalLayout_2' ]:
913
924
getattr (GUI , element ).setContentsMargins (- 1 , 0 , - 1 , 0 )
@@ -1050,11 +1061,11 @@ def __init__(self, kccapp, kccwindow):
1050
1061
"Kobo Mini/Touch" ,
1051
1062
]
1052
1063
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.'
1054
1065
'com/ciromattia/kcc/blob/master/README.md#issues--new-features--donations">DO'
1055
1066
'NATE</a> - <a href="http://www.mobileread.com/forums/showthread.php?t=207461'
1056
1067
'">FORUM</a></b>' )
1057
- statusBarLabel .setAlignment (QtCore . Qt .AlignmentFlag .AlignCenter )
1068
+ statusBarLabel .setAlignment (Qt .AlignmentFlag .AlignCenter )
1058
1069
statusBarLabel .setOpenExternalLinks (True )
1059
1070
GUI .statusBar .addPermanentWidget (statusBarLabel , 1 )
1060
1071
@@ -1218,15 +1229,15 @@ def cleanData(self, s):
1218
1229
return escape (s .strip ())
1219
1230
1220
1231
def __init__ (self ):
1221
- self .ui = QtWidgets . QDialog ()
1232
+ self .ui = QDialog ()
1222
1233
self .parser = None
1223
1234
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 )
1225
1236
self .okButton .clicked .connect (self .saveData )
1226
1237
self .cancelButton .clicked .connect (self .ui .close )
1227
1238
if sys .platform .startswith ('linux' ):
1228
1239
self .ui .resize (450 , 260 )
1229
- self .ui .setMinimumSize (QtCore . QSize (450 , 260 ))
1240
+ self .ui .setMinimumSize (QSize (450 , 260 ))
1230
1241
elif sys .platform .startswith ('darwin' ):
1231
1242
self .ui .resize (450 , 310 )
1232
- self .ui .setMinimumSize (QtCore . QSize (450 , 310 ))
1243
+ self .ui .setMinimumSize (QSize (450 , 310 ))
0 commit comments