Ignore:
Timestamp:
05/27/12 11:15:19 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

Added support for smoothed IAS and VS values

File:
1 edited

Legend:

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

    r186 r197  
    229229        self._syncFSTime.set_active(config.syncFSTime)
    230230        self._usingFS2Crew.set_active(config.usingFS2Crew)
     231       
     232        self._setSmoothing(self._iasSmoothingEnabled, self._iasSmoothingLength,
     233                           config.iasSmoothingLength)
     234        self._setSmoothing(self._vsSmoothingEnabled, self._vsSmoothingLength,
     235                           config.vsSmoothingLength)
    231236
    232237        pirepDirectory = config.pirepDirectory
     
    269274        config.syncFSTime = self._syncFSTime.get_active()
    270275        config.usingFS2Crew = self._usingFS2Crew.get_active()
     276        config.iasSmoothingLength = self._getSmoothing(self._iasSmoothingEnabled,
     277                                                       self._iasSmoothingLength)
     278        config.vsSmoothingLength = self._getSmoothing(self._vsSmoothingEnabled,
     279                                                       self._vsSmoothingLength)
    271280        config.pirepDirectory = text2unicode(self._pirepDirectory.get_text())
    272281
     
    366375        self._usingFS2Crew.set_tooltip_text(xstr("prefs_usingFS2Crew_tooltip"))
    367376        simulatorBox.pack_start(self._usingFS2Crew, False, False, 4)
     377       
     378        (iasSmoothingBox, self._iasSmoothingEnabled,
     379         self._iasSmoothingLength) = \
     380           self._createSmoothingBox(xstr("prefs_iasSmoothingEnabled"),
     381                                    xstr("prefs_iasSmoothingEnabledTooltip"))
     382        simulatorBox.pack_start(iasSmoothingBox, False, False, 4)
     383
     384        (vsSmoothingBox, self._vsSmoothingEnabled,
     385         self._vsSmoothingLength) = \
     386           self._createSmoothingBox(xstr("prefs_vsSmoothingEnabled"),
     387                                    xstr("prefs_vsSmoothingEnabledTooltip"))
     388        simulatorBox.pack_start(vsSmoothingBox, False, False, 4)
    368389
    369390        pirepBox = gtk.HBox()
     
    401422
    402423        return vbox
     424
     425    def _createSmoothingBox(self, checkBoxLabel, checkBoxTooltip,
     426                            maxSeconds = 10):
     427        """Create a HBox that contains entry fields for smoothing some value."""
     428        smoothingBox = gtk.HBox()
     429
     430        smoothingEnabled = gtk.CheckButton(checkBoxLabel)
     431        smoothingEnabled.set_use_underline(True)
     432        smoothingEnabled.set_tooltip_text(checkBoxTooltip)
     433
     434        smoothingBox.pack_start(smoothingEnabled, False, False, 0)
     435
     436        smoothingLength = gtk.SpinButton()
     437        smoothingLength.set_numeric(True)
     438        smoothingLength.set_range(2, maxSeconds)
     439        smoothingLength.set_increments(1, 1)
     440        smoothingLength.set_alignment(1.0)
     441        smoothingLength.set_width_chars(2)
     442
     443        smoothingBox.pack_start(smoothingLength, False, False, 0)
     444
     445        smoothingBox.pack_start(gtk.Label(xstr("prefs_smoothing_seconds")),
     446                                False, False, 4)
     447
     448        smoothingEnabled.connect("toggled", self._smoothingToggled,
     449                                 smoothingLength)
     450        smoothingLength.set_sensitive(False)
     451
     452        return (smoothingBox, smoothingEnabled, smoothingLength)
    403453
    404454    def _setLanguage(self, language):
     
    434484            dialog.hide()
    435485            self._warnedRestartNeeded = True
    436        
     486
     487    def _smoothingToggled(self, smoothingEnabled, smoothingLength):
     488        """Called when a smoothing enabled check box is toggled."""
     489        sensitive = smoothingEnabled.get_active()
     490        smoothingLength.set_sensitive(sensitive)
     491        if sensitive:
     492            smoothingLength.grab_focus()
     493
     494    def _setSmoothing(self, smoothingEnabled, smoothingLength, smoothing):
     495        """Set the smoothing controls from the given value.
     496
     497        If the value is less than 2, smoothing is disabled. The smoothing
     498        length is the absolute value of the value."""
     499        smoothingEnabled.set_active(smoothing>=2)
     500        smoothingLength.set_value(abs(smoothing))
     501       
     502    def _getSmoothing(self, smoothingEnabled, smoothingLength):
     503        """Get the smoothing value from the given controls.
     504
     505        The returned value is the value of smoothingLength multiplied by -1, if
     506        smoothing is disabled."""
     507        value = smoothingLength.get_value_as_int()
     508        if not smoothingEnabled.get_active():
     509            value *= -1
     510        return value
     511       
    437512    def _pirepDirectoryButtonClicked(self, button):
    438513        """Called when the PIREP directory button is clicked."""
Note: See TracChangeset for help on using the changeset viewer.