summaryrefslogtreecommitdiff
path: root/uitools/Cursors.py
blob: 647b81c2d707935a11225a0ab43c9edd087345c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python
######################################################################
# This module defines commonly-used CDE cursors.
#
# Mitch Chapman
#---------------------------------------------------------------------
# $Log: Cursors.py,v $
# Revision 1.1  1996/12/01 22:58:54  mchapman
# Initial revision
#
######################################################################

__version__ = "$Revision: 1.1 $"

import Tkinter

# If you're running Solaris >= 2.4, you might want to try these
# cursors:
#busyCursorTuple = ('@/usr/dt/include/bitmaps/xm_hour16',
#		   '/usr/dt/include/bitmaps/xm_hour16m',
#		   'black', 'white')
#noEnterCursorTuple = ('@/usr/dt/include/bitmaps/xm_noenter16',
#		      '/usr/dt/include/bitmaps/xm_noenter16m',
#		      'black', 'white')
#
# Clients can specify any of these cursors for CDE-style cursoring.
#busyCursor = "%s %s %s %s" % busyCursorTuple
#noEnterCursor = "%s %s %s %s" % noEnterCursorTuple

busyCursor = "watch"
noEnterCursor = "X_cursor red white"

# _instances records all instances of Mixin.  (See below.)
_instances = {}

######################################################################
# This mixin class gives the ability to push and pop cursors on a
# widget.
######################################################################
class Mixin:
    ##################################################################
    # Initialize a new instance.
    ##################################################################
    def __init__(self):
	# Register self to participate in cursoring.  Whenever other
	# Mixin instances pushOtherCursors(), self will get a new
	# cursor.
	_instances[self] = self
	self.cursorStack = []

    ##################################################################
    # Destroy self.  (Is this the right way to do this?)
    ##################################################################
    def destroy(self):
        del _instances[self]  # De-register self
	
    ##################################################################
    # Set a cursor on self.
    ##################################################################
    def setCursor(self, cursor):
	# Why not just self.config(cursor=cursor)?
	# I originally wanted to be able to mix this in to class Tk.
	apply(self.tk.call, (self._w, "configure", "-cursor", cursor))

    ##################################################################
    # Push a cursor on self.  (Doesn't affect other CursorMixin
    # instances.)
    ##################################################################
    def pushCursor(self, newCursor):
	self.setCursor(newCursor)
	self.cursorStack.append(newCursor)

    ##################################################################
    # Pop a cursor off self.
    ##################################################################
    def popCursor(self):
	stack = self.cursorStack
	# Pop.
	if stack:
	    del stack[-1]
	# Re-install the old cursor, or else the default cursor.
	if stack:
	    self.setCursor(stack[-1])
	else:
	    self.setCursor('')

    ##################################################################
    # Push a cursor on all other registered instances.
    # This is useful e.g. when displaying a modal dialog, and
    # displaying busy cursors in other dialogs and toplevels.
    ##################################################################
    def pushOtherCursors(self, newCursor):
	for w in _instances.keys():
	    if w != self:
		w.pushCursor(newCursor)

    ##################################################################
    # Pop a cursor from all other registered instances.
    ##################################################################
    def popOtherCursors(self):
	for w in _instances.keys():
	    if w != self:
		w.popCursor()