source: src/mlx/gui/statusbar.py@ 113:a3c4d9205538

Last change on this file since 113:a3c4d9205538 was 112:d8661c37cda9, checked in by István Váradi <ivaradi@…>, 13 years ago

Internationalized the status bar

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