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