summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>1998-10-01 13:41:05 (GMT)
committerBarry Warsaw <barry@python.org>1998-10-01 13:41:05 (GMT)
commit85e6965071d76ca8d58e6162d96918277e4c56fe (patch)
treea8768f2a03ef8af3052d1dc0390d66e6679c9cbb /Tools
parentd344165f48aa985d5a65bbc7351599e208bbbfdb (diff)
downloadcpython-85e6965071d76ca8d58e6162d96918277e4c56fe.zip
cpython-85e6965071d76ca8d58e6162d96918277e4c56fe.tar.gz
cpython-85e6965071d76ca8d58e6162d96918277e4c56fe.tar.bz2
Fixed toggle b/w hex and decimal
Diffstat (limited to 'Tools')
-rw-r--r--Tools/pynche/TypeinViewer.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/Tools/pynche/TypeinViewer.py b/Tools/pynche/TypeinViewer.py
index 1608b03..2da25af 100644
--- a/Tools/pynche/TypeinViewer.py
+++ b/Tools/pynche/TypeinViewer.py
@@ -39,9 +39,24 @@ class TypeinViewer:
# Hex/Dec
self.__hex = Checkbutton(self.__frame,
text='Hexadecimal',
- variable=self.__hexp)
+ variable=self.__hexp,
+ command=self.__togglehex)
self.__hex.grid(row=4, column=0, columnspan=2, sticky=W)
+ def __togglehex(self, event=None):
+ rstr = self.__x.get()
+ gstr = self.__y.get()
+ bstr = self.__z.get()
+ if self.__hexp.get():
+ # it was decimal and is now hex
+ apply(self.update_yourself, tuple(map(int, (rstr, gstr, bstr))))
+ else:
+ # it was hex and is now decimal
+ red = string.atoi(rstr, 16)
+ green = string.atoi(gstr, 16)
+ blue = string.atoi(bstr, 16)
+ self.update_yourself(red, green, blue)
+
def __normalize(self, event=None):
ew = event.widget
contents = ew.get()
@@ -55,9 +70,11 @@ class TypeinViewer:
v = string.atoi(contents)
except ValueError:
v = None
- # if value is not legal, delete the last character and ring the bell
+ # if value is not legal, delete the last character inserted and ring
+ # the bell
if v is None or v < 0 or v > 255:
- contents = contents[:-1]
+ i = ew.index(INSERT)
+ contents = contents[:i-1] + contents[i:]
ew.bell()
elif self.__hexp.get():
contents = hex(v)
@@ -86,7 +103,7 @@ class TypeinViewer:
if self.__hexp.get():
redstr, greenstr, bluestr = map(hex, (red, green, blue))
else:
- redstr, greenstr, bluestr = map(int, (red, green, blue))
+ redstr, greenstr, bluestr = red, green, blue
self.__x.delete(0, END)
self.__y.delete(0, END)
self.__z.delete(0, END)