[118] | 1 |
|
---|
| 2 | from mlx.gui.common import *
|
---|
| 3 |
|
---|
| 4 | from mlx.i18n import xstr
|
---|
| 5 | import mlx.const as const
|
---|
[619] | 6 | from mlx.gates import Gates, lhbpGates
|
---|
[118] | 7 |
|
---|
| 8 | #-------------------------------------------------------------------------------
|
---|
| 9 |
|
---|
[300] | 10 | ## @package mlx.gui.gates
|
---|
| 11 | #
|
---|
| 12 | # The gate status display.
|
---|
| 13 | #
|
---|
| 14 | # This module contains the \ref FleetGateStatus widget, which is the tab
|
---|
| 15 | # displaying the status of the MAVA Fleet and the gates at LHBP. The left side
|
---|
| 16 | # of the widget is the table with the list of the planes and their states. The
|
---|
| 17 | # right side displays the numbers of the gates and their occupation status.
|
---|
| 18 |
|
---|
| 19 | #-------------------------------------------------------------------------------
|
---|
| 20 |
|
---|
[118] | 21 | class FleetGateStatus(gtk.VBox):
|
---|
| 22 | """The tab to display the fleet and gate status."""
|
---|
| 23 | def __init__(self, gui):
|
---|
| 24 | """Construct the tab."""
|
---|
| 25 | super(FleetGateStatus, self).__init__()
|
---|
| 26 |
|
---|
| 27 | self._gui = gui
|
---|
| 28 |
|
---|
| 29 | mainAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
| 30 | xscale = 1.0, yscale = 1.0)
|
---|
| 31 | mainAlignment.set_padding(padding_top = 4, padding_bottom = 4,
|
---|
| 32 | padding_left = 12, padding_right = 12)
|
---|
| 33 | self.add(mainAlignment)
|
---|
| 34 |
|
---|
| 35 | self._mainBox = mainBox = gtk.VBox()
|
---|
| 36 | mainAlignment.add(mainBox)
|
---|
| 37 |
|
---|
[121] | 38 | self._statusBox = statusBox = gtk.HBox()
|
---|
[118] | 39 | mainBox.pack_start(statusBox, True, True, 4)
|
---|
| 40 |
|
---|
[121] | 41 | fleetFrame = gtk.Frame(label = xstr("gates_fleet_title"))
|
---|
[118] | 42 | fleetLabel = fleetFrame.get_label_widget()
|
---|
| 43 | fleetLabel.set_use_underline(True)
|
---|
| 44 | statusBox.pack_start(fleetFrame, False, False, 4)
|
---|
| 45 |
|
---|
| 46 | self._fleetStore = gtk.ListStore(str, str)
|
---|
| 47 | self._fleetList = gtk.TreeView(self._fleetStore)
|
---|
| 48 | self._fleetList.set_tooltip_markup(xstr("gates_planes_tooltip"))
|
---|
| 49 | fleetLabel.set_mnemonic_widget(self._fleetList)
|
---|
| 50 | column = gtk.TreeViewColumn(xstr("gates_tailno"), gtk.CellRendererText(),
|
---|
| 51 | text = 0)
|
---|
| 52 | column.set_expand(True)
|
---|
| 53 | column.set_sort_column_id(0)
|
---|
| 54 | self._fleetList.append_column(column)
|
---|
| 55 |
|
---|
| 56 | column = gtk.TreeViewColumn(xstr("gates_planestatus"), gtk.CellRendererText(),
|
---|
| 57 | markup = 1)
|
---|
| 58 | column.set_expand(True)
|
---|
| 59 | column.set_sort_column_id(1)
|
---|
| 60 | self._fleetList.append_column(column)
|
---|
| 61 |
|
---|
| 62 | scrolledWindow = gtk.ScrolledWindow()
|
---|
| 63 | scrolledWindow.add(self._fleetList)
|
---|
| 64 | scrolledWindow.set_size_request(200, -1)
|
---|
| 65 | # FIXME: these should be constants in common.py
|
---|
| 66 | scrolledWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
|
---|
| 67 | else gtk.POLICY_AUTOMATIC,
|
---|
| 68 | gtk.PolicyType.AUTOMATIC if pygobject
|
---|
| 69 | else gtk.POLICY_AUTOMATIC)
|
---|
| 70 | scrolledWindow.set_shadow_type(gtk.ShadowType.IN if pygobject
|
---|
| 71 | else gtk.SHADOW_IN)
|
---|
| 72 |
|
---|
| 73 |
|
---|
[121] | 74 | self._fleetAlignment = alignment = \
|
---|
| 75 | gtk.Alignment(xalign = 0.5, yalign = 0.0,
|
---|
| 76 | xscale = 0.0, yscale = 1.0)
|
---|
[118] | 77 | alignment.set_padding(padding_top = 4, padding_bottom = 4,
|
---|
| 78 | padding_left = 4, padding_right = 4)
|
---|
| 79 | alignment.add(scrolledWindow)
|
---|
| 80 | fleetFrame.add(alignment)
|
---|
| 81 |
|
---|
| 82 | self._gatesFrame = gatesFrame = gtk.Frame(label = xstr("gates_gates_title"))
|
---|
| 83 | statusBox.pack_start(gatesFrame, True, True, 4)
|
---|
| 84 |
|
---|
[619] | 85 | self._gatesTable = table = gtk.Table(lhbpGates.numRows,
|
---|
| 86 | lhbpGates.numColumns)
|
---|
[118] | 87 | table.set_tooltip_markup(xstr("gates_gates_tooltip"))
|
---|
| 88 | alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
| 89 | xscale = 1.0, yscale = 1.0)
|
---|
| 90 | alignment.set_padding(padding_top = 4, padding_bottom = 4,
|
---|
| 91 | padding_left = 4, padding_right = 4)
|
---|
| 92 | alignment.add(table)
|
---|
| 93 | gatesFrame.add(alignment)
|
---|
| 94 |
|
---|
| 95 | self._gateLabels = {}
|
---|
| 96 | column = 0
|
---|
| 97 | row = 0
|
---|
[619] | 98 | for (type, data) in lhbpGates.displayInfos:
|
---|
| 99 | if type==Gates.DISPLAY_GATE:
|
---|
| 100 | gate = data
|
---|
| 101 |
|
---|
| 102 | label = gtk.Label()
|
---|
| 103 | label.set_markup("<b>" + gate.number + "</b>")
|
---|
| 104 | table.attach(label, column, column + 1, row, row + 1)
|
---|
[118] | 105 |
|
---|
[619] | 106 | self._gateLabels[gate.number] = label
|
---|
| 107 | row += 1
|
---|
| 108 | elif type==Gates.DISPLAY_SPACE:
|
---|
| 109 | row += 1
|
---|
| 110 | elif type==Gates.DISPLAY_NEW_COLUMN:
|
---|
| 111 | row = 0
|
---|
[118] | 112 | column += 1
|
---|
[619] | 113 |
|
---|
[118] | 114 | button = gtk.Button(xstr("gates_refresh"))
|
---|
| 115 | button.set_use_underline(True)
|
---|
| 116 | button.set_tooltip_text(xstr("gates_refresh_tooltip"))
|
---|
| 117 | button.connect("clicked", self._refreshClicked)
|
---|
| 118 |
|
---|
| 119 | alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
| 120 | xscale = 0.0, yscale = 0.0)
|
---|
| 121 | alignment.add(button)
|
---|
| 122 | mainBox.pack_start(alignment, False, False, 4)
|
---|
| 123 |
|
---|
[121] | 124 | self._fleetList.set_sensitive(False)
|
---|
| 125 | self._gatesTable.set_sensitive(False)
|
---|
[118] | 126 |
|
---|
| 127 | def disable(self):
|
---|
| 128 | """Disable the widget."""
|
---|
| 129 | self._mainBox.set_sensitive(False)
|
---|
| 130 |
|
---|
| 131 | def enable(self):
|
---|
| 132 | """Enable the widget."""
|
---|
| 133 | self._mainBox.set_sensitive(True)
|
---|
| 134 |
|
---|
| 135 | def _refreshClicked(self, button):
|
---|
| 136 | """Called when the Refresh data button is clicked."""
|
---|
[119] | 137 | self._gui.getFleet(force = True)
|
---|
| 138 |
|
---|
| 139 | def handleFleet(self, fleet):
|
---|
| 140 | """Handle new fleet information.
|
---|
[118] | 141 |
|
---|
[119] | 142 | If fleet is None, the data will be cleared."""
|
---|
| 143 | self._fleetStore.clear()
|
---|
| 144 | if fleet is None:
|
---|
[919] | 145 | for (gateNumber, label) in self._gateLabels.items():
|
---|
[119] | 146 | label.set_markup("<b>" + gateNumber + "</b>")
|
---|
| 147 | else:
|
---|
[118] | 148 | for plane in fleet:
|
---|
| 149 | conflicting = False
|
---|
| 150 | tailNumber = plane.tailNumber
|
---|
| 151 | if plane.status==const.PLANE_HOME:
|
---|
| 152 | status = "LHBP - %s" % (plane.gateNumber,)
|
---|
| 153 | conflicting = fleet.isGateConflicting(plane)
|
---|
| 154 | elif plane.status==const.PLANE_AWAY:
|
---|
| 155 | status = xstr("gates_plane_away")
|
---|
| 156 | elif plane.status==const.PLANE_PARKING:
|
---|
| 157 | status = xstr("gates_plane_parking")
|
---|
| 158 | else:
|
---|
| 159 | status = xstr("gates_plane_unknown")
|
---|
| 160 |
|
---|
| 161 | if conflicting:
|
---|
| 162 | tailNumber = '<span foreground="red">' + tailNumber + '</span>'
|
---|
| 163 | status = '<span foreground="red">' + status + '</span>'
|
---|
| 164 |
|
---|
| 165 | self._fleetStore.append([tailNumber, status])
|
---|
| 166 | # FIXME: this should be a constant in common.py
|
---|
| 167 | self._fleetStore.set_sort_column_id(0,
|
---|
| 168 | gtk.SortType.ASCENDING if pygobject
|
---|
| 169 | else gtk.SORT_ASCENDING)
|
---|
| 170 |
|
---|
| 171 | occupiedGateNumbers = fleet.getOccupiedGateNumbers()
|
---|
[619] | 172 | for gate in lhbpGates.gates:
|
---|
| 173 | gateNumber = gate.number
|
---|
[118] | 174 | markup = gateNumber
|
---|
| 175 | if gateNumber in occupiedGateNumbers:
|
---|
| 176 | markup = '<span foreground="orange">' + markup + '</span>'
|
---|
| 177 | markup = '<b>' + markup + '</b>'
|
---|
| 178 | self._gateLabels[gateNumber].set_markup(markup)
|
---|
| 179 |
|
---|
[121] | 180 | self._fleetList.set_sensitive(fleet is not None)
|
---|
| 181 | self._gatesTable.set_sensitive(fleet is not None)
|
---|
[118] | 182 |
|
---|
| 183 | #----------------------------------------------------------------------------
|
---|