Ignore:
Timestamp:
02/26/11 04:05:23 (8 years ago)
Author:
aspidites
Message:

Patch by Aspidites:

  • started integrating settings.py into current modules.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/active/character_customization/game/parpg/settings.py

    r746 r747  
    7878            @param option: name of the option whose value is being requested 
    7979        """ 
    80         return self.__dict__[option] 
     80        try: 
     81            return self.__dict__[option] 
     82        except KeyError: 
     83            return None 
    8184 
    8285    def options(self): 
     
    8790            options.pop('name') 
    8891 
    89         return options 
    90  
    91 #TODO: remember config filenames 
    92 #TODO: remove hard-coded settings filename 
     92        return options.keys() 
     93 
     94#TODO: remember config filenames/paths 
     95#TODO: remove hard-coded settings filename/path 
    9396class Settings(object): 
    9497    """ An object that represents a settings file, its sectons, 
     
    116119        self.config_file = '' 
    117120 
    118         if len(filenames) == 0: 
    119             self.filenames = self.defaultPaths() 
     121        if hasattr(filenames, 'split'): 
     122            self.read(filenames) 
    120123        else: 
    121             self.filenames = filenames 
    122  
    123         if hasattr(self.filenames, 'split'): 
    124             self.read(self.filenames) 
    125         else: 
    126             for filename in self.filenames: 
     124            for filename in filenames: 
    127125                self.read(filename) 
    128126 
     
    209207 
    210208    # backward compatibility methods 
    211     def get(self, section, option): 
     209    def get(self, section, option, default=None): 
    212210        """ Returns the value of the requested option located in the 
    213211            requested section. 
     
    220218            @param option: the option being requested 
    221219            @type section: string 
    222         """ 
    223         return getattr(getattr(self, section), option) 
     220            @param default: the default value to return if a section's option 
     221                is not defined 
     222            @type section: any valid object 
     223        """ 
     224        value = getattr(getattr(self, section), option) 
     225        if value is None and default is not None: 
     226            return default 
     227        else: 
     228            return value 
    224229 
    225230    def getScreenWidth(self): 
     
    228233    def getScreenHeight(self): 
    229234        return self.FIFE.ScreenHeight 
    230  
    231 if __name__ == '__main__': 
    232     a = Settings() 
    233     a = Settings('test.ini', 'test2.ini') 
Note: See TracChangeset for help on using the changeset viewer.