source: src/mlx/gui/statusbar.py@ 77:cc8b178b8102

Last change on this file since 77:cc8b178b8102 was 70:64fb5caf4cad, checked in by István Váradi <ivaradi@…>, 13 years ago

Implemented two-way navigation between the wizard pages.

File size: 4.3 KB
Line 
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(12)
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._busyLabel = gtk.Label()
71 self._busyLabel.set_width_chars(30)
72 self._busyLabel.set_tooltip_text("The status of the background tasks.")
73 self._busyLabel.set_alignment(1.0, 0.5)
74 statusBox.pack_start(self._busyLabel, True, True, 8)
75
76 self._updateFlightStatus()
77
78 def updateConnection(self, connecting, connected):
79 """Update the connection status."""
80 self._connecting = connecting
81 self._connected = connected
82 self._connStateArea.queue_draw()
83
84 def updateBusyState(self, message):
85 """Update the busy state."""
86 self._busyLabel.set_text("" if message is None else message)
87
88 def _drawConnState(self, connStateArea, eventOrContext):
89 """Draw the connection state."""
90 context = eventOrContext if pygobject else connStateArea.window.cairo_create()
91
92 if self._connecting:
93 if self._connected:
94 context.set_source_rgb(0.0, 1.0, 0.0)
95 else:
96 context.set_source_rgb(1.0, 0.0, 0.0)
97 else:
98 context.set_source_rgb(0.75, 0.75, 0.75)
99
100 width = connStateArea.get_allocated_width() if pygobject \
101 else connStateArea.allocation.width
102 height = connStateArea.get_allocated_height() if pygobject \
103 else connStateArea.allocation.height
104 context.arc(width/2, height/2, width/2, 0, 2*math.pi)
105
106 context.fill()
107
108 def _updateFlightStatus(self):
109 """Update the flight status information."""
110 self._stageLabel.set_text("-" if self._stage is None
111 else const.stage2string(self._stage).upper())
112
113 if self._noGoReason is None:
114 rating = "%.0f%%" % (self._rating,)
115 else:
116 rating = '<span foreground="red">' + self._noGoReason + '</span>'
117 self._ratingLabel.set_markup(rating)
Note: See TracBrowser for help on using the repository browser.