source: src/mlx/gui/info.py@ 111:3543a2c2192c

Last change on this file since 111:3543a2c2192c was 111:3543a2c2192c, checked in by István Váradi <ivaradi@…>, 12 years ago

The Flight Info tab is now internationalized

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