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