Ignore:
Timestamp:
12/22/12 10:23:19 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Added the automatic saving of the PIREP (re #163)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/gui/flight.py

    r391 r393  
    1515import datetime
    1616import time
     17import os
    1718
    1819#-----------------------------------------------------------------------------
     
    28722873                     self._gate.get_active()>=0)
    28732874
     2875        wasSensitive = self._saveButton.get_sensitive()
     2876
     2877        gui = self._wizard.gui
     2878        config = gui.config
     2879        if config.pirepAutoSave and sensitive and not wasSensitive:
     2880            self._lastSavePath = os.path.join(config.pirepDirectory,
     2881                                              self._getDefaultPIREPName())
     2882            self._lastSavePath = text2unicode(self._lastSavePath)
     2883            self._savePIREP(automatic = True)
     2884
    28742885        self._saveButton.set_sensitive(sensitive)
    28752886        self._sendButton.set_sensitive(sensitive and
     
    29032914        gui.reset()
    29042915
     2916    def _getDefaultPIREPName(self):
     2917        """Get the default name of the PIREP."""
     2918        gui = self._wizard.gui
     2919
     2920        bookedFlight = gui.bookedFlight
     2921        tm = time.gmtime()
     2922
     2923        pilotID = self._wizard.pilotID
     2924        if pilotID: pilotID += " "
     2925        return "%s%s %02d%02d %s-%s.pirep" % \
     2926               (pilotID, str(bookedFlight.departureTime.date()),
     2927                tm.tm_hour, tm.tm_min,
     2928                bookedFlight.departureICAO, bookedFlight.arrivalICAO)
     2929
     2930
    29052931    def _saveClicked(self, button):
    29062932        """Called when the Save PIREP button is clicked."""
    29072933        gui = self._wizard.gui
    29082934
    2909         bookedFlight = gui.bookedFlight
    2910         tm = time.gmtime()
    2911 
    2912         pilotID = self._wizard.pilotID
    2913         if pilotID: pilotID += " "
    2914         fileName = "%s%s %02d%02d %s-%s.pirep" % \
    2915                    (pilotID, str(bookedFlight.departureTime.date()),
    2916                     tm.tm_hour, tm.tm_min,
    2917                     bookedFlight.departureICAO,
    2918                     bookedFlight.arrivalICAO)
     2935        fileName = self._getDefaultPIREPName()
    29192936
    29202937        dialog = self._getSaveDialog()
     
    29322949
    29332950        if result==RESPONSETYPE_OK:
    2934             pirep = PIREP(gui.flight)
    2935 
    29362951            self._lastSavePath = text2unicode(dialog.get_filename())
    2937 
    2938             if pirep.save(self._lastSavePath):
    2939                 type = MESSAGETYPE_INFO
    2940                 message = xstr("finish_save_done")
     2952            self._savePIREP()
     2953
     2954    def _savePIREP(self, automatic = False):
     2955        """Perform the saving of the PIREP."""
     2956
     2957        gui = self._wizard.gui
     2958
     2959        if automatic:
     2960            gui.beginBusy(xstr("finish_autosave_busy"))
     2961
     2962        pirep = PIREP(gui.flight)
     2963        error = pirep.save(self._lastSavePath)
     2964
     2965        if automatic:
     2966            gui.endBusy()
     2967
     2968        if error:
     2969            type = MESSAGETYPE_ERROR
     2970            message = xstr("finish_save_failed")
     2971            secondary = xstr("finish_save_failed_sec") % (text2unicode(error),)
     2972        else:
     2973            type = MESSAGETYPE_INFO
     2974            message = xstr("finish_save_done")
     2975            if automatic:
     2976                secondary = xstr("finish_save_done_sec") % (self._lastSavePath,)
     2977            else:
    29412978                secondary = None
    2942                 self._pirepSaved = True
    2943             else:
    2944                 type = MESSAGETYPE_ERROR
    2945                 message = xstr("finish_save_failed")
    2946                 secondary = xstr("finish_save_failed_sec")
    2947 
    2948             dialog = gtk.MessageDialog(parent = gui.mainWindow,
    2949                                        type = type, message_format = message)
    2950             dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK)
    2951             dialog.set_title(WINDOW_TITLE_BASE)
    2952             if secondary is not None:
    2953                 dialog.format_secondary_markup(secondary)
    2954 
    2955             dialog.run()
    2956             dialog.hide()
     2979            self._pirepSaved = True
     2980
     2981        dialog = gtk.MessageDialog(parent = gui.mainWindow,
     2982                                   type = type, message_format = message)
     2983        dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK)
     2984        dialog.set_title(WINDOW_TITLE_BASE)
     2985        if secondary is not None:
     2986            dialog.format_secondary_markup(secondary)
     2987
     2988        dialog.run()
     2989        dialog.hide()
    29572990
    29582991    def _getSaveDialog(self):
Note: See TracChangeset for help on using the changeset viewer.