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