source: src/mlx/gui/statusbar.py@ 33:a9150c8d2767

Last change on this file since 33:a9150c8d2767 was 32:46c1a12f72d1, checked in by István Váradi <ivaradi@…>, 13 years ago

Implemented the status bar.

File size: 3.9 KB
RevLine 
[32]1# Implementation of the status bar.
2
3#-------------------------------------------------------------------------------
4
5from common import *
6
7import mlx.const as const
8
9import math
10
11#-------------------------------------------------------------------------------
12
13class Statusbar(gtk.Frame, FlightStatusHandler):
14 """A status bar for the logger."""
15 def __init__(self):
16 """Construct the status bar."""
17 gtk.Frame.__init__(self)
18 FlightStatusHandler.__init__(self)
19
20 self._connecting = False
21 self._connected = False
22
23 self.set_shadow_type(gtk.ShadowType.NONE if pygobject
24 else gtk.SHADOW_NONE)
25
26 frameAlignment = gtk.Alignment(xscale = 1.0, yscale = 1.0)
27
28 frameAlignment.set_padding(padding_top = 2, padding_bottom = 2,
29 padding_left = 16, padding_right = 16)
30 self.add(frameAlignment)
31
32 statusBox = gtk.HBox()
33 frameAlignment.add(statusBox)
34
35 self._connStateArea = gtk.DrawingArea()
36 self._connStateArea.set_size_request(16, 16)
37 self._connStateArea.set_tooltip_markup('The state of the connection.\n'
38 '<span foreground="grey">Grey</span> means idle.\n'
39 '<span foreground="red">Red</span> means trying to connect.\n'
40 '<span foreground="green">Green</span> means connected.')
41
42 if pygobject:
43 self._connStateArea.connect("draw", self._drawConnState)
44 else:
45 self._connStateArea.connect("expose_event", self._drawConnState)
46
47 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5)
48 alignment.add(self._connStateArea)
49
50 statusBox.pack_start(alignment, False, False, 8)
51
52 statusBox.pack_start(gtk.VSeparator(), False, False, 8)
53
54 self._stageLabel = gtk.Label()
55 self._stageLabel.set_width_chars(20)
56 self._stageLabel.set_tooltip_text("The flight stage")
57 self._stageLabel.set_alignment(0.0, 0.5)
58
59 statusBox.pack_start(self._stageLabel, False, False, 8)
60
61 statusBox.pack_start(gtk.VSeparator(), False, False, 8)
62
63 self._ratingLabel = gtk.Label()
64 self._ratingLabel.set_width_chars(10)
65 self._ratingLabel.set_tooltip_text("The flight rating")
66 self._ratingLabel.set_alignment(0.0, 0.5)
67
68 statusBox.pack_start(self._ratingLabel, False, False, 8)
69
70 self._updateFlightStatus()
71
72 def updateConnection(self, connecting, connected):
73 """Update the connection status."""
74 self._connecting = connecting
75 self._connected = connected
76 self._connStateArea.queue_draw()
77
78 def _drawConnState(self, connStateArea, eventOrContext):
79 """Draw the connection state."""
80 context = eventOrContext if pygobject else connStateArea.window.cairo_create()
81
82 if self._connecting:
83 if self._connected:
84 context.set_source_rgb(0.0, 1.0, 0.0)
85 else:
86 context.set_source_rgb(1.0, 0.0, 0.0)
87 else:
88 context.set_source_rgb(0.75, 0.75, 0.75)
89
90 width = connStateArea.get_allocated_width() if pygobject \
91 else connStateArea.allocation.width
92 height = connStateArea.get_allocated_height() if pygobject \
93 else connStateArea.allocation.height
94 context.arc(width/2, height/2, width/2, 0, 2*math.pi)
95
96 context.fill()
97
98 def _updateFlightStatus(self):
99 """Update the flight status information."""
100 self._stageLabel.set_text("-" if self._stage is None
101 else const.stage2string(self._stage).upper())
102
103 if self._noGoReason is None:
104 rating = "%.0f%%" % (self._rating,)
105 else:
106 rating = '<span foreground="red">' + self._noGoReason + '</span>'
107 self._ratingLabel.set_markup(rating)
Note: See TracBrowser for help on using the repository browser.