1 | # Implementation of the status bar.
|
---|
2 |
|
---|
3 | #-------------------------------------------------------------------------------
|
---|
4 |
|
---|
5 | from common import *
|
---|
6 |
|
---|
7 | import mlx.const as const
|
---|
8 |
|
---|
9 | import math
|
---|
10 | import time
|
---|
11 |
|
---|
12 | #-------------------------------------------------------------------------------
|
---|
13 |
|
---|
14 | class Statusbar(gtk.Frame, FlightStatusHandler):
|
---|
15 | """A status bar for the logger."""
|
---|
16 | def __init__(self):
|
---|
17 | """Construct the status bar."""
|
---|
18 | gtk.Frame.__init__(self)
|
---|
19 | FlightStatusHandler.__init__(self)
|
---|
20 |
|
---|
21 | self._connecting = False
|
---|
22 | self._connected = False
|
---|
23 |
|
---|
24 | self.set_shadow_type(gtk.ShadowType.NONE if pygobject
|
---|
25 | else gtk.SHADOW_NONE)
|
---|
26 |
|
---|
27 | frameAlignment = gtk.Alignment(xscale = 1.0, yscale = 1.0)
|
---|
28 |
|
---|
29 | frameAlignment.set_padding(padding_top = 2, padding_bottom = 2,
|
---|
30 | padding_left = 16, padding_right = 16)
|
---|
31 | self.add(frameAlignment)
|
---|
32 |
|
---|
33 | statusBox = gtk.HBox()
|
---|
34 | frameAlignment.add(statusBox)
|
---|
35 |
|
---|
36 | self._connStateArea = gtk.DrawingArea()
|
---|
37 | self._connStateArea.set_size_request(16, 16)
|
---|
38 | self._connStateArea.set_tooltip_markup('The state of the connection.\n'
|
---|
39 | '<span foreground="grey">Grey</span> means idle.\n'
|
---|
40 | '<span foreground="red">Red</span> means trying to connect.\n'
|
---|
41 | '<span foreground="green">Green</span> means connected.')
|
---|
42 |
|
---|
43 | if pygobject:
|
---|
44 | self._connStateArea.connect("draw", self._drawConnState)
|
---|
45 | else:
|
---|
46 | self._connStateArea.connect("expose_event", self._drawConnState)
|
---|
47 |
|
---|
48 | alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5)
|
---|
49 | alignment.add(self._connStateArea)
|
---|
50 |
|
---|
51 | statusBox.pack_start(alignment, False, False, 8)
|
---|
52 |
|
---|
53 | statusBox.pack_start(gtk.VSeparator(), False, False, 8)
|
---|
54 |
|
---|
55 | self._stageLabel = gtk.Label()
|
---|
56 | self._stageLabel.set_width_chars(20)
|
---|
57 | self._stageLabel.set_tooltip_text("The flight stage")
|
---|
58 | self._stageLabel.set_alignment(0.0, 0.5)
|
---|
59 |
|
---|
60 | statusBox.pack_start(self._stageLabel, False, False, 8)
|
---|
61 |
|
---|
62 | statusBox.pack_start(gtk.VSeparator(), False, False, 8)
|
---|
63 |
|
---|
64 | self._timeLabel = gtk.Label("--:--:--")
|
---|
65 | self._timeLabel.set_width_chars(8)
|
---|
66 | self._timeLabel.set_tooltip_text("The simulator time in UTC")
|
---|
67 | self._timeLabel.set_alignment(1.0, 0.5)
|
---|
68 |
|
---|
69 | statusBox.pack_start(self._timeLabel, False, False, 8)
|
---|
70 |
|
---|
71 | statusBox.pack_start(gtk.VSeparator(), False, False, 8)
|
---|
72 |
|
---|
73 | self._ratingLabel = gtk.Label()
|
---|
74 | self._ratingLabel.set_width_chars(12)
|
---|
75 | self._ratingLabel.set_tooltip_text("The flight rating")
|
---|
76 | self._ratingLabel.set_alignment(0.0, 0.5)
|
---|
77 |
|
---|
78 | statusBox.pack_start(self._ratingLabel, False, False, 8)
|
---|
79 |
|
---|
80 | self._busyLabel = gtk.Label()
|
---|
81 | self._busyLabel.set_width_chars(30)
|
---|
82 | self._busyLabel.set_tooltip_text("The status of the background tasks.")
|
---|
83 | self._busyLabel.set_alignment(1.0, 0.5)
|
---|
84 | statusBox.pack_start(self._busyLabel, True, True, 8)
|
---|
85 |
|
---|
86 | self._updateFlightStatus()
|
---|
87 | self.updateTime()
|
---|
88 |
|
---|
89 | def updateConnection(self, connecting, connected):
|
---|
90 | """Update the connection status."""
|
---|
91 | self._connecting = connecting
|
---|
92 | self._connected = connected
|
---|
93 | self._connStateArea.queue_draw()
|
---|
94 |
|
---|
95 | def updateBusyState(self, message):
|
---|
96 | """Update the busy state."""
|
---|
97 | self._busyLabel.set_text("" if message is None else message)
|
---|
98 |
|
---|
99 | def updateTime(self, t = None):
|
---|
100 | """Update the time"""
|
---|
101 | timeStr = "--:--:--" if t is None \
|
---|
102 | else time.strftime("%H:%M:%S", time.gmtime(t))
|
---|
103 |
|
---|
104 | self._timeLabel.set_text(timeStr)
|
---|
105 |
|
---|
106 | def _drawConnState(self, connStateArea, eventOrContext):
|
---|
107 | """Draw the connection state."""
|
---|
108 | context = eventOrContext if pygobject else connStateArea.window.cairo_create()
|
---|
109 |
|
---|
110 | if self._connecting:
|
---|
111 | if self._connected:
|
---|
112 | context.set_source_rgb(0.0, 1.0, 0.0)
|
---|
113 | else:
|
---|
114 | context.set_source_rgb(1.0, 0.0, 0.0)
|
---|
115 | else:
|
---|
116 | context.set_source_rgb(0.75, 0.75, 0.75)
|
---|
117 |
|
---|
118 | width = connStateArea.get_allocated_width() if pygobject \
|
---|
119 | else connStateArea.allocation.width
|
---|
120 | height = connStateArea.get_allocated_height() if pygobject \
|
---|
121 | else connStateArea.allocation.height
|
---|
122 | context.arc(width/2, height/2, width/2, 0, 2*math.pi)
|
---|
123 |
|
---|
124 | context.fill()
|
---|
125 |
|
---|
126 | def _updateFlightStatus(self):
|
---|
127 | """Update the flight status information."""
|
---|
128 | self._stageLabel.set_text("-" if self._stage is None
|
---|
129 | else const.stage2string(self._stage).upper())
|
---|
130 |
|
---|
131 | if self._noGoReason is None:
|
---|
132 | rating = "%.0f%%" % (self._rating,)
|
---|
133 | else:
|
---|
134 | rating = '<span foreground="red">' + self._noGoReason + '</span>'
|
---|
135 | self._ratingLabel.set_markup(rating)
|
---|