This commit is contained in:
Kovid Goyal 2016-05-09 20:50:10 +05:30
commit 291b27e425
5 changed files with 28 additions and 10 deletions

View File

@ -12,6 +12,7 @@ from PyQt5.Qt import (QDialog, QIcon, QApplication, QSize, QKeySequence,
QLabel, QPlainTextEdit, QTextDocument, QCheckBox, pyqtSignal) QLabel, QPlainTextEdit, QTextDocument, QCheckBox, pyqtSignal)
from calibre.constants import __version__, isfrozen from calibre.constants import __version__, isfrozen
from calibre.gui2 import gprefs
class MessageBox(QDialog): # {{{ class MessageBox(QDialog): # {{{
@ -167,7 +168,7 @@ class MessageBox(QDialog): # {{{
class ViewLog(QDialog): # {{{ class ViewLog(QDialog): # {{{
def __init__(self, title, html, parent=None): def __init__(self, title, html, parent=None, unique_name=None):
QDialog.__init__(self, parent) QDialog.__init__(self, parent)
self.l = l = QVBoxLayout() self.l = l = QVBoxLayout()
self.setLayout(l) self.setLayout(l)
@ -184,8 +185,16 @@ class ViewLog(QDialog): # {{{
self.copy_button.setIcon(QIcon(I('edit-copy.png'))) self.copy_button.setIcon(QIcon(I('edit-copy.png')))
self.copy_button.clicked.connect(self.copy_to_clipboard) self.copy_button.clicked.connect(self.copy_to_clipboard)
l.addWidget(self.bb) l.addWidget(self.bb)
self.setModal(False)
self.unique_name = unique_name or 'view-log-dialog'
self.finished.connect(self.dialog_closing)
self.resize(QSize(700, 500)) self.resize(QSize(700, 500))
geom = gprefs.get(self.unique_name, None)
if geom is not None:
self.restoreGeometry(self.geom)
self.resize_dialog()
self.setModal(False)
self.setWindowTitle(title) self.setWindowTitle(title)
self.setWindowIcon(QIcon(I('debug.png'))) self.setWindowIcon(QIcon(I('debug.png')))
self.show() self.show()
@ -193,6 +202,10 @@ class ViewLog(QDialog): # {{{
def copy_to_clipboard(self): def copy_to_clipboard(self):
txt = self.tb.toPlainText() txt = self.tb.toPlainText()
QApplication.clipboard().setText(txt) QApplication.clipboard().setText(txt)
def dialog_closing(self, result):
self.geom = bytearray(self.saveGeometry())
gprefs[self.unique_name] = self.geom
# }}} # }}}
_proceed_memory = [] _proceed_memory = []

View File

@ -37,6 +37,7 @@ class SavedSearchEditor(QDialog, Ui_SavedSearchEditor):
def populate_search_list(self): def populate_search_list(self):
self.search_name_box.blockSignals(True) self.search_name_box.blockSignals(True)
self.search_name_box.clear() self.search_name_box.clear()
self.search_name_box.addItem('')
for name in sorted(self.searches.keys(), key=sort_key): for name in sorted(self.searches.keys(), key=sort_key):
self.search_name_box.addItem(name) self.search_name_box.addItem(name)
self.search_names = set([icu_lower(n) for n in self.searches.keys()]) self.search_names = set([icu_lower(n) for n in self.searches.keys()])
@ -88,6 +89,7 @@ class SavedSearchEditor(QDialog, Ui_SavedSearchEditor):
if self.current_search_name in self.searches: if self.current_search_name in self.searches:
self.searches[new_search_name] = self.searches[self.current_search_name] self.searches[new_search_name] = self.searches[self.current_search_name]
del self.searches[self.current_search_name] del self.searches[self.current_search_name]
self.current_search_name = None
self.populate_search_list() self.populate_search_list()
self.select_search(new_search_name) self.select_search(new_search_name)
return True return True

View File

@ -123,7 +123,7 @@
<item row="0" column="5"> <item row="0" column="5">
<widget class="QToolButton" name="add_search_button"> <widget class="QToolButton" name="add_search_button">
<property name="toolTip"> <property name="toolTip">
<string>Add the new saved search</string> <string>Add a new, empty saved search with the name entered</string>
</property> </property>
<property name="text"> <property name="text">
<string>...</string> <string>...</string>

View File

