source: src/mlx/gui/statusbar.py

python3
Last change on this file 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
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
[996]22class Statusbar(Gtk.Frame, FlightStatusHandler):
[32]23 """A status bar for the logger."""
[281]24 def __init__(self, iconDirectory):
[32]25 """Construct the status bar."""
[996]26 Gtk.Frame.__init__(self)
[32]27 FlightStatusHandler.__init__(self)
28
29 self._connecting = False
30 self._connected = False
31
[996]32 self.set_shadow_type(Gtk.ShadowType.NONE)
[32]33
[996]34 frameAlignment = Gtk.Alignment(xscale = 1.0, yscale = 1.0)
[32]35
36 frameAlignment.set_padding(padding_top = 2, padding_bottom = 2,
37 padding_left = 16, padding_right = 16)
38 self.add(frameAlignment)
39
[996]40 statusBox = Gtk.HBox()
[32]41 frameAlignment.add(statusBox)
42
[281]43 iconPath = os.path.join(iconDirectory, "conn_grey.png")
[999]44 self._connGreyIcon = GdkPixbuf.Pixbuf.new_from_file(iconPath)
[281]45
46 iconPath = os.path.join(iconDirectory, "conn_red.png")
[999]47 self._connRedIcon = GdkPixbuf.Pixbuf.new_from_file(iconPath)
[281]48
49 iconPath = os.path.join(iconDirectory, "conn_green.png")
[999]50 self._connGreenIcon = GdkPixbuf.Pixbuf.new_from_file(iconPath)
[281]51
[996]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
[996]58 alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5)
[32]59 alignment.add(self._connStateArea)
60
61 statusBox.pack_start(alignment, False, False, 8)
62
[996]63 statusBox.pack_start(Gtk.VSeparator(), False, False, 8)
[32]64
[996]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
[996]74 statusBox.pack_start(Gtk.VSeparator(), False, False, 8)
[32]75
[996]76 self._timeLabel = Gtk.Label("--:--:--")
[80]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
[996]83 statusBox.pack_start(Gtk.VSeparator(), False, False, 8)
[80]84
[996]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
[996]92 self._busyLabel = Gtk.Label()
[49]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
[997]128 Gdk.cairo_set_source_pixbuf(eventOrContext, icon, 0, 0)
[994]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.