TabularAdapter 的列宽?
Column widths with TabularAdapters?
使用 Enthought Canopy 的 TraitsUI,我正在使用 TabularAdapters 来显示一些数组,但它们总是产生均匀比例的列宽...我想让一些宽度比其他宽度小,但还没有找到任何简单的还好...有人有什么建议吗?
控制列宽的一种方法是覆盖 TabularArrayAdapter
的 get_width()
方法。例如,
import numpy as np
from traits.api import HasTraits, Array
from traitsui.api import View, Item, TabularEditor
from traitsui.tabular_adapter import TabularAdapter
test_dtype = np.dtype([('x', 'int'),
('y', 'int'),
('r', 'float')])
class TestArrayAdapter(TabularAdapter):
columns = [(name, idx) for idx, name in enumerate(test_dtype.names)]
even_bg_color = 0xF0F4FF
def get_width(self, object, name, col):
widths = {0: 50, 1: 50, 2: 150}
return widths[col]
class Test(HasTraits):
array1 = Array(dtype=test_dtype)
view = \
View(
Item(name='array1', show_label=False,
editor=TabularEditor(adapter=TestArrayAdapter())),
resizable=True,
)
a1 = np.array([(10, 20, 1.5), (15, 31, 2.4), (14, 11, 1.9), (21, 13, 2.5)],
dtype=test_dtype)
test = Test(array1=a1)
test.configure_traits()
截图:
使用 Enthought Canopy 的 TraitsUI,我正在使用 TabularAdapters 来显示一些数组,但它们总是产生均匀比例的列宽...我想让一些宽度比其他宽度小,但还没有找到任何简单的还好...有人有什么建议吗?
控制列宽的一种方法是覆盖 TabularArrayAdapter
的 get_width()
方法。例如,
import numpy as np
from traits.api import HasTraits, Array
from traitsui.api import View, Item, TabularEditor
from traitsui.tabular_adapter import TabularAdapter
test_dtype = np.dtype([('x', 'int'),
('y', 'int'),
('r', 'float')])
class TestArrayAdapter(TabularAdapter):
columns = [(name, idx) for idx, name in enumerate(test_dtype.names)]
even_bg_color = 0xF0F4FF
def get_width(self, object, name, col):
widths = {0: 50, 1: 50, 2: 150}
return widths[col]
class Test(HasTraits):
array1 = Array(dtype=test_dtype)
view = \
View(
Item(name='array1', show_label=False,
editor=TabularEditor(adapter=TestArrayAdapter())),
resizable=True,
)
a1 = np.array([(10, 20, 1.5), (15, 31, 2.4), (14, 11, 1.9), (21, 13, 2.5)],
dtype=test_dtype)
test = Test(array1=a1)
test.configure_traits()
截图: