This commit converts the whole config file management to yaml.
Everything still works like before except ladimenu, ladimenu does not *ever* get to create a config object ! Ladimenu's config is passed uppon manager object creation as a parameter, and saved by the parrent app.
This commit is contained in:
parent
3a971c8f29
commit
c955d77564
25
ladilog
25
ladilog
|
@ -34,7 +34,7 @@ try:
|
|||
import vte
|
||||
import laditools
|
||||
except Exception, e:
|
||||
error = gtk.MessageDialog (None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "Wow dude...\n\nYou really need to get you dependencies right before you run this program. Ask your package maintainer why he didn't do his job properly\n%s" % repr(e))
|
||||
error = gtk.MessageDialog (None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "You need to get you dependencies right before you run this program. Ask your package maintainer why this is happening to you\n%s" % repr(e))
|
||||
error.run ()
|
||||
exit (1)
|
||||
|
||||
|
@ -85,18 +85,22 @@ class ladilog (gtk.glade.XML):
|
|||
]
|
||||
|
||||
# Handle the configuration
|
||||
self.jacklog_config = laditools.config ()
|
||||
self.param_dict = self.jacklog_config.get_as_dict ('ladilog')
|
||||
self.global_config = laditools.config ()
|
||||
self.param_dict = self.global_config.get_config_section ('ladilog')
|
||||
|
||||
for log in self.log_files:
|
||||
if log['config_name'] not in self.param_dict:
|
||||
self.param_dict[log['config_name']] = log['config_default'], {}
|
||||
for log in self.log_files:
|
||||
if self.param_dict != None:
|
||||
if log['config_name'] not in self.param_dict:
|
||||
self.param_dict[log['config_name']] = log['config_default']
|
||||
else:
|
||||
self.param_dict = {}
|
||||
self.param_dict[log['config_name']] = log['config_default']
|
||||
|
||||
if 'max_lines' not in self.param_dict:
|
||||
self.param_dict['max_lines'] = max_lines_default, {}
|
||||
self.param_dict['max_lines'] = max_lines_default
|
||||
|
||||
for log in self.log_files:
|
||||
log['logfile_path'], devnull = self.param_dict[log['config_name']]
|
||||
log['logfile_path'] = self.param_dict[log['config_name']]
|
||||
# skip logfiles that dont exist
|
||||
if not os.access(log['logfile_path'], os.R_OK):
|
||||
self.log_files.remove(log)
|
||||
|
@ -104,7 +108,7 @@ class ladilog (gtk.glade.XML):
|
|||
else:
|
||||
print "Watching '%s'" % log['logfile_path']
|
||||
|
||||
max_lines_text, devnull = self.param_dict['max_lines']
|
||||
max_lines_text = self.param_dict['max_lines']
|
||||
self.max_lines = int (max_lines_text)
|
||||
# Load the glade file
|
||||
gtk.glade.XML.__init__(self, laditools.find_data_file("ladilog_ui.glade"))
|
||||
|
@ -171,7 +175,8 @@ class ladilog (gtk.glade.XML):
|
|||
|
||||
def run (self):
|
||||
gtk.main ()
|
||||
self.jacklog_config.set_as_dict ("ladilog", self.param_dict)
|
||||
self.global_config.set_config_section ("ladilog", self.param_dict)
|
||||
self.global_config.save ()
|
||||
return 0
|
||||
|
||||
try:
|
||||
|
|
30
laditray
30
laditray
|
@ -29,13 +29,13 @@ autostart_default = False
|
|||
class laditray (gtk.StatusIcon, laditools.manager):
|
||||
def __init__ (self):
|
||||
# Handle the configuration
|
||||
self.laditray_config = laditools.config ()
|
||||
self.param_dict = self.laditray_config.get_as_dict ('laditray')
|
||||
if 'autostart' not in self.param_dict:
|
||||
self.param_dict['autostart'] = autostart_default
|
||||
autostart = self.param_dict['autostart']
|
||||
self.global_config = laditools.config ()
|
||||
self.laditray_param_dict = self.global_config.get_config_section ('laditray')
|
||||
if 'autostart' not in self.laditray_param_dict:
|
||||
self.laditray_param_dict['autostart'] = autostart_default
|
||||
autostart = self.laditray_param_dict['autostart']
|
||||
# Build the UI
|
||||
laditools.manager.__init__(self, autostart)
|
||||
laditools.manager.__init__(self, self.global_config.get_config_section ('ladimenu'), autostart)
|
||||
gtk.StatusIcon.__init__ (self)
|
||||
self.icon_state = ""
|
||||
self.last_status_text = ""
|
||||
|
@ -102,12 +102,16 @@ class laditray (gtk.StatusIcon, laditools.manager):
|
|||
|
||||
def run(self):
|
||||
gtk.main ()
|
||||
self.laditray_config.set_as_dict ('laditray', self.param_dict)
|
||||
# Some default config might need to be injected in the config file,
|
||||
# we handle all that before we quit.
|
||||
self.global_config.set_config_section ('ladimenu', self.menu_array)
|
||||
self.global_config.set_config_section ('laditray', self.laditray_param_dict)
|
||||
self.global_config.save ()
|
||||
return 0
|
||||
|
||||
#try:
|
||||
laditray().run()
|
||||
#except Exception, e:
|
||||
# error = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "Unexpected error\n\n" + repr(e))
|
||||
# error.run()
|
||||
# exit(1)
|
||||
try:
|
||||
laditray().run()
|
||||
except Exception, e:
|
||||
error = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "Unexpected error\n\n" + repr(e))
|
||||
error.run()
|
||||
exit(1)
|
||||
|
|
|
@ -21,44 +21,34 @@ from os import environ, sep, mkdir
|
|||
from os.path import exists
|
||||
config_dir = environ['HOME'] + sep + ".config" + sep + "laditools" + sep
|
||||
config_filename = config_dir + "laditools.conf"
|
||||
if not exists(config_dir):
|
||||
mkdir(config_dir, 0755)
|
||||
if not exists (config_dir):
|
||||
mkdir (config_dir, 0755)
|
||||
|
||||
# Note to users of the config class. Only applications should create an instance
|
||||
# of the config object. The ladimenu is *NOT* an application...
|
||||
class config:
|
||||
def __init__(self):
|
||||
def __init__ (self):
|
||||
try:
|
||||
self.appdict = yaml.load(config_filename)
|
||||
config_file = open (config_filename)
|
||||
self.appdict = yaml.load (config_file)
|
||||
config_file.close ()
|
||||
except:
|
||||
self.appdict = {}
|
||||
print "Config file doesn't exist, creating a new one..."
|
||||
self.appdict = dict ()
|
||||
|
||||
# Use this to create the dictionary that you'll use in your application
|
||||
# You can add remove any parameters you wish from it, it'll get saved magically
|
||||
def get_as_dict(self, app_name):
|
||||
# Returns the section named <app_name> from the global config
|
||||
def get_config_section (self, app_name):
|
||||
if app_name in self.appdict:
|
||||
return self.appdict[app_name]
|
||||
else:
|
||||
return {}
|
||||
return None
|
||||
|
||||
# Use this to create the array that you'll use in your application
|
||||
# The array is used when you want to take into account the order the items are listed in the file
|
||||
# You can add remove any parameters you wish from it, it'll get saved magically
|
||||
def get_as_array(self, app_name):
|
||||
if app_name in self.appdict:
|
||||
return self.appdict[app_name]
|
||||
else:
|
||||
return []
|
||||
|
||||
# Use this when you want to update the yaml config with the content of the dictionary
|
||||
def set_as_dict(self, app_name, param_dict):
|
||||
# Saves the section named <app_name> into the global config
|
||||
def set_config_section (self, app_name, param_dict):
|
||||
self.appdict[app_name] = param_dict
|
||||
self.save()
|
||||
|
||||
# Use this when you want to update the yaml config with the content of the array
|
||||
def set_as_array(self, app_name, param_array):
|
||||
self.appdict[app_name] = param_array
|
||||
self.save()
|
||||
|
||||
# Use this when you want to write the config file to disk
|
||||
def save(self):
|
||||
config_file = open(config_filename, 'w')
|
||||
yaml.dump(self.appdict, config_file)
|
||||
# This writes the config file to the disk
|
||||
def save (self):
|
||||
config_file = open (config_filename, 'w')
|
||||
yaml.dump (self.appdict, config_file)
|
||||
config_file.close ()
|
||||
|
|
|
@ -34,25 +34,24 @@ menu_default = [("Configure...", "ladiconf"),
|
|||
("Logs...", "ladilog")]
|
||||
|
||||
class manager:
|
||||
def __init__(self, jack_autostart = False):
|
||||
def __init__(self, menu_config_array, jack_autostart = False):
|
||||
self.proxy_jack_controller = None
|
||||
self.proxy_jack_configure = None
|
||||
self.proxy_a2j_controller = None
|
||||
self.proxy_ladish_controller = None
|
||||
self.diagnose_text = ""
|
||||
# Handle the configuration and grab custom menu items
|
||||
self.ladimenu_config = config()
|
||||
self.menu_array = self.ladimenu_config.get_as_array('ladimenu')
|
||||
self.menu_array = menu_config_array
|
||||
# Add some defaults if we don't already have a menu
|
||||
if self.menu_array == []:
|
||||
if self.menu_array == None:
|
||||
self.menu_array = []
|
||||
for element in menu_default:
|
||||
self.menu_array.append(element)
|
||||
self.ladimenu_config.set_as_array('ladimenu', self.menu_array, 'menuitem')
|
||||
|
||||
self.proc_list = []
|
||||
|
||||
if jack_autostart:
|
||||
self.jack_start()
|
||||
self.jack_start ()
|
||||
|
||||
def set_diagnose_text(self, text):
|
||||
self.diagnose_text = text
|
||||
|
@ -62,7 +61,6 @@ class manager:
|
|||
|
||||
def get_jack_controller(self):
|
||||
if not self.proxy_jack_controller:
|
||||
#print "creating jack proxy"
|
||||
self.proxy_jack_controller = jack_controller()
|
||||
return self.proxy_jack_controller
|
||||
|
||||
|
@ -75,7 +73,6 @@ class manager:
|
|||
return self.proxy_jack_configure
|
||||
|
||||
def clear_jack_proxies(self):
|
||||
#print "clearing jack proxies"
|
||||
self.proxy_jack_controller = None
|
||||
self.proxy_jack_configure = None
|
||||
|
||||
|
@ -107,27 +104,21 @@ class manager:
|
|||
self.get_jack_controller().reset_xruns()
|
||||
|
||||
def jack_is_started(self):
|
||||
#print "jack_is_started"
|
||||
return self.get_jack_controller().is_started()
|
||||
|
||||
def jack_is_realtime(self):
|
||||
#print "jack_is_realtime"
|
||||
return self.get_jack_controller().is_realtime()
|
||||
|
||||
def jack_get_load(self):
|
||||
#print "jack_get_load"
|
||||
return self.get_jack_controller().get_load()
|
||||
|
||||
def jack_get_xruns(self):
|
||||
#print "jack_get_xruns"
|
||||
return self.get_jack_controller().get_xruns()
|
||||
|
||||
def jack_get_sample_rate(self):
|
||||
#print "jack_get_sample_rate"
|
||||
return self.get_jack_controller().get_sample_rate()
|
||||
|
||||
def jack_get_latency(self):
|
||||
#print "jack_get_latency"
|
||||
return self.get_jack_controller().get_latency()
|
||||
|
||||
def get_a2j_controller(self):
|
||||
|
@ -297,8 +288,8 @@ class manager:
|
|||
menu_items.append((gtk.ImageMenuItem("Start gladish"), self.on_menu_launcher, "gladish"))
|
||||
|
||||
# Add the laucher entries at the beginning of the menu
|
||||
for path, attrib_dict in self.menu_array:
|
||||
menu_items.append((gtk.ImageMenuItem(attrib_dict['name']), self.on_menu_launcher, path))
|
||||
for menu_label, path in self.menu_array:
|
||||
menu_items.append((gtk.ImageMenuItem(menu_label), self.on_menu_launcher, path))
|
||||
|
||||
menu = gtk.Menu()
|
||||
menu_items.append((gtk.SeparatorMenuItem(),))
|
||||
|
|
17
wmladi
17
wmladi
|
@ -32,21 +32,21 @@ import gobject
|
|||
autostart_default = 0
|
||||
debug = False
|
||||
|
||||
class wmjackctl (wmoo.Application, laditools.manager):
|
||||
class wmladi (wmoo.Application, laditools.manager):
|
||||
def __init__ (self):
|
||||
# Handle the configuration
|
||||
self.wmjackctl_config = laditools.config ()
|
||||
self.param_dict = self.wmjackctl_config.get_as_dict ('wmjackctl')
|
||||
self.global_config = laditools.config ()
|
||||
self.param_dict = self.global_config.get_config_setion ('wmladi')
|
||||
if 'autostart' not in self.param_dict:
|
||||
self.param_dict['autostart'] = str (autostart_default), {}
|
||||
autostart, devnull = self.param_dict['autostart']
|
||||
self.param_dict['autostart'] = str (autostart_default)
|
||||
autostart = self.param_dict['autostart']
|
||||
wmoo.Application.__init__ (
|
||||
self,
|
||||
#background = os.path.dirname(sys.argv[0]) + os.sep + "wmjackctl.xpm",
|
||||
margin = 2,
|
||||
debug = False)
|
||||
|
||||
laditools.manager.__init__(self, int(autostart))
|
||||
laditools.manager.__init__(self, self.global_config.get_config_setion ('ladimenu'), int(autostart))
|
||||
|
||||
self.addCallback (self.on_button_release, 'buttonrelease', area=(0,0,64,64))
|
||||
|
||||
|
@ -197,6 +197,7 @@ class wmjackctl (wmoo.Application, laditools.manager):
|
|||
|
||||
def run (self):
|
||||
self.run_gtk ()
|
||||
self.wmjackctl_config.set_as_dict ('wmjackctl', self.param_dict)
|
||||
self.global_config.set_config_section ('wmladi', self.param_dict)
|
||||
self.global_config.save ()
|
||||
|
||||
wmjackctl ().run ()
|
||||
wmladi ().run ()
|
||||
|
|
Loading…
Reference in New Issue