source: src/mlx/gui/statusbar.py@ 357:95a02e0c97d3

Last change on this file since 357:95a02e0c97d3 was 300:f101bd18f39d, checked in by István Váradi <ivaradi@…>, 12 years ago

Added the module comments for the GUI

File size: 5.3 KB
Line 
1
2from common import *
3
4import mlx.const as const
5from mlx.i18n import xstr
6
7import math
8import time
9
10#-------------------------------------------------------------------------------
11
12## @package mlx.gui.statusbar
13#
14# The status bar.
15#
16# This module implements the status bar seen at the lower part of the main
17# window. It contains the icon depicting the status of the connection to the
18# simulator, the current flight stage, rating and the simulator time.
19
20#-------------------------------------------------------------------------------
21
22class Statusbar(gtk.Frame, FlightStatusHandler):
23 """A status bar for the logger."""
24 def __init__(self, iconDirectory):
25 """Construct the status bar."""
26 gtk.Frame.__init__(self)
27 FlightStatusHandler.__init__(self)
28
29 self._connecting = False
30 self._connected = False
31
32 self.set_shadow_type(gtk.ShadowType.NONE if pygobject
33 else gtk.SHADOW_NONE)
34
35 frameAlignment = gtk.Alignment(xscale = 1.0, yscale = 1.0)
36
37 frameAlignment.set_padding(padding_top = 2, padding_bottom = 2,
38 padding_left = 16, padding_right = 16)
39 self.add(frameAlignment)
40
41 statusBox = gtk.HBox()
42 frameAlignment.add(statusBox)
43
44 iconPath = os.path.join(iconDirectory, "conn_grey.png")
45 self._connGreyIcon = pixbuf_new_from_file(iconPath)
46
47 iconPath = os.path.join(iconDirectory, "conn_red.png")
48 self._connRedIcon = pixbuf_new_from_file(iconPath)
49
50 iconPath = os.path.join(iconDirectory, "conn_green.png")
51 self._connGreenIcon = pixbuf_new_from_file(iconPath)
52
53 self._connStateArea = gtk.DrawingArea()
54 self._connStateArea.set_size_request(18, 18)
55 self._connStateArea.set_tooltip_markup(xstr("statusbar_conn_tooltip"))
56
57 if pygobject:
58 self._connStateArea.connect("draw", self._drawConnState)
59 else:
60 self._connStateArea.connect("expose_event", self._drawConnState)
61
62 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5)
63 alignment.add(self._connStateArea)
64
65 statusBox.pack_start(alignment, False, False, 8)
66
67 statusBox.pack_start(gtk.VSeparator(), False, False, 8)
68
69 self._stageLabel = gtk.Label()
70 longestStage = xstr("flight_stage_" +
71 const.stage2string(const.STAGE_PUSHANDTAXI))
72 self._stageLabel.set_width_chars(len(longestStage) + 3)
73 self._stageLabel.set_tooltip_text(xstr("statusbar_stage_tooltip"))
74 self._stageLabel.set_alignment(0.0, 0.5)
75
76 statusBox.pack_start(self._stageLabel, False, False, 8)
77
78 statusBox.pack_start(gtk.VSeparator(), False, False, 8)
79
80 self._timeLabel = gtk.Label("--:--:--")
81 self._timeLabel.set_width_chars(8)
82 self._timeLabel.set_tooltip_text(xstr("statusbar_time_tooltip"))
83 self._timeLabel.set_alignment(1.0, 0.5)
84
85 statusBox.pack_start(self._timeLabel, False, False, 8)
86
87 statusBox.pack_start(gtk.VSeparator(), False, False, 8)
88
89 self._ratingLabel = gtk.Label()
90 self._ratingLabel.set_width_chars(12)
91 self._ratingLabel.set_tooltip_text(xstr("statusbar_rating_tooltip"))
92 self._ratingLabel.set_alignment(0.0, 0.5)
93
94 statusBox.pack_start(self._ratingLabel, False, False, 8)
95
96 self._busyLabel = gtk.Label()
97 self._busyLabel.set_width_chars(30)
98 self._busyLabel.set_tooltip_text(xstr("statusbar_busy_tooltip"))
99 self._busyLabel.set_alignment(1.0, 0.5)
100 statusBox.pack_start(self._busyLabel, True, True, 8)
101
102 self._updateFlightStatus()
103 self.updateTime()
104
105 def updateConnection(self, connecting, connected):
106 """Update the connection status."""
107 self._connecting = connecting
108 self._connected = connected
109 self._connStateArea.queue_draw()
110
111 def updateBusyState(self, message):
112 """Update the busy state."""
113 self._busyLabel.set_text("" if message is None else message)
114
115 def updateTime(self, t = None):
116 """Update the time"""
117 timeStr = "--:--:--" if t is None \
118 else time.strftime("%H:%M:%S", time.gmtime(t))
119
120 self._timeLabel.set_text(timeStr)
121
122 def _drawConnState(self, connStateArea, eventOrContext):
123 """Draw the connection state."""
124 if self._connecting:
125 if self._connected:
126 icon = self._connGreenIcon
127 else:
128 icon = self._connRedIcon
129 else:
130 icon = self._connGreyIcon
131
132 if pygobject:
133 gdk.cairo_set_source_pixbuf(eventOrContext, icon, 0, 0)
134 eventOrContext.paint()
135 else:
136 gc = connStateArea.get_style().fg_gc[gtk.STATE_NORMAL]
137 drawable = connStateArea.get_window()
138 drawable.draw_pixbuf(gc, icon, 0, 0, 0, 0)
139
140 def _updateFlightStatus(self):
141 """Update the flight status information."""
142 if self._stage is None:
143 text = "-"
144 else:
145 text = xstr("flight_stage_" + const.stage2string(self._stage)).upper()
146 self._stageLabel.set_text(text)
147
148 if self._noGoReason is None:
149 rating = "%.0f%%" % (self._rating,)
150 else:
151 rating = '<span foreground="red">' + self._noGoReason + '</span>'
152 self._ratingLabel.set_markup(rating)
Note: See TracBrowser for help on using the repository browser.