[90] | 1 |
|
---|
| 2 | from common import *
|
---|
| 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 |
|
---|
[90] | 23 | class FlightInfo(gtk.VBox):
|
---|
| 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 |
|
---|
| 33 | frame = gtk.Frame(label = label)
|
---|
| 34 | label = frame.get_label_widget()
|
---|
| 35 | label.set_use_underline(True)
|
---|
| 36 |
|
---|
| 37 | alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
| 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 |
|
---|
[90] | 42 | scroller = gtk.ScrolledWindow()
|
---|
[437] | 43 | scroller.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
|
---|
| 44 | scroller.set_shadow_type(SHADOW_IN)
|
---|
| 45 |
|
---|
[90] | 46 | comments = gtk.TextView()
|
---|
[127] | 47 | comments.set_wrap_mode(WRAP_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 |
|
---|
| 56 | def __init__(self, gui):
|
---|
| 57 | """Construct the flight info tab."""
|
---|
| 58 | super(FlightInfo, self).__init__()
|
---|
| 59 | self._gui = gui
|
---|
| 60 |
|
---|
[93] | 61 | self._commentsAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
| 62 | xscale = 1.0, yscale = 1.0)
|
---|
[90] | 63 | commentsBox = gtk.HBox()
|
---|
[604] | 64 | commentsBox.set_homogeneous(True)
|
---|
[90] | 65 |
|
---|
[111] | 66 | (frame, self._comments) = FlightInfo._createCommentArea(xstr("info_comments"))
|
---|
[90] | 67 | commentsBox.pack_start(frame, True, True, 8)
|
---|
[349] | 68 | self._comments.get_buffer().connect("changed", self._commentsChanged)
|
---|
[90] | 69 |
|
---|
[620] | 70 | self._faultExplainWidget = FaultExplainWidget(gui)
|
---|
[605] | 71 | self._faultExplainWidget.connect("explanations-changed",
|
---|
| 72 | self._faultExplanationsChanged)
|
---|
[604] | 73 | commentsBox.pack_start(self._faultExplainWidget, True, True, 8)
|
---|
[90] | 74 |
|
---|
[93] | 75 | self._commentsAlignment.add(commentsBox)
|
---|
| 76 | self.pack_start(self._commentsAlignment, True, True, 8)
|
---|
[90] | 77 |
|
---|
[111] | 78 | frame = gtk.Frame(label = xstr("info_delay"))
|
---|
[90] | 79 | label = frame.get_label_widget()
|
---|
| 80 | label.set_use_underline(True)
|
---|
| 81 |
|
---|
| 82 | alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
[441] | 83 | xscale = 1.0, yscale = 1.0)
|
---|
[90] | 84 | alignment.set_padding(padding_top = 4, padding_bottom = 4,
|
---|
| 85 | padding_left = 8, padding_right = 8)
|
---|
| 86 |
|
---|
[555] | 87 | self._delayCodeTable = table = DelayCodeTable(self)
|
---|
[433] | 88 | self._delayWindow = scrolledWindow = gtk.ScrolledWindow()
|
---|
| 89 | scrolledWindow.add(table)
|
---|
[441] | 90 | scrolledWindow.set_size_request(-1, 185)
|
---|
[434] | 91 | scrolledWindow.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
|
---|
| 92 | scrolledWindow.set_shadow_type(SHADOW_IN)
|
---|
[90] | 93 |
|
---|
[433] | 94 | alignment.add(scrolledWindow)
|
---|
[90] | 95 | frame.add(alignment)
|
---|
| 96 |
|
---|
[93] | 97 | self._delayAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
[441] | 98 | xscale = 1.0, yscale = 1.0)
|
---|
[93] | 99 | self._delayAlignment.add(frame)
|
---|
[441] | 100 | self._delayAlignment.set_padding(padding_top = 0, padding_bottom = 0,
|
---|
| 101 | padding_left = 8, padding_right = 8)
|
---|
[93] | 102 |
|
---|
| 103 | self.pack_start(self._delayAlignment, False, False, 8)
|
---|
[90] | 104 |
|
---|
[97] | 105 | @property
|
---|
| 106 | def comments(self):
|
---|
| 107 | """Get the comments."""
|
---|
| 108 | buffer = self._comments.get_buffer()
|
---|
| 109 | return text2unicode(buffer.get_text(buffer.get_start_iter(),
|
---|
| 110 | buffer.get_end_iter(), True))
|
---|
[349] | 111 |
|
---|
| 112 | @property
|
---|
| 113 | def hasComments(self):
|
---|
| 114 | """Get whether there is any text in comments field."""
|
---|
| 115 | return self._comments.get_buffer().get_char_count()>0
|
---|
| 116 |
|
---|
[97] | 117 | @property
|
---|
[604] | 118 | def faultsAndExplanations(self):
|
---|
| 119 | """Get the faults and explanations as HTML."""
|
---|
| 120 | return self._faultExplainWidget.html
|
---|
[97] | 121 |
|
---|
[99] | 122 | @property
|
---|
| 123 | def delayCodes(self):
|
---|
| 124 | """Get the list of delay codes checked by the user."""
|
---|
[437] | 125 | return self._delayCodeTable.delayCodes
|
---|
[349] | 126 |
|
---|
[555] | 127 | @property
|
---|
| 128 | def hasDelayCode(self):
|
---|
| 129 | """Determine if there is at least one delay code selected."""
|
---|
| 130 | return self._delayCodeTable.hasDelayCode
|
---|
| 131 |
|
---|
[605] | 132 | @property
|
---|
| 133 | def faultsFullyExplained(self):
|
---|
| 134 | """Determine if all the faults have been explained by the pilot."""
|
---|
| 135 | return self._faultExplainWidget.fullyExplained
|
---|
| 136 |
|
---|
[604] | 137 | def addFault(self, id, faultText):
|
---|
| 138 | """Add a fault to the list of faults."""
|
---|
| 139 | self._faultExplainWidget.addFault(id, faultText)
|
---|
| 140 |
|
---|
| 141 | def updateFault(self, id, faultText):
|
---|
| 142 | """Update a fault to the list of faults."""
|
---|
| 143 | self._faultExplainWidget.updateFault(id, faultText)
|
---|
| 144 |
|
---|
| 145 | def clearFault(self, id):
|
---|
| 146 | """Clear a fault to the list of faults."""
|
---|
| 147 | self._faultExplainWidget.clearFault(id)
|
---|
| 148 |
|
---|
[436] | 149 | def enable(self, aircraftType):
|
---|
[93] | 150 | """Enable the flight info tab."""
|
---|
[122] | 151 | self._comments.set_sensitive(True)
|
---|
[604] | 152 | self._faultExplainWidget.set_sensitive(True)
|
---|
[437] | 153 | self._delayCodeTable.setType(aircraftType)
|
---|
[433] | 154 | self._delayWindow.set_sensitive(True)
|
---|
[437] | 155 | self._delayCodeTable.setStyle()
|
---|
[349] | 156 |
|
---|
[93] | 157 | def disable(self):
|
---|
| 158 | """Enable the flight info tab."""
|
---|
[122] | 159 | self._comments.set_sensitive(False)
|
---|
[604] | 160 | self._faultExplainWidget.set_sensitive(False)
|
---|
[433] | 161 | self._delayWindow.set_sensitive(False)
|
---|
[437] | 162 | self._delayCodeTable.setStyle()
|
---|
[90] | 163 |
|
---|
| 164 | def reset(self):
|
---|
| 165 | """Reset the flight info tab."""
|
---|
| 166 | self._comments.get_buffer().set_text("")
|
---|
[604] | 167 | self._faultExplainWidget.reset()
|
---|
[437] | 168 | self._delayCodeTable.reset()
|
---|
[349] | 169 |
|
---|
[555] | 170 | def delayCodesChanged(self):
|
---|
| 171 | """Callewd when the delay codes have changed."""
|
---|
| 172 | self._gui.delayCodesChanged()
|
---|
| 173 |
|
---|
[349] | 174 | def _commentsChanged(self, textbuffer):
|
---|
| 175 | """Called when the comments have changed."""
|
---|
[555] | 176 | self._gui.commentsChanged()
|
---|
[605] | 177 |
|
---|
| 178 | def _faultExplanationsChanged(self, faultExplainWidget, fullyExplained):
|
---|
| 179 | """Called when the status of the fault explanations has changed."""
|
---|
| 180 | self._gui.faultExplanationsChanged()
|
---|