Add file watching support to ValuestoreRC. Also slightly improve a debug statement in the root config class
This commit is contained in:
parent
8ff0dfa72a
commit
9c75e20492
|
@ -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,12 +207,36 @@ 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)
|
||||||
ini = ConfigFile(self.rcfilename, self._rc_set_callback())
|
|
||||||
try:
|
monfile = gio.File(self.rcfilename)
|
||||||
ini.parse()
|
monmon = monfile.monitor_file()
|
||||||
except ParsedWithErrors, e:
|
monmon.connect("changed", self.file_changed)
|
||||||
msg = _("""<big><b>Configuration error</b></big>
|
|
||||||
|
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())
|
||||||
|
try:
|
||||||
|
ini.parse()
|
||||||
|
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>
|
||||||
|
|
||||||
Errors were encountered while parsing terminator_config(5) file:
|
Errors were encountered while parsing terminator_config(5) file:
|
||||||
|
|
||||||
|
@ -220,41 +244,41 @@ Errors were encountered while parsing terminator_config(5) file:
|
||||||
|
|
||||||
%d line(s) have been ignored.""") % (self.rcfilename, len(e.errors))
|
%d line(s) have been ignored.""") % (self.rcfilename, len(e.errors))
|
||||||
|
|
||||||
dialog = gtk.Dialog(_("Configuration error"), None, gtk.DIALOG_MODAL,
|
dialog = gtk.Dialog(_("Configuration error"), None, gtk.DIALOG_MODAL,
|
||||||
(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
|
(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
|
||||||
dialog.set_has_separator(False)
|
dialog.set_has_separator(False)
|
||||||
dialog.set_resizable(False)
|
dialog.set_resizable(False)
|
||||||
|
|
||||||
image = gtk.image_new_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG)
|
image = gtk.image_new_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG)
|
||||||
image.set_alignment (0.5, 0)
|
image.set_alignment (0.5, 0)
|
||||||
dmsg = gtk.Label(msg)
|
dmsg = gtk.Label(msg)
|
||||||
dmsg.set_use_markup(True)
|
dmsg.set_use_markup(True)
|
||||||
dmsg.set_alignment(0, 0.5)
|
dmsg.set_alignment(0, 0.5)
|
||||||
|
|
||||||
textbuff = gtk.TextBuffer()
|
textbuff = gtk.TextBuffer()
|
||||||
textbuff.set_text("\n".join(map(lambda e: str(e), e.errors)))
|
textbuff.set_text("\n".join(map(lambda e: str(e), e.errors)))
|
||||||
textview = gtk.TextView(textbuff)
|
textview = gtk.TextView(textbuff)
|
||||||
textview.set_editable(False)
|
textview.set_editable(False)
|
||||||
|
|
||||||
textview.modify_font(pango.FontDescription(Defaults['font']))
|
textview.modify_font(pango.FontDescription(Defaults['font']))
|
||||||
textscroll = gtk.ScrolledWindow()
|
textscroll = gtk.ScrolledWindow()
|
||||||
textscroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
textscroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
||||||
textscroll.add(textview)
|
textscroll.add(textview)
|
||||||
# This should be scaled with the size of the text and font
|
# This should be scaled with the size of the text and font
|
||||||
textscroll.set_size_request(600, 200)
|
textscroll.set_size_request(600, 200)
|
||||||
|
|
||||||
root = gtk.VBox()
|
root = gtk.VBox()
|
||||||
root.pack_start(dmsg, padding = 6)
|
root.pack_start(dmsg, padding = 6)
|
||||||
root.pack_start(textscroll, padding = 6)
|
root.pack_start(textscroll, padding = 6)
|
||||||
|
|
||||||
box = gtk.HBox()
|
box = gtk.HBox()
|
||||||
box.pack_start (image, False, False, 6)
|
box.pack_start (image, False, False, 6)
|
||||||
box.pack_start (root, False, False, 6)
|
box.pack_start (root, False, False, 6)
|
||||||
dialog.vbox.pack_start (box, False, False, 12)
|
dialog.vbox.pack_start (box, False, False, 12)
|
||||||
dialog.show_all()
|
dialog.show_all()
|
||||||
|
|
||||||
dialog.run()
|
dialog.run()
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
dbg("ConfigFile settings are: %s" % repr(self.values))
|
dbg("ConfigFile settings are: %s" % repr(self.values))
|
||||||
|
|
||||||
|
|
|
@ -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"):
|
||||||
|
|
Loading…
Reference in New Issue