Changeset 393:977efa7a177b


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)

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • locale/en/mlx.po

    r392 r393  
    951951msgstr "The PIREP was saved successfully"
    952952
     953msgid "finish_save_done_sec"
     954msgstr "Path: %s"
     955
    953956msgid "finish_save_failed"
    954957msgstr "Failed to save the PIREP"
    955958
    956959msgid "finish_save_failed_sec"
    957 msgstr "See the debug log for the details."
     960msgstr "Error: %s."
     961
     962msgid "finish_autosave_busy"
     963msgstr "Saving PIREP automatically..."
    958964
    959965msgid "info_comments"
  • locale/hu/mlx.po

    r392 r393  
    954954msgstr "A PIREP mentése sikerült"
    955955
     956msgid "finish_save_done_sec"
     957msgstr "Elérési út: %s"
     958
    956959msgid "finish_save_failed"
    957960msgstr "A PIREP mentése nem sikerült"
    958961
    959962msgid "finish_save_failed_sec"
    960 msgstr "A részleteket lásd a debug naplóban."
     963msgstr "A hiba: %s."
     964
     965msgid "finish_autosave_busy"
     966msgstr "A PIREP automatikus mentése..."
    961967
    962968msgid "info_comments"
  • 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):
  • src/mlx/gui/gui.py

    r391 r393  
    4848    _authors = [ (u"Váradi", u"István", "prog_test"),
    4949                 (u"Galyassy", u"Tamás", "negotiation"),
    50                  (u"Petrovszki", u"Gábor", "test"),
    51                  (u"Zsebényi-Loksa", u"Gergely", "test"),
    5250                 (u"Kurják", u"Ákos", "test"),
    5351                 (u"Nagy", u"Dániel", "test"),
    54                  (u"Radó", u"Iván", "test") ]
     52                 (u"Radó", u"Iván", "test"),
     53                 (u"Petrovszki", u"Gábor", "test"),
     54                 (u"Serfőző", u"Tamás", "test"),
     55                 (u"Szebenyi", u"Bálint", "test"),
     56                 (u"Zsebényi-Loksa", u"Gergely", "test") ]
    5557
    5658    def __init__(self, programDirectory, config):
  • src/mlx/pirep.py

    r345 r393  
    155155            with open(path, "wb") as f:
    156156                pickle.dump(self, f)
    157             return True
     157            return None
    158158        except Exception, e:
    159             print "Failed saving PIREP to %s: %s" % (path, str(e))
    160             return False
     159            error = str(e)
     160            #print u"Failed saving PIREP to %s: %s" % (path, error)
     161            return error
Note: See TracChangeset for help on using the changeset viewer.