def create_widgets(self, base): cc = self.cc cc.find_status_bar() if False: fr = Frame(base) fr.pack(side='top', fill='x') cap = '&Tree Editor' cap = 'ツリーエディタ(&T)' pos, label = item_caption(cap) cap = Label(fr, text=label, underline=pos).pack(side='left') fr = Frame(base).pack(side='top', fill='both', expand=1) tree = Treeview(fr, show='tree', takefocus=True, height=10, selectmode='extended') self.tree = tree ysb = Scrollbar(fr, orient='vertical', command=tree.yview) ysb.pack(side='right', fill='y') tree.configure(yscroll=ysb.set) tree.pack(side='top', fill='both', expand=1) tree.heading('#0', text='Path', anchor='w') shortcut = self.find_menu('tree-shortcut') ui.register_shortcut(tree, shortcut) tree.timer = None delay_msec = 600 def _delay_proc(event): # 遅延表示 if tree.timer: tree.after_cancel(tree.timer) tiid = tree.focus() if tiid: tree.timer = tree.after( delay_msec, lambda wi=tree, iid=tiid: trace(wi.index(iid), wi.item(iid, 'text'), iid)) tree.bind('<<TreeviewSelect>>', _delay_proc) tree.bind('<<TreeviewOpen>>', _delay_proc) tree.bind('<<TreeviewClose>>', _delay_proc) sm = cc.menu['select-mode'] sm.set('sm.extended') self.selection_mode = sm self.__test_data(tree) for ev, cmd in ( ('<Control-c>', 'copy'), ('<Control-Insert>', 'copy'), ('<Control-v>', 'paste'), ('<Shift-Insert>', 'paste'), ('<Delete>', 'delete-node'), ('<F2>', 'rename'), ('<Control-w>', 'close'), ('<Control-Right>', 'expand-all'), ('<Control-Left>', 'collapse-all'), ): tree.bind(ev, self.bind_proc(cmd))
def create_widgets(self, base, ModelClass=_EmptyTableData, *args, **opts): """コンポーネントを作成する""" cc = self.cc td = ModelClass(*args, **opts) hinfo = td.column_info cols = [hi[0] for hi in hinfo] if not cols: raise ui.AppException('no column') fr = Frame(base) self.style_name = tree_style = 'Sheet%d.Treeview' % 1 self.table = tbl = Treeview(fr, takefocus=1, show='tree headings', columns=cols, style=tree_style) fr.pack(side='top', expand=1, fill='both') ysb = Scrollbar(fr, orient='vertical', command=tbl.yview) tbl.configure(yscroll=ysb.set) ysb.pack(side='right', fill='y') xsb = Scrollbar(base, orient='horizontal', command=tbl.xview) tbl.configure(xscroll=xsb.set) xsb.bind('<MouseWheel>', lambda e, wi=tbl: wi.xview_scroll( -1 * (1 if e.delta > 0 else -1), 'page')) xsb.bind('<Enter>', lambda e, wi=xsb: wi.focus_set()) if len(hinfo[0]) == 4: for col, cap, w, st in hinfo: tbl.heading(col, text=cap, command=lambda c=col: sorter(tbl, c, c, 0)) tbl.column(col, stretch=st, width=w) elif len(hinfo[0]) == 6: for col, cap, w, st, sc, isFloat in hinfo: tbl.heading(col, text=cap, command=lambda tc=col, c=sc, fc=isFloat: sorter( tbl, tc, c, 0, fc)) tbl.column(col, stretch=st, width=w) tbl.column('#0', stretch=False, width=80, anchor='e') #tbl.heading('#0', anchor='e') tbl.pack(side='left', expand=1, fill='both') xsb.pack(side='top', fill='x') ui.register_editable_cell(tbl) self._load_table_data(td) if 0: # フォントを指定する場合 def set_font(font): self.font = font fn = 'Times-10-normal' tbl.after_idle(lambda font=fn: set_font(font)) shortcut = self.find_menu('tsv-shortcut') ui.register_shortcut(tbl, shortcut) for ev, cmd in ( ('<Control-a>', 'select-all'), ('<Control-c>', 'copy'), ('<Control-d>', 'delete'), ('<Control-Insert>', 'copy'), ('<Control-v>', 'paste'), ('<Shift-Insert>', 'paste'), ('<Control-d>', 'duplicate'), ('<Control-q>', 'exit'), ('<Control-w>', 'close'), ('<Delete>', 'delete'), ): tbl.bind(ev, self.bind_proc(cmd)) cc.bind('<MouseWheel>', self._adjust_font_size, '+') cc.bind('<Button-4>', self._adjust_font_size, '+') cc.bind('<Button-5>', self._adjust_font_size, '+')