From 72a2591ec1800d0bd2c8e6eb4226e6f73a568425 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Mon, 22 May 2017 18:38:20 +0300 Subject: [PATCH] Preemptive tkinter conversion to py2/py3. Using the six module. Did it before 2to3 reports it. --- pysollib/pysolgtk/findcarddialog.py | 2 +- pysollib/pysolgtk/gameinfodialog.py | 2 +- pysollib/pysolgtk/tkcanvas.py | 4 +- pysollib/pysolgtk/tkhtml.py | 2 +- pysollib/tile/fontsdialog.py | 12 ++-- pysollib/tile/playeroptionsdialog.py | 8 +-- pysollib/tile/progressbar.py | 4 +- pysollib/tile/selectcardset.py | 16 ++--- pysollib/tile/selecttile.py | 4 +- pysollib/tile/soundoptionsdialog.py | 50 ++++++------- pysollib/tile/statusbar.py | 4 +- pysollib/tile/timeoutsdialog.py | 14 ++-- pysollib/tile/tkhtml.py | 6 +- pysollib/tile/tkstats.py | 16 ++--- pysollib/tile/tktree.py | 8 +-- pysollib/tile/tkwidget.py | 18 ++--- pysollib/tile/toolbar.py | 6 +- pysollib/tile/ttk.py | 46 ++++++------ pysollib/tile/wizarddialog.py | 12 ++-- pysollib/tk/fontsdialog.py | 32 ++++----- pysollib/tk/playeroptionsdialog.py | 28 ++++---- pysollib/tk/progressbar.py | 18 ++--- pysollib/tk/selectcardset.py | 38 +++++----- pysollib/tk/selectgame.py | 16 ++--- pysollib/tk/selecttile.py | 6 +- pysollib/tk/solverdialog.py | 10 +-- pysollib/tk/soundoptionsdialog.py | 68 +++++++++--------- pysollib/tk/statusbar.py | 8 +-- pysollib/tk/tabpage.py | 49 +++++++------ pysollib/tk/timeoutsdialog.py | 22 +++--- pysollib/tk/tkhtml.py | 18 ++--- pysollib/tk/tkstats.py | 80 ++++++++++----------- pysollib/tk/tktree.py | 8 +-- pysollib/tk/tkwidget.py | 48 ++++++------- pysollib/tk/toolbar.py | 22 +++--- pysollib/tk/wizarddialog.py | 28 ++++---- pysollib/ui/tktile/colorsdialog.py | 20 +++--- pysollib/ui/tktile/edittextdialog.py | 4 +- pysollib/ui/tktile/findcarddialog.py | 8 +-- pysollib/ui/tktile/menubar.py | 98 +++++++++++++------------- pysollib/ui/tktile/solverdialog.py | 8 +-- pysollib/ui/tktile/tkcanvas.py | 14 ++-- pysollib/ui/tktile/tkconst.py | 32 ++++----- pysollib/ui/tktile/tkhtml.py | 6 +- pysollib/ui/tktile/tkutil.py | 24 +++---- pysollib/ui/tktile/tkwrap.py | 14 ++-- scripts/cardset_viewer.py | 101 +++++++++++++-------------- setup_osx.py | 6 +- 48 files changed, 533 insertions(+), 535 deletions(-) diff --git a/pysollib/pysolgtk/findcarddialog.py b/pysollib/pysolgtk/findcarddialog.py index b1c87809..5027ff30 100644 --- a/pysollib/pysolgtk/findcarddialog.py +++ b/pysollib/pysolgtk/findcarddialog.py @@ -28,7 +28,7 @@ __all__ = ['create_find_card_dialog', # imports # import os -# import Tkinter +# from six.moves import tkinter # import traceback # # PySol imports diff --git a/pysollib/pysolgtk/gameinfodialog.py b/pysollib/pysolgtk/gameinfodialog.py index 78a55c0a..296f2b61 100644 --- a/pysollib/pysolgtk/gameinfodialog.py +++ b/pysollib/pysolgtk/gameinfodialog.py @@ -26,7 +26,7 @@ __all__ = ['GameInfoDialog'] # # imports # import os, sys -# import Tkinter +# from six.moves import tkinter # # PySol imports # from pysollib.mfxutil import KwStruct diff --git a/pysollib/pysolgtk/tkcanvas.py b/pysollib/pysolgtk/tkcanvas.py index 2620d8e5..3205dc8f 100644 --- a/pysollib/pysolgtk/tkcanvas.py +++ b/pysollib/pysolgtk/tkcanvas.py @@ -23,7 +23,7 @@ # -# This files tries to wrap a limited subset of the Tkinter canvas +# This files tries to wrap a limited subset of the tkinter canvas # into GTK / Gnome. # @@ -282,7 +282,7 @@ class MfxCanvasText(_CanvasItem): class MfxCanvas(gnomecanvas.Canvas): def __init__(self, top, bg=None, highlightthickness=0): self.preview = 0 - # Tkinter compat + # tkinter compat self.items = {} self._all_items = [] self._text_items = [] diff --git a/pysollib/pysolgtk/tkhtml.py b/pysollib/pysolgtk/tkhtml.py index 7a0feaf1..6a27f805 100644 --- a/pysollib/pysolgtk/tkhtml.py +++ b/pysollib/pysolgtk/tkhtml.py @@ -425,7 +425,7 @@ class HTMLViewer: def display(self, url, add=1, relpath=1, position=(0, 0)): # print 'display:', url, position # for some reason we have to stop the PySol demo - # (is this a multithread problem with Tkinter ?) + # (is this a multithread problem with tkinter ?) try: # self.app.game.stopDemo() # self.app.game._cancelDrag() diff --git a/pysollib/tile/fontsdialog.py b/pysollib/tile/fontsdialog.py index 2cc82b20..2064c01c 100644 --- a/pysollib/tile/fontsdialog.py +++ b/pysollib/tile/fontsdialog.py @@ -24,7 +24,7 @@ __all__ = ['FontsDialog'] # imports -import Tkinter +from six.moves import tkinter import ttk import tkFont @@ -74,12 +74,12 @@ class FontChooserDialog(MfxDialog): else: raise ValueError('invalid font style: '+init_font[3]) - # self.family_var = Tkinter.StringVar() - self.weight_var = Tkinter.BooleanVar() + # 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 = tkinter.BooleanVar() self.slant_var.set(self.font_slant == 'italic') - self.size_var = Tkinter.IntVar() + self.size_var = tkinter.IntVar() self.size_var.set(self.font_size) # frame = ttk.Frame(top_frame) @@ -89,7 +89,7 @@ class FontChooserDialog(MfxDialog): 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) + 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) diff --git a/pysollib/tile/playeroptionsdialog.py b/pysollib/tile/playeroptionsdialog.py index cd4b5463..9a1d46e7 100644 --- a/pysollib/tile/playeroptionsdialog.py +++ b/pysollib/tile/playeroptionsdialog.py @@ -24,7 +24,7 @@ __all__ = ['PlayerOptionsDialog'] # imports -import Tkinter +from six.moves import tkinter import ttk # PySol imports @@ -47,11 +47,11 @@ class PlayerOptionsDialog(MfxDialog): self.createBitmaps(top_frame, kw) self.app = app # - self.update_stats_var = Tkinter.BooleanVar() + self.update_stats_var = tkinter.BooleanVar() self.update_stats_var.set(app.opt.update_player_stats != 0) - self.confirm_var = Tkinter.BooleanVar() + self.confirm_var = tkinter.BooleanVar() self.confirm_var.set(app.opt.confirm != 0) - self.win_animation_var = Tkinter.BooleanVar() + self.win_animation_var = tkinter.BooleanVar() self.win_animation_var.set(app.opt.win_animation != 0) # frame = ttk.Frame(top_frame) diff --git a/pysollib/tile/progressbar.py b/pysollib/tile/progressbar.py index 7fe1a963..8fd33850 100644 --- a/pysollib/tile/progressbar.py +++ b/pysollib/tile/progressbar.py @@ -24,7 +24,7 @@ __all__ = ['PysolProgressBar'] # imports -import Tkinter +from six.moves import tkinter import ttk # Toolkit imports @@ -122,7 +122,7 @@ class TestProgressBar: def progressbar_main(args): from pysollib.ui.tktile.tkutil import wm_withdraw - tk = Tkinter.Tk() + tk = tkinter.Tk() wm_withdraw(tk) TestProgressBar(tk) tk.mainloop() diff --git a/pysollib/tile/selectcardset.py b/pysollib/tile/selectcardset.py index c931d304..9076b7f2 100644 --- a/pysollib/tile/selectcardset.py +++ b/pysollib/tile/selectcardset.py @@ -25,7 +25,7 @@ __all__ = ['SelectCardsetDialogWithPreview'] # imports import os -import Tkinter +from six.moves import tkinter import ttk # PySol imports @@ -245,7 +245,7 @@ class SelectCardsetDialogWithPreview(MfxDialog): padx=padx, pady=pady) if USE_PIL: # - var = Tkinter.DoubleVar() + var = tkinter.DoubleVar() var.set(app.opt.scale_x) self.scale_x = PysolScale( left_frame, label=_('Scale X:'), @@ -256,7 +256,7 @@ class SelectCardsetDialogWithPreview(MfxDialog): self.scale_x.grid( row=1, column=0, sticky='ew', padx=padx, pady=pady) # - var = Tkinter.DoubleVar() + var = tkinter.DoubleVar() var.set(app.opt.scale_y) self.scale_y = PysolScale( left_frame, label=_('Scale Y:'), @@ -267,7 +267,7 @@ class SelectCardsetDialogWithPreview(MfxDialog): self.scale_y.grid( row=2, column=0, sticky='ew', padx=padx, pady=pady) # - self.auto_scale = Tkinter.BooleanVar() + self.auto_scale = tkinter.BooleanVar() self.auto_scale.set(app.opt.auto_scale) check = ttk.Checkbutton( left_frame, text=_('Auto scaling'), @@ -278,7 +278,7 @@ class SelectCardsetDialogWithPreview(MfxDialog): check.grid(row=3, column=0, columnspan=2, sticky='ew', padx=padx, pady=pady) # - self.preserve_aspect = Tkinter.BooleanVar() + 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'), @@ -492,7 +492,7 @@ class CardsetInfoDialog(MfxDialog): settings_frame.grid(row=row, column=0, columnspan=2, sticky='ew', padx=0, pady=5, ipadx=5, ipady=5) row += 1 - var = Tkinter.IntVar() + var = tkinter.IntVar() self.x_offset = PysolScale( settings_frame, label=_('X offset:'), from_=5, to=40, resolution=1, @@ -502,7 +502,7 @@ class CardsetInfoDialog(MfxDialog): ) self.x_offset.grid(row=0, column=0, sticky='ew', padx=padx, pady=pady) - var = Tkinter.IntVar() + var = tkinter.IntVar() self.y_offset = PysolScale( settings_frame, label=_('Y offset:'), from_=5, to=40, resolution=1, @@ -516,7 +516,7 @@ class CardsetInfoDialog(MfxDialog): # bg = top_frame["bg"] bg = 'white' - text_w = Tkinter.Text(frame, bd=1, relief="sunken", wrap="word", + text_w = tkinter.Text(frame, bd=1, relief="sunken", wrap="word", padx=4, width=64, height=16, bg=bg) text_w.grid(row=row, column=0, sticky='nsew') sb = ttk.Scrollbar(frame) diff --git a/pysollib/tile/selecttile.py b/pysollib/tile/selecttile.py index a621bbde..1b4ac550 100644 --- a/pysollib/tile/selecttile.py +++ b/pysollib/tile/selecttile.py @@ -24,7 +24,7 @@ # imports import sys -import Tkinter +from six.moves import tkinter import ttk import tkColorChooser @@ -178,7 +178,7 @@ class SelectTileDialogWithPreview(MfxDialog): c = tkColorChooser.askcolor(master=self.top, initialcolor=self.table_color, title=_("Select table color")) - except Tkinter.TclError: + except tkinter.TclError: pass else: if c and c[1]: diff --git a/pysollib/tile/soundoptionsdialog.py b/pysollib/tile/soundoptionsdialog.py index be354c19..2cc94148 100644 --- a/pysollib/tile/soundoptionsdialog.py +++ b/pysollib/tile/soundoptionsdialog.py @@ -25,7 +25,7 @@ __all__ = ['SoundOptionsDialog'] # imports import os -import Tkinter +from six.moves import tkinter import ttk # PySol imports @@ -54,42 +54,42 @@ class SoundOptionsDialog(MfxDialog): self.createBitmaps(top_frame, kw) # self.saved_opt = app.opt.copy() - self.sound = Tkinter.BooleanVar() + self.sound = tkinter.BooleanVar() self.sound.set(app.opt.sound != 0) - self.sound_mode = Tkinter.BooleanVar() + self.sound_mode = tkinter.BooleanVar() self.sound_mode.set(app.opt.sound_mode != 0) - self.sample_volume = Tkinter.IntVar() + self.sample_volume = tkinter.IntVar() self.sample_volume.set(app.opt.sound_sample_volume) - self.music_volume = Tkinter.IntVar() + self.music_volume = tkinter.IntVar() self.music_volume.set(app.opt.sound_music_volume) self.samples = [ - ('areyousure', _('Are You Sure'), Tkinter.BooleanVar()), + ('areyousure', _('Are You Sure'), tkinter.BooleanVar()), - ('deal', _('Deal'), Tkinter.BooleanVar()), - ('dealwaste', _('Deal waste'), Tkinter.BooleanVar()), + ('deal', _('Deal'), tkinter.BooleanVar()), + ('dealwaste', _('Deal waste'), tkinter.BooleanVar()), - ('turnwaste', _('Turn waste'), Tkinter.BooleanVar()), - ('startdrag', _('Start drag'), Tkinter.BooleanVar()), + ('turnwaste', _('Turn waste'), tkinter.BooleanVar()), + ('startdrag', _('Start drag'), tkinter.BooleanVar()), - ('drop', _('Drop'), Tkinter.BooleanVar()), - ('droppair', _('Drop pair'), Tkinter.BooleanVar()), - ('autodrop', _('Auto drop'), Tkinter.BooleanVar()), + ('drop', _('Drop'), tkinter.BooleanVar()), + ('droppair', _('Drop pair'), tkinter.BooleanVar()), + ('autodrop', _('Auto drop'), tkinter.BooleanVar()), - ('flip', _('Flip'), Tkinter.BooleanVar()), - ('autoflip', _('Auto flip'), Tkinter.BooleanVar()), - ('move', _('Move'), Tkinter.BooleanVar()), - ('nomove', _('No move'), Tkinter.BooleanVar()), + ('flip', _('Flip'), tkinter.BooleanVar()), + ('autoflip', _('Auto flip'), tkinter.BooleanVar()), + ('move', _('Move'), tkinter.BooleanVar()), + ('nomove', _('No move'), tkinter.BooleanVar()), - ('undo', _('Undo'), Tkinter.BooleanVar()), - ('redo', _('Redo'), Tkinter.BooleanVar()), + ('undo', _('Undo'), tkinter.BooleanVar()), + ('redo', _('Redo'), tkinter.BooleanVar()), - ('autopilotlost', _('Autopilot lost'), Tkinter.BooleanVar()), - ('autopilotwon', _('Autopilot won'), Tkinter.BooleanVar()), + ('autopilotlost', _('Autopilot lost'), tkinter.BooleanVar()), + ('autopilotwon', _('Autopilot won'), tkinter.BooleanVar()), - ('gamefinished', _('Game finished'), Tkinter.BooleanVar()), - ('gamelost', _('Game lost'), Tkinter.BooleanVar()), - ('gamewon', _('Game won'), Tkinter.BooleanVar()), - ('gameperfect', _('Perfect game'), Tkinter.BooleanVar()), + ('gamefinished', _('Game finished'), tkinter.BooleanVar()), + ('gamelost', _('Game lost'), tkinter.BooleanVar()), + ('gamewon', _('Game won'), tkinter.BooleanVar()), + ('gameperfect', _('Perfect game'), tkinter.BooleanVar()), ] # diff --git a/pysollib/tile/statusbar.py b/pysollib/tile/statusbar.py index 3daa0cb8..6195be6c 100644 --- a/pysollib/tile/statusbar.py +++ b/pysollib/tile/statusbar.py @@ -27,7 +27,7 @@ __all__ = ['PysolStatusbar', # imports import os import sys -import Tkinter +from six.moves import tkinter import ttk # PySol imports @@ -199,7 +199,7 @@ class TestStatusbar(PysolStatusbar): def statusbar_main(args): - tk = Tkinter.Tk() + tk = tkinter.Tk() TestStatusbar(tk, args) tk.mainloop() return 0 diff --git a/pysollib/tile/timeoutsdialog.py b/pysollib/tile/timeoutsdialog.py index 8f696986..164fb5fa 100644 --- a/pysollib/tile/timeoutsdialog.py +++ b/pysollib/tile/timeoutsdialog.py @@ -24,7 +24,7 @@ __all__ = ['TimeoutsDialog'] # imports -import Tkinter +from six.moves import tkinter import ttk # PySol imports @@ -50,17 +50,17 @@ class TimeoutsDialog(MfxDialog): frame.pack(expand=True, fill='both', padx=5, pady=10) frame.columnconfigure(0, weight=1) - self.demo_sleep_var = Tkinter.DoubleVar() + self.demo_sleep_var = tkinter.DoubleVar() self.demo_sleep_var.set(app.opt.timeouts['demo']) - self.hint_sleep_var = Tkinter.DoubleVar() + self.hint_sleep_var = tkinter.DoubleVar() self.hint_sleep_var.set(app.opt.timeouts['hint']) - self.raise_card_sleep_var = Tkinter.DoubleVar() + self.raise_card_sleep_var = tkinter.DoubleVar() self.raise_card_sleep_var.set(app.opt.timeouts['raise_card']) - self.highlight_piles_sleep_var = Tkinter.DoubleVar() + self.highlight_piles_sleep_var = tkinter.DoubleVar() self.highlight_piles_sleep_var.set(app.opt.timeouts['highlight_piles']) - self.highlight_cards_sleep_var = Tkinter.DoubleVar() + self.highlight_cards_sleep_var = tkinter.DoubleVar() self.highlight_cards_sleep_var.set(app.opt.timeouts['highlight_cards']) - self.highlight_samerank_sleep_var = Tkinter.DoubleVar() + self.highlight_samerank_sleep_var = tkinter.DoubleVar() self.highlight_samerank_sleep_var.set( app.opt.timeouts['highlight_samerank']) # diff --git a/pysollib/tile/tkhtml.py b/pysollib/tile/tkhtml.py index 5ec7fb73..4d820d8e 100644 --- a/pysollib/tile/tkhtml.py +++ b/pysollib/tile/tkhtml.py @@ -26,7 +26,7 @@ __all__ = ['HTMLViewer'] # imports import os import sys -import Tkinter +from six.moves import tkinter import ttk # PySol imports @@ -102,7 +102,7 @@ class HTMLViewer(Base_HTMLViewer): sticky='nsew', padx=1, pady=1) vbar = ttk.Scrollbar(text_frame) vbar.pack(side='right', fill='y') - self.text = Tkinter.Text(text_frame, + self.text = tkinter.Text(text_frame, fg='black', bg='white', bd=1, relief='sunken', cursor=self.defcursor, @@ -134,7 +134,7 @@ def tkhtml_main(args): url = args[1] except: url = os.path.join(os.pardir, os.pardir, "data", "html", "index.html") - top = Tkinter.Tk() + top = tkinter.Tk() top.tk.call("package", "require", "tile") top.wm_minsize(400, 200) viewer = HTMLViewer(top) diff --git a/pysollib/tile/tkstats.py b/pysollib/tile/tkstats.py index 4b555c80..75c1d001 100644 --- a/pysollib/tile/tkstats.py +++ b/pysollib/tile/tkstats.py @@ -33,7 +33,7 @@ __all__ = ['SingleGame_StatsDialog', # imports import os import time -import Tkinter +from six.moves import tkinter import ttk import tkFont @@ -231,7 +231,7 @@ class SingleGameFrame(ttk.Frame): self.fg = fg # w, h = self.tab_x[-1], max(self.tab_y[-1], self.oval_height+40) - c = Tkinter.Canvas(frame, width=w, height=h, + c = tkinter.Canvas(frame, width=w, height=h, bg=bg, highlightthickness=0) c.pack(fill='both', expand=True) self.canvas = c @@ -880,7 +880,7 @@ class ProgressionFrame(ttk.Frame): self.won_color = '#00dc28' self.percent_color = 'blue' # create canvas - self.canvas = canvas = Tkinter.Canvas(frame, bg='#dfe8ff', bd=0, + self.canvas = canvas = tkinter.Canvas(frame, bg='#dfe8ff', bd=0, highlightthickness=1, highlightbackground='black', width=self.canvas_width, @@ -890,7 +890,7 @@ class ProgressionFrame(ttk.Frame): # right frame right_frame = ttk.Frame(frame) right_frame.pack(side='left', fill='x', padx=5) - self.all_games_variable = var = Tkinter.StringVar() + self.all_games_variable = var = tkinter.StringVar() var.set('all') b = ttk.Radiobutton(right_frame, text=_('All games'), variable=var, value='all', @@ -902,7 +902,7 @@ class ProgressionFrame(ttk.Frame): 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() + self.variable = var = tkinter.StringVar() var.set('week') for v, t in ( ('week', _('Last 7 days')), @@ -915,19 +915,19 @@ class ProgressionFrame(ttk.Frame): 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 = 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 = 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 = tkinter.BooleanVar() self.percent_graph_var.set(True) b = ttk.Checkbutton(label_frame, text=_('% won'), command=self.updateGraph, diff --git a/pysollib/tile/tktree.py b/pysollib/tile/tktree.py index 81ec2e7b..30c01250 100644 --- a/pysollib/tile/tktree.py +++ b/pysollib/tile/tktree.py @@ -23,7 +23,7 @@ # imports import os -import Tkinter +from six.moves import tkinter # Toolkit imports from pysollib.ui.tktile.tkutil import bind @@ -106,7 +106,7 @@ class MfxTreeBaseNode: try: # _tkinter.TclError: unknown option "-fill" ??? canvas.itemconfig(self.textrect_id, fill=bg) - except Tkinter.TclError: + except tkinter.TclError: pass elif self.selected: b = canvas.bbox(self.text_id) @@ -281,7 +281,7 @@ class MfxTreeInCanvas(MfxScrolledCanvas): # draw try: lx, ly, nx, ny = node.draw(nx, ny, None, None) - except Tkinter.TclError: + except tkinter.TclError: # FIXME: Tk bug ??? raise # set scroll region @@ -405,7 +405,7 @@ class DirectoryBrowser(MfxTreeInCanvas): if __name__ == "__main__": - tk = Tkinter.Tk() + tk = tkinter.Tk() if os.name == "nt": app = DirectoryBrowser(tk, ("c:\\", "c:\\windows")) else: diff --git a/pysollib/tile/tkwidget.py b/pysollib/tile/tkwidget.py index 7de23173..8a8c8df1 100644 --- a/pysollib/tile/tkwidget.py +++ b/pysollib/tile/tkwidget.py @@ -36,7 +36,7 @@ import sys import os import time import locale -import Tkinter +from six.moves import tkinter import ttk import tkFont import traceback @@ -89,7 +89,7 @@ class MfxDialog: # ex. _ToplevelDialog setTransient(self.top, self.parent) try: self.top.grab_set() - except Tkinter.TclError: + except tkinter.TclError: if traceback: traceback.print_exc() pass @@ -460,11 +460,11 @@ class MfxTooltip: y = self.widget.winfo_rooty() + self.widget.winfo_height() x += self.xoffset y += self.yoffset - self.tooltip = Tkinter.Toplevel() + self.tooltip = tkinter.Toplevel() self.tooltip.wm_iconify() self.tooltip.wm_overrideredirect(1) self.tooltip.wm_protocol("WM_DELETE_WINDOW", self.destroy) - self.label = Tkinter.Label(self.tooltip, text=self.text, + self.label = tkinter.Label(self.tooltip, text=self.text, relief=self.relief, justify=self.justify, fg=self.fg, bg=self.bg, bd=1, takefocus=0) self.label.pack(ipadx=1, ipady=1) @@ -573,7 +573,7 @@ class MfxScrolledCanvas: kw['bd'] = 0 relief = kw['relief'] del kw['relief'] - frame = Tkinter.Frame(self.frame, bd=bd, relief=relief) + frame = tkinter.Frame(self.frame, bd=bd, relief=relief) frame.grid(row=0, column=0, sticky="news") self.canvas = MfxCanvas(frame, **kw) self.canvas.pack(expand=True, fill='both') @@ -712,9 +712,9 @@ class StackDesc: text = stack.getHelp()+'\n'+stack.getBaseCard() text = text.strip() if text: - frame = Tkinter.Frame(self.canvas) + frame = tkinter.Frame(self.canvas) self.frame = frame - label = Tkinter.Message(frame, font=font, text=text, + label = tkinter.Message(frame, font=font, text=text, width=cardw-8, relief='solid', fg='#000000', bg='#ffffe0', bd=1) label.pack() @@ -839,11 +839,11 @@ class MyPysolScale: self.variable.set(v) -class TkinterScale(Tkinter.Scale): +class TkinterScale(tkinter.Scale): def __init__(self, parent, **kw): if 'value' in kw: del kw['value'] - Tkinter.Scale.__init__(self, parent, **kw) + tkinter.Scale.__init__(self, parent, **kw) PysolScale = MyPysolScale diff --git a/pysollib/tile/toolbar.py b/pysollib/tile/toolbar.py index 0a7e8763..5ca8f75f 100644 --- a/pysollib/tile/toolbar.py +++ b/pysollib/tile/toolbar.py @@ -25,7 +25,7 @@ __all__ = ['PysolToolbarTk'] # imports import os -import Tkinter +from six.moves import tkinter import ttk # PySol imports @@ -127,9 +127,9 @@ class ToolbarSeparator(ttk.Separator): self.grid_forget() -class ToolbarLabel(Tkinter.Message): +class ToolbarLabel(tkinter.Message): def __init__(self, parent, toolbar, toolbar_name, position, **kwargs): - Tkinter.Message.__init__(self, parent, **kwargs) + tkinter.Message.__init__(self, parent, **kwargs) self.toolbar = toolbar self.toolbar_name = toolbar_name self.position = position diff --git a/pysollib/tile/ttk.py b/pysollib/tile/ttk.py index 0ad84837..c78f7c46 100644 --- a/pysollib/tile/ttk.py +++ b/pysollib/tile/ttk.py @@ -25,16 +25,16 @@ __all__ = ["Button", "Checkbutton", "Combobox", "Entry", "Frame", "Label", # functions "tclobjs_to_py"] -import Tkinter +from six.moves import tkinter from pysollib.mygettext import _, n_ -_flatten = Tkinter._flatten +_flatten = tkinter._flatten # Verify if Tk is new enough to not need Tile checking -_REQUIRE_TILE = True if Tkinter.TkVersion < 8.5 else False +_REQUIRE_TILE = True if tkinter.TkVersion < 8.5 else False def _loadttk(loadtk): - # This extends the default Tkinter.Tk._loadtk method so we can be + # This extends the default tkinter.Tk._loadtk method so we can be # sure that ttk is available for use, or not. def _wrapper(self): loadtk(self) @@ -52,7 +52,7 @@ def _loadttk(loadtk): return _wrapper -Tkinter.Tk._loadtk = _loadttk(Tkinter.Tk._loadtk) +tkinter.Tk._loadtk = _loadttk(tkinter.Tk._loadtk) def _format_optdict(optdict, script=False, ignore=None): """Formats optdict to a tuple to pass it to tk.call. @@ -362,10 +362,10 @@ class Style(object): def __init__(self, master=None): if master is None: - if Tkinter._support_default_root: - master = Tkinter._default_root or Tkinter.Tk() + if tkinter._support_default_root: + master = tkinter._default_root or tkinter.Tk() else: - raise RuntimeError("No master specified and Tkinter is " + raise RuntimeError("No master specified and tkinter is " "configured to not support default master") self.master = master @@ -520,7 +520,7 @@ class Style(object): self.tk.call("ttk::setTheme", themename) -class Widget(Tkinter.Widget): +class Widget(tkinter.Widget): """Base class for Tk themed widgets.""" def __init__(self, master, widgetname, kw=None): @@ -543,7 +543,7 @@ class Widget(Tkinter.Widget): active, disabled, focus, pressed, selected, background, readonly, alternate, invalid """ - Tkinter.Widget.__init__(self, master, widgetname, kw=kw) + tkinter.Widget.__init__(self, master, widgetname, kw=kw) def identify(self, x, y): @@ -634,7 +634,7 @@ class Checkbutton(Widget): return self.tk.call(self._w, "invoke") -class Entry(Widget, Tkinter.Entry): +class Entry(Widget, tkinter.Entry): """Ttk Entry widget displays a one-line text string and allows that string to be edited by the user.""" @@ -784,7 +784,7 @@ class Labelframe(Widget): """ Widget.__init__(self, master, "ttk::labelframe", kw) -LabelFrame = Labelframe # Tkinter name compatibility +LabelFrame = Labelframe # tkinter name compatibility class Menubutton(Widget): @@ -939,7 +939,7 @@ class Notebook(Widget): self.tk.call("ttk::notebook::enableTraversal", self._w) -class Panedwindow(Widget, Tkinter.PanedWindow): +class Panedwindow(Widget, tkinter.PanedWindow): """Ttk Panedwindow widget displays a number of subwindows, stacked either vertically or horizontally.""" @@ -961,7 +961,7 @@ class Panedwindow(Widget, Tkinter.PanedWindow): Widget.__init__(self, master, "ttk::panedwindow", kw) - forget = Tkinter.PanedWindow.forget # overrides Pack.forget + forget = tkinter.PanedWindow.forget # overrides Pack.forget def insert(self, pos, child, **kw): @@ -995,7 +995,7 @@ class Panedwindow(Widget, Tkinter.PanedWindow): Returns the new position of sash number index.""" return self.tk.call(self._w, "sashpos", index, newpos) -PanedWindow = Panedwindow # Tkinter name compatibility +PanedWindow = Panedwindow # tkinter name compatibility class Progressbar(Widget): @@ -1068,7 +1068,7 @@ class Radiobutton(Widget): return self.tk.call(self._w, "invoke") -class Scale(Widget, Tkinter.Scale): +class Scale(Widget, tkinter.Scale): """Ttk Scale widget is typically used to control the numeric value of a linked variable that varies uniformly over some range.""" @@ -1107,7 +1107,7 @@ class Scale(Widget, Tkinter.Scale): return self.tk.call(self._w, 'get', x, y) -class Scrollbar(Widget, Tkinter.Scrollbar): +class Scrollbar(Widget, tkinter.Scrollbar): """Ttk Scrollbar controls the viewport of a scrollable widget.""" def __init__(self, master=None, **kw): @@ -1487,7 +1487,7 @@ class LabeledScale(Frame, object): def __init__(self, master=None, variable=None, from_=0, to=10, **kw): """Construct an horizontal LabeledScale with parent master, a variable to be associated with the Ttk Scale widget and its range. - If variable is not specified, a Tkinter.IntVar is created. + If variable is not specified, a tkinter.IntVar is created. WIDGET-SPECIFIC OPTIONS @@ -1498,7 +1498,7 @@ class LabeledScale(Frame, object): self._label_top = kw.pop('compound', 'top') == 'top' Frame.__init__(self, master, **kw) - self._variable = variable or Tkinter.IntVar(master) + self._variable = variable or tkinter.IntVar(master) self._variable.set(from_) self._last_valid = from_ @@ -1567,7 +1567,7 @@ class LabeledScale(Frame, object): class OptionMenu(Menubutton): - """Themed OptionMenu, based after Tkinter's OptionMenu, which allows + """Themed OptionMenu, based after tkinter's OptionMenu, which allows the user to select a value from a menu.""" def __init__(self, master, variable, default=None, *values, **kwargs): @@ -1588,12 +1588,12 @@ class OptionMenu(Menubutton): kw = {'textvariable': variable, 'style': kwargs.pop('style', None), 'direction': kwargs.pop('direction', None)} Menubutton.__init__(self, master, **kw) - self['menu'] = Tkinter.Menu(self, tearoff=False) + self['menu'] = tkinter.Menu(self, tearoff=False) self._variable = variable self._callback = kwargs.pop('command', None) if kwargs: - raise Tkinter.TclError('unknown option -%s' % ( + raise tkinter.TclError('unknown option -%s' % ( kwargs.iterkeys().next())) self.set_menu(default, *values) @@ -1613,7 +1613,7 @@ class OptionMenu(Menubutton): menu.delete(0, 'end') for val in values: menu.add_radiobutton(label=val, - command=Tkinter._setit(self._variable, val, self._callback)) + command=tkinter._setit(self._variable, val, self._callback)) if default: self._variable.set(default) diff --git a/pysollib/tile/wizarddialog.py b/pysollib/tile/wizarddialog.py index f65031c7..519631c1 100644 --- a/pysollib/tile/wizarddialog.py +++ b/pysollib/tile/wizarddialog.py @@ -27,7 +27,7 @@ __all__ = ['WizardDialog'] # imports import sys -import Tkinter +from six.moves import tkinter import ttk # PySol imports @@ -74,7 +74,7 @@ class WizardDialog(MfxDialog): if w.widget == 'preset': if w.variable is None: - w.variable = Tkinter.StringVar() + w.variable = tkinter.StringVar() values = [_(v) for v in w.values] default = _(w.default) values.remove(default) @@ -91,12 +91,12 @@ class WizardDialog(MfxDialog): cb.grid(row=row, column=1, sticky='ew', padx=2, pady=2) elif w.widget == 'entry': if w.variable is None: - w.variable = Tkinter.StringVar() + w.variable = tkinter.StringVar() en = ttk.Entry(frame, textvariable=w.variable) en.grid(row=row, column=1, sticky='ew', padx=2, pady=2) elif w.widget == 'menu': if w.variable is None: - w.variable = Tkinter.StringVar() + w.variable = tkinter.StringVar() values = [_(v) for v in w.values] cb = PysolCombo(frame, values=tuple(values), textvariable=w.variable, @@ -105,7 +105,7 @@ class WizardDialog(MfxDialog): cb.grid(row=row, column=1, sticky='ew', padx=2, pady=2) elif w.widget == 'spin': if w.variable is None: - w.variable = Tkinter.IntVar() + w.variable = tkinter.IntVar() else: # delete all trace callbacks for mod, cbname in w.variable.trace_vinfo(): @@ -119,7 +119,7 @@ class WizardDialog(MfxDialog): s.grid(row=row, column=1, sticky='ew', padx=2, pady=2) elif w.widget == 'check': if w.variable is None: - w.variable = Tkinter.BooleanVar() + w.variable = tkinter.BooleanVar() ch = ttk.Checkbutton(frame, variable=w.variable, takefocus=False) ch.grid(row=row, column=1, sticky='ew', padx=2, pady=2) diff --git a/pysollib/tk/fontsdialog.py b/pysollib/tk/fontsdialog.py index 18310beb..12606a31 100644 --- a/pysollib/tk/fontsdialog.py +++ b/pysollib/tk/fontsdialog.py @@ -24,7 +24,7 @@ __all__ = ['FontsDialog'] # imports -import Tkinter +from six.moves import tkinter import tkFont # PySol imports @@ -72,36 +72,36 @@ class FontChooserDialog(MfxDialog): 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() + # 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 = 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 = 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 = 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, '<>', self.fontupdate) # self.list_box.focus() - cb1 = Tkinter.Checkbutton(frame, anchor='w', text=_('Bold'), + 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'), + 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, + sc = tkinter.Scale(frame, from_=6, to=40, resolution=1, # label='Size', orient='horizontal', command=self.fontupdate, variable=self.size_var) @@ -164,7 +164,7 @@ class FontsDialog(MfxDialog): top_frame, bottom_frame = self.createFrames(kw) self.createBitmaps(top_frame, kw) - frame = Tkinter.Frame(top_frame) + frame = tkinter.Frame(top_frame) frame.pack(expand=True, fill='both', padx=5, pady=10) frame.columnconfigure(0, weight=1) @@ -181,15 +181,15 @@ class FontsDialog(MfxDialog): ): font = app.opt.fonts[fn] self.fonts[fn] = font - Tkinter.Label(frame, text=title, anchor='w' + tkinter.Label(frame, text=title, anchor='w' ).grid(row=row, column=0, sticky='we') if font: title = self._font2title(font) elif font is None: title = 'Default' - l = Tkinter.Label(frame, font=font, text=title) + l = tkinter.Label(frame, font=font, text=title) l.grid(row=row, column=1) - b = Tkinter.Button(frame, text=_('Change...'), width=10, + b = tkinter.Button(frame, text=_('Change...'), width=10, command=lambda l=l, fn=fn: self.selectFont(l, fn)) b.grid(row=row, column=2) diff --git a/pysollib/tk/playeroptionsdialog.py b/pysollib/tk/playeroptionsdialog.py index fe480923..41b3214d 100644 --- a/pysollib/tk/playeroptionsdialog.py +++ b/pysollib/tk/playeroptionsdialog.py @@ -24,7 +24,7 @@ __all__ = ['PlayerOptionsDialog'] # imports -import Tkinter +from six.moves import tkinter # PySol imports from pysollib.mygettext import _ @@ -46,9 +46,9 @@ class SelectUserNameDialog(MfxDialog): top_frame, bottom_frame = self.createFrames(kw) self.createBitmaps(top_frame, kw) # - listbox = Tkinter.Listbox(top_frame) + listbox = tkinter.Listbox(top_frame) listbox.pack(side='left', fill='both', expand=True) - scrollbar = Tkinter.Scrollbar(top_frame) + scrollbar = tkinter.Scrollbar(top_frame) scrollbar.pack(side='right', fill='y') listbox.configure(yscrollcommand=scrollbar.set) scrollbar.configure(command=listbox.yview) @@ -87,34 +87,34 @@ class PlayerOptionsDialog(MfxDialog): self.createBitmaps(top_frame, kw) self.app = app # - self.update_stats_var = Tkinter.BooleanVar() + self.update_stats_var = tkinter.BooleanVar() self.update_stats_var.set(app.opt.update_player_stats != 0) - self.confirm_var = Tkinter.BooleanVar() + self.confirm_var = tkinter.BooleanVar() self.confirm_var.set(app.opt.confirm != 0) - self.win_animation_var = Tkinter.BooleanVar() + self.win_animation_var = tkinter.BooleanVar() self.win_animation_var.set(app.opt.win_animation != 0) # - frame = Tkinter.Frame(top_frame) + frame = tkinter.Frame(top_frame) frame.pack(expand=True, fill='both', padx=5, pady=10) - widget = Tkinter.Label(frame, text=_("\nPlease enter your name"), + widget = tkinter.Label(frame, text=_("\nPlease enter your name"), # justify='left', anchor='w', takefocus=0) widget.grid(row=0, column=0, columnspan=2, sticky='ew', padx=0, pady=5) w = kw.get("e_width", 30) # width in characters - self.player_var = Tkinter.Entry(frame, exportselection=1, width=w) + self.player_var = tkinter.Entry(frame, exportselection=1, width=w) self.player_var.insert(0, app.opt.player) self.player_var.grid(row=1, column=0, sticky='ew', padx=0, pady=5) - widget = Tkinter.Button(frame, text=_('Choose...'), + widget = tkinter.Button(frame, text=_('Choose...'), command=self.selectUserName) widget.grid(row=1, column=1, padx=5, pady=5) - widget = Tkinter.Checkbutton(frame, variable=self.confirm_var, + widget = tkinter.Checkbutton(frame, variable=self.confirm_var, anchor='w', text=_("Confirm quit")) widget.grid(row=2, column=0, columnspan=2, sticky='ew', padx=0, pady=5) - widget = Tkinter.Checkbutton(frame, variable=self.update_stats_var, + widget = tkinter.Checkbutton(frame, variable=self.update_stats_var, anchor='w', text=_("Update statistics and logs")) widget.grid(row=3, column=0, columnspan=2, sticky='ew', padx=0, pady=5) - # widget = Tkinter.Checkbutton(frame, variable=self.win_animation_var, + # widget = tkinter.Checkbutton(frame, variable=self.win_animation_var, # text="Win animation") # widget.pack(side='top', padx=kw.padx, pady=kw.pady) frame.columnconfigure(0, weight=1) @@ -159,7 +159,7 @@ def playeroptionsdialog_main(args): from pysollib.ui.tktile.tkutil import wm_withdraw opt = Struct(player="Test", update_player_stats=1) app = Struct(opt=opt) - tk = Tkinter.Tk() + tk = tkinter.Tk() wm_withdraw(tk) tk.update() d = PlayerOptionsDialog(tk, "Player options", app) diff --git a/pysollib/tk/progressbar.py b/pysollib/tk/progressbar.py index 008fd165..cd36c1dd 100644 --- a/pysollib/tk/progressbar.py +++ b/pysollib/tk/progressbar.py @@ -24,7 +24,7 @@ __all__ = ['PysolProgressBar'] # imports -import Tkinter +from six.moves import tkinter # Toolkit imports from pysollib.ui.tktile.tkconst import EVENT_HANDLED @@ -44,24 +44,24 @@ class PysolProgressBar: self.top.wm_protocol("WM_DELETE_WINDOW", self.wmDeleteWindow) self.top.wm_group(parent) self.top.wm_resizable(False, False) - self.frame = Tkinter.Frame(self.top, relief='flat', bd=0, + self.frame = tkinter.Frame(self.top, relief='flat', bd=0, takefocus=0) - self.cframe = Tkinter.Frame(self.frame, relief='sunken', bd=1, + self.cframe = tkinter.Frame(self.frame, relief='sunken', bd=1, takefocus=0) - self.canvas = Tkinter.Canvas(self.cframe, width=width, height=height, + self.canvas = tkinter.Canvas(self.cframe, width=width, height=height, takefocus=0, bd=0, highlightthickness=0) self.scale = self.canvas.create_rectangle(-10, -10, 0, height, outline=color, fill=color) self.text = -1 if show_text: - self.text = self.canvas.create_text(0, 0, anchor=Tkinter.CENTER) + self.text = self.canvas.create_text(0, 0, anchor=tkinter.CENTER) self.cframe.grid_configure(column=0, row=0, sticky="ew") if images: - self.f1 = Tkinter.Label(self.frame, image=images[0]) + self.f1 = tkinter.Label(self.frame, image=images[0]) self.f1.grid_configure( column=0, row=0, sticky="ew", ipadx=8, ipady=4) self.cframe.grid_configure(column=1, row=0, sticky="ew", padx=8) - self.f2 = Tkinter.Label(self.frame, image=images[1]) + self.f2 = tkinter.Label(self.frame, image=images[1]) self.f2.grid_configure( column=2, row=0, sticky="ew", ipadx=8, ipady=4) self.top.config(cursor="watch") @@ -85,7 +85,7 @@ class PysolProgressBar: self.top = None def pack(self, **kw): - self.canvas.pack(fill=Tkinter.X, expand=False) + self.canvas.pack(fill=tkinter.X, expand=False) self.frame.pack(**kw) def reset(self, percent=0): @@ -137,7 +137,7 @@ class TestProgressBar: def progressbar_main(args): from pysollib.ui.tktile.tkutil import wm_withdraw - tk = Tkinter.Tk() + tk = tkinter.Tk() wm_withdraw(tk) TestProgressBar(tk) tk.mainloop() diff --git a/pysollib/tk/selectcardset.py b/pysollib/tk/selectcardset.py index edc977ae..28adad16 100644 --- a/pysollib/tk/selectcardset.py +++ b/pysollib/tk/selectcardset.py @@ -25,7 +25,7 @@ __all__ = ['SelectCardsetDialogWithPreview'] # imports import os -import Tkinter +from six.moves import tkinter # PySol imports from pysollib.mygettext import _ @@ -227,10 +227,10 @@ class SelectCardsetDialogWithPreview(MfxDialog): w1, w2 = 240, 400 else: w1, w2 = 200, 300 - paned_window = Tkinter.PanedWindow(top_frame) + paned_window = tkinter.PanedWindow(top_frame) paned_window.pack(expand=True, fill='both') - left_frame = Tkinter.Frame(paned_window) - right_frame = Tkinter.Frame(paned_window) + left_frame = tkinter.Frame(paned_window) + right_frame = tkinter.Frame(paned_window) paned_window.add(left_frame) paned_window.add(right_frame) @@ -242,9 +242,9 @@ class SelectCardsetDialogWithPreview(MfxDialog): padx=padx, pady=pady) if USE_PIL: # - var = Tkinter.DoubleVar() + var = tkinter.DoubleVar() var.set(app.opt.scale_x) - self.scale_x = Tkinter.Scale( + self.scale_x = tkinter.Scale( left_frame, label=_('Scale X:'), from_=0.5, to=4.0, resolution=0.1, orient='horizontal', variable=var, @@ -253,9 +253,9 @@ class SelectCardsetDialogWithPreview(MfxDialog): self.scale_x.grid( row=1, column=0, sticky='ew', padx=padx, pady=pady) # - var = Tkinter.DoubleVar() + var = tkinter.DoubleVar() var.set(app.opt.scale_y) - self.scale_y = Tkinter.Scale( + self.scale_y = tkinter.Scale( left_frame, label=_('Scale Y:'), from_=0.5, to=4.0, resolution=0.1, orient='horizontal', variable=var, @@ -264,9 +264,9 @@ class SelectCardsetDialogWithPreview(MfxDialog): self.scale_y.grid( row=2, column=0, sticky='ew', padx=padx, pady=pady) # - self.auto_scale = Tkinter.BooleanVar() + self.auto_scale = tkinter.BooleanVar() self.auto_scale.set(app.opt.auto_scale) - check = Tkinter.Checkbutton( + check = tkinter.Checkbutton( left_frame, text=_('Auto scaling'), variable=self.auto_scale, takefocus=False, @@ -275,9 +275,9 @@ class SelectCardsetDialogWithPreview(MfxDialog): check.grid(row=3, column=0, columnspan=2, sticky='w', padx=padx, pady=pady) # - self.preserve_aspect = Tkinter.BooleanVar() + self.preserve_aspect = tkinter.BooleanVar() self.preserve_aspect.set(app.opt.preserve_aspect_ratio) - self.aspect_check = Tkinter.Checkbutton( + self.aspect_check = tkinter.Checkbutton( left_frame, text=_('Preserve aspect ratio'), variable=self.preserve_aspect, takefocus=False, @@ -427,11 +427,11 @@ class CardsetInfoDialog(MfxDialog): MfxDialog.__init__(self, parent, title, kw.resizable, kw.default) top_frame, bottom_frame = self.createFrames(kw) self.createBitmaps(top_frame, kw) - frame = Tkinter.Frame(top_frame) + frame = tkinter.Frame(top_frame) frame.pack(fill="both", expand=True, padx=5, pady=10) # # - info_frame = Tkinter.LabelFrame(frame, text=_('About cardset')) + info_frame = tkinter.LabelFrame(frame, text=_('About cardset')) info_frame.grid(row=0, column=0, columnspan=2, sticky='ew', padx=0, pady=5, ipadx=5, ipady=5) styles = nationalities = year = None @@ -453,10 +453,10 @@ class CardsetInfoDialog(MfxDialog): (_('Size:'), '%d x %d' % (cardset.CARDW, cardset.CARDH)), ): if t is not None: - l = Tkinter.Label(info_frame, text=n, + l = tkinter.Label(info_frame, text=n, anchor='w', justify='left') l.grid(row=row, column=0, sticky='nw') - l = Tkinter.Label(info_frame, text=t, + l = tkinter.Label(info_frame, text=t, anchor='w', justify='left') l.grid(row=row, column=1, sticky='nw') row += 1 @@ -466,7 +466,7 @@ class CardsetInfoDialog(MfxDialog): im = choice(images) f = os.path.join(cardset.dir, cardset.backname) self.back_image = loadImage(file=f) - canvas = Tkinter.Canvas(info_frame, + canvas = tkinter.Canvas(info_frame, width=2*im.width()+30, height=im.height()+2) canvas.create_image(10, 1, image=im, anchor='nw') @@ -479,10 +479,10 @@ class CardsetInfoDialog(MfxDialog): pass # bg = top_frame["bg"] bg = 'white' - text_w = Tkinter.Text(frame, bd=1, relief="sunken", wrap="word", + text_w = tkinter.Text(frame, bd=1, relief="sunken", wrap="word", padx=4, width=64, height=16, bg=bg) text_w.grid(row=1, column=0, sticky='nsew') - sb = Tkinter.Scrollbar(frame) + sb = tkinter.Scrollbar(frame) sb.grid(row=1, column=1, sticky='ns') text_w.configure(yscrollcommand=sb.set) sb.configure(command=text_w.yview) diff --git a/pysollib/tk/selectgame.py b/pysollib/tk/selectgame.py index ce53a693..f73cd57e 100644 --- a/pysollib/tk/selectgame.py +++ b/pysollib/tk/selectgame.py @@ -24,7 +24,7 @@ # imports import os -import Tkinter +from six.moves import tkinter from UserList import UserList # PySol imports @@ -367,10 +367,10 @@ class SelectGameDialogWithPreview(SelectGameDialog): # padx, pady = kw.padx, kw.pady padx, pady = kw.padx/2, kw.pady/2 # PanedWindow - paned_window = Tkinter.PanedWindow(top_frame) + paned_window = tkinter.PanedWindow(top_frame) paned_window.pack(expand=True, fill='both') - left_frame = Tkinter.Frame(paned_window) - right_frame = Tkinter.Frame(paned_window) + left_frame = tkinter.Frame(paned_window) + right_frame = tkinter.Frame(paned_window) paned_window.add(left_frame) paned_window.add(right_frame) # Tree @@ -379,8 +379,8 @@ class SelectGameDialogWithPreview(SelectGameDialog): default=kw.default, font=font, width=w1) self.tree.frame.pack(padx=padx, pady=pady, expand=True, fill='both') # LabelFrame - info_frame = Tkinter.LabelFrame(right_frame, text=_('About game')) - stats_frame = Tkinter.LabelFrame(right_frame, text=_('Statistics')) + info_frame = tkinter.LabelFrame(right_frame, text=_('About game')) + stats_frame = tkinter.LabelFrame(right_frame, text=_('Statistics')) info_frame.grid(row=0, column=0, padx=padx, pady=pady, ipadx=padx, ipady=pady, sticky='nws') stats_frame.grid(row=0, column=1, padx=padx, pady=pady, @@ -403,9 +403,9 @@ class SelectGameDialogWithPreview(SelectGameDialog): ('moves', _('Moves:'), stats_frame, 4), ('percent', _('% won:'), stats_frame, 5), ): - title_label = Tkinter.Label(f, text=t, justify='left', anchor='w') + title_label = tkinter.Label(f, text=t, justify='left', anchor='w') title_label.grid(row=row, column=0, sticky='nw') - text_label = Tkinter.Label(f, justify='left', anchor='w') + text_label = tkinter.Label(f, justify='left', anchor='w') text_label.grid(row=row, column=1, sticky='nw') self.info_labels[n] = (title_label, text_label) # info_frame.columnconfigure(1, weight=1) diff --git a/pysollib/tk/selecttile.py b/pysollib/tk/selecttile.py index 013f5a4b..31603cc0 100644 --- a/pysollib/tk/selecttile.py +++ b/pysollib/tk/selecttile.py @@ -24,7 +24,7 @@ # imports import sys -import Tkinter +from six.moves import tkinter import tkColorChooser # PySol imports @@ -128,7 +128,7 @@ class SelectTileDialogWithPreview(MfxDialog): w1, w2 = 200, 300 font = app.getFont("default") padx, pady = 4, 4 - frame = Tkinter.Frame(top_frame) + frame = tkinter.Frame(top_frame) frame.pack(fill='both', expand=True, padx=kw.padx-padx, pady=kw.pady-pady) self.tree = self.Tree_Class(self, frame, key=key, @@ -177,7 +177,7 @@ class SelectTileDialogWithPreview(MfxDialog): c = tkColorChooser.askcolor(master=self.top, initialcolor=self.table_color, title=_("Select table color")) - except Tkinter.TclError: + except tkinter.TclError: pass else: if c and c[1]: diff --git a/pysollib/tk/solverdialog.py b/pysollib/tk/solverdialog.py index ebd36d30..a568da03 100644 --- a/pysollib/tk/solverdialog.py +++ b/pysollib/tk/solverdialog.py @@ -31,7 +31,7 @@ __all__ = [ # imports import sys -import Tkinter +from six.moves import tkinter # PySol imports from pysollib.mygettext import _ @@ -56,8 +56,8 @@ solver_dialog = solver_dialog class SolverDialog(BaseSolverDialog, BaseTkMfxDialog): def _createGamesVar(self, frame, row): - var = Tkinter.StringVar() - om = Tkinter.OptionMenu(frame, var, command=self.gameSelected, + var = tkinter.StringVar() + om = tkinter.OptionMenu(frame, var, command=self.gameSelected, *(self.gamenames)) om.grid(row=row, column=1, sticky='ew', padx=2, pady=2) n = len(self.gamenames) @@ -68,9 +68,9 @@ class SolverDialog(BaseSolverDialog, BaseTkMfxDialog): return var def _createPresetVar(self, frame, row): - var = Tkinter.StringVar() + var = tkinter.StringVar() var.set('none') - om = Tkinter.OptionMenu(frame, var, *(self.presets)) + om = tkinter.OptionMenu(frame, var, *(self.presets)) om.grid(row=row, column=1, sticky='ew', padx=2, pady=2) return var diff --git a/pysollib/tk/soundoptionsdialog.py b/pysollib/tk/soundoptionsdialog.py index fdef1d3b..38150cbb 100644 --- a/pysollib/tk/soundoptionsdialog.py +++ b/pysollib/tk/soundoptionsdialog.py @@ -25,7 +25,7 @@ __all__ = ['SoundOptionsDialog'] # imports import os -import Tkinter +from six.moves import tkinter # PySol imports from pysollib.mygettext import _ @@ -52,74 +52,74 @@ class SoundOptionsDialog(MfxDialog): self.createBitmaps(top_frame, kw) # self.saved_opt = app.opt.copy() - self.sound = Tkinter.BooleanVar() + self.sound = tkinter.BooleanVar() self.sound.set(app.opt.sound != 0) - self.sound_mode = Tkinter.BooleanVar() + self.sound_mode = tkinter.BooleanVar() self.sound_mode.set(app.opt.sound_mode != 0) - self.sample_volume = Tkinter.IntVar() + self.sample_volume = tkinter.IntVar() self.sample_volume.set(app.opt.sound_sample_volume) - self.music_volume = Tkinter.IntVar() + self.music_volume = tkinter.IntVar() self.music_volume.set(app.opt.sound_music_volume) self.samples = [ - ('areyousure', _('Are You Sure'), Tkinter.BooleanVar()), + ('areyousure', _('Are You Sure'), tkinter.BooleanVar()), - ('deal', _('Deal'), Tkinter.BooleanVar()), - ('dealwaste', _('Deal waste'), Tkinter.BooleanVar()), + ('deal', _('Deal'), tkinter.BooleanVar()), + ('dealwaste', _('Deal waste'), tkinter.BooleanVar()), - ('turnwaste', _('Turn waste'), Tkinter.BooleanVar()), - ('startdrag', _('Start drag'), Tkinter.BooleanVar()), + ('turnwaste', _('Turn waste'), tkinter.BooleanVar()), + ('startdrag', _('Start drag'), tkinter.BooleanVar()), - ('drop', _('Drop'), Tkinter.BooleanVar()), - ('droppair', _('Drop pair'), Tkinter.BooleanVar()), - ('autodrop', _('Auto drop'), Tkinter.BooleanVar()), + ('drop', _('Drop'), tkinter.BooleanVar()), + ('droppair', _('Drop pair'), tkinter.BooleanVar()), + ('autodrop', _('Auto drop'), tkinter.BooleanVar()), - ('flip', _('Flip'), Tkinter.BooleanVar()), - ('autoflip', _('Auto flip'), Tkinter.BooleanVar()), - ('move', _('Move'), Tkinter.BooleanVar()), - ('nomove', _('No move'), Tkinter.BooleanVar()), + ('flip', _('Flip'), tkinter.BooleanVar()), + ('autoflip', _('Auto flip'), tkinter.BooleanVar()), + ('move', _('Move'), tkinter.BooleanVar()), + ('nomove', _('No move'), tkinter.BooleanVar()), - ('undo', _('Undo'), Tkinter.BooleanVar()), - ('redo', _('Redo'), Tkinter.BooleanVar()), + ('undo', _('Undo'), tkinter.BooleanVar()), + ('redo', _('Redo'), tkinter.BooleanVar()), - ('autopilotlost', _('Autopilot lost'), Tkinter.BooleanVar()), - ('autopilotwon', _('Autopilot won'), Tkinter.BooleanVar()), + ('autopilotlost', _('Autopilot lost'), tkinter.BooleanVar()), + ('autopilotwon', _('Autopilot won'), tkinter.BooleanVar()), - ('gamefinished', _('Game finished'), Tkinter.BooleanVar()), - ('gamelost', _('Game lost'), Tkinter.BooleanVar()), - ('gamewon', _('Game won'), Tkinter.BooleanVar()), - ('gameperfect', _('Perfect game'), Tkinter.BooleanVar()), + ('gamefinished', _('Game finished'), tkinter.BooleanVar()), + ('gamelost', _('Game lost'), tkinter.BooleanVar()), + ('gamewon', _('Game won'), tkinter.BooleanVar()), + ('gameperfect', _('Perfect game'), tkinter.BooleanVar()), ] # - frame = Tkinter.Frame(top_frame) + frame = tkinter.Frame(top_frame) frame.pack(expand=True, fill='both', padx=5, pady=5) frame.columnconfigure(1, weight=1) # row = 0 - w = Tkinter.Checkbutton(frame, variable=self.sound, + w = tkinter.Checkbutton(frame, variable=self.sound, text=_("Sound enabled"), anchor='w') w.grid(row=row, column=0, columnspan=2, sticky='ew') # if os.name == "nt" and pysolsoundserver: row += 1 - w = Tkinter.Checkbutton(frame, variable=self.sound_mode, + w = tkinter.Checkbutton(frame, variable=self.sound_mode, text=_("Use DirectX for sound playing"), command=self.mOptSoundDirectX, anchor='w') w.grid(row=row, column=0, columnspan=2, sticky='ew') # if app.audio.CAN_PLAY_MUSIC: # and app.startup_opt.sound_mode > 0: row += 1 - w = Tkinter.Label(frame, text=_('Sample volume:')) + w = tkinter.Label(frame, text=_('Sample volume:')) w.grid(row=row, column=0, sticky='w', padx=5) - w = Tkinter.Scale(frame, from_=0, to=128, resolution=1, + w = tkinter.Scale(frame, from_=0, to=128, resolution=1, orient='horizontal', takefocus=0, length="3i", # label=_('Sample volume'), variable=self.sample_volume) w.grid(row=row, column=1, sticky='ew', padx=5) row += 1 - w = Tkinter.Label(frame, text=_('Music volume:')) + w = tkinter.Label(frame, text=_('Music volume:')) w.grid(row=row, column=0, sticky='w', padx=5) - w = Tkinter.Scale(frame, from_=0, to=128, resolution=1, + w = tkinter.Scale(frame, from_=0, to=128, resolution=1, orient='horizontal', takefocus=0, length="3i", # label=_('Music volume'), variable=self.music_volume) @@ -129,7 +129,7 @@ class SoundOptionsDialog(MfxDialog): # remove "Apply" button kw.strings[1] = None # - frame = Tkinter.LabelFrame(top_frame, text=_('Enable samles'), + frame = tkinter.LabelFrame(top_frame, text=_('Enable samles'), padx=5, pady=5) frame.pack(expand=True, fill='both', padx=5, pady=5) frame.columnconfigure(0, weight=1) @@ -139,7 +139,7 @@ class SoundOptionsDialog(MfxDialog): col = 0 for n, t, v in self.samples: v.set(app.opt.sound_samples[n]) - w = Tkinter.Checkbutton(frame, text=t, anchor='w', variable=v) + w = tkinter.Checkbutton(frame, text=t, anchor='w', variable=v) w.grid(row=row, column=col, sticky='ew') if col == 1: col = 0 diff --git a/pysollib/tk/statusbar.py b/pysollib/tk/statusbar.py index 9c987880..b1d86559 100644 --- a/pysollib/tk/statusbar.py +++ b/pysollib/tk/statusbar.py @@ -27,7 +27,7 @@ __all__ = ['PysolStatusbar', # imports import os import sys -import Tkinter +from six.moves import tkinter from pysollib.mygettext import _ from tkwidget import MfxTooltip from pysollib.settings import WIN_SYSTEM @@ -61,7 +61,7 @@ class MfxStatusbar: # self.padx = 1 self.label_relief = 'sunken' - self.frame = Tkinter.Frame(self.top, bd=1) + self.frame = tkinter.Frame(self.top, bd=1) self.frame.grid(row=self._row, column=self._column, columnspan=self._columnspan, sticky='ew', padx=1, pady=1) @@ -75,7 +75,7 @@ class MfxStatusbar: # util def _createLabel(self, name, expand=False, width=0, tooltip=None): - label = Tkinter.Label(self.frame, width=width, + label = tkinter.Label(self.frame, width=width, relief=self.label_relief, bd=1, highlightbackground='black' ) @@ -192,7 +192,7 @@ class TestStatusbar(PysolStatusbar): def statusbar_main(args): - tk = Tkinter.Tk() + tk = tkinter.Tk() TestStatusbar(tk, args) tk.mainloop() return 0 diff --git a/pysollib/tk/tabpage.py b/pysollib/tk/tabpage.py index 1798c9ca..da81a472 100644 --- a/pysollib/tk/tabpage.py +++ b/pysollib/tk/tabpage.py @@ -24,11 +24,10 @@ a couple of classes for implementing partial tabbed-page like behaviour """ -from Tkinter import EW, FALSE, Frame, Radiobutton, RAISED, RIDGE, StringVar -from Tkinter import BOTH, Button, Entry, Label, LEFT, NSEW, Tk, TRUE +from six.moves import tkinter -MYRIDGE, MYRAISED = RAISED, RIDGE -# MYRIDGE, MYRAISED = RIDGE, RAISED +MYRIDGE, MYRAISED = tkinter.RAISED, tkinter.RIDGE +# MYRIDGE, MYRAISED = tkinter.RIDGE, tkinter.RAISED class InvalidTabPage(Exception): @@ -39,20 +38,20 @@ class AlreadyExists(Exception): pass -class PageTab(Frame): +class PageTab(tkinter.Frame): """ a 'page tab' like framed button """ def __init__(self, parent): - Frame.__init__(self, parent, borderwidth=2, relief=MYRIDGE) - self.button = Radiobutton( + tkinter.Frame.__init__(self, parent, borderwidth=2, relief=MYRIDGE) + self.button = tkinter.Radiobutton( self, padx=5, pady=5, takefocus=0, - indicatoron=FALSE, highlightthickness=0, + indicatoron=tkinter.FALSE, highlightthickness=0, borderwidth=0, selectcolor=self.cget('bg')) self.button.pack() -class TabPageSet(Frame): +class TabPageSet(tkinter.Frame): """ a set of 'pages' with TabButtons for controlling their display """ @@ -63,13 +62,13 @@ class TabPageSet(Frame): specified in desired page order. The first page will be the default and first active page. """ - Frame.__init__(self, parent, kw) + tkinter.Frame.__init__(self, parent, kw) self.grid_location(0, 0) self.columnconfigure(0, weight=1) self.rowconfigure(1, weight=1) - self.tabBar = Frame(self) - self.tabBar.grid(row=0, column=0, sticky=EW) - self.activePage = StringVar(self) + self.tabBar = tkinter.Frame(self) + self.tabBar.grid(row=0, column=0, sticky=tkinter.EW) + self.activePage = tkinter.StringVar(self) self.defaultPage = '' self.pages = {} for name in pageNames: @@ -96,7 +95,7 @@ class TabPageSet(Frame): raise AlreadyExists('TabPage Name Already Exists') self.pages[pageName] = { 'tab': PageTab(self.tabBar), - 'page': Frame(self, borderwidth=2, relief=RAISED) + 'page': tkinter.Frame(self, borderwidth=2, relief=tkinter.RAISED) } self.pages[pageName]['tab'].button.config( text=pageName, @@ -104,8 +103,8 @@ class TabPageSet(Frame): variable=self.activePage, value=pageName ) - self.pages[pageName]['tab'].pack(side=LEFT) - self.pages[pageName]['page'].grid(row=1, column=0, sticky=NSEW) + self.pages[pageName]['tab'].pack(side=tkinter.LEFT) + self.pages[pageName]['page'].grid(row=1, column=0, sticky=tkinter.NSEW) if len(self.pages) == 1: # adding first page self.defaultPage = pageName self.activePage.set(self.defaultPage) @@ -133,20 +132,20 @@ class TabPageSet(Frame): if __name__ == '__main__': # test dialog - root = Tk() + root = tkinter.Tk() tabPage = TabPageSet(root, pageNames=['Foobar', 'Baz']) - tabPage.pack(expand=TRUE, fill=BOTH) - Label(tabPage.pages['Foobar']['page'], text='Foo', pady=20).pack() - Label(tabPage.pages['Foobar']['page'], text='Bar', pady=20).pack() - Label(tabPage.pages['Baz']['page'], text='Baz').pack() - entryPgName = Entry(root) - buttonAdd = Button( + tabPage.pack(expand=tkinter.TRUE, fill=tkinter.BOTH) + tkinter.Label(tabPage.pages['Foobar']['page'], text='Foo', pady=20).pack() + tkinter.Label(tabPage.pages['Foobar']['page'], text='Bar', pady=20).pack() + tkinter.Label(tabPage.pages['Baz']['page'], text='Baz').pack() + entryPgName = tkinter.Entry(root) + buttonAdd = tkinter.Button( root, text='Add Page', command=lambda: tabPage.AddPage(entryPgName.get())) - buttonRemove = Button( + buttonRemove = tkinter.Button( root, text='Remove Page', command=lambda: tabPage.RemovePage(entryPgName.get())) - labelPgName = Label(root, text='name of page to add/remove:') + labelPgName = tkinter.Label(root, text='name of page to add/remove:') buttonAdd.pack(padx=5, pady=5) buttonRemove.pack(padx=5, pady=5) labelPgName.pack(padx=5) diff --git a/pysollib/tk/timeoutsdialog.py b/pysollib/tk/timeoutsdialog.py index b7cdbc28..8a67dfee 100644 --- a/pysollib/tk/timeoutsdialog.py +++ b/pysollib/tk/timeoutsdialog.py @@ -24,7 +24,7 @@ __all__ = ['TimeoutsDialog'] # imports -import Tkinter +from six.moves import tkinter # PySol imports from pysollib.mygettext import _ @@ -45,25 +45,25 @@ class TimeoutsDialog(MfxDialog): top_frame, bottom_frame = self.createFrames(kw) # self.createBitmaps(top_frame, kw) - frame = Tkinter.Frame(top_frame) + frame = tkinter.Frame(top_frame) frame.pack(expand=True, fill='both', padx=5, pady=10) frame.columnconfigure(0, weight=1) - self.demo_sleep_var = Tkinter.DoubleVar() + self.demo_sleep_var = tkinter.DoubleVar() self.demo_sleep_var.set(app.opt.timeouts['demo']) - self.hint_sleep_var = Tkinter.DoubleVar() + self.hint_sleep_var = tkinter.DoubleVar() self.hint_sleep_var.set(app.opt.timeouts['hint']) - self.raise_card_sleep_var = Tkinter.DoubleVar() + self.raise_card_sleep_var = tkinter.DoubleVar() self.raise_card_sleep_var.set(app.opt.timeouts['raise_card']) - self.highlight_piles_sleep_var = Tkinter.DoubleVar() + self.highlight_piles_sleep_var = tkinter.DoubleVar() self.highlight_piles_sleep_var.set(app.opt.timeouts['highlight_piles']) - self.highlight_cards_sleep_var = Tkinter.DoubleVar() + self.highlight_cards_sleep_var = tkinter.DoubleVar() self.highlight_cards_sleep_var.set(app.opt.timeouts['highlight_cards']) - self.highlight_samerank_sleep_var = Tkinter.DoubleVar() + self.highlight_samerank_sleep_var = tkinter.DoubleVar() self.highlight_samerank_sleep_var.set( app.opt.timeouts['highlight_samerank']) # - # Tkinter.Label(frame, text='Set delays in seconds').grid( + # tkinter.Label(frame, text='Set delays in seconds').grid( # row=0, column=0, columnspan=2) row = 0 for title, var in ((_('Demo:'), self.demo_sleep_var), @@ -76,9 +76,9 @@ class TimeoutsDialog(MfxDialog): (_('Highlight same rank:'), self.highlight_samerank_sleep_var), ): - Tkinter.Label(frame, text=title, anchor='w' + tkinter.Label(frame, text=title, anchor='w' ).grid(row=row, column=0, sticky='we') - widget = Tkinter.Scale(frame, from_=0.2, to=9.9, + widget = tkinter.Scale(frame, from_=0.2, to=9.9, resolution=0.1, orient='horizontal', length="3i", variable=var, takefocus=0) widget.grid(row=row, column=1) diff --git a/pysollib/tk/tkhtml.py b/pysollib/tk/tkhtml.py index 0294651c..29d08378 100644 --- a/pysollib/tk/tkhtml.py +++ b/pysollib/tk/tkhtml.py @@ -26,7 +26,7 @@ __all__ = ['HTMLViewer'] # imports import os import sys -import Tkinter +from six.moves import tkinter # PySol imports from pysollib.mygettext import _ @@ -74,30 +74,30 @@ class HTMLViewer(Base_HTMLViewer): # create buttons button_width = 8 - self.homeButton = Tkinter.Button(parent, text=_("Index"), + self.homeButton = tkinter.Button(parent, text=_("Index"), width=button_width, command=self.goHome) self.homeButton.grid(row=0, column=0, sticky='w') - self.backButton = Tkinter.Button(parent, text=_("Back"), + self.backButton = tkinter.Button(parent, text=_("Back"), width=button_width, command=self.goBack) self.backButton.grid(row=0, column=1, sticky='w') - self.forwardButton = Tkinter.Button(parent, text=_("Forward"), + self.forwardButton = tkinter.Button(parent, text=_("Forward"), width=button_width, command=self.goForward) self.forwardButton.grid(row=0, column=2, sticky='w') - self.closeButton = Tkinter.Button(parent, text=_("Close"), + self.closeButton = tkinter.Button(parent, text=_("Close"), width=button_width, command=self.destroy) self.closeButton.grid(row=0, column=3, sticky='e') # create text widget - text_frame = Tkinter.Frame(parent) + text_frame = tkinter.Frame(parent) text_frame.grid(row=1, column=0, columnspan=4, sticky='nsew') text_frame.grid_propagate(False) - vbar = Tkinter.Scrollbar(text_frame) + vbar = tkinter.Scrollbar(text_frame) vbar.pack(side='right', fill='y') - self.text = Tkinter.Text(text_frame, + self.text = tkinter.Text(text_frame, fg='black', bg='white', bd=1, relief='sunken', cursor=self.defcursor, @@ -129,7 +129,7 @@ def tkhtml_main(args): url = args[1] except: url = os.path.join(os.pardir, os.pardir, "data", "html", "index.html") - top = Tkinter.Tk() + top = tkinter.Tk() top.wm_minsize(400, 200) viewer = HTMLViewer(top) viewer.app = None diff --git a/pysollib/tk/tkstats.py b/pysollib/tk/tkstats.py index 8aee4a1c..f0ff55c8 100644 --- a/pysollib/tk/tkstats.py +++ b/pysollib/tk/tkstats.py @@ -33,7 +33,7 @@ __all__ = ['SingleGame_StatsDialog', # imports import os import time -import Tkinter +from six.moves import tkinter import tkFont # PySol imports @@ -133,14 +133,14 @@ class SingleGame_StatsDialog(MfxDialog): def _createChartInit(self, text): w, h = self.tab_x[-1]+20, self.tab_y[-1]+20 - c = Tkinter.Canvas(self.top_frame, width=w, height=h) + c = tkinter.Canvas(self.top_frame, width=w, height=h) c.pack(side='top', fill='both', expand=False, padx=20, pady=10) self.canvas = c # self.fg = c.cget("insertbackground") self.fg = c.option_get('foreground', '') or c.cget("insertbackground") # c.create_rectangle(2, 7, w, h, fill="", outline="#7f7f7f") - l = Tkinter.Label(c, text=text, font=self.font, bd=0, padx=3, pady=1) + l = tkinter.Label(c, text=text, font=self.font, bd=0, padx=3, pady=1) dy = int(self.font_metrics['ascent']) - 10 dy = dy/2 c.create_window(20, -dy, window=l, anchor="nw") @@ -682,38 +682,38 @@ class _TopDialog(MfxDialog): 'highlightthickness': 1, 'highlightbackground': 'black', } - frame = Tkinter.Frame(**cnf) + frame = tkinter.Frame(**cnf) frame.pack(expand=True, fill='both', padx=10, pady=10) frame.columnconfigure(0, weight=1) cnf['master'] = frame cnf['text'] = _('N') - l = Tkinter.Label(**cnf) + l = tkinter.Label(**cnf) l.grid(row=0, column=0, sticky='ew') cnf['text'] = _('Game number') - l = Tkinter.Label(**cnf) + l = tkinter.Label(**cnf) l.grid(row=0, column=1, sticky='ew') cnf['text'] = _('Started at') - l = Tkinter.Label(**cnf) + l = tkinter.Label(**cnf) l.grid(row=0, column=2, sticky='ew') cnf['text'] = _('Result') - l = Tkinter.Label(**cnf) + l = tkinter.Label(**cnf) l.grid(row=0, column=3, sticky='ew') row = 1 for i in top: # N cnf['text'] = str(row) - l = Tkinter.Label(**cnf) + l = tkinter.Label(**cnf) l.grid(row=row, column=0, sticky='ew') # Game number cnf['text'] = '#'+str(i.game_number) - l = Tkinter.Label(**cnf) + l = tkinter.Label(**cnf) l.grid(row=row, column=1, sticky='ew') # Start time t = time.strftime( '%Y-%m-%d %H:%M', time.localtime(i.game_start_time)) cnf['text'] = t - l = Tkinter.Label(**cnf) + l = tkinter.Label(**cnf) l.grid(row=row, column=2, sticky='ew') # Result if isinstance(i.value, float): @@ -723,7 +723,7 @@ class _TopDialog(MfxDialog): # moves s = str(i.value) cnf['text'] = s - l = Tkinter.Label(**cnf) + l = tkinter.Label(**cnf) l.grid(row=row, column=3, sticky='ew') row += 1 @@ -743,7 +743,7 @@ class Top_StatsDialog(MfxDialog): top_frame, bottom_frame = self.createFrames(kw) self.createBitmaps(top_frame, kw) - frame = Tkinter.Frame(top_frame) + frame = tkinter.Frame(top_frame) frame.pack(expand=True, fill='both', padx=10, pady=10) frame.columnconfigure(0, weight=1) @@ -751,10 +751,10 @@ class Top_StatsDialog(MfxDialog): gameid in app.stats.games_stats[player] and app.stats.games_stats[player][gameid].time_result.top): - Tkinter.Label(frame, text=_('Minimum')).grid(row=0, column=1) - Tkinter.Label(frame, text=_('Maximum')).grid(row=0, column=2) - Tkinter.Label(frame, text=_('Average')).grid(row=0, column=3) - # Tkinter.Label(frame, text=_('Total')).grid(row=0, column=4) + tkinter.Label(frame, text=_('Minimum')).grid(row=0, column=1) + tkinter.Label(frame, text=_('Maximum')).grid(row=0, column=2) + tkinter.Label(frame, text=_('Average')).grid(row=0, column=3) + # tkinter.Label(frame, text=_('Total')).grid(row=0, column=4) s = app.stats.games_stats[player][gameid] row = 1 @@ -794,17 +794,17 @@ class Top_StatsDialog(MfxDialog): # s.score_casino_result.max, # round(s.score_casino_result.average, 2), )) for l, min, max, avr, tot, top in ll: - Tkinter.Label(frame, text=l).grid(row=row, column=0) - Tkinter.Label(frame, text=str(min)).grid(row=row, column=1) - Tkinter.Label(frame, text=str(max)).grid(row=row, column=2) - Tkinter.Label(frame, text=str(avr)).grid(row=row, column=3) - # Tkinter.Label(frame, text=str(tot)).grid(row=row, column=4) - b = Tkinter.Button(frame, text=TOP_TITLE+' ...', width=10, + tkinter.Label(frame, text=l).grid(row=row, column=0) + tkinter.Label(frame, text=str(min)).grid(row=row, column=1) + tkinter.Label(frame, text=str(max)).grid(row=row, column=2) + tkinter.Label(frame, text=str(avr)).grid(row=row, column=3) + # tkinter.Label(frame, text=str(tot)).grid(row=row, column=4) + b = tkinter.Button(frame, text=TOP_TITLE+' ...', width=10, command=lambda top=top: self.showTop(top)) b.grid(row=row, column=5) row += 1 else: - Tkinter.Label(frame, text=_('No TOP for this game')).pack() + tkinter.Label(frame, text=_('No TOP for this game')).pack() focus = self.createButtons(bottom_frame, kw) self.mainloop(focus, kw.timeout) @@ -846,7 +846,7 @@ class ProgressionDialog(MfxDialog): top_frame, bottom_frame = self.createFrames(kw) self.createBitmaps(top_frame, kw) - frame = Tkinter.Frame(top_frame) + frame = tkinter.Frame(top_frame) frame.pack(expand=True, fill='both', padx=5, pady=10) frame.columnconfigure(0, weight=1) @@ -861,7 +861,7 @@ class ProgressionDialog(MfxDialog): self.won_color = '#00dc28' self.percent_color = 'blue' # create canvas - self.canvas = canvas = Tkinter.Canvas(frame, bg='#dfe8ff', + self.canvas = canvas = tkinter.Canvas(frame, bg='#dfe8ff', highlightthickness=1, highlightbackground='black', width=self.canvas_width, @@ -918,25 +918,25 @@ class ProgressionDialog(MfxDialog): canvas.create_text(x, y, anchor='sw', text=_('% won')) # right frame - right_frame = Tkinter.Frame(frame) + right_frame = tkinter.Frame(frame) right_frame.pack(side='left', fill='x', padx=5) - self.all_games_variable = var = Tkinter.StringVar() + self.all_games_variable = var = tkinter.StringVar() var.set('all') - b = Tkinter.Radiobutton(right_frame, text=_('All games'), + b = tkinter.Radiobutton(right_frame, text=_('All games'), variable=var, value='all', command=self.updateGraph, justify='left', anchor='w' ) b.pack(fill='x', expand=True, padx=3, pady=1) - b = Tkinter.Radiobutton(right_frame, text=_('Current game'), + b = tkinter.Radiobutton(right_frame, text=_('Current game'), variable=var, value='current', command=self.updateGraph, justify='left', anchor='w' ) b.pack(fill='x', expand=True, padx=3, pady=1) - label_frame = Tkinter.LabelFrame(right_frame, text=_('Statistics for')) + label_frame = tkinter.LabelFrame(right_frame, text=_('Statistics for')) label_frame.pack(side='top', fill='x', pady=10) - self.variable = var = Tkinter.StringVar() + self.variable = var = tkinter.StringVar() var.set('week') for v, t in ( ('week', _('Last 7 days')), @@ -944,32 +944,32 @@ class ProgressionDialog(MfxDialog): ('year', _('Last year')), ('all', _('All time')), ): - b = Tkinter.Radiobutton(label_frame, text=t, variable=var, value=v, + b = tkinter.Radiobutton(label_frame, text=t, variable=var, value=v, command=self.updateGraph, justify='left', anchor='w' ) b.pack(fill='x', expand=True, padx=3, pady=1) - label_frame = Tkinter.LabelFrame(right_frame, text=_('Show graphs')) + label_frame = tkinter.LabelFrame(right_frame, text=_('Show graphs')) label_frame.pack(side='top', fill='x') - self.played_graph_var = Tkinter.BooleanVar() + self.played_graph_var = tkinter.BooleanVar() self.played_graph_var.set(True) - b = Tkinter.Checkbutton(label_frame, text=_('Played'), + b = tkinter.Checkbutton(label_frame, text=_('Played'), command=self.updateGraph, variable=self.played_graph_var, justify='left', anchor='w' ) b.pack(fill='x', expand=True, padx=3, pady=1) - self.won_graph_var = Tkinter.BooleanVar() + self.won_graph_var = tkinter.BooleanVar() self.won_graph_var.set(True) - b = Tkinter.Checkbutton(label_frame, text=_('Won'), + b = tkinter.Checkbutton(label_frame, text=_('Won'), command=self.updateGraph, variable=self.won_graph_var, justify='left', anchor='w' ) b.pack(fill='x', expand=True, padx=3, pady=1) - self.percent_graph_var = Tkinter.BooleanVar() + self.percent_graph_var = tkinter.BooleanVar() self.percent_graph_var.set(True) - b = Tkinter.Checkbutton(label_frame, text=_('% won'), + b = tkinter.Checkbutton(label_frame, text=_('% won'), command=self.updateGraph, variable=self.percent_graph_var, justify='left', anchor='w' diff --git a/pysollib/tk/tktree.py b/pysollib/tk/tktree.py index 2f34d0f2..a08993e2 100644 --- a/pysollib/tk/tktree.py +++ b/pysollib/tk/tktree.py @@ -23,7 +23,7 @@ # imports import os -import Tkinter +from six.moves import tkinter # Toolkit imports from pysollib.ui.tktile.tkutil import bind @@ -106,7 +106,7 @@ class MfxTreeBaseNode: try: # _tkinter.TclError: unknown option "-fill" ??? canvas.itemconfig(self.textrect_id, fill=bg) - except Tkinter.TclError: + except tkinter.TclError: pass elif self.selected: b = canvas.bbox(self.text_id) @@ -279,7 +279,7 @@ class MfxTreeInCanvas(MfxScrolledCanvas): # draw try: lx, ly, nx, ny = node.draw(nx, ny, None, None) - except Tkinter.TclError: + except tkinter.TclError: # FIXME: Tk bug ??? raise # set scroll region @@ -401,7 +401,7 @@ class DirectoryBrowser(MfxTreeInCanvas): if __name__ == "__main__": - tk = Tkinter.Tk() + tk = tkinter.Tk() if os.name == "nt": app = DirectoryBrowser(tk, ("c:\\", "c:\\windows")) else: diff --git a/pysollib/tk/tkwidget.py b/pysollib/tk/tkwidget.py index 56bd0d65..d2afdb41 100644 --- a/pysollib/tk/tkwidget.py +++ b/pysollib/tk/tkwidget.py @@ -34,7 +34,7 @@ __all__ = ['MfxDialog', # imports import sys import time -import Tkinter +from six.moves import tkinter import tkFont import traceback @@ -84,7 +84,7 @@ class MfxDialog: # ex. _ToplevelDialog setTransient(self.top, self.parent) try: self.top.grab_set() - except Tkinter.TclError: + except tkinter.TclError: if traceback: traceback.print_exc() pass @@ -171,26 +171,26 @@ class MfxDialog: # ex. _ToplevelDialog return kw def createFrames(self, kw): - bottom_frame = Tkinter.Frame(self.top) + bottom_frame = tkinter.Frame(self.top) bottom_frame.pack(side='bottom', fill='both', expand=False, ipadx=3, ipady=3) if kw.separator: - separator = Tkinter.Frame( + separator = tkinter.Frame( self.top, relief="sunken", height=2, width=2, borderwidth=1) separator.pack(side='bottom', fill='x') - top_frame = Tkinter.Frame(self.top) + top_frame = tkinter.Frame(self.top) top_frame.pack(side='top', fill='both', expand=True) return top_frame, bottom_frame def createBitmaps(self, frame, kw): if kw.bitmap: # in ("error", "info", "question", "warning") img = self.img.get(kw.bitmap) - b = Tkinter.Label(frame, image=img) + b = tkinter.Label(frame, image=img) b.pack(side=kw.bitmap_side, padx=kw.bitmap_padx, pady=kw.bitmap_pady) elif kw.image: - b = Tkinter.Label(frame, image=kw.image) + b = tkinter.Label(frame, image=kw.image) b.pack(side=kw.image_side, padx=kw.image_padx, pady=kw.image_pady) def createButtons(self, frame, kw): @@ -230,10 +230,10 @@ class MfxDialog: # ex. _ToplevelDialog accel_indx = s.find('&') s = s.replace('&', '') if button < 0: - b = Tkinter.Button(frame, text=s, state="disabled") + b = tkinter.Button(frame, text=s, state="disabled") button = xbutton else: - b = Tkinter.Button( + b = tkinter.Button( frame, text=s, default="normal", command=(lambda self=self, button=button: self.mDone(button))) @@ -277,7 +277,7 @@ class MfxMessageDialog(MfxDialog): self.createBitmaps(top_frame, kw) # self.button = kw.default - msg = Tkinter.Label(top_frame, text=kw.text, justify=kw.justify, + msg = tkinter.Label(top_frame, text=kw.text, justify=kw.justify, width=kw.width) msg.pack(fill='both', expand=True, padx=kw.padx, pady=kw.pady) # @@ -318,15 +318,15 @@ class PysolAboutDialog(MfxMessageDialog): self.createBitmaps(top_frame, kw) # self.button = kw.default - frame = Tkinter.Frame(top_frame) + frame = tkinter.Frame(top_frame) frame.pack(fill='both', expand=True, padx=kw.padx, pady=kw.pady) - msg = Tkinter.Label(frame, text=kw.text, justify=kw.justify, + msg = tkinter.Label(frame, text=kw.text, justify=kw.justify, width=kw.width) msg.pack(fill='both', expand=True) font = tkFont.Font(parent, app.getFont('default')) font.configure(underline=True) - url_label = Tkinter.Label(frame, text=kw.url, font=font, + url_label = tkinter.Label(frame, text=kw.url, font=font, foreground='blue', cursor='hand2') url_label.pack() url_label.bind('<1>', self._urlClicked) @@ -351,10 +351,10 @@ class MfxSimpleEntry(MfxDialog): # self.value = value if label: - label = Tkinter.Label(top_frame, text=label, takefocus=0) + label = tkinter.Label(top_frame, text=label, takefocus=0) label.pack(pady=5) w = kw.get("e_width", 0) # width in characters - self.var = Tkinter.Entry(top_frame, exportselection=1, width=w) + self.var = tkinter.Entry(top_frame, exportselection=1, width=w) self.var.insert(0, value) self.var.pack(side='top', padx=kw.padx, pady=kw.pady) # @@ -445,7 +445,7 @@ class MfxTooltip: self.timer = None if self.tooltip or not self.text: return - # if isinstance(self.widget, (Tkinter.Button, Tkinter.Checkbutton)): + # if isinstance(self.widget, (tkinter.Button, tkinter.Checkbutton)): # if self.widget["state"] == 'disabled': # return # x = self.widget.winfo_rootx() @@ -453,11 +453,11 @@ class MfxTooltip: y = self.widget.winfo_rooty() + self.widget.winfo_height() x += self.xoffset y += self.yoffset - self.tooltip = Tkinter.Toplevel() + self.tooltip = tkinter.Toplevel() self.tooltip.wm_iconify() self.tooltip.wm_overrideredirect(1) self.tooltip.wm_protocol("WM_DELETE_WINDOW", self.destroy) - self.label = Tkinter.Label(self.tooltip, text=self.text, + self.label = tkinter.Label(self.tooltip, text=self.text, relief=self.relief, justify=self.justify, fg=self.fg, bg=self.bg, bd=1, takefocus=0) self.label.pack(ipadx=1, ipady=1) @@ -559,20 +559,20 @@ class MfxScrolledCanvas: def createFrame(self, kw): width = kw.get("width") height = kw.get("height") - self.frame = Tkinter.Frame(self.parent, width=width, height=height) + self.frame = tkinter.Frame(self.parent, width=width, height=height) def createCanvas(self, kw): bd = kw['bd'] kw['bd'] = 0 relief = kw['relief'] del kw['relief'] - frame = Tkinter.Frame(self.frame, bd=bd, relief=relief) + frame = tkinter.Frame(self.frame, bd=bd, relief=relief) frame.grid(row=0, column=0, sticky="news") self.canvas = MfxCanvas(frame, **kw) self.canvas.pack(expand=True, fill='both') def createHbar(self): - self.hbar = Tkinter.Scrollbar(self.frame, takefocus=0, + self.hbar = tkinter.Scrollbar(self.frame, takefocus=0, orient="horizontal") self.canvas["xscrollcommand"] = self._setHbar self.hbar["command"] = self.canvas.xview @@ -580,7 +580,7 @@ class MfxScrolledCanvas: self.hbar.grid_remove() def createVbar(self): - self.vbar = Tkinter.Scrollbar(self.frame, takefocus=0) + self.vbar = tkinter.Scrollbar(self.frame, takefocus=0) self.canvas["yscrollcommand"] = self._setVbar self.vbar["command"] = self.canvas.yview self.vbar.grid(row=0, column=1, sticky="ns") @@ -704,9 +704,9 @@ class StackDesc: text = stack.getHelp()+'\n'+stack.getBaseCard() text = text.strip() if text: - frame = Tkinter.Frame(self.canvas) + frame = tkinter.Frame(self.canvas) self.frame = frame - label = Tkinter.Message(frame, font=font, text=text, + label = tkinter.Message(frame, font=font, text=text, width=cardw-8, relief='solid', fg='#000000', bg='#ffffe0', bd=1) label.pack() diff --git a/pysollib/tk/toolbar.py b/pysollib/tk/toolbar.py index 6d807910..c7b129e0 100644 --- a/pysollib/tk/toolbar.py +++ b/pysollib/tk/toolbar.py @@ -25,7 +25,7 @@ __all__ = ['PysolToolbarTk'] # imports import os -import Tkinter +from six.moves import tkinter # PySol imports from pysollib.mygettext import _, n_ @@ -74,23 +74,23 @@ class AbstractToolbarButton: self.grid_forget() -class ToolbarCheckbutton(AbstractToolbarButton, Tkinter.Checkbutton): +class ToolbarCheckbutton(AbstractToolbarButton, tkinter.Checkbutton): def __init__(self, parent, toolbar, toolbar_name, position, **kwargs): - Tkinter.Checkbutton.__init__(self, parent, kwargs) + tkinter.Checkbutton.__init__(self, parent, kwargs) AbstractToolbarButton.__init__( self, parent, toolbar, toolbar_name, position) -class ToolbarButton(AbstractToolbarButton, Tkinter.Button): +class ToolbarButton(AbstractToolbarButton, tkinter.Button): def __init__(self, parent, toolbar, toolbar_name, position, **kwargs): - Tkinter.Button.__init__(self, parent, kwargs) + tkinter.Button.__init__(self, parent, kwargs) AbstractToolbarButton.__init__( self, parent, toolbar, toolbar_name, position) -class ToolbarSeparator(Tkinter.Frame): +class ToolbarSeparator(tkinter.Frame): def __init__(self, parent, toolbar, position, **kwargs): - Tkinter.Frame.__init__(self, parent, kwargs) + tkinter.Frame.__init__(self, parent, kwargs) self.toolbar = toolbar self.position = position self.visible = False @@ -127,9 +127,9 @@ class ToolbarFlatSeparator(ToolbarSeparator): pass -class ToolbarLabel(Tkinter.Message): +class ToolbarLabel(tkinter.Message): def __init__(self, parent, toolbar, toolbar_name, position, **kwargs): - Tkinter.Message.__init__(self, parent, kwargs) + tkinter.Message.__init__(self, parent, kwargs) self.toolbar = toolbar self.toolbar_name = toolbar_name self.position = position @@ -178,7 +178,7 @@ class PysolToolbarTk: self.orient = 'horizontal' self.button_pad = 2 # - self.frame = Tkinter.Frame(top, relief=TkSettings.toolbar_relief, + self.frame = tkinter.Frame(top, relief=TkSettings.toolbar_relief, bd=TkSettings.toolbar_borderwidth) # for l, f, t in ( @@ -268,7 +268,7 @@ class PysolToolbarTk: if Image: image = ImageTk.PhotoImage(Image.open(file)) else: - image = Tkinter.PhotoImage(file=file) + image = tkinter.PhotoImage(file=file) break return image diff --git a/pysollib/tk/wizarddialog.py b/pysollib/tk/wizarddialog.py index ef5b76e3..516107b1 100644 --- a/pysollib/tk/wizarddialog.py +++ b/pysollib/tk/wizarddialog.py @@ -26,7 +26,7 @@ __all__ = ['WizardDialog'] # imports import sys -import Tkinter +from six.moves import tkinter from tabpage import TabPageSet # PySol imports @@ -54,7 +54,7 @@ class WizardDialog(MfxDialog): top_frame, bottom_frame = self.createFrames(kw) self.createBitmaps(top_frame, kw) - frame = Tkinter.Frame(top_frame) + frame = tkinter.Frame(top_frame) frame.pack(expand=True, fill='both', padx=10, pady=10) frame.columnconfigure(0, weight=1) @@ -64,17 +64,17 @@ class WizardDialog(MfxDialog): for w in WizardWidgets: if isinstance(w, basestring): notebook.AddPage(w) - frame = Tkinter.Frame(notebook.pages[w]['page']) + frame = tkinter.Frame(notebook.pages[w]['page']) frame.pack(expand=True, fill='both', padx=2, pady=4) frame.columnconfigure(1, weight=1) row = 0 continue - Tkinter.Label(frame, text=w.label).grid(row=row, column=0, padx=2) + tkinter.Label(frame, text=w.label).grid(row=row, column=0, padx=2) if w.widget == 'preset': if w.variable is None: - w.variable = Tkinter.StringVar() + w.variable = tkinter.StringVar() values = [_(v) for v in w.values] default = _(w.default) values.remove(default) @@ -83,32 +83,32 @@ class WizardDialog(MfxDialog): def callback(v, w=w): return self.presetSelected(v, w) - om = Tkinter.OptionMenu(frame, w.variable, + om = tkinter.OptionMenu(frame, w.variable, command=callback, *values) om.grid(row=row, column=1, sticky='ew', padx=2) elif w.widget == 'entry': if w.variable is None: - w.variable = Tkinter.StringVar() - en = Tkinter.Entry(frame, textvariable=w.variable) + w.variable = tkinter.StringVar() + en = tkinter.Entry(frame, textvariable=w.variable) en.grid(row=row, column=1, sticky='ew', padx=2) elif w.widget == 'menu': if w.variable is None: - w.variable = Tkinter.StringVar() + w.variable = tkinter.StringVar() values = [_(v) for v in w.values] - om = Tkinter.OptionMenu(frame, w.variable, *values) + om = tkinter.OptionMenu(frame, w.variable, *values) om.grid(row=row, column=1, sticky='ew', padx=2) elif w.widget == 'spin': if w.variable is None: - w.variable = Tkinter.IntVar() + w.variable = tkinter.IntVar() from_, to = w.values - s = Tkinter.Scale(frame, from_=from_, to=to, resolution=1, + s = tkinter.Scale(frame, from_=from_, to=to, resolution=1, orient='horizontal', length=200, variable=w.variable) s.grid(row=row, column=1, sticky='ew', padx=2) elif w.widget == 'check': if w.variable is None: - w.variable = Tkinter.BooleanVar() - ch = Tkinter.Checkbutton(frame, variable=w.variable, + w.variable = tkinter.BooleanVar() + ch = tkinter.Checkbutton(frame, variable=w.variable, takefocus=False, anchor='w') ch.grid(row=row, column=1, sticky='ew', padx=2, pady=2) diff --git a/pysollib/ui/tktile/colorsdialog.py b/pysollib/ui/tktile/colorsdialog.py index c0abb295..a20b1d8e 100644 --- a/pysollib/ui/tktile/colorsdialog.py +++ b/pysollib/ui/tktile/colorsdialog.py @@ -22,7 +22,7 @@ # --------------------------------------------------------------------------- # imports -import Tkinter +from six.moves import tkinter from tkColorChooser import askcolor # PySol imports @@ -55,21 +55,21 @@ class BaseColorsDialog: frame.pack(expand=True, fill='both', padx=5, pady=10) frame.columnconfigure(0, weight=1) - self.text_var = Tkinter.StringVar() + self.text_var = tkinter.StringVar() self.text_var.set(app.opt.colors['text']) - self.piles_var = Tkinter.StringVar() + self.piles_var = tkinter.StringVar() self.piles_var.set(app.opt.colors['piles']) - self.cards_1_var = Tkinter.StringVar() + self.cards_1_var = tkinter.StringVar() self.cards_1_var.set(app.opt.colors['cards_1']) - self.cards_2_var = Tkinter.StringVar() + self.cards_2_var = tkinter.StringVar() self.cards_2_var.set(app.opt.colors['cards_2']) - self.samerank_1_var = Tkinter.StringVar() + self.samerank_1_var = tkinter.StringVar() self.samerank_1_var.set(app.opt.colors['samerank_1']) - self.samerank_2_var = Tkinter.StringVar() + self.samerank_2_var = tkinter.StringVar() self.samerank_2_var.set(app.opt.colors['samerank_2']) - self.hintarrow_var = Tkinter.StringVar() + self.hintarrow_var = tkinter.StringVar() self.hintarrow_var.set(app.opt.colors['hintarrow']) - self.not_matching_var = Tkinter.StringVar() + self.not_matching_var = tkinter.StringVar() self.not_matching_var.set(app.opt.colors['not_matching']) # row = 0 @@ -86,7 +86,7 @@ class BaseColorsDialog: self._calcLabel()( frame, text=title, anchor='w',).grid( row=row, column=0, sticky='we') - l = Tkinter.Label(frame, width=10, height=2, + l = tkinter.Label(frame, width=10, height=2, bg=var.get(), textvariable=var) l.grid(row=row, column=1, padx=5) b = self._calcButton()( diff --git a/pysollib/ui/tktile/edittextdialog.py b/pysollib/ui/tktile/edittextdialog.py index 432e8ce4..b1976967 100644 --- a/pysollib/ui/tktile/edittextdialog.py +++ b/pysollib/ui/tktile/edittextdialog.py @@ -1,4 +1,4 @@ -import Tkinter +from six.moves import tkinter from pysollib.mygettext import _ from pysollib.mfxutil import KwStruct @@ -12,7 +12,7 @@ class BaseEditTextDialog: top_frame, bottom_frame = self.createFrames(kw) self.createBitmaps(top_frame, kw) # - self.text_w = Tkinter.Text(top_frame, bd=1, relief="sunken", + self.text_w = tkinter.Text(top_frame, bd=1, relief="sunken", wrap="word", width=64, height=16) self.text_w.pack(side='left', fill="both", expand=True) # self.text_w.pack(side='top', padx=kw.padx, pady=kw.pady) diff --git a/pysollib/ui/tktile/findcarddialog.py b/pysollib/ui/tktile/findcarddialog.py index e97acb88..4265f527 100644 --- a/pysollib/ui/tktile/findcarddialog.py +++ b/pysollib/ui/tktile/findcarddialog.py @@ -28,7 +28,7 @@ __all__ = ['create_find_card_dialog', # imports import os -import Tkinter +from six.moves import tkinter # PySol imports from pysollib.mygettext import _ @@ -50,11 +50,11 @@ LARGE_EMBLEMS_SIZE = (38, 34) SMALL_EMBLEMS_SIZE = (31, 21) -class FindCardDialog(Tkinter.Toplevel): +class FindCardDialog(tkinter.Toplevel): CARD_IMAGES = {} # key: (rank, suit) def __init__(self, parent, game, dir, size='large'): - Tkinter.Toplevel.__init__(self) + tkinter.Toplevel.__init__(self) title = TITLE + ' - ' + _('Find card') self.title(title) self.wm_resizable(False, False) @@ -201,7 +201,7 @@ class FindCardDialog(Tkinter.Toplevel): if self.highlight_items: for i in self.highlight_items: i.delete() - Tkinter.Toplevel.destroy(self) + tkinter.Toplevel.destroy(self) find_card_dialog = None diff --git a/pysollib/ui/tktile/menubar.py b/pysollib/ui/tktile/menubar.py index f5b4b0e5..01f76bdf 100644 --- a/pysollib/ui/tktile/menubar.py +++ b/pysollib/ui/tktile/menubar.py @@ -3,7 +3,7 @@ import os import re import sys -import Tkinter +from six.moves import tkinter import tkFileDialog from pysollib.mfxutil import Struct, kwdefault @@ -73,14 +73,14 @@ def createToolbarMenu(menubar, menu): # * # ************************************************************************ -class MfxMenubar(Tkinter.Menu): +class MfxMenubar(tkinter.Menu): addPath = None def __init__(self, master, **kw): self.name = kw["name"] tearoff = 0 self.n = kw["tearoff"] = int(kw.get("tearoff", tearoff)) - Tkinter.Menu.__init__(self, master, **kw) + tkinter.Menu.__init__(self, master, **kw) def labeltoname(self, label): # print label, type(label) @@ -104,7 +104,7 @@ class MfxMenubar(Tkinter.Menu): if name and self.addPath: path = str(self._w) + "." + name self.addPath(path, self, self.n, cnf.get("menu")) - Tkinter.Menu.add(self, itemType, cnf) + tkinter.Menu.add(self, itemType, cnf) self.n = self.n + 1 @@ -152,54 +152,54 @@ class PysolMenubarTkCommon: def _createTkOpt(self): # structure to convert menu-options to Toolkit variables self.tkopt = Struct( - gameid=Tkinter.IntVar(), - gameid_popular=Tkinter.IntVar(), - comment=Tkinter.BooleanVar(), - autofaceup=Tkinter.BooleanVar(), - autodrop=Tkinter.BooleanVar(), - autodeal=Tkinter.BooleanVar(), - quickplay=Tkinter.BooleanVar(), - undo=Tkinter.BooleanVar(), - bookmarks=Tkinter.BooleanVar(), - hint=Tkinter.BooleanVar(), - shuffle=Tkinter.BooleanVar(), - highlight_piles=Tkinter.BooleanVar(), - highlight_cards=Tkinter.BooleanVar(), - highlight_samerank=Tkinter.BooleanVar(), - highlight_not_matching=Tkinter.BooleanVar(), - mahjongg_show_removed=Tkinter.BooleanVar(), - shisen_show_hint=Tkinter.BooleanVar(), - sound=Tkinter.BooleanVar(), - auto_scale=Tkinter.BooleanVar(), - cardback=Tkinter.IntVar(), - tabletile=Tkinter.IntVar(), - animations=Tkinter.IntVar(), - redeal_animation=Tkinter.BooleanVar(), - win_animation=Tkinter.BooleanVar(), - shadow=Tkinter.BooleanVar(), - shade=Tkinter.BooleanVar(), - shade_filled_stacks=Tkinter.BooleanVar(), - shrink_face_down=Tkinter.BooleanVar(), - toolbar=Tkinter.IntVar(), - toolbar_style=Tkinter.StringVar(), - toolbar_relief=Tkinter.StringVar(), - toolbar_compound=Tkinter.StringVar(), - toolbar_size=Tkinter.IntVar(), - statusbar=Tkinter.BooleanVar(), - num_cards=Tkinter.BooleanVar(), - helpbar=Tkinter.BooleanVar(), - save_games_geometry=Tkinter.BooleanVar(), - splashscreen=Tkinter.BooleanVar(), - demo_logo=Tkinter.BooleanVar(), - mouse_type=Tkinter.StringVar(), - mouse_undo=Tkinter.BooleanVar(), - negative_bottom=Tkinter.BooleanVar(), - pause=Tkinter.BooleanVar(), - theme=Tkinter.StringVar(), + gameid=tkinter.IntVar(), + gameid_popular=tkinter.IntVar(), + comment=tkinter.BooleanVar(), + autofaceup=tkinter.BooleanVar(), + autodrop=tkinter.BooleanVar(), + autodeal=tkinter.BooleanVar(), + quickplay=tkinter.BooleanVar(), + undo=tkinter.BooleanVar(), + bookmarks=tkinter.BooleanVar(), + hint=tkinter.BooleanVar(), + shuffle=tkinter.BooleanVar(), + highlight_piles=tkinter.BooleanVar(), + highlight_cards=tkinter.BooleanVar(), + highlight_samerank=tkinter.BooleanVar(), + highlight_not_matching=tkinter.BooleanVar(), + mahjongg_show_removed=tkinter.BooleanVar(), + shisen_show_hint=tkinter.BooleanVar(), + sound=tkinter.BooleanVar(), + auto_scale=tkinter.BooleanVar(), + cardback=tkinter.IntVar(), + tabletile=tkinter.IntVar(), + animations=tkinter.IntVar(), + redeal_animation=tkinter.BooleanVar(), + win_animation=tkinter.BooleanVar(), + shadow=tkinter.BooleanVar(), + shade=tkinter.BooleanVar(), + shade_filled_stacks=tkinter.BooleanVar(), + shrink_face_down=tkinter.BooleanVar(), + toolbar=tkinter.IntVar(), + toolbar_style=tkinter.StringVar(), + toolbar_relief=tkinter.StringVar(), + toolbar_compound=tkinter.StringVar(), + toolbar_size=tkinter.IntVar(), + statusbar=tkinter.BooleanVar(), + num_cards=tkinter.BooleanVar(), + helpbar=tkinter.BooleanVar(), + save_games_geometry=tkinter.BooleanVar(), + splashscreen=tkinter.BooleanVar(), + demo_logo=tkinter.BooleanVar(), + mouse_type=tkinter.StringVar(), + mouse_undo=tkinter.BooleanVar(), + negative_bottom=tkinter.BooleanVar(), + pause=tkinter.BooleanVar(), + theme=tkinter.StringVar(), toolbar_vars={}, ) for w in TOOLBAR_BUTTONS: - self.tkopt.toolbar_vars[w] = Tkinter.BooleanVar() + self.tkopt.toolbar_vars[w] = tkinter.BooleanVar() def _setOptions(self): tkopt, opt = self.tkopt, self.app.opt diff --git a/pysollib/ui/tktile/solverdialog.py b/pysollib/ui/tktile/solverdialog.py index dcbd2f1d..9c3c10dc 100644 --- a/pysollib/ui/tktile/solverdialog.py +++ b/pysollib/ui/tktile/solverdialog.py @@ -1,4 +1,4 @@ -import Tkinter +from six.moves import tkinter from pysollib.mygettext import _ from pysollib.ui.tktile.tkconst import EVENT_HANDLED @@ -48,18 +48,18 @@ class BaseSolverDialog: # row += 1 - self.max_iters_var = Tkinter.IntVar() + self.max_iters_var = tkinter.IntVar() self.max_iters_var.set(10e4) self._calcToolkit().Label( frame, text=_('Max iterations:'), anchor='w').grid( row=row, column=0, sticky='ew', padx=2, pady=2) - spin = Tkinter.Spinbox(frame, bg='white', from_=1000, to=10e6, + spin = tkinter.Spinbox(frame, bg='white', from_=1000, to=10e6, increment=1000, textvariable=self.max_iters_var) spin.grid(row=row, column=1, sticky='w', padx=2, pady=2) # row += 1 - self.progress_var = Tkinter.BooleanVar() + self.progress_var = tkinter.BooleanVar() self.progress_var.set(True) w = self._createShowProgressButton(frame) w.grid(row=row, column=0, columnspan=2, sticky='ew', padx=2, pady=2) diff --git a/pysollib/ui/tktile/tkcanvas.py b/pysollib/ui/tktile/tkcanvas.py index c6dc5238..1919a46a 100644 --- a/pysollib/ui/tktile/tkcanvas.py +++ b/pysollib/ui/tktile/tkcanvas.py @@ -29,7 +29,7 @@ __all__ = ['MfxCanvasGroup', 'MfxCanvas'] # imports -import Tkinter +from six.moves import tkinter import Canvas # PySol imports @@ -129,9 +129,9 @@ class MfxCanvasText(Canvas.CanvasText): # * canvas # ************************************************************************ -class MfxCanvas(Tkinter.Canvas): +class MfxCanvas(tkinter.Canvas): def __init__(self, *args, **kw): - Tkinter.Canvas.__init__(self, *args, **kw) + tkinter.Canvas.__init__(self, *args, **kw) self.preview = 0 self.busy = False # this is also used by lib-tk/Canvas.py @@ -219,11 +219,11 @@ class MfxCanvas(Tkinter.Canvas): # def _x_create(self, itemType, *args, **kw): - return Tkinter.Canvas._create(self, itemType, args, kw) + return tkinter.Canvas._create(self, itemType, args, kw) def _create(self, itemType, args, kw): # print "_create:", itemType, args, kw - id = Tkinter.Canvas._create(self, itemType, args, kw) + id = tkinter.Canvas._create(self, itemType, args, kw) if self.__tops: self.tk.call(self._w, "lower", id, self.__tops[0]) return id @@ -340,7 +340,7 @@ class MfxCanvas(Tkinter.Canvas): try: if image and isinstance(image, str): image = loadImage(file=image) - except Tkinter.TclError: + except tkinter.TclError: return 0 if len(self.__tops) == 1 and image is self.__tops[0]: return 1 @@ -391,7 +391,7 @@ class MfxCanvas(Tkinter.Canvas): return funcid def _substitute(self, *args): - e = Tkinter.Event() + e = tkinter.Event() try: # Tk changed behavior in 8.4.2, returning "??" rather more often. e.x = int(args[0]) diff --git a/pysollib/ui/tktile/tkconst.py b/pysollib/ui/tktile/tkconst.py index c4bdb490..cbfa3a7b 100644 --- a/pysollib/ui/tktile/tkconst.py +++ b/pysollib/ui/tktile/tkconst.py @@ -39,7 +39,7 @@ __all__ = ['EVENT_HANDLED', ] # imports -import Tkinter +from six.moves import tkinter from pysollib.mygettext import n_ @@ -54,23 +54,23 @@ CURSOR_DRAG = "hand1" CURSOR_WATCH = "watch" CURSOR_DOWN_ARROW = 'sb_down_arrow' -ANCHOR_CENTER = Tkinter.CENTER -ANCHOR_N = Tkinter.N -ANCHOR_NW = Tkinter.NW -ANCHOR_NE = Tkinter.NE -ANCHOR_S = Tkinter.S -ANCHOR_SW = Tkinter.SW -ANCHOR_SE = Tkinter.SE -ANCHOR_W = Tkinter.W -ANCHOR_E = Tkinter.E +ANCHOR_CENTER = tkinter.CENTER +ANCHOR_N = tkinter.N +ANCHOR_NW = tkinter.NW +ANCHOR_NE = tkinter.NE +ANCHOR_S = tkinter.S +ANCHOR_SW = tkinter.SW +ANCHOR_SE = tkinter.SE +ANCHOR_W = tkinter.W +ANCHOR_E = tkinter.E COMPOUNDS = ( - # (Tkinter.BOTTOM, 'bottom'), - # (Tkinter.CENTER, 'center'), - # (Tkinter.RIGHT, 'right'), - (Tkinter.NONE, n_('Icons only')), - (Tkinter.TOP, n_('Text below icons')), - (Tkinter.LEFT, n_('Text beside icons')), + # (tkinter.BOTTOM, 'bottom'), + # (tkinter.CENTER, 'center'), + # (tkinter.RIGHT, 'right'), + (tkinter.NONE, n_('Icons only')), + (tkinter.TOP, n_('Text below icons')), + (tkinter.LEFT, n_('Text beside icons')), ('text', n_('Text only')), ) diff --git a/pysollib/ui/tktile/tkhtml.py b/pysollib/ui/tktile/tkhtml.py index f7270082..bfb6deba 100644 --- a/pysollib/ui/tktile/tkhtml.py +++ b/pysollib/ui/tktile/tkhtml.py @@ -24,7 +24,7 @@ import os import htmllib import formatter -import Tkinter +from six.moves import tkinter from pysollib.ui.tktile.tkutil import bind, unbind_destroy from pysollib.mygettext import _ @@ -289,7 +289,7 @@ class Base_HTMLViewer: def display(self, url, add=1, relpath=1, xview=0, yview=0): # for some reason we have to stop the PySol demo - # (is this a multithread problem with Tkinter ?) + # (is this a multithread problem with tkinter ?) if self.app and self.app.game: self.app.game.stopDemo() # self.app.game._cancelDrag() @@ -425,7 +425,7 @@ to open the following URL: if fn in self.images: return self.images[fn] try: - img = Tkinter.PhotoImage(master=self.parent, file=fn) + img = tkinter.PhotoImage(master=self.parent, file=fn) except: img = None self.images[fn] = img diff --git a/pysollib/ui/tktile/tkutil.py b/pysollib/ui/tktile/tkutil.py index 2c54a48b..220d1384 100644 --- a/pysollib/ui/tktile/tkutil.py +++ b/pysollib/ui/tktile/tkutil.py @@ -47,7 +47,7 @@ __all__ = ['wm_withdraw', # imports import re -import Tkinter +from six.moves import tkinter from tkFont import Font # PySol imports @@ -82,7 +82,7 @@ def wm_get_geometry(window): g = window.wm_geometry() m = __wm_get_geometry_re.search(g) if not m: - raise Tkinter.TclError("invalid geometry "+str(g)) + raise tkinter.TclError("invalid geometry "+str(g)) l = map(int, m.groups()) if window.wm_state() == "zoomed": # workaround as Tk returns the "unzoomed" origin @@ -120,7 +120,7 @@ def makeToplevel(parent, title=None): # # This is a shortcut for a Toplevel() instantiation plus calls to # set the title and icon name of the window. - window = Tkinter.Toplevel(parent) # , class_=TITLE) + window = tkinter.Toplevel(parent) # , class_=TITLE) # window.wm_group(parent) # window.wm_command("") if WIN_SYSTEM == "x11": @@ -135,7 +135,7 @@ def makeToplevel(parent, title=None): def make_help_toplevel(app, title=None): # Create an independent Toplevel window. from pysollib.winsystems import init_root_window - window = Tkinter.Tk(className=TITLE) + window = tkinter.Tk(className=TITLE) init_root_window(window, app) return window @@ -198,7 +198,7 @@ def __getWidgetXY(widget, parent, relx=None, rely=None, # ************************************************************************ -# * bind wrapper - Tkinter doesn't properly delete all bindings +# * bind wrapper - tkinter doesn't properly delete all bindings # ************************************************************************ __mfx_bindings = {} @@ -235,7 +235,7 @@ def unbind_destroy(widget): # widget.deletecommand(funcid) else: widget.unbind(sequence, funcid) - except Tkinter.TclError: + except tkinter.TclError: pass del __mfx_bindings[k] # for k in __mfx_bindings.keys(): print __mfx_bindings[k] @@ -243,7 +243,7 @@ def unbind_destroy(widget): # ************************************************************************ -# * timer wrapper - Tkinter doesn't properly delete all commands +# * timer wrapper - tkinter doesn't properly delete all commands # ************************************************************************ def after(widget, ms, func, *args): @@ -261,7 +261,7 @@ def after_cancel(t): t[2].after_cancel(t[0]) try: t[2].deletecommand(t[1]) - except Tkinter.TclError: + except tkinter.TclError: pass @@ -311,8 +311,8 @@ def makeImage(file=None, data=None, dither=None, alpha=None): return im # fromstring(mode, size, data, decoder_name='raw', *args) else: - return Tkinter.PhotoImage(data=data) - return Tkinter.PhotoImage(**kw) + return tkinter.PhotoImage(data=data) + return tkinter.PhotoImage(**kw) loadImage = makeImage @@ -323,7 +323,7 @@ def copyImage(image, x, y, width, height): if isinstance(image, PIL_Image): return ImageTk.PhotoImage( image._pil_image.crop((x, y, x+width, y+height))) - dest = Tkinter.PhotoImage(width=width, height=height) + dest = tkinter.PhotoImage(width=width, height=height) assert dest.width() == width assert dest.height() == height dest.blank() @@ -366,7 +366,7 @@ def fillImage(image, fill, outline=None): def createImage(width, height, fill, outline=None): - image = Tkinter.PhotoImage(width=width, height=height) + image = tkinter.PhotoImage(width=width, height=height) assert image.width() == width assert image.height() == height image.blank() diff --git a/pysollib/ui/tktile/tkwrap.py b/pysollib/ui/tktile/tkwrap.py index ab51e9f5..9f312acc 100644 --- a/pysollib/ui/tktile/tkwrap.py +++ b/pysollib/ui/tktile/tkwrap.py @@ -25,9 +25,9 @@ __all__ = ['TclError', 'MfxRoot'] # imports -import Tkinter +from six.moves import tkinter from pysollib.ui.tktile.tkconst import EVENT_PROPAGATE -TclError = Tkinter.TclError +TclError = tkinter.TclError # PySol imports @@ -37,13 +37,13 @@ TclError = Tkinter.TclError # * Required so that a Game will get properly destroyed. # ************************************************************************ -class MfxRoot(Tkinter.Tk): +class MfxRoot(tkinter.Tk): def __init__(self, **kw): - Tkinter.Tk.__init__(self, **kw) + tkinter.Tk.__init__(self, **kw) self.app = None self.wm_protocol('WM_DELETE_WINDOW', self.wmDeleteWindow) # for interruptible sleep - # self.sleep_var = Tkinter.IntVar(self) + # self.sleep_var = tkinter.IntVar(self) # self.sleep_var.set(0) self.sleep_var = 0 self.after_id = None @@ -78,7 +78,7 @@ class MfxRoot(Tkinter.Tk): def setCursor(self, cursor): if 0: # FIXME: this causes ugly resizes ! - Tkinter.Tk.config(self, cursor=cursor) + tkinter.Tk.config(self, cursor=cursor) elif 0: # and this is even worse # print self.children @@ -138,7 +138,7 @@ class MfxRoot(Tkinter.Tk): # def update(self): - Tkinter.Tk.update(self) + tkinter.Tk.update(self) def wmDeleteWindow(self): if self.app and self.app.menubar: diff --git a/scripts/cardset_viewer.py b/scripts/cardset_viewer.py index 803e6dcf..ddf55ceb 100755 --- a/scripts/cardset_viewer.py +++ b/scripts/cardset_viewer.py @@ -6,10 +6,7 @@ import sys import os from glob import glob from math import sqrt, sin, cos, pi -from Tkinter import BOTH, Button, Frame, PhotoImage, NW, Text, Toplevel, X, YES -from Tkinter import RIGHT, Tk, Listbox, NS, END, Scrollbar, Canvas, NSEW -from Tkinter import HORIZONTAL, Label, EW, IntVar, StringVar, LEFT, Checkbutton -from Tkinter import OptionMenu +from six.moves import tkinter try: from PIL import Image, ImageTk except ImportError: @@ -136,9 +133,9 @@ def show_cardset(*args): else: zoom_label.config(text='') - image = ImageTk.PhotoImage(im) + image = ImageTk.tkinter.PhotoImage(im) else: - image = PhotoImage(file=f) + image = tkinter.PhotoImage(file=f) tk_images.append(image) ff = os.path.split(f)[1] if pf is None: @@ -150,7 +147,7 @@ def show_cardset(*args): y += image.height()+10 else: x += image.width()+10 - canvas.create_image(x, y, image=image, anchor=NW) + canvas.create_image(x, y, image=image, anchor=tkinter.NW) # canvas.create_rectangle(x, y, x+image.width(), y+image.height()) width = max(width, x) height = max(height, y) @@ -186,81 +183,83 @@ def show_info(*args): cs_name = list_box.get(list_box.curselection()) cs = cardsets_dict[cs_name] fn = os.path.join(cs.dir, 'COPYRIGHT') - top = Toplevel() - text = Text(top) + top = tkinter.Toplevel() + text = tkinter.Text(top) text.insert('insert', open(fn).read()) - text.pack(expand=YES, fill=BOTH) - b_frame = Frame(top) - b_frame.pack(fill=X) - button = Button(b_frame, text='Close', command=top.destroy) - button.pack(side=RIGHT) + text.pack(expand=tkinter.YES, fill=tkinter.BOTH) + b_frame = tkinter.Frame(top) + b_frame.pack(fill=tkinter.X) + button = tkinter.Button(b_frame, text='Close', command=top.destroy) + button.pack(side=tkinter.RIGHT) def create_widgets(): global list_box, canvas, label, zoom_label # - root = Tk() + root = tkinter.Tk() # - list_box = Listbox(root, exportselection=False) - list_box.grid(row=0, column=0, rowspan=2, sticky=NS) + list_box = tkinter.Listbox(root, exportselection=False) + list_box.grid(row=0, column=0, rowspan=2, sticky=tkinter.NS) cardsets_list = list(cardsets_dict) cardsets_list.sort() for cs in cardsets_list: - list_box.insert(END, cs) + list_box.insert(tkinter.END, cs) list_box.bind('<>', show_cardset) # - sb = Scrollbar(root) - sb.grid(row=0, column=1, rowspan=2, sticky=NS) + sb = tkinter.Scrollbar(root) + sb.grid(row=0, column=1, rowspan=2, sticky=tkinter.NS) list_box.config(yscrollcommand=sb.set) sb.config(command=list_box.yview) # - canvas = Canvas(root, bg='#5eab6b') - canvas.grid(row=0, column=2, sticky=NSEW) + canvas = tkinter.Canvas(root, bg='#5eab6b') + canvas.grid(row=0, column=2, sticky=tkinter.NSEW) canvas.bind('<4>', lambda e: canvas.yview_scroll(-5, 'unit')) canvas.bind('<5>', lambda e: canvas.yview_scroll(5, 'unit')) # - sb = Scrollbar(root) - sb.grid(row=0, column=3, sticky=NS) + sb = tkinter.Scrollbar(root) + sb.grid(row=0, column=3, sticky=tkinter.NS) canvas.config(yscrollcommand=sb.set) sb.config(command=canvas.yview) # if True: - sb = Scrollbar(root, orient=HORIZONTAL) - sb.grid(row=1, column=2, sticky=EW) + sb = tkinter.Scrollbar(root, orient=tkinter.HORIZONTAL) + sb.grid(row=1, column=2, sticky=tkinter.EW) canvas.config(xscrollcommand=sb.set) sb.config(command=canvas.xview) # - label = Label(root) + label = tkinter.Label(root) label.grid(row=2, column=0, columnspan=4) # - b_frame = Frame(root) - b_frame.grid(row=3, column=0, columnspan=4, sticky=EW) - button = Button(b_frame, text='Quit', command=root.quit, width=8) - button.pack(side=RIGHT) - button = Button(b_frame, text='Info', command=show_info, width=8) - button.pack(side=RIGHT) + b_frame = tkinter.Frame(root) + b_frame.grid(row=3, column=0, columnspan=4, sticky=tkinter.EW) + button = tkinter.Button(b_frame, text='Quit', command=root.quit, width=8) + button.pack(side=tkinter.RIGHT) + button = tkinter.Button(b_frame, text='Info', command=show_info, width=8) + button.pack(side=tkinter.RIGHT) if Image: global rotate_var, filter_var - rotate_var = IntVar(root) - filter_var = StringVar(root) - button = Button(b_frame, text=' + ', command=zoom_in) - button.pack(side=LEFT) - button = Button(b_frame, text=' - ', command=zoom_out) - button.pack(side=LEFT) - button = Button(b_frame, text=' = ', command=zoom_cancel) - button.pack(side=LEFT) - button = Checkbutton(b_frame, text='Rotate', indicatoron=0, - selectcolor=b_frame['bg'], width=8, - variable=rotate_var, command=show_cardset) - button.pack(side=LEFT, fill='y') - om = OptionMenu(b_frame, filter_var, - 'NEAREST', 'BILINEAR', 'BICUBIC', 'ANTIALIAS', - command=show_cardset) + rotate_var = tkinter.IntVar(root) + filter_var = tkinter.StringVar(root) + button = tkinter.Button(b_frame, text=' + ', command=zoom_in) + button.pack(side=tkinter.LEFT) + button = tkinter.Button(b_frame, text=' - ', command=zoom_out) + button.pack(side=tkinter.LEFT) + button = tkinter.Button(b_frame, text=' = ', command=zoom_cancel) + button.pack(side=tkinter.LEFT) + button = tkinter.Checkbutton( + b_frame, text='Rotate', indicatoron=0, + selectcolor=b_frame['bg'], width=8, + variable=rotate_var, command=show_cardset) + button.pack(side=tkinter.LEFT, fill='y') + om = tkinter.OptionMenu( + b_frame, filter_var, + 'NEAREST', 'BILINEAR', 'BICUBIC', 'ANTIALIAS', + command=show_cardset) filter_var.set('NEAREST') - om.pack(side=LEFT, fill='y') + om.pack(side=tkinter.LEFT, fill='y') - zoom_label = Label(b_frame) - zoom_label.pack(side=LEFT) + zoom_label = tkinter.Label(b_frame) + zoom_label.pack(side=tkinter.LEFT) # root.columnconfigure(2, weight=1) root.rowconfigure(0, weight=1) diff --git a/setup_osx.py b/setup_osx.py index fe44ee01..c10a148d 100644 --- a/setup_osx.py +++ b/setup_osx.py @@ -6,7 +6,7 @@ Usage: import os import sys import shutil -import Tkinter +from six.moves import tkinter from subprocess import call from setuptools import setup from pysollib.settings import PACKAGE, VERSION @@ -28,7 +28,7 @@ call("./scripts/all_games.py > docs/all_games.html", shell=True) # Use Tile widgets, if they are installed. # http://tktable.sourceforge.net/tile/ -root = Tkinter.Tk() +root = tkinter.Tk() root.withdraw() try: root.tk.call('package', 'require', 'tile', '0.7.8') @@ -39,7 +39,7 @@ else: TCL_EXTENSION_PATH = "/Library/Tcl" finally: root.destroy() - del root, Tkinter + del root, tkinter # Use Freecell Solver, if it is installed. # http://fc-solve.berlios.de/