1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
|
# -*- coding: utf-8 -*-
"""
Copyright (c) 2015, Jairus Martin.
Distributed under the terms of the MIT License.
The full license is in the file COPYING.txt, distributed with this software.
Created on Aug 23, 2015
"""
from atom.api import (
Bool,
ContainerList,
Enum,
ForwardInstance,
Int,
Property,
observe,
set_default,
)
from enaml.core.declarative import d_
from enaml.widgets.control import Control, ProxyControl
from .abstract_item import AbstractWidgetItemGroup
class ProxyAbstractItemView(ProxyControl):
#: Reference to the declaration
declaration = ForwardInstance(lambda: AbstractItemView)
def set_items(self, items):
pass
def set_selection_mode(self, mode):
pass
def set_selection_behavior(self, behavior):
pass
def set_selection(self, items):
pass
def set_scroll_to_bottom(self, scroll_to_bottom):
pass
def set_alternating_row_colors(self, alternate):
pass
def set_cell_padding(self, padding):
pass
def set_auto_resize(self, enabled):
pass
def set_resize_mode(self, mode):
pass
def set_word_wrap(self, enabled):
pass
def set_show_vertical_header(self, visible):
pass
def set_vertical_headers(self, headers):
pass
def set_vertical_stretch(self, stretch):
pass
def set_vertical_sizes(self, sizes):
pass
def set_vertical_minimum_section_size(self, size):
pass
def set_show_horizontal_header(self, visible):
pass
def set_horizontal_headers(self, headers):
pass
def set_horizontal_sizes(self, sizes):
pass
def set_horizontal_stretch(self, stretch):
pass
def set_horizontal_minimum_section_size(self, size):
pass
def set_sortable(self, sortable):
pass
def set_visible_row(self, row):
pass
def set_visible_column(self, column):
pass
class AbstractItemView(Control):
#: Table should expand by default
hug_width = set_default("ignore")
#: Table should expand by default
hug_height = set_default("ignore")
#: The items to display in the view
items = d_(ContainerList(default=[]))
#: Selection mode of the view
selection_mode = d_(Enum("extended", "none", "multi", "single", "contiguous"))
#: Selection behavior of the view
selection_behavior = d_(Enum("items", "rows", "columns"))
#: Selection
selection = d_(ContainerList(default=[]))
#: Automatically scroll to bottm when new items are added
scroll_to_bottom = d_(Bool(False))
#: Set alternating row colors
alternating_row_colors = d_(Bool(False))
#: Cell padding
cell_padding = d_(Int(0))
#: Automatically resize columns to fit contents
auto_resize = d_(Bool(True))
#: Resize mode of columns and rows
resize_mode = d_(
Enum("interactive", "fixed", "stretch", "resize_to_contents", "custom")
)
#: Word wrap
word_wrap = d_(Bool(False))
#: Show vertical header bar
show_vertical_header = d_(Bool(True))
#: Row headers
vertical_headers = d_(ContainerList())
#: Stretch last row
vertical_stretch = d_(Bool(False))
#: Sizes for vertical headers (list of int)
vertical_sizes = d_(ContainerList())
#: Minimum row size
vertical_minimum_section_size = d_(Int(0))
#: Show horizontal hearder bar
show_horizontal_header = d_(Bool(True))
#: Column headers
horizontal_headers = d_(ContainerList())
#: Stretch last column
horizontal_stretch = d_(Bool(False))
#: Minimum column size
horizontal_minimum_section_size = d_(Int(0))
#: Sizes for horizontal headers (list of int)
horizontal_sizes = d_(ContainerList())
#: Table is sortable
sortable = d_(Bool(True))
#: Current row index
current_row = d_(Int(0))
#: Current column index
current_column = d_(Int(0))
#: First visible row
visible_row = d_(Int(0))
#: Number of rows visible
visible_rows = d_(Int(100))
#: First visible column
visible_column = d_(Int(0))
#: Number of columns visible
visible_columns = d_(Int(1))
def _get_items(self):
return [c for c in self.children if isinstance(c, AbstractWidgetItemGroup)]
#: Cached property listing the row or columns of the table
_items = Property(_get_items, cached=True)
@observe(
"items",
"scroll_to_bottom",
"alternating_row_colors",
"selection_mode",
"selection_behavior",
"selection",
"cell_padding",
"auto_resize",
"resize_mode",
"word_wrap",
"show_horizontal_header",
"horizontal_headers",
"horizontal_sizes",
"horizontal_stretch",
"show_vertical_header",
"vertical_headers",
"vertical_stretch",
"vertical_sizes",
"visible_row",
"visible_column",
)
def _update_proxy(self, change):
"""An observer which sends state change to the proxy."""
# The superclass handler implementation is sufficient.
super(AbstractItemView, self)._update_proxy(change)
def child_added(self, child):
"""Reset the item cache when a child is added"""
super(AbstractItemView, self).child_added(child)
self.get_member("_items").reset(self)
def child_removed(self, child):
"""Reset the item cache when a child is removed"""
super(AbstractItemView, self).child_removed(child)
self.get_member("_items").reset(self)
|