Ignore:
Timestamp:
05/13/12 07:52:31 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Checklist saving/restoring and editing is implemented

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/config.py

    r166 r175  
    5252#-------------------------------------------------------------------------------
    5353
     54class Checklist(object):
     55    """A checklist for a certain aircraft type."""
     56    # The name of the section of the checklists
     57    SECTION="checklists"
     58   
     59    @staticmethod
     60    def fromConfig(config, aircraftType):
     61        """Create a checklist for the given aircraft type from the given
     62        config."""
     63        baseName = "checklist." + const.icaoCodes[aircraftType] + "."
     64        fileList = []
     65        while True:
     66            option = baseName + str(len(fileList))
     67            if config.has_option(Checklist.SECTION, option):
     68                fileList.append(config.get(Checklist.SECTION, option))
     69            else:
     70                break
     71
     72        return Checklist(fileList)
     73
     74    def __init__(self, fileList = None):
     75        """Construct the check list with the given file list."""
     76        self._fileList = [] if fileList is None else fileList[:]
     77
     78    def clone(self):
     79        """Clone the checklist."""
     80        return Checklist(self._fileList)
     81
     82    def toConfig(self, config, aircraftType):
     83        """Add this checklist to the given config."""
     84        baseName = "checklist." + const.icaoCodes[aircraftType] + "."
     85        for index in range(0, len(self._fileList)):
     86            option = baseName + str(index)
     87            config.set(Checklist.SECTION, option,
     88                       self._fileList[index])
     89
     90    def __eq__(self, other):
     91        """Determine if the checklist is equal to the given other one."""
     92        return self._fileList == other._fileList
     93
     94    def __len__(self):
     95        """Get the length of the file list."""
     96        return len(self._fileList)
     97
     98    def __getitem__(self, index):
     99        """Get the file with the given index."""
     100        return self._fileList[index]
     101
     102    def __iter__(self):
     103        """Iterate over the files."""
     104        return iter(self._fileList)
     105
     106#-------------------------------------------------------------------------------
     107
    54108class Config(object):
    55109    """Our configuration."""
     
    89143
    90144        self._messageTypeLevels = {}
     145
     146        self._checklists = {}
     147        for aircraftType in const.aircraftTypes:
     148            self._checklists[aircraftType] = Checklist()
    91149       
    92150        self._modified = False
     
    344402        if updateURL!=self._updateURL:
    345403            self._updateURL = updateURL
     404            self._modified = True
     405
     406    def getChecklist(self, aircraftType):
     407        """Get the checklist for the given aircraft type."""
     408        return self._checklists[aircraftType]
     409
     410    def setChecklist(self, aircraftType, checklist):
     411        """Set the checklist for the given aircraft type."""
     412        if checklist!=self._checklists[aircraftType]:
     413            self._checklists[aircraftType] = checklist.clone()
    346414            self._modified = True
    347415
     
    399467                                    Config.DEFAULT_UPDATE_URL)
    400468
     469        for aircraftType in const.aircraftTypes:
     470            self._checklists[aircraftType] = \
     471                Checklist.fromConfig(config, aircraftType)
     472
    401473        self._modified = False
    402474
     
    459531                   "yes" if self._autoUpdate else "no")
    460532        config.set("update", "url", self._updateURL)
     533
     534        config.add_section(Checklist.SECTION)
     535        for aircraftType in const.aircraftTypes:
     536            self._checklists[aircraftType].toConfig(config, aircraftType)
    461537
    462538        try:
Note: See TracChangeset for help on using the changeset viewer.