mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	minsize --> getminsize.
Added keyboard downcalls. (I mean keyboard focus policy and activate/deactivate)
This commit is contained in:
		
							parent
							
								
									ce27298640
								
							
						
					
					
						commit
						9b1bfc8810
					
				
					 2 changed files with 128 additions and 18 deletions
				
			
		| 
						 | 
					@ -1,11 +1,12 @@
 | 
				
			||||||
# Generic Split implementation.
 | 
					# Generic Split implementation.
 | 
				
			||||||
# Use as a base class for other splits.
 | 
					# Use as a base class for other splits.
 | 
				
			||||||
# Derived classes should at least implement the methods that call
 | 
					# 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
 | 
					Error = 'Split.Error'	# Exception
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import rect
 | 
					import rect
 | 
				
			||||||
 | 
					from stdwinevents import *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Split():
 | 
					class Split():
 | 
				
			||||||
	#
 | 
						#
 | 
				
			||||||
| 
						 | 
					@ -20,7 +21,8 @@ def create(self, parent):
 | 
				
			||||||
		self.keybd_interest = []
 | 
							self.keybd_interest = []
 | 
				
			||||||
		self.timer_interest = []
 | 
							self.timer_interest = []
 | 
				
			||||||
		self.altdraw_interest = []
 | 
							self.altdraw_interest = []
 | 
				
			||||||
		self.mouse_focus = 0
 | 
							self.mouse_focus = None
 | 
				
			||||||
 | 
							self.keybd_focus = None
 | 
				
			||||||
		return self
 | 
							return self
 | 
				
			||||||
	#
 | 
						#
 | 
				
			||||||
	# Downcalls from parent to child
 | 
						# Downcalls from parent to child
 | 
				
			||||||
| 
						 | 
					@ -35,10 +37,14 @@ def destroy(self):
 | 
				
			||||||
		del self.timer_interest[:]
 | 
							del self.timer_interest[:]
 | 
				
			||||||
		del self.altdraw_interest[:]
 | 
							del self.altdraw_interest[:]
 | 
				
			||||||
		self.mouse_focus = None
 | 
							self.mouse_focus = None
 | 
				
			||||||
 | 
							self.keybd_focus = None
 | 
				
			||||||
	#
 | 
						#
 | 
				
			||||||
	def minsize(self, m): return unimpl()	# Should ask children
 | 
						def getminsize(self, (m, (width, height))):
 | 
				
			||||||
	def getbounds(self): return unimpl()
 | 
							return unimpl()			# Should ask children
 | 
				
			||||||
	def setbounds(self, bounds): unimpl()	# Should tell children
 | 
						def getbounds(self):
 | 
				
			||||||
 | 
							return unimpl()
 | 
				
			||||||
 | 
						def setbounds(self, bounds):
 | 
				
			||||||
 | 
							unimpl()			# Should tell children
 | 
				
			||||||
	#
 | 
						#
 | 
				
			||||||
	def realize(self):
 | 
						def realize(self):
 | 
				
			||||||
		for child in self.children:
 | 
							for child in self.children:
 | 
				
			||||||
| 
						 | 
					@ -53,15 +59,41 @@ def altdraw(self, detail):
 | 
				
			||||||
		for child in self.altdraw_interest:
 | 
							for child in self.altdraw_interest:
 | 
				
			||||||
			child.altdraw(detail)
 | 
								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
 | 
						# Downcalls only made after certain upcalls
 | 
				
			||||||
	#
 | 
						#
 | 
				
			||||||
	def mouse_down(self, detail):
 | 
						def mouse_down(self, detail):
 | 
				
			||||||
		if self.mouse_focus:
 | 
							if self.mouse_focus:
 | 
				
			||||||
			self.mouse_focus.mouse_down(detail)
 | 
								self.mouse_focus.mouse_down(detail)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
		p = detail[0]
 | 
							p = detail[0]
 | 
				
			||||||
		for child in self.mouse_interest:
 | 
							for child in self.mouse_interest:
 | 
				
			||||||
			if rect.pointinrect(p, child.getbounds()):
 | 
								if rect.pointinrect(p, child.getbounds()):
 | 
				
			||||||
				self.mouse_focus = child
 | 
									self.mouse_focus = child
 | 
				
			||||||
 | 
									if child in self.keybd_interest:
 | 
				
			||||||
 | 
										self.set_keybd_focus(child)
 | 
				
			||||||
				child.mouse_down(detail)
 | 
									child.mouse_down(detail)
 | 
				
			||||||
	def mouse_move(self, detail):
 | 
						def mouse_move(self, detail):
 | 
				
			||||||
		if self.mouse_focus:
 | 
							if self.mouse_focus:
 | 
				
			||||||
