summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/asymptote/GUI/xasyColorPicker.py
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/asymptote/GUI/xasyColorPicker.py')
-rwxr-xr-xMaster/texmf-dist/asymptote/GUI/xasyColorPicker.py40
1 files changed, 16 insertions, 24 deletions
diff --git a/Master/texmf-dist/asymptote/GUI/xasyColorPicker.py b/Master/texmf-dist/asymptote/GUI/xasyColorPicker.py
index 7415be205c4..217835bdbb0 100755
--- a/Master/texmf-dist/asymptote/GUI/xasyColorPicker.py
+++ b/Master/texmf-dist/asymptote/GUI/xasyColorPicker.py
@@ -10,8 +10,15 @@
#
############################################################################
-from Tkinter import *
-import tkColorChooser
+import sys
+
+if sys.version_info >= (3, 0):
+ from tkinter import *
+ from tkinter import colorchooser
+else:
+ from Tkinter import *
+ import tkColorChooser as colorchooser
+
asyColors = { "black":(0,0,0),
"white":(1,1,1),
"gray":(0.5,0.5,0.5),
@@ -145,28 +152,13 @@ def makeRGBfromTkColor(tkColor):
b /= 255.0
return (r,g,b)
-def RGBreal255((r,g,b)):
+def RGBreal255(rgb):
"""Convert an RGB color from 0-1 to 0-255"""
- a,b,c = (256*r,256*g,256*b)
- if a == 256:
- a = 255
- if b == 256:
- b = 255
- if c == 256:
- c = 255
- return map(int,(a,b,c))
+ return [min(int(256*a),255) for a in rgb]
-def RGB255hex((r,g,b)):
+def RGB255hex(rgb):
"""Make a color in the form #rrggbb in hex from r,g,b in 0-255"""
- rs,gs,bs = map(hex,(r,g,b))
- rs,gs,bs = rs[2:],gs[2:],bs[2:]
- if len(rs) < 2:
- rs += '0'
- if len(gs) < 2:
- gs += '0'
- if len(bs) < 2:
- bs += '0'
- return '#'+rs+gs+bs
+ return "#{}".format("".join(["{:02x}".format(a) for a in rgb]))
class xasyColorDlg(Toplevel):
"""A dialog for choosing an asymptote color. It displays the usual asy presets and allows custom rgb colors"""
@@ -216,8 +208,8 @@ class xasyColorDlg(Toplevel):
"""Close the dialog forcibly"""
self.destroy()
def getCustom(self):
- """Request a custom RGB color using a tkColorChooser"""
- result=tkColorChooser.askcolor(initialcolor=RGB255hex(RGBreal255(self.color)),title="Custom Color",parent=self)
+ """Request a custom RGB color using a colorchooser"""
+ result=colorchooser.askcolor(initialcolor=RGB255hex(RGBreal255(self.color)),title="Custom Color",parent=self)
if result != (None,None):
self.setColor((result[0][0]/255.0,result[0][1]/255.0,result[0][2]/255.0))
def cancel(self):
@@ -235,7 +227,7 @@ class xasyColorDlg(Toplevel):
"""Use this method to prompt for a color. It returns the new color or the old color if the user cancelled the operation.
e.g:
- print xasyColorDlg(Tk()).getColor((1,1,0))
+ print (xasyColorDlg(Tk()).getColor((1,1,0)))
"""
self.setColor(initialColor)
self.oldColor = initialColor