source: src/mlx/gui/statusbar.py@ 1063:b2b67f680d11

python3
Last change on this file since 1063:b2b67f680d11 was 999:e096a5638b87, checked in by István Váradi <ivaradi@…>, 5 years ago

Removed Gtk 2/3 constant definitions (re #347)

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