| 
						 | 
					@ -69,11 +101,26 @@ def mouse_move(self, detail):
 | 
				
			||||||
	def mouse_up(self, detail):
 | 
						def mouse_up(self, detail):
 | 
				
			||||||
		if self.mouse_focus:
 | 
							if self.mouse_focus:
 | 
				
			||||||
			self.mouse_focus.mouse_up(detail)
 | 
								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):
 | 
						def keybd(self, type_detail):
 | 
				
			||||||
		for child in self.keybd_interest:
 | 
							if not self.keybd_focus:
 | 
				
			||||||
			child.keybd(type_detail)
 | 
								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):
 | 
						def timer(self):
 | 
				
			||||||
		for child in self.timer_interest:
 | 
							for child in self.timer_interest:
 | 
				
			||||||
| 
						 | 
					@ -98,13 +145,17 @@ def delchild(self, child):
 | 
				
			||||||
		if child in self.altdraw_interest:
 | 
							if child in self.altdraw_interest:
 | 
				
			||||||
			self.altdraw_interest.remove(child)
 | 
								self.altdraw_interest.remove(child)
 | 
				
			||||||
		if child = self.mouse_focus:
 | 
							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):
 | 
						def need_mouse(self, child):
 | 
				
			||||||
		if child not in self.mouse_interest:
 | 
							if child not in self.mouse_interest:
 | 
				
			||||||
			self.mouse_interest.append(child)
 | 
								self.mouse_interest.append(child)
 | 
				
			||||||
			self.parent.need_mouse(self)
 | 
								self.parent.need_mouse(self)
 | 
				
			||||||
	def no_mouse(self, child):
 | 
						def no_mouse(self, child):
 | 
				
			||||||
 | 
							if child = self.mouse_focus:
 | 
				
			||||||
 | 
								self.mouse_focus = None
 | 
				
			||||||
		if child in self.mouse_interest:
 | 
							if child in self.mouse_interest:
 | 
				
			||||||
			self.mouse_interest.remove(child)
 | 
								self.mouse_interest.remove(child)
 | 
				
			||||||
			if not self.mouse_interest:
 | 
								if not self.mouse_interest:
 | 
				
			||||||
| 
						 | 
					@ -114,7 +165,11 @@ def need_keybd(self, child):
 | 
				
			||||||
		if child not in self.keybd_interest:
 | 
							if child not in self.keybd_interest:
 | 
				
			||||||
			self.keybd_interest.append(child)
 | 
								self.keybd_interest.append(child)
 | 
				
			||||||
			self.parent.need_keybd(self)
 | 
								self.parent.need_keybd(self)
 | 
				
			||||||
 | 
							if not self.keybd_focus:
 | 
				
			||||||
 | 
								self.set_keybd_focus(child)
 | 
				
			||||||
	def no_keybd(self, 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:
 | 
							if child in self.keybd_interest:
 | 
				
			||||||
			self.keybd_interest.remove(child)
 | 
								self.keybd_interest.remove(child)
 | 
				
			||||||
			if not self.keybd_interest:
 | 
								if not self.keybd_interest:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,11 +1,12 @@
 | 
				
			||||||
# Generic Split implementation.
 | 
					# Generic Split implementation.
 | 
				
			||||||
# Use as a base class for other splits.
 | 
					# Use as a base class for other splits.
 | 
				
			||||||
# Derived classes should at least implement the methods that call
 | 
					# 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
 | 
					Error = 'Split.Error'	# Exception
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import rect
 | 
					import rect
 | 
				
			||||||
 | 
					from stdwinevents import *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Split():
 | 
					class Split():
 | 
				
			||||||
	#
 | 
						#
 | 
				
			||||||
| 
						 | 
					@ -20,7 +21,8 @@ def create(self, parent):
 | 
				
			||||||
		self.keybd_interest = []
 | 
							self.keybd_interest = []
 | 
				
			||||||
		self.timer_interest = []
 | 
							self.timer_interest = []
 | 
				
			||||||
		self.altdraw_interest = []
 | 
							self.altdraw_interest = []
 | 
				
			||||||
		self.mouse_focus = 0
 | 
							self.mouse_focus = None
 | 
				
			||||||
 | 
							self.keybd_focus = None
 | 
				
			||||||
		return self
 | 
							return self
 | 
				
			||||||
	#
 | 
						#
 | 
				
			||||||
	# Downcalls from parent to child
 | 
						# Downcalls from parent to child
 | 
				
			||||||
| 
						 | 
					@ -35,10 +37,14 @@ def destroy(self):
 | 
				
			||||||
		del self.timer_interest[:]
 | 
							del self.timer_interest[:]
 | 
				
			||||||
		del self.altdraw_interest[:]
 | 
							del self.altdraw_interest[:]
 | 
				
			||||||
		self.mouse_focus = None
 | 
							self.mouse_focus = None
 | 
				
			||||||
 | 
							self.keybd_focus = None
 | 
				
			||||||
	#
 | 
						#
 | 
				
			||||||
	def minsize(self, m): return unimpl()	# Should ask children
 | 
						def getminsize(self, (m, (width, height))):
 | 
				
			||||||
	def getbounds(self): return unimpl()
 | 
							return unimpl()			# Should ask children
 | 
				
			||||||
	def setbounds(self, bounds): unimpl()	# Should tell children
 | 
						def getbounds(self):
 | 
				
			||||||
 | 
							return unimpl()
 | 
				
			||||||
 | 
						def setbounds(self, bounds):
 | 
				
			||||||
 | 
							unimpl()			# Should tell children
 | 
				
			||||||
	#
 | 
						#
 | 
				
			||||||
	def realize(self):
 | 
						def realize(self):
 | 
				
			||||||
		for child in self.children:
 | 
							for child in self.children:
 | 
				
			||||||
| 
						 | 
					@ -53,15 +59,41 @@ def altdraw(self, detail):
 | 
				
			||||||
		for child in self.altdraw_interest:
 | 
							for child in self.altdraw_interest:
 | 
				
			||||||
			child.altdraw(detail)
 | 
								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
 | 
						# Downcalls only made after certain upcalls
 | 
				
			||||||
	#
 | 
						#
 | 
				
			||||||
	def mouse_down(self, detail):
 | 
						def mouse_down(self, detail):
 | 
				
			||||||
		if self.mouse_focus:
 | 
							if self.mouse_focus:
 | 
				
			||||||
			self.mouse_focus.mouse_down(detail)
 | 
								self.mouse_focus.mouse_down(detail)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
		p = detail[0]
 | 
							p = detail[0]
 | 
				
			||||||
		for child in self.mouse_interest:
 | 
							for child in self.mouse_interest:
 | 
				
			||||||
			if rect.pointinrect(p, child.getbounds()):
 | 
								if rect.pointinrect(p, child.getbounds()):
 | 
				
			||||||
				self.mouse_focus = child
 | 
									self.mouse_focus = child
 | 
				
			||||||
 | 
									if child in self.keybd_interest:
 | 
				
			||||||
 | 
										self.set_keybd_focus(child)
 | 
				
			||||||
				child.mouse_down(detail)
 | 
									child.mouse_down(detail)
 | 
				
			||||||
	def mouse_move(self, detail):
 | 
						def mouse_move(self, detail):
 | 
				
			||||||
		if self.mouse_focus:
 | 
							if self.mouse_focus:
 | 
				
			||||||
| 
						 | 
					@ -69,11 +101,26 @@ def mouse_move(self, detail):
 | 
				
			||||||
	def mouse_up(self, detail):
 | 
						def mouse_up(self, detail):
 | 
				
			||||||
		if self.mouse_focus:
 | 
							if self.mouse_focus:
 | 
				
			||||||
			self.mouse_focus.mouse_up(detail)
 | 
								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):
 | 
						def keybd(self, type_detail):
 | 
				
			||||||
		for child in self.keybd_interest:
 | 
							if not self.keybd_focus:
 | 
				
			||||||
			child.keybd(type_detail)
 | 
								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):
 | 
						def timer(self):
 | 
				
			||||||
		for child in self.timer_interest:
 | 
							for child in self.timer_interest:
 | 
				
			||||||
