[433] | 1 | # Module to handle the GUI aspects of the table of the delay codes
|
---|
| 2 |
|
---|
| 3 | #------------------------------------------------------------------------------
|
---|
| 4 |
|
---|
| 5 | from mlx.gui.common import *
|
---|
| 6 |
|
---|
[436] | 7 | import mlx.const as const
|
---|
| 8 |
|
---|
[433] | 9 | #------------------------------------------------------------------------------
|
---|
| 10 |
|
---|
| 11 | if pygobject:
|
---|
| 12 |
|
---|
| 13 | #------------------------------------------------------------------------------
|
---|
| 14 |
|
---|
| 15 | class Viewport(gtk.Viewport):
|
---|
| 16 | """Viewport implementation that alleviates the problem with improper
|
---|
| 17 | resizing by the VBox."""
|
---|
| 18 | def __init__(self):
|
---|
| 19 | """Construct the viewport."""
|
---|
| 20 | gtk.Viewport.__init__(self)
|
---|
| 21 | self._recursive = False
|
---|
| 22 | self._vboxHeight = None
|
---|
| 23 |
|
---|
| 24 | def setVBOXHeight(self, vboxHeight):
|
---|
| 25 | """Set the height of the VBox which will be used to calculate the
|
---|
| 26 | viewport's height."""
|
---|
| 27 | self._vboxHeight = vboxHeight
|
---|
| 28 |
|
---|
| 29 | def do_size_allocate(self, allocation):
|
---|
| 30 | """Called when the viewport's size is allocated.
|
---|
| 31 |
|
---|
| 32 | The height in the allocation object is modified so that it is only
|
---|
| 33 | so high to fit into the VBox."""
|
---|
| 34 | if self._vboxHeight is not None:
|
---|
| 35 | allocation.height = self._vboxHeight - allocation.y
|
---|
| 36 | self._vboxHeight = None
|
---|
| 37 | gtk.Viewport.do_size_allocate(self, allocation)
|
---|
| 38 |
|
---|
| 39 | class DelayCodeTableBase(gtk.VBox, gtk.Scrollable):
|
---|
| 40 | """PyGObject-specific base class for the delay code table."""
|
---|
| 41 | __gproperties__ = {
|
---|
| 42 | "vscroll-policy" : ( gtk.ScrollablePolicy,
|
---|
| 43 | "vscroll-policy",
|
---|
| 44 | "The vertical scrolling policy",
|
---|
| 45 | gtk.ScrollablePolicy.MINIMUM,
|
---|
| 46 | gobject.PARAM_READWRITE ),
|
---|
| 47 | "vadjustment" : ( gtk.Adjustment,
|
---|
| 48 | "vadjustment",
|
---|
| 49 | "The vertical adjustment",
|
---|
| 50 | gobject.PARAM_READWRITE ),
|
---|
| 51 | "hscroll-policy" : ( gtk.ScrollablePolicy,
|
---|
| 52 | "hscroll-policy",
|
---|
| 53 | "The horizontal scrolling policy",
|
---|
| 54 | gtk.ScrollablePolicy.MINIMUM,
|
---|
| 55 | gobject.PARAM_READWRITE ),
|
---|
| 56 | "hadjustment" : ( gtk.Adjustment,
|
---|
| 57 | "hadjustment",
|
---|
| 58 | "The horizontal adjustment",
|
---|
| 59 | gobject.PARAM_READWRITE ) }
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | @staticmethod
|
---|
| 63 | def _createViewport():
|
---|
| 64 | """Create an instance of the viewport class used by this base class."""
|
---|
| 65 | return Viewport()
|
---|
| 66 |
|
---|
| 67 | def __init__(self):
|
---|
| 68 | """Construct the delay code table."""
|
---|
| 69 | super(DelayCodeTableBase, self).__init__()
|
---|
| 70 |
|
---|
| 71 | def do_size_allocate(self, allocation):
|
---|
| 72 | """Allocate the size for the table and its children.
|
---|
| 73 |
|
---|
| 74 | This sets up the VBox height in the viewport and then calls the
|
---|
| 75 | do_size_allocate() function of VBox()."""
|
---|
| 76 | self._viewport.setVBOXHeight(allocation.height)
|
---|
| 77 | gtk.VBox.do_size_allocate(self, allocation)
|
---|
| 78 | self.allocate_column_sizes(allocation)
|
---|
| 79 |
|
---|
| 80 | def do_get_property(self, prop):
|
---|
| 81 | """Get the value of one of the properties defined above.
|
---|
| 82 |
|
---|
| 83 | The request is forwarded to the viewport."""
|
---|
| 84 | if prop.name=="vscroll-policy":
|
---|
| 85 | return self._viewport.get_vscroll_policy()
|
---|
| 86 | elif prop.name=="hscroll-policy":
|
---|
| 87 | return self._viewport.get_hscroll_policy()
|
---|
| 88 | elif prop.name=="vadjustment":
|
---|
| 89 | return self._viewport.get_vadjustment()
|
---|
| 90 | elif prop.name=="hadjustment":
|
---|
| 91 | return self._viewport.get_hadjustment()
|
---|
| 92 | else:
|
---|
| 93 | raise AttributeError("mlx.gui.delaycodes.DelayCodeTableBase: property %s is not handled in do_get_property" %
|
---|
| 94 | (prop.name,))
|
---|
| 95 |
|
---|
| 96 | def do_set_property(self, prop, value):
|
---|
| 97 | """Set the value of the adjustment properties defined above.
|
---|
| 98 |
|
---|
| 99 | The adjustments are forwarded to the viewport."""
|
---|
| 100 | if prop.name=="vadjustment":
|
---|
| 101 | self._viewport.set_vadjustment(value)
|
---|
| 102 | elif prop.name=="hadjustment":
|
---|
| 103 | self._viewport.set_hadjustment(value)
|
---|
[435] | 104 | self._treeView.set_hadjustment(value)
|
---|
[433] | 105 | else:
|
---|
| 106 | raise AttributeError("mlx.gui.delaycodes.DelayCodeTableBase: property %s is not handled in do_set_property" %
|
---|
| 107 | (prop.name,))
|
---|
| 108 |
|
---|
[435] | 109 | def setStyle(self):
|
---|
| 110 | """Set the style of the event box from the treeview."""
|
---|
| 111 |
|
---|
| 112 | class Alignment(gtk.Alignment):
|
---|
| 113 | """An alignment that remembers the width it was given."""
|
---|
| 114 | def __init__(self, xalign = 0.0, yalign=0.0,
|
---|
| 115 | xscale = 0.0, yscale = 0.0 ):
|
---|
| 116 | """Construct the alignment."""
|
---|
| 117 | super(Alignment, self).__init__(xalign = xalign, yalign = yalign,
|
---|
| 118 | xscale = xscale, yscale = yscale)
|
---|
| 119 | self.allocatedWidth = 0
|
---|
| 120 |
|
---|
| 121 | def do_size_allocate(self, allocation):
|
---|
| 122 | """Called with the new size allocation."""
|
---|
| 123 | self.allocatedWidth = allocation.width
|
---|
| 124 | gtk.Alignment.do_size_allocate(self, allocation)
|
---|
| 125 |
|
---|
[433] | 126 | #------------------------------------------------------------------------------
|
---|
| 127 |
|
---|
| 128 | else: # pygobject
|
---|
| 129 |
|
---|
| 130 | #------------------------------------------------------------------------------
|
---|
| 131 |
|
---|
| 132 | class DelayCodeTableBase (gtk.VBox):
|
---|
| 133 | """Base class of the delay code table for PyGtk."""
|
---|
| 134 |
|
---|
| 135 | __gsignals__ = {
|
---|
| 136 | "set-scroll-adjustments": (
|
---|
| 137 | gobject.SIGNAL_RUN_LAST,
|
---|
| 138 | gobject.TYPE_NONE, (gtk.Adjustment, gtk.Adjustment))
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | @staticmethod
|
---|
| 142 | def _createViewport():
|
---|
| 143 | """Create an instance of the viewport class used by this base class."""
|
---|
| 144 | return gtk.Viewport()
|
---|
| 145 |
|
---|
| 146 | def __init__(self):
|
---|
| 147 | """Construct the base class."""
|
---|
| 148 | super(DelayCodeTableBase, self).__init__()
|
---|
| 149 | self.set_set_scroll_adjustments_signal("set-scroll-adjustments")
|
---|
| 150 | self.connect("size-allocate", self._do_size_allocate)
|
---|
| 151 |
|
---|
| 152 | def do_set_scroll_adjustments(self, hAdjustment, vAdjustment):
|
---|
| 153 | """Set the adjustments on the viewport."""
|
---|
| 154 | self._viewport.set_hadjustment(hAdjustment)
|
---|
| 155 | self._viewport.set_vadjustment(vAdjustment)
|
---|
[435] | 156 | self._treeView.set_hadjustment(hAdjustment)
|
---|
[433] | 157 |
|
---|
| 158 | def _do_size_allocate(self, widget, allocation):
|
---|
| 159 | """Handler of the size-allocate signal.
|
---|
| 160 |
|
---|
| 161 | Calls allocate_column_sizes()."""
|
---|
| 162 | self.allocate_column_sizes(allocation)
|
---|
| 163 |
|
---|
[435] | 164 | def setStyle(self):
|
---|
| 165 | """Set the style of the event box from the treeview."""
|
---|
[436] | 166 | if self._treeView is not None:
|
---|
| 167 | style = self._treeView.rc_get_style()
|
---|
| 168 | self._eventBox.modify_bg(0, style.bg[2])
|
---|
| 169 | self._eventBox.modify_fg(0, style.fg[2])
|
---|
[435] | 170 |
|
---|
| 171 | class Alignment(gtk.Alignment):
|
---|
| 172 | """An alignment that remembers the width it was given."""
|
---|
| 173 | def __init__(self, xalign = 0.0, yalign=0.0,
|
---|
| 174 | xscale = 0.0, yscale = 0.0 ):
|
---|
| 175 | """Construct the alignment."""
|
---|
| 176 | super(Alignment, self).__init__(xalign = xalign, yalign = yalign,
|
---|
| 177 | xscale = xscale, yscale = yscale)
|
---|
| 178 | self.allocatedWidth = 0
|
---|
| 179 | self.connect("size-allocate", self._do_size_allocate)
|
---|
| 180 |
|
---|
| 181 | def _do_size_allocate(self, widget, allocation):
|
---|
| 182 | """Called with the new size allocation."""
|
---|
| 183 | self.allocatedWidth = allocation.width
|
---|
| 184 |
|
---|
| 185 | #------------------------------------------------------------------------------
|
---|
| 186 |
|
---|
[437] | 187 | class CheckButton(gtk.CheckButton):
|
---|
| 188 | """A check button that contains a reference to a row in the delay code
|
---|
| 189 | data table."""
|
---|
| 190 | def __init__(self, delayCodeRow):
|
---|
| 191 | """Construct the check button."""
|
---|
| 192 | super(CheckButton, self).__init__()
|
---|
| 193 | self.delayCodeRow = delayCodeRow
|
---|
| 194 |
|
---|
| 195 | #------------------------------------------------------------------------------
|
---|
| 196 |
|
---|
[435] | 197 | CAPTION = 1
|
---|
| 198 |
|
---|
| 199 | DELAYCODE = 2
|
---|
| 200 |
|
---|
[437] | 201 | _data1 = ( lambda row: row[0].strip(),
|
---|
| 202 | ["Num", "Code", "Title", "Description"],
|
---|
[436] | 203 | [ (CAPTION, "Others"),
|
---|
[438] | 204 | (DELAYCODE, (" 6", "OA ", "NO GATES/STAND AVAILABLE",
|
---|
[436] | 205 | "Due to own airline activity")),
|
---|
| 206 | (DELAYCODE, ("9", "SG", "SCHEDULED GROUND TIME",
|
---|
| 207 | "Planned turnaround time less than declared minimum")),
|
---|
| 208 | (CAPTION, "Passenger and baggage"),
|
---|
| 209 | (DELAYCODE, ("11", "PD", "LATE CHECK-IN",
|
---|
| 210 | "Check-in reopened for late passengers")),
|
---|
| 211 | (DELAYCODE, ("12", "PL", "LATE CHECK-IN",
|
---|
| 212 | "Check-in not completed by flight closure time")),
|
---|
| 213 | (DELAYCODE, ("13", "PE", "CHECK-IN ERROR",
|
---|
| 214 | "Error with passenger or baggage details")) ] )
|
---|
| 215 |
|
---|
[437] | 216 | _data2 = ( lambda row: row[0].strip(),
|
---|
| 217 | ["MA", "IATA", "Description"],
|
---|
[436] | 218 | [ (CAPTION, "Passenger and baggage"),
|
---|
[438] | 219 | (DELAYCODE, (" 012", "01 ",
|
---|
[436] | 220 | "Late shipping of parts and/or materials")),
|
---|
[438] | 221 | (DELAYCODE, (" 111", "11",
|
---|
[436] | 222 | "Check-in reopened for late passengers")),
|
---|
[438] | 223 | (DELAYCODE, (" 121", "12",
|
---|
[436] | 224 | "Check-in not completed by flight closure time")),
|
---|
[438] | 225 | (DELAYCODE, (" 132", "13",
|
---|
[436] | 226 | "Error with passenger or baggage details"))
|
---|
| 227 | ])
|
---|
[435] | 228 |
|
---|
[433] | 229 | #------------------------------------------------------------------------------
|
---|
| 230 |
|
---|
| 231 | class DelayCodeTable(DelayCodeTableBase):
|
---|
| 232 | """The delay code table."""
|
---|
| 233 | def __init__(self):
|
---|
| 234 | """Construct the delay code table."""
|
---|
| 235 | super(DelayCodeTable, self).__init__()
|
---|
| 236 |
|
---|
[437] | 237 | self._delayCodeData = None
|
---|
| 238 |
|
---|
| 239 | self._treeView = gtk.TreeView(gtk.ListStore(str, str))
|
---|
[435] | 240 | self._treeView.set_rules_hint(True)
|
---|
| 241 |
|
---|
[436] | 242 | self.pack_start(self._treeView, False, False, 0)
|
---|
| 243 |
|
---|
| 244 | self._alignments = []
|
---|
[437] | 245 | self._checkButtons = []
|
---|
[436] | 246 |
|
---|
| 247 | self._eventBox = gtk.EventBox()
|
---|
| 248 |
|
---|
| 249 | self._table = None
|
---|
| 250 |
|
---|
| 251 | self._viewport = self._createViewport()
|
---|
| 252 | self._viewport.add(self._eventBox)
|
---|
| 253 | self._viewport.set_shadow_type(SHADOW_NONE)
|
---|
| 254 |
|
---|
| 255 | self.pack_start(self._viewport, True, True, 0)
|
---|
| 256 |
|
---|
| 257 | self._previousWidth = 0
|
---|
| 258 |
|
---|
[437] | 259 | @property
|
---|
| 260 | def delayCodes(self):
|
---|
| 261 | """Get a list of the delay codes checked by the user."""
|
---|
| 262 | codes = []
|
---|
| 263 |
|
---|
| 264 | if self._delayCodeData is not None:
|
---|
| 265 | codeExtractor = self._delayCodeData[0]
|
---|
| 266 | for checkButton in self._checkButtons:
|
---|
| 267 | if checkButton.get_active():
|
---|
| 268 | codes.append(codeExtractor(checkButton.delayCodeRow))
|
---|
| 269 |
|
---|
| 270 | return codes
|
---|
| 271 |
|
---|
[436] | 272 | def allocate_column_sizes(self, allocation):
|
---|
| 273 | """Allocate the column sizes."""
|
---|
| 274 | if allocation.width!=self._previousWidth:
|
---|
| 275 | self._previousWidth = allocation.width
|
---|
| 276 | index = 0
|
---|
[438] | 277 | lastIndex = len(self._alignments) - 1
|
---|
[436] | 278 | for alignment in self._alignments:
|
---|
| 279 | column = self._treeView.get_column(index)
|
---|
[438] | 280 | width = alignment.allocatedWidth
|
---|
| 281 | width += 8 if (index==0 or index==lastIndex) else 16
|
---|
[436] | 282 | column.set_fixed_width(width)
|
---|
| 283 | index += 1
|
---|
| 284 |
|
---|
| 285 | def setType(self, aircraftType):
|
---|
| 286 | """Setup the delay code table according to the given aircraft type."""
|
---|
| 287 | if aircraftType==const.AIRCRAFT_B736:
|
---|
| 288 | data = _data1
|
---|
| 289 | else:
|
---|
| 290 | data = _data2
|
---|
| 291 |
|
---|
[437] | 292 | self._delayCodeData = data
|
---|
| 293 |
|
---|
[436] | 294 | columns = self._treeView.get_columns()
|
---|
| 295 | for column in columns:
|
---|
| 296 | self._treeView.remove_column(column)
|
---|
| 297 |
|
---|
[437] | 298 | (_extractor, headers, rows) = data
|
---|
[436] | 299 | numColumns = len(headers) + 1
|
---|
| 300 | numRows = len(rows)
|
---|
| 301 |
|
---|
[435] | 302 | column = gtk.TreeViewColumn("", gtk.CellRendererText())
|
---|
[433] | 303 | column.set_sizing(TREE_VIEW_COLUMN_FIXED)
|
---|
| 304 | self._treeView.append_column(column)
|
---|
| 305 |
|
---|
[435] | 306 | for header in headers:
|
---|
| 307 | column = gtk.TreeViewColumn(header, gtk.CellRendererText())
|
---|
| 308 | column.set_sizing(TREE_VIEW_COLUMN_FIXED)
|
---|
| 309 | self._treeView.append_column(column)
|
---|
| 310 |
|
---|
| 311 | self._table = gtk.Table(numRows, numColumns)
|
---|
| 312 | self._table.set_homogeneous(False)
|
---|
| 313 | self._table.set_col_spacings(16)
|
---|
| 314 | self._table.set_row_spacings(4)
|
---|
[436] | 315 | self._eventBox.add(self._table)
|
---|
| 316 |
|
---|
| 317 | self._alignments = []
|
---|
[437] | 318 | self._checkButtons = []
|
---|
[435] | 319 |
|
---|
| 320 | firstDelayCodeRow = True
|
---|
| 321 | for i in range(0, numRows):
|
---|
| 322 | (type, elements) = rows[i]
|
---|
| 323 | if type==CAPTION:
|
---|
| 324 | alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
|
---|
| 325 | xscale = 1.0)
|
---|
| 326 | label = gtk.Label("<b>" + elements + "</b>")
|
---|
| 327 | label.set_use_markup(True)
|
---|
| 328 | label.set_alignment(0.0, 0.5)
|
---|
| 329 | alignment.add(label)
|
---|
[438] | 330 | self._table.attach(alignment, 1, numColumns, i, i+1,
|
---|
| 331 | yoptions = FILL)
|
---|
[435] | 332 | self._table.set_row_spacing(i, 8)
|
---|
| 333 | elif type==DELAYCODE:
|
---|
[437] | 334 | checkButton = CheckButton(elements)
|
---|
| 335 | self._checkButtons.append(checkButton)
|
---|
[435] | 336 | alignment = Alignment(xalign = 0.5, yalign = 0.5, xscale = 1.0)
|
---|
[437] | 337 | alignment.add(checkButton)
|
---|
[438] | 338 | self._table.attach(alignment, 0, 1, i, i+1,
|
---|
| 339 | xoptions = FILL, yoptions = FILL)
|
---|
[435] | 340 | if firstDelayCodeRow:
|
---|
| 341 | self._alignments.append(alignment)
|
---|
| 342 |
|
---|
[438] | 343 | for j in range(0, numColumns-1):
|
---|
[435] | 344 | label = gtk.Label(elements[j])
|
---|
| 345 | label.set_alignment(1.0 if j==0 else 0.0, 0.5)
|
---|
| 346 | alignment = Alignment(xalign = 0.5, yalign = 0.5,
|
---|
| 347 | xscale = 1.0)
|
---|
| 348 | alignment.add(label)
|
---|
[438] | 349 | xoptions = FILL
|
---|
| 350 | if j==(numColumns-2): xoptions |= EXPAND
|
---|
| 351 | self._table.attach(alignment, j+1, j+2, i, i+1,
|
---|
| 352 | xoptions = xoptions, yoptions = FILL)
|
---|
[435] | 353 | if firstDelayCodeRow:
|
---|
| 354 | self._alignments.append(alignment)
|
---|
| 355 | firstDelayCodeRow = False
|
---|
[433] | 356 |
|
---|
| 357 | self._previousWidth = 0
|
---|
[436] | 358 | self.show_all()
|
---|
[433] | 359 |
|
---|
[436] | 360 | def reset(self):
|
---|
| 361 | """Reset the delay code table."""
|
---|
| 362 | columns = self._treeView.get_columns()
|
---|
| 363 | for column in columns:
|
---|
| 364 | self._treeView.remove_column(column)
|
---|
| 365 | self._eventBox.remove(self._table)
|
---|
| 366 | self._table = None
|
---|
| 367 | self.show_all()
|
---|
[433] | 368 |
|
---|
| 369 | #------------------------------------------------------------------------------
|
---|