@ -20,7 +20,8 @@ from calibre.gui2.dialogs.message_box import ViewLog
Question = namedtuple('Question', 'payload callback cancel_callback ' Question = namedtuple('Question', 'payload callback cancel_callback '
'title msg html_log log_viewer_title log_is_file det_msg ' 'title msg html_log log_viewer_title log_is_file det_msg '
'show_copy_button checkbox_msg checkbox_checked action_callback ' 'show_copy_button checkbox_msg checkbox_checked action_callback '
'action_label action_icon focus_action show_det show_ok icon') 'action_label action_icon focus_action show_det show_ok icon '
'log_viewer_unique_name')
class Icon(QWidget): class Icon(QWidget):
@ -306,7 +307,7 @@ class ProceedQuestion(QWidget):
msg, det_msg='', show_copy_button=False, cancel_callback=None, msg, det_msg='', show_copy_button=False, cancel_callback=None,
log_is_file=False, checkbox_msg=None, checkbox_checked=False, log_is_file=False, checkbox_msg=None, checkbox_checked=False,
action_callback=None, action_label=None, action_icon=None, focus_action=False, action_callback=None, action_label=None, action_icon=None, focus_action=False,
show_det=False, show_ok=False, icon=None, **kw): show_det=False, show_ok=False, icon=None, log_viewer_unique_name=None, **kw):
''' '''
A non modal popup that notifies the user that a background task has A non modal popup that notifies the user that a background task has
been completed. This class guarantees that only a single popup is been completed. This class guarantees that only a single popup is
@ -341,12 +342,13 @@ class ProceedQuestion(QWidget):
:param show_det: If True, the Detailed message will be shown initially :param show_det: If True, the Detailed message will be shown initially
:param show_ok: If True, OK will be shown instead of YES/NO :param show_ok: If True, OK will be shown instead of YES/NO
:param icon: The icon to be used for this popop (defaults to question mark). Can be either a QIcon or a string to be used with I() :param icon: The icon to be used for this popop (defaults to question mark). Can be either a QIcon or a string to be used with I()
:log_viewer_unique_name: If set, ViewLog will remember/reuse its size for this name in calibre.gui2.gprefs
''' '''
question = Question( question = Question(
payload, callback, cancel_callback, title, msg, html_log, payload, callback, cancel_callback, title, msg, html_log,
log_viewer_title, log_is_file, det_msg, show_copy_button, log_viewer_title, log_is_file, det_msg, show_copy_button,
checkbox_msg, checkbox_checked, action_callback, action_label, checkbox_msg, checkbox_checked, action_callback, action_label,
action_icon, focus_action, show_det, show_ok, icon) action_icon, focus_action, show_det, show_ok, icon, log_viewer_unique_name)
self.questions.append(question) self.questions.append(question)
self.show_question() self.show_question()
@ -358,7 +360,7 @@ class ProceedQuestion(QWidget):
with open(log, 'rb') as f: with open(log, 'rb') as f:
log = f.read().decode('utf-8') log = f.read().decode('utf-8')
self.log_viewer = ViewLog(q.log_viewer_title, log, self.log_viewer = ViewLog(q.log_viewer_title, log,
parent=self) parent=self, unique_name=q.log_viewer_unique_name)
def paintEvent(self, ev): def paintEvent(self, ev):
painter = QPainter(self) painter = QPainter(self)

View File

@ -334,6 +334,7 @@ class SavedSearchBox(QComboBox): # {{{
QComboBox.clear(self) QComboBox.clear(self)
self.initialize_saved_search_names() self.initialize_saved_search_names()
self.setEditText('') self.setEditText('')
self.setToolTip(self.tool_tip_text)
self.line_edit.home(False) self.line_edit.home(False)
def key_pressed(self, event): def key_pressed(self, event):
@ -525,9 +526,9 @@ class SavedSearchBoxMixin(object): # {{{
# self.saved_searches_changed() # self.saved_searches_changed()
self.saved_search.initialize(self.search, colorize=True, self.saved_search.initialize(self.search, colorize=True,
help_text=_('Saved Searches')) help_text=_('Saved Searches'))
self.saved_search.setToolTip( self.saved_search.tool_tip_text=_('Choose saved search or enter name for new saved search')
_('Choose saved search or enter name for new saved search')) self.saved_search.setToolTip(self.saved_search.tool_tip_text)
self.saved_search.setStatusTip(self.saved_search.toolTip()) self.saved_search.setStatusTip(self.saved_search.tool_tip_text)
for x in ('copy', 'save'): for x in ('copy', 'save'):
b = getattr(self, x+'_search_button') b = getattr(self, x+'_search_button')
b.setStatusTip(b.toolTip()) b.setStatusTip(b.toolTip())