source: src/mlx/gui/info.py@ 123:3b181cd0ab99

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

The Preferences dialog works

File size: 5.7 KB
Line 
1#The Flight Info tab
2
3from common import *
4
5from mlx.i18n import xstr
6import mlx.const as const
7
8#------------------------------------------------------------------------------
9
10class 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 scroller.add(comments)
53 alignment.add(scroller)
54 frame.add(alignment)
55
56 label.set_mnemonic_widget(comments)
57
58 return (frame, comments)
59
60 def __init__(self, gui):
61 """Construct the flight info tab."""
62 super(FlightInfo, self).__init__()
63 self._gui = gui
64
65 self._commentsAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
66 xscale = 1.0, yscale = 1.0)
67 commentsBox = gtk.HBox()
68
69 (frame, self._comments) = FlightInfo._createCommentArea(xstr("info_comments"))
70 commentsBox.pack_start(frame, True, True, 8)
71
72 (frame, self._flightDefects) = \
73 FlightInfo._createCommentArea(xstr("info_defects"))
74 commentsBox.pack_start(frame, True, True, 8)
75
76 self._commentsAlignment.add(commentsBox)
77 self.pack_start(self._commentsAlignment, True, True, 8)
78
79 frame = gtk.Frame(label = xstr("info_delay"))
80 label = frame.get_label_widget()
81 label.set_use_underline(True)
82
83 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
84 xscale = 0.0, yscale = 0.0)
85 alignment.set_padding(padding_top = 4, padding_bottom = 4,
86 padding_left = 8, padding_right = 8)
87
88 self._delayTable = table = gtk.Table(5, 2)
89 table.set_col_spacings(16)
90
91 row = 0
92 column = 0
93
94 self._delayCodeWidgets = []
95 for (_code, label) in FlightInfo._delayCodes():
96 button = gtk.CheckButton(label)
97 button.set_use_underline(True)
98 table.attach(button, column, column + 1, row, row + 1)
99 self._delayCodeWidgets.append(button)
100 if column==0:
101 column += 1
102 else:
103 row += 1
104 column = 0
105
106 alignment.add(table)
107 frame.add(alignment)
108
109 self._delayAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
110 xscale = 0.0, yscale = 0.0)
111 self._delayAlignment.add(frame)
112
113 self.pack_start(self._delayAlignment, False, False, 8)
114
115 @property
116 def comments(self):
117 """Get the comments."""
118 buffer = self._comments.get_buffer()
119 return text2unicode(buffer.get_text(buffer.get_start_iter(),
120 buffer.get_end_iter(), True))
121
122 @property
123 def flightDefects(self):
124 """Get the flight defects."""
125 buffer = self._flightDefects.get_buffer()
126 return text2unicode(buffer.get_text(buffer.get_start_iter(),
127 buffer.get_end_iter(), True))
128
129 @property
130 def delayCodes(self):
131 """Get the list of delay codes checked by the user."""
132 codes = []
133 for index in range(0, len(FlightInfo._delayCodes)):
134 if self._delayCodeWidgets[index].get_active():
135 codes.append(FlightInfo._delayCodes[index][0])
136 return codes
137
138 def enable(self):
139 """Enable the flight info tab."""
140 self._comments.set_sensitive(True)
141 self._flightDefects.set_sensitive(True)
142 self._delayTable.set_sensitive(True)
143
144 def disable(self):
145 """Enable the flight info tab."""
146 self._comments.set_sensitive(False)
147 self._flightDefects.set_sensitive(False)
148 self._delayTable.set_sensitive(False)
149
150 def reset(self):
151 """Reset the flight info tab."""
152 self._comments.get_buffer().set_text("")
153 self._flightDefects.get_buffer().set_text("")
154
155 for widget in self._delayCodeWidgets:
156 widget.set_active(False)
Note: See TracBrowser for help on using the repository browser.