def __init__(self, **kwargs):
super().__init__(**kwargs)
if 'background_color' not in kwargs:
self.background_color = 'white'
if 'frame' not in kwargs:
self.width = min(ui.get_window_size()[0] * 0.8, 700)
self.height = ui.get_window_size()[1] * 0.8
self._tableview = ui.TableView()
self._textfield = ui.TextField()
self._help_label = ui.Label()
self._datasource = None
self._handlers = None
self.shift_enter_enabled = True
self.did_select_item_action = None
tf = LayoutProxy(self._textfield)
self.add_subview(tf)
tf.layout.align_left_with_superview.equal = 8
tf.layout.align_top_with_superview.equal = 8
tf.layout.align_right_with_superview.equal = -8
tf.layout.height.equal = 31
tf.delegate = self
tv = LayoutProxy(self._tableview)
self.add_subview(tv)
tv.layout.align_left_to(tf).equal = 0
tv.layout.align_right_to(tf).equal = 0
tv.layout.top_offset_to(tf).equal = 8
tv.allows_selection = True
tv.allows_multiple_selection = False
hl = LayoutProxy(self._help_label)
self.add_subview(hl)
hl.layout.align_left_to(tv).equal = 0
hl.layout.align_right_to(tv).equal = 0
hl.layout.top_offset_to(tv).equal = 8
hl.layout.align_bottom_with_superview.equal = -8
hl.layout.height.max = 66
hl.font = ('<system>', 13.0)
hl.alignment = ui.ALIGN_CENTER
hl.text_color = (0, 0, 0, 0.5)
hl.number_of_lines = 2
if is_in_hardware_keyboard_mode:
tf.view.begin_editing()
self._register_key_event_handlers()
python类Label()的实例源码
def tableview_cell_for_row(self, tv, section, row):
if section == self._folder_section:
item = self.items[row]
node = item['node']
else:
item = self._files[row]
node = None
cell = ui.TableViewCell()
cvb = cell.content_view.bounds
x = 15 + cvb.x + item['level'] * 15
if node and node.children_exists:
image_view = ui.ImageView()
image_view.frame = (x, 10, 24, 24)
image_view.image = ui.Image.named(
'iob:arrow_down_b_24' if node.path in self._expanded_node_paths else 'iob:arrow_right_b_24'
)
cell.content_view.add_subview(image_view)
x += 24 + 8
image_view = ui.ImageView()
image_view.frame = (x, 10, 24, 24)
image_view.image = ui.Image.named('iob:folder_24' if node else 'iob:document_24')
cell.content_view.add_subview(image_view)
x += 24 + 8
title_label = ui.Label(flex='W')
title_label.text = item['title']
title_label.size_to_fit()
title_label.frame = (
x, cvb.y + (cvb.height - title_label.height) / 2.0,
cvb.width - (x - cvb.x) - 8, title_label.height
)
cell.content_view.add_subview(title_label)
separator = ui.View(flex='W')
separator.background_color = (0, 0, 0, 0.05)
x = title_label.frame.x - 12 - 8
separator.frame = (
x, cvb.y + cvb.height - 1,
cvb.width - (x - cvb.x), 1
)
cell.content_view.add_subview(separator)
cell_objc = ObjCInstance(cell)
cell_objc.setSelectionStyle(0)
return cell