[90] | 1 |
|
---|
[919] | 2 | from .common import *
|
---|
[90] | 3 |
|
---|
[433] | 4 | from mlx.gui.delaycodes import DelayCodeTable
|
---|
[604] | 5 | from mlx.gui.faultexplain import FaultExplainWidget
|
---|
[433] | 6 |
|
---|
[111] | 7 | from mlx.i18n import xstr
|
---|
[98] | 8 | import mlx.const as const
|
---|
| 9 |
|
---|
[123] | 10 | #------------------------------------------------------------------------------
|
---|
| 11 |
|
---|
[300] | 12 | ## @package mlx.gui.info
|
---|
| 13 | #
|
---|
| 14 | # The flight info tab.
|
---|
| 15 | #
|
---|
| 16 | # This module implements to \ref FlightInfo class, which is the widget for the
|
---|
[604] | 17 | # extra information related to the flight. It contains a text area for the
|
---|
| 18 | # comments, the fault list widget, and the frame for the delay codes at the
|
---|
| 19 | # bottom in the centre.
|
---|
[300] | 20 |
|
---|
| 21 | #------------------------------------------------------------------------------
|
---|
| 22 |
|
---|
[996] | 23 | class FlightInfo(Gtk.VBox):
|
---|
[90] | 24 | """The flight info tab."""
|
---|
[111] | 25 | @staticmethod
|
---|
[90] | 26 | def _createCommentArea(label):
|
---|
| 27 | """Create a comment area.
|
---|
| 28 |
|
---|
| 29 | Returns a tuple of two items:
|
---|
| 30 | - the top-level widget of the comment area, and
|
---|
| 31 | - the comment text editor."""
|
---|
| 32 |
|
---|
[996] | 33 | frame = Gtk.Frame(label = label)
|
---|
[90] | 34 | label = frame.get_label_widget()
|
---|
| 35 | label.set_use_underline(True)
|
---|
| 36 |
|
---|
[996] | 37 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
[90] | 38 | xscale = 1.0, yscale = 1.0)
|
---|
| 39 | alignment.set_padding(padding_top = 4, padding_bottom = 4,
|
---|
| 40 | padding_left = 8, padding_right = 8)
|
---|
[349] | 41 |
|
---|
[996] | 42 | scroller = Gtk.ScrolledWindow()
|
---|
[999] | 43 | scroller.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
|
---|
| 44 | scroller.set_shadow_type(Gtk.ShadowType.IN)
|
---|
[437] | 45 |
|
---|
[996] | 46 | comments = Gtk.TextView()
|
---|
[999] | 47 | comments.set_wrap_mode(Gtk.WrapMode.WORD)
|
---|
[90] | 48 | scroller.add(comments)
|
---|
| 49 | alignment.add(scroller)
|
---|
| 50 | frame.add(alignment)
|
---|
| 51 |
|
---|
| 52 | label.set_mnemonic_widget(comments)
|
---|
| 53 |
|
---|
| 54 | return (frame, comments)
|
---|
| 55 |
|
---|
[846] | 56 | def __init__(self, gui, callbackObject = None):
|
---|
[90] | 57 | """Construct the flight info tab."""
|
---|
| 58 | super(FlightInfo, self).__init__()
|
---|
| 59 | self._gui = gui
|
---|
[846] | 60 | self._callbackObject = callbackObject
|
---|
[90] | 61 |
|
---|
[996] | 62 | self._commentsAlignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
[93] | 63 | xscale = 1.0, yscale = 1.0)
|
---|
[996] | 64 | commentsBox = Gtk.HBox()
|
---|
[604] | 65 | commentsBox.set_homogeneous(True)
|
---|
[90] | 66 |
|
---|
[111] | 67 | (frame, self._comments) = FlightInfo._createCommentArea(xstr("info_comments"))
|
---|
[90] | 68 | commentsBox.pack_start(frame, True, True, 8)
|
---|
[349] | 69 | self._comments.get_buffer().connect("changed", self._commentsChanged)
|
---|
[90] | 70 |
|
---|
[620] | 71 | self._faultExplainWidget = FaultExplainWidget(gui)
|
---|
[605] | 72 | self._faultExplainWidget.connect("explanations-changed",
|
---|
| 73 | self._faultExplanationsChanged)
|
---|
[604] | 74 | commentsBox.pack_start(self._faultExplainWidget, True, True, 8)
|
---|
[90] | 75 |
|
---|
[93] | 76 | self._commentsAlignment.add(commentsBox)
|
---|
| 77 | self.pack_start(self._commentsAlignment, True, True, 8)
|
---|
[90] | 78 |
|
---|
[996] | 79 | frame = Gtk.Frame(label = xstr("info_delay"))
|
---|
[90] | 80 | label = frame.get_label_widget()
|
---|
| 81 | label.set_use_underline(True)
|
---|
| 82 |
|
---|
[996] | 83 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
[441] | 84 | xscale = 1.0, yscale = 1.0)
|
---|
[90] | 85 | alignment.set_padding(padding_top = 4, padding_bottom = 4,
|
---|
| 86 | padding_left = 8, padding_right = 8)
|
---|
| 87 |
|
---|
[555] | 88 | self._delayCodeTable = table = DelayCodeTable(self)
|
---|
[996] | 89 | self._delayWindow = scrolledWindow = Gtk.ScrolledWindow()
|
---|
[433] | 90 | scrolledWindow.add(table)
|
---|
[441] | 91 | scrolledWindow.set_size_request(-1, 185)
|
---|
[999] | 92 | scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC,
|
---|
| 93 | Gtk.PolicyType.AUTOMATIC)
|
---|
| 94 | scrolledWindow.set_shadow_type(Gtk.ShadowType.IN)
|
---|
[90] | 95 |
|
---|
[433] | 96 | alignment.add(scrolledWindow)
|
---|
[90] | 97 | frame.add(alignment)
|
---|
| 98 |
|
---|
[996] | 99 | self._delayAlignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
[441] | 100 | xscale = 1.0, yscale = 1.0)
|
---|
[93] | 101 | self._delayAlignment.add(frame)
|
---|
[441] | 102 | self._delayAlignment.set_padding(padding_top = 0, padding_bottom = 0,
|
---|
| 103 | padding_left = 8, padding_right = 8)
|
---|
[93] | 104 |
|
---|
| 105 | self.pack_start(self._delayAlignment, False, False, 8)
|
---|
[90] | 106 |
|
---|
[97] | 107 | @property
|
---|
| 108 | def comments(self):
|
---|
| 109 | """Get the comments."""
|
---|
| 110 | buffer = self._comments.get_buffer()
|
---|
[954] | 111 | return buffer.get_text(buffer.get_start_iter(),
|
---|
| 112 | buffer.get_end_iter(), True)
|
---|
[349] | 113 |
|
---|
[843] | 114 | @comments.setter
|
---|
| 115 | def comments(self, comments):
|
---|
| 116 | """Set the comments."""
|
---|
| 117 | self._comments.get_buffer().set_text(comments)
|
---|
| 118 |
|
---|
[349] | 119 | @property
|
---|
| 120 | def hasComments(self):
|
---|
| 121 | """Get whether there is any text in comments field."""
|
---|
| 122 | return self._comments.get_buffer().get_char_count()>0
|
---|
| 123 |
|
---|
[97] | 124 | @property
|
---|
[604] | 125 | def faultsAndExplanations(self):
|
---|
| 126 | """Get the faults and explanations as HTML."""
|
---|
| 127 | return self._faultExplainWidget.html
|
---|
[97] | 128 |
|
---|
[99] | 129 | @property
|
---|
| 130 | def delayCodes(self):
|
---|
| 131 | """Get the list of delay codes checked by the user."""
|
---|
[437] | 132 | return self._delayCodeTable.delayCodes
|
---|
[349] | 133 |
|
---|
[555] | 134 | @property
|
---|
| 135 | def hasDelayCode(self):
|
---|
| 136 | """Determine if there is at least one delay code selected."""
|
---|
| 137 | return self._delayCodeTable.hasDelayCode
|
---|
| 138 |
|
---|
[605] | 139 | @property
|
---|
| 140 | def faultsFullyExplained(self):
|
---|
| 141 | """Determine if all the faults have been explained by the pilot."""
|
---|
| 142 | return self._faultExplainWidget.fullyExplained
|
---|
| 143 |
|
---|
[604] | 144 | def addFault(self, id, faultText):
|
---|
| 145 | """Add a fault to the list of faults."""
|
---|
| 146 | self._faultExplainWidget.addFault(id, faultText)
|
---|
| 147 |
|
---|
| 148 | def updateFault(self, id, faultText):
|
---|
| 149 | """Update a fault to the list of faults."""
|
---|
| 150 | self._faultExplainWidget.updateFault(id, faultText)
|
---|
| 151 |
|
---|
| 152 | def clearFault(self, id):
|
---|
| 153 | """Clear a fault to the list of faults."""
|
---|
| 154 | self._faultExplainWidget.clearFault(id)
|
---|
| 155 |
|
---|
[841] | 156 | def setExplanation(self, id, explanation):
|
---|
| 157 | """Set the explanation of the given fault."""
|
---|
| 158 | self._faultExplainWidget.setExplanation(id, explanation)
|
---|
| 159 |
|
---|
[436] | 160 | def enable(self, aircraftType):
|
---|
[93] | 161 | """Enable the flight info tab."""
|
---|
[122] | 162 | self._comments.set_sensitive(True)
|
---|
[604] | 163 | self._faultExplainWidget.set_sensitive(True)
|
---|
[437] | 164 | self._delayCodeTable.setType(aircraftType)
|
---|
[433] | 165 | self._delayWindow.set_sensitive(True)
|
---|
[437] | 166 | self._delayCodeTable.setStyle()
|
---|
[349] | 167 |
|
---|
[93] | 168 | def disable(self):
|
---|
| 169 | """Enable the flight info tab."""
|
---|
[122] | 170 | self._comments.set_sensitive(False)
|
---|
[604] | 171 | self._faultExplainWidget.set_sensitive(False)
|
---|
[433] | 172 | self._delayWindow.set_sensitive(False)
|
---|
[437] | 173 | self._delayCodeTable.setStyle()
|
---|
[90] | 174 |
|
---|
| 175 | def reset(self):
|
---|
| 176 | """Reset the flight info tab."""
|
---|
| 177 | self._comments.get_buffer().set_text("")
|
---|
[604] | 178 | self._faultExplainWidget.reset()
|
---|
[437] | 179 | self._delayCodeTable.reset()
|
---|
[349] | 180 |
|
---|
[840] | 181 | def activateDelayCode(self, code):
|
---|
| 182 | """Active the checkbox corresponding to the given code."""
|
---|
| 183 | self._delayCodeTable.activateCode(code)
|
---|
| 184 |
|
---|
[555] | 185 | def delayCodesChanged(self):
|
---|
| 186 | """Callewd when the delay codes have changed."""
|
---|
[846] | 187 | if self._callbackObject is None:
|
---|
[844] | 188 | self._gui.delayCodesChanged()
|
---|
[846] | 189 | else:
|
---|
| 190 | self._callbackObject.delayCodesChanged()
|
---|
[555] | 191 |
|
---|
[349] | 192 | def _commentsChanged(self, textbuffer):
|
---|
| 193 | """Called when the comments have changed."""
|
---|
[846] | 194 | if self._callbackObject is None:
|
---|
[844] | 195 | self._gui.commentsChanged()
|
---|
[846] | 196 | else:
|
---|
| 197 | self._callbackObject.commentsChanged()
|
---|
[605] | 198 |
|
---|
| 199 | def _faultExplanationsChanged(self, faultExplainWidget, fullyExplained):
|
---|
| 200 | """Called when the status of the fault explanations has changed."""
|
---|
[846] | 201 | if self._callbackObject is None:
|
---|
[844] | 202 | self._gui.faultExplanationsChanged()
|
---|
[846] | 203 | else:
|
---|
| 204 | self._callbackObject.faultExplanationsChanged()
|
---|