[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 |
|
---|
| 40 | # if alloc is not None:
|
---|
| 41 | # import gi.repository.cairo
|
---|
| 42 | # allocation1 = gi.repository.cairo.RectangleInt()
|
---|
| 43 | # allocation1.x = allocation.x
|
---|
| 44 | # allocation1.y = allocation.y
|
---|
| 45 | # allocation1.width = allocation.width
|
---|
| 46 | # allocation1.height = height = alloc[3] - allocation.y
|
---|
| 47 | # allocation = allocation1
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 | __gproperties__ = {
|
---|
| 52 | "vscroll-policy" : ( gtk.ScrollablePolicy,
|
---|
| 53 | "vscroll-policy",
|
---|
| 54 | "The vertical scrolling policy",
|
---|
| 55 | gtk.ScrollablePolicy.MINIMUM,
|
---|
| 56 | gobject.PARAM_READWRITE ),
|
---|
| 57 | "vadjustment" : ( gtk.Adjustment,
|
---|
| 58 | "vadjustment",
|
---|
| 59 | "The vertical adjustment",
|
---|
| 60 | gobject.PARAM_READWRITE ),
|
---|
| 61 | "hscroll-policy" : ( gtk.ScrollablePolicy,
|
---|
| 62 | "hscroll-policy",
|
---|
| 63 | "The horizontal scrolling policy",
|
---|
| 64 | gtk.ScrollablePolicy.MINIMUM,
|
---|
| 65 | gobject.PARAM_READWRITE ),
|
---|
| 66 | "hadjustment" : ( gtk.Adjustment,
|
---|
| 67 | "hadjustment",
|
---|
| 68 | "The horizontal adjustment",
|
---|
| 69 | gobject.PARAM_READWRITE ) }
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | @staticmethod
|
---|
| 73 | def _createViewport():
|
---|
| 74 | """Create an instance of the viewport class used by this base class."""
|
---|
| 75 | return Viewport()
|
---|
| 76 |
|
---|
| 77 | def __init__(self):
|
---|
| 78 | """Construct the delay code table."""
|
---|
| 79 | super(DelayCodeTableBase, self).__init__()
|
---|
| 80 |
|
---|
| 81 | def do_size_allocate(self, allocation):
|
---|
| 82 | """Allocate the size for the table and its children.
|
---|
| 83 |
|
---|
| 84 | This sets up the VBox height in the viewport and then calls the
|
---|
| 85 | do_size_allocate() function of VBox()."""
|
---|
| 86 | self._viewport.setVBOXHeight(allocation.height)
|
---|
| 87 | gtk.VBox.do_size_allocate(self, allocation)
|
---|
| 88 | self.allocate_column_sizes(allocation)
|
---|
| 89 |
|
---|
| 90 | def do_get_property(self, prop):
|
---|
| 91 | """Get the value of one of the properties defined above.
|
---|
| 92 |
|
---|
| 93 | The request is forwarded to the viewport."""
|
---|
| 94 | if prop.name=="vscroll-policy":
|
---|
| 95 | return self._viewport.get_vscroll_policy()
|
---|
| 96 | elif prop.name=="hscroll-policy":
|
---|
| 97 | return self._viewport.get_hscroll_policy()
|
---|
| 98 | elif prop.name=="vadjustment":
|
---|
| 99 | return self._viewport.get_vadjustment()
|
---|
| 100 | elif prop.name=="hadjustment":
|
---|
| 101 | return self._viewport.get_hadjustment()
|
---|
| 102 | else:
|
---|
| 103 | raise AttributeError("mlx.gui.delaycodes.DelayCodeTableBase: property %s is not handled in do_get_property" %
|
---|
| 104 | (prop.name,))
|
---|
| 105 |
|
---|
| 106 | def do_set_property(self, prop, value):
|
---|
| 107 | """Set the value of the adjustment properties defined above.
|
---|
| 108 |
|
---|
| 109 | The adjustments are forwarded to the viewport."""
|
---|
| 110 | if prop.name=="vadjustment":
|
---|
| 111 | self._viewport.set_vadjustment(value)
|
---|
| 112 | elif prop.name=="hadjustment":
|
---|
| 113 | self._viewport.set_hadjustment(value)
|
---|
| 114 | else:
|
---|
| 115 | raise AttributeError("mlx.gui.delaycodes.DelayCodeTableBase: property %s is not handled in do_set_property" %
|
---|
| 116 | (prop.name,))
|
---|
| 117 |
|
---|
| 118 | #------------------------------------------------------------------------------
|
---|
| 119 |
|
---|
| 120 | else: # pygobject
|
---|
| 121 |
|
---|
| 122 | #------------------------------------------------------------------------------
|
---|
| 123 |
|
---|
| 124 | class DelayCodeTableBase (gtk.VBox):
|
---|
| 125 | """Base class of the delay code table for PyGtk."""
|
---|
| 126 |
|
---|
| 127 | __gsignals__ = {
|
---|
| 128 | "set-scroll-adjustments": (
|
---|
| 129 | gobject.SIGNAL_RUN_LAST,
|
---|
| 130 | gobject.TYPE_NONE, (gtk.Adjustment, gtk.Adjustment))
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | @staticmethod
|
---|
| 134 | def _createViewport():
|
---|
| 135 | """Create an instance of the viewport class used by this base class."""
|
---|
| 136 | return gtk.Viewport()
|
---|
| 137 |
|
---|
| 138 | def __init__(self):
|
---|
| 139 | """Construct the base class."""
|
---|
| 140 | super(DelayCodeTableBase, self).__init__()
|
---|
| 141 | self.set_set_scroll_adjustments_signal("set-scroll-adjustments")
|
---|
| 142 | self.connect("size-allocate", self._do_size_allocate)
|
---|
| 143 |
|
---|
| 144 | def do_set_scroll_adjustments(self, hAdjustment, vAdjustment):
|
---|
| 145 | """Set the adjustments on the viewport."""
|
---|
| 146 | self._viewport.set_hadjustment(hAdjustment)
|
---|
| 147 | self._viewport.set_vadjustment(vAdjustment)
|
---|
| 148 |
|
---|
| 149 | def _do_size_allocate(self, widget, allocation):
|
---|
| 150 | """Handler of the size-allocate signal.
|
---|
| 151 |
|
---|
| 152 | Calls allocate_column_sizes()."""
|
---|
| 153 | self.allocate_column_sizes(allocation)
|
---|
| 154 |
|
---|
| 155 | #------------------------------------------------------------------------------
|
---|
| 156 |
|
---|
| 157 | class DelayCodeTable(DelayCodeTableBase):
|
---|
| 158 | """The delay code table."""
|
---|
| 159 | def __init__(self):
|
---|
| 160 | """Construct the delay code table."""
|
---|
| 161 | super(DelayCodeTable, self).__init__()
|
---|
| 162 |
|
---|
| 163 | self._listStore = gtk.ListStore(str, str, str, str)
|
---|
| 164 | self._treeView = gtk.TreeView(self._listStore)
|
---|
| 165 | column = gtk.TreeViewColumn("IATA", gtk.CellRendererText())
|
---|
| 166 | column.set_sizing(TREE_VIEW_COLUMN_FIXED)
|
---|
| 167 | self._treeView.append_column(column)
|
---|
| 168 | column = gtk.TreeViewColumn("Description", gtk.CellRendererText())
|
---|
| 169 | column.set_sizing(TREE_VIEW_COLUMN_FIXED)
|
---|
| 170 | self._treeView.append_column(column)
|
---|
| 171 |
|
---|
| 172 | self.pack_start(self._treeView, False, False, 0)
|
---|
| 173 |
|
---|
| 174 | self._table = gtk.Table(10, 2)
|
---|
| 175 | for i in range(0, 10):
|
---|
| 176 | self._table.attach(gtk.Label("ZZZ" + `i`), 0, 1, i, i+1)
|
---|
| 177 | self._table.attach(gtk.Label("AAA" + `i`), 1, 2, i, i+1)
|
---|
| 178 |
|
---|
| 179 | self._viewport = self._createViewport()
|
---|
| 180 | self._viewport.add(self._table)
|
---|
| 181 | self._viewport.set_shadow_type(SHADOW_NONE)
|
---|
| 182 |
|
---|
| 183 | self.pack_start(self._viewport, True, True, 0)
|
---|
| 184 |
|
---|
| 185 | self._previousWidth = 0
|
---|
| 186 |
|
---|
| 187 | def allocate_column_sizes(self, allocation):
|
---|
| 188 | """Allocate the column sizes."""
|
---|
| 189 | if allocation.width!=self._previousWidth:
|
---|
| 190 | self._previousWidth = allocation.width
|
---|
| 191 | column0 = self._treeView.get_column(0)
|
---|
| 192 | column0.set_fixed_width(allocation.width/2)
|
---|
| 193 | column1 = self._treeView.get_column(1)
|
---|
| 194 | column1.set_fixed_width(allocation.width/2)
|
---|
| 195 |
|
---|
| 196 | #------------------------------------------------------------------------------
|
---|