Changeset 264:6fbadb22b2c3


Ignore:
Timestamp:
07/01/12 07:58:44 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

Started implementing the approach callout editor

Location:
src/mlx
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/config.py

    r249 r264  
    4242               self.key == other.key
    4343
     44    def __ne__(self, other):
     45        """Check if the given hotkey is not equal to the other one."""
     46        return not self==other
     47       
    4448    def __str__(self):
    4549        """Construct the hotkey to a string."""
     
    9296        return self._fileList == other._fileList
    9397
     98    def __ne__(self, other):
     99        """Determine if the checklist is not equal to the given other one."""
     100        return not self==other
     101       
    94102    def __len__(self):
    95103        """Get the length of the file list."""
     
    103111        """Iterate over the files."""
    104112        return iter(self._fileList)
     113
     114#-------------------------------------------------------------------------------
     115
     116class ApproachCallouts(object):
     117    """The approach callouts for a certain aircraft type."""
     118    # The name of the section of the approach callouts
     119    SECTION="callouts"
     120   
     121    @staticmethod
     122    def fromConfig(config, aircraftType):
     123        """Create a checklist for the given aircraft type from the given
     124        config."""
     125        baseName = "callouts." + const.icaoCodes[aircraftType] + "."
     126        mapping = {}
     127        while True:
     128            option = baseName + str(len(mapping))
     129            if config.has_option(ApproachCallouts.SECTION, option):
     130                value = config.get(ApproachCallouts.SECTION, option)
     131                (altitude, path) = value.split(",")
     132                altitude = int(altitude.strip())
     133                path = path.strip()
     134                mapping[altitude] = path
     135            else:
     136                break
     137
     138        return ApproachCallouts(mapping)   
     139
     140    def __init__(self, mapping = None):
     141        """Construct the check list with the given mapping of altitudes to
     142        files."""
     143        self._mapping = {} if mapping is None else mapping.copy()
     144
     145    def clone(self):
     146        """Clone the callout information."""
     147        return ApproachCallouts(self._mapping)
     148
     149    def toConfig(self, config, aircraftType):
     150        """Add this checklist to the given config."""
     151        baseName = "callouts." + const.icaoCodes[aircraftType] + "."
     152        index = 0
     153        for (altitude, path) in self._mapping.iteritems():
     154            option = baseName + str(index)
     155            config.set(ApproachCallouts.SECTION, option,
     156                       "%d, %s" % (altitude, path))
     157            index += 1
     158
     159    def __eq__(self, other):
     160        """Determine if the approach callout mapping is equal to the given
     161        other one."""
     162        return self._mapping == other._mapping
     163
     164    def __ne__(self, other):
     165        """Determine if the approach callout mapping is not equal to the given
     166        other one."""
     167        return not self==other
     168
     169    def __len__(self):
     170        """Get the number of elements in the mapping."""
     171        return len(self._mapping)
     172
     173    def __getitem__(self, altitude):
     174        """Get the file that is associated with the highest altitude not higher
     175        than the given one.
     176
     177        If no such file found, return None."""
     178        candidate = None
     179        for (alt, path) in self._mapping.iteritems():
     180            if alt<=altitude:
     181                if candidate is None or alt>candidate[0]:
     182                    candidate = (alt, path)
     183
     184        return candidate
     185
     186    def __iter__(self):
     187        """Iterate over the pairs of altitudes and paths in decreasing order of
     188        the altitude."""
     189        altitudes = self._mapping.keys()
     190        altitudes.sort(reverse = True)
     191
     192        for altitude in altitudes:
     193            yield (altitude, self._mapping[altitude])
    105194
    106195#-------------------------------------------------------------------------------
     
    137226        self._pilotHotkey = Hotkey(ctrl = True, shift = False, key = "0")
    138227
    139         #self._approachCallOuts = False
     228        self._enableApproachCallouts = False
    140229        self._speedbrakeAtTD = True
    141230
     
    149238
    150239        self._checklists = {}
     240        self._approachCallouts = {}
    151241        for aircraftType in const.aircraftTypes:
    152242            self._checklists[aircraftType] = Checklist()
    153        
     243            self._approachCallouts[aircraftType] = ApproachCallouts()
     244           
    154245        self._modified = False
    155246
     
    404495            self._modified = True
    405496
    406     # @property
    407     # def approachCallOuts(self):
    408     #     """Get whether the approach callouts should be played."""
    409     #     return self._approachCallOuts
    410 
    411     # @approachCallOuts.setter
    412     # def approachCallOuts(self, approachCallOuts):
    413     #     """Set whether the approach callouts should be played."""
    414     #     if approachCallOuts!=self._approachCallOuts:
    415     #         self._approachCallOuts = approachCallOuts
    416     #         self._modified = True
     497    @property
     498    def enableApproachCallouts(self):
     499        """Get whether the approach callouts should be played."""
     500        return self._enableApproachCallouts
     501
     502    @enableApproachCallouts.setter
     503    def enableApproachCallouts(self, enableApproachCallouts):
     504        """Set whether the approach callouts should be played."""
     505        if enableApproachCallouts!=self._enableApproachCallouts:
     506            self._enableApproachCallouts = enableApproachCallouts
     507            self._modified = True
    417508
    418509    @property
     
    484575        if checklist!=self._checklists[aircraftType]:
    485576            self._checklists[aircraftType] = checklist.clone()
     577            self._modified = True
     578
     579    def getApproachCallouts(self, aircraftType):
     580        """Get the approach callouts for the given aircraft type."""
     581        return self._approachCallouts[aircraftType]
     582
     583    def setApproachCallouts(self, aircraftType, approachCallouts):
     584        """Set the approach callouts for the given aircraft type."""
     585        if not approachCallouts==self._approachCallouts[aircraftType]:
     586            print "Updating approach callouts"
     587            self._approachCallouts[aircraftType] = approachCallouts.clone()
    486588            self._modified = True
    487589
     
    538640        self._pilotHotkey.set(self._get(config, "sounds",
    539641                                        "pilotHotkey", "C0"))
    540         #self._approachCallOuts = self._getBoolean(config, "sounds",
    541         #                                          "approachCallOuts", False)
     642        self._enableApproachCallOuts = \
     643            self._getBoolean(config, "sounds", "enableApproachCallOuts", False)
    542644        self._speedbrakeAtTD = self._getBoolean(config, "sounds",
    543645                                                "speedbrakeAtTD", True)
     
    555657            self._checklists[aircraftType] = \
    556658                Checklist.fromConfig(config, aircraftType)
     659            self._approachCallouts[aircraftType] = \
     660                ApproachCallouts.fromConfig(config, aircraftType)
    557661
    558662        self._modified = False
     
    626730
    627731        config.add_section(Checklist.SECTION)
     732        config.add_section(ApproachCallouts.SECTION)
    628733        for aircraftType in const.aircraftTypes:
    629734            self._checklists[aircraftType].toConfig(config, aircraftType)
     735            self._approachCallouts[aircraftType].toConfig(config, aircraftType)
    630736
    631737        try:
  • src/mlx/gui/checklist.py

    r260 r264  
    203203        selection = self._fileList.get_selection()
    204204        (model, paths) = selection.get_selected_rows()
    205         while paths:
    206             model.remove(model.get_iter(paths[0]))
    207             (model, paths) = selection.get_selected_rows()
     205
     206        iters = [model.get_iter(path) for path in paths]
     207
     208        for i in iters:
     209            if i is not None:
     210                model.remove(i)
    208211       
    209212    def _moveUpButtonClicked(self, button):
  • src/mlx/gui/common.py

    r246 r264  
    6262    WINDOW_STATE_ICONIFIED = gdk.WINDOW_STATE_ICONIFIED
    6363    WINDOW_STATE_WITHDRAWN = gdk.WINDOW_STATE_WITHDRAWN
     64
     65    SORT_ASCENDING = gtk.SORT_ASCENDING
     66    SORT_DESCENDING = gtk.SORT_DESCENDING
    6467
    6568    pixbuf_new_from_file = gdk.pixbuf_new_from_file
     
    118121    WINDOW_STATE_WITHDRAWN = gdk.WindowState.WITHDRAWN
    119122
     123    SORT_ASCENDING = gtk.SortType.ASCENDING
     124    SORT_DESCENDING = gtk.SortType.DESCENDING
     125
    120126    pixbuf_new_from_file = gdkPixbuf.Pixbuf.new_from_file
    121127
  • src/mlx/gui/gui.py

    r261 r264  
    1313from mlx.gui.prefs import Preferences
    1414from mlx.gui.checklist import ChecklistEditor
     15from mlx.gui.callouts import ApproachCalloutsEditor
    1516from mlx.gui.pirep import PIREPViewer
    1617
     
    9596        self._preferences = Preferences(self)
    9697        self._checklistEditor = ChecklistEditor(self)
     98        self._approachCalloutsEditor = ApproachCalloutsEditor(self)
    9799
    98100        menuBar = self._buildMenuBar(accelGroup)
     
    870872        checklistMenuItem.connect("activate", self._editChecklist)
    871873        toolsMenu.append(checklistMenuItem)
     874
     875        approachCalloutsMenuItem = gtk.ImageMenuItem(gtk.STOCK_EDIT)
     876        approachCalloutsMenuItem.set_use_stock(True)
     877        approachCalloutsMenuItem.set_label(xstr("menu_tools_callouts"))
     878        approachCalloutsMenuItem.add_accelerator("activate", accelGroup,
     879                                                 ord(xstr("menu_tools_callouts_key")),
     880                                                 CONTROL_MASK, ACCEL_VISIBLE)
     881        approachCalloutsMenuItem.connect("activate", self._editApproachCallouts)
     882        toolsMenu.append(approachCalloutsMenuItem)
    872883
    873884        prefsMenuItem = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES)
     
    10071018        """Callback for editing the checklists."""
    10081019        self._checklistEditor.run()
     1020       
     1021    def _editApproachCallouts(self, menuItem):
     1022        """Callback for editing the approach callouts."""
     1023        self._approachCalloutsEditor.run()
    10091024       
    10101025    def _editPreferences(self, menuItem):
  • src/mlx/i18n.py

    r256 r264  
    181181        self.add("menu_tools_chklst", "_Checklist Editor")
    182182        self.add("menu_tools_chklst_key", "c")
     183        self.add("menu_tools_callouts", "_Approach Callouts Editor")
     184        self.add("menu_tools_callouts_key", "e")
    183185        self.add("menu_tools_prefs", "_Preferences")
    184186        self.add("menu_tools_prefs_key", "p")
     
    975977        self.add("about_role_negotiation", "negotiation")
    976978        self.add("about_role_test", "testing")
     979
     980        self.add("callouts_title", "Approach Callouts Editor")
     981        self.add("callouts_aircraftType", "Aircraft _type:")
     982        self.add("callouts_aircraftType_tooltip",
     983                 "The type of the aircraft for which the approach "
     984                 "callouts are being edited.")
     985        self.add("callouts_header_altitude", "Altitude")
     986        self.add("callouts_header_path", "Callout file")
     987        self.add("callouts_add", "_Add new callout")
     988        self.add("callouts_add_tooltip",
     989                 "Add a new callout with some default altitude.")
     990        self.add("callouts_remove", "_Remove")
     991        self.add("callouts_remove_tooltip",
     992                 "Remove the selected items from the list of callouts.")
     993        self.add("callouts_altitude_clash",
     994                 "There is already a callout for this altitude")
     995        self.add("callouts_altitude_clash_sec",
     996                 "Shall I set the altitude nevertheless? If so, "
     997                 "both callouts will be played when reaching the altitude "
     998                 "simultaneously.")
     999        # self.add("chklst_moveUp", "Move _up")
     1000        # self.add("chklst_moveUp_tooltip",
     1001        #          "Move up the selected file(s) in the checklist.")
     1002        # self.add("chklst_moveDown", "Move _down")
     1003        # self.add("chklst_moveDown_tooltip",
     1004        #          "Move down the selected file(s) in the checklist.")
     1005        # self.add("chklst_filter_audio", "Audio files")
    9771006
    9781007#------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.