mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Save/reuse ViewLog size from proceed_question when called with log_viewer_unique_name.
This commit is contained in:
parent
b594de0ae4
commit
463603dab0
@ -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)
|
||||||
|
|
||||||
|
if unique_name:
|
||||||
|
self.unique_name = "ViewLog_size_"+unique_name
|
||||||
|
else:
|
||||||
|
self.unique_name = None
|
||||||
|
self.geom = gprefs.get(self.unique_name, None)
|
||||||
|
self.finished.connect(self.dialog_closing)
|
||||||
|
self.resize_dialog()
|
||||||
|
|
||||||
self.setModal(False)
|
self.setModal(False)
|
||||||
self.resize(QSize(700, 500))
|
|
||||||
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,17 @@ 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 resize_dialog(self):
|
||||||
|
if self.geom is None:
|
||||||
|
self.resize(QSize(700, 500))
|
||||||
|
else:
|
||||||
|
self.restoreGeometry(self.geom)
|
||||||
|
|
||||||
|
def dialog_closing(self, result):
|
||||||
|
if self.unique_name:
|
||||||
|
self.geom = bytearray(self.saveGeometry())
|
||||||
|
gprefs[self.unique_name] = self.geom
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
_proceed_memory = []
|
_proceed_memory = []
|
||||||
|
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user