Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to configure cell width (font character spacing) #552

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions terminatorlib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
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

Expand Down Expand Up @@ -113,7 +113,8 @@
'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,
Expand Down Expand Up @@ -244,7 +245,8 @@
'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,
Expand Down Expand Up @@ -507,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"""
Expand Down Expand Up @@ -626,6 +629,14 @@ def load(self):
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:
Expand Down
88 changes: 80 additions & 8 deletions terminatorlib/preferences.glade
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand All @@ -959,25 +966,25 @@
</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>
<property name="top-attach">4</property>
</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>
Expand All @@ -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>
Expand Down
48 changes: 37 additions & 11 deletions terminatorlib/prefseditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,27 @@ def set_values(self):
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')
Expand Down Expand Up @@ -1252,16 +1266,28 @@ def on_handlesize_value_changed(self, widget):
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['cell_height'] = value
self.config.save()
guiget = self.builder.get_object
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['line_height'] = value
self.config['cell_width'] = value
self.config.save()
guiget = self.builder.get_object
label_widget = guiget('lineheight_value_label')
label_widget = guiget('cellwidth_value_label')
label_widget.set_text(str(value))

def on_focuscombo_changed(self, widget):
Expand Down
4 changes: 3 additions & 1 deletion terminatorlib/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,9 @@ def reconfigure(self, _widget=None):
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'])

Expand Down
33 changes: 33 additions & 0 deletions terminatorlib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))