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 __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")) # from pysollib.options import calcCustomMouseButtonsBinding bind(self.canvas, calcCustomMouseButtonsBinding("<ButtonPress-{mouse_button1}>"), self.singleClick) bind(self.canvas, calcCustomMouseButtonsBinding("<Double-Button-{mouse_button1}>"), self.doubleClick) # bind(self.canvas, # calcCustomMouseButtonsBinding( # "<ButtonRelease-{mouse_button1}>"), xxx) self.pack(fill='both', expand=True)
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 __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 __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 = tkinter_font.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 = tkinter_font.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 __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 = tkinter_font.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 from pysollib.options import calcCustomMouseButtonsBinding bind(self.canvas, calcCustomMouseButtonsBinding("<{mouse_button1}>"), 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 __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 = tkinter_font.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, 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 __init__(self, parent, title, app, manager, key=None, **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) # if key is None: key = manager.getSelected() self.manager = manager self.key = key self.app = app self.cardset_values = None # padx, pady = kw.padx, kw.pady padx, pady = 4, 4 if self.TreeDataHolder_Class.data is None: self.TreeDataHolder_Class.data = self.TreeData_Class(manager, key) # sw = self.top.winfo_screenwidth() sh = self.top.winfo_screenheight() h = int(sh * .8) w = int(sw * .8) w1 = int(min(275, sw / 2.5)) geometry = ("%dx%d+%d+%d" % (w, h, (sw - w) / 2, (sh - h) / 2)) self.top.wm_minsize(400, 200) paned_window = ttk.PanedWindow(top_frame, orient='horizontal') paned_window.pack(expand=True, fill='both', padx=8, pady=8) left_frame = ttk.Frame(paned_window) right_frame = ttk.Frame(paned_window) paned_window.add(left_frame) paned_window.add(right_frame) notebook = ttk.Notebook(left_frame) notebook.grid(row=0, column=0, sticky='nsew', padx=padx, pady=pady) tree_frame = ttk.Frame(notebook) notebook.add(tree_frame, text=_('Tree View')) search_frame = ttk.Frame(notebook) notebook.add(search_frame, text=_('Search')) # Tree font = app.getFont("default") self.tree = self.Tree_Class(self, tree_frame, key=key, default=kw.default, font=font, width=w1) self.tree.frame.pack(padx=padx, pady=pady, expand=True, fill='both') # Search searchText = tkinter.StringVar() self.list_searchlabel = tkinter.Label(search_frame, text="Search:", justify='left', anchor='w') self.list_searchlabel.pack(side="top", fill='both', ipadx=1) self.list_searchtext = tkinter.Entry(search_frame, textvariable=searchText) self.list_searchtext.pack(side="top", fill='both', padx=padx, pady=pady, ipadx=1) searchText.trace('w', self.performSearch) self.list_scrollbar = tkinter.Scrollbar(search_frame) self.list_scrollbar.pack(side="right", fill='both') self.createBitmaps(search_frame, kw) self.list = tkinter.Listbox(search_frame, exportselection=False) self.list.pack(padx=padx, pady=pady, expand=True, side='left', fill='both', ipadx=1) self.updateSearchList("") bind(self.list, '<<ListboxSelect>>', self.selectSearchResult) bind(self.list, '<FocusOut>', lambda e: self.list.selection_clear(0, 'end')) self.list.config(yscrollcommand=self.list_scrollbar.set) self.list_scrollbar.config(command=self.list.yview) if USE_PIL: # var = tkinter.DoubleVar() var.set(app.opt.scale_x) self.scale_x = PysolScale(left_frame, label=_('Scale X:'), from_=0.5, to=4.0, resolution=0.1, orient='horizontal', variable=var, value=app.opt.scale_x, command=self._updateScale) self.scale_x.grid(row=1, column=0, sticky='ew', padx=padx, pady=pady) # var = tkinter.DoubleVar() var.set(app.opt.scale_y) self.scale_y = PysolScale(left_frame, label=_('Scale Y:'), from_=0.5, to=4.0, resolution=0.1, orient='horizontal', variable=var, value=app.opt.scale_y, command=self._updateScale) self.scale_y.grid(row=2, column=0, sticky='ew', padx=padx, pady=pady) # # sliders at new position cs = self.manager.get(self.tree.selection_key) var = tkinter.IntVar() self.x_offset = PysolScale(left_frame, label=_('X offset:'), from_=5, to=100, resolution=1, orient='horizontal', variable=var, value=cs.CARD_XOFFSET) self.x_offset.grid(row=3, column=0, sticky='ew', padx=padx, pady=pady) var = tkinter.IntVar() self.y_offset = PysolScale(left_frame, label=_('Y offset:'), from_=5, to=100, resolution=1, orient='horizontal', variable=var, value=cs.CARD_YOFFSET) self.y_offset.grid(row=4, column=0, sticky='ew', padx=padx, pady=pady) self.auto_scale = tkinter.BooleanVar() self.auto_scale.set(app.opt.auto_scale) check = ttk.Checkbutton(left_frame, text=_('Auto scaling'), variable=self.auto_scale, takefocus=False, command=self._updateAutoScale) check.grid(row=5, column=0, columnspan=2, sticky='ew', padx=padx, pady=pady) # self.preserve_aspect = tkinter.BooleanVar() self.preserve_aspect.set(app.opt.preserve_aspect_ratio) self.aspect_check = ttk.Checkbutton( left_frame, text=_('Preserve aspect ratio'), variable=self.preserve_aspect, takefocus=False, # command=self._updateScale ) self.aspect_check.grid(row=6, column=0, sticky='ew', padx=padx, pady=pady) self._updateAutoScale() # left_frame.rowconfigure(0, weight=1) left_frame.columnconfigure(0, weight=1) # self.preview = MfxScrolledCanvas(right_frame) self.preview.setTile(app, app.tabletile_index, force=True) self.preview.pack(fill='both', expand=True, padx=padx, pady=pady) self.preview.canvas.preview = 1 # create a preview of the current state self.preview_key = -1 self.preview_images = [] self.scale_images = [] self.updatePreview(key) # focus = self.createButtons(bottom_frame, kw) focus = self.tree.frame self.mainloop(focus, kw.timeout, geometry=geometry)
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 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 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
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 cond = parent.winfo_screenwidth() < 800 or \ parent.winfo_screenheight() < 600 if cond: 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 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: def cb(event=None, w=focus): return w.event_generate('<<Invoke>>') bind(self.top, "<Return>", cb) bind(self.top, "<KP_Enter>", cb) # right justify frame.columnconfigure(sep_column, weight=1) return focus
def __init__(self, parent, title, app, manager, key=None, **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) # if key is None: key = manager.getSelected() self.app = app self.manager = manager self.key = key self.table_color = app.opt.colors['table'] if self.TreeDataHolder_Class.data is None: self.TreeDataHolder_Class.data = self.TreeData_Class(manager, key) # sw = self.top.winfo_screenwidth() sh = self.top.winfo_screenheight() h = int(sh * .8) w = int(sw * .8) w1 = int(min(275, sw / 2.5)) geometry = ("%dx%d+%d+%d" % (w, h, (sw - w) / 2, (sh - h) / 2)) self.top.wm_minsize(400, 200) padx, pady = 4, 4 paned_window = ttk.PanedWindow(top_frame, orient='horizontal') paned_window.pack(expand=True, fill='both', padx=8, pady=8) left_frame = ttk.Frame(paned_window) right_frame = ttk.Frame(paned_window) paned_window.add(left_frame) paned_window.add(right_frame) notebook = ttk.Notebook(left_frame) notebook.pack(expand=True, fill='both') tree_frame = ttk.Frame(notebook) notebook.add(tree_frame, text=_('Tree View')) search_frame = ttk.Frame(notebook) notebook.add(search_frame, text=_('Search')) font = app.getFont("default") padx, pady = 4, 4 self.tree = self.Tree_Class(self, tree_frame, key=key, default=kw.default, font=font, width=w1) self.tree.frame.pack(padx=padx, pady=pady, expand=True, fill='both') # Search searchText = tkinter.StringVar() self.list_searchlabel = tkinter.Label(search_frame, text="Search:", justify='left', anchor='w') self.list_searchlabel.pack(side="top", fill='both', ipadx=1) self.list_searchtext = tkinter.Entry(search_frame, textvariable=searchText) self.list_searchtext.pack(side="top", fill='both', padx=padx, pady=pady, ipadx=1) searchText.trace('w', self.performSearch) self.list_scrollbar = tkinter.Scrollbar(search_frame) self.list_scrollbar.pack(side="right", fill='both') self.createBitmaps(search_frame, kw) self.list = tkinter.Listbox(search_frame, exportselection=False) self.list.pack(padx=padx, pady=pady, expand=True, side='left', fill='both', ipadx=1) self.updateSearchList("") bind(self.list, '<<ListboxSelect>>', self.selectSearchResult) bind(self.list, '<FocusOut>', lambda e: self.list.selection_clear(0, 'end')) self.list.config(yscrollcommand=self.list_scrollbar.set) self.list_scrollbar.config(command=self.list.yview) self.preview = MfxScrolledCanvas(right_frame, hbar=0, vbar=0) self.preview.pack(side="right", fill='both', expand=True, padx=padx, pady=pady) self.preview.canvas.preview = 1 # create a preview of the current state self.preview_key = -1 self.updatePreview(key) # focus = self.createButtons(bottom_frame, kw) focus = self.tree.frame self.mainloop(focus, kw.timeout, geometry=geometry)
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(tkinter_font.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): 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: cb = (lambda event=None, self=self, button=kw.default: self.mDone(button)) bind(self.top, "<Return>", cb) bind(self.top, "<KP_Enter>", cb) frame.columnconfigure(0, weight=1) frame.columnconfigure(99, weight=1) return focus
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.slant_var = tkinter.BooleanVar() self.size_var = tkinter.IntVar() frame = tkinter.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 = tkinter.Entry(frame, bg='white') 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 = tkinter.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 = tkinter.Checkbutton(frame, anchor='w', text=_('Bold'), command=self.fontupdate, variable=self.weight_var) cb1.grid(row=2, column=0, columnspan=2, sticky='we') cb2 = tkinter.Checkbutton(frame, anchor='w', text=_('Italic'), command=self.fontupdate, variable=self.slant_var) cb2.grid(row=3, column=0, columnspan=2, sticky='we') sc = tkinter.Scale(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') # self.size_var.set(self.font_size) self.weight_var.set(self.font_weight == 'bold') self.slant_var.set(self.font_slant == 'italic') font_families = list(tkinter_font.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 __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, 325 cond = parent.winfo_screenwidth() < 800 or \ parent.winfo_screenheight() < 600 if cond: 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=5) 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', pady=5) 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) label_frame = ttk.LabelFrame(right_frame, text=_('Date format')) label_frame.pack(side='top', fill='x', pady=5) self.date_format = tkinter.StringVar() self.date_format.set(self.app.opt.date_format) b = ttk.Radiobutton(label_frame, text=_('MM-DD'), command=self.updateDateFormat, variable=self.date_format, value='%m-%d') b.pack(fill='x', expand=True, padx=3, pady=1) b = ttk.Radiobutton(label_frame, text=_('DD-MM'), command=self.updateDateFormat, variable=self.date_format, value='%d-%m') b.pack(fill='x', expand=True, padx=3, pady=1) # self.createGraph() bind(canvas, '<Map>', self.createGraph)
def __init__(self, parent, title, app, gameid, bookmark=None, **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) # self.app = app self.gameid = gameid self.bookmark = bookmark self.random = None if self.TreeDataHolder_Class.data is None: self.TreeDataHolder_Class.data = self.TreeData_Class(app) # sw = self.top.winfo_screenwidth() sh = self.top.winfo_screenheight() h = int(sh * .8) w = int(sw * .8) w1 = int(min(275, sw / 2.5)) geometry = ("%dx%d+%d+%d" % (w, h, (sw - w) / 2, (sh - h) / 2)) self.top.wm_minsize(400, 200) # print sw, w1, w2 # w2 = max(200, min(w2, 10 + 12 * (app.subsampled_images.CARDW + 10))) # print sw, w1, w2 # padx, pady = kw.padx, kw.pady # padx, pady = kw.padx/2, kw.pady/2 padx, pady = 4, 4 # PanedWindow paned_window = ttk.PanedWindow(top_frame, orient='horizontal') paned_window.pack(expand=True, fill='both', padx=8, pady=8) left_frame = ttk.Frame(paned_window) right_frame = ttk.Frame(paned_window) paned_window.add(left_frame) paned_window.add(right_frame) notebook = ttk.Notebook(left_frame) notebook.pack(expand=True, fill='both') tree_frame = ttk.Frame(notebook) notebook.add(tree_frame, text=_('Tree View')) search_frame = ttk.Frame(notebook) notebook.add(search_frame, text=_('Search')) # Tree font = app.getFont("default") self.tree = self.Tree_Class(self, tree_frame, key=gameid, default=kw.default, font=font, width=w1) self.tree.frame.pack(padx=padx, pady=pady, expand=True, fill='both') # Search searchText = tkinter.StringVar() self.list_searchlabel = tkinter.Label(search_frame, text="Search:", justify='left', anchor='w') self.list_searchlabel.pack(side="top", fill='both', ipadx=1) self.list_searchtext = tkinter.Entry(search_frame, textvariable=searchText) self.list_searchtext.pack(side="top", fill='both', padx=padx, pady=pady, ipadx=1) searchText.trace('w', self.performSearch) self.list_scrollbar = tkinter.Scrollbar(search_frame) self.list_scrollbar.pack(side="right", fill='both') self.createBitmaps(search_frame, kw) self.list = tkinter.Listbox(search_frame, exportselection=False) self.list.pack(padx=padx, pady=pady, expand=True, side='left', fill='both', ipadx=1) self.updateSearchList("") bind(self.list, '<<ListboxSelect>>', self.selectSearchResult) bind(self.list, '<FocusOut>', lambda e: self.list.selection_clear(0, 'end')) self.list.config(yscrollcommand=self.list_scrollbar.set) self.list_scrollbar.config(command=self.list.yview) # LabelFrame info_frame = ttk.LabelFrame(right_frame, text=_('About game')) info_frame.grid(row=0, column=0, padx=padx, pady=pady, ipadx=4, ipady=4, sticky='nws') stats_frame = ttk.LabelFrame(right_frame, text=_('Statistics')) stats_frame.grid(row=0, column=1, padx=padx, pady=pady, ipadx=4, ipady=4, sticky='nws') # Info self.info_labels = {} for n, t, f, row in ( ('name', _('Name:'), info_frame, 0), ('altnames', _('Alternate names:'), info_frame, 1), ('category', _('Category:'), info_frame, 2), ('type', _('Type:'), info_frame, 3), ('skill_level', _('Skill level:'), info_frame, 4), ('decks', _('Decks:'), info_frame, 5), ('redeals', _('Redeals:'), info_frame, 6), # ('played', _('Played:'), stats_frame, 0), ('won', _('Won:'), stats_frame, 1), ('lost', _('Lost:'), stats_frame, 2), ('time', _('Playing time:'), stats_frame, 3), ('moves', _('Moves:'), stats_frame, 4), ('percent', _('% won:'), stats_frame, 5), ): title_label = ttk.Label(f, text=t, justify='left', anchor='w') title_label.grid(row=row, column=0, sticky='nw', padx=4) text_label = ttk.Label(f, justify='left', anchor='w') text_label.grid(row=row, column=1, sticky='nw', padx=4) self.info_labels[n] = (title_label, text_label) # info_frame.columnconfigure(1, weight=1) info_frame.rowconfigure(6, weight=1) stats_frame.rowconfigure(6, weight=1) # Canvas self.preview = MfxScrolledCanvas(right_frame) self.preview.setTile(app, app.tabletile_index, force=True) self.preview.grid(row=1, column=0, columnspan=3, padx=padx, pady=pady, sticky='nsew') right_frame.columnconfigure(1, weight=1) right_frame.rowconfigure(1, weight=1) # focus = self.createButtons(bottom_frame, kw) # set the scale factor self.preview.canvas.preview = 2 # create a preview of the current game self.preview_key = -1 self.preview_game = None self.preview_app = None self.updatePreview(gameid, animations=0) # focus = self.tree.frame self.mainloop(focus, kw.timeout, geometry=geometry)