1 |
|
---|
2 | from common import *
|
---|
3 |
|
---|
4 | from mlx.gui.delaycodes import DelayCodeTable
|
---|
5 |
|
---|
6 | from mlx.i18n import xstr
|
---|
7 | import mlx.const as const
|
---|
8 |
|
---|
9 | #------------------------------------------------------------------------------
|
---|
10 |
|
---|
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 |
|
---|
22 | class FlightInfo(gtk.VBox):
|
---|
23 | """The flight info tab."""
|
---|
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")) ]
|
---|
37 |
|
---|
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)
|
---|
54 |
|
---|
55 | scroller = gtk.ScrolledWindow()
|
---|
56 | # FIXME: these should be constants
|
---|
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()
|
---|
64 | comments.set_wrap_mode(WRAP_WORD)
|
---|
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 |
|
---|
78 | self._commentsAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
79 | xscale = 1.0, yscale = 1.0)
|
---|
80 | commentsBox = gtk.HBox()
|
---|
81 |
|
---|
82 | (frame, self._comments) = FlightInfo._createCommentArea(xstr("info_comments"))
|
---|
83 | commentsBox.pack_start(frame, True, True, 8)
|
---|
84 | self._comments.get_buffer().connect("changed", self._commentsChanged)
|
---|
85 |
|
---|
86 | (frame, self._flightDefects) = \
|
---|
87 | FlightInfo._createCommentArea(xstr("info_defects"))
|
---|
88 | commentsBox.pack_start(frame, True, True, 8)
|
---|
89 |
|
---|
90 | self._commentsAlignment.add(commentsBox)
|
---|
91 | self.pack_start(self._commentsAlignment, True, True, 8)
|
---|
92 |
|
---|
93 | frame = gtk.Frame(label = xstr("info_delay"))
|
---|
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 |
|
---|
103 | # self._delayTable = table = gtk.Table(5, 2)
|
---|
104 | # table.set_col_spacings(16)
|
---|
105 |
|
---|
106 | # row = 0
|
---|
107 | # column = 0
|
---|
108 |
|
---|
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)
|
---|
124 | scrolledWindow.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
|
---|
125 | scrolledWindow.set_shadow_type(SHADOW_IN)
|
---|
126 |
|
---|
127 | alignment.add(scrolledWindow)
|
---|
128 | frame.add(alignment)
|
---|
129 |
|
---|
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)
|
---|
135 |
|
---|
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))
|
---|
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 |
|
---|
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 |
|
---|
155 | @property
|
---|
156 | def delayCodes(self):
|
---|
157 | """Get the list of delay codes checked by the user."""
|
---|
158 | codes = []
|
---|
159 | delayCodes = FlightInfo._delayCodes()
|
---|
160 | for index in range(0, len(delayCodes)):
|
---|
161 | if self._delayCodeWidgets[index].get_active():
|
---|
162 | codes.append(delayCodes[index][0])
|
---|
163 | return codes
|
---|
164 |
|
---|
165 | def enable(self):
|
---|
166 | """Enable the flight info tab."""
|
---|
167 | self._comments.set_sensitive(True)
|
---|
168 | self._flightDefects.set_sensitive(True)
|
---|
169 | self._delayWindow.set_sensitive(True)
|
---|
170 |
|
---|
171 | def disable(self):
|
---|
172 | """Enable the flight info tab."""
|
---|
173 | self._comments.set_sensitive(False)
|
---|
174 | self._flightDefects.set_sensitive(False)
|
---|
175 | self._delayWindow.set_sensitive(False)
|
---|
176 |
|
---|
177 | def reset(self):
|
---|
178 | """Reset the flight info tab."""
|
---|
179 | self._comments.get_buffer().set_text("")
|
---|
180 | self._flightDefects.get_buffer().set_text("")
|
---|
181 |
|
---|
182 | for widget in self._delayCodeWidgets:
|
---|
183 | widget.set_active(False)
|
---|
184 |
|
---|
185 | def _commentsChanged(self, textbuffer):
|
---|
186 | """Called when the comments have changed."""
|
---|
187 | self._gui.updateRTO(inLoop = True)
|
---|