[Python-checkins] r83605 - in python/branches/py3k/Tools/pynche: ChipViewer.py DetailsViewer.py ListViewer.py PyncheWidget.py StripViewer.py Switchboard.py TextViewer.py TypeinViewer.py

georg.brandl python-checkins at python.org
Tue Aug 3 00:08:58 CEST 2010


Author: georg.brandl
Date: Tue Aug  3 00:08:58 2010
New Revision: 83605

Log:
Make the Pynche tool work with Python 3.

Modified:
   python/branches/py3k/Tools/pynche/ChipViewer.py
   python/branches/py3k/Tools/pynche/DetailsViewer.py
   python/branches/py3k/Tools/pynche/ListViewer.py
   python/branches/py3k/Tools/pynche/PyncheWidget.py
   python/branches/py3k/Tools/pynche/StripViewer.py
   python/branches/py3k/Tools/pynche/Switchboard.py
   python/branches/py3k/Tools/pynche/TextViewer.py
   python/branches/py3k/Tools/pynche/TypeinViewer.py

Modified: python/branches/py3k/Tools/pynche/ChipViewer.py
==============================================================================
--- python/branches/py3k/Tools/pynche/ChipViewer.py	(original)
+++ python/branches/py3k/Tools/pynche/ChipViewer.py	Tue Aug  3 00:08:58 2010
@@ -13,7 +13,7 @@
 selected and nearest ChipWidgets.
 """
 
-from Tkinter import *
+from tkinter import *
 import ColorDB
 
 

Modified: python/branches/py3k/Tools/pynche/DetailsViewer.py
==============================================================================
--- python/branches/py3k/Tools/pynche/DetailsViewer.py	(original)
+++ python/branches/py3k/Tools/pynche/DetailsViewer.py	Tue Aug  3 00:08:58 2010
@@ -52,7 +52,7 @@
 Shift + Right == +25
 """
 
-from Tkinter import *
+from tkinter import *
 
 STOP = 'Stop'
 WRAP = 'Wrap Around'

Modified: python/branches/py3k/Tools/pynche/ListViewer.py
==============================================================================
--- python/branches/py3k/Tools/pynche/ListViewer.py	(original)
+++ python/branches/py3k/Tools/pynche/ListViewer.py	Tue Aug  3 00:08:58 2010
@@ -15,7 +15,7 @@
 given name, without selecting the color.
 """
 
-from Tkinter import *
+from tkinter import *
 import ColorDB
 
 ADDTOVIEW = 'Color %List Window...'

Modified: python/branches/py3k/Tools/pynche/PyncheWidget.py
==============================================================================
--- python/branches/py3k/Tools/pynche/PyncheWidget.py	(original)
+++ python/branches/py3k/Tools/pynche/PyncheWidget.py	Tue Aug  3 00:08:58 2010
@@ -6,9 +6,8 @@
 
 import sys
 import os
-from Tkinter import *
-import tkMessageBox
-import tkFileDialog
+from tkinter import *
+from tkinter import messagebox, filedialog
 import ColorDB
 
 # Milliseconds between interrupt checks
@@ -150,7 +149,7 @@
 
     def __popup_about(self, event=None):
         from Main import __version__
-        tkMessageBox.showinfo('About Pynche ' + __version__,
+        messagebox.showinfo('About Pynche ' + __version__,
                               '''\
 Pynche %s
 The PYthonically Natural
@@ -168,7 +167,7 @@
     def __load(self, event=None):
         while 1:
             idir, ifile = os.path.split(self.__sb.colordb().filename())
-            file = tkFileDialog.askopenfilename(
+            file = filedialog.askopenfilename(
                 filetypes=[('Text files', '*.txt'),
                            ('All files', '*'),
                            ],
@@ -180,12 +179,12 @@
             try:
                 colordb = ColorDB.get_colordb(file)
             except IOError:
-                tkMessageBox.showerror('Read error', '''\
+                messagebox.showerror('Read error', '''\
 Could not open file for reading:
 %s''' % file)
                 continue
             if colordb is None:
-                tkMessageBox.showerror('Unrecognized color file type', '''\
+                messagebox.showerror('Unrecognized color file type', '''\
 Unrecognized color file type in file:
 %s''' % file)
                 continue
@@ -249,6 +248,8 @@
 
 
 
+import functools
+ at functools.total_ordering
 class PopupViewer:
     def __init__(self, module, name, switchboard, root):
         self.__m = module
@@ -279,8 +280,11 @@
             self.__sb.add_view(self.__window)
         self.__window.deiconify()
 
-    def __cmp__(self, other):
-        return cmp(self.__menutext, other.__menutext)
+    def __eq__(self, other):
+        return self.__menutext == other.__menutext
+
+    def __lt__(self, other):
+        return self.__menutext < other.__menutext
 
 
 def make_view_popups(switchboard, root, extrapath):

Modified: python/branches/py3k/Tools/pynche/StripViewer.py
==============================================================================
--- python/branches/py3k/Tools/pynche/StripViewer.py	(original)
+++ python/branches/py3k/Tools/pynche/StripViewer.py	Tue Aug  3 00:08:58 2010
@@ -24,7 +24,7 @@
 this can be slow.
 """
 
