source: src/mlx/gui/statusbar.py@ 116:d2b6481a2857

Last change on this file since 116:d2b6481a2857 was 116:d2b6481a2857, checked in by István Váradi <ivaradi@…>, 12 years ago

Removed unnecessary printout

File size: 4.9 KB
RevLine 
[32]1# Implementation of the status bar.
2
3#-------------------------------------------------------------------------------
4
5from common import *
6
7import mlx.const as const
[112]8from mlx.i18n import xstr
[32]9
10import math
[80]11import time
[32]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)
[112]39 self._connStateArea.set_tooltip_markup(xstr("statusbar_conn_tooltip"))
[32]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()
[112]54 longestStage = xstr("flight_stage_" +
55 const.stage2string(const.STAGE_PUSHANDTAXI))
56 self._stageLabel.set_width_chars(len(longestStage) + 3)
57 self._stageLabel.set_tooltip_text(xstr("statusbar_stage_tooltip"))
[32]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
[80]64 self._timeLabel = gtk.Label("--:--:--")
65 self._timeLabel.set_width_chars(8)
[112]66 self._timeLabel.set_tooltip_text(xstr("statusbar_time_tooltip"))
[80]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
[32]73 self._ratingLabel = gtk.Label()
[70]74 self._ratingLabel.set_width_chars(12)
[112]75 self._ratingLabel.set_tooltip_text(xstr("statusbar_rating_tooltip"))
[32]76 self._ratingLabel.set_alignment(0.0, 0.5)
77
78 statusBox.pack_start(self._ratingLabel, False, False, 8)
79
[49]80 self._busyLabel = gtk.Label()
81 self._busyLabel.set_width_chars(30)
[112]82 self._busyLabel.set_tooltip_text(xstr("statusbar_busy_tooltip"))
[49]83 self._busyLabel.set_alignment(1.0, 0.5)
84 statusBox.pack_start(self._busyLabel, True, True, 8)
85
[32]86 self._updateFlightStatus()
[80]87 self.updateTime()
[32]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()
[49]94
95 def updateBusyState(self, message):
96 """Update the busy state."""
97 self._busyLabel.set_text("" if message is None else message)
[70]98
[80]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
[32]106 def _drawConnState(self, connStateArea, eventOrContext):
[59]107 """Draw the connection state."""
[32]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."""
[112]128 if self._stage is None:
129 text = "-"
130 else:
131 text = xstr("flight_stage_" + const.stage2string(self._stage)).upper()
132 self._stageLabel.set_text(text)
[32]133
134 if self._noGoReason is None:
135 rating = "%.0f%%" % (self._rating,)
136 else:
137 rating = '<span foreground="red">' + self._noGoReason + '</span>'
138 self._ratingLabel.set_markup(rating)
Note: See TracBrowser for help on using the repository browser.