| 
						 | 
					@ -98,13 +145,17 @@ def delchild(self, child):
 | 
				
			||||||
		if child in self.altdraw_interest:
 | 
							if child in self.altdraw_interest:
 | 
				
			||||||
			self.altdraw_interest.remove(child)
 | 
								self.altdraw_interest.remove(child)
 | 
				
			||||||
		if child = self.mouse_focus:
 | 
							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):
 | 
						def need_mouse(self, child):
 | 
				
			||||||
		if child not in self.mouse_interest:
 | 
							if child not in self.mouse_interest:
 | 
				
			||||||
			self.mouse_interest.append(child)
 | 
								self.mouse_interest.append(child)
 | 
				
			||||||
			self.parent.need_mouse(self)
 | 
								self.parent.need_mouse(self)
 | 
				
			||||||
	def no_mouse(self, child):
 | 
						def no_mouse(self, child):
 | 
				
			||||||
 | 
							if child = self.mouse_focus:
 | 
				
			||||||
 | 
								self.mouse_focus = None
 | 
				
			||||||
		if child in self.mouse_interest:
 | 
							if child in self.mouse_interest:
 | 
				
			||||||
			self.mouse_interest.remove(child)
 | 
								self.mouse_interest.remove(child)
 | 
				
			||||||
			if not self.mouse_interest:
 | 
								if not self.mouse_interest:
 | 
				
			||||||
| 
						 | 
					@ -114,7 +165,11 @@ def need_keybd(self, child):
 | 
				
			||||||
		if child not in self.keybd_interest:
 | 
							if child not in self.keybd_interest:
 | 
				
			||||||
			self.keybd_interest.append(child)
 | 
								self.keybd_interest.append(child)
 | 
				
			||||||
			self.parent.need_keybd(self)
 | 
								self.parent.need_keybd(self)
 | 
				
			||||||
 | 
							if not self.keybd_focus:
 | 
				
			||||||
 | 
								self.set_keybd_focus(child)
 | 
				
			||||||
	def no_keybd(self, 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:
 | 
							if child in self.keybd_interest:
 | 
				
			||||||
			self.keybd_interest.remove(child)
 | 
								self.keybd_interest.remove(child)
 | 
				
			||||||
			if not self.keybd_interest:
 | 
								if not self.keybd_interest:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue