def __init__(self, parent, game, dir, size='large'): Tkinter.Toplevel.__init__(self) title = TITLE + ' - ' + _('Find card') self.title(title) self.wm_resizable(False, False) # ##self.images_dir = dir if size == 'large': self.images_dir = os.path.join(dir, 'large') self.label_width, self.label_height = LARGE_EMBLEMS_SIZE else: self.images_dir = os.path.join(dir, 'small') self.label_width, self.label_height = SMALL_EMBLEMS_SIZE self.canvas = MfxCanvas(self, bg='white') ##self.canvas = MfxCanvas(self, bg='black') self.canvas.pack(expand=True, fill='both') # self.groups = [] self.highlight_items = None self.busy = False self.connectGame(game) # bind(self, "WM_DELETE_WINDOW", self.destroy) bind(self, "<Escape>", self.destroy) # ##self.normal_timeout = 400 # in milliseconds self.normal_timeout = int(1000*game.app.opt.timeouts['highlight_samerank']) self.hidden_timeout = 200 self.timer = None
def createCardLabel(self, suit, rank, x0, y0): dx, dy = self.label_width, self.label_height dir = self.images_dir canvas = self.canvas group = MfxCanvasGroup(canvas) # im = FindCardDialog.CARD_IMAGES.get((rank, suit)) if im is None: r = '%02d' % (rank+1) s = 'cshd'[suit] fn = os.path.join(dir, r+s+'.gif') im = makeImage(file=fn) FindCardDialog.CARD_IMAGES[(rank, suit)] = im cim = MfxCanvasImage(canvas, x0, y0, image=im, anchor='nw') cim.addtag(group) cim.lower() # rect_width = 4 x1, y1 = x0+dx, y0+dy rect = MfxCanvasRectangle(self.canvas, x0+1, y0+1, x1-1, y1-1, width=rect_width, fill=None, outline='red', state='hidden' ) rect.addtag(group) # bind(group, '<Enter>', lambda e, suit=suit, rank=rank, rect=rect: self.enterEvent(suit, rank, rect, group)) bind(group, '<Leave>', lambda e, suit=suit, rank=rank, rect=rect: self.leaveEvent(suit, rank, rect, group)) self.groups.append(group)
def createButtons(self, frame, kw): button = column = -1 padx, pady = kw.get("buttonpadx", 10), kw.get("buttonpady", 10) focus = None max_len = 6 for s in kw.strings: if type(s) is types.TupleType: s = s[0] if s: s = re.sub(r"[\s\.\,]", "", s) max_len = max(max_len, len(s)) for s in kw.strings: xbutton = button = button + 1 if type(s) is types.TupleType: assert len(s) == 2 button = int(s[1]) s = s[0] if s is None: continue if button < 0: b = Tkinter.Button(frame, text=s, font=kw.buttonfont, state="disabled") button = xbutton else: b = Tkinter.Button( frame, text=s, font=kw.buttonfont, default="normal", command=( lambda self=self, button=button: self.mDone(button))) if button == kw.default: focus = b focus.config(default="active") l = len(s) if 1 and l < max_len: l = l + (max_len - l) / 2 b.config(width=l) column = column + 1 b.grid_configure(column=column, row=0, sticky="ew", padx=padx, pady=pady) b.grid_columnconfigure(column) if focus is not None: l = (lambda event=None, self=self, button=kw.default: self.mDone( button)) bind(self.top, "<Return>", l) bind(self.top, "<KP_Enter>", l) return focus
def __init__(self, parent, title="", resizable=False, default=-1): self.parent = parent self.status = 0 self.button = default self.timer = None self.buttons = [] self.accel_keys = {} self.top = makeToplevel(parent, title=title) self.top.wm_resizable(resizable, resizable) ##w, h = self.top.winfo_screenwidth(), self.top.winfo_screenheight() ##self.top.wm_maxsize(w-4, h-32) bind(self.top, "WM_DELETE_WINDOW", self.wmDeleteWindow)
def __init__(self, parent, title, app, player, gameid, **kw): kw = self.initKw(kw) title = _('Statistics') MfxDialog.__init__(self, parent, title, kw.resizable, kw.default) self.font = app.getFont('default') self.tkfont = tkFont.Font(parent, self.font) self.font_metrics = self.tkfont.metrics() style = ttk.Style(parent) heading_font = style.lookup('Heading', 'font') # treeview heading self.heading_tkfont = tkFont.Font(parent, heading_font) self.selected_game = None top_frame, bottom_frame = self.createFrames(kw) notebook = ttk.Notebook(top_frame) notebook.pack(expand=True, fill='both', padx=10, pady=10) self.notebook_tabs = [] single_frame = SingleGameFrame(self, notebook, app, player, gameid) notebook.add(single_frame, text=_('Current game')) self.notebook_tabs.append(single_frame._w) all_frame = AllGamesFrame(self, notebook, app, player) notebook.add(all_frame, text=_('All games')) self.all_games_frame = all_frame self.notebook_tabs.append(all_frame._w) top_frame = TopFrame(self, notebook, app, player, gameid) notebook.add(top_frame, text=TOP_TITLE) self.notebook_tabs.append(top_frame._w) if player is not None: progr_frame = ProgressionFrame(self, notebook, app, player, gameid) notebook.add(progr_frame, text=_('Progression')) self.notebook_tabs.append(progr_frame._w) if StatsDialog.SELECTED_TAB < len(self.notebook_tabs): notebook.select(StatsDialog.SELECTED_TAB) bind(notebook, '<<NotebookTabChanged>>', self.tabChanged) ##notebook.enableTraversal() self.notebook = notebook focus = self.createButtons(bottom_frame, kw) self.tabChanged() # configure buttons state self.mainloop(focus, kw.timeout)
def mainloop(self, focus=None, timeout=0): bind(self.top, "<Escape>", self.mCancel) if focus is not None: focus.focus() setTransient(self.top, self.parent) try: self.top.grab_set() except Tkinter.TclError: pass if timeout > 0: self.timer = after(self.top, timeout, self.mTimeout) try: self.top.mainloop() except SystemExit: pass self.destroy()
def __init__(self, parent, title, app, player, **kw): lines = 25 #if parent and parent.winfo_screenheight() < 600: # lines = 20 # self.font = app.getFont(self.FONT_TYPE) font = tkFont.Font(parent, self.font) self.font_metrics = font.metrics() self.CHAR_H = self.font_metrics['linespace'] self.CHAR_W = font.measure('M') self.app = app # self.player = player self.title = title self.sort_by = 'name' self.selected_game = None # kwdefault(kw, width=self.CHAR_W*64, height=lines*self.CHAR_H) kw = self.initKw(kw) MfxDialog.__init__(self, parent, title, kw.resizable, kw.default) top_frame, bottom_frame = self.createFrames(kw) self.createBitmaps(top_frame, kw) # self.top.wm_minsize(200, 200) self.button = kw.default # self.sc = AllGames_StatsDialogScrolledCanvas(top_frame, width=kw.width, height=kw.height) self.sc.pack(fill='both', expand=True, padx=kw.padx, pady=kw.pady) # self.nodes = {} self.canvas = self.sc.canvas self.canvas.dialog = self bind(self.canvas, "<1>", self.singleClick) self.fillCanvas(player, title) bbox = self.canvas.bbox("all") ##print bbox ##self.canvas.config(scrollregion=bbox) dx, dy = 4, 0 self.canvas.config(scrollregion=(-dx,-dy,bbox[2]+dx,bbox[3]+dy)) self.canvas.xview_moveto(-dx) self.canvas.yview_moveto(self.YVIEW) # focus = self.createButtons(bottom_frame, kw) self.mainloop(focus, kw.timeout)
def mainloop(self, focus=None, timeout=0, transient=True): bind(self.top, "<Escape>", self.mCancel) bind(self.top, '<Alt-Key>', self.altKeyEvent) # for accelerators if focus is not None: focus.focus() if transient: setTransient(self.top, self.parent) try: self.top.grab_set() except Tkinter.TclError: if traceback: traceback.print_exc() pass if timeout > 0: self.timer = after(self.top, timeout, self.mTimeout) try: self.top.mainloop() except SystemExit: pass self.destroy()
def __init__(self, parent, rootnodes, **kw): kw['bd'] = 0 kw['bg'] = 'white' MfxScrolledCanvas.__init__(self, parent, **kw) # self.rootnodes = rootnodes self.updateNodesWithTree(self.rootnodes, self) self.selection_key = None self.nodes = {} self.keys = {} # self.style = self.Style() ##self.style.text_normal_fg = self.canvas.cget("insertbackground") #self.style.text_normal_fg = self.canvas.option_get('foreground', '') or self.canvas.cget("insertbackground") #self.style.text_normal_bg = self.canvas.option_get('background', self.canvas.cget("background")) # bind(self.canvas, "<ButtonPress-1>", self.singleClick) bind(self.canvas, "<Double-Button-1>", self.doubleClick) ##bind(self.canvas, "<ButtonRelease-1>", xxx) self.pack(fill='both', expand=True)
def __init__(self, parent, title, usernames=[], **kw): kw = self.initKw(kw) MfxDialog.__init__(self, parent, title, kw.resizable, kw.default) top_frame, bottom_frame = self.createFrames(kw) self.createBitmaps(top_frame, kw) # listbox = Tkinter.Listbox(top_frame) listbox.pack(side="left", fill="both", expand=True) scrollbar = Tkinter.Scrollbar(top_frame) scrollbar.pack(side="right", fill="y") listbox.configure(yscrollcommand=scrollbar.set) scrollbar.configure(command=listbox.yview) self.username = None self.listbox = listbox bind(listbox, "<<ListboxSelect>>", self.updateUserName) # for un in usernames: listbox.insert("end", un) focus = self.createButtons(bottom_frame, kw) self.mainloop(focus, kw.timeout)
def __init__(self, parent, hbar=2, vbar=2, **kw): bg = kw.get("bg", parent.cget("bg")) kwdefault(kw, bg=bg, highlightthickness=0, xscrollincrement=16, yscrollincrement=16) self.parent = parent self.createFrame(kw) self.canvas = None self.hbar = None self.hbar_mode = hbar self.vbar = None self.vbar_mode = vbar self.hbar_show = 0 self.vbar_show = 0 self.resize_pending = 0 self.timer = None self.createCanvas(kw) self.frame.grid_rowconfigure(0, weight=1) self.frame.grid_columnconfigure(0, weight=1) if hbar: if hbar == 3: w = 21 if win32api: w = win32api.GetSystemMetrics(3) # SM_CYHSCROLL self.frame.grid_rowconfigure(1, minsize=w) self.createHbar(bg) if not vbar: bind(self.hbar, "<Map>", self._mapBar) self.bindHbar() if vbar: if vbar == 3: w = 21 if win32api: w = win32api.GetSystemMetrics(2) # SM_CXVSCROLL self.frame.grid_columnconfigure(1, minsize=w) self.createVbar(bg) bind(self.vbar, "<Map>", self._mapBar) self.bindVbar()
def __init__(self, parent, title="", resizable=0, default=-1): self.parent = parent self.status = 0 self.button = default self.timer = None self.top = makeToplevel(parent, title=title) self.top.wm_resizable(resizable, resizable) bind(self.top, "WM_DELETE_WINDOW", self.wmDeleteWindow) if self.img is None: _ToplevelDialog.img = (makeImage(dither=0, data=""" R0lGODlhIAAgAPICAH8AAH9/f7+/v/8AAP///wAAAAAAAAAAACH5BAEAAAIALAAAAAAgACAAAAPZ KLos8PC1SRccOGNYO9AgCHTNE57ZQwoA6mZAB7z0AFRA/QLBBISEFyEECDAAIYISpSSEAAwAqKkM UQkgQGABCF011xAgEBAAUFfMFQUICACu69UFCAgAL7nyBSADaHI0AGQANHI0AGQAL3oELwBkAC6N Si4AZAAoVxhXKABkAgAhVxpXIQBkAQIAIFchVyAAqQIAIU0oTSEAZAsAIQQvBCEAqQwAOi4AqQEM AMgoAKkTAM8gAKkVD9UPyx0BAMgAywErARAoEOMrC2QREeMB6w3w9AHyFfUrCQA7"""), makeImage(dither=0, data=""" R0lGODlhIAAgAPIDAAAAAAAA/39/f7+/v////wAAAAAAAAAAACH5BAEAAAMALAAAAAAgACAAAAPU OLo88vC1SRccJOsBa32DJo7D4zHCMK7jIJyDwA5BHQws4AksYds9AEXQI/xqRUBDMCgOfoPiAMAQ FK8sgEAhGGC/mgFAMBBcjzUsQDAQfI9YAOR7xAIg3yMWAPkesQAQA1hHVwMADwMCWEdXABADAgNX R0UDABAKAj1oNiwAEAwAYEUAEQ0ApCsAERQAA6oEAwARHgAAA18DtxEwArcAAysDwBECMAoQwAMa AMYPyAwRABoAxtEVAgAaAA/YyAAZAA/fyAAEAA/lyLcP68gQ78gPMAkAOw=="""), makeImage(dither=0, data=""" R0lGODlhIAAgAPIDAAAAAAAA/39/f7+/v////wAAAAAAAAAAACH5BAEAAAMALAAAAAAgACAAAAPp OLo88vC1SRccJOsBa32DJo7D4zHCMK7jIJyDwM4j4AnsEOz8wAIUAWsQGGR4gQEL0BAMWDsRkjUA MAQzZAY5AwgUgsEMSRggZwOAYCCgDXYDApJGAAgGArpmwNMDIHoZPIEAEIEEOwOBABCHO4cAEAOH hwMADwMCegM7A3oAEAMCA3RIdAMAEAoCdEh0ABAMADQDOwM0ABENAJQrABEUAAO9BAMAER4AAAOB A8oRMALKAAMrA9MRAjAKENMDGgDZD9sMEQAaANnkFQIAGgAP69sAGQAP8tsABAAP+NvKD/xtgyBw 2wMYCQAAOw=="""), makeImage(dither=0, data=""" R0lGODlhIAAgAPIDAAAAAH9/AH9/f7+/v///AAAAAAAAAAAAACH5BAEAAAMALAAAAAAgACAAAAPu OLq88S3KqQIhA9Atw70DIHDkEHwXIAglFaDXAKytFMAXsNZNgF8DwIq3CPwugBVxEDheBoAVMfAZ AK6DD2DFC6Cu4M8AsKoFUOArCrBqBWBpAGoAWJUCsDgMsCIFcHEwAwArHAE4AWABOAArGwE/A2AD OAMAKxQBR2BHACsTAU4BAAFHAwArEgFOAwADTgArEQFOFwC1AwArDQG1vhcAKwwBvgNXA04DACsL Ab5ptQArCgG/abUDACsDAb8DVwO+ACsDAb/nFwArAgHovwMA6wMB7k4DAOsCCgFx/f79+QQwCEiw oEEBEQ4qJKggAQA7"""))
def __init__(self, dialog, parent, app, player, **kw): ttk.Frame.__init__(self, parent) # self.dialog = dialog self.app = app self.CHAR_H = self.dialog.font_metrics['linespace'] self.CHAR_W = self.dialog.tkfont.measure('M') # self.player = player self.sort_by = 'name' self.tree_items = [] self.tree_tabs = None self.games = {} # tree_itemid: gameid # frame = ttk.Frame(self) frame.pack(fill='both', expand=True, padx=10, pady=10) vsb = ttk.Scrollbar(frame) vsb.grid(row=0, column=1, sticky='ns') self.tree = ttk.Treeview(frame, columns=self.COLUMNS, selectmode='browse') self.tree.grid(row=0, column=0, sticky='nsew') self.tree.config(yscrollcommand=vsb.set) vsb.config(command=self.tree.yview) frame.rowconfigure(0, weight=1) frame.columnconfigure(0, weight=1) hsb = ttk.Scrollbar(frame, orient='horizontal') hsb.grid(row=1, column=0, sticky='ew') self.tree.config(xscrollcommand=hsb.set) hsb.config(command=self.tree.xview) bind(self.tree, '<<TreeviewSelect>>', self.treeviewSelected) # self.formatter = TreeFormatter(self.app, self.tree, self, self.dialog.heading_tkfont, self.CHAR_W, self.CHAR_H) self.createHeader(player) bind(self.tree, '<Map>', self.mapEvent)
def initBindings(self): w = self.parent bind(w, "WM_DELETE_WINDOW", self.destroy) bind(w, "<Escape>", self.destroy) bind(w, "<KeyPress-Prior>", self.page_up) bind(w, "<KeyPress-Next>", self.page_down) bind(w, "<KeyPress-Up>", self.unit_up) bind(w, "<KeyPress-Down>", self.unit_down) bind(w, "<KeyPress-Begin>", self.scroll_top) bind(w, "<KeyPress-Home>", self.scroll_top) bind(w, "<KeyPress-End>", self.scroll_bottom) bind(w, "<KeyPress-BackSpace>", self.goBack)
def bind(self, sequence, func, add=None): bind(self._item, sequence, func, add)
def __init__(self, dialog, parent, app, player, gameid, **kw): ttk.Frame.__init__(self, parent) self.mapped = False self.dialog = dialog self.app = app self.player = player self.gameid = gameid self.items = [] self.formatter = ProgressionFormatter(app, player, gameid) frame = ttk.Frame(self) frame.pack(expand=True, fill='both', padx=5, pady=10) frame.columnconfigure(0, weight=1) # constants w = dialog.tkfont.measure('M') * 42 w = max(w, 500) w = min(w, 600) self.canvas_width, self.canvas_height = w, 250 if parent.winfo_screenwidth() < 800 or \ parent.winfo_screenheight() < 600: self.canvas_width, self.canvas_height = 400, 200 self.xmargin, self.ymargin = 10, 10 self.graph_dx, self.graph_dy = 10, 10 self.played_color = '#ff7ee9' self.won_color = '#00dc28' self.percent_color = 'blue' # create canvas self.canvas = canvas = Tkinter.Canvas(frame, bg='#dfe8ff', bd=0, highlightthickness=1, highlightbackground='black', width=self.canvas_width, height=self.canvas_height) canvas.pack(side='left', padx=5) # right frame right_frame = ttk.Frame(frame) right_frame.pack(side='left', fill='x', padx=5) self.all_games_variable = var = Tkinter.StringVar() var.set('all') b = ttk.Radiobutton(right_frame, text=_('All games'), variable=var, value='all', command=self.updateGraph) b.pack(fill='x', expand=True, padx=3, pady=1) b = ttk.Radiobutton(right_frame, text=_('Current game'), variable=var, value='current', command=self.updateGraph) b.pack(fill='x', expand=True, padx=3, pady=1) label_frame = ttk.LabelFrame(right_frame, text=_('Statistics for')) label_frame.pack(side='top', fill='x', pady=10) self.variable = var = Tkinter.StringVar() var.set('week') for v, t in ( ('week', _('Last 7 days')), ('month', _('Last month')), ('year', _('Last year')), ('all', _('All time')), ): b = ttk.Radiobutton(label_frame, text=t, variable=var, value=v, command=self.updateGraph) b.pack(fill='x', expand=True, padx=3, pady=1) label_frame = ttk.LabelFrame(right_frame, text=_('Show graphs')) label_frame.pack(side='top', fill='x') self.played_graph_var = Tkinter.BooleanVar() self.played_graph_var.set(True) b = ttk.Checkbutton(label_frame, text=_('Played'), command=self.updateGraph, variable=self.played_graph_var) b.pack(fill='x', expand=True, padx=3, pady=1) self.won_graph_var = Tkinter.BooleanVar() self.won_graph_var.set(True) b = ttk.Checkbutton(label_frame, text=_('Won'), command=self.updateGraph, variable=self.won_graph_var) b.pack(fill='x', expand=True, padx=3, pady=1) self.percent_graph_var = Tkinter.BooleanVar() self.percent_graph_var.set(True) b = ttk.Checkbutton(label_frame, text=_('% won'), command=self.updateGraph, variable=self.percent_graph_var) b.pack(fill='x', expand=True, padx=3, pady=1) #self.createGraph() bind(canvas, '<Map>', self.createGraph)
def bindVbar(self, w=None): if w is None: w = self.canvas bind(w, "<KeyPress-Prior>", self.page_up) bind(w, "<KeyPress-Next>", self.page_down) bind(w, "<KeyPress-Up>", self.unit_up) bind(w, "<KeyPress-Down>", self.unit_down) bind(w, "<KeyPress-Begin>", self.scroll_top) bind(w, "<KeyPress-Home>", self.scroll_top) bind(w, "<KeyPress-End>", self.scroll_bottom)
def bindHbar(self, w=None): if w is None: w = self.canvas bind(w, "<KeyPress-Left>", self.unit_left) bind(w, "<KeyPress-Right>", self.unit_right)
def __init__(self, parent, title, init_font, **kw): ##print init_font kw = self.initKw(kw) MfxDialog.__init__(self, parent, title, kw.resizable, kw.default) top_frame, bottom_frame = self.createFrames(kw) self.createBitmaps(top_frame, kw) self.font_family = 'Helvetica' self.font_size = 12 self.font_weight = 'normal' self.font_slant = 'roman' if init_font is not None: assert 2 <= len(init_font) <= 4 assert isinstance(init_font[1], int) self.font_family, self.font_size = init_font[:2] if len(init_font) > 2: if init_font[2] in ['bold', 'normal']: self.font_weight = init_font[2] elif init_font[2] in ['italic', 'roman']: self.font_slant = init_font[2] else: raise ValueError('invalid font style: '+init_font[2]) if len(init_font) > 3: if init_font[3] in ['bold', 'normal']: self.font_weight = init_font[3] elif init_font[2] in ['italic', 'roman']: self.font_slant = init_font[3] else: raise ValueError('invalid font style: '+init_font[3]) #self.family_var = Tkinter.StringVar() self.weight_var = Tkinter.BooleanVar() self.weight_var.set(self.font_weight == 'bold') self.slant_var = Tkinter.BooleanVar() self.slant_var.set(self.font_slant == 'italic') self.size_var = Tkinter.IntVar() self.size_var.set(self.font_size) # frame = ttk.Frame(top_frame) frame.pack(expand=True, fill='both', padx=5, pady=10) frame.columnconfigure(0, weight=1) #frame.rowconfigure(1, weight=1) self.entry = ttk.Entry(frame) self.entry.grid(row=0, column=0, columnspan=2, sticky='news') self.entry.insert('end', _('abcdefghABCDEFGH')) self.list_box = Tkinter.Listbox(frame, width=36, exportselection=False) sb = ttk.Scrollbar(frame) self.list_box.configure(yscrollcommand=sb.set) sb.configure(command=self.list_box.yview) self.list_box.grid(row=1, column=0, sticky='news') # rowspan=4 sb.grid(row=1, column=1, sticky='ns') bind(self.list_box, '<<ListboxSelect>>', self.fontupdate) ##self.list_box.focus() cb1 = ttk.Checkbutton(frame, text=_('Bold'), command=self.fontupdate, variable=self.weight_var) cb1.grid(row=2, column=0, columnspan=2, sticky='we') cb2 = ttk.Checkbutton(frame, text=_('Italic'), command=self.fontupdate, variable=self.slant_var) cb2.grid(row=3, column=0, columnspan=2, sticky='we') sc = PysolScale(frame, from_=6, to=40, resolution=1, label=_('Size:'), orient='horizontal', command=self.fontupdate, variable=self.size_var) sc.grid(row=4, column=0, columnspan=2, sticky='news') # font_families = list(tkFont.families()) font_families.sort() selected = -1 n = 0 self.list_box.insert('end', *font_families) for font in font_families: if font.lower() == self.font_family.lower(): selected = n break n += 1 if selected >= 0: self.list_box.select_set(selected) self.list_box.see(selected) # focus = self.createButtons(bottom_frame, kw) self.mainloop(focus, kw.timeout) self.font = (self.font_family, self.font_size, self.font_slant, self.font_weight)
def createButtons(self, frame, kw): padx, pady = 4, 4 xbutton = column = -1 focus = None max_len = 0 if 'sep' in kw.strings: sep_column = list(kw.strings).index('sep') strings = kw.strings[sep_column+1:] else: sep_column = 0 strings = kw.strings for s in strings: if isinstance(s, tuple): s = s[0] if s: s = s.replace('&', '') max_len = max(max_len, len(s)) ##print s, len(s) if max_len > 12 and WIN_SYSTEM == 'x11': button_width = max_len elif max_len > 9 : button_width = max_len+1 elif max_len > 6 : button_width = max_len+2 else : button_width = 8 # for s in kw.strings: if s is None: xbutton += 1 continue if s == 'sep': column += 1 continue if isinstance(s, tuple): assert len(s) == 2 button = int(s[1]) s = s[0] else: xbutton += 1 button = xbutton accel_indx = s.find('&') button_img = None if MfxDialog.button_img: button_img = MfxDialog.button_img.get(s) s = s.replace('&', '') if button < 0: widget = ttk.Button(frame, text=s, state="disabled") else: widget = ttk.Button(frame, text=s, default="normal", command = lambda self=self, button=button: \ self.mDone(button)) if button == kw.default: focus = widget focus.config(default="active") self.buttons.append(widget) # column += 1 if column >= sep_column: widget.config(width=button_width) else: widget.config(width=max(button_width, len(s))) if accel_indx >= 0: # key accelerator widget.config(underline=accel_indx) key = s[accel_indx] self.accel_keys[key.lower()] = widget # if button_img: widget.config(compound='left', image=button_img) widget.grid(column=column, row=0, sticky="nse", padx=padx, pady=pady) if focus is not None: l = lambda event=None, w=focus: w.event_generate('<<Invoke>>') bind(self.top, "<Return>", l) bind(self.top, "<KP_Enter>", l) # right justify frame.columnconfigure(sep_column, weight=1) return focus
def bindVbar(self, w=None): if w is None: w = self.canvas bind(w, "<KeyPress-Prior>", self.page_up) bind(w, "<KeyPress-Next>", self.page_down) bind(w, "<KeyPress-Up>", self.unit_up) bind(w, "<KeyPress-Down>", self.unit_down) bind(w, "<KeyPress-Begin>", self.scroll_top) bind(w, "<KeyPress-Home>", self.scroll_top) bind(w, "<KeyPress-End>", self.scroll_bottom) # mousewheel support if WIN_SYSTEM == 'x11': bind(w, '<4>', self.mouse_wheel_up) bind(w, '<5>', self.mouse_wheel_down)
def createButtons(self, frame, kw): button = -1 column = 0 padx, pady = kw.get("buttonpadx", 10), kw.get("buttonpady", 10) focus = None max_len = 0 for s in kw.strings: if isinstance(s, tuple): s = s[0] if s: #if os.name == 'posix': # s = s.replace('...', '.') s = s.replace('&', '') max_len = max(max_len, len(s)) ##print s, len(s) if max_len > 12 and WIN_SYSTEM == 'x11': button_width = max_len elif max_len > 9 : button_width = max_len+1 elif max_len > 6 : button_width = max_len+2 else : button_width = 8 #print 'button_width =', button_width # # for s in kw.strings: xbutton = button = button + 1 if isinstance(s, tuple): assert len(s) == 2 button = int(s[1]) s = s[0] if s is None: continue accel_indx = s.find('&') s = s.replace('&', '') if button < 0: b = Tkinter.Button(frame, text=s, state="disabled") button = xbutton else: b = Tkinter.Button(frame, text=s, default="normal", command=(lambda self=self, button=button: self.mDone(button))) if button == kw.default: focus = b focus.config(default="active") self.buttons.append(b) # b.config(width=button_width) if accel_indx >= 0: # key accelerator b.config(underline=accel_indx) key = s[accel_indx] self.accel_keys[key.lower()] = button # ## img = None ## if self.button_img: ## img = self.button_img.get(s) ## b.config(compound='left', image=img) column += 1 b.grid(column=column, row=0, sticky="ns", padx=padx, pady=pady) if focus is not None: l = (lambda event=None, self=self, button=kw.default: self.mDone(button)) bind(self.top, "<Return>", l) bind(self.top, "<KP_Enter>", l) frame.columnconfigure(0, weight=1) frame.columnconfigure(99, weight=1) return focus