source: src/mlx/gui/info.py@ 928:3b16c095d166

python3
Last change on this file since 928:3b16c095d166 was 919:2ce8ca39525b, checked in by István Váradi <ivaradi@…>, 6 years ago

Ran 2to3

File size: 7.3 KB
Line 
1
2from .common import *
3
4from mlx.gui.delaycodes import DelayCodeTable
5from mlx.gui.faultexplain import FaultExplainWidget
6
7from mlx.i18n import xstr
8import mlx.const as const
9
10#------------------------------------------------------------------------------
11
12## @package mlx.gui.info
13#
14# The flight info tab.
15#
16# This module implements to \ref FlightInfo class, which is the widget for the
17# extra information related to the flight. It contains a text area for the
18# comments, the fault list widget, and the frame for the delay codes at the
19# bottom in the centre.
20
21#------------------------------------------------------------------------------
22
23class FlightInfo(gtk.VBox):
24 """The flight info tab."""
25 @staticmethod
26 def _createCommentArea(label):
27 """Create a comment area.
28
29 Returns a tuple of two items:
30 - the top-level widget of the comment area, and
31 - the comment text editor."""
32
33 frame = gtk.Frame(label = label)
34 label = frame.get_label_widget()
35 label.set_use_underline(True)
36
37 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
38 xscale = 1.0, yscale = 1.0)
39 alignment.set_padding(padding_top = 4, padding_bottom = 4,
40 padding_left = 8, padding_right = 8)
41
42 scroller = gtk.ScrolledWindow()
43 scroller.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
44 scroller.set_shadow_type(SHADOW_IN)
45
46 comments = gtk.TextView()
47 comments.set_wrap_mode(WRAP_WORD)
48 scroller.add(comments)
49 alignment.add(scroller)
50 frame.add(alignment)
51
52 label.set_mnemonic_widget(comments)
53
54 return (frame, comments)
55
56 def __init__(self, gui, callbackObject = None):
57 """Construct the flight info tab."""
58 super(FlightInfo, self).__init__()
59 self._gui = gui
60 self._callbackObject = callbackObject
61
62 self._commentsAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
63 xscale = 1.0, yscale = 1.0)
64 commentsBox = gtk.HBox()
65 commentsBox.set_homogeneous(True)
66
67 (frame, self._comments) = FlightInfo._createCommentArea(xstr("info_comments"))
68 commentsBox.pack_start(frame, True, True, 8)
69 self._comments.get_buffer().connect("changed", self._commentsChanged)
70
71 self._faultExplainWidget = FaultExplainWidget(gui)
72 self._faultExplainWidget.connect("explanations-changed",
73 self._faultExplanationsChanged)
74 commentsBox.pack_start(self._faultExplainWidget, 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 = 1.0, yscale = 1.0)
85 alignment.set_padding(padding_top = 4, padding_bottom = 4,
86 padding_left = 8, padding_right = 8)
87
88 self._delayCodeTable = table = DelayCodeTable(self)
89 self._delayWindow = scrolledWindow = gtk.ScrolledWindow()
90 scrolledWindow.add(table)
91 scrolledWindow.set_size_request(-1, 185)
92 scrolledWindow.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
93 scrolledWindow.set_shadow_type(SHADOW_IN)
94
95 alignment.add(scrolledWindow)
96 frame.add(alignment)
97
98 self._delayAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
99 xscale = 1.0, yscale = 1.0)
100 self._delayAlignment.add(frame)
101 self._delayAlignment.set_padding(padding_top = 0, padding_bottom = 0,
102 padding_left = 8, padding_right = 8)
103
104 self.pack_start(self._delayAlignment, False, False, 8)
105
106 @property
107 def comments(self):
108 """Get the comments."""
109 buffer = self._comments.get_buffer()
110 return text2unicode(buffer.get_text(buffer.get_start_iter(),
111 buffer.get_end_iter(), True))
112
113 @comments.setter
114 def comments(self, comments):
115 """Set the comments."""
116 self._comments.get_buffer().set_text(comments)
117
118 @property
119 def hasComments(self):
120 """Get whether there is any text in comments field."""
121 return self._comments.get_buffer().get_char_count()>0
122
123 @property
124 def faultsAndExplanations(self):
125 """Get the faults and explanations as HTML."""
126 return self._faultExplainWidget.html
127
128 @property
129 def delayCodes(self):
130 """Get the list of delay codes checked by the user."""
131 return self._delayCodeTable.delayCodes
132
133 @property
134 def hasDelayCode(self):
135 """Determine if there is at least one delay code selected."""
136 return self._delayCodeTable.hasDelayCode
137
138 @property
139 def faultsFullyExplained(self):
140 """Determine if all the faults have been explained by the pilot."""
141 return self._faultExplainWidget.fullyExplained
142
143 def addFault(self, id, faultText):
144 """Add a fault to the list of faults."""
145 self._faultExplainWidget.addFault(id, faultText)
146
147 def updateFault(self, id, faultText):
148 """Update a fault to the list of faults."""
149 self._faultExplainWidget.updateFault(id, faultText)
150
151 def clearFault(self, id):
152 """Clear a fault to the list of faults."""
153 self._faultExplainWidget.clearFault(id)
154
155 def setExplanation(self, id, explanation):
156 """Set the explanation of the given fault."""
157 self._faultExplainWidget.setExplanation(id, explanation)
158
159 def enable(self, aircraftType):
160 """Enable the flight info tab."""
161 self._comments.set_sensitive(True)
162 self._faultExplainWidget.set_sensitive(True)
163 self._delayCodeTable.setType(aircraftType)
164 self._delayWindow.set_sensitive(True)
165 self._delayCodeTable.setStyle()
166
167 def disable(self):
168 """Enable the flight info tab."""
169 self._comments.set_sensitive(False)
170 self._faultExplainWidget.set_sensitive(False)
171 self._delayWindow.set_sensitive(False)
172 self._delayCodeTable.setStyle()
173
174 def reset(self):
175 """Reset the flight info tab."""
176 self._comments.get_buffer().set_text("")
177 self._faultExplainWidget.reset()
178 self._delayCodeTable.reset()
179
180 def activateDelayCode(self, code):
181 """Active the checkbox corresponding to the given code."""
182 self._delayCodeTable.activateCode(code)
183
184 def delayCodesChanged(self):
185 """Callewd when the delay codes have changed."""
186 if self._callbackObject is None:
187 self._gui.delayCodesChanged()
188 else:
189 self._callbackObject.delayCodesChanged()
190
191 def _commentsChanged(self, textbuffer):
192 """Called when the comments have changed."""
193 if self._callbackObject is None:
194 self._gui.commentsChanged()
195 else:
196 self._callbackObject.commentsChanged()
197
198 def _faultExplanationsChanged(self, faultExplainWidget, fullyExplained):
199 """Called when the status of the fault explanations has changed."""
200 if self._callbackObject is None:
201 self._gui.faultExplanationsChanged()
202 else:
203 self._callbackObject.faultExplanationsChanged()
Note: See TracBrowser for help on using the repository browser.