From 1d73fabf59992010cbd1ee050061a9a4c7df53b7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 17 Apr 2024 06:34:22 +0530 Subject: [PATCH] Edit book: Add a setting to control cursor width under Preferences->Editor settings --- src/calibre/gui2/tweak_book/__init__.py | 1 + src/calibre/gui2/tweak_book/editor/text.py | 3 +++ src/calibre/gui2/tweak_book/preferences.py | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/src/calibre/gui2/tweak_book/__init__.py b/src/calibre/gui2/tweak_book/__init__.py index f82558e354..7bc8dcbdb0 100644 --- a/src/calibre/gui2/tweak_book/__init__.py +++ b/src/calibre/gui2/tweak_book/__init__.py @@ -19,6 +19,7 @@ d['editor_font_family'] = None d['editor_font_size'] = 12 d['editor_line_wrap'] = True d['editor_tab_stop_width'] = 2 +d['editor_cursor_width'] = 1 d['editor_show_char_under_cursor'] = True d['replace_entities_as_typed'] = True d['preview_refresh_time'] = 2 diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index f81d7958b1..d8981fb741 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -7,6 +7,7 @@ import os import re import textwrap import unicodedata +from contextlib import suppress import regex from qt.core import ( @@ -229,6 +230,8 @@ class TextEdit(PlainTextEdit): prefs = prefs or tprefs self.setAcceptDrops(prefs.get('editor_accepts_drops', True)) self.setLineWrapMode(QPlainTextEdit.LineWrapMode.WidgetWidth if prefs['editor_line_wrap'] else QPlainTextEdit.LineWrapMode.NoWrap) + with suppress(Exception): + self.setCursorWidth(int(prefs.get('editor_cursor_width', 1))) theme = get_theme(prefs['editor_theme']) self.apply_theme(theme) fm = self.fontMetrics() diff --git a/src/calibre/gui2/tweak_book/preferences.py b/src/calibre/gui2/tweak_book/preferences.py index 558a9d4e42..d0946fbff3 100644 --- a/src/calibre/gui2/tweak_book/preferences.py +++ b/src/calibre/gui2/tweak_book/preferences.py @@ -197,6 +197,10 @@ class EditorSettings(BasicSettings): # {{{ fs.setMinimum(8), fs.setSuffix(' pt'), fs.setMaximum(50) l.addRow(_('Editor font &size:'), fs) + cs = self('editor_cursor_width') + cs.setMinimum(1), cs.setSuffix(' px'), cs.setMaximum(50) + l.addRow(_('Editor cursor &width:'), cs) + choices = self.theme_choices() theme = self.choices_widget('editor_theme', choices, 'auto', 'auto') self.custom_theme_button = b = QPushButton(_('Create/edit &custom color schemes'))