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))