Mercurial > fife-parpg
view clients/pychan_demo/dynamic.py @ 164:5b04a7d3ded6
typo fix
some missing event (de)registrations
ability to capture one event multiple times (instead of only having one slot, we have groups and each group has an own slot, the default group is "default" so we are backward compatible
author | spq@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Wed, 15 Oct 2008 14:57:04 +0000 |
parents | bb9902910067 |
children | 51cc05d862f2 |
line wrap: on
line source
#!/usr/bin/env python # coding: utf-8 import sys, os, re def _jp(path): return os.path.sep.join(path.split('/')) _paths = ('../../engine/swigwrappers/python', '../../engine/extensions') for p in _paths: if p not in sys.path: sys.path.append(_jp(p)) import fife import fifelog import settings import pychan from pychan_test import PyChanExample class Test(object): def __init__(self,button,text1,text2): super(Test,self).__init__() self.button = button self.text1 = text1 self.text2 = text2 self.button.text = text1 def mouseEntered(self, event): print event self.button.text = self.text2 def mouseExited(self, event): print event self.button.text = self.text1 class DynamicExample(PyChanExample): def __init__(self): super(DynamicExample,self).__init__('gui/dynamic.xml') def start(self): self.widget = pychan.loadXML(self.xmlFile) self.l = Test(self.widget.findChild(name="okButton"),"Ok?","Ok!") self.widget.mapEvents({ 'okButton' :self.stop, 'addButton' :self.addLabel, 'okButton/mouseEntered' : self.l.mouseEntered, 'okButton/mouseExited' : self.l.mouseExited }) self.labelBox = self.widget.findChild(name="labelBox") self.widget.show() def addLabel(self): # Code to check text wrapping code in FIFE label = pychan.widgets.Label(max_size=(200,1000),wrap_text=True) label.text = self.widget.collectData('labelText') label.capture(self.removeLabel) self.labelBox.addChild( label ) self.widget.adaptLayout() def removeLabel(self,widget=None): widget._parent.removeChild(widget) self.widget.adaptLayout()