source: src/mlx/gui/info.py@ 604:0ec6a6f58f08

Last change on this file since 604:0ec6a6f58f08 was 604:0ec6a6f58f08, checked in by István Váradi <ivaradi@…>, 9 years ago

Added a new widget to list the faults and provide space for the user to enter an explanation (re #248).

File size: 5.9 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):
57 """Construct the flight info tab."""
58 super(FlightInfo, self).__init__()
59 self._gui = gui
60
61 self._commentsAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
62 xscale = 1.0, yscale = 1.0)
63 commentsBox = gtk.HBox()
64 commentsBox.set_homogeneous(True)
65
66 (frame, self._comments) = FlightInfo._createCommentArea(xstr("info_comments"))
67 commentsBox.pack_start(frame, True, True, 8)
68 self._comments.get_buffer().connect("changed", self._commentsChanged)
69
70 self._faultExplainWidget = FaultExplainWidget()
71 commentsBox.pack_start(self._faultExplainWidget, True, True, 8)
72
73 self._commentsAlignment.add(commentsBox)
74 self.pack_start(self._commentsAlignment, True, True, 8)
75
76 frame = gtk.Frame(label = xstr("info_delay"))
77 label = frame.get_label_widget()
78 label.set_use_underline(True)
79
80 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
81 xscale = 1.0, yscale = 1.0)
82 alignment.set_padding(padding_top = 4, padding_bottom = 4,
83 padding_left = 8, padding_right = 8)
84
85 self._delayCodeTable = table = DelayCodeTable(self)
86 self._delayWindow = scrolledWindow = gtk.ScrolledWindow()
87 scrolledWindow.add(table)
88 scrolledWindow.set_size_request(-1, 185)
89 scrolledWindow.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
90 scrolledWindow.set_shadow_type(SHADOW_IN)
91
92 alignment.add(scrolledWindow)
93 frame.add(alignment)
94
95 self._delayAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
96 xscale = 1.0, yscale = 1.0)
97 self._delayAlignment.add(frame)
98 self._delayAlignment.set_padding(padding_top = 0, padding_bottom = 0,
99 padding_left = 8, padding_right = 8)
100
101 self.pack_start(self._delayAlignment, False, False, 8)
102
103 @property
104 def comments(self):
105 """Get the comments."""
106 buffer = self._comments.get_buffer()
107 return text2unicode(buffer.get_text(buffer.get_start_iter(),
108 buffer.get_end_iter(), True))
109
110 @property
111 def hasComments(self):
112 """Get whether there is any text in comments field."""
113 return self._comments.get_buffer().get_char_count()>0
114
115 @property
116 def faultsAndExplanations(self):
117 """Get the faults and explanations as HTML."""
118 return self._faultExplainWidget.html
119
120 @property
121 def delayCodes(self):
122 """Get the list of delay codes checked by the user."""
123 return self._delayCodeTable.delayCodes
124
125 @property
126 def hasDelayCode(self):
127 """Determine if there is at least one delay code selected."""
128 return self._delayCodeTable.hasDelayCode
129
130 def addFault(self, id, faultText):
131 """Add a fault to the list of faults."""
132 self._faultExplainWidget.addFault(id, faultText)
133
134 def updateFault(self, id, faultText):
135 """Update a fault to the list of faults."""
136 self._faultExplainWidget.updateFault(id, faultText)
137
138 def clearFault(self, id):
139 """Clear a fault to the list of faults."""
140 self._faultExplainWidget.clearFault(id)
141
142 def enable(self, aircraftType):
143 """Enable the flight info tab."""
144 self._comments.set_sensitive(True)
145 self._faultExplainWidget.set_sensitive(True)
146 self._delayCodeTable.setType(aircraftType)
147 self._delayWindow.set_sensitive(True)
148 self._delayCodeTable.setStyle()
149
150 def disable(self):
151 """Enable the flight info tab."""
152 self._comments.set_sensitive(False)
153 self._faultExplainWidget.set_sensitive(False)
154 self._delayWindow.set_sensitive(False)
155 self._delayCodeTable.setStyle()
156
157 def reset(self):
158 """Reset the flight info tab."""
159 self._comments.get_buffer().set_text("")
160 self._faultExplainWidget.reset()
161 self._delayCodeTable.reset()
162
163 def delayCodesChanged(self):
164 """Callewd when the delay codes have changed."""
165 self._gui.delayCodesChanged()
166
167 def _commentsChanged(self, textbuffer):
168 """Called when the comments have changed."""
169 self._gui.commentsChanged()
Note: See TracBrowser for help on using the repository browser.