From 2523138eb917aba960be70e30872c3ebdec4cd4e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 6 Dec 2013 13:55:32 +0530 Subject: [PATCH] Remove the need to special case standalone launches in the editor code --- src/calibre/gui2/tweak_book/editor/image.py | 8 ++----- src/calibre/gui2/tweak_book/editor/widget.py | 24 +++++++++----------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/calibre/gui2/tweak_book/editor/image.py b/src/calibre/gui2/tweak_book/editor/image.py index 3bd1efe616..af247b4317 100644 --- a/src/calibre/gui2/tweak_book/editor/image.py +++ b/src/calibre/gui2/tweak_book/editor/image.py @@ -226,12 +226,8 @@ class Editor(QMainWindow): b.addAction(getattr(self.canvas, '%s_action' % x)) self.edit_bar = b = self.addToolBar(_('Edit actions tool bar')) for x in ('copy', 'paste'): - try: - ac = actions['editor-%s' % x] - except KeyError: - setattr(self, 'action_' + x, b.addAction(x, getattr(self.canvas, x))) - else: - setattr(self, 'action_' + x, b.addAction(ac.icon(), x, getattr(self, x))) + ac = actions['editor-%s' % x] + setattr(self, 'action_' + x, b.addAction(ac.icon(), x, getattr(self, x))) self.update_clipboard_actions() b.addSeparator() diff --git a/src/calibre/gui2/tweak_book/editor/widget.py b/src/calibre/gui2/tweak_book/editor/widget.py index fd319bb025..a311905a0d 100644 --- a/src/calibre/gui2/tweak_book/editor/widget.py +++ b/src/calibre/gui2/tweak_book/editor/widget.py @@ -126,22 +126,15 @@ class Editor(QMainWindow): self.action_bar = b = self.addToolBar(_('File actions tool bar')) b.setObjectName('action_bar') # Needed for saveState for x in ('undo', 'redo'): - try: - b.addAction(actions['editor-%s' % x]) - except KeyError: - pass + b.addAction(actions['editor-%s' % x]) self.edit_bar = b = self.addToolBar(_('Edit actions tool bar')) for x in ('cut', 'copy', 'paste'): - try: - b.addAction(actions['editor-%s' % x]) - except KeyError: - pass + b.addAction(actions['editor-%s' % x]) self.tools_bar = b = self.addToolBar(_('Editor tools')) - if actions: - if self.syntax == 'html': - b.addAction(actions['fix-html-current']) - if self.syntax in {'xml', 'html', 'css'}: - b.addAction(actions['pretty-current']) + if self.syntax == 'html': + b.addAction(actions['fix-html-current']) + if self.syntax in {'xml', 'html', 'css'}: + b.addAction(actions['pretty-current']) def break_cycles(self): self.modification_state_changed.disconnect() @@ -211,7 +204,12 @@ class Editor(QMainWindow): return False def launch_editor(path_to_edit, path_is_raw=False, syntax='html'): + from calibre.gui2.tweak_book.main import option_parser + from calibre.gui2.tweak_book.ui import Main + opts = option_parser().parse_args([]) app = QApplication([]) + # Create the actions that are placed into the editors toolbars + main = Main(opts) # noqa if path_is_raw: raw = path_to_edit else: