From 8a09e1ccdab7e47780780761c3ea8355ca7ded60 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Tue, 20 Oct 1998 20:45:46 +0000 Subject: Saving/Restoring state into ~/.pynche file --- Tools/pynche/Switchboard.py | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'Tools/pynche/Switchboard.py') diff --git a/Tools/pynche/Switchboard.py b/Tools/pynche/Switchboard.py index 4286b486bb..7ac3df11b4 100644 --- a/Tools/pynche/Switchboard.py +++ b/Tools/pynche/Switchboard.py @@ -12,13 +12,32 @@ conform to the following interface: since this would cause it to get updated twice. """ +from types import DictType +import marshal + class Switchboard: - def __init__(self, colordb): - self.__views = [] + def __init__(self, colordb, initfile): self.__colordb = colordb + self.__optiondb = {} + self.__views = [] self.__red = 0 self.__green = 0 self.__blue = 0 + # read the initialization file + fp = None + if initfile: + try: + try: + fp = open(initfile) + self.__optiondb = marshal.load(fp) + if type(self.__optiondb) <> DictType: + print 'Problem reading options from file:', initfile + self.__optiondb = {} + except (IOError, EOFError): + pass + finally: + if fp: + fp.close() def add_view(self, view): self.__views.append(view) @@ -38,3 +57,25 @@ class Switchboard: def colordb(self): return self.__colordb + + def optiondb(self): + return self.__optiondb + + def save_views(self, file): + # save the current color + self.__optiondb['RED'] = self.__red + self.__optiondb['GREEN'] = self.__green + self.__optiondb['BLUE'] = self.__blue + for v in self.__views: + v.save_options(self.__optiondb) + fp = None + try: + try: + fp = open(file, 'w') + except IOError: + print 'Cannot write options to file:', file + else: + marshal.dump(self.__optiondb, fp) + finally: + if fp: + fp.close() -- cgit v1.2.1