source: src/mlx/gui/gates.py@ 1067:9ce88d0b881d

python3
Last change on this file since 1067:9ce88d0b881d was 996:8035d80d5feb, checked in by István Váradi <ivaradi@…>, 5 years ago

Using 'Gtk' instead of 'gtk' (re #347)

File size: 7.1 KB
Line 
1
2from mlx.gui.common import *
3
4from mlx.i18n import xstr
5import mlx.const as const
6from mlx.gates import Gates, lhbpGates
7
8#-------------------------------------------------------------------------------
9
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
21class 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
38 self._statusBox = statusBox = Gtk.HBox()
39 mainBox.pack_start(statusBox, True, True, 4)
40
41 fleetFrame = Gtk.Frame(label = xstr("gates_fleet_title"))
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,
67 Gtk.PolicyType.AUTOMATIC)
68 scrolledWindow.set_shadow_type(Gtk.ShadowType.IN)
69
70
71 self._fleetAlignment = alignment = \
72 Gtk.Alignment(xalign = 0.5, yalign = 0.0,
73 xscale = 0.0, yscale = 1.0)
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
79 self._gatesFrame = gatesFrame = Gtk.Frame(label = xstr("gates_gates_title"))
80 statusBox.pack_start(gatesFrame, True, True, 4)
81
82 self._gatesTable = table = Gtk.Table(lhbpGates.numRows,
83 lhbpGates.numColumns)
84 table.set_tooltip_markup(xstr("gates_gates_tooltip"))
85 alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
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
95 for (type, data) in lhbpGates.displayInfos:
96 if type==Gates.DISPLAY_GATE:
97 gate = data
98
99 label = Gtk.Label()
100 label.set_markup("<b>" + gate.number + "</b>")
101 table.attach(label, column, column + 1, row, row + 1)
102
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
109 column += 1
110
111 button = Gtk.Button(xstr("gates_refresh"))
112 button.set_use_underline(True)
113 button.set_tooltip_text(xstr("gates_refresh_tooltip"))
114 button.connect("clicked", self._refreshClicked)
115
116 alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
117 xscale = 0.0, yscale = 0.0)
118 alignment.add(button)
119 mainBox.pack_start(alignment, False, False, 4)
120
121 self._fleetList.set_sensitive(False)
122 self._gatesTable.set_sensitive(False)
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."""
134 self._gui.getFleet(force = True)
135
136 def handleFleet(self, fleet):
137 """Handle new fleet information.
138
139 If fleet is None, the data will be cleared."""
140 self._fleetStore.clear()
141 if fleet is None:
142 for (gateNumber, label) in self._gateLabels.items():
143 label.set_markup("<b>" + gateNumber + "</b>")
144 else:
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
164 self._fleetStore.set_sort_column_id(0, Gtk.SortType.ASCENDING)
165
166 occupiedGateNumbers = fleet.getOccupiedGateNumbers()
167 for gate in lhbpGates.gates:
168 gateNumber = gate.number
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
175 self._fleetList.set_sensitive(fleet is not None)
176 self._gatesTable.set_sensitive(fleet is not None)
177
178#----------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.