Refactor line height to cell height
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. ef1768505c
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
This commit is contained in:
parent
ef1768505c
commit
bd5dba5b08
|
@ -76,7 +76,7 @@ from copy import copy
|
||||||
from configobj import ConfigObj, flatten_errors
|
from configobj import ConfigObj, flatten_errors
|
||||||
from validate import Validator
|
from validate import Validator
|
||||||
from .borg import Borg
|
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
|
from gi.repository import Gio
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ DEFAULTS = {
|
||||||
'disable_mouse_paste' : False,
|
'disable_mouse_paste' : False,
|
||||||
'smart_copy' : True,
|
'smart_copy' : True,
|
||||||
'clear_select_on_copy' : False,
|
'clear_select_on_copy' : False,
|
||||||
'line_height' : 1.0,
|
'cell_height' : 1.0,
|
||||||
'cell_width' : 1.0,
|
'cell_width' : 1.0,
|
||||||
'case_sensitive' : True,
|
'case_sensitive' : True,
|
||||||
'invert_search' : False,
|
'invert_search' : False,
|
||||||
|
@ -245,7 +245,7 @@ DEFAULTS = {
|
||||||
'use_system_font' : True,
|
'use_system_font' : True,
|
||||||
'use_theme_colors' : False,
|
'use_theme_colors' : False,
|
||||||
'bold_is_bright' : False,
|
'bold_is_bright' : False,
|
||||||
'line_height' : 1.0,
|
'cell_height' : 1.0,
|
||||||
'cell_width' : 1.0,
|
'cell_width' : 1.0,
|
||||||
'focus_on_close' : 'auto',
|
'focus_on_close' : 'auto',
|
||||||
'force_no_bell' : False,
|
'force_no_bell' : False,
|
||||||
|
@ -509,6 +509,7 @@ class ConfigBase(Borg):
|
||||||
plugins = None
|
plugins = None
|
||||||
layouts = None
|
layouts = None
|
||||||
command_line_options = None
|
command_line_options = None
|
||||||
|
config_file_updated_to_cell_height = False
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Class initialiser"""
|
"""Class initialiser"""
|
||||||
|
@ -628,6 +629,14 @@ class ConfigBase(Borg):
|
||||||
filename = os.path.join(get_system_config_dir(), 'config')
|
filename = os.path.join(get_system_config_dir(), 'config')
|
||||||
dbg('looking for config file: %s' % filename)
|
dbg('looking for config file: %s' % filename)
|
||||||
try:
|
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')
|
configfile = open(filename, 'r')
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
if not self.whined:
|
if not self.whined:
|
||||||
|
|
|
@ -340,7 +340,7 @@
|
||||||
<property name="step-increment">0.10</property>
|
<property name="step-increment">0.10</property>
|
||||||
<property name="page-increment">0.20</property>
|
<property name="page-increment">0.20</property>
|
||||||
</object>
|
</object>
|
||||||
<object class="GtkAdjustment" id="adjustment_lineheight">
|
<object class="GtkAdjustment" id="adjustment_cellheight">
|
||||||
<property name="lower">1</property>
|
<property name="lower">1</property>
|
||||||
<property name="upper">2</property>
|
<property name="upper">2</property>
|
||||||
<property name="value">1</property>
|
<property name="value">1</property>
|
||||||
|
@ -954,10 +954,10 @@
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="line_height_label">
|
<object class="GtkLabel" id="cell_height_label">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can-focus">False</property>
|
<property name="can-focus">False</property>
|
||||||
<property name="label" translatable="yes">Line Height:</property>
|
<property name="label" translatable="yes">Cell Height:</property>
|
||||||
<property name="xalign">0</property>
|
<property name="xalign">0</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
|
@ -966,17 +966,17 @@
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkScale" id="lineheight">
|
<object class="GtkScale" id="cellheight">
|
||||||
<property name="width-request">100</property>
|
<property name="width-request">100</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can-focus">True</property>
|
<property name="can-focus">True</property>
|
||||||
<property name="halign">baseline</property>
|
<property name="halign">baseline</property>
|
||||||
<property name="hexpand">True</property>
|
<property name="hexpand">True</property>
|
||||||
<property name="adjustment">adjustment_lineheight</property>
|
<property name="adjustment">adjustment_cellheight</property>
|
||||||
<property name="round-digits">1</property>
|
<property name="round-digits">1</property>
|
||||||
<property name="draw-value">False</property>
|
<property name="draw-value">False</property>
|
||||||
<property name="value-pos">bottom</property>
|
<property name="value-pos">bottom</property>
|
||||||
<signal name="value-changed" handler="on_lineheight_value_changed" swapped="no"/>
|
<signal name="value-changed" handler="on_cellheight_value_changed" swapped="no"/>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="left-attach">2</property>
|
<property name="left-attach">2</property>
|
||||||
|
@ -984,7 +984,7 @@
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="lineheight_value_label">
|
<object class="GtkLabel" id="cellheight_value_label">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can-focus">False</property>
|
<property name="can-focus">False</property>
|
||||||
<property name="label">1.0</property>
|
<property name="label">1.0</property>
|
||||||
|
|
|
@ -256,13 +256,16 @@ class PrefsEditor:
|
||||||
widget.set_value(float(termsepsize))
|
widget.set_value(float(termsepsize))
|
||||||
widget = guiget('handlesize_value_label')
|
widget = guiget('handlesize_value_label')
|
||||||
widget.set_text(str(termsepsize))
|
widget.set_text(str(termsepsize))
|
||||||
# Line Height
|
|
||||||
lineheightsize = self.config['line_height']
|
#
|
||||||
lineheightsize = round(float(lineheightsize),1)
|
# Cell Height
|
||||||
widget = guiget('lineheight')
|
#
|
||||||
widget.set_value(lineheightsize)
|
cellheightsize = self.config['cell_height']
|
||||||
widget = guiget('lineheight_value_label')
|
cellheightsize = round(float(cellheightsize),1)
|
||||||
widget.set_text(str(lineheightsize))
|
widget = guiget('cellheight')
|
||||||
|
widget.set_value(cellheightsize)
|
||||||
|
widget = guiget('cellheight_value_label')
|
||||||
|
widget.set_text(str(cellheightsize))
|
||||||
|
|
||||||
#
|
#
|
||||||
# Cell Width
|
# Cell Width
|
||||||
|
@ -1263,16 +1266,16 @@ class PrefsEditor:
|
||||||
label_widget = guiget('handlesize_value_label')
|
label_widget = guiget('handlesize_value_label')
|
||||||
label_widget.set_text(str(value))
|
label_widget.set_text(str(value))
|
||||||
|
|
||||||
def on_lineheight_value_changed(self, widget):
|
def on_cellheight_value_changed(self, widget):
|
||||||
"""Handles line height changed"""
|
"""Handles cell height changed"""
|
||||||
value = widget.get_value()
|
value = widget.get_value()
|
||||||
value = round(float(value), 1)
|
value = round(float(value), 1)
|
||||||
if value > 2.0:
|
if value > 2.0:
|
||||||
value = 2.0
|
value = 2.0
|
||||||
self.config['line_height'] = value
|
self.config['cell_height'] = value
|
||||||
self.config.save()
|
self.config.save()
|
||||||
guiget = self.builder.get_object
|
guiget = self.builder.get_object
|
||||||
label_widget = guiget('lineheight_value_label')
|
label_widget = guiget('cellheight_value_label')
|
||||||
label_widget.set_text(str(value))
|
label_widget.set_text(str(value))
|
||||||
|
|
||||||
def on_handlewidth_value_changed(self, widget):
|
def on_handlewidth_value_changed(self, widget):
|
||||||
|
|
|
@ -717,7 +717,7 @@ class Terminal(Gtk.VBox):
|
||||||
pass
|
pass
|
||||||
self.vte.set_allow_bold(self.config['allow_bold'])
|
self.vte.set_allow_bold(self.config['allow_bold'])
|
||||||
if hasattr(self.vte,'set_cell_height_scale'):
|
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'):
|
if hasattr(self.vte,'set_cell_width_scale'):
|
||||||
self.vte.set_cell_width_scale(self.config['cell_width'])
|
self.vte.set_cell_width_scale(self.config['cell_width'])
|
||||||
if hasattr(self.vte, 'set_bold_is_bright'):
|
if hasattr(self.vte, 'set_bold_is_bright'):
|
||||||
|
|
|
@ -361,3 +361,36 @@ def display_manager():
|
||||||
return 'WAYLAND'
|
return 'WAYLAND'
|
||||||
# Fallback assumption of X11
|
# Fallback assumption of X11
|
||||||
return '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))
|
||||||
|
|
Loading…
Reference in New Issue