source: src/mlx/gui/gates.py@ 138:bc4d9d192a7b

Last change on this file since 138:bc4d9d192a7b was 121:5ce72e33e807, checked in by István Váradi <ivaradi@…>, 13 years ago

Eliminated PyGObject assertion failures due to sensitivity setting

File size: 6.9 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 self._statusBox = statusBox = gtk.HBox()
30 mainBox.pack_start(statusBox, True, True, 4)
31
32 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 self._fleetAlignment = alignment = \
66 gtk.Alignment(xalign = 0.5, yalign = 0.0,
67 xscale = 0.0, yscale = 1.0)
68 alignment.set_padding(padding_top = 4, padding_bottom = 4,
69 padding_left = 4, padding_right = 4)
70 alignment.add(scrolledWindow)
71 fleetFrame.add(alignment)
72
73 self._gatesFrame = gatesFrame = gtk.Frame(label = xstr("gates_gates_title"))
74 statusBox.pack_start(gatesFrame, True, True, 4)
75
76 self._gatesTable = table = gtk.Table(14, 4)
77 table.set_tooltip_markup(xstr("gates_gates_tooltip"))
78 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
79 xscale = 1.0, yscale = 1.0)
80 alignment.set_padding(padding_top = 4, padding_bottom = 4,
81 padding_left = 4, padding_right = 4)
82 alignment.add(table)
83 gatesFrame.add(alignment)
84
85 self._gateLabels = {}
86 column = 0
87 row = 0
88 for gateNumber in const.lhbpGateNumbers:
89 label = gtk.Label()
90 label.set_markup("<b>" + gateNumber + "</b>")
91 table.attach(label, column, column + 1, row, row + 1)
92
93 self._gateLabels[gateNumber] = label
94
95 if column==1 and row==12:
96 column = 2
97 row = 1
98 elif row==13:
99 column += 1
100 row = 0
101 else:
102 row += 1
103
104 button = gtk.Button(xstr("gates_refresh"))
105 button.set_use_underline(True)
106 button.set_tooltip_text(xstr("gates_refresh_tooltip"))
107 button.connect("clicked", self._refreshClicked)
108
109 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
110 xscale = 0.0, yscale = 0.0)
111 alignment.add(button)
112 mainBox.pack_start(alignment, False, False, 4)
113
114 self._fleetList.set_sensitive(False)
115 self._gatesTable.set_sensitive(False)
116
117 def disable(self):
118 """Disable the widget."""
119 self._mainBox.set_sensitive(False)
120
121 def enable(self):
122 """Enable the widget."""
123 self._mainBox.set_sensitive(True)
124
125 def _refreshClicked(self, button):
126 """Called when the Refresh data button is clicked."""
127 self._gui.getFleet(force = True)
128
129 def handleFleet(self, fleet):
130 """Handle new fleet information.
131
132 If fleet is None, the data will be cleared."""
133 self._fleetStore.clear()
134 if fleet is None:
135 for (gateNumber, label) in self._gateLabels.iteritems():
136 label.set_markup("<b>" + gateNumber + "</b>")
137 else:
138 for plane in fleet:
139 conflicting = False
140 tailNumber = plane.tailNumber
141 if plane.status==const.PLANE_HOME:
142 status = "LHBP - %s" % (plane.gateNumber,)
143 conflicting = fleet.isGateConflicting(plane)
144 elif plane.status==const.PLANE_AWAY:
145 status = xstr("gates_plane_away")
146 elif plane.status==const.PLANE_PARKING:
147 status = xstr("gates_plane_parking")
148 else:
149 status = xstr("gates_plane_unknown")
150
151 if conflicting:
152 tailNumber = '<span foreground="red">' + tailNumber + '</span>'
153 status = '<span foreground="red">' + status + '</span>'
154
155 self._fleetStore.append([tailNumber, status])
156 # FIXME: this should be a constant in common.py
157 self._fleetStore.set_sort_column_id(0,
158 gtk.SortType.ASCENDING if pygobject
159 else gtk.SORT_ASCENDING)
160
161 occupiedGateNumbers = fleet.getOccupiedGateNumbers()
162 for gateNumber in const.lhbpGateNumbers:
163 markup = gateNumber
164 if gateNumber in occupiedGateNumbers:
165 markup = '<span foreground="orange">' + markup + '</span>'
166 markup = '<b>' + markup + '</b>'
167 self._gateLabels[gateNumber].set_markup(markup)
168
169 self._fleetList.set_sensitive(fleet is not None)
170 self._gatesTable.set_sensitive(fleet is not None)
171
172#----------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.