source: src/mlx/gui/info.py@ 342:f3257ba8eca2

Last change on this file since 342:f3257ba8eca2 was 300:f101bd18f39d, checked in by István Váradi <ivaradi@…>, 12 years ago

Added the module comments for the GUI

File size: 6.1 KB
Line 
1
2from common import *
3
4from mlx.i18n import xstr
5import 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
20class 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
83 (frame, self._flightDefects) = \
84 FlightInfo._createCommentArea(xstr("info_defects"))
85 commentsBox.pack_start(frame, True, True, 8)
86
87 self._commentsAlignment.add(commentsBox)
88 self.pack_start(self._commentsAlignment, True, True, 8)
89
90 frame = gtk.Frame(label = xstr("info_delay"))
91 label = frame.get_label_widget()
92 label.set_use_underline(True)
93
94 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
95 xscale = 0.0, yscale = 0.0)
96 alignment.set_padding(padding_top = 4, padding_bottom = 4,
97 padding_left = 8, padding_right = 8)
98
99 self._delayTable = table = gtk.Table(5, 2)
100 table.set_col_spacings(16)
101
102 row = 0
103 column = 0
104
105 self._delayCodeWidgets = []
106 for (_code, label) in FlightInfo._delayCodes():
107 button = gtk.CheckButton(label)
108 button.set_use_underline(True)
109 table.attach(button, column, column + 1, row, row + 1)
110 self._delayCodeWidgets.append(button)
111 if column==0:
112 column += 1
113 else:
114 row += 1
115 column = 0
116
117 alignment.add(table)
118 frame.add(alignment)
119
120 self._delayAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
121 xscale = 0.0, yscale = 0.0)
122 self._delayAlignment.add(frame)
123
124 self.pack_start(self._delayAlignment, False, False, 8)
125
126 @property
127 def comments(self):
128 """Get the comments."""
129 buffer = self._comments.get_buffer()
130 return text2unicode(buffer.get_text(buffer.get_start_iter(),
131 buffer.get_end_iter(), True))
132
133 @property
134 def flightDefects(self):
135 """Get the flight defects."""
136 buffer = self._flightDefects.get_buffer()
137 return text2unicode(buffer.get_text(buffer.get_start_iter(),
138 buffer.get_end_iter(), True))
139
140 @property
141 def delayCodes(self):
142 """Get the list of delay codes checked by the user."""
143 codes = []
144 delayCodes = FlightInfo._delayCodes()
145 for index in range(0, len(delayCodes)):
146 if self._delayCodeWidgets[index].get_active():
147 codes.append(delayCodes[index][0])
148 return codes
149
150 def enable(self):
151 """Enable the flight info tab."""
152 self._comments.set_sensitive(True)
153 self._flightDefects.set_sensitive(True)
154 self._delayTable.set_sensitive(True)
155
156 def disable(self):
157 """Enable the flight info tab."""
158 self._comments.set_sensitive(False)
159 self._flightDefects.set_sensitive(False)
160 self._delayTable.set_sensitive(False)
161
162 def reset(self):
163 """Reset the flight info tab."""
164 self._comments.get_buffer().set_text("")
165 self._flightDefects.get_buffer().set_text("")
166
167 for widget in self._delayCodeWidgets:
168 widget.set_active(False)
Note: See TracBrowser for help on using the repository browser.