[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 |
|
---|
| 7 | #------------------------------------------------------------------------------
|
---|
| 8 |
|
---|
| 9 | if pygobject:
|
---|
| 10 |
|
---|
| 11 | #------------------------------------------------------------------------------
|
---|
| 12 |
|
---|
| 13 | class Viewport(gtk.Viewport):
|
---|
| 14 | """Viewport implementation that alleviates the problem with improper
|
---|
| 15 | resizing by the VBox."""
|
---|
| 16 | def __init__(self):
|
---|
| 17 | """Construct the viewport."""
|
---|
| 18 | gtk.Viewport.__init__(self)
|
---|
| 19 | self._recursive = False
|
---|
| 20 | self._vboxHeight = None
|
---|
| 21 |
|
---|
| 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
|
---|
| 26 |
|
---|
| 27 | def do_size_allocate(self, allocation):
|
---|
| 28 | """Called when the viewport's size is allocated.
|
---|
| 29 |
|
---|
| 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.height = self._vboxHeight - allocation.y
|
---|
| 34 | self._vboxHeight = None
|
---|
| 35 | gtk.Viewport.do_size_allocate(self, allocation)
|
---|
| 36 |
|
---|
| 37 | class DelayCodeTableBase(gtk.VBox, gtk.Scrollable):
|
---|
| 38 | """PyGObject-specific base class for the delay code table."""
|
---|
| 39 | __gproperties__ = {
|
---|
| 40 | "vscroll-policy" : ( gtk.ScrollablePolicy,
|
---|
| 41 | "vscroll-policy",
|
---|
| 42 | "The vertical scrolling policy",
|
---|
| 43 | gtk.ScrollablePolicy.MINIMUM,
|
---|
| 44 | gobject.PARAM_READWRITE ),
|
---|
| 45 | "vadjustment" : ( gtk.Adjustment,
|
---|
| 46 | "vadjustment",
|
---|
| 47 | "The vertical adjustment",
|
---|
| 48 | gobject.PARAM_READWRITE ),
|
---|
| 49 | "hscroll-policy" : ( gtk.ScrollablePolicy,
|
---|
| 50 | "hscroll-policy",
|
---|
| 51 | "The horizontal scrolling policy",
|
---|
| 52 | gtk.ScrollablePolicy.MINIMUM,
|
---|
| 53 | gobject.PARAM_READWRITE ),
|
---|
| 54 | "hadjustment" : ( gtk.Adjustment,
|
---|
| 55 | "hadjustment",
|
---|
| 56 | "The horizontal adjustment",
|
---|
| 57 | gobject.PARAM_READWRITE ) }
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | @staticmethod
|
---|
| 61 | def _createViewport():
|
---|
| 62 | """Create an instance of the viewport class used by this base class."""
|
---|
| 63 | return Viewport()
|
---|
| 64 |
|
---|
| 65 | def __init__(self):
|
---|
| 66 | """Construct the delay code table."""
|
---|
| 67 | super(DelayCodeTableBase, self).__init__()
|
---|
| 68 |
|
---|
| 69 | def do_size_allocate(self, allocation):
|
---|
| 70 | """Allocate the size for the table and its children.
|
---|
| 71 |
|
---|
| 72 | This sets up the VBox height in the viewport and then calls the
|
---|
| 73 | do_size_allocate() function of VBox()."""
|
---|
| 74 | self._viewport.setVBOXHeight(allocation.height)
|
---|
| 75 | gtk.VBox.do_size_allocate(self, allocation)
|
---|
| 76 | self.allocate_column_sizes(allocation)
|
---|
| 77 |
|
---|
| 78 | def do_get_property(self, prop):
|
---|
| 79 | """Get the value of one of the properties defined above.
|
---|
| 80 |
|
---|
| 81 | The request is forwarded to the viewport."""
|
---|
| 82 | if prop.name=="vscroll-policy":
|
---|
| 83 | return self._viewport.get_vscroll_policy()
|
---|
| 84 | elif prop.name=="hscroll-policy":
|
---|
| 85 | return self._viewport.get_hscroll_policy()
|
---|
| 86 | elif prop.name=="vadjustment":
|
---|
| 87 | return self._viewport.get_vadjustment()
|
---|
| 88 | elif prop.name=="hadjustment":
|
---|
| 89 | return self._viewport.get_hadjustment()
|
---|
| 90 | else:
|
---|
| 91 | raise AttributeError("mlx.gui.delaycodes.DelayCodeTableBase: property %s is not handled in do_get_property" %
|
---|
| 92 | (prop.name,))
|
---|
| 93 |
|
---|
| 94 | def do_set_property(self, prop, value):
|
---|
| 95 | """Set the value of the adjustment properties defined above.
|
---|
| 96 |
|
---|
| 97 | The adjustments are forwarded to the viewport."""
|
---|
| 98 | if prop.name=="vadjustment":
|
---|
| 99 | self._viewport.set_vadjustment(value)
|
---|
| 100 | elif prop.name=="hadjustment":
|
---|
| 101 | self._viewport.set_hadjustment(value)
|
---|
[435] | 102 | self._treeView.set_hadjustment(value)
|
---|
[433] | 103 | else:
|
---|
| 104 | raise AttributeError("mlx.gui.delaycodes.DelayCodeTableBase: property %s is not handled in do_set_property" %
|
---|
| 105 | (prop.name,))
|
---|
| 106 |
|
---|
[435] | 107 | def setStyle(self):
|
---|
| 108 | """Set the style of the event box from the treeview."""
|
---|
| 109 |
|
---|
| 110 | class Alignment(gtk.Alignment):
|
---|
| 111 | """An alignment that remembers the width it was given."""
|
---|
| 112 | def __init__(self, xalign = 0.0, yalign=0.0,
|
---|
| 113 | xscale = 0.0, yscale = 0.0 ):
|
---|
| 114 | """Construct the alignment."""
|
---|
| 115 | super(Alignment, self).__init__(xalign = xalign, yalign = yalign,
|
---|
| 116 | xscale = xscale, yscale = yscale)
|
---|
| 117 | self.allocatedWidth = 0
|
---|
| 118 |
|
---|
| 119 | def do_size_allocate(self, allocation):
|
---|
| 120 | """Called with the new size allocation."""
|
---|
| 121 | self.allocatedWidth = allocation.width
|
---|
| 122 | gtk.Alignment.do_size_allocate(self, allocation)
|
---|
| 123 |
|
---|
[433] | 124 | #------------------------------------------------------------------------------
|
---|
| 125 |
|
---|
| 126 | else: # pygobject
|
---|
| 127 |
|
---|
| 128 | #------------------------------------------------------------------------------
|
---|
| 129 |
|
---|
| 130 | class DelayCodeTableBase (gtk.VBox):
|
---|
| 131 | """Base class of the delay code table for PyGtk."""
|
---|
| 132 |
|
---|
| 133 | __gsignals__ = {
|
---|
| 134 | "set-scroll-adjustments": (
|
---|
| 135 | gobject.SIGNAL_RUN_LAST,
|
---|
| 136 | gobject.TYPE_NONE, (gtk.Adjustment, gtk.Adjustment))
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | @staticmethod
|
---|
| 140 | def _createViewport():
|
---|
| 141 | """Create an instance of the viewport class used by this base class."""
|
---|
| 142 | return gtk.Viewport()
|
---|
| 143 |
|
---|
| 144 | def __init__(self):
|
---|
| 145 | """Construct the base class."""
|
---|
| 146 | super(DelayCodeTableBase, self).__init__()
|
---|
| 147 | self.set_set_scroll_adjustments_signal("set-scroll-adjustments")
|
---|
| 148 | self.connect("size-allocate", self._do_size_allocate)
|
---|
| 149 |
|
---|
| 150 | def do_set_scroll_adjustments(self, hAdjustment, vAdjustment):
|
---|
| 151 | """Set the adjustments on the viewport."""
|
---|
| 152 | self._viewport.set_hadjustment(hAdjustment)
|
---|
| 153 | self._viewport.set_vadjustment(vAdjustment)
|
---|
[435] | 154 | self._treeView.set_hadjustment(hAdjustment)
|
---|
[433] | 155 |
|
---|
| 156 | def _do_size_allocate(self, widget, allocation):
|
---|
| 157 | """Handler of the size-allocate signal.
|
---|
| 158 |
|
---|
| 159 | Calls allocate_column_sizes()."""
|
---|
| 160 | self.allocate_column_sizes(allocation)
|
---|
| 161 |
|
---|
[435] | 162 | def setStyle(self):
|
---|
| 163 | """Set the style of the event box from the treeview."""
|
---|
| 164 | style = self._treeView.rc_get_style()
|
---|
| 165 | self._eventBox.modify_bg(0, style.bg[2])
|
---|
| 166 | self._eventBox.modify_fg(0, style.fg[2])
|
---|
| 167 |
|
---|
| 168 |
|
---|
| 169 | class Alignment(gtk.Alignment):
|
---|
| 170 | """An alignment that remembers the width it was given."""
|
---|
| 171 | def __init__(self, xalign = 0.0, yalign=0.0,
|
---|
| 172 | xscale = 0.0, yscale = 0.0 ):
|
---|
| 173 | """Construct the alignment."""
|
---|
| 174 | super(Alignment, self).__init__(xalign = xalign, yalign = yalign,
|
---|
| 175 | xscale = xscale, yscale = yscale)
|
---|
| 176 | self.allocatedWidth = 0
|
---|
| 177 | self.connect("size-allocate", self._do_size_allocate)
|
---|
| 178 |
|
---|
| 179 | def _do_size_allocate(self, widget, allocation):
|
---|
| 180 | """Called with the new size allocation."""
|
---|
| 181 | self.allocatedWidth = allocation.width
|
---|
| 182 |
|
---|
| 183 | #------------------------------------------------------------------------------
|
---|
| 184 |
|
---|
| 185 | CAPTION = 1
|
---|
| 186 |
|
---|
| 187 | DELAYCODE = 2
|
---|
| 188 |
|
---|
| 189 | _data = ( ["Num", "Code", "Reason", "Description"],
|
---|
| 190 | [ (CAPTION, "Others"),
|
---|
| 191 | (DELAYCODE, (" 6", "OA ", "NO GATES/STAND AVAILABLE",
|
---|
| 192 | "Due to own airline activity")),
|
---|
| 193 | (DELAYCODE, ("9", "SG", "SCHEDULED GROUND TIME",
|
---|
| 194 | "Planned turnaround time less than declared minimum")),
|
---|
| 195 | (CAPTION, "Passenger and baggage"),
|
---|
| 196 | (DELAYCODE, ("11", "PD", "LATE CHECK-IN",
|
---|
| 197 | "Check-in reopened for late passengers")),
|
---|
| 198 | (DELAYCODE, ("12", "PL", "LATE CHECK-IN",
|
---|
| 199 | "Check-in not completed by flight closure time")),
|
---|
| 200 | (DELAYCODE, ("13", "PE", "CHECK-IN ERROR",
|
---|
| 201 | "Error with passenger or baggage details")) ] )
|
---|
| 202 |
|
---|
[433] | 203 | #------------------------------------------------------------------------------
|
---|
| 204 |
|
---|
| 205 | class DelayCodeTable(DelayCodeTableBase):
|
---|
| 206 | """The delay code table."""
|
---|
| 207 | def __init__(self):
|
---|
| 208 | """Construct the delay code table."""
|
---|
| 209 | super(DelayCodeTable, self).__init__()
|
---|
| 210 |
|
---|
[435] | 211 | (headers, rows) = _data
|
---|
| 212 | numColumns = len(headers) + 1
|
---|
| 213 | numRows = len(rows)
|
---|
| 214 |
|
---|
| 215 | self._listStore = gtk.ListStore(str, str)
|
---|
[433] | 216 | self._treeView = gtk.TreeView(self._listStore)
|
---|
[435] | 217 | self._treeView.set_rules_hint(True)
|
---|
| 218 |
|
---|
| 219 | column = gtk.TreeViewColumn("", gtk.CellRendererText())
|
---|
[433] | 220 | column.set_sizing(TREE_VIEW_COLUMN_FIXED)
|
---|
| 221 | self._treeView.append_column(column)
|
---|
| 222 |
|
---|
[435] | 223 | for header in headers:
|
---|
| 224 | column = gtk.TreeViewColumn(header, gtk.CellRendererText())
|
---|
| 225 | column.set_sizing(TREE_VIEW_COLUMN_FIXED)
|
---|
| 226 | self._treeView.append_column(column)
|
---|
| 227 |
|
---|
[433] | 228 | self.pack_start(self._treeView, False, False, 0)
|
---|
| 229 |
|
---|
[435] | 230 | self._alignments = []
|
---|
| 231 |
|
---|
| 232 | self._eventBox = gtk.EventBox()
|
---|
| 233 |
|
---|
| 234 | self._table = gtk.Table(numRows, numColumns)
|
---|
| 235 | self._table.set_homogeneous(False)
|
---|
| 236 | self._table.set_col_spacings(16)
|
---|
| 237 | self._table.set_row_spacings(4)
|
---|
| 238 |
|
---|
| 239 | firstDelayCodeRow = True
|
---|
| 240 | for i in range(0, numRows):
|
---|
| 241 | (type, elements) = rows[i]
|
---|
| 242 | if type==CAPTION:
|
---|
| 243 | alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
|
---|
| 244 | xscale = 1.0)
|
---|
| 245 | label = gtk.Label("<b>" + elements + "</b>")
|
---|
| 246 | label.set_use_markup(True)
|
---|
| 247 | label.set_alignment(0.0, 0.5)
|
---|
| 248 | alignment.add(label)
|
---|
| 249 | self._table.attach(alignment, 1, numColumns, i, i+1)
|
---|
| 250 | self._table.set_row_spacing(i, 8)
|
---|
| 251 | elif type==DELAYCODE:
|
---|
| 252 | alignment = Alignment(xalign = 0.5, yalign = 0.5, xscale = 1.0)
|
---|
| 253 | alignment.add(gtk.CheckButton())
|
---|
| 254 | self._table.attach(alignment, 0, 1, i, i+1)
|
---|
| 255 | if firstDelayCodeRow:
|
---|
| 256 | self._alignments.append(alignment)
|
---|
| 257 |
|
---|
| 258 | for j in range(0, len(elements)):
|
---|
| 259 | label = gtk.Label(elements[j])
|
---|
| 260 | label.set_alignment(1.0 if j==0 else 0.0, 0.5)
|
---|
| 261 | alignment = Alignment(xalign = 0.5, yalign = 0.5,
|
---|
| 262 | xscale = 1.0)
|
---|
| 263 | alignment.add(label)
|
---|
| 264 | self._table.attach(alignment, j+1, j+2, i, i+1)
|
---|
| 265 | if firstDelayCodeRow:
|
---|
| 266 | self._alignments.append(alignment)
|
---|
| 267 | firstDelayCodeRow = False
|
---|
[433] | 268 |
|
---|
| 269 | self._viewport = self._createViewport()
|
---|
[435] | 270 | self._eventBox.add(self._table)
|
---|
| 271 | self._viewport.add(self._eventBox)
|
---|
[433] | 272 | self._viewport.set_shadow_type(SHADOW_NONE)
|
---|
| 273 |
|
---|
| 274 | self.pack_start(self._viewport, True, True, 0)
|
---|
| 275 |
|
---|
| 276 | self._previousWidth = 0
|
---|
| 277 |
|
---|
| 278 | def allocate_column_sizes(self, allocation):
|
---|
| 279 | """Allocate the column sizes."""
|
---|
| 280 | if allocation.width!=self._previousWidth:
|
---|
| 281 | self._previousWidth = allocation.width
|
---|
[435] | 282 | index = 0
|
---|
| 283 | for alignment in self._alignments:
|
---|
| 284 | column = self._treeView.get_column(index)
|
---|
| 285 | width = alignment.allocatedWidth + (8 if index==0 else 16)
|
---|
| 286 | column.set_fixed_width(width)
|
---|
| 287 | index += 1
|
---|
| 288 |
|
---|
[433] | 289 |
|
---|
| 290 | #------------------------------------------------------------------------------
|
---|