[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
|
---|
| 25 | def _delayCodes():
|
---|
| 26 | """Get an array of delay codes."""
|
---|
| 27 | return [ (const.DELAYCODE_LOADING, xstr("info_delay_loading")),
|
---|
| 28 | (const.DELAYCODE_VATSIM, xstr("info_delay_vatsim")),
|
---|
| 29 | (const.DELAYCODE_NETWORK, xstr("info_delay_net")),
|
---|
| 30 | (const.DELAYCODE_CONTROLLER, xstr("info_delay_atc")),
|
---|
| 31 | (const.DELAYCODE_SYSTEM, xstr("info_delay_system")),
|
---|
| 32 | (const.DELAYCODE_NAVIGATION, xstr("info_delay_nav")),
|
---|
| 33 | (const.DELAYCODE_TRAFFIC, xstr("info_delay_traffic")),
|
---|
| 34 | (const.DELAYCODE_APRON, xstr("info_delay_apron")),
|
---|
| 35 | (const.DELAYCODE_WEATHER, xstr("info_delay_weather")),
|
---|
| 36 | (const.DELAYCODE_PERSONAL, xstr("info_delay_personal")) ]
|
---|
[349] | 37 |
|
---|
[90] | 38 | @staticmethod
|
---|
| 39 | def _createCommentArea(label):
|
---|
| 40 | """Create a comment area.
|
---|
| 41 |
|
---|
| 42 | Returns a tuple of two items:
|
---|
| 43 | - the top-level widget of the comment area, and
|
---|
| 44 | - the comment text editor."""
|
---|
| 45 |
|
---|
| 46 | frame = gtk.Frame(label = label)
|
---|
| 47 | label = frame.get_label_widget()
|
---|
| 48 | label.set_use_underline(True)
|
---|
| 49 |
|
---|
| 50 | alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
| 51 | xscale = 1.0, yscale = 1.0)
|
---|
| 52 | alignment.set_padding(padding_top = 4, padding_bottom = 4,
|
---|
| 53 | padding_left = 8, padding_right = 8)
|
---|
[349] | 54 |
|
---|
[90] | 55 | scroller = gtk.ScrolledWindow()
|
---|
[97] | 56 | # FIXME: these should be constants
|
---|
[90] | 57 | scroller.set_policy(gtk.PolicyType.AUTOMATIC if pygobject
|
---|
| 58 | else gtk.POLICY_AUTOMATIC,
|
---|
| 59 | gtk.PolicyType.AUTOMATIC if pygobject
|
---|
| 60 | else gtk.POLICY_AUTOMATIC)
|
---|
| 61 | scroller.set_shadow_type(gtk.ShadowType.IN if pygobject
|
---|
| 62 | else gtk.SHADOW_IN)
|
---|
| 63 | comments = gtk.TextView()
|
---|
[127] | 64 | comments.set_wrap_mode(WRAP_WORD)
|
---|
[90] | 65 | scroller.add(comments)
|
---|
| 66 | alignment.add(scroller)
|
---|
| 67 | frame.add(alignment)
|
---|
| 68 |
|
---|
| 69 | label.set_mnemonic_widget(comments)
|
---|
| 70 |
|
---|
| 71 | return (frame, comments)
|
---|
| 72 |
|
---|
| 73 | def __init__(self, gui):
|
---|
| 74 | """Construct the flight info tab."""
|
---|
| 75 | super(FlightInfo, self).__init__()
|
---|
| 76 | self._gui = gui
|
---|
| 77 |
|
---|
[93] | 78 | self._commentsAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
| 79 | xscale = 1.0, yscale = 1.0)
|
---|
[90] | 80 | commentsBox = gtk.HBox()
|
---|
| 81 |
|
---|
[111] | 82 | (frame, self._comments) = FlightInfo._createCommentArea(xstr("info_comments"))
|
---|
[90] | 83 | commentsBox.pack_start(frame, True, True, 8)
|
---|
[349] | 84 | self._comments.get_buffer().connect("changed", self._commentsChanged)
|
---|
[90] | 85 |
|
---|
[111] | 86 | (frame, self._flightDefects) = \
|
---|
| 87 | FlightInfo._createCommentArea(xstr("info_defects"))
|
---|
[90] | 88 | commentsBox.pack_start(frame, True, True, 8)
|
---|
| 89 |
|
---|
[93] | 90 | self._commentsAlignment.add(commentsBox)
|
---|
| 91 | self.pack_start(self._commentsAlignment, True, True, 8)
|
---|
[90] | 92 |
|
---|
[111] | 93 | frame = gtk.Frame(label = xstr("info_delay"))
|
---|
[90] | 94 | label = frame.get_label_widget()
|
---|
| 95 | label.set_use_underline(True)
|
---|
| 96 |
|
---|
| 97 | alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
| 98 | xscale = 0.0, yscale = 0.0)
|
---|
| 99 | alignment.set_padding(padding_top = 4, padding_bottom = 4,
|
---|
| 100 | padding_left = 8, padding_right = 8)
|
---|
| 101 |
|
---|
| 102 |
|
---|
[433] | 103 | # self._delayTable = table = gtk.Table(5, 2)
|
---|
| 104 | # table.set_col_spacings(16)
|
---|
| 105 |
|
---|
| 106 | # row = 0
|
---|
| 107 | # column = 0
|
---|
[90] | 108 |
|
---|
[433] | 109 | # self._delayCodeWidgets = []
|
---|
| 110 | # for (_code, label) in FlightInfo._delayCodes():
|
---|
| 111 | # button = gtk.CheckButton(label)
|
---|
| 112 | # button.set_use_underline(True)
|
---|
| 113 | # table.attach(button, column, column + 1, row, row + 1)
|
---|
| 114 | # self._delayCodeWidgets.append(button)
|
---|
| 115 | # if column==0:
|
---|
| 116 | # column += 1
|
---|
| 117 | # else:
|
---|
| 118 | # row += 1
|
---|
| 119 | # column = 0
|
---|
| 120 | self._delayTable = table = DelayCodeTable()
|
---|
| 121 | self._delayWindow = scrolledWindow = gtk.ScrolledWindow()
|
---|
| 122 | scrolledWindow.add(table)
|
---|
| 123 | scrolledWindow.set_size_request(400, 150)
|
---|
[434] | 124 | scrolledWindow.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
|
---|
| 125 | scrolledWindow.set_shadow_type(SHADOW_IN)
|
---|
[90] | 126 |
|
---|
[433] | 127 | alignment.add(scrolledWindow)
|
---|
[90] | 128 | frame.add(alignment)
|
---|
| 129 |
|
---|
[93] | 130 | self._delayAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
| 131 | xscale = 0.0, yscale = 0.0)
|
---|
| 132 | self._delayAlignment.add(frame)
|
---|
| 133 |
|
---|
| 134 | self.pack_start(self._delayAlignment, False, False, 8)
|
---|
[90] | 135 |
|
---|
[97] | 136 | @property
|
---|
| 137 | def comments(self):
|
---|
| 138 | """Get the comments."""
|
---|
| 139 | buffer = self._comments.get_buffer()
|
---|
| 140 | return text2unicode(buffer.get_text(buffer.get_start_iter(),
|
---|
| 141 | buffer.get_end_iter(), True))
|
---|
[349] | 142 |
|
---|
| 143 | @property
|
---|
| 144 | def hasComments(self):
|
---|
| 145 | """Get whether there is any text in comments field."""
|
---|
| 146 | return self._comments.get_buffer().get_char_count()>0
|
---|
| 147 |
|
---|
[97] | 148 | @property
|
---|
| 149 | def flightDefects(self):
|
---|
| 150 | """Get the flight defects."""
|
---|
| 151 | buffer = self._flightDefects.get_buffer()
|
---|
| 152 | return text2unicode(buffer.get_text(buffer.get_start_iter(),
|
---|
| 153 | buffer.get_end_iter(), True))
|
---|
| 154 |
|
---|
[99] | 155 | @property
|
---|
| 156 | def delayCodes(self):
|
---|
| 157 | """Get the list of delay codes checked by the user."""
|
---|
| 158 | codes = []
|
---|
[128] | 159 | delayCodes = FlightInfo._delayCodes()
|
---|
| 160 | for index in range(0, len(delayCodes)):
|
---|
[99] | 161 | if self._delayCodeWidgets[index].get_active():
|
---|
[128] | 162 | codes.append(delayCodes[index][0])
|
---|
[99] | 163 | return codes
|
---|
[349] | 164 |
|
---|
[436] | 165 | def enable(self, aircraftType):
|
---|
[93] | 166 | """Enable the flight info tab."""
|
---|
[122] | 167 | self._comments.set_sensitive(True)
|
---|
| 168 | self._flightDefects.set_sensitive(True)
|
---|
[436] | 169 | self._delayTable.setType(aircraftType)
|
---|
[433] | 170 | self._delayWindow.set_sensitive(True)
|
---|
[435] | 171 | self._delayTable.setStyle()
|
---|
[349] | 172 |
|
---|
[93] | 173 | def disable(self):
|
---|
| 174 | """Enable the flight info tab."""
|
---|
[122] | 175 | self._comments.set_sensitive(False)
|
---|
| 176 | self._flightDefects.set_sensitive(False)
|
---|
[433] | 177 | self._delayWindow.set_sensitive(False)
|
---|
[435] | 178 | self._delayTable.setStyle()
|
---|
[90] | 179 |
|
---|
| 180 | def reset(self):
|
---|
| 181 | """Reset the flight info tab."""
|
---|
| 182 | self._comments.get_buffer().set_text("")
|
---|
| 183 | self._flightDefects.get_buffer().set_text("")
|
---|
[436] | 184 | self._delayTable.reset()
|
---|
| 185 | # for widget in self._delayCodeWidgets:
|
---|
| 186 | # widget.set_active(False)
|
---|
[349] | 187 |
|
---|
| 188 | def _commentsChanged(self, textbuffer):
|
---|
| 189 | """Called when the comments have changed."""
|
---|
| 190 | self._gui.updateRTO(inLoop = True)
|
---|