Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bf76ce1

Browse files
committed
Make the Pynche tool work with Python 3.
1 parent 1800934 commit bf76ce1

8 files changed

Lines changed: 32 additions & 28 deletions

File tree

Tools/pynche/ChipViewer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
selected and nearest ChipWidgets.
1414
"""
1515

16-
from Tkinter import *
16+
from tkinter import *
1717
import ColorDB
1818

1919

Tools/pynche/DetailsViewer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
Shift + Right == +25
5353
"""
5454

55-
from Tkinter import *
55+
from tkinter import *
5656

5757
STOP = 'Stop'
5858
WRAP = 'Wrap Around'

Tools/pynche/ListViewer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
given name, without selecting the color.
1616
"""
1717

18-
from Tkinter import *
18+
from tkinter import *
1919
import ColorDB
2020

2121
ADDTOVIEW = 'Color %List Window...'

Tools/pynche/PyncheWidget.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
import sys
88
import os
9-
from Tkinter import *
10-
import tkMessageBox
11-
import tkFileDialog
9+
from tkinter import *
10+
from tkinter import messagebox, filedialog
1211
import ColorDB
1312

1413
# Milliseconds between interrupt checks
@@ -150,7 +149,7 @@ def window(self):
150149

151150
def __popup_about(self, event=None):
152151
from Main import __version__
153-
tkMessageBox.showinfo('About Pynche ' + __version__,
152+
messagebox.showinfo('About Pynche ' + __version__,
154153
'''\
155154
Pynche %s
156155
The PYthonically Natural
@@ -168,7 +167,7 @@ def __popup_usage(self, event=None):
168167
def __load(self, event=None):
169168
while 1:
170169
idir, ifile = os.path.split(self.__sb.colordb().filename())
171-
file = tkFileDialog.askopenfilename(
170+
file = filedialog.askopenfilename(
172171
filetypes=[('Text files', '*.txt'),
173172
('All files', '*'),
174173
],
@@ -180,12 +179,12 @@ def __load(self, event=None):
180179
try:
181180
colordb = ColorDB.get_colordb(file)
182181
except IOError:
183-
tkMessageBox.showerror('Read error', '''\
182+
messagebox.showerror('Read error', '''\
184183
Could not open file for reading:
185184
%s''' % file)
186185
continue
187186
if colordb is None:
188-
tkMessageBox.showerror('Unrecognized color file type', '''\
187+
messagebox.showerror('Unrecognized color file type', '''\
189188
Unrecognized color file type in file:
190189
%s''' % file)
191190
continue
@@ -249,6 +248,8 @@ def deiconify(self):
249248

250249

251250

251+
import functools
252+
@functools.total_ordering
252253
class PopupViewer:
253254
def __init__(self, module, name, switchboard, root):
254255
self.__m = module
@@ -279,8 +280,11 @@ def popup(self, event=None):
279280
self.__sb.add_view(self.__window)
280281
self.__window.deiconify()
281282

282-
def __cmp__(self, other):
283-
return cmp(self.__menutext, other.__menutext)
283+
def __eq__(self, other):
284+
return self.__menutext == other.__menutext
285+
286+
def __lt__(self, other):
287+
return self.__menutext < other.__menutext
284288

285289

286290
def make_view_popups(switchboard, root, extrapath):

Tools/pynche/StripViewer.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
this can be slow.
2525
"""
2626

27-
from Tkinter import *
27+
from tkinter import *
2828
import ColorDB
2929

3030
# Load this script into the Tcl interpreter and call it in
@@ -62,32 +62,32 @@ def constant(numchips):
6262
# red variations, green+blue = cyan constant
6363
def constant_red_generator(numchips, red, green, blue):
6464
seq = constant(numchips)
65-
return list(map(None, [red] * numchips, seq, seq))
65+
return list(zip([red] * numchips, seq, seq))
6666

6767
# green variations, red+blue = magenta constant
6868
def constant_green_generator(numchips, red, green, blue):
6969
seq = constant(numchips)
70-
return list(map(None, seq, [green] * numchips, seq))
70+
return list(zip(seq, [green] * numchips, seq))
7171

7272
# blue variations, red+green = yellow constant
7373
def constant_blue_generator(numchips, red, green, blue):
7474
seq = constant(numchips)
75-
return list(map(None, seq, seq, [blue] * numchips))
75+
return list(zip(seq, seq, [blue] * numchips))
7676

7777
# red variations, green+blue = cyan constant
7878
def constant_cyan_generator(numchips, red, green, blue):
7979
seq = constant(numchips)
80-
return list(map(None, seq, [green] * numchips, [blue] * numchips))
80+
return list(zip(seq, [green] * numchips, [blue] * numchips))
8181

8282
# green variations, red+blue = magenta constant
8383
def constant_magenta_generator(numchips, red, green, blue):
8484
seq = constant(numchips)
85-
return list(map(None, [red] * numchips, seq, [blue] * numchips))
85+
return list(zip([red] * numchips, seq, [blue] * numchips))
8686

8787
# blue variations, red+green = yellow constant
8888
def constant_yellow_generator(numchips, red, green, blue):
8989
seq = constant(numchips)
90-
return list(map(None, [red] * numchips, [green] * numchips, seq))
90+
return list(zip([red] * numchips, [green] * numchips, seq))
9191

9292

9393

@@ -119,7 +119,7 @@ def _create(self, x):
119119
return arrow, text
120120

121121
def _x(self):
122-
coords = self._canvas.coords(self._TAG)
122+
coords = list(self._canvas.coords(self._TAG))
123123
assert coords
124124
return coords[0]
125125

@@ -151,7 +151,7 @@ def _create(self, x):
151151
return arrow, text
152152

153153
def _x(self):
154-
coords = self._canvas.coords(self._TAG)
154+
coords = list(self._canvas.coords(self._TAG))
155155
assert coords
156156
return coords[0] + self._ARROWWIDTH
157157

Tools/pynche/Switchboard.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"""
4343

4444
import sys
45-
from types import DictType
4645
import marshal
4746

4847

@@ -62,10 +61,11 @@ def __init__(self, initfile):
6261
if initfile:
6362
try:
6463
try:
65-
fp = open(initfile)
64+
fp = open(initfile, 'rb')
6665
self.__optiondb = marshal.load(fp)
67-
if not isinstance(self.__optiondb, DictType):
68-
print('Problem reading options from file:', initfile, file=sys.stderr)
66+
if not isinstance(self.__optiondb, dict):
67+
print('Problem reading options from file:', initfile,
68+
file=sys.stderr)
6969
self.__optiondb = {}
7070
except (IOError, EOFError, ValueError):
7171
pass
@@ -116,7 +116,7 @@ def save_views(self):
116116
fp = None
117117
try:
118118
try:
119-
fp = open(self.__initfile, 'w')
119+
fp = open(self.__initfile, 'wb')
120120
except IOError:
121121
print('Cannot write options to file:', \
122122
self.__initfile, file=sys.stderr)

Tools/pynche/TextViewer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
in the text window (which only has a background).
1616
"""
1717

18-
from Tkinter import *
18+
from tkinter import *
1919
import ColorDB
2020

2121
ADDTOVIEW = 'Text Window...'

Tools/pynche/TypeinViewer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
you must hit Return or Tab to select the color.
1313
"""
1414

15-
from Tkinter import *
15+
from tkinter import *
1616

1717

1818

0 commit comments

Comments
 (0)