source: src/mlx/gui/statusbar.py@ 292:8528c186485c

Last change on this file since 292:8528c186485c was 281:c9e392a0a8b1, checked in by István Váradi <ivaradi@…>, 12 years ago

Using icons instead of a drawing for the connection state

File size: 5.1 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, iconDirectory):
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 iconPath = os.path.join(iconDirectory, "conn_grey.png")
38 self._connGreyIcon = pixbuf_new_from_file(iconPath)
39
40 iconPath = os.path.join(iconDirectory, "conn_red.png")
41 self._connRedIcon = pixbuf_new_from_file(iconPath)
42
43 iconPath = os.path.join(iconDirectory, "conn_green.png")
44 self._connGreenIcon = pixbuf_new_from_file(iconPath)
45
46 self._connStateArea = gtk.DrawingArea()
47 self._connStateArea.set_size_request(18, 18)
48 self._connStateArea.set_tooltip_markup(xstr("statusbar_conn_tooltip"))
49
50 if pygobject:
51 self._connStateArea.connect("draw", self._drawConnState)
52 else:
53 self._connStateArea.connect("expose_event", self._drawConnState)
54
55 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5)
56 alignment.add(self._connStateArea)
57
58 statusBox.pack_start(alignment, False, False, 8)
59
60 statusBox.pack_start(gtk.VSeparator(), False, False, 8)
61
62 self._stageLabel = gtk.Label()
63 longestStage = xstr("flight_stage_" +
64 const.stage2string(const.STAGE_PUSHANDTAXI))
65 self._stageLabel.set_width_chars(len(longestStage) + 3)
66 self._stageLabel.set_tooltip_text(xstr("statusbar_stage_tooltip"))
67 self._stageLabel.set_alignment(0.0, 0.5)
68
69 statusBox.pack_start(self._stageLabel, False, False, 8)
70
71 statusBox.pack_start(gtk.VSeparator(), False, False, 8)
72
73 self._timeLabel = gtk.Label("--:--:--")
74 self._timeLabel.set_width_chars(8)
75 self._timeLabel.set_tooltip_text(xstr("statusbar_time_tooltip"))
76 self._timeLabel.set_alignment(1.0, 0.5)
77
78 statusBox.pack_start(self._timeLabel, False, False, 8)
79
80 statusBox.pack_start(gtk.VSeparator(), False, False, 8)
81
82 self._ratingLabel = gtk.Label()
83 self._ratingLabel.set_width_chars(12)
84 self._ratingLabel.set_tooltip_text(xstr("statusbar_rating_tooltip"))
85 self._ratingLabel.set_alignment(0.0, 0.5)
86
87 statusBox.pack_start(self._ratingLabel, False, False, 8)
88
89 self._busyLabel = gtk.Label()
90 self._busyLabel.set_width_chars(30)
91 self._busyLabel.set_tooltip_text(xstr("statusbar_busy_tooltip"))
92 self._busyLabel.set_alignment(1.0, 0.5)
93 statusBox.pack_start(self._busyLabel, True, True, 8)
94
95 self._updateFlightStatus()
96 self.updateTime()
97
98 def updateConnection(self, connecting, connected):
99 """Update the connection status."""
100 self._connecting = connecting
101 self._connected = connected
102 self._connStateArea.queue_draw()
103
104 def updateBusyState(self, message):
105 """Update the busy state."""
106 self._busyLabel.set_text("" if message is None else message)
107
108 def updateTime(self, t = None):
109 """Update the time"""
110 timeStr = "--:--:--" if t is None \
111 else time.strftime("%H:%M:%S", time.gmtime(t))
112
113 self._timeLabel.set_text(timeStr)
114
115 def _drawConnState(self, connStateArea, eventOrContext):
116 """Draw the connection state."""
117 if self._connecting:
118 if self._connected:
119 icon = self._connGreenIcon
120 else:
121 icon = self._connRedIcon
122 else:
123 icon = self._connGreyIcon
124
125 if pygobject:
126 gdk.cairo_set_source_pixbuf(eventOrContext, icon, 0, 0)
127 eventOrContext.paint()
128 else:
129 gc = connStateArea.get_style().fg_gc[gtk.STATE_NORMAL]
130 drawable = connStateArea.get_window()
131 drawable.draw_pixbuf(gc, icon, 0, 0, 0, 0)
132
133 def _updateFlightStatus(self):
134 """Update the flight status information."""
135 if self._stage is None:
136 text = "-"
137 else:
138 text = xstr("flight_stage_" + const.stage2string(self._stage)).upper()
139 self._stageLabel.set_text(text)
140
141 if self._noGoReason is None:
142 rating = "%.0f%%" % (self._rating,)
143 else:
144 rating = '<span foreground="red">' + self._noGoReason + '</span>'
145 self._ratingLabel.set_markup(rating)
Note: See TracBrowser for help on using the repository browser.