Skip to content

Commit

Permalink
Terminal: Use system font.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeanEYE committed May 16, 2020
1 parent fa8fb9e commit d357c83
Showing 1 changed file with 8 additions and 35 deletions.
43 changes: 8 additions & 35 deletions sunflower/plugin_base/terminal.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
from __future__ import absolute_import

import gi

try:
gi.require_version('GConf', '1.0')
from gi.repository import GConf
gconf_loaded = True
except:
gconf_loaded = False

gi.require_version('Vte', '2.91')

from gi.repository import Gtk, Gdk, Vte, Pango
from gi.repository import Gtk, Gdk, Gio, Vte, Pango
from sunflower.plugin_base.plugin import PluginBase
from sunflower.accelerator_group import AcceleratorGroup

Expand Down Expand Up @@ -39,6 +31,8 @@ class Terminal(PluginBase):
"""

FONT = None

def __init__(self, parent, notebook, options):
PluginBase.__init__(self, parent, notebook, options)

Expand Down Expand Up @@ -99,7 +93,7 @@ def __init__(self, parent, notebook, options):
# terminal container
if self._terminal_type == TerminalType.VTE:
self._container = Gtk.ScrolledWindow()
self._container.set_shadow_type(Gtk.ShadowType.IN)
self._container.set_shadow_type(Gtk.ShadowType.NONE)

# apply scrollbar visibility
show_scrollbars = section.get('show_scrollbars')
Expand All @@ -125,32 +119,11 @@ def __init__(self, parent, notebook, options):

def __set_system_font(self, client=None, *args, **kwargs):
"""Set system font to terminal"""
# TODO: Switch to using dconf
if not gconf_loaded:
return

path = '/desktop/gnome/interface'
key = '{0}/monospace_font_name'.format(path)

if client is None:
if not hasattr(self._terminal, 'client'):
# client wasn't assigned to widget, get default one and set events
client = GConf.Client.get_default()
client.add_dir(path, GConf.ClientPreloadType.PRELOAD_NONE)
client.notify_add(key, self.__set_system_font)
self._terminal.client = client

else:
# get assigned client
client = self._terminal.client

else:
# try to get font and set it
font_name = client.get_string(key)
if not self.FONT:
settings = Gio.Settings.new('org.gnome.desktop.interface')
self.FONT = Pango.FontDescription.from_string(settings.get_string('monospace-font-name'))

if font_name is not None:
font = Pango.FontDescription(font_name)
self._terminal.set_font(font_name)
self._terminal.set_font(self.FONT)

def _create_buttons(self):
"""Create titlebar buttons."""
Expand Down

0 comments on commit d357c83

Please sign in to comment.