/[ascend]/trunk/pygtk/interface/preferences.py
ViewVC logotype

Annotation of /trunk/pygtk/interface/preferences.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 132 - (hide annotations) (download) (as text)
Wed Dec 21 00:14:13 2005 UTC (14 years, 10 months ago) by johnpye
File MIME type: text/x-python
File size: 1564 byte(s)
Adding the PyGTK interface to CMU repository. Whaddyareckon?
1 johnpye 132 # Preferences module for ASCPY.
2    
3     import ConfigParser, os
4    
5     class Preferences:
6     __sharedstate = {}
7    
8     def __init__(self):
9     self.__dict__ = self.__sharedstate
10    
11     if not hasattr(self,'n'):
12     self.n = 0;
13     self.fname = os.path.expanduser("~/.ascend.ini");
14     self.n = self.n + 1;
15    
16     if not hasattr(self,'ini'):
17     print "CREATING CONFIG"
18     self.ini = ConfigParser.SafeConfigParser();
19     self.ini.read( [ self.fname ] );
20    
21     def __del__(self):
22     self.n = self.n - 1;
23     if self.n==0:
24     print "WRITING CONFIG to",self.fname
25     f = open(self.fname, "w");
26     self.ini.write( f );
27    
28     def getPreferredUnits(self,key):
29     try:
30     _u = self.ini.get("PreferredUnits",key);
31     except ConfigParser.NoSectionError:
32     return None;
33     except ConfigParser.NoOptionError:
34     return None;
35     return _u;
36    
37     def setPreferredUnits(self,key,val):
38     if not self.ini.has_section("PreferredUnits"):
39     self.ini.add_section("PreferredUnits")
40     self.ini.set("PreferredUnits",key,val)
41     #print "SET PREFERRED UNITS FOR %s TO %s" % ( key, val )
42    
43     # Test script:
44     def main():
45     x = Preferences();
46     y = Preferences();
47    
48     print "Units for length: ",x.getPreferredUnits("length");
49     print "Units for time: ",x.getPreferredUnits("time");
50    
51     x.setPreferredUnits("length","m");
52     y.setPreferredUnits("time","hr");
53     print "Units for length: ",y.getPreferredUnits("length");
54     print "Units for time: ",y.getPreferredUnits("time");
55    
56     print "About to delete x"
57     del x;
58     print "Deleted x"
59    
60     y.setPreferredUnits("length","cm");
61    
62     print "About to delete y"
63     del y;
64    
65     print "Deleted y"
66    
67     if __name__ == "__main__":
68     main()

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22