summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1994-06-28 13:48:26 (GMT)
committerGuido van Rossum <guido@python.org>1994-06-28 13:48:26 (GMT)
commit0b0804be77bbeceb5d7b036fe01b4f6222f30a90 (patch)
treeefde173c0c5e7a8b6a2f787c286df8e0f2ecb8b4
parent9beb9327dff9e47feb0f608eee81c2c5db0d7f41 (diff)
downloadcpython-0b0804be77bbeceb5d7b036fe01b4f6222f30a90.zip
cpython-0b0804be77bbeceb5d7b036fe01b4f6222f30a90.tar.gz
cpython-0b0804be77bbeceb5d7b036fe01b4f6222f30a90.tar.bz2
Lots of new stuff
-rw-r--r--Lib/lib-tk/Canvas.py144
-rwxr-xr-xLib/tkinter/Canvas.py144
2 files changed, 204 insertions, 84 deletions
diff --git a/Lib/lib-tk/Canvas.py b/Lib/lib-tk/Canvas.py
index 2af1459..da68195 100644
--- a/Lib/lib-tk/Canvas.py
+++ b/Lib/lib-tk/Canvas.py
@@ -1,22 +1,28 @@
# This module exports classes for the various canvas item types
-from Tkinter import Canvas, _isfunctype
+from Tkinter import Canvas, _isfunctype, _flatten
+
+StringType = type('')
+DictionaryType = type({})
class CanvasItem:
- def __init__(self, canvas, itemType, args = (), cnf={}):
+ def __init__(self, canvas, itemType, *args):
self.canvas = canvas
- self.id = canvas._create(itemType, args + (cnf,))
+ self.id = canvas._create(itemType, args)
+ if not hasattr(canvas, 'items'):
+ canvas.items = {}
+ canvas.items[self.id] = self
def __str__(self):
return str(self.id)
def __repr__(self):
return '<%s, id=%d>' % (self.__class__.__name__, self.id)
- def __del__(self):
+ def delete(self):
+ del self.canvas.items[self.id]
self.canvas.delete(self.id)
- delete = __del__
def __getitem__(self, key):
v = self.canvas.tk.split(self.canvas.tk.call(
self.canvas._w, 'itemconfigure',
- str(self.id), '-' + key))
+ self.id, '-' + key))
return v[4]
def __setitem__(self, key, value):
self.canvas._itemconfig(self.id, {key: value})
@@ -24,10 +30,10 @@ class CanvasItem:
if not hasattr(self, '_keys'):
self._keys = map(lambda x, tk=self.canvas.tk:
tk.splitlist(x)[0][1:],
- self.canvas._splitlist(
- self.canvas.cmd(
+ self.canvas.tk.splitlist(
+ self.canvas._do(
'itemconfigure',
- self.id)))
+ (self.id,))))
return self._keys
def has_key(self, key):
return key in self.keys()
@@ -38,6 +44,8 @@ class CanvasItem:
return (x1, y1), (x2, y2)
def bind(self, sequence=None, command=None):
return self.canvas.bind(self.id, sequence, command)
+ def config(self, cnf=None):
+ return self.canvas.itemconfig(self.id, cnf)
def coords(self, pts = ()):
flat = ()
for x, y in pts: flat = flat + (x, y)
@@ -68,49 +76,101 @@ class CanvasItem:
return self.canvas.type(self.id)
class Arc(CanvasItem):
- def __init__(self, canvas, (x1, y1), (x2, y2), cnf={}):
- CanvasItem.__init__(self, canvas, 'arc',
- (str(x1), str(y1), str(x2), str(y2)), cnf)
+ def __init__(self, canvas, *args):
+ CanvasItem.__init__(self, canvas, 'arc', args)
class Bitmap(CanvasItem):
- def __init__(self, canvas, (x1, y1), cnf={}):
- CanvasItem.__init__(self, canvas, 'bitmap',
- (str(x1), str(y1)), cnf)
+ def __init__(self, canvas, *args):
+ CanvasItem.__init__(self, canvas, 'bitmap', args)
class Line(CanvasItem):
- def __init__(self, canvas, pts, cnf={}):
- pts = reduce(lambda a, b: a+b,
- map(lambda pt: (str(pt[0]), str(pt[1])), pts))
- CanvasItem.__init__(self, canvas, 'line', pts, cnf)
+ def __init__(self, canvas, *args):
+ CanvasItem.__init__(self, canvas, 'line', args)
class Oval(CanvasItem):
- def __init__(self, canvas, (x1, y1), (x2, y2), cnf={}):
- CanvasItem.__init__(self, canvas, 'oval',
- (str(x1), str(y1), str(x2), str(y2)), cnf)
+ def __init__(self, canvas, *args):
+ CanvasItem.__init__(self, canvas, 'oval', args)
class Polygon(CanvasItem):
- def __init__(self, canvas, pts, cnf={}):
- pts = reduce(lambda a, b: a+b,
- map(lambda pt: (str(pt[0]), str(pt[1])), pts))
- CanvasItem.__init__(self, canvas, 'polygon', pts, cnf)
-
-class Curve(Polygon):
- def __init__(self, canvas, pts, cnf={}):
- cnf['smooth'] = 'yes'
- Polygon.__init__(self, canvas, pts, cnf)
+ def __init__(self, canvas, *args):
+ CanvasItem.__init__(self, canvas, 'polygon', args)
class Rectangle(CanvasItem):
- def __init__(self, canvas, (x1, y1), (x2, y2), cnf={}):
- CanvasItem.__init__(self, canvas, 'rectangle',
- (str(x1), str(y1), str(x2), str(y2)), cnf)
+ def __init__(self, canvas, *args):
+ CanvasItem.__init__(self, canvas, 'rectangle', args)
-# XXX Can't use name "Text" since that is already taken by the Text widget...
-class String(CanvasItem):
- def __init__(self, canvas, (x1, y1), cnf={}):
- CanvasItem.__init__(self, canvas, 'text',
- (str(x1), str(y1)), cnf)
+# XXX "Text" is taken by the Text widget...
+class CanvasText(CanvasItem):
+ def __init__(self, canvas, *args):
+ CanvasItem.__init__(self, canvas, 'text', args)
class Window(CanvasItem):
- def __init__(self, canvas, where, cnf={}):
- CanvasItem.__init__(self, canvas, 'window',
- (str(where[0]), str(where[1])), cnf)
+ def __init__(self, canvas, *args):
+ CanvasItem.__init__(self, canvas, 'window', args)
+
+class Group:
+ def __init__(self, canvas, tag=None):
+ if not tag:
+ tag = 'Group%d' % id(self)
+ self.tag = self.id = tag
+ self.canvas = canvas
+ self.canvas.dtag(self.tag)
+ def str(self):
+ return self.tag
+ def _do(self, cmd, *args):
+ return self.canvas._do(cmd, (self.tag,) + _flatten(args))
+ def addtag_above(self, tagOrId):
+ self._do('addtag', 'above', tagOrId)
+ def addtag_all(self):
+ self._do('addtag', 'all')
+ def addtag_below(self, tagOrId):
+ self._do('addtag', 'below', tagOrId)
+ def addtag_closest(self, x, y, halo=None, start=None):
+ self._do('addtag', 'closest', x, y, halo, start)
+ def addtag_enclosed(self, x1, y1, x2, y2):
+ self._do('addtag', 'enclosed', x1, y1, x2, y2)
+ def addtag_overlapping(self, x1, y1, x2, y2):
+ self._do('addtag', 'overlapping', x1, y1, x2, y2)
+ def addtag_withtag(self, tagOrId):
+ self._do('addtag', 'withtag', tagOrId)
+ def bbox(self):
+ return self._getints(self._do('bbox'))
+ def bind(self, sequence=None, command=None): # XXX args?
+ return self._do('bind', sequence, command)
+ def coords(self, *pts):
+ return self._do('coords', pts)
+ def dchars(self, first, last=None):
+ self._do('dchars', first, last)
+ def delete(self):
+ self._do('delete')
+ def dtag(self, tagToDelete=None):
+ self._do('dtag', tagToDelete)
+ def focus(self):
+ self._do('focus')
+ def gettags(self):
+ return self.canvas.tk.splitlist(self._do('gettags', self.tag))
+ def icursor(self, index):
+ return self._do('icursor')
+ def index(self, index):
+ return self.canvas.tk.getint(self._do('index', index))
+ def insert(self, beforeThis, string):
+ self._do('insert', beforeThis, string)
+ def config(self, cnf=None):
+ return self.canvas.itemconfigure(self.tag, cnf)
+ def lower(self, belowThis=None):
+ self._do('lower', belowThis)
+ def move(self, xAmount, yAmount):
+ self._do('move', xAmount, yAmount)
+ def tkraise(self, aboveThis=None):
+ self._do('raise', aboveThis)
+ lift = tkraise
+ def scale(self, xOrigin, yOrigin, xScale, yScale):
+ self._do('scale', xOrigin, yOrigin, xScale, yScale)
+ def select_adjust(self, index):
+ self.canvas._do('select', ('adjust', self.tag, index))
+ def select_from(self, index):
+ self.canvas._do('select', ('from', self.tag, index))
+ def select_to(self, index):
+ self.canvas._do('select', ('to', self.tag, index))
+ def type(self):
+ return self._do('type')
diff --git a/Lib/tkinter/Canvas.py b/Lib/tkinter/Canvas.py
index 2af1459..da68195 100755
--- a/Lib/tkinter/Canvas.py
+++ b/Lib/tkinter/Canvas.py
@@ -1,22 +1,28 @@
# This module exports classes for the various canvas item types
-from Tkinter import Canvas, _isfunctype
+from Tkinter import Canvas, _isfunctype, _flatten
+
+StringType = type('')
+DictionaryType = type({})
class CanvasItem:
- def __init__(self, canvas, itemType, args = (), cnf={}):
+ def __init__(self, canvas, itemType, *args):
self.canvas = canvas
- self.id = canvas._create(itemType, args + (cnf,))
+ self.id = canvas._create(itemType, args)
+ if not hasattr(canvas, 'items'):
+ canvas.items = {}
+ canvas.items[self.id] = self
def __str__(self):
return str(self.id)
def __repr__(self):
return '<%s, id=%d>' % (self.__class__.__name__, self.id)
- def __del__(self):
+ def delete(self):
+ del self.canvas.items[self.id]
self.canvas.delete(self.id)
- delete = __del__
def __getitem__(self, key):
v = self.canvas.tk.split(self.canvas.tk.call(
self.canvas._w, 'itemconfigure',
- str(self.id), '-' + key))
+ self.id, '-' + key))
return v[4]
def __setitem__(self, key, value):
self.canvas._itemconfig(self.id, {key: value})
@@ -24,10 +30,10 @@ class CanvasItem:
if not hasattr(self, '_keys'):
self._keys = map(lambda x, tk=self.canvas.tk:
tk.splitlist(x)[0][1:],
- self.canvas._splitlist(
- self.canvas.cmd(
+ self.canvas.tk.splitlist(
+ self.canvas._do(
'itemconfigure',
- self.id)))
+ (self.id,))))
return self._keys
def has_key(self, key):
return key in self.keys()
@@ -38,6 +44,8 @@ class CanvasItem:
return (x1, y1), (x2, y2)
def bind(self, sequence=None, command=None):
return self.canvas.bind(self.id, sequence, command)
+ def config(self, cnf=None):
+ return self.canvas.itemconfig(self.id, cnf)
def coords(self, pts = ()):
flat = ()
for x, y in pts: flat = flat + (x, y)
@@ -68,49 +76,101 @@ class CanvasItem:
return self.canvas.type(self.id)
class Arc(CanvasItem):
- def __init__(self, canvas, (x1, y1), (x2, y2), cnf={}):
- CanvasItem.__init__(self, canvas, 'arc',
- (str(x1), str(y1), str(x2), str(y2)), cnf)
+ def __init__(self, canvas, *args):
+ CanvasItem.__init__(self, canvas, 'arc', args)
class Bitmap(CanvasItem):
- def __init__(self, canvas, (x1, y1), cnf={}):
- CanvasItem.__init__(self, canvas, 'bitmap',
- (str(x1), str(y1)), cnf)
+ def __init__(self, canvas, *args):
+ CanvasItem.__init__(self, canvas, 'bitmap', args)
class Line(CanvasItem):
- def __init__(self, canvas, pts, cnf={}):
- pts = reduce(lambda a, b: a+b,
- map(lambda pt: (str(pt[0]), str(pt[1])), pts))
- CanvasItem.__init__(self, canvas, 'line', pts, cnf)
+ def __init__(self, canvas, *args):
+ CanvasItem.__init__(self, canvas, 'line', args)
class Oval(CanvasItem):
- def __init__(self, canvas, (x1, y1), (x2, y2), cnf={}):
- CanvasItem.__init__(self, canvas, 'oval',
- (str(x1), str(y1), str(x2), str(y2)), cnf)
+ def __init__(self, canvas, *args):
+ CanvasItem.__init__(self, canvas, 'oval', args)
class Polygon(CanvasItem):
- def __init__(self, canvas, pts, cnf={}):
- pts = reduce(lambda a, b: a+b,
- map(lambda pt: (str(pt[0]), str(pt[1])), pts))
- CanvasItem.__init__(self, canvas, 'polygon', pts, cnf)
-
-class Curve(Polygon):
- def __init__(self, canvas, pts, cnf={}):
- cnf['smooth'] = 'yes'
- Polygon.__init__(self, canvas, pts, cnf)
+ def __init__(self, canvas, *args):
+ CanvasItem.__init__(self, canvas, 'polygon', args)
class Rectangle(CanvasItem):
- def __init__(self, canvas, (x1, y1), (x2, y2), cnf={}):
- CanvasItem.__init__(self, canvas, 'rectangle',
- (str(x1), str(y1), str(x2), str(y2)), cnf)
+ def __init__(self, canvas, *args):
+ CanvasItem.__init__(self, canvas, 'rectangle', args)
-# XXX Can't use name "Text" since that is already taken by the Text widget...
-class String(CanvasItem):
- def __init__(self, canvas, (x1, y1), cnf={}):
- CanvasItem.__init__(self, canvas, 'text',
- (str(x1), str(y1)), cnf)
+# XXX "Text" is taken by the Text widget...
+class CanvasText(CanvasItem):
+ def __init__(self, canvas, *args):
+ CanvasItem.__init__(self, canvas, 'text', args)
class Window(CanvasItem):
- def __init__(self, canvas, where, cnf={}):
- CanvasItem.__init__(self, canvas, 'window',
- (str(where[0]), str(where[1])), cnf)
+ def __init__(self, canvas, *args):
+ CanvasItem.__init__(self, canvas, 'window', args)
+
+class Group:
+ def __init__(self, canvas, tag=None):
+ if not tag:
+ tag = 'Group%d' % id(self)
+ self.tag = self.id = tag
+ self.canvas = canvas
+ self.canvas.dtag(self.tag)
+ def str(self):
+ return self.tag
+ def _do(self, cmd, *args):
+ return self.canvas._do(cmd, (self.tag,) + _flatten(args))
+ def addtag_above(self, tagOrId):
+ self._do('addtag', 'above', tagOrId)
+ def addtag_all(self):
+ self._do('addtag', 'all')
+ def addtag_below(self, tagOrId):
+ self._do('addtag', 'below', tagOrId)
+ def addtag_closest(self, x, y, halo=None, start=None):
+ self._do('addtag', 'closest', x, y, halo, start)
+ def addtag_enclosed(self, x1, y1, x2, y2):
+ self._do('addtag', 'enclosed', x1, y1, x2, y2)
+ def addtag_overlapping(self, x1, y1, x2, y2):
+ self._do('addtag', 'overlapping', x1, y1, x2, y2)
+ def addtag_withtag(self, tagOrId):
+ self._do('addtag', 'withtag', tagOrId)
+ def bbox(self):
+ return self._getints(self._do('bbox'))
+ def bind(self, sequence=None, command=None): # XXX args?
+ return self._do('bind', sequence, command)
+ def coords(self, *pts):
+ return self._do('coords', pts)
+ def dchars(self, first, last=None):
+ self._do('dchars', first, last)
+ def delete(self):
+ self._do('delete')
+ def dtag(self, tagToDelete=None):
+ self._do('dtag', tagToDelete)
+ def focus(self):
+ self._do('focus')
+ def gettags(self):
+ return self.canvas.tk.splitlist(self._do('gettags', self.tag))
+ def icursor(self, index):
+ return self._do('icursor')
+ def index(self, index):
+ return self.canvas.tk.getint(self._do('index', index))
+ def insert(self, beforeThis, string):
+ self._do('insert', beforeThis, string)
+ def config(self, cnf=None):
+ return self.canvas.itemconfigure(self.tag, cnf)
+ def lower(self, belowThis=None):
+ self._do('lower', belowThis)
+ def move(self, xAmount, yAmount):
+ self._do('move', xAmount, yAmount)
+ def tkraise(self, aboveThis=None):
+ self._do('raise', aboveThis)
+ lift = tkraise
+ def scale(self, xOrigin, yOrigin, xScale, yScale):
+ self._do('scale', xOrigin, yOrigin, xScale, yScale)
+ def select_adjust(self, index):
+ self.canvas._do('select', ('adjust', self.tag, index))
+ def select_from(self, index):
+ self.canvas._do('select', ('from', self.tag, index))
+ def select_to(self, index):
+ self.canvas._do('select', ('to', self.tag, index))
+ def type(self):
+ return self._do('type')