source: src/mlx/gui/statusbar.py@ 994:e71fbf2ee978

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

Removed conditions on pygobject (re #347)

File size: 4.9 KB
RevLine 
[32]1
[919]2from .common import *
[32]3
4import mlx.const as const
[112]5from mlx.i18n import xstr
[32]6
7import math
[80]8import time
[32]9
10#-------------------------------------------------------------------------------
11
[300]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
[32]22class Statusbar(gtk.Frame, FlightStatusHandler):
23 """A status bar for the logger."""
[281]24 def __init__(self, iconDirectory):
[32]25 """Construct the status bar."""
26 gtk.Frame.__init__(self)
27 FlightStatusHandler.__init__(self)
28
29 self._connecting = False
30 self._connected = False
31
[994]32 self.set_shadow_type(gtk.ShadowType.NONE)
[32]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
[281]43 iconPath = os.path.join(iconDirectory, "conn_grey.png")
44 self._connGreyIcon = pixbuf_new_from_file(iconPath)
45
46 iconPath = os.path.join(iconDirectory, "conn_red.png")
47 self._connRedIcon = pixbuf_new_from_file(iconPath)
48
49 iconPath = os.path.join(iconDirectory, "conn_green.png")
50 self._connGreenIcon = pixbuf_new_from_file(iconPath)
51
[32]52 self._connStateArea = gtk.DrawingArea()
[281]53 self._connStateArea.set_size_request(18, 18)
[112]54 self._connStateArea.set_tooltip_markup(xstr("statusbar_conn_tooltip"))
[32]55
[994]56 self._connStateArea.connect("draw", self._drawConnState)
[32]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()
[112]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"))
[32]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
[80]76 self._timeLabel = gtk.Label("--:--:--")
77 self._timeLabel.set_width_chars(8)
[112]78 self._timeLabel.set_tooltip_text(xstr("statusbar_time_tooltip"))
[80]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
[32]85 self._ratingLabel = gtk.Label()
[679]86 self._ratingLabel.set_width_chars(20)
[112]87 self._ratingLabel.set_tooltip_text(xstr("statusbar_rating_tooltip"))
[32]88 self._ratingLabel.set_alignment(0.0, 0.5)
89
90 statusBox.pack_start(self._ratingLabel, False, False, 8)
91
[49]92 self._busyLabel = gtk.Label()
93 self._busyLabel.set_width_chars(30)
[112]94 self._busyLabel.set_tooltip_text(xstr("statusbar_busy_tooltip"))
[49]95 self._busyLabel.set_alignment(1.0, 0.5)
96 statusBox.pack_start(self._busyLabel, True, True, 8)
97
[32]98 self._updateFlightStatus()
[80]99 self.updateTime()
[32]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()
[49]106
107 def updateBusyState(self, message):
108 """Update the busy state."""
109 self._busyLabel.set_text("" if message is None else message)
[70]110
[80]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
[32]118 def _drawConnState(self, connStateArea, eventOrContext):
[281]119 """Draw the connection state."""
[32]120 if self._connecting:
121 if self._connected:
[281]122 icon = self._connGreenIcon
[32]123 else:
[281]124 icon = self._connRedIcon
[32]125 else:
[281]126 icon = self._connGreyIcon
[32]127
[994]128 gdk.cairo_set_source_pixbuf(eventOrContext, icon, 0, 0)
129 eventOrContext.paint()
[32]130
131 def _updateFlightStatus(self):
132 """Update the flight status information."""
[112]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)
[32]138
139 if self._noGoReason is None:
[404]140 rating = "%.1f%%" % (self._rating,)
[32]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.