forked from al1b/Calibre-KiPEO
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
57 lines (48 loc) · 2.17 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
# The base class that all tools must inherit from
from calibre.gui2.tweak_book.plugin import Tool
from calibre.gui2 import error_dialog
from qt.core import QAction, QMessageBox
from calibre_plugins.kipeo import reshaper
class KiPEOTool(Tool):
name = 'KiPEOTool'
allowed_in_toolbar = True
allowed_in_menu = True
def create_action(self, for_toolbar=True):
ac = QAction(get_icons('images/icon.png'), 'Reshape book by KiPEO', self.gui)
if not for_toolbar:
self.register_shortcut(ac, 'kipeo-tool', default_keys=('Ctrl+Shift+Alt+D',))
ac.triggered.connect(self.start_reshape)
return ac
def start_reshape(self):
# Ensure any in progress editing the user is doing is present in the container
self.boss.commit_all_editors_to_container()
try:
self.reshape()
except Exception:
# Something bad happened report the error to the user
import traceback
error_dialog(self.gui, _('Failed to reshape fonts'), _(
'Failed to reshape fonts, click "Show details" for more info'),
det_msg=traceback.format_exc(), show=True)
# Revert to the saved restore point
self.boss.revert_requested(self.boss.global_undo.previous_container)
def reshape(self):
self.boss.add_savepoint('Before: Reshape')
container = self.current_container
reshaper.reshape_book(container)
self.show_success()
def show_success(self):
message = QMessageBox(self.gui)
message.setIcon(QMessageBox.Information)
message.setText("KiPEO has completely reshaped your e-book.\r\n\r\nDo you like to see the changes?")
message.setWindowTitle("KiPEO")
message.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
message.show()
user_choice = message.exec_()
if user_choice == QMessageBox.Yes:
#Show the user what changes we have made, allowing her to
#revert them if necessary
self.boss.show_current_diff()
#Update the editor UI to take into account all the changes we
#have made
self.boss.apply_container_update_to_gui()