This commit is contained in:
Kovid Goyal 2021-04-18 21:13:37 +05:30
commit 36511cb505
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 23 additions and 12 deletions

View file

@ -570,3 +570,8 @@
# Useful if for some reason your operating systems network checking
# facilities are not reliable (for example NetworkManager on Linux).
skip_network_check = False
#: Tab stop width in the template editor
# Sets the width of the tab stop in the template editor in "average characters".
# For example, a value of 1 results in a space the width of one average character.
template_editor_tab_stop_width = 4

View file

@ -12,7 +12,7 @@
QRegExp, QApplication, QTextCharFormat, QColor, QCursor,
QIcon, QSize, QPalette, QLineEdit, QByteArray, QFontInfo,
QFontDatabase, QVBoxLayout, QTableWidget, QTableWidgetItem,
QComboBox, QAbstractItemView, QTextOption)
QComboBox, QAbstractItemView, QTextOption, QFontMetrics)
from calibre import sanitize_file_name
from calibre.constants import config_dir
@ -21,6 +21,7 @@
from calibre.gui2 import gprefs, error_dialog, choose_files, choose_save_file, pixmap_to_data
from calibre.gui2.dialogs.template_dialog_ui import Ui_TemplateDialog
from calibre.library.coloring import (displayable_columns, color_row_key)
from calibre.utils.config_base import tweaks
from calibre.utils.formatter_functions import formatter_functions
from calibre.utils.formatter import StopException
from calibre.utils.icu import sort_key
@ -322,10 +323,8 @@ def __init__(self, parent, text, mi=None, fm=None, color_field=None,
self.highlighter = TemplateHighlighter(self.textbox.document(), builtin_functions=self.builtins)
self.textbox.cursorPositionChanged.connect(self.text_cursor_changed)
self.textbox.textChanged.connect(self.textbox_changed)
self.textbox.setFont(self.get_current_font())
self.set_editor_font()
self.textbox.setTabStopWidth(10)
self.source_code.setTabStopWidth(10)
self.documentation.setReadOnly(True)
self.source_code.setReadOnly(True)
@ -524,6 +523,17 @@ def get_current_font(self):
font = QFont(font_name, pointSize=size)
return font
def set_editor_font(self):
font = self.get_current_font()
fm = QFontMetrics(font)
chars = tweaks['template_editor_tab_stop_width']
w = fm.averageCharWidth() * chars
self.textbox.setTabStopDistance(w)
self.source_code.setTabStopDistance(w)
self.textbox.setFont(font)
self.highlighter.initializeFormats()
self.highlighter.rehighlight()
def set_up_font_boxes(self):
font = self.get_current_font()
self.font_box.setWritingSystem(QFontDatabase.Latin)
@ -533,21 +543,15 @@ def set_up_font_boxes(self):
self.font_size_box.setValue(font.pointSize())
self.font_box.currentFontChanged.connect(self.font_changed)
self.font_size_box.valueChanged.connect(self.font_size_changed)
self.highlighter.initializeFormats()
self.highlighter.rehighlight()
def font_changed(self, font):
fi = QFontInfo(font)
gprefs['gpm_template_editor_font'] = unicode_type(fi.family())
self.textbox.setFont(self.get_current_font())
self.highlighter.initializeFormats()
self.highlighter.rehighlight()
self.set_editor_font()
def font_size_changed(self, toWhat):
gprefs['gpm_template_editor_font_size'] = toWhat
self.textbox.setFont(self.get_current_font())
self.highlighter.initializeFormats()
self.highlighter.rehighlight()
self.set_editor_font()
def break_box_changed(self, new_state):
gprefs['template_editor_break_on_print'] = new_state != 0

View file

@ -796,6 +796,8 @@ def do_node_call(self, prog, args=None):
saved_line_number = self.override_line_number
self.override_line_number = (self.override_line_number if self.override_line_number
else prog.line_number)
else:
saved_line_number = None
try:
val = self.expression_list(prog.function)
except ReturnExecuted as e: