mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Use both a colored border and an icon to indicate errors in line edits. Fixes #2007764 [Enhancement Request: Valid/invalid metadata display options](https://bugs.launchpad.net/calibre/+bug/2007764)
This commit is contained in:
parent
bcfb519afb
commit
02f50bf6ce
@ -15,6 +15,7 @@ from qt.core import (
|
|||||||
QIcon, QApplication, QKeyEvent)
|
QIcon, QApplication, QKeyEvent)
|
||||||
|
|
||||||
from calibre.gui2 import config, question_dialog, gprefs, QT_HIDDEN_CLEAR_ACTION
|
from calibre.gui2 import config, question_dialog, gprefs, QT_HIDDEN_CLEAR_ACTION
|
||||||
|
from calibre.gui2.widgets import stylesheet_for_lineedit
|
||||||
from calibre.gui2.dialogs.saved_search_editor import SavedSearchEditor
|
from calibre.gui2.dialogs.saved_search_editor import SavedSearchEditor
|
||||||
from calibre.gui2.dialogs.search import SearchDialog
|
from calibre.gui2.dialogs.search import SearchDialog
|
||||||
from calibre.utils.icu import primary_sort_key
|
from calibre.utils.icu import primary_sort_key
|
||||||
@ -174,7 +175,7 @@ class SearchBox2(QComboBox): # {{{
|
|||||||
|
|
||||||
def normalize_state(self):
|
def normalize_state(self):
|
||||||
self.setToolTip(self.tool_tip_text)
|
self.setToolTip(self.tool_tip_text)
|
||||||
self.line_edit.setStyleSheet('')
|
self.setStyleSheet('')
|
||||||
self.show_parse_error_action(False)
|
self.show_parse_error_action(False)
|
||||||
|
|
||||||
def text(self):
|
def text(self):
|
||||||
@ -194,11 +195,9 @@ class SearchBox2(QComboBox): # {{{
|
|||||||
self.setFocus(Qt.FocusReason.OtherFocusReason)
|
self.setFocus(Qt.FocusReason.OtherFocusReason)
|
||||||
|
|
||||||
def show_parse_error_action(self, to_show, tooltip=''):
|
def show_parse_error_action(self, to_show, tooltip=''):
|
||||||
try:
|
if self.parse_error_action is not None:
|
||||||
self.parse_error_action.setVisible(to_show)
|
self.parse_error_action.setVisible(to_show)
|
||||||
self.parse_error_action.setToolTip(tooltip)
|
self.parse_error_action.setToolTip(tooltip)
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def search_done(self, ok):
|
def search_done(self, ok):
|
||||||
if isinstance(ok, string_or_bytes):
|
if isinstance(ok, string_or_bytes):
|
||||||
@ -206,9 +205,14 @@ class SearchBox2(QComboBox): # {{{
|
|||||||
self.show_parse_error_action(True, tooltip=ok)
|
self.show_parse_error_action(True, tooltip=ok)
|
||||||
ok = False
|
ok = False
|
||||||
if not str(self.currentText()).strip():
|
if not str(self.currentText()).strip():
|
||||||
|
self.setStyleSheet('')
|
||||||
self.clear(emit_search=False)
|
self.clear(emit_search=False)
|
||||||
return
|
return
|
||||||
self._in_a_search = ok
|
self._in_a_search = ok
|
||||||
|
if self.parse_error_action is not None and not ok:
|
||||||
|
self.setStyleSheet(stylesheet_for_lineedit(bool(ok), 'QComboBox'))
|
||||||
|
else:
|
||||||
|
self.setStyleSheet('')
|
||||||
|
|
||||||
# Comes from the lineEdit control
|
# Comes from the lineEdit control
|
||||||
def key_pressed(self, event):
|
def key_pressed(self, event):
|
||||||
|
@ -555,6 +555,14 @@ def setup_status_actions(self: QLineEdit):
|
|||||||
self.status_actions[0].setVisible(False)
|
self.status_actions[0].setVisible(False)
|
||||||
self.status_actions[1].setVisible(False)
|
self.status_actions[1].setVisible(False)
|
||||||
|
|
||||||
|
|
||||||
|
def stylesheet_for_lineedit(ok, selector='QLineEdit') -> str:
|
||||||
|
if ok is None:
|
||||||
|
return ''
|
||||||
|
col = '#50c878' if ok else '#FF2400'
|
||||||
|
return f'{selector} {{ border: 2px solid {col}; border-radius: 3px }}'
|
||||||
|
|
||||||
|
|
||||||
def update_status_actions(self: QLineEdit, ok, tooltip: str = ''):
|
def update_status_actions(self: QLineEdit, ok, tooltip: str = ''):
|
||||||
self.status_actions[0].setVisible(bool(ok))
|
self.status_actions[0].setVisible(bool(ok))
|
||||||
self.status_actions[1].setVisible(not ok)
|
self.status_actions[1].setVisible(not ok)
|
||||||
@ -564,6 +572,8 @@ def update_status_actions(self: QLineEdit, ok, tooltip: str = ''):
|
|||||||
self.status_actions[1].setVisible(False)
|
self.status_actions[1].setVisible(False)
|
||||||
else:
|
else:
|
||||||
self.status_actions[1].setToolTip(tooltip)
|
self.status_actions[1].setToolTip(tooltip)
|
||||||
|
self.setStyleSheet(stylesheet_for_lineedit(ok))
|
||||||
|
|
||||||
|
|
||||||
class LineEditIndicators:
|
class LineEditIndicators:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user