Add file watching support to ValuestoreRC. Also slightly improve a debug statement in the root config class

This commit is contained in:
Chris Jones 2008-10-23 23:29:26 +01:00
parent 8ff0dfa72a
commit 9c75e20492
2 changed files with 67 additions and 40 deletions

View File

@ -34,6 +34,7 @@ up, set a default for it first."""
import os, platform, sys, re import os, platform, sys, re
import pwd import pwd
import gtk, pango import gtk, pango
import gio
# set this to true to enable debugging output # set this to true to enable debugging output
# These should be moved somewhere better. # These should be moved somewhere better.
@ -183,8 +184,9 @@ class TerminatorConfValuestore:
# Our settings # Our settings
def __getitem__ (self, keyname): def __getitem__ (self, keyname):
if self.values.has_key (keyname): if self.values.has_key (keyname):
dbg ("Returning '%s'"%keyname) value = self.values[keyname]
return self.values[keyname] dbg ("Returning '%s':'%s'"%(keyname, value))
return value
else: else:
dbg ("Failed to find '%s'"%keyname) dbg ("Failed to find '%s'"%keyname)
raise (KeyError) raise (KeyError)
@ -197,8 +199,6 @@ class TerminatorConfValuestoreDefault (TerminatorConfValuestore):
class TerminatorConfValuestoreRC (TerminatorConfValuestore): class TerminatorConfValuestoreRC (TerminatorConfValuestore):
rcfilename = "" rcfilename = ""
type = "RCFile" type = "RCFile"
#FIXME: use inotify to watch the rc, split __init__ into a parsing function
# that can be re-used when rc changes.
def __init__ (self): def __init__ (self):
try: try:
directory = os.environ['XDG_CONFIG_HOME'] directory = os.environ['XDG_CONFIG_HOME']
@ -207,11 +207,35 @@ class TerminatorConfValuestoreRC (TerminatorConfValuestore):
directory = os.path.join (os.path.expanduser("~"), ".config") directory = os.path.join (os.path.expanduser("~"), ".config")
self.rcfilename = os.path.join(directory, "terminator/config") self.rcfilename = os.path.join(directory, "terminator/config")
dbg(" VS_RCFile: config file located at %s" % self.rcfilename) dbg(" VS_RCFile: config file located at %s" % self.rcfilename)
if os.path.exists (self.rcfilename): self.call_parser(True)
monfile = gio.File(self.rcfilename)
monmon = monfile.monitor_file()
monmon.connect("changed", self.file_changed)
def set_reconfigure_callback (self, function):
dbg (" VS_RCFile: setting callback to: %s"%function)
self.reconfigure_callback = function
return (True)
def file_changed (self, monitor, file, unknown, event):
if event == gio.FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
print "VS_RCFile: config file changed, reload"
self.values = {}
self.call_parser()
self.reconfigure_callback()
def call_parser (self, is_init = False):
dbg (" VS_RCFile: parsing config file")
if not os.path.exists (self.rcfilename):
err (" VS_RCFile: %s does not exist" % self.rcfilename)
ini = ConfigFile(self.rcfilename, self._rc_set_callback()) ini = ConfigFile(self.rcfilename, self._rc_set_callback())
try: try:
ini.parse() ini.parse()
except ParsedWithErrors, e: except ParsedWithErrors, e:
# We don't really want to produce an error dialog every run
if not is_init:
pass
msg = _("""<big><b>Configuration error</b></big> msg = _("""<big><b>Configuration error</b></big>
Errors were encountered while parsing terminator_config(5) file: Errors were encountered while parsing terminator_config(5) file:

View File

@ -106,7 +106,10 @@ class Terminator:
self.term_list = [] self.term_list = []
self.gnome_client = None self.gnome_client = None
stores = [] stores = []
stores.append (config.TerminatorConfValuestoreRC ())
store = config.TerminatorConfValuestoreRC ()
store.set_reconfigure_callback (self.reconfigure_vtes)
stores.append (store)
self._tab_reorderable = True self._tab_reorderable = True
if not hasattr(gtk.Notebook, "set_tab_reorderable") or not hasattr(gtk.Notebook, "get_tab_reorderable"): if not hasattr(gtk.Notebook, "set_tab_reorderable") or not hasattr(gtk.Notebook, "get_tab_reorderable"):