def create_widgets(self, base): cc = self.cc # -- entry fr = fr1 = Frame(base).pack(side='top') cap = 'エントリ(&E)' pos, label = item_caption(cap) lab = Label(fr, text=label, underline=pos).pack(side='left', padx=3) ent = Entry(fr, name='input', width=25).pack(side='left', padx=3, pady=3) ent.bind('<Return>', self.bind_proc('input')) self.input = 'AAA' lab.label_for = ent ent.after_idle(lambda wi=ent:entry_focus(wi)) # -- passwod entry fr = Frame(base).pack(side='top') cap = 'パスワード(&P)' pos, label = item_caption(cap) lab = Label(fr, text=label, underline=pos).pack(side='left', padx=3) ent = Entry(fr, name='passwd', show='*', width=25).pack(side='left', padx=3, pady=3) ent.bind('<Return>', self.bind_proc('input')) self.passwd = 'BBB' lab.label_for = ent # -- combobox(Edit) fr = Frame(base).pack(side='top') cap = 'コンボボックス(&B)' pos, label = item_caption(cap) lab = Label(fr, text=label, underline=pos).pack(side='left', padx=3) ent = Combobox(fr, name='combo', width=25).pack(side='left', padx=3, pady=3) ent['values'] = ('AA', 'BB', 'CC') ent.current(1) self.combo = 'CCC' lab.label_for = ent ent.bind('<<ComboboxSelected>>', self.bind_proc('combo')) ent.bind('<Return>', self.bind_proc('combo')) ent.bind('<Control-j>', self.bind_proc('combo')) # -- readonly text ent = Entry(base, name='message', width=25, takefocus=0, state='readonly', style='TLabel').pack(side='top', padx=3, pady=3, before=fr1) self.message = 'Uneditable Text' # -- button fr = Frame(base).pack(side='top') cap = 'ボタン(&A)' pos, label = item_caption(cap) btn = Button(fr, text=label, underline=pos, command=self.menu_proc('apply')).pack(side='left', padx=3, pady=3) cap = 'close' pos, label = item_caption(cap) btn = Button(fr, text=label, underline=pos, command=self.menu_proc('close')) btn.pack(side='left', padx=3, pady=3) cc.bind('<Escape>', lambda ev, wi=btn: wi.invoke())
def create_widgets(self, base): """ コンポーネントを作成する """ cc = self.cc fr = Frame(base).pack(side='top') cal = _Calendar(fr).pack(side='left') cal.base = self self.cal1 = cal1 = cal (month, year) = cal.next_month() cal = _Calendar(fr, month, year).pack(side='left') cal.base = self self.cal2 = cal fr = Frame(base).pack(side='bottom') cap = '&Select' cap = '選択(&S)' pos, label = item_caption(cap) btn = Button(fr, text=label, underline=pos, command=self._pickup_date) btn.pack(side='left', padx=3, pady=3) cap = '&Today' cap = '今日(&T)' pos, label = item_caption(cap) btn = Button(fr, text=label, underline=pos, command=self._this_month) btn.pack(side='left', padx=3, pady=3) cap = '&Previous' cap = '先月(&P)' pos, label = item_caption(cap) btn = Button(fr, text=label, underline=pos, command=self._previous_month) btn.pack(side='left', padx=3, pady=3) cap = '&Next' cap = '来月(&N)' pos, label = item_caption(cap) btn = Button(fr, text=label, underline=pos, command=self._next_month) btn.pack(side='left', padx=3) var = StringVar() self.today = var now = _dt.now() tf = u'today: %s-%s-%s' tf = u'今日: %s-%s-%s' var.set(tf % (now.year, now.month, now.day)) cap = Label(fr, textvariable=var).pack(side='left', padx=3) cc.bind('<Control-w>', self.close) cc.bind('<Escape>', self.close) cal1.table.focus_set()
def create_widgets(self, tab): rows = 8 # -- left list fr = Frame(tab).pack(side='left', fill='both', expand=1) cap = "Source" pos, label = item_caption(cap) cap = Label(fr, text=label, underline=pos).pack(side='top', padx=3) lb = Listbox(fr, height=rows, selectmode=tk.EXTENDED).pack(side='left', fill='both', expand=1) lb.bind('<Double-1>', self._left_selected) lb.bind('<Return>', self._left_selected) ui.setup_theme(lb) sb = Scrollbar(fr).pack(side='left', fill='y', expand=0) sb.config(command=lb.yview) lb.config(yscrollcommand=sb.set) for nn in dir(self): lb.insert(END, nn) self.leftList = lb fr = Frame(tab).pack(side='left', fill='y') # -- button fr = Frame(tab).pack(side='left', fill='y', pady=10, padx=3) btn = Button(fr, text='>>', command=self._left_move_all).pack(side='top', pady=3) btn = Button(fr, text='<<', command=self._right_move_all).pack(side='top', pady=3) btn = Button(fr, text='>', command=self._left_selected).pack(side='top', pady=3) btn = Button(fr, text='<', command=self._right_selected).pack(side='top', pady=3) # -- right list fr = Frame(tab).pack(side='left', fill='both', expand=1) cap = "Selected" pos, label = item_caption(cap) cap = Label(fr, text=label, underline=pos).pack(side='top', padx=3) lb = Listbox(fr, height=rows, selectmode=tk.EXTENDED).pack(side='left', fill='both', expand=1) lb.bind('<Double-1>', self._right_selected) lb.bind('<Return>', self._right_selected) sb = Scrollbar(fr).pack(side='left', fill='y', expand=0) sb.config(command=lb.yview) lb.config(yscrollcommand=sb.set) self.rightList = lb
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): """構成コンポーネントの作成""" fr = self.cc.find_status_bar() nb = Notebook(base).pack(expand=1, fill='both', padx=5, pady=5) nb.enable_traversal() nb.tno = None tno = 0 tab_bind = {} def _tab_changed(event): """タブの切り替えで、まとめてバインド""" if nb.tno in tab_bind: for bk, proc in tab_bind[nb.tno]: self.cc.unbind(bk) nb.tno = nb.index('current') if nb.tno in tab_bind: for bk, proc in tab_bind[nb.tno]: self.cc.bind(bk, proc) # タブの切り替えで呼び出される仮想イベント nb.bind('<<NotebookTabChanged>>', _tab_changed) # -- 基本コンポーネントシート tab = Frame(nb).pack(expand=1, fill='both', padx=5, pady=5) cap = '&Basic' pos, label = item_caption(cap) nb.add(tab, text=label, underline=pos) self._create_basic_tab(tab) if hasattr(tab, 'blist'): tab_bind[tno] = tab.blist tno += 1 # -- ダイアログ呼び出し tab = Frame(nb).pack(expand=1, fill='both', padx=5, pady=5) cap = '&Dialog' pos, label = item_caption(cap) nb.add(tab, text=label, underline=pos) self._create_dialog_tab(tab) if hasattr(tab, 'blist'): tab_bind[tno] = tab.blist tno += 1 # -- リスト・コンポーネントシート if 1: tab = Frame(nb).pack(expand=1, fill='both', padx=5, pady=5) cap = '&List' pos, label = item_caption(cap) nb.add(tab, text=label, underline=pos) self._create_list_tab(tab) tno += 1 # -- テーブル表示のサンプル if 0: tab = Frame(nb).pack(expand=1, fill='both', padx=5, pady=5) cap = '&Table' pos, label = item_caption(cap) nb.add(tab, text=label, underline=pos) self._create_table_tab(tab) tno += 1 # -- テキスト表示のサンプル if 0: tab = Frame(nb).pack(expand=1, fill='both', padx=5, pady=5) cap = 'Te&xt' pos, label = item_caption(cap) nb.add(tab, text=label, underline=pos) self._create_text_tab(tab) tno += 1 # -- 下部のボタン配置 if 1: fr = Frame(base).pack(expand=0, side='bottom') cap = '&Close' pos, label = item_caption(cap) btn = Button(fr, text=label, underline=pos, command=self.dispose).pack(side='left', padx=3, pady=3) self.cc.bind('<Alt-%s>' % cap[pos + 1].lower(), lambda event, wi=btn: wi.invoke()) # -- キーバインドの設定 if 1: for ev, cmd in ( ('<Control-a>', 'select-all'), ('<Control-o>', 'open'), ('<Control-s>', 'save'), ('<Control-q>', 'exit'), ('<Control-w>', 'close'), ('<F5>', 'datetime'), ): self.cc.bind(ev, self.bind_proc(cmd))
def _create_dialog_tab(self, tab): """ダイアログ・タブシートの作成 """ blist = [] tab.blist = blist fr = Frame(tab).pack(side='top', fill='x', expand=0, padx=5, pady=5) cap = '&Open' pos, label = item_caption(cap) btn = Button(fr, text=label, underline=pos, command=self.menu_proc('open')).pack(side='left', padx=3, pady=3) self.multi = 1 cb = Checkbutton(fr, text='multiple', name='multi').pack(side='left', padx=3, pady=3) cap = '&Save' pos, label = item_caption(cap) btn = Button(fr, text=label, underline=pos, command=self.menu_proc('save')).pack(side='left', padx=3, pady=3) # -- ディレクトリ選択 fr = Frame(tab).pack(side='top', fill='x', expand=0, padx=5, pady=5) cap = '&Directory' pos, label = item_caption(cap) lab = Label(fr, text=label, underline=pos).pack(side='left', padx=3) ent = Entry(fr, width=25, name='dirinput').pack(side='left', padx=3, pady=3) ent.label = lab btn = tk.Button(fr, text='..', command=self.menu_proc('dir')).pack(side='left', padx=3, pady=3) # ポップアップ fr = LabelFrame(tab, text='message dialog').pack(side='top', fill='x', expand=0, padx=5, pady=5) for cap, cmd in ( ('&Information', 'info-msg'), ('&Warning', 'warn-msg'), ('&Error', 'error-msg'), ): pos, label = item_caption(cap) btn = Button(fr, text=label, underline=pos, command=self.menu_proc(cmd)) btn.pack(side='left', padx=3, pady=3) fr = LabelFrame(tab, text='confirm dialog').pack(side='top', fill='x', expand=0, padx=5, pady=5) for cap, cmd in ( ('&Yes No', 'yes-no'), ('&Retry Cancel', 'retry-cancel'), ('&Abort Retry Ignore', 'abort-retry-ignore'), ('Input &Text', 'input-text'), ): pos, label = item_caption(cap) btn = Button(fr, text=label, underline=pos, command=self.menu_proc(cmd)) btn.pack(side='left', padx=3, pady=3) # -- カレンダ選択 fr = Frame(tab).pack(side='top', fill='x', expand=0, padx=5, pady=5) cap = '&Calendar' pos, label = item_caption(cap) lab = Label(fr, text=label, underline=pos).pack(side='left', padx=3) ent = Entry(fr, width=15, name='datepickup').pack(side='left', padx=3, pady=3) ent.label = lab btn = tk.Button(fr, text='..', command=self.menu_proc('calendar-popup')).pack( side='left', padx=3, pady=3) # -- 色選択 fr = Frame(tab).pack(side='top', fill='x', expand=0, padx=5, pady=5) cap = '&Foreground' pos, label = item_caption(cap) lab = Label(fr, text=label, underline=pos).pack(side='left', padx=3) self.fg_sample = tk.Label(fr, text=' ').pack(side='left', padx=3) ent = Entry(fr, width=25, name='foreground').pack(side='left', padx=3, pady=3) ent.bind('<Return>', self.bind_proc('fg_color')) ent.label = lab btn = tk.Button(fr, text='..', command=self.menu_proc('fg_select')).pack(side='left', padx=3, pady=3) cn = 'black' self._set_fg_input(cn)
def _create_basic_tab(self, tab): """Basicタブを作成 """ fr = Frame(tab).pack(side='top') self.prompt = 'メッセージ表示(変更できます)' lab = Label(tab, name='prompt').pack(side='top', fill='x') # -- entry fr = Frame(tab).pack(side='top') cap = 'I&nput' pos, label = item_caption(cap) lab = Label(fr, text=label, underline=pos).pack(side='left', padx=3) self.input = 'aaa' ent = Entry(fr, width=25, name='input').pack(side='left', padx=3, pady=3) ent.bind('<Return>', self.bind_proc('input')) ent.label = lab entry_focus(ent) # -- passwod entry fr = Frame(tab).pack(side='top') cap = '&Password' pos, label = item_caption(cap) cap = Label(fr, text=label, underline=pos).pack(side='left', padx=3) self.passwd = 'bbb' ent = Entry(fr, show='*', width=25, name='passwd').pack(side='left', padx=3, pady=3) # -- button fr = Frame(tab).pack(side='top') CLOCK = 'ref/meza-bl-2.gif' img = find_image(CLOCK) cap = 'Change' pos, label = item_caption(cap) btn = Button(fr, text=label, underline=pos, image=img, compound='top', command=self.menu_proc('input')).pack(side='left', padx=3, pady=3) ui.set_tool_tip(btn, 'メッセージを入力値に置き換えます。') # -- combobox(Edit) fr = Frame(tab).pack(side='top') cap = 'Co&mbobox' pos, label = item_caption(cap) lab = Label(fr, text=label, underline=pos).pack(side='left', padx=3) ent = Combobox(fr, width=30, name='combo').pack(side='left', padx=3, pady=3) ent['values'] = ('AA', 'BB', 'CC') ent.current(1) self.combo_ent = ent ent.bind('<<ComboboxSelected>>', self.bind_proc('combo')) ent.bind('<Return>', self.bind_proc('combo')) ent.bind('<Control-j>', self.bind_proc('combo')) # -- combobox(Readonly) fr = Frame(tab).pack(side='top') cap = 'Theme &Select' pos, label = item_caption(cap) lab = Label(fr, text=label, underline=pos).pack(side='left', padx=3) themes = list(ui.style.theme_names()) themes.insert(0, 'Pick a theme') cmb = Combobox(fr, values=themes, state='readonly', height=8) cmb.set(themes[0]) cmb.pack(side='left', padx=3, pady=3) cmb.bind('<<ComboboxSelected>>', self.bind_proc('theme')) cmb.label = lab # -- Text fr = Frame(tab).pack(side='top') cap = '&Text' pos, label = item_caption(cap) lab = Label(fr, text=label, underline=pos).pack(side='left', padx=3) buf = Text(fr, undo=1, maxundo=50, width=25, height=3).pack(side='left', padx=3, pady=3) self.buf = buf lab.label_for = buf
def create_widgets(self, base): cc = self.cc fb = Frame(base).pack(side='top', fill='both', expand=1, padx=3, pady=3) item_count = 10 # ----- フォントファミリー fr = Frame(fb).pack(side='left', fill='both', expand=1, padx=3, pady=3) cap = 'Font &Family' cap = 'フォント名(&F)' pos, label = item_caption(cap) cap = Label(fr, text=label, underline=pos) cap.pack(side='top', fill='x', expand=0) self.family = var = StringVar() var.set('Terminal') tf = Entry(fr, width=20, textvariable=var).pack(side='top', fill='x', expand=0, padx=3, pady=3) ui.register_entry_popup(tf) fl = Frame(fr).pack(side='top', fill='both', expand=1) self.family_list = lb = Listbox(fl, height=item_count).pack(side='left', fill='both', expand=1) lb.bind('<Double-1>', self._select_family) sb = Scrollbar(fl).pack(side='left', fill='y', expand=0) sb.config(command=lb.yview) lb.config(yscrollcommand=sb.set) for nn in tkfont.families(): lb.insert(END, nn) # ----- サイズ fr = Frame(fb).pack(side='left', fill='both', expand=0, padx=3, pady=3) cap = '&Size' cap = '大きさ(&S)' pos, label = item_caption(cap) cap = Label(fr, text=label, underline=pos).pack(side='top', fill='x', expand=0) self.size = var = StringVar() var.set('9') tf = Entry(fr, width=5, textvariable=var).pack(side='top', fill='x', expand=0, padx=3, pady=3) ui.register_entry_popup(tf) fl = Frame(fr).pack(side='top', fill='both', expand=1) lb = self.size_list = Listbox(fl, width=5, height=item_count).pack(side='left', fill='both', expand=1) lb.bind('<Double-1>', self._select_size) sb = Scrollbar(fl).pack(side='left', fill='y', expand=0) sb.config(command=lb.yview) lb.config(yscrollcommand=sb.set) for nn in size_list: lb.insert(END, nn) # ----- スタイル fr = Frame(fb).pack(side='left', fill='x', expand=0, padx=3, pady=3) self.bold = var = BooleanVar() var.set(1) cap = '&Bold' cap = '太字(&B)' pos, label = item_caption(cap) cb = Checkbutton(fr, variable=var, text=label, underline=pos, command=self._change_style).pack() self.italic = var = BooleanVar() var.set(0) cap = '&Italic' cap = '斜字(&I)' pos, label = item_caption(cap) cb = Checkbutton(fr, variable=var, text=label, underline=pos, command=self._change_style).pack() # ----- サンプルテキスト fr = Frame(base).pack(side='top', fill='x', expand=0, padx=3, pady=3) self.sample = var = StringVar() var.set('''AaBbCcDdEe\nFfGgHhIiJjK\n1234567890\n#:+=(){}[] あいうえお\nアイウエオ亜愛 ''') cap = Label(fr, textvariable=var).pack() var.cap = cap cc.bind('<MouseWheel>', self._adjust_size, '+') cc.bind('<Button-4>', self._adjust_size, '+') cc.bind('<Button-5>', self._adjust_size, '+') # ----- ボタン等 fr = Frame(base).pack(side='bottom', fill='x', expand=0, padx=3, pady=3) cap = '&OK' cap = '選択(&O)' pos, label = item_caption(cap) btn = Button(fr, text=label, underline=pos, command=self._do_ok).pack(side='left', padx=3, pady=3) cap = '&Apply' cap = '適用(&A)' pos, label = item_caption(cap) btn = Button(fr, text=label, underline=pos, command=self._do_apply).pack(side='left', padx=3, pady=3) #cc.bind('<Alt-a>', lambda event, wi=btn: wi.focus()) cap = '&Cancel' cap = '閉じる(&C)' pos, label = item_caption(cap) btn = Button(fr, text=label, underline=pos, command=self._do_cancel).pack(side='left', padx=3, pady=3) cc.bind('<Escape>', lambda ev, wi=btn: wi.invoke()) for ev, cmd in (('<Control-w>', 'close'), ): cc.bind(ev, self.bind_proc(cmd))
def create_widgets(self, base): """構成コンポーネントの作成""" blist = [] cc = self.cc # ----- 検索キーワード fr = Frame(base).pack(side='top', fill='x', expand=1, padx=3, pady=3) self.keyFrame = fr cap = 'Search &Word' cap = '検索テキスト(&W)' pos, label = item_caption(cap) lab = Label(fr, text=label, underline=pos).pack(side='left', padx=5) tf = self.fkey_ent = Combobox(fr, width=30, name='fkey').pack(side='left', fill='x', expand=1, padx=3, pady=3) tf['values'] = searchWords tf.focus() lab.label_for = tf tf.bind('<Return>', self._do_find) tf.bind('<Control-j>', self._do_find) # ----- 置換キーワード fr = Frame(base).pack(side='top', fill='x', expand=1) self.replaceFrame = fr cap = '&Replace With' cap = '置換テキスト(&R)' pos, label = item_caption(cap) lab = Label(fr, text=label, underline=pos).pack(side='left', padx=5) tf = self.rkey_ent = Combobox(fr, width=30, name='rkey').pack(side='left', fill='x', expand=1, padx=3, pady=3) tf['values'] = replaceWords lab.label_for = tf self.rkey = '' # ----- 検索方向 cap = 'Direction' cap = '検索方向' fr = LabelFrame(base, labelanchor='w', text=cap).pack(side='top', padx=2, pady=2) cap = '&Forward' cap = '文末に向かって(&F)' pos, label = item_caption(cap) Radiobutton(fr, text=label, underline=pos, name='fdir/forward').pack(side='left') cap = '&Backward' cap = '文頭に向かって(&B)' pos, label = item_caption(cap) Radiobutton(fr, text=label, underline=pos, name='fdir/backward').pack(side='left') self.fdir = 'forward' # ----- オプション fr = Frame(base).pack(side='top') cap = '&Ignore case' cap = '文字のケースを無視(&I)' pos, label = item_caption(cap) Checkbutton(fr, text=label, underline=pos, name='ignoreCase').pack(side='left') self.ignoreCase = False cap = 'Regular &Expression' cap = '正規表現(&E)' pos, label = item_caption(cap) Checkbutton(fr, text=label, underline=pos, name='regularExp').pack(side='left') self.regularExp = False # ----- ボタンなど fr = Frame(base).pack(side='top', fill='x') cap = 'Find &Next' cap = '次を検索(&N)' pos, label = item_caption(cap) btn = Button(fr, text=label, underline=pos, command=self._do_find) btn.pack(side='left', padx=3, pady=3) self.findButton = btn cap = 'Replace and Fin&d' cap = '置き換えて次を検索(&D)' pos, label = item_caption(cap) btn = Button(fr, text=label, underline=pos, command=self._do_replace) btn.pack(side='left', padx=3, pady=3) self.replaceButton = btn if self.with_hilight: cap = '&Hilight' pos, label = item_caption(cap) btn = Button(fr, text=label, underline=pos, command=self._do_hilight) btn.pack(side='left', padx=3, pady=3) cap = '&Close' cap = '閉じる(&C)' pos, label = item_caption(cap) btn = Button(fr, text=label, underline=pos, command=self.menu_proc('close')) btn.pack(side='left', padx=3, pady=3) cc.bind('<Escape>', lambda ev, wi=btn: wi.invoke()) for bk, proc in blist: cc.bind(bk, proc)