Merge pull request #552 from FernandoBasso/feat/configure-cell-width
Add ability to configure cell width (font character spacing)
This commit is contained in:
commit
8f13beffbf
@ -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,8 @@ 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,
|
||||
'link_single_click' : False,
|
||||
@ -245,7 +246,8 @@ 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,
|
||||
'cycle_term_tab' : True,
|
||||
@ -506,6 +508,7 @@ class ConfigBase(Borg):
|
||||
plugins = None
|
||||
layouts = None
|
||||
command_line_options = None
|
||||
config_file_updated_to_cell_height = False
|
||||
|
||||
def __init__(self):
|
||||
"""Class initialiser"""
|
||||
@ -625,6 +628,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:
|
||||
|
@ -340,7 +340,14 @@
|
||||
<property name="step-increment">0.10</property>
|
||||
<property name="page-increment">0.20</property>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="adjustment_lineheight">
|
||||
<object class="GtkAdjustment" id="adjustment_cellheight">
|
||||
<property name="lower">1</property>
|
||||
<property name="upper">2</property>
|
||||
<property name="value">1</property>
|
||||
<property name="step-increment">0.10</property>
|
||||
<property name="page-increment">0.20</property>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="adjustment_cellwidth">
|
||||
<property name="lower">1</property>
|
||||
<property name="upper">2</property>
|
||||
<property name="value">1</property>
|
||||
@ -880,7 +887,7 @@
|
||||
<property name="spacing">36</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<child>
|
||||
<!-- n-columns=3 n-rows=5 -->
|
||||
<!-- n-columns=3 n-rows=6 -->
|
||||
<object class="GtkGrid" id="grid3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
@ -947,10 +954,10 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="line_height_label">
|
||||
<object class="GtkLabel" id="cell_height_label">
|
||||
<property name="visible">True</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>
|
||||
</object>
|
||||
<packing>
|
||||
@ -959,17 +966,17 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScale" id="lineheight">
|
||||
<object class="GtkScale" id="cellheight">
|
||||
<property name="width-request">100</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="halign">baseline</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="draw-value">False</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>
|
||||
<packing>
|
||||
<property name="left-attach">2</property>
|
||||
@ -977,7 +984,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="lineheight_value_label">
|
||||
<object class="GtkLabel" id="cellheight_value_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label">1.0</property>
|
||||
@ -992,6 +999,71 @@
|
||||
<property name="top-attach">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScale" id="handlewidth">
|
||||
<property name="width-request">100</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="halign">baseline</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="adjustment">adjustment1</property>
|
||||
<property name="round-digits">0</property>
|
||||
<property name="digits">0</property>
|
||||
<property name="draw-value">False</property>
|
||||
<property name="value-pos">bottom</property>
|
||||
<signal name="value-changed" handler="on_handlewidth_value_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">2</property>
|
||||
<property name="top-attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="cell_width_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label" translatable="yes">Cell Width:</property>
|
||||
<property name="xalign">0</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">5</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScale" id="cellwidth">
|
||||
<property name="width-request">100</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="halign">baseline</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="adjustment">adjustment_cellwidth</property>
|
||||
<property name="round-digits">1</property>
|
||||
<property name="draw-value">False</property>
|
||||
<property name="value-pos">bottom</property>
|
||||
<signal name="value-changed" handler="on_handlewidth_value_changed" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">2</property>
|
||||
<property name="top-attach">5</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="cellwidth_value_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="label">1.0</property>
|
||||
<property name="justify">right</property>
|
||||
<property name="width-chars">5</property>
|
||||
<property name="max-width-chars">5</property>
|
||||
<property name="lines">1</property>
|
||||
<property name="xalign">1</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">1</property>
|
||||
<property name="top-attach">5</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScale" id="inactive_color_offset">
|
||||
<property name="width-request">100</property>
|
||||
|
@ -256,13 +256,27 @@ 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
|
||||
#
|
||||
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')
|
||||
@ -1252,16 +1266,28 @@ 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):
|
||||
"""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):
|
||||
|
@ -705,7 +705,9 @@ 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'):
|
||||
self.vte.set_bold_is_bright(self.config['bold_is_bright'])
|
||||
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user