From a2727ec253b55aaf583f81d0da849f62ca7508ab Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 7 Feb 2014 15:34:44 +0530 Subject: [PATCH] Edit book: Fix previously used locations for file open dialogs not being remembered when edit book is launched from within the main calibre program --- src/calibre/gui2/__init__.py | 6 ++++++ src/calibre/gui2/tweak_book/main.py | 3 ++- src/calibre/utils/config.py | 18 ++++++++++++++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 0f8e67596e..7eedab5d0e 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -763,6 +763,12 @@ def pixmap_to_data(pixmap, format='JPEG', quality=90): pixmap.save(buf, format, quality=quality) return bytes(ba.data()) +def decouple(prefix): + ' Ensure that config files used by utility code are not the same as those used by the main calibre GUI ' + dynamic.decouple(prefix) + from calibre.gui2.widgets import history + history.decouple(prefix) + class ResizableDialog(QDialog): def __init__(self, *args, **kwargs): diff --git a/src/calibre/gui2/tweak_book/main.py b/src/calibre/gui2/tweak_book/main.py index ffd479cf6e..155a3e2537 100644 --- a/src/calibre/gui2/tweak_book/main.py +++ b/src/calibre/gui2/tweak_book/main.py @@ -11,7 +11,7 @@ import sys, os, importlib from PyQt4.Qt import QIcon from calibre.constants import islinux, iswindows -from calibre.gui2 import Application, ORG_NAME, APP_UID, setup_gui_option_parser, detach_gui +from calibre.gui2 import Application, ORG_NAME, APP_UID, setup_gui_option_parser, detach_gui, decouple from calibre.ptempfile import reset_base_dir from calibre.utils.config import OptionParser @@ -54,6 +54,7 @@ def _run(args, notify=None): opts, args = parser.parse_args(args) if getattr(opts, 'detach', False): detach_gui() + decouple('edit-book-') override = 'calibre-edit-book' if islinux else None app = Application(args, override_program_name=override) app.load_builtin_fonts() diff --git a/src/calibre/utils/config.py b/src/calibre/utils/config.py index 3d0738f46c..2da7863192 100644 --- a/src/calibre/utils/config.py +++ b/src/calibre/utils/config.py @@ -202,7 +202,11 @@ class DynamicConfig(dict): self.file_path = os.path.join(config_dir, name+'.pickle') self.refresh() - def refresh(self): + def decouple(self, prefix): + self.file_path = os.path.join(os.path.dirname(self.file_path), prefix + os.path.basename(self.file_path)) + self.refresh(clear_current=False) + + def refresh(self, clear_current=True): d = {} if os.path.exists(self.file_path): with ExclusiveFile(self.file_path) as f: @@ -216,7 +220,8 @@ class DynamicConfig(dict): print 'Failed to unpickle stored object:' traceback.print_exc() d = {} - self.clear() + if clear_current: + self.clear() self.update(d) def __getitem__(self, key): @@ -280,7 +285,11 @@ class XMLConfig(dict): def to_raw(self): return plistlib.writePlistToString(self) - def refresh(self): + def decouple(self, prefix): + self.file_path = os.path.join(os.path.dirname(self.file_path), prefix + os.path.basename(self.file_path)) + self.refresh(clear_current=False) + + def refresh(self, clear_current=True): d = {} if os.path.exists(self.file_path): with ExclusiveFile(self.file_path) as f: @@ -293,7 +302,8 @@ class XMLConfig(dict): import traceback traceback.print_exc() d = {} - self.clear() + if clear_current: + self.clear() self.update(d) def __getitem__(self, key):