[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 |
|
---|
[996] | 21 | class FleetGateStatus(Gtk.VBox):
|
---|
[118] | 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 |
|
---|
[996] | 29 | mainAlignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
[118] | 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 |
|
---|
[996] | 35 | self._mainBox = mainBox = Gtk.VBox()
|
---|
[118] | 36 | mainAlignment.add(mainBox)
|
---|
| 37 |
|
---|
[996] | 38 | self._statusBox = statusBox = Gtk.HBox()
|
---|
[118] | 39 | mainBox.pack_start(statusBox, True, True, 4)
|
---|
| 40 |
|
---|
[996] | 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 |
|
---|
[996] | 46 | self._fleetStore = Gtk.ListStore(str, str)
|
---|
| 47 | self._fleetList = Gtk.TreeView(self._fleetStore)
|
---|
[118] | 48 | self._fleetList.set_tooltip_markup(xstr("gates_planes_tooltip"))
|
---|
| 49 | fleetLabel.set_mnemonic_widget(self._fleetList)
|
---|
[996] | 50 | column = Gtk.TreeViewColumn(xstr("gates_tailno"), Gtk.CellRendererText(),
|
---|
[118] | 51 | text = 0)
|
---|
| 52 | column.set_expand(True)
|
---|
| 53 | column.set_sort_column_id(0)
|
---|
| 54 | self._fleetList.append_column(column)
|
---|
| 55 |
|
---|
[996] | 56 | column = Gtk.TreeViewColumn(xstr("gates_planestatus"), Gtk.CellRendererText(),
|
---|
[118] | 57 | markup = 1)
|
---|
| 58 | column.set_expand(True)
|
---|
| 59 | column.set_sort_column_id(1)
|
---|
| 60 | self._fleetList.append_column(column)
|
---|
| 61 |
|
---|
[996] | 62 | scrolledWindow = Gtk.ScrolledWindow()
|
---|
[118] | 63 | scrolledWindow.add(self._fleetList)
|
---|
| 64 | scrolledWindow.set_size_request(200, -1)
|
---|
| 65 | # FIXME: these should be constants in common.py
|
---|
[996] | 66 | scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC,
|
---|
| 67 | Gtk.PolicyType.AUTOMATIC)
|
---|
| 68 | scrolledWindow.set_shadow_type(Gtk.ShadowType.IN)
|
---|
[118] | 69 |
|
---|
| 70 |
|
---|
[121] | 71 | self._fleetAlignment = alignment = \
|
---|
[996] | 72 | Gtk.Alignment(xalign = 0.5, yalign = 0.0,
|
---|
[121] | 73 | xscale = 0.0, yscale = 1.0)
|
---|
[118] | 74 | alignment.set_padding(padding_top = 4, padding_bottom = 4,
|
---|
| 75 | padding_left = 4, padding_right = 4)
|
---|
| 76 | alignment.add(scrolledWindow)
|
---|
| 77 | fleetFrame.add(alignment)
|
---|
| 78 |
|
---|
[996] | 79 | self._gatesFrame = gatesFrame = Gtk.Frame(label = xstr("gates_gates_title"))
|
---|
[118] | 80 | statusBox.pack_start(gatesFrame, True, True, 4)
|
---|
| 81 |
|
---|
[996] | 82 | self._gatesTable = table = Gtk.Table(lhbpGates.numRows,
|
---|
[619] | 83 | lhbpGates.numColumns)
|
---|
[118] | 84 | table.set_tooltip_markup(xstr("gates_gates_tooltip"))
|
---|
[996] | 85 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
[118] | 86 | xscale = 1.0, yscale = 1.0)
|
---|
| 87 | alignment.set_padding(padding_top = 4, padding_bottom = 4,
|
---|
| 88 | padding_left = 4, padding_right = 4)
|
---|
| 89 | alignment.add(table)
|
---|
| 90 | gatesFrame.add(alignment)
|
---|
| 91 |
|
---|
| 92 | self._gateLabels = {}
|
---|
| 93 | column = 0
|
---|
| 94 | row = 0
|
---|
[619] | 95 | for (type, data) in lhbpGates.displayInfos:
|
---|
| 96 | if type==Gates.DISPLAY_GATE:
|
---|
| 97 | gate = data
|
---|
| 98 |
|
---|
[996] | 99 | label = Gtk.Label()
|
---|
[619] | 100 | label.set_markup("<b>" + gate.number + "</b>")
|
---|
| 101 | table.attach(label, column, column + 1, row, row + 1)
|
---|
[118] | 102 |
|
---|
[619] | 103 | self._gateLabels[gate.number] = label
|
---|
| 104 | row += 1
|
---|
| 105 | elif type==Gates.DISPLAY_SPACE:
|
---|
| 106 | row += 1
|
---|
| 107 | elif type==Gates.DISPLAY_NEW_COLUMN:
|
---|
| 108 | row = 0
|
---|
[118] | 109 | column += 1
|
---|
[619] | 110 |
|
---|
[996] | 111 | button = Gtk.Button(xstr("gates_refresh"))
|
---|
[118] | 112 | button.set_use_underline(True)
|
---|
| 113 | button.set_tooltip_text(xstr("gates_refresh_tooltip"))
|
---|
| 114 | button.connect("clicked", self._refreshClicked)
|
---|
| 115 |
|
---|
[996] | 116 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
[118] | 117 | xscale = 0.0, yscale = 0.0)
|
---|
| 118 | alignment.add(button)
|
---|
| 119 | mainBox.pack_start(alignment, False, False, 4)
|
---|
| 120 |
|
---|
[121] | 121 | self._fleetList.set_sensitive(False)
|
---|
| 122 | self._gatesTable.set_sensitive(False)
|
---|
[118] | 123 |
|
---|
| 124 | def disable(self):
|
---|
| 125 | """Disable the widget."""
|
---|
| 126 | self._mainBox.set_sensitive(False)
|
---|
| 127 |
|
---|
| 128 | def enable(self):
|
---|
| 129 | """Enable the widget."""
|
---|
| 130 | self._mainBox.set_sensitive(True)
|
---|
| 131 |
|
---|
| 132 | def _refreshClicked(self, button):
|
---|
| 133 | """Called when the Refresh data button is clicked."""
|
---|
[119] | 134 | self._gui.getFleet(force = True)
|
---|
| 135 |
|
---|
| 136 | def handleFleet(self, fleet):
|
---|
| 137 | """Handle new fleet information.
|
---|
[118] | 138 |
|
---|
[119] | 139 | If fleet is None, the data will be cleared."""
|
---|
| 140 | self._fleetStore.clear()
|
---|
| 141 | if fleet is None:
|
---|
[919] | 142 | for (gateNumber, label) in self._gateLabels.items():
|
---|
[119] | 143 | label.set_markup("<b>" + gateNumber + "</b>")
|
---|
| 144 | else:
|
---|
[118] | 145 | for plane in fleet:
|
---|
| 146 | conflicting = False
|
---|
| 147 | tailNumber = plane.tailNumber
|
---|
| 148 | if plane.status==const.PLANE_HOME:
|
---|
| 149 | status = "LHBP - %s" % (plane.gateNumber,)
|
---|
| 150 | conflicting = fleet.isGateConflicting(plane)
|
---|
| 151 | elif plane.status==const.PLANE_AWAY:
|
---|
| 152 | status = xstr("gates_plane_away")
|
---|
| 153 | elif plane.status==const.PLANE_PARKING:
|
---|
| 154 | status = xstr("gates_plane_parking")
|
---|
| 155 | else:
|
---|
| 156 | status = xstr("gates_plane_unknown")
|
---|
| 157 |
|
---|
| 158 | if conflicting:
|
---|
| 159 | tailNumber = '<span foreground="red">' + tailNumber + '</span>'
|
---|
| 160 | status = '<span foreground="red">' + status + '</span>'
|
---|
| 161 |
|
---|
| 162 | self._fleetStore.append([tailNumber, status])
|
---|
| 163 | # FIXME: this should be a constant in common.py
|
---|
[996] | 164 | self._fleetStore.set_sort_column_id(0, Gtk.SortType.ASCENDING)
|
---|
[118] | 165 |
|
---|
| 166 | occupiedGateNumbers = fleet.getOccupiedGateNumbers()
|
---|
[619] | 167 | for gate in lhbpGates.gates:
|
---|
| 168 | gateNumber = gate.number
|
---|
[118] | 169 | markup = gateNumber
|
---|
| 170 | if gateNumber in occupiedGateNumbers:
|
---|
| 171 | markup = '<span foreground="orange">' + markup + '</span>'
|
---|
| 172 | markup = '<b>' + markup + '</b>'
|
---|
| 173 | self._gateLabels[gateNumber].set_markup(markup)
|
---|
| 174 |
|
---|
[121] | 175 | self._fleetList.set_sensitive(fleet is not None)
|
---|
| 176 | self._gatesTable.set_sensitive(fleet is not None)
|
---|
[118] | 177 |
|
---|
| 178 | #----------------------------------------------------------------------------
|
---|