From e6894094ec7950bf198c8c808358226d882957a9 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Wed, 24 May 2017 17:08:05 +0300 Subject: [PATCH] 2to3 on pysollib/ui/tktile/*.py --- pysollib/ui/tktile/colorsdialog.py | 2 +- pysollib/ui/tktile/gameinfodialog.py | 2 +- pysollib/ui/tktile/menubar.py | 29 ++++++++++++++-------------- pysollib/ui/tktile/tkcanvas.py | 6 +++--- pysollib/ui/tktile/tkhtml.py | 12 ++++++++---- pysollib/ui/tktile/tkutil.py | 2 +- 6 files changed, 29 insertions(+), 24 deletions(-) diff --git a/pysollib/ui/tktile/colorsdialog.py b/pysollib/ui/tktile/colorsdialog.py index a20b1d8e..4ca04858 100644 --- a/pysollib/ui/tktile/colorsdialog.py +++ b/pysollib/ui/tktile/colorsdialog.py @@ -23,7 +23,7 @@ # imports from six.moves import tkinter -from tkColorChooser import askcolor +from six.moves.tkinter_colorchooser import askcolor # PySol imports from pysollib.mygettext import _ diff --git a/pysollib/ui/tktile/gameinfodialog.py b/pysollib/ui/tktile/gameinfodialog.py index b1d545f3..89d4cae0 100644 --- a/pysollib/ui/tktile/gameinfodialog.py +++ b/pysollib/ui/tktile/gameinfodialog.py @@ -146,7 +146,7 @@ class BaseGameInfoDialog: fs[cn] += 1 else: fs[cn] = 1 - t = '\n'.join(['%s (%d)' % (i[0], i[1]) for i in fs.items()]) + t = '\n'.join(['%s (%d)' % (i[0], i[1]) for i in list(fs.items())]) else: t = stacks.__class__.__name__ self._calcToolkit().Label( diff --git a/pysollib/ui/tktile/menubar.py b/pysollib/ui/tktile/menubar.py index 01f76bdf..c45b7f88 100644 --- a/pysollib/ui/tktile/menubar.py +++ b/pysollib/ui/tktile/menubar.py @@ -4,7 +4,7 @@ import re import sys from six.moves import tkinter -import tkFileDialog +from six.moves import tkinter_filedialog from pysollib.mfxutil import Struct, kwdefault from pysollib.mfxutil import Image, USE_PIL @@ -782,7 +782,8 @@ class PysolMenubarTkCommon: def _addSelectGameMenu(self, menu): # games = map(self.app.gdb.get, # self.app.gdb.getGamesIdSortedByShortName()) - games = map(self.app.gdb.get, self.app.gdb.getGamesIdSortedByName()) + games = list(map( + self.app.gdb.get, self.app.gdb.getGamesIdSortedByName())) # games = tuple(games) # menu = MfxMenu(menu, label="Select &game") m = "Ctrl-" @@ -823,7 +824,7 @@ class PysolMenubarTkCommon: if label is None: need_sep = 1 continue - g = filter(select_func, games) + g = list(filter(select_func, games)) if not g: continue if need_sep: @@ -835,13 +836,13 @@ class PysolMenubarTkCommon: def _getNumGames(self, games, select_data): ngames = 0 for label, select_func in select_data: - ngames += len(filter(select_func, games)) + ngames += len(list(filter(select_func, games))) return ngames def _addSelectMahjonggGameSubMenu(self, games, menu, command, variable): def select_func(gi): return gi.si.game_type == GI.GT_MAHJONGG - mahjongg_games = filter(select_func, games) + mahjongg_games = list(filter(select_func, games)) if len(mahjongg_games) == 0: return # @@ -865,7 +866,7 @@ class PysolMenubarTkCommon: games[c].append(gi) else: games[c] = [gi] - games = games.items() + games = list(games.items()) games.sort() g0 = [] c0 = c1 = games[0][0] @@ -882,7 +883,7 @@ class PysolMenubarTkCommon: def _addSelectPopularGameSubMenu(self, games, menu, command, variable): def select_func(gi): return gi.si.game_flags & GI.GT_POPULAR - if len(filter(select_func, games)) == 0: + if len(list(filter(select_func, games))) == 0: return data = (n_("&Popular games"), select_func) self._addSelectGameSubMenu(games, menu, (data, ), @@ -917,7 +918,7 @@ class PysolMenubarTkCommon: def select_func(gi): return gi.si.game_type == GI.GT_CUSTOM - games = filter(select_func, games) + games = list(filter(select_func, games)) self.updateGamesMenu(submenu, games) def _addSelectAllGameSubMenu(self, games, menu, command, variable): @@ -1151,7 +1152,7 @@ class PysolMenubarTkCommon: idir, ifile = "", "" if not idir: idir = self.app.dn.savegames - d = tkFileDialog.Open() + d = tkinter_filedialog.Open() filename = d.show(filetypes=self.FILETYPES, defaultextension=self.DEFAULTEXTENSION, initialdir=idir, initialfile=ifile) @@ -1188,7 +1189,7 @@ Unsupported game for export. if not idir: idir = self.app.dn.savegames # print self.game.filename, ifile - d = tkFileDialog.SaveAs() + d = tkinter_filedialog.SaveAs() filename = d.show(filetypes=self.FILETYPES, defaultextension=self.DEFAULTEXTENSION, initialdir=idir, initialfile=ifile) @@ -1219,7 +1220,7 @@ Unsupported game for export. if not idir: idir = self.app.dn.savegames # print self.game.filename, ifile - d = tkFileDialog.SaveAs() + d = tkinter_filedialog.SaveAs() filename = d.show(filetypes=self.FILETYPES, defaultextension=self.DEFAULTEXTENSION, initialdir=idir, initialfile=ifile) @@ -1633,9 +1634,9 @@ Error while saving game. def select_func(gi): return gi.si.game_type == GI.GT_CUSTOM - games = map(self.app.gdb.get, - self.app.gdb.getGamesIdSortedByName()) - games = filter(select_func, games) + games = list(map(self.app.gdb.get, + self.app.gdb.getGamesIdSortedByName())) + games = list(filter(select_func, games)) self.updateGamesMenu(menu, games) self.tkopt.gameid.set(gameid) diff --git a/pysollib/ui/tktile/tkcanvas.py b/pysollib/ui/tktile/tkcanvas.py index 1919a46a..a2964214 100644 --- a/pysollib/ui/tktile/tkcanvas.py +++ b/pysollib/ui/tktile/tkcanvas.py @@ -264,7 +264,7 @@ class MfxCanvas(tkinter.Canvas): # delete all CanvasItems, but keep the background and top tiles def deleteAllItems(self): self._text_items = [] - for id in self.items.keys(): + for id in list(self.items.keys()): assert id not in self.__tiles # because the tile is created by id unbind_destroy(self.items[id]) self.items[id].delete() @@ -372,11 +372,11 @@ class MfxCanvas(tkinter.Canvas): # def hideAllItems(self): - for item in self.items.values(): + for item in list(self.items.values()): item.config(state='hidden') def showAllItems(self): - for item in self.items.values(): + for item in list(self.items.values()): item.config(state='normal') # diff --git a/pysollib/ui/tktile/tkhtml.py b/pysollib/ui/tktile/tkhtml.py index bfb6deba..b1bcb7c1 100644 --- a/pysollib/ui/tktile/tkhtml.py +++ b/pysollib/ui/tktile/tkhtml.py @@ -255,8 +255,10 @@ class Base_HTMLViewer: if baseurl is None: baseurl = self.url if 0: - import urllib - url = urllib.pathname2url(url) + import urllib.request + import urllib.parse + import urllib.error + url = urllib.request.pathname2url(url) if relpath and self.url: url = urllib.basejoin(baseurl, url) else: @@ -316,8 +318,10 @@ to open the following URL: try: file = None if 0: - import urllib - file = urllib.urlopen(url) + import urllib.request + import urllib.parse + import urllib.error + file = urllib.request.urlopen(url) else: file, url = self.openfile(url) data = file.read() diff --git a/pysollib/ui/tktile/tkutil.py b/pysollib/ui/tktile/tkutil.py index 9e30f46b..5359eecb 100644 --- a/pysollib/ui/tktile/tkutil.py +++ b/pysollib/ui/tktile/tkutil.py @@ -83,7 +83,7 @@ def wm_get_geometry(window): m = __wm_get_geometry_re.search(g) if not m: raise tkinter.TclError("invalid geometry "+str(g)) - l = map(int, m.groups()) + l = list(map(int, m.groups())) if window.wm_state() == "zoomed": # workaround as Tk returns the "unzoomed" origin l[2] = l[3] = 0