-from Tkinter import *
+from tkinter import *
 import ColorDB
 
 # Load this script into the Tcl interpreter and call it in
@@ -62,32 +62,32 @@
 # red variations, green+blue = cyan constant
 def constant_red_generator(numchips, red, green, blue):
     seq = constant(numchips)
-    return list(map(None, [red] * numchips, seq, seq))
+    return list(zip([red] * numchips, seq, seq))
 
 # green variations, red+blue = magenta constant
 def constant_green_generator(numchips, red, green, blue):
     seq = constant(numchips)
-    return list(map(None, seq, [green] * numchips, seq))
+    return list(zip(seq, [green] * numchips, seq))
 
 # blue variations, red+green = yellow constant
 def constant_blue_generator(numchips, red, green, blue):
     seq = constant(numchips)
-    return list(map(None, seq, seq, [blue] * numchips))
+    return list(zip(seq, seq, [blue] * numchips))
 
 # red variations, green+blue = cyan constant
 def constant_cyan_generator(numchips, red, green, blue):
     seq = constant(numchips)
-    return list(map(None, seq, [green] * numchips, [blue] * numchips))
+    return list(zip(seq, [green] * numchips, [blue] * numchips))
 
 # green variations, red+blue = magenta constant
 def constant_magenta_generator(numchips, red, green, blue):
     seq = constant(numchips)
-    return list(map(None, [red] * numchips, seq, [blue] * numchips))
+    return list(zip([red] * numchips, seq, [blue] * numchips))
 
 # blue variations, red+green = yellow constant
 def constant_yellow_generator(numchips, red, green, blue):
     seq = constant(numchips)
-    return list(map(None, [red] * numchips, [green] * numchips, seq))
+    return list(zip([red] * numchips, [green] * numchips, seq))
 
 
 
@@ -119,7 +119,7 @@
         return arrow, text
 
     def _x(self):
-        coords = self._canvas.coords(self._TAG)
+        coords = list(self._canvas.coords(self._TAG))
         assert coords
         return coords[0]
 
@@ -151,7 +151,7 @@
         return arrow, text
 
     def _x(self):
-        coords = self._canvas.coords(self._TAG)
+        coords = list(self._canvas.coords(self._TAG))
         assert coords
         return coords[0] + self._ARROWWIDTH
 

Modified: python/branches/py3k/Tools/pynche/Switchboard.py
==============================================================================
--- python/branches/py3k/Tools/pynche/Switchboard.py	(original)
+++ python/branches/py3k/Tools/pynche/Switchboard.py	Tue Aug  3 00:08:58 2010
@@ -42,7 +42,6 @@
 """
 
 import sys
-from types import DictType
 import marshal
 
 
@@ -62,10 +61,11 @@
         if initfile:
             try:
                 try:
-                    fp = open(initfile)
+                    fp = open(initfile, 'rb')
                     self.__optiondb = marshal.load(fp)
-                    if not isinstance(self.__optiondb, DictType):
-                        print('Problem reading options from file:', initfile, file=sys.stderr)
+                    if not isinstance(self.__optiondb, dict):
+                        print('Problem reading options from file:', initfile,
+                              file=sys.stderr)
                         self.__optiondb = {}
                 except (IOError, EOFError, ValueError):
                     pass
@@ -116,7 +116,7 @@
         fp = None
         try:
             try:
-                fp = open(self.__initfile, 'w')
+                fp = open(self.__initfile, 'wb')
             except IOError:
                 print('Cannot write options to file:', \
                       self.__initfile, file=sys.stderr)

Modified: python/branches/py3k/Tools/pynche/TextViewer.py
==============================================================================
--- python/branches/py3k/Tools/pynche/TextViewer.py	(original)
+++ python/branches/py3k/Tools/pynche/TextViewer.py	Tue Aug  3 00:08:58 2010
@@ -15,7 +15,7 @@
 in the text window (which only has a background).
 """
 
-from Tkinter import *
+from tkinter import *
 import ColorDB
 
 ADDTOVIEW = 'Text Window...'

Modified: python/branches/py3k/Tools/pynche/TypeinViewer.py
==============================================================================
--- python/branches/py3k/Tools/pynche/TypeinViewer.py	(original)
+++ python/branches/py3k/Tools/pynche/TypeinViewer.py	Tue Aug  3 00:08:58 2010
@@ -12,7 +12,7 @@
 you must hit Return or Tab to select the color.
 """
 
-from Tkinter import *
+from tkinter import *
 
 
 


More information about the Python-checkins mailing list