Changeset 77:cc8b178b8102 for src/mlx


Ignore:
Timestamp:
04/14/12 08:33:42 (13 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

The monitoring window is now separate window

Location:
src/mlx/gui
Files:
3 edited

Legend:

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

    r76 r77  
    66from mlx.gui.common import *
    77from mlx.gui.flight import Wizard
     8from mlx.gui.monitor import MonitorWindow
    89
    910import mlx.const as const
     
    1718import threading
    1819import sys
     20
     21#------------------------------------------------------------------------------
    1922
    2023acftTypes = [ ("Boeing 737-600", const.AIRCRAFT_B736),
     
    3437              ("Yakovlev Yak-40", const.AIRCRAFT_YK40) ]
    3538
     39#------------------------------------------------------------------------------
     40
    3641class GUI(fs.ConnectionListener):
    3742    """The main GUI class."""
     
    8186        notebook.append_page(self._wizard, label)
    8287
    83         dataVBox = gtk.VBox()
    84         label = gtk.Label("_Data")
    85         label.set_use_underline(True)
    86         label.set_tooltip_text("FSUIPC data access")
    87 
    88         if "USE_SCROLLEDDATA" in os.environ:
    89             dataScrolledWindow = gtk.ScrolledWindow()
    90             dataScrolledWindow.add_with_viewport(dataVBox)
    91             notebook.append_page(dataScrolledWindow, label)
    92         else:
    93             notebook.append_page(dataVBox, label)
    94 
    95         setupFrame = self._buildSetupFrame()
    96         setupFrame.set_border_width(8)
    97         dataVBox.pack_start(setupFrame, False, False, 0)
    98 
    99         dataFrame = self._buildDataFrame()
    100         dataFrame.set_border_width(8)
    101         dataVBox.pack_start(dataFrame, False, False, 0)
    102 
    10388        logVBox = gtk.VBox()
    10489        label = gtk.Label("_Log")
     
    117102
    118103        notebook.connect("switch-page", self._notebookPageSwitch)
     104
     105        self._monitorWindow = MonitorWindow(self, iconDirectory)
     106        self._monitorWindowX = None
     107        self._monitorWindowY = None
    119108
    120109        window.show_all()
     
    246235    def check(self, flight, aircraft, logger, oldState, state):
    247236        """Update the data."""
    248         gobject.idle_add(self._setData, state)
     237        gobject.idle_add(self._monitorWindow.setData, state)
    249238
    250239    def resetFlightStatus(self):
     
    314303        else:
    315304            self.showMainWindow()
     305
     306    def hideMonitorWindow(self, savePosition = True):
     307        """Hide the monitor window."""
     308        if savePosition:
     309            (self._monitorWindowX, self._monitorWindowY) = \
     310                 self._monitorWindow.get_window().get_root_origin()
     311        else:
     312            self._monitorWindowX = self._monitorWindowY = None
     313        self._monitorWindow.hide()
     314        self._statusIcon.monitorWindowHidden()
     315        return True
     316
     317    def showMonitorWindow(self):
     318        """Show the monitor window."""
     319        if self._monitorWindowX is not None and self._monitorWindowY is not None:
     320            self._monitorWindow.move(self._monitorWindowX, self._monitorWindowY)
     321        self._monitorWindow.show_all()
     322        self._statusIcon.monitorWindowShown()
    316323
    317324    def restart(self):
     
    388395        self._simulator.connect(self._flight.aircraft)       
    389396
    390     def _connectToggled(self, button):
    391         """Callback for the connection button."""
    392         if self._connectButton.get_active():
    393             acftListModel = self._acftList.get_model()
    394             self.connectSimulator(acftListModel[self._acftList.get_active()][1])
    395            
    396             self._flight.cruiseAltitude = self._flSpinButton.get_value_as_int() * 100
    397 
    398             self._flight.zfw = self._zfwSpinButton.get_value_as_int()
    399            
    400             self.startMonitoring()
    401         else:
    402             self.resetFlightStatus()
    403             self._connecting = False
    404             self._connected = False
    405 
    406             self._simulator.stopMonitoring()
    407             self._monitoring = False
    408 
    409             self._simulator.disconnect()
    410             self._flight = None
    411 
    412         self._statusbar.updateConnection(self._connecting, self._connected)
    413 
    414397    def startMonitoring(self):
    415398        """Start monitoring."""
     
    421404        self._simulator.stoptMonitoring()
    422405        self._monitoring = False
    423 
    424     def _buildSetupFrame(self):
    425         """Build the setup frame."""
    426         setupFrame = gtk.Frame(label = "Setup")
    427 
    428         frameAlignment = gtk.Alignment(xalign = 0.5)
    429 
    430         frameAlignment.set_padding(padding_top = 4, padding_bottom = 10,
    431                                    padding_left = 16, padding_right = 16)
    432 
    433         setupFrame.add(frameAlignment)
    434 
    435         setupBox = gtk.HBox()
    436         frameAlignment.add(setupBox)
    437 
    438         # self._fs9Button = gtk.RadioButton(label = "FS9")
    439         # self._fs9Button.set_tooltip_text("Use MS Flight Simulator 2004")
    440         # setupBox.pack_start(self._fs9Button, False, False, 0)
    441 
    442         # self._fsxButton = gtk.RadioButton(group = self._fs9Button, label = "FSX")
    443         # self._fsxButton.set_tooltip_text("Use MS Flight Simulator X")
    444         # setupBox.pack_start(self._fsxButton, False, False, 0)
    445 
    446         # setupBox.pack_start(gtk.VSeparator(), False, False, 8)
    447 
    448         alignment = gtk.Alignment(yalign = 0.5)
    449         alignment.set_padding(padding_top = 0, padding_bottom = 0,
    450                               padding_left = 0, padding_right = 16)
    451         alignment.add(gtk.Label("Aicraft:"))
    452         setupBox.pack_start(alignment, False, False, 0)
    453 
    454         acftListModel = gtk.ListStore(str, int)
    455         for (name, type) in acftTypes:
    456             acftListModel.append([name, type])
    457 
    458         self._acftList = gtk.ComboBox(model = acftListModel)   
    459         renderer_text = gtk.CellRendererText()
    460         self._acftList.pack_start(renderer_text, True)
    461         self._acftList.add_attribute(renderer_text, "text", 0)
    462         self._acftList.set_active(0)
    463         self._acftList.set_tooltip_text("Select the type of the aircraft used for the flight.")
    464 
    465         setupBox.pack_start(self._acftList, True, True, 0)
    466 
    467         setupBox.pack_start(gtk.VSeparator(), False, False, 8)
    468 
    469         alignment = gtk.Alignment(yalign = 0.5)
    470         alignment.set_padding(padding_top = 0, padding_bottom = 0,
    471                               padding_left = 0, padding_right = 16)
    472         alignment.add(gtk.Label("Cruise FL:"))
    473         setupBox.pack_start(alignment, False, False, 0)
    474 
    475         self._flSpinButton = gtk.SpinButton()
    476         self._flSpinButton.set_increments(step = 10, page = 100)
    477         self._flSpinButton.set_range(min = 0, max = 500)
    478         self._flSpinButton.set_value(240)
    479         self._flSpinButton.set_tooltip_text("The cruise flight level.")
    480         self._flSpinButton.set_numeric(True)
    481 
    482         setupBox.pack_start(self._flSpinButton, False, False, 0)
    483 
    484         setupBox.pack_start(gtk.VSeparator(), False, False, 8)
    485 
    486         alignment = gtk.Alignment(yalign = 0.5)
    487         alignment.set_padding(padding_top = 0, padding_bottom = 0,
    488                               padding_left = 0, padding_right = 16)
    489         alignment.add(gtk.Label("ZFW:"))
    490         setupBox.pack_start(alignment, False, False, 0)
    491 
    492         self._zfwSpinButton = gtk.SpinButton()
    493         self._zfwSpinButton.set_increments(step = 100, page = 1000)
    494         self._zfwSpinButton.set_range(min = 0, max = 500000)
    495         self._zfwSpinButton.set_value(50000)
    496         self._zfwSpinButton.set_tooltip_text("The Zero Fuel Weight for the flight in kgs")
    497         self._zfwSpinButton.set_numeric(True)
    498 
    499         setupBox.pack_start(self._zfwSpinButton, False, False, 0)
    500 
    501         setupBox.pack_start(gtk.VSeparator(), False, False, 8)   
    502 
    503         self._connectButton = gtk.ToggleButton(label = "_Connect",
    504                                                use_underline = True)
    505         self._connectButton.set_tooltip_text("Push to connect to Flight Simulator and start a new flight.\n"
    506                                              "Push again to disconnect from FS.")
    507         self._connectButton.set_can_default(True)
    508        
    509         self._connectButton.connect("toggled", self._connectToggled)
    510 
    511         setupBox.pack_start(self._connectButton, False, False, 0)
    512 
    513         setupBox.pack_start(gtk.VSeparator(), False, False, 8)   
    514 
    515         self._quitButton = gtk.Button(label = "_Quit", use_underline = True)
    516         self._quitButton.set_tooltip_text("Quit the program.")
    517        
    518         self._quitButton.connect("clicked", self._quit)
    519 
    520         setupBox.pack_start(self._quitButton, False, False, 0)
    521 
    522         return setupFrame
    523 
    524     def _createLabeledEntry(self, label, width = 8, xalign = 1.0):
    525         """Create a labeled entry.
    526 
    527         Return a tuple consisting of:
    528         - the box
    529         - the entry."""
    530        
    531         alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5, xscale = 1.0)
    532         alignment.set_padding(padding_top = 0, padding_bottom = 0,
    533                               padding_left = 0, padding_right = 16)
    534         alignment.add(gtk.Label(label))
    535 
    536         entry = gtk.Entry()
    537         entry.set_editable(False)
    538         entry.set_width_chars(width)
    539         entry.set_max_length(width)
    540         entry.set_alignment(xalign)
    541 
    542         return (alignment, entry)
    543 
    544     def _buildDataFrame(self):
    545         """Build the frame for the data."""
    546         dataFrame = gtk.Frame(label = "Data")
    547 
    548         frameAlignment = gtk.Alignment(xscale = 1.0, yscale = 1.0)
    549 
    550         frameAlignment.set_padding(padding_top = 4, padding_bottom = 10,
    551                                    padding_left = 16, padding_right = 16)
    552 
    553         table = gtk.Table(rows = 7, columns = 12)
    554         table.set_homogeneous(False)
    555         table.set_row_spacings(4)
    556         table.set_col_spacings(8)
    557 
    558         (label, self._timestamp) = self._createLabeledEntry("Time:")
    559         table.attach(label, 0, 1, 0, 1)
    560         table.attach(self._timestamp, 1, 2, 0, 1)
    561 
    562         self._paused = gtk.Label("PAUSED")
    563         table.attach(self._paused, 2, 4, 0, 1)
    564        
    565         self._trickMode = gtk.Label("TRICKMODE")
    566         table.attach(self._trickMode, 4, 6, 0, 1, xoptions = 0)
    567        
    568         self._overspeed = gtk.Label("OVERSPEED")
    569         table.attach(self._overspeed, 6, 8, 0, 1)
    570        
    571         self._stalled = gtk.Label("STALLED")
    572         table.attach(self._stalled, 8, 10, 0, 1)
    573        
    574         self._onTheGround = gtk.Label("ONTHEGROUND")
    575         table.attach(self._onTheGround, 10, 12, 0, 1)
    576        
    577         (label, self._zfw) = self._createLabeledEntry("ZFW:", 6)
    578         table.attach(label, 0, 1, 1, 2)
    579         table.attach(self._zfw, 1, 2, 1, 2)
    580 
    581         (label, self._grossWeight) = self._createLabeledEntry("Weight:", 6)
    582         table.attach(label, 2, 3, 1, 2)
    583         table.attach(self._grossWeight, 3, 4, 1, 2)
    584 
    585         (label, self._heading) = self._createLabeledEntry("Heading:", 3)
    586         table.attach(label, 4, 5, 1, 2)
    587         table.attach(self._heading, 5, 6, 1, 2)
    588 
    589         (label, self._pitch) = self._createLabeledEntry("Pitch:", 3)
    590         table.attach(label, 6, 7, 1, 2)
    591         table.attach(self._pitch, 7, 8, 1, 2)
    592 
    593         (label, self._bank) = self._createLabeledEntry("Bank:", 3)
    594         table.attach(label, 8, 9, 1, 2)
    595         table.attach(self._bank, 9, 10, 1, 2)
    596 
    597         (label, self._vs) = self._createLabeledEntry("VS:", 5)
    598         table.attach(label, 10, 11, 1, 2)
    599         table.attach(self._vs, 11, 12, 1, 2)
    600 
    601         (label, self._ias) = self._createLabeledEntry("IAS:", 4)
    602         table.attach(label, 0, 1, 2, 3)
    603         table.attach(self._ias, 1, 2, 2, 3)
    604 
    605         (label, self._mach) = self._createLabeledEntry("Mach:", 4)
    606         table.attach(label, 2, 3, 2, 3)
    607         table.attach(self._mach, 3, 4, 2, 3)
    608 
    609         (label, self._groundSpeed) = self._createLabeledEntry("GS:", 4)
    610         table.attach(label, 4, 5, 2, 3)
    611         table.attach(self._groundSpeed, 5, 6, 2, 3)
    612 
    613         (label, self._radioAltitude) = self._createLabeledEntry("Radio alt.:", 6)
    614         table.attach(label, 6, 7, 2, 3)
    615         table.attach(self._radioAltitude, 7, 8, 2, 3)
    616 
    617         (label, self._altitude) = self._createLabeledEntry("Altitude:", 6)
    618         table.attach(label, 8, 9, 2, 3)
    619         table.attach(self._altitude, 9, 10, 2, 3)
    620 
    621         (label, self._gLoad) = self._createLabeledEntry("G-Load:", 4)
    622         table.attach(label, 10, 11, 2, 3)
    623         table.attach(self._gLoad, 11, 12, 2, 3)
    624 
    625         (label, self._flapsSet) = self._createLabeledEntry("Flaps set:", 2)
    626         table.attach(label, 0, 1, 3, 4)
    627         table.attach(self._flapsSet, 1, 2, 3, 4)
    628 
    629         (label, self._flaps) = self._createLabeledEntry("Flaps:", 2)
    630         table.attach(label, 2, 3, 3, 4)
    631         table.attach(self._flaps, 3, 4, 3, 4)
    632 
    633         (label, self._altimeter) = self._createLabeledEntry("Altimeter:", 4)
    634         table.attach(label, 4, 5, 3, 4)
    635         table.attach(self._altimeter, 5, 6, 3, 4)
    636 
    637         (label, self._squawk) = self._createLabeledEntry("Squawk:", 4)
    638         table.attach(label, 6, 7, 3, 4)
    639         table.attach(self._squawk, 7, 8, 3, 4)
    640 
    641         (label, self._nav1) = self._createLabeledEntry("NAV1:", 5)
    642         table.attach(label, 8, 9, 3, 4)
    643         table.attach(self._nav1, 9, 10, 3, 4)
    644 
    645         (label, self._nav2) = self._createLabeledEntry("NAV2:", 5)
    646         table.attach(label, 10, 11, 3, 4)
    647         table.attach(self._nav2, 11, 12, 3, 4)
    648 
    649         (label, self._fuel) = self._createLabeledEntry("Fuel:", 40, xalign = 0.0)
    650         table.attach(label, 0, 1, 4, 5)
    651         table.attach(self._fuel, 1, 4, 4, 5)
    652 
    653         (label, self._n1) = self._createLabeledEntry("N1/RPM:", 20, xalign = 0.0)
    654         table.attach(label, 4, 5, 4, 5)
    655         table.attach(self._n1, 5, 8, 4, 5)
    656 
    657         (label, self._reverser) = self._createLabeledEntry("Reverser:", 20, xalign = 0.0)
    658         table.attach(label, 8, 9, 4, 5)
    659         table.attach(self._reverser, 9, 12, 4, 5)
    660 
    661         self._navLightsOn = gtk.Label("NAV")
    662         table.attach(self._navLightsOn, 0, 1, 5, 6)
    663 
    664         self._antiCollisionLightsOn = gtk.Label("ANTICOLLISION")
    665         table.attach(self._antiCollisionLightsOn, 1, 3, 5, 6)
    666 
    667         self._strobeLightsOn = gtk.Label("STROBE")
    668         table.attach(self._strobeLightsOn, 3, 4, 5, 6)
    669 
    670         self._landingLightsOn = gtk.Label("LANDING")
    671         table.attach(self._landingLightsOn, 4, 5, 5, 6)
    672 
    673         self._pitotHeatOn = gtk.Label("PITOT HEAT")
    674         table.attach(self._pitotHeatOn, 5, 7, 5, 6)
    675 
    676         self._parking = gtk.Label("PARKING")
    677         table.attach(self._parking, 7, 8, 5, 6)
    678 
    679         self._gearsDown = gtk.Label("GEARS DOWN")
    680         table.attach(self._gearsDown, 8, 10, 5, 6)
    681 
    682         self._spoilersArmed = gtk.Label("SPOILERS ARMED")
    683         table.attach(self._spoilersArmed, 10, 12, 5, 6)
    684 
    685         (label, self._spoilersExtension) = self._createLabeledEntry("Spoilers:", 3)
    686         table.attach(label, 0, 1, 6, 7)
    687         table.attach(self._spoilersExtension, 1, 2, 6, 7)
    688 
    689         (label, self._windSpeed) = self._createLabeledEntry("Wind speed:", 3)
    690         table.attach(label, 2, 3, 6, 7)
    691         table.attach(self._windSpeed, 3, 4, 6, 7)
    692 
    693         (label, self._windDirection) = self._createLabeledEntry("Wind from:", 3)
    694         table.attach(label, 4, 5, 6, 7)
    695         table.attach(self._windDirection, 5, 6, 6, 7)
    696 
    697         frameAlignment.add(table)
    698 
    699         dataFrame.add(frameAlignment)
    700 
    701         self._setData()
    702 
    703         return dataFrame       
    704 
    705     def _setData(self, aircraftState = None):
    706         """Set the data.
    707 
    708         If aircraftState is None, everything will be set to its default."""
    709         if aircraftState is None:
    710             self._timestamp.set_text("--:--:--")
    711             self._paused.set_sensitive(False)
    712             self._trickMode.set_sensitive(False)
    713             self._overspeed.set_sensitive(False)
    714             self._stalled.set_sensitive(False)
    715             self._onTheGround.set_sensitive(False)
    716             self._zfw.set_text("-")
    717             self._grossWeight.set_text("-")
    718             self._heading.set_text("-")
    719             self._pitch.set_text("-")
    720             self._bank.set_text("-")
    721             self._vs.set_text("-")
    722             self._ias.set_text("-")
    723             self._mach.set_text("-")
    724             self._groundSpeed.set_text("-")
    725             self._radioAltitude.set_text("-")
    726             self._altitude.set_text("-")
    727             self._gLoad.set_text("-")
    728             self._flapsSet.set_text("-")
    729             self._flaps.set_text("-")
    730             self._altimeter.set_text("-")
    731             self._squawk.set_text("-")
    732             self._nav1.set_text("-")
    733             self._nav2.set_text("-")
    734             self._fuel.set_text("-")
    735             self._n1.set_text("-")
    736             self._reverser.set_text("-")
    737             self._navLightsOn.set_sensitive(False)
    738             self._antiCollisionLightsOn.set_sensitive(False)
    739             self._strobeLightsOn.set_sensitive(False)
    740             self._landingLightsOn.set_sensitive(False)
    741             self._pitotHeatOn.set_sensitive(False)
    742             self._parking.set_sensitive(False)
    743             self._gearsDown.set_sensitive(False)
    744             self._spoilersArmed.set_sensitive(False)
    745             self._spoilersExtension.set_text("-")
    746             self._windSpeed.set_text("-")
    747             self._windDirection.set_text("-")
    748         else:
    749             self._timestamp.set_text(time.strftime("%H:%M:%S",
    750                                                    time.gmtime(aircraftState.timestamp)))
    751             self._paused.set_sensitive(aircraftState.paused)
    752             self._trickMode.set_sensitive(aircraftState.trickMode)
    753             self._overspeed.set_sensitive(aircraftState.overspeed)
    754             self._stalled.set_sensitive(aircraftState.stalled)
    755             self._onTheGround.set_sensitive(aircraftState.onTheGround)
    756             self._zfw.set_text("%.0f" % (aircraftState.zfw,))
    757             self._grossWeight.set_text("%.0f" % (aircraftState.grossWeight,))
    758             self._heading.set_text("%03.0f" % (aircraftState.heading,))
    759             self._pitch.set_text("%.0f" % (aircraftState.pitch,))
    760             self._bank.set_text("%.0f" % (aircraftState.bank,))
    761             self._vs.set_text("%.0f" % (aircraftState.vs,))
    762             self._ias.set_text("%.0f" % (aircraftState.ias,))
    763             self._mach.set_text("%.2f" % (aircraftState.mach,))
    764             self._groundSpeed.set_text("%.0f" % (aircraftState.groundSpeed,))
    765             self._radioAltitude.set_text("%.0f" % (aircraftState.radioAltitude,))
    766             self._altitude.set_text("%.0f" % (aircraftState.altitude,))
    767             self._gLoad.set_text("%.2f" % (aircraftState.gLoad,))
    768             self._flapsSet.set_text("%.0f" % (aircraftState.flapsSet,))
    769             self._flaps.set_text("%.0f" % (aircraftState.flaps,))
    770             self._altimeter.set_text("%.0f" % (aircraftState.altimeter,))
    771             self._squawk.set_text(aircraftState.squawk)
    772             self._nav1.set_text(aircraftState.nav1)
    773             self._nav2.set_text(aircraftState.nav2)
    774 
    775             fuelStr = ""
    776             for fuel in aircraftState.fuel:
    777                 if fuelStr: fuelStr += ", "
    778                 fuelStr += "%.0f" % (fuel,)               
    779             self._fuel.set_text(fuelStr)
    780 
    781             if hasattr(aircraftState, "n1"):
    782                 n1Str = ""
    783                 for n1 in aircraftState.n1:
    784                     if n1Str: n1Str += ", "
    785                     n1Str += "%.0f" % (n1,)
    786             elif hasattr(aircraftState, "rpm"):
    787                 n1Str = ""
    788                 for rpm in aircraftState.rpm:
    789                     if n1Str: n1Str += ", "
    790                     n1Str += "%.0f" % (rpm,)
    791             else:
    792                 n1Str = "-"
    793             self._n1.set_text(n1Str)
    794 
    795             reverserStr = ""
    796             for reverser in aircraftState.reverser:
    797                 if reverserStr: reverserStr += ", "
    798                 reverserStr += "ON" if reverser else "OFF"
    799             self._reverser.set_text(reverserStr)
    800 
    801             self._navLightsOn.set_sensitive(aircraftState.navLightsOn)
    802             self._antiCollisionLightsOn.set_sensitive(aircraftState.antiCollisionLightsOn)
    803             self._strobeLightsOn.set_sensitive(aircraftState.strobeLightsOn)
    804             self._landingLightsOn.set_sensitive(aircraftState.landingLightsOn)
    805             self._pitotHeatOn.set_sensitive(aircraftState.pitotHeatOn)
    806             self._parking.set_sensitive(aircraftState.parking)
    807             self._gearsDown.set_sensitive(aircraftState.gearsDown)
    808             self._spoilersArmed.set_sensitive(aircraftState.spoilersArmed)
    809             self._spoilersExtension.set_text("%.0f" % (aircraftState.spoilersExtension,))
    810             self._windSpeed.set_text("%.0f" % (aircraftState.windSpeed,))
    811             self._windDirection.set_text("%03.0f" % (aircraftState.windDirection,))
    812406
    813407    def _buildLogFrame(self):
     
    858452        if page_num==0:
    859453            gobject.idle_add(self._wizard.grabDefault)
    860         elif page_num==1:
    861             gobject.idle_add(self._connectButton.grab_default)
    862454        else:
    863455            self._mainWindow.set_default(None)
    864 
    865 class TrackerStatusIcon(gtk.StatusIcon):
    866         def __init__(self):
    867                 gtk.StatusIcon.__init__(self)
    868                 menu = '''
    869                         <ui>
    870                          <menubar name="Menubar">
    871                           <menu action="Menu">
    872                            <menuitem action="Search"/>
    873                            <menuitem action="Preferences"/>
    874                            <separator/>
    875                            <menuitem action="About"/>
    876                           </menu>
    877                          </menubar>
    878                         </ui>
    879                 '''
    880                 actions = [
    881                         ('Menu',  None, 'Menu'),
    882                         ('Search', None, '_Search...', None, 'Search files with MetaTracker', self.on_activate),
    883                         ('Preferences', gtk.STOCK_PREFERENCES, '_Preferences...', None, 'Change MetaTracker preferences', self.on_preferences),
    884                         ('About', gtk.STOCK_ABOUT, '_About...', None, 'About MetaTracker', self.on_about)]
    885                 ag = gtk.ActionGroup('Actions')
    886                 ag.add_actions(actions)
    887                 self.manager = gtk.UIManager()
    888                 self.manager.insert_action_group(ag, 0)
    889                 self.manager.add_ui_from_string(menu)
    890                 self.menu = self.manager.get_widget('/Menubar/Menu/About').props.parent
    891                 search = self.manager.get_widget('/Menubar/Menu/Search')
    892                 search.get_children()[0].set_markup('<b>_Search...</b>')
    893                 search.get_children()[0].set_use_underline(True)
    894                 search.get_children()[0].set_use_markup(True)
    895                 #search.get_children()[1].set_from_stock(gtk.STOCK_FIND, gtk.ICON_SIZE_MENU)
    896                 self.set_from_stock(gtk.STOCK_FIND)
    897                 self.set_tooltip('Tracker Desktop Search')
    898                 self.set_visible(True)
    899                 self.connect('activate', self.on_activate)
    900                 self.connect('popup-menu', self.on_popup_menu)
    901 
    902         def on_activate(self, data):
    903                 os.spawnlpe(os.P_NOWAIT, 'tracker-search-tool', os.environ)
    904 
    905         def on_popup_menu(self, status, button, time):
    906                 self.menu.popup(None, None, None, button, time)
    907 
    908         def on_preferences(self, data):
    909                 print 'preferences'
    910 
    911         def on_about(self, data):
    912                 dialog = gtk.AboutDialog()
    913                 dialog.set_name('Tracker')
    914                 dialog.set_version('0.5.0')
    915                 dialog.set_comments('A desktop indexing and search tool')
    916                 dialog.set_website('www.freedesktop.org/Tracker')
    917                 dialog.run()
    918                 dialog.destroy()
  • src/mlx/gui/monitor.py

    r76 r77  
    11# The monitoring window
     2
     3from mlx.gui.common import *
     4
     5import mlx.const as const
     6
     7import time
     8
     9#------------------------------------------------------------------------------
     10
     11class MonitorWindow(gtk.Window):
     12    """The window for the data monitor."""
     13    def __init__(self, gui, iconDirectory):
     14        """Construct the monitor window."""
     15        super(MonitorWindow, self).__init__()
     16       
     17        self._gui = gui
     18
     19        self.set_title("MAVA Logger X " + const.VERSION + " - Data Monitor")
     20        self.set_icon_from_file(os.path.join(iconDirectory, "logo.ico"))
     21        self.connect("delete-event",
     22                     lambda a, b: self._gui.hideMonitorWindow())
     23
     24        alignment = gtk.Alignment(xscale = 1.0, yscale = 1.0)
     25
     26        alignment.set_padding(padding_top = 4, padding_bottom = 10,
     27                              padding_left = 16, padding_right = 16)
     28
     29        table = gtk.Table(rows = 7, columns = 12)
     30        table.set_homogeneous(False)
     31        table.set_row_spacings(4)
     32        table.set_col_spacings(8)
     33
     34        (label, self._timestamp) = self._createLabeledEntry("Time:")
     35        table.attach(label, 0, 1, 0, 1)
     36        table.attach(self._timestamp, 1, 2, 0, 1)
     37
     38        self._paused = gtk.Label("PAUSED")
     39        table.attach(self._paused, 2, 4, 0, 1)
     40       
     41        self._trickMode = gtk.Label("TRICKMODE")
     42        table.attach(self._trickMode, 4, 6, 0, 1, xoptions = 0)
     43       
     44        self._overspeed = gtk.Label("OVERSPEED")
     45        table.attach(self._overspeed, 6, 8, 0, 1)
     46       
     47        self._stalled = gtk.Label("STALLED")
     48        table.attach(self._stalled, 8, 10, 0, 1)
     49       
     50        self._onTheGround = gtk.Label("ONTHEGROUND")
     51        table.attach(self._onTheGround, 10, 12, 0, 1)
     52       
     53        (label, self._zfw) = self._createLabeledEntry("ZFW:", 6)
     54        table.attach(label, 0, 1, 1, 2)
     55        table.attach(self._zfw, 1, 2, 1, 2)
     56
     57        (label, self._grossWeight) = self._createLabeledEntry("Weight:", 6)
     58        table.attach(label, 2, 3, 1, 2)
     59        table.attach(self._grossWeight, 3, 4, 1, 2)
     60
     61        (label, self._heading) = self._createLabeledEntry("Heading:", 3)
     62        table.attach(label, 4, 5, 1, 2)
     63        table.attach(self._heading, 5, 6, 1, 2)
     64
     65        (label, self._pitch) = self._createLabeledEntry("Pitch:", 3)
     66        table.attach(label, 6, 7, 1, 2)
     67        table.attach(self._pitch, 7, 8, 1, 2)
     68
     69        (label, self._bank) = self._createLabeledEntry("Bank:", 3)
     70        table.attach(label, 8, 9, 1, 2)
     71        table.attach(self._bank, 9, 10, 1, 2)
     72
     73        (label, self._vs) = self._createLabeledEntry("VS:", 5)
     74        table.attach(label, 10, 11, 1, 2)
     75        table.attach(self._vs, 11, 12, 1, 2)
     76
     77        (label, self._ias) = self._createLabeledEntry("IAS:", 4)
     78        table.attach(label, 0, 1, 2, 3)
     79        table.attach(self._ias, 1, 2, 2, 3)
     80
     81        (label, self._mach) = self._createLabeledEntry("Mach:", 4)
     82        table.attach(label, 2, 3, 2, 3)
     83        table.attach(self._mach, 3, 4, 2, 3)
     84
     85        (label, self._groundSpeed) = self._createLabeledEntry("GS:", 4)
     86        table.attach(label, 4, 5, 2, 3)
     87        table.attach(self._groundSpeed, 5, 6, 2, 3)
     88
     89        (label, self._radioAltitude) = self._createLabeledEntry("Radio alt.:", 6)
     90        table.attach(label, 6, 7, 2, 3)
     91        table.attach(self._radioAltitude, 7, 8, 2, 3)
     92
     93        (label, self._altitude) = self._createLabeledEntry("Altitude:", 6)
     94        table.attach(label, 8, 9, 2, 3)
     95        table.attach(self._altitude, 9, 10, 2, 3)
     96
     97        (label, self._gLoad) = self._createLabeledEntry("G-Load:", 4)
     98        table.attach(label, 10, 11, 2, 3)
     99        table.attach(self._gLoad, 11, 12, 2, 3)
     100
     101        (label, self._flapsSet) = self._createLabeledEntry("Flaps set:", 2)
     102        table.attach(label, 0, 1, 3, 4)
     103        table.attach(self._flapsSet, 1, 2, 3, 4)
     104
     105        (label, self._flaps) = self._createLabeledEntry("Flaps:", 2)
     106        table.attach(label, 2, 3, 3, 4)
     107        table.attach(self._flaps, 3, 4, 3, 4)
     108
     109        (label, self._altimeter) = self._createLabeledEntry("Altimeter:", 4)
     110        table.attach(label, 4, 5, 3, 4)
     111        table.attach(self._altimeter, 5, 6, 3, 4)
     112
     113        (label, self._squawk) = self._createLabeledEntry("Squawk:", 4)
     114        table.attach(label, 6, 7, 3, 4)
     115        table.attach(self._squawk, 7, 8, 3, 4)
     116
     117        (label, self._nav1) = self._createLabeledEntry("NAV1:", 5)
     118        table.attach(label, 8, 9, 3, 4)
     119        table.attach(self._nav1, 9, 10, 3, 4)
     120
     121        (label, self._nav2) = self._createLabeledEntry("NAV2:", 5)
     122        table.attach(label, 10, 11, 3, 4)
     123        table.attach(self._nav2, 11, 12, 3, 4)
     124
     125        (label, self._fuel) = self._createLabeledEntry("Fuel:", 40, xalign = 0.0)
     126        table.attach(label, 0, 1, 4, 5)
     127        table.attach(self._fuel, 1, 4, 4, 5)
     128
     129        (label, self._n1) = self._createLabeledEntry("N1/RPM:", 20, xalign = 0.0)
     130        table.attach(label, 4, 5, 4, 5)
     131        table.attach(self._n1, 5, 8, 4, 5)
     132
     133        (label, self._reverser) = self._createLabeledEntry("Reverser:", 20, xalign = 0.0)
     134        table.attach(label, 8, 9, 4, 5)
     135        table.attach(self._reverser, 9, 12, 4, 5)
     136
     137        self._navLightsOn = gtk.Label("NAV")
     138        table.attach(self._navLightsOn, 0, 1, 5, 6)
     139
     140        self._antiCollisionLightsOn = gtk.Label("ANTICOLLISION")
     141        table.attach(self._antiCollisionLightsOn, 1, 3, 5, 6)
     142
     143        self._strobeLightsOn = gtk.Label("STROBE")
     144        table.attach(self._strobeLightsOn, 3, 4, 5, 6)
     145
     146        self._landingLightsOn = gtk.Label("LANDING")
     147        table.attach(self._landingLightsOn, 4, 5, 5, 6)
     148
     149        self._pitotHeatOn = gtk.Label("PITOT HEAT")
     150        table.attach(self._pitotHeatOn, 5, 7, 5, 6)
     151
     152        self._parking = gtk.Label("PARKING")
     153        table.attach(self._parking, 7, 8, 5, 6)
     154
     155        self._gearsDown = gtk.Label("GEARS DOWN")
     156        table.attach(self._gearsDown, 8, 10, 5, 6)
     157
     158        self._spoilersArmed = gtk.Label("SPOILERS ARMED")
     159        table.attach(self._spoilersArmed, 10, 12, 5, 6)
     160
     161        (label, self._spoilersExtension) = self._createLabeledEntry("Spoilers:", 3)
     162        table.attach(label, 0, 1, 6, 7)
     163        table.attach(self._spoilersExtension, 1, 2, 6, 7)
     164
     165        (label, self._windSpeed) = self._createLabeledEntry("Wind speed:", 3)
     166        table.attach(label, 2, 3, 6, 7)
     167        table.attach(self._windSpeed, 3, 4, 6, 7)
     168
     169        (label, self._windDirection) = self._createLabeledEntry("Wind from:", 3)
     170        table.attach(label, 4, 5, 6, 7)
     171        table.attach(self._windDirection, 5, 6, 6, 7)
     172
     173        alignment.add(table)
     174
     175        self.add(alignment)
     176
     177        self.setData()
     178
     179    def _createLabeledEntry(self, label, width = 8, xalign = 1.0):
     180        """Create a labeled entry.
     181
     182        Return a tuple consisting of:
     183        - the box
     184        - the entry."""
     185       
     186        alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5, xscale = 1.0)
     187        alignment.set_padding(padding_top = 0, padding_bottom = 0,
     188                              padding_left = 0, padding_right = 16)
     189        alignment.add(gtk.Label(label))
     190
     191        entry = gtk.Entry()
     192        entry.set_editable(False)
     193        entry.set_width_chars(width)
     194        entry.set_max_length(width)
     195        entry.set_alignment(xalign)
     196
     197        return (alignment, entry)
     198
     199    def setData(self, aircraftState = None):
     200        """Set the data.
     201
     202        If aircraftState is None, everything will be set to its default."""
     203        if aircraftState is None:
     204            self._timestamp.set_text("--:--:--")
     205            self._paused.set_sensitive(False)
     206            self._trickMode.set_sensitive(False)
     207            self._overspeed.set_sensitive(False)
     208            self._stalled.set_sensitive(False)
     209            self._onTheGround.set_sensitive(False)
     210            self._zfw.set_text("-")
     211            self._grossWeight.set_text("-")
     212            self._heading.set_text("-")
     213            self._pitch.set_text("-")
     214            self._bank.set_text("-")
     215            self._vs.set_text("-")
     216            self._ias.set_text("-")
     217            self._mach.set_text("-")
     218            self._groundSpeed.set_text("-")
     219            self._radioAltitude.set_text("-")
     220            self._altitude.set_text("-")
     221            self._gLoad.set_text("-")
     222            self._flapsSet.set_text("-")
     223            self._flaps.set_text("-")
     224            self._altimeter.set_text("-")
     225            self._squawk.set_text("-")
     226            self._nav1.set_text("-")
     227            self._nav2.set_text("-")
     228            self._fuel.set_text("-")
     229            self._n1.set_text("-")
     230            self._reverser.set_text("-")
     231            self._navLightsOn.set_sensitive(False)
     232            self._antiCollisionLightsOn.set_sensitive(False)
     233            self._strobeLightsOn.set_sensitive(False)
     234            self._landingLightsOn.set_sensitive(False)
     235            self._pitotHeatOn.set_sensitive(False)
     236            self._parking.set_sensitive(False)
     237            self._gearsDown.set_sensitive(False)
     238            self._spoilersArmed.set_sensitive(False)
     239            self._spoilersExtension.set_text("-")
     240            self._windSpeed.set_text("-")
     241            self._windDirection.set_text("-")
     242        else:
     243            self._timestamp.set_text(time.strftime("%H:%M:%S",
     244                                                   time.gmtime(aircraftState.timestamp)))
     245            self._paused.set_sensitive(aircraftState.paused)
     246            self._trickMode.set_sensitive(aircraftState.trickMode)
     247            self._overspeed.set_sensitive(aircraftState.overspeed)
     248            self._stalled.set_sensitive(aircraftState.stalled)
     249            self._onTheGround.set_sensitive(aircraftState.onTheGround)
     250            self._zfw.set_text("%.0f" % (aircraftState.zfw,))
     251            self._grossWeight.set_text("%.0f" % (aircraftState.grossWeight,))
     252            self._heading.set_text("%03.0f" % (aircraftState.heading,))
     253            self._pitch.set_text("%.0f" % (aircraftState.pitch,))
     254            self._bank.set_text("%.0f" % (aircraftState.bank,))
     255            self._vs.set_text("%.0f" % (aircraftState.vs,))
     256            self._ias.set_text("%.0f" % (aircraftState.ias,))
     257            self._mach.set_text("%.2f" % (aircraftState.mach,))
     258            self._groundSpeed.set_text("%.0f" % (aircraftState.groundSpeed,))
     259            self._radioAltitude.set_text("%.0f" % (aircraftState.radioAltitude,))
     260            self._altitude.set_text("%.0f" % (aircraftState.altitude,))
     261            self._gLoad.set_text("%.2f" % (aircraftState.gLoad,))
     262            self._flapsSet.set_text("%.0f" % (aircraftState.flapsSet,))
     263            self._flaps.set_text("%.0f" % (aircraftState.flaps,))
     264            self._altimeter.set_text("%.0f" % (aircraftState.altimeter,))
     265            self._squawk.set_text(aircraftState.squawk)
     266            self._nav1.set_text(aircraftState.nav1)
     267            self._nav2.set_text(aircraftState.nav2)
     268
     269            fuelStr = ""
     270            for fuel in aircraftState.fuel:
     271                if fuelStr: fuelStr += ", "
     272                fuelStr += "%.0f" % (fuel,)               
     273            self._fuel.set_text(fuelStr)
     274
     275            if hasattr(aircraftState, "n1"):
     276                n1Str = ""
     277                for n1 in aircraftState.n1:
     278                    if n1Str: n1Str += ", "
     279                    n1Str += "%.0f" % (n1,)
     280            elif hasattr(aircraftState, "rpm"):
     281                n1Str = ""
     282                for rpm in aircraftState.rpm:
     283                    if n1Str: n1Str += ", "
     284                    n1Str += "%.0f" % (rpm,)
     285            else:
     286                n1Str = "-"
     287            self._n1.set_text(n1Str)
     288
     289            reverserStr = ""
     290            for reverser in aircraftState.reverser:
     291                if reverserStr: reverserStr += ", "
     292                reverserStr += "ON" if reverser else "OFF"
     293            self._reverser.set_text(reverserStr)
     294
     295            self._navLightsOn.set_sensitive(aircraftState.navLightsOn)
     296            self._antiCollisionLightsOn.set_sensitive(aircraftState.antiCollisionLightsOn)
     297            self._strobeLightsOn.set_sensitive(aircraftState.strobeLightsOn)
     298            self._landingLightsOn.set_sensitive(aircraftState.landingLightsOn)
     299            self._pitotHeatOn.set_sensitive(aircraftState.pitotHeatOn)
     300            self._parking.set_sensitive(aircraftState.parking)
     301            self._gearsDown.set_sensitive(aircraftState.gearsDown)
     302            self._spoilersArmed.set_sensitive(aircraftState.spoilersArmed)
     303            self._spoilersExtension.set_text("%.0f" % (aircraftState.spoilersExtension,))
     304            self._windSpeed.set_text("%.0f" % (aircraftState.windSpeed,))
     305            self._windDirection.set_text("%03.0f" % (aircraftState.windDirection,))
     306
     307#------------------------------------------------------------------------------
  • src/mlx/gui/statusicon.py

    r76 r77  
    3939        self._showHideMenuItem.show() 
    4040        menu.append(self._showHideMenuItem) 
     41
     42        self._showMonitorMenuItem = gtk.CheckMenuItem() 
     43        self._showMonitorMenuItem.set_label("Show monitor window") 
     44        self._showMonitorMenuItem.set_active(False)
     45        self._showMonitorMenuItem.connect("toggled", self._showMonitorToggled)
     46        self._showMonitorMenuItem.show() 
     47        menu.append(self._showMonitorMenuItem) 
     48
     49        separator = gtk.SeparatorMenuItem()
     50        separator.show()
     51        menu.append(separator)
    4152
    4253        self._quitMenuItem = gtk.MenuItem() 
     
    89100            self._showHideMenuItem.set_active(True)
    90101
     102    def monitorWindowHidden(self):
     103        """Called when the monitor window is hidden."""
     104        if self._showMonitorMenuItem.get_active():
     105            self._selfToggling = True
     106            self._showMonitorMenuItem.set_active(False)
     107
     108    def monitorWindowShown(self):
     109        """Called when the monitor window is shown."""
     110        if not self._showMonitorMenuItem.get_active():
     111            self._selfToggling = True
     112            self._showMonitorMenuItem.set_active(True)
     113
    91114    def destroy(self):
    92115        """Hide and destroy the status icon."""
     
    108131            self._gui.hideMainWindow()
    109132
     133    def _showMonitorToggled(self, menuitem):
     134        """Called when the show/hide monitor window menu item is toggled."""
     135        if self._selfToggling:
     136            self._selfToggling = False
     137        elif self._showMonitorMenuItem.get_active():
     138            self._gui.showMonitorWindow()
     139        else:
     140            self._gui.hideMonitorWindow()
     141
    110142    def _updateFlightStatus(self):
    111143        """Update the flight status."""
Note: See TracChangeset for help on using the changeset viewer.