source: src/mlx/gui/info.py@ 98:f017d907fa39

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

The delay code buttons are generated in a more generic way

File size: 5.5 KB
Line 
1#The Flight Info tab
2
3from common import *
4
5import mlx.const as const
6
7class 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 def enable(self):
123 """Enable the flight info tab."""
124 #gobject.idle_add(self.set_sensitive, True)
125 self._commentsAlignment.set_sensitive(True)
126 self._delayAlignment.set_sensitive(True)
127
128 def disable(self):
129 """Enable the flight info tab."""
130 #gobject.idle_add(self.set_sensitive, False)
131 self._commentsAlignment.set_sensitive(False)
132 self._delayAlignment.set_sensitive(False)
133
134 def reset(self):
135 """Reset the flight info tab."""
136 self._comments.get_buffer().set_text("")
137 self._flightDefects.get_buffer().set_text("")
138
139 self._loadingProblems.set_active(False)
140 self._vatsimProblem.set_active(False)
141 self._netProblems.set_active(False)
142 self._controllersFault.set_active(False)
143 self._systemCrash.set_active(False)
144 self._navigationProblem.set_active(False)
145 self._trafficProblems.set_active(False)
146 self._apronProblem.set_active(False)
147 self._weatherProblems.set_active(False)
148 self._personalReasons.set_active(False)
Note: See TracBrowser for help on using the repository browser.