diff engine/extensions/pychan/widgets.py @ 154:d29593182f40

- modified clicklabel to provide a mouse listener for hover events - modified clicklabel.i to make new methods available for python - added LabelListener to pychan wrapper, as well as two new methods to Label class to set enter / exit callbacks NOTE:
author chewie@33b003aa-7bff-0310-803a-e67f0ece8222
date Sat, 11 Oct 2008 14:13:56 +0000
parents fe7ff4808529
children bb9902910067
line wrap: on
line diff
--- a/engine/extensions/pychan/widgets.py	Sat Oct 11 14:03:01 2008 +0000
+++ b/engine/extensions/pychan/widgets.py	Sat Oct 11 14:13:56 2008 +0000
@@ -1028,11 +1028,31 @@
 		return self._image
 	image = property(_getImage,_setImage)
 
+class LabelListener(fife.ClickLabelListener):
+	""" the listener class for label onMouse events
+	
+	@type	btn:	object
+	@param	btn:	the label widget
+	"""
+	def __init__(self, lbl):
+		fife.ClickLabelListener.__init__(self)
+		self.lbl = lbl
+		self.entercb = None
+		self.exitcb = None
+
+	def mouseEntered(self, lbl):
+		if self.entercb:
+			self.entercb(self.lbl)
+
+	def mouseExited(self, lbl):
+		if self.exitcb:
+			self.exitcb(self.lbl)
+
 class Label(BasicTextWidget):
 	"""
 	A basic label - displaying a string.
 
-	Also allows text wrapping.
+	Also allows text wrapping and onMouse hover callbacks.
 
 	New Attributes
 	==============
@@ -1041,6 +1061,7 @@
 	 Currently to actually see text wrapping you have to explicitly set a max_size with
 	 the desired width of the text, as the layout engine is not capable of deriving
 	 the maximum width from a parent container.
+	 
 	"""
 
 	ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [BoolAttr('wrap_text')]
@@ -1049,7 +1070,9 @@
 		self.real_widget = fife.Label("")
 		self.wrap_text = wrap_text
 		super(Label,self).__init__(**kwargs)
-
+		self.listener = LabelListener(self)
+		self.real_widget.setListener(self.listener)
+		
 	def resizeToContent(self):
 		self.real_widget.setWidth( self.max_size[0] )
 		self.real_widget.adjustSize()
@@ -1061,6 +1084,20 @@
 	def _getTextWrapping(self): self.real_widget.isTextWrapping()
 	wrap_text = property(_getTextWrapping,_setTextWrapping)
 
+	def setEnterCallback(self, cb):
+		"""
+		Callback is called when mouse enters the area of Label
+		callback should have form of function(button)
+		"""
+		self.listener.entercb = cb
+
+	def setExitCallback(self, cb):
+		"""
+		Callback is called when mouse enters the area of Label
+		callback should have form of function(button)
+		"""
+		self.listener.exitcb = cb
+
 class ClickLabel(Label):
 	"""
 	Deprecated - use L{Label} instead.
@@ -1165,17 +1202,17 @@
 		self.width = max(self._upimage.getWidth(),self._downimage.getWidth(),self._hoverimage.getWidth()) + self.margins[1]*2
 
 	def setEnterCallback(self, cb):
-		'''
+		"""
 		Callback is called when mouse enters the area of ImageButton
 		callback should have form of function(button)
-		'''
+		"""
 		self.listener.entercb = cb
 
 	def setExitCallback(self, cb):
-		'''
+		"""
 		Callback is called when mouse enters the area of ImageButton
 		callback should have form of function(button)
-		'''
+		"""
 		self.listener.exitcb = cb