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