From ef1768505ccadce82880a707b60b3d5b8f44684a Mon Sep 17 00:00:00 2001 From: Fernando Basso Date: Fri, 10 Dec 2021 07:58:02 -0300 Subject: [PATCH 1/2] Add cell width configuration in preferences Currently, we have a setting for changing the line height (cell height), but not for changing cell width (both available in VTE). Depending on the font used, it is useful to have the ability to set a little more space between characters. This commit adds a configuration similar to the existing one for line height, but for character space (cell width scale [1]). Thanks Matt Rose for helping and encouraging me to implement this. 1. https://lazka.github.io/pgi-docs/Vte-2.91/classes/Terminal.html#Vte.Terminal.set_cell_width_scale --- terminatorlib/config.py | 2 + terminatorlib/preferences.glade | 74 ++++++++++++++++++++++++++++++++- terminatorlib/prefseditor.py | 23 ++++++++++ terminatorlib/terminal.py | 2 + 4 files changed, 100 insertions(+), 1 deletion(-) diff --git a/terminatorlib/config.py b/terminatorlib/config.py index b0888a71..2a5e01d8 100644 --- a/terminatorlib/config.py +++ b/terminatorlib/config.py @@ -114,6 +114,7 @@ DEFAULTS = { 'smart_copy' : True, 'clear_select_on_copy' : False, 'line_height' : 1.0, + 'cell_width' : 1.0, 'case_sensitive' : True, 'invert_search' : False, 'link_single_click' : False, @@ -245,6 +246,7 @@ DEFAULTS = { 'use_theme_colors' : False, 'bold_is_bright' : False, 'line_height' : 1.0, + 'cell_width' : 1.0, 'focus_on_close' : 'auto', 'force_no_bell' : False, 'cycle_term_tab' : True, diff --git a/terminatorlib/preferences.glade b/terminatorlib/preferences.glade index 2c73f5e5..9eb5b61b 100644 --- a/terminatorlib/preferences.glade +++ b/terminatorlib/preferences.glade @@ -347,6 +347,13 @@ 0.10 0.20 + + 1 + 2 + 1 + 0.10 + 0.20 + 1 0.10 @@ -880,7 +887,7 @@ 36 True - + True False @@ -992,6 +999,71 @@ 4 + + + 100 + True + True + baseline + True + adjustment1 + 0 + 0 + False + bottom + + + + 2 + 1 + + + + + True + False + Cell Width: + 0 + + + 0 + 5 + + + + + 100 + True + True + baseline + True + adjustment_cellwidth + 1 + False + bottom + + + + 2 + 5 + + + + + True + False + 1.0 + right + 5 + 5 + 1 + 1 + + + 1 + 5 + + 100 diff --git a/terminatorlib/prefseditor.py b/terminatorlib/prefseditor.py index 90e2b04c..d59c80db 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -263,6 +263,17 @@ class PrefsEditor: widget.set_value(lineheightsize) widget = guiget('lineheight_value_label') widget.set_text(str(lineheightsize)) + + # + # Cell Width + # + cellwidthsize = self.config['cell_width'] + cellwidthsize = round(float(cellwidthsize),1) + widget = guiget('cellwidth') + widget.set_value(cellwidthsize) + widget = guiget('cellwidth_value_label') + widget.set_text(str(cellwidthsize)) + # Window geometry hints geomhint = self.config['geometry_hinting'] widget = guiget('wingeomcheck') @@ -1264,6 +1275,18 @@ class PrefsEditor: label_widget = guiget('lineheight_value_label') label_widget.set_text(str(value)) + def on_handlewidth_value_changed(self, widget): + """Handles cell width changed""" + value = widget.get_value() + value = round(float(value), 1) + if value > 2.0: + value = 2.0 + self.config['cell_width'] = value + self.config.save() + guiget = self.builder.get_object + label_widget = guiget('cellwidth_value_label') + label_widget.set_text(str(value)) + def on_focuscombo_changed(self, widget): """Focus type changed""" selected = widget.get_active() diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 6c224b94..69cfa6fe 100644 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -718,6 +718,8 @@ class Terminal(Gtk.VBox): self.vte.set_allow_bold(self.config['allow_bold']) if hasattr(self.vte,'set_cell_height_scale'): self.vte.set_cell_height_scale(self.config['line_height']) + if hasattr(self.vte,'set_cell_width_scale'): + self.vte.set_cell_width_scale(self.config['cell_width']) if hasattr(self.vte, 'set_bold_is_bright'): self.vte.set_bold_is_bright(self.config['bold_is_bright']) From bd5dba5b08981c1313c3d4ca3f104dd29f56e1ff Mon Sep 17 00:00:00 2001 From: Fernando Basso Date: Fri, 10 Dec 2021 08:18:37 -0300 Subject: [PATCH 2/2] Refactor line height to cell height MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After the previous commit [1], which implements ‘cell width’, it makes sense to rename ‘line height’ to ‘cell height’, especially because it is the terminology used by VTE itself [2]. 1. ef1768505ccadc Add cell width configuration in preferences 2. https://lazka.github.io/pgi-docs/Vte-2.91/classes/Terminal.html#Vte.Terminal.set_cell_height_scale --- terminatorlib/config.py | 15 ++++++++++++--- terminatorlib/preferences.glade | 14 +++++++------- terminatorlib/prefseditor.py | 25 ++++++++++++++----------- terminatorlib/terminal.py | 2 +- terminatorlib/util.py | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 22 deletions(-) diff --git a/terminatorlib/config.py b/terminatorlib/config.py index 2a5e01d8..75e65328 100644 --- a/terminatorlib/config.py +++ b/terminatorlib/config.py @@ -76,7 +76,7 @@ from copy import copy from configobj import ConfigObj, flatten_errors from validate import Validator from .borg import Borg -from .util import dbg, err, DEBUG, get_system_config_dir, get_config_dir, dict_diff +from .util import dbg, err, DEBUG, get_system_config_dir, get_config_dir, dict_diff, update_config_to_cell_height from gi.repository import Gio @@ -113,7 +113,7 @@ DEFAULTS = { 'disable_mouse_paste' : False, 'smart_copy' : True, 'clear_select_on_copy' : False, - 'line_height' : 1.0, + 'cell_height' : 1.0, 'cell_width' : 1.0, 'case_sensitive' : True, 'invert_search' : False, @@ -245,7 +245,7 @@ DEFAULTS = { 'use_system_font' : True, 'use_theme_colors' : False, 'bold_is_bright' : False, - 'line_height' : 1.0, + 'cell_height' : 1.0, 'cell_width' : 1.0, 'focus_on_close' : 'auto', 'force_no_bell' : False, @@ -509,6 +509,7 @@ class ConfigBase(Borg): plugins = None layouts = None command_line_options = None + config_file_updated_to_cell_height = False def __init__(self): """Class initialiser""" @@ -628,6 +629,14 @@ class ConfigBase(Borg): filename = os.path.join(get_system_config_dir(), 'config') dbg('looking for config file: %s' % filename) try: + # + # Make sure we attempt to update the ‘cell_height’ config + # only once when starting a new instance of Terminator. + # + if not self.config_file_updated_to_cell_height: + update_config_to_cell_height(filename) + self.config_file_updated_to_cell_height = True + configfile = open(filename, 'r') except Exception as ex: if not self.whined: diff --git a/terminatorlib/preferences.glade b/terminatorlib/preferences.glade index 9eb5b61b..6719c89d 100644 --- a/terminatorlib/preferences.glade +++ b/terminatorlib/preferences.glade @@ -340,7 +340,7 @@ 0.10 0.20 - + 1 2 1 @@ -954,10 +954,10 @@ - + True False - Line Height: + Cell Height: 0 @@ -966,17 +966,17 @@ - + 100 True True baseline True - adjustment_lineheight + adjustment_cellheight 1 False bottom - + 2 @@ -984,7 +984,7 @@ - + True False 1.0 diff --git a/terminatorlib/prefseditor.py b/terminatorlib/prefseditor.py index d59c80db..965473a6 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -256,13 +256,16 @@ class PrefsEditor: widget.set_value(float(termsepsize)) widget = guiget('handlesize_value_label') widget.set_text(str(termsepsize)) - # Line Height - lineheightsize = self.config['line_height'] - lineheightsize = round(float(lineheightsize),1) - widget = guiget('lineheight') - widget.set_value(lineheightsize) - widget = guiget('lineheight_value_label') - widget.set_text(str(lineheightsize)) + + # + # Cell Height + # + cellheightsize = self.config['cell_height'] + cellheightsize = round(float(cellheightsize),1) + widget = guiget('cellheight') + widget.set_value(cellheightsize) + widget = guiget('cellheight_value_label') + widget.set_text(str(cellheightsize)) # # Cell Width @@ -1263,16 +1266,16 @@ class PrefsEditor: label_widget = guiget('handlesize_value_label') label_widget.set_text(str(value)) - def on_lineheight_value_changed(self, widget): - """Handles line height changed""" + def on_cellheight_value_changed(self, widget): + """Handles cell height changed""" value = widget.get_value() value = round(float(value), 1) if value > 2.0: value = 2.0 - self.config['line_height'] = value + self.config['cell_height'] = value self.config.save() guiget = self.builder.get_object - label_widget = guiget('lineheight_value_label') + label_widget = guiget('cellheight_value_label') label_widget.set_text(str(value)) def on_handlewidth_value_changed(self, widget): diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 69cfa6fe..894666c1 100644 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -717,7 +717,7 @@ class Terminal(Gtk.VBox): pass self.vte.set_allow_bold(self.config['allow_bold']) if hasattr(self.vte,'set_cell_height_scale'): - self.vte.set_cell_height_scale(self.config['line_height']) + self.vte.set_cell_height_scale(self.config['cell_height']) if hasattr(self.vte,'set_cell_width_scale'): self.vte.set_cell_width_scale(self.config['cell_width']) if hasattr(self.vte, 'set_bold_is_bright'): diff --git a/terminatorlib/util.py b/terminatorlib/util.py index 5a9055a5..4c4a72d4 100644 --- a/terminatorlib/util.py +++ b/terminatorlib/util.py @@ -361,3 +361,36 @@ def display_manager(): return 'WAYLAND' # Fallback assumption of X11 return 'X11' + +def update_config_to_cell_height(filename): + '''Replace ‘line_height’ with ‘cell_height’ in Terminator + config file (usually ~/.config/terminator/config on + Unix-like systems).''' + + dbg('update_config_to_cell_height() config filename %s' % filename) + + try: + with open(filename, 'r+') as file: + config_text = file.read() + + if not 'line_height' in config_text: + # + # It is either a new config, or it is already using the + # new ‘cell_height’ property instead the old ‘line_height’. + # + dbg('No ‘line_height’ found in ‘%s’.' % filename) + file.close() + return + + updated_config_text = config_text.replace('line_height', 'cell_height') + + file.seek(0) + file.write(updated_config_text) + file.truncate() + file.close() + + dbg('Updted ‘line_height’ to ‘cell_height’.') + + except Exception as ex: + err('Unable to open ‘%s’ for reading and/or writting.\n(%s)' + % (filename, ex))