source: src/mlx/gui/gates.py@ 119:0185f1446770

Last change on this file since 119:0185f1446770 was 119:0185f1446770, checked in by István Váradi <ivaradi@…>, 13 years ago

The fleet is now retrieved centrally and is updated on the Gates page all the time

File size: 6.8 KB
Line 
1# Module to display the status of the planes and the gates
2
3#----------------------------------------------------------------------------
4
5from mlx.gui.common import *
6
7from mlx.i18n import xstr
8import mlx.const as const
9
10#-------------------------------------------------------------------------------
11
12class 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.getFleet(force = True)
127
128 def handleFleet(self, fleet):
129 """Handle new fleet information.
130
131 If fleet is None, the data will be cleared."""
132 self._fleetStore.clear()
133 if fleet is None:
134 for (gateNumber, label) in self._gateLabels.iteritems():
135 label.set_markup("<b>" + gateNumber + "</b>")
136 else:
137 for plane in fleet:
138 conflicting = False
139 tailNumber = plane.tailNumber
140 if plane.status==const.PLANE_HOME:
141 status = "LHBP - %s" % (plane.gateNumber,)
142 conflicting = fleet.isGateConflicting(plane)
143 elif plane.status==const.PLANE_AWAY:
144 status = xstr("gates_plane_away")
145 elif plane.status==const.PLANE_PARKING:
146 status = xstr("gates_plane_parking")
147 else:
148 status = xstr("gates_plane_unknown")
149
150 if conflicting:
151 tailNumber = '<span foreground="red">' + tailNumber + '</span>'
152 status = '<span foreground="red">' + status + '</span>'
153
154 self._fleetStore.append([tailNumber, status])
155 # FIXME: this should be a constant in common.py
156 self._fleetStore.set_sort_column_id(0,
157 gtk.SortType.ASCENDING if pygobject
158 else gtk.SORT_ASCENDING)
159
160 occupiedGateNumbers = fleet.getOccupiedGateNumbers()
161 for gateNumber in const.lhbpGateNumbers:
162 markup = gateNumber
163 if gateNumber in occupiedGateNumbers:
164 markup = '<span foreground="orange">' + markup + '</span>'
165 markup = '<b>' + markup + '</b>'
166 self._gateLabels[gateNumber].set_markup(markup)
167
168 self._fleetFrame.set_sensitive(fleet is not None)
169 self._gatesFrame.set_sensitive(fleet is not None)
170
171
172#----------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.