From bad5db6d5766355528390b4832ba91d05e3f4ee1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 10 Aug 2009 15:48:18 -0600 Subject: [PATCH] IGN:Various miscellaneous fixes. --- src/calibre/gui2/__init__.py | 9 ++++++--- src/calibre/gui2/dialogs/config.py | 3 ++- src/calibre/gui2/main.py | 2 +- src/calibre/utils/ipc/launch.py | 12 ++++++++++++ src/calibre/utils/ipc/server.py | 13 ++++++++----- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 63d7e5407f..0fd4054763 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -9,7 +9,7 @@ from PyQt4.QtGui import QFileDialog, QMessageBox, QPixmap, QFileIconProvider, \ ORG_NAME = 'KovidsBrain' APP_UID = 'libprs500' -from calibre import islinux, iswindows +from calibre import islinux, iswindows, isosx from calibre.startup import get_lang from calibre.utils.config import Config, ConfigProxy, dynamic import calibre.resources as resources @@ -110,7 +110,7 @@ class CopyButton(QPushButton): def copied(self): self.emit(SIGNAL('copy()')) self.setDisabled(True) - self.setText(_('Copied to clipboard')) + self.setText(_('Copied')) def keyPressEvent(self, ev): @@ -139,7 +139,7 @@ class MessageBox(QMessageBox): self.det_msg = det_msg self.setDetailedText(det_msg) # Cannot set keyboard shortcut as the event is not easy to filter - self.cb = CopyButton(_('Copy to Clipboard')) + self.cb = CopyButton(_('Copy') if isosx else _('Copy to Clipboard')) self.connect(self.cb, SIGNAL('copy()'), self.copy_to_clipboard) self.addButton(self.cb, QMessageBox.ActionRole) default_button = self.button(self.Ok) @@ -158,6 +158,7 @@ class MessageBox(QMessageBox): def warning_dialog(parent, title, msg, det_msg='', show=False): d = MessageBox(QMessageBox.Warning, 'WARNING: '+title, msg, QMessageBox.Ok, parent, det_msg) + d.setEscapeButton(QMessageBox.Ok) d.setIconPixmap(QPixmap(':/images/dialog_warning.svg')) if show: return d.exec_() @@ -167,6 +168,7 @@ def error_dialog(parent, title, msg, det_msg='', show=False): d = MessageBox(QMessageBox.Critical, 'ERROR: '+title, msg, QMessageBox.Ok, parent, det_msg) d.setIconPixmap(QPixmap(':/images/dialog_error.svg')) + d.setEscapeButton(QMessageBox.Ok) if show: return d.exec_() return d @@ -175,6 +177,7 @@ def question_dialog(parent, title, msg, det_msg=''): d = MessageBox(QMessageBox.Question, title, msg, QMessageBox.Yes|QMessageBox.No, parent, det_msg) d.setIconPixmap(QPixmap(':/images/dialog_information.svg')) + d.setEscapeButton(QMessageBox.No) return d.exec_() == QMessageBox.Yes def info_dialog(parent, title, msg, det_msg='', show=False): diff --git a/src/calibre/gui2/dialogs/config.py b/src/calibre/gui2/dialogs/config.py index 7ffaf90b2e..04b5650188 100644 --- a/src/calibre/gui2/dialogs/config.py +++ b/src/calibre/gui2/dialogs/config.py @@ -166,7 +166,8 @@ class PluginModel(QAbstractItemModel): if index.internalId() == 0: if role == Qt.DisplayRole: category = self.categories[index.row()] - return QVariant(category + _(' plugins')) + return QVariant(_("%(plugin_type)s %(plugins)s")%\ + dict(plugin_type=category, plugins=_('plugins'))) else: plugin = self.index_to_plugin(index) if role == Qt.DisplayRole: diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index a6a2e90e18..8ca4c9a17d 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -1788,7 +1788,7 @@ def init_qt(args): parser = option_parser() opts, args = parser.parse_args(args) if opts.with_library is not None and os.path.isdir(opts.with_library): - prefs.set('library_path', opts.with_library) + prefs.set('library_path', os.path.abspath(opts.with_library)) print 'Using library at', prefs['library_path'] app = Application(args) actions = tuple(Main.create_application_menubar()) diff --git a/src/calibre/utils/ipc/launch.py b/src/calibre/utils/ipc/launch.py index 4aa8f684ad..7a03010dc4 100644 --- a/src/calibre/utils/ipc/launch.py +++ b/src/calibre/utils/ipc/launch.py @@ -14,6 +14,7 @@ from calibre.ptempfile import PersistentTemporaryFile if iswindows: import win32process + _windows_null_file = open(os.devnull, 'wb') class Worker(object): ''' @@ -149,9 +150,20 @@ class Worker(object): self._file = PersistentTemporaryFile('_worker_redirect.log') args['stdout'] = self._file._fd args['stderr'] = subprocess.STDOUT + if iswindows: + args['stdin'] = subprocess.PIPE ret = self._file.name + if iswindows and 'stdin' not in args: + # On windows when usingthepythonw interpreter, + # stdout, stderr and stdin may not be valid + args['stdin'] = subprocess.PIPE + args['stdout'] = _windows_null_file + args['stderr'] = subprocess.STDOUT + self.child = subprocess.Popen(cmd, **args) + if 'stdin' in args: + self.child.stdin.close() self.log_path = ret return ret diff --git a/src/calibre/utils/ipc/server.py b/src/calibre/utils/ipc/server.py index 2613702084..448797eba4 100644 --- a/src/calibre/utils/ipc/server.py +++ b/src/calibre/utils/ipc/server.py @@ -78,7 +78,8 @@ class ConnectedWorker(Thread): self._returncode = r return r - +class CriticalError(Exception): + pass class Server(Thread): @@ -112,6 +113,8 @@ class Server(Thread): id = self.launched_worker_count rfile = os.path.join(tempfile.gettempdir(), 'calibre_ipc_result_%d_%d.pickle'%(self.id, id)) + if redirect_output is None: + redirect_output = not gui env = { 'CALIBRE_WORKER_ADDRESS' : @@ -126,14 +129,12 @@ class Server(Thread): if isinstance(cw, ConnectedWorker): break if isinstance(cw, basestring): - raise Exception('Failed to launch worker process:\n'+cw) + raise CriticalError('Failed to launch worker process:\n'+cw) return cw def do_launch(self, env, gui, redirect_output, rfile): w = Worker(env, gui=gui) - if redirect_output is None: - redirect_output = not gui try: w(redirect_output=redirect_output) conn = self.listener.accept() @@ -191,7 +192,9 @@ class Server(Thread): if len(self.pool) + len(self.workers) < self.pool_size: try: self.pool.append(self.launch_worker()) - except Exception, err: + except CriticalError: + raise + except Exception: pass if len(self.pool) > 0 and len(self.waiting_jobs) > 0: