diff --git a/calibre-plugin/config.py b/calibre-plugin/config.py index c646877..4b981a4 100644 --- a/calibre-plugin/config.py +++ b/calibre-plugin/config.py @@ -73,7 +73,7 @@ no_trans = { 'pini':'personal.ini', from calibre_plugins.fanfictiondownloader_plugin.prefs import prefs, PREFS_NAMESPACE from calibre_plugins.fanfictiondownloader_plugin.dialogs \ import (UPDATE, UPDATEALWAYS, collision_order, save_collisions, RejectListDialog, - EditTextDialog, IniTextDialog, RejectUrlEntry, errors_dialog) + EditTextDialog, IniTextDialog, RejectUrlEntry) from calibre_plugins.fanfictiondownloader_plugin.fanficdownloader.adapters \ import getConfigSections @@ -655,25 +655,9 @@ class PersonalIniTab(QWidget): tooltip=_("Edit personal.ini"), use_find=True, save_size_name='ffdl:personal.ini') - retry=True - while retry: - d.exec_() - if d.result() == d.Accepted: - editini = d.get_plain_text() - errors = test_config(editini) - - if errors: - retry = errors_dialog(self.plugin_action.gui, - _('Go back to fix errors?'), - '
'+'
'.join([ '(lineno: %s) %s'%e for e in errors ])+'
') - else: - retry = False - - if not retry: - self.personalini = unicode(editini) - else: - # cancelled - retry = False + d.exec_() + if d.result() == d.Accepted: + self.personalini = d.get_plain_text() class ReadingListTab(QWidget): diff --git a/calibre-plugin/dialogs.py b/calibre-plugin/dialogs.py index a066ac2..9fdde96 100644 --- a/calibre-plugin/dialogs.py +++ b/calibre-plugin/dialogs.py @@ -1265,6 +1265,30 @@ class IniTextDialog(SizePersistedDialog): # Cause our dialog size to be restored from prefs or created on first usage self.resize_dialog() + def accept(self): + from ffdl_util import test_config + + print("in accept") + errors = test_config(self.get_plain_text()) + + retry = False + if errors: + d = ViewLog(self, + _('Go back to fix errors?'), + errors) + retry = d.exec_() == d.Accepted + + print("retry:%s"%retry) + + if retry: + lineno=d.get_lineno() + if lineno: + print("go to lineno (%s) here"%lineno) + self.select_line(lineno) + else: + print("call parent accept") + return SizePersistedDialog.accept(self) + def addCtrlKeyPress(self,key,func): # print("addKeyPress: key(0x%x)"%key) # print("control: 0x%x"%QtCore.Qt.ControlModifier) @@ -1328,31 +1352,65 @@ class IniTextDialog(SizePersistedDialog): # And finally we set this new cursor as the parent's self.textedit.setTextCursor(cursor) -def errors_dialog(parent, - title, - html): - - d = ViewLog(title,html,parent) - - return d.exec_() == d.Accepted + def select_line(self,lineno): + # We retrieve the QTextCursor object from the parent's QTextEdit + cursor = self.textedit.textCursor() + + # Then we set the position to the beginning of the buffer + cursor.setPosition(0) + + # Next we move the Cursor down lineno times + cursor.movePosition(cursor.Down,cursor.MoveAnchor,lineno-1) + + # Next we move the Cursor to the end of the line + cursor.movePosition(cursor.EndOfLine,cursor.KeepAnchor,1) + + # And finally we set this new cursor as the parent's + self.textedit.setTextCursor(cursor) + + class ViewLog(SizePersistedDialog): - def __init__(self, title, html, parent=None, + def label_clicked(self, event, lineno=None): + self.lineno = lineno + print("lineno set to: %s"%lineno) + self.accept() + + def get_lineno(self): + return self.lineno + + def __init__(self, parent, title, errors, save_size_name='ffdl:view log dialog',): SizePersistedDialog.__init__(self, parent,save_size_name) self.l = l = QVBoxLayout() self.setLayout(l) - label = QLabel(_('Eventually I intend for errors to be clickable and take you to the error in the file. For now, use copy and Find.')) + label = QLabel(_('Click an error below to go directly to that line:')) label.setWordWrap(True) self.l.addWidget(label) + + self.lineno = None + + ## error = (lineno, msg) + for (lineno, error_msg) in errors: + print('adding label for error:%s: %s'%(lineno, error_msg)) + label = QLabel('%s: %s'%(lineno, error_msg)) + label.setWordWrap(True) + label.setStyleSheet("QLabel { margin-left: 2em; color : blue; } QLabel:hover { color: red; }"); + label.setToolTip(_('Click to go to line %s')%lineno) + label.mouseReleaseEvent = partial(self.label_clicked, lineno=lineno) + self.l.addWidget(label) - self.tb = QTextBrowser(self) - self.tb.setFont(QFont("Courier", - parent.font().pointSize()+1)) - self.tb.setHtml(html) - l.addWidget(self.tb) + # html=''+'
'.join([ '(lineno: %s) %s'%e for e in errors ])+'
' + + # self.tb = QTextBrowser(self) + # self.tb.setFont(QFont("Courier", + # parent.font().pointSize()+1)) + # self.tb.setHtml(html) + # l.addWidget(self.tb) + + self.l.insertStretch(-1) horz = QHBoxLayout() diff --git a/calibre-plugin/ffdl_util.py b/calibre-plugin/ffdl_util.py index 6f28eb3..8cb6863 100644 --- a/calibre-plugin/ffdl_util.py +++ b/calibre-plugin/ffdl_util.py @@ -43,10 +43,9 @@ def get_ffdl_adapter(url,fileform="epub",personalini=None): return adapters.getAdapter(get_ffdl_config(url,fileform,personalini),url) def test_config(initext): - - configini = get_ffdl_config("test1.com?sid=555", - personalini=initext) try: + configini = get_ffdl_config("test1.com?sid=555", + personalini=initext) errors = configini.test_config() except ParsingError as pe: errors = pe.errors