summaryrefslogtreecommitdiffstats
path: root/Lib/stdwin
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1991-08-16 13:17:27 (GMT)
committerGuido van Rossum <guido@python.org>1991-08-16 13:17:27 (GMT)
commit9b1bfc88100f91c700a44c07dec2124201e3a6e8 (patch)
treed7f169a52abbedce8444911c7533a781420ff409 /Lib/stdwin
parentce27298640bb05e8398e2c00e56627926caa0c05 (diff)
downloadcpython-9b1bfc88100f91c700a44c07dec2124201e3a6e8.zip
cpython-9b1bfc88100f91c700a44c07dec2124201e3a6e8.tar.gz
cpython-9b1bfc88100f91c700a44c07dec2124201e3a6e8.tar.bz2
minsize --> getminsize.
Added keyboard downcalls. (I mean keyboard focus policy and activate/deactivate)
Diffstat (limited to 'Lib/stdwin')
-rwxr-xr-xLib/stdwin/Split.py73
1 files changed, 64 insertions, 9 deletions
diff --git a/Lib/stdwin/Split.py b/Lib/stdwin/Split.py
index 80e1e74..a5a6542 100755
--- a/Lib/stdwin/Split.py
+++ b/Lib/stdwin/Split.py
@@ -1,11 +1,12 @@
# Generic Split implementation.
# Use as a base class for other splits.
# Derived classes should at least implement the methods that call
-# unimpl() below: minsize(), getbounds() and setbounds().
+# unimpl() below: getminsize(), getbounds() and setbounds().
Error = 'Split.Error' # Exception
import rect
+from stdwinevents import *
class Split():
#
@@ -20,7 +21,8 @@ class Split():
self.keybd_interest = []
self.timer_interest = []
self.altdraw_interest = []
- self.mouse_focus = 0
+ self.mouse_focus = None
+ self.keybd_focus = None
return self
#
# Downcalls from parent to child
@@ -35,10 +37,14 @@ class Split():
del self.timer_interest[:]
del self.altdraw_interest[:]
self.mouse_focus = None
+ self.keybd_focus = None
#
- def minsize(self, m): return unimpl() # Should ask children
- def getbounds(self): return unimpl()
- def setbounds(self, bounds): unimpl() # Should tell children
+ def getminsize(self, (m, (width, height))):
+ return unimpl() # Should ask children
+ def getbounds(self):
+ return unimpl()
+ def setbounds(self, bounds):
+ unimpl() # Should tell children
#
def realize(self):
for child in self.children:
@@ -53,15 +59,41 @@ class Split():
for child in self.altdraw_interest:
child.altdraw(detail)
#
+ # Keyboard focus handling (used internally)
+ # XXX This is not enough if two levels of splits
+ # XXX surround text fields!
+ #
+ def set_keybd_focus(self, child):
+ if self.keybd_focus <> child:
+ if self.keybd_focus:
+ self.keybd_focus.deactivate()
+ self.keybd_focus = None
+ if child:
+ child.activate()
+ self.keybd_focus = child
+ def next_keybd_focus(self):
+ if not self.keybd_interest:
+ self.set_keybd_focus(None)
+ return
+ if self.keybd_focus in self.keybd_interest:
+ i = self.keybd_interest.index(self.keybd_focus)
+ i = (i+1) % len(self.keybd_interest)
+ else:
+ i = 0
+ self.set_keybd_focus(self.keybd_interest[i])
+ #
# Downcalls only made after certain upcalls
#
def mouse_down(self, detail):
if self.mouse_focus:
self.mouse_focus.mouse_down(detail)
+ return
p = detail[0]
for child in self.mouse_interest:
if rect.pointinrect(p, child.getbounds()):
self.mouse_focus = child
+ if child in self.keybd_interest:
+ self.set_keybd_focus(child)
child.mouse_down(detail)
def mouse_move(self, detail):
if self.mouse_focus:
@@ -69,11 +101,26 @@ class Split():
def mouse_up(self, detail):
if self.mouse_focus:
self.mouse_focus.mouse_up(detail)
- self.mouse_focus = 0
+ self.mouse_focus = None
+ #
+ def activate(self):
+ if self.keybd_focus:
+ self.keybd_focus.activate()
+ else:
+ self.next_keybd_focus()
+ def deactivate(self):
+ if self.keybd_focus:
+ self.keybd_focus.deactivate()
#
def keybd(self, type_detail):
- for child in self.keybd_interest:
- child.keybd(type_detail)
+ if not self.keybd_focus:
+ self.set_keybd_focus(self.keybd_interest[0])
+ type, detail = type_detail
+ if type = WE_COMMAND and detail = WC_TAB and \
+ len(self.keybd_interest) > 1:
+ self.next_keybd_focus()
+ return
+ self.keybd_focus.keybd(type_detail)
#
def timer(self):
for child in self.timer_interest:
@@ -98,13 +145,17 @@ class Split():
if child in self.altdraw_interest:
self.altdraw_interest.remove(child)
if child = self.mouse_focus:
- self.mouse_focus = 0
+ self.mouse_focus = None
+ if child = self.keybd_focus:
+ self.keybd_focus = None
#
def need_mouse(self, child):
if child not in self.mouse_interest:
self.mouse_interest.append(child)
self.parent.need_mouse(self)
def no_mouse(self, child):
+ if child = self.mouse_focus:
+ self.mouse_focus = None
if child in self.mouse_interest:
self.mouse_interest.remove(child)
if not self.mouse_interest:
@@ -114,7 +165,11 @@ class Split():
if child not in self.keybd_interest:
self.keybd_interest.append(child)
self.parent.need_keybd(self)
+ if not self.keybd_focus:
+ self.set_keybd_focus(child)
def no_keybd(self, child):
+ if child = self.keybd_focus:
+ self.keybd_focus = None # Don't call child.deactivate()
if child in self.keybd_interest:
self.keybd_interest.remove(child)
if not self.keybd_interest: