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