source: src/mlx/gui/info.py@ 555:e62f78ae65a0

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

The departure and arrival times are displayed on the finish page and if one of the differences is greater than 15 minutes, the PIREP cannot be saved or sent unless a delay code or a comment is provided (re #224)

File size: 5.6 KB
Line 
1
2from common import *
3
4from mlx.gui.delaycodes import DelayCodeTable
5
6from mlx.i18n import xstr
7import mlx.const as const
8
9#------------------------------------------------------------------------------
10
11## @package mlx.gui.info
12#
13# The flight info tab.
14#
15# This module implements to \ref FlightInfo class, which is the widget for the
16# extra information related to the flight. It contains text areas for the
17# comments and the flight defects at the top next to each other, and the frame
18# for the delay codes at the bottom in the centre.
19
20#------------------------------------------------------------------------------
21
22class FlightInfo(gtk.VBox):
23 """The flight info tab."""
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 scroller.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
43 scroller.set_shadow_type(SHADOW_IN)
44
45 comments = gtk.TextView()
46 comments.set_wrap_mode(WRAP_WORD)
47 scroller.add(comments)
48 alignment.add(scroller)
49 frame.add(alignment)
50
51 label.set_mnemonic_widget(comments)
52
53 return (frame, comments)
54
55 def __init__(self, gui):
56 """Construct the flight info tab."""
57 super(FlightInfo, self).__init__()
58 self._gui = gui
59
60 self._commentsAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
61 xscale = 1.0, yscale = 1.0)
62 commentsBox = gtk.HBox()
63
64 (frame, self._comments) = FlightInfo._createCommentArea(xstr("info_comments"))
65 commentsBox.pack_start(frame, True, True, 8)
66 self._comments.get_buffer().connect("changed", self._commentsChanged)
67
68 (frame, self._flightDefects) = \
69 FlightInfo._createCommentArea(xstr("info_defects"))
70 commentsBox.pack_start(frame, True, True, 8)
71
72 self._commentsAlignment.add(commentsBox)
73 self.pack_start(self._commentsAlignment, True, True, 8)
74
75 frame = gtk.Frame(label = xstr("info_delay"))
76 label = frame.get_label_widget()
77 label.set_use_underline(True)
78
79 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
80 xscale = 1.0, yscale = 1.0)
81 alignment.set_padding(padding_top = 4, padding_bottom = 4,
82 padding_left = 8, padding_right = 8)
83
84 self._delayCodeTable = table = DelayCodeTable(self)
85 self._delayWindow = scrolledWindow = gtk.ScrolledWindow()
86 scrolledWindow.add(table)
87 scrolledWindow.set_size_request(-1, 185)
88 scrolledWindow.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
89 scrolledWindow.set_shadow_type(SHADOW_IN)
90
91 alignment.add(scrolledWindow)
92 frame.add(alignment)
93
94 self._delayAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
95 xscale = 1.0, yscale = 1.0)
96 self._delayAlignment.add(frame)
97 self._delayAlignment.set_padding(padding_top = 0, padding_bottom = 0,
98 padding_left = 8, padding_right = 8)
99
100 self.pack_start(self._delayAlignment, False, False, 8)
101
102 @property
103 def comments(self):
104 """Get the comments."""
105 buffer = self._comments.get_buffer()
106 return text2unicode(buffer.get_text(buffer.get_start_iter(),
107 buffer.get_end_iter(), True))
108
109 @property
110 def hasComments(self):
111 """Get whether there is any text in comments field."""
112 return self._comments.get_buffer().get_char_count()>0
113
114 @property
115 def flightDefects(self):
116 """Get the flight defects."""
117 buffer = self._flightDefects.get_buffer()
118 return text2unicode(buffer.get_text(buffer.get_start_iter(),
119 buffer.get_end_iter(), True))
120
121 @property
122 def delayCodes(self):
123 """Get the list of delay codes checked by the user."""
124 return self._delayCodeTable.delayCodes
125
126 @property
127 def hasDelayCode(self):
128 """Determine if there is at least one delay code selected."""
129 return self._delayCodeTable.hasDelayCode
130
131 def enable(self, aircraftType):
132 """Enable the flight info tab."""
133 self._comments.set_sensitive(True)
134 self._flightDefects.set_sensitive(True)
135 self._delayCodeTable.setType(aircraftType)
136 self._delayWindow.set_sensitive(True)
137 self._delayCodeTable.setStyle()
138
139 def disable(self):
140 """Enable the flight info tab."""
141 self._comments.set_sensitive(False)
142 self._flightDefects.set_sensitive(False)
143 self._delayWindow.set_sensitive(False)
144 self._delayCodeTable.setStyle()
145
146 def reset(self):
147 """Reset the flight info tab."""
148 self._comments.get_buffer().set_text("")
149 self._flightDefects.get_buffer().set_text("")
150 self._delayCodeTable.reset()
151
152 def delayCodesChanged(self):
153 """Callewd when the delay codes have changed."""
154 self._gui.delayCodesChanged()
155
156 def _commentsChanged(self, textbuffer):
157 """Called when the comments have changed."""
158 self._gui.commentsChanged()
Note: See TracBrowser for help on using the repository browser.