[90] | 1 |
|
---|
| 2 | from common import *
|
---|
| 3 |
|
---|
[433] | 4 | from mlx.gui.delaycodes import DelayCodeTable
|
---|
| 5 |
|
---|
[111] | 6 | from mlx.i18n import xstr
|
---|
[98] | 7 | import mlx.const as const
|
---|
| 8 |
|
---|
[123] | 9 | #------------------------------------------------------------------------------
|
---|
| 10 |
|
---|
[300] | 11 | ## @package mlx.gui.info
|
---|
| 12 | #
|
---|
| 13 | # The flight info tab.
|
---|
| 14 | #
|
---|
| 15 | # This module implements to \ref FlightInfo class, which is the widget for the
|
---|
| 16 | # extra information related to the flight. It contains text areas for the
|
---|
| 17 | # comments and the flight defects at the top next to each other, and the frame
|
---|
| 18 | # for the delay codes at the bottom in the centre.
|
---|
| 19 |
|
---|
| 20 | #------------------------------------------------------------------------------
|
---|
| 21 |
|
---|
[90] | 22 | class FlightInfo(gtk.VBox):
|
---|
| 23 | """The flight info tab."""
|
---|
[111] | 24 | @staticmethod
|
---|
[90] | 25 | def _createCommentArea(label):
|
---|
| 26 | """Create a comment area.
|
---|
| 27 |
|
---|
| 28 | Returns a tuple of two items:
|
---|
| 29 | - the top-level widget of the comment area, and
|
---|
| 30 | - the comment text editor."""
|
---|
| 31 |
|
---|
| 32 | frame = gtk.Frame(label = label)
|
---|
| 33 | label = frame.get_label_widget()
|
---|
| 34 | label.set_use_underline(True)
|
---|
| 35 |
|
---|
| 36 | alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
| 37 | xscale = 1.0, yscale = 1.0)
|
---|
| 38 | alignment.set_padding(padding_top = 4, padding_bottom = 4,
|
---|
| 39 | padding_left = 8, padding_right = 8)
|
---|
[349] | 40 |
|
---|
[90] | 41 | scroller = gtk.ScrolledWindow()
|
---|
[437] | 42 | scroller.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
|
---|
| 43 | scroller.set_shadow_type(SHADOW_IN)
|
---|
| 44 |
|
---|
[90] | 45 | comments = gtk.TextView()
|
---|
[127] | 46 | comments.set_wrap_mode(WRAP_WORD)
|
---|
[90] | 47 | scroller.add(comments)
|
---|
| 48 | alignment.add(scroller)
|
---|
| 49 | frame.add(alignment)
|
---|
| 50 |
|
---|
| 51 | label.set_mnemonic_widget(comments)
|
---|
| 52 |
|
---|
| 53 | return (frame, comments)
|
---|
| 54 |
|
---|
| 55 | def __init__(self, gui):
|
---|
| 56 | """Construct the flight info tab."""
|
---|
| 57 | super(FlightInfo, self).__init__()
|
---|
| 58 | self._gui = gui
|
---|
| 59 |
|
---|
[93] | 60 | self._commentsAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
| 61 | xscale = 1.0, yscale = 1.0)
|
---|
[90] | 62 | commentsBox = gtk.HBox()
|
---|
| 63 |
|
---|
[111] | 64 | (frame, self._comments) = FlightInfo._createCommentArea(xstr("info_comments"))
|
---|
[90] | 65 | commentsBox.pack_start(frame, True, True, 8)
|
---|
[349] | 66 | self._comments.get_buffer().connect("changed", self._commentsChanged)
|
---|
[90] | 67 |
|
---|
[111] | 68 | (frame, self._flightDefects) = \
|
---|
| 69 | FlightInfo._createCommentArea(xstr("info_defects"))
|
---|
[90] | 70 | commentsBox.pack_start(frame, True, True, 8)
|
---|
| 71 |
|
---|
[93] | 72 | self._commentsAlignment.add(commentsBox)
|
---|
| 73 | self.pack_start(self._commentsAlignment, True, True, 8)
|
---|
[90] | 74 |
|
---|
[111] | 75 | frame = gtk.Frame(label = xstr("info_delay"))
|
---|
[90] | 76 | label = frame.get_label_widget()
|
---|
| 77 | label.set_use_underline(True)
|
---|
| 78 |
|
---|
| 79 | alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
[441] | 80 | xscale = 1.0, yscale = 1.0)
|
---|
[90] | 81 | alignment.set_padding(padding_top = 4, padding_bottom = 4,
|
---|
| 82 | padding_left = 8, padding_right = 8)
|
---|
| 83 |
|
---|
[555] | 84 | self._delayCodeTable = table = DelayCodeTable(self)
|
---|
[433] | 85 | self._delayWindow = scrolledWindow = gtk.ScrolledWindow()
|
---|
| 86 | scrolledWindow.add(table)
|
---|
[441] | 87 | scrolledWindow.set_size_request(-1, 185)
|
---|
[434] | 88 | scrolledWindow.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
|
---|
| 89 | scrolledWindow.set_shadow_type(SHADOW_IN)
|
---|
[90] | 90 |
|
---|
[433] | 91 | alignment.add(scrolledWindow)
|
---|
[90] | 92 | frame.add(alignment)
|
---|
| 93 |
|
---|
[93] | 94 | self._delayAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
[441] | 95 | xscale = 1.0, yscale = 1.0)
|
---|
[93] | 96 | self._delayAlignment.add(frame)
|
---|
[441] | 97 | self._delayAlignment.set_padding(padding_top = 0, padding_bottom = 0,
|
---|
| 98 | padding_left = 8, padding_right = 8)
|
---|
[93] | 99 |
|
---|
| 100 | self.pack_start(self._delayAlignment, False, False, 8)
|
---|
[90] | 101 |
|
---|
[97] | 102 | @property
|
---|
| 103 | def comments(self):
|
---|
| 104 | """Get the comments."""
|
---|
| 105 | buffer = self._comments.get_buffer()
|
---|
| 106 | return text2unicode(buffer.get_text(buffer.get_start_iter(),
|
---|
| 107 | buffer.get_end_iter(), True))
|
---|
[349] | 108 |
|
---|
| 109 | @property
|
---|
| 110 | def hasComments(self):
|
---|
| 111 | """Get whether there is any text in comments field."""
|
---|
| 112 | return self._comments.get_buffer().get_char_count()>0
|
---|
| 113 |
|
---|
[97] | 114 | @property
|
---|
| 115 | def flightDefects(self):
|
---|
| 116 | """Get the flight defects."""
|
---|
| 117 | buffer = self._flightDefects.get_buffer()
|
---|
| 118 | return text2unicode(buffer.get_text(buffer.get_start_iter(),
|
---|
| 119 | buffer.get_end_iter(), True))
|
---|
| 120 |
|
---|
[99] | 121 | @property
|
---|
| 122 | def delayCodes(self):
|
---|
| 123 | """Get the list of delay codes checked by the user."""
|
---|
[437] | 124 | return self._delayCodeTable.delayCodes
|
---|
[349] | 125 |
|
---|
[555] | 126 | @property
|
---|
| 127 | def hasDelayCode(self):
|
---|
| 128 | """Determine if there is at least one delay code selected."""
|
---|
| 129 | return self._delayCodeTable.hasDelayCode
|
---|
| 130 |
|
---|
[436] | 131 | def enable(self, aircraftType):
|
---|
[93] | 132 | """Enable the flight info tab."""
|
---|
[122] | 133 | self._comments.set_sensitive(True)
|
---|
| 134 | self._flightDefects.set_sensitive(True)
|
---|
[437] | 135 | self._delayCodeTable.setType(aircraftType)
|
---|
[433] | 136 | self._delayWindow.set_sensitive(True)
|
---|
[437] | 137 | self._delayCodeTable.setStyle()
|
---|
[349] | 138 |
|
---|
[93] | 139 | def disable(self):
|
---|
| 140 | """Enable the flight info tab."""
|
---|
[122] | 141 | self._comments.set_sensitive(False)
|
---|
| 142 | self._flightDefects.set_sensitive(False)
|
---|
[433] | 143 | self._delayWindow.set_sensitive(False)
|
---|
[437] | 144 | self._delayCodeTable.setStyle()
|
---|
[90] | 145 |
|
---|
| 146 | def reset(self):
|
---|
| 147 | """Reset the flight info tab."""
|
---|
| 148 | self._comments.get_buffer().set_text("")
|
---|
| 149 | self._flightDefects.get_buffer().set_text("")
|
---|
[437] | 150 | self._delayCodeTable.reset()
|
---|
[349] | 151 |
|
---|
[555] | 152 | def delayCodesChanged(self):
|
---|
| 153 | """Callewd when the delay codes have changed."""
|
---|
| 154 | self._gui.delayCodesChanged()
|
---|
| 155 |
|
---|
[349] | 156 | def _commentsChanged(self, textbuffer):
|
---|
| 157 | """Called when the comments have changed."""
|
---|
[555] | 158 | self._gui.commentsChanged()
|
---|