source: src/mlx/gui/info.py@ 433:340267206759

Last change on this file since 433:340267206759 was 433:340267206759, checked in by István Váradi <ivaradi@…>, 11 years ago

Added the beginnings of the new delay code list widget (re #154)

File size: 7.1 KB
Line 
1
2from common import *
3
4from mlx.gui.delaycodes import DelayCodeTable
5
6from mlx.i18n import xstr
7import 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
22class 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(gtk.PolicyType.ALWAYS if pygobject
125 else gtk.POLICY_AUTOMATIC,
126 gtk.PolicyType.ALWAYS if pygobject
127 else gtk.POLICY_AUTOMATIC)
128 scrolledWindow.set_shadow_type(gtk.ShadowType.IN if pygobject
129 else gtk.SHADOW_IN)
130
131 alignment.add(scrolledWindow)
132 frame.add(alignment)
133
134 self._delayAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
135 xscale = 0.0, yscale = 0.0)
136 self._delayAlignment.add(frame)
137
138 self.pack_start(self._delayAlignment, False, False, 8)
139
140 @property
141 def comments(self):
142 """Get the comments."""
143 buffer = self._comments.get_buffer()
144 return text2unicode(buffer.get_text(buffer.get_start_iter(),
145 buffer.get_end_iter(), True))
146
147 @property
148 def hasComments(self):
149 """Get whether there is any text in comments field."""
150 return self._comments.get_buffer().get_char_count()>0
151
152 @property
153 def flightDefects(self):
154 """Get the flight defects."""
155 buffer = self._flightDefects.get_buffer()
156 return text2unicode(buffer.get_text(buffer.get_start_iter(),
157 buffer.get_end_iter(), True))
158
159 @property
160 def delayCodes(self):
161 """Get the list of delay codes checked by the user."""
162 codes = []
163 delayCodes = FlightInfo._delayCodes()
164 for index in range(0, len(delayCodes)):
165 if self._delayCodeWidgets[index].get_active():
166 codes.append(delayCodes[index][0])
167 return codes
168
169 def enable(self):
170 """Enable the flight info tab."""
171 self._comments.set_sensitive(True)
172 self._flightDefects.set_sensitive(True)
173 self._delayWindow.set_sensitive(True)
174
175 def disable(self):
176 """Enable the flight info tab."""
177 self._comments.set_sensitive(False)
178 self._flightDefects.set_sensitive(False)
179 self._delayWindow.set_sensitive(False)
180
181 def reset(self):
182 """Reset the flight info tab."""
183 self._comments.get_buffer().set_text("")
184 self._flightDefects.get_buffer().set_text("")
185
186 for widget in self._delayCodeWidgets:
187 widget.set_active(False)
188
189 def _commentsChanged(self, textbuffer):
190 """Called when the comments have changed."""
191 self._gui.updateRTO(inLoop = True)
Note: See TracBrowser for help on using the repository browser.