Mercurial > fife-parpg
comparison engine/extensions/pychan/widgets.py @ 143:fe7ff4808529
- added guichan slider widget to pychan gui wrapper
- added new attribute class to attrs.py (FloatAttr)
- added demo to pychan demo client
NOTE:
- demo isn't nice yet - but I'll refactor the client anyway
author | chewie@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 07 Oct 2008 02:12:57 +0000 |
parents | 9a1529f9625e |
children | d29593182f40 |
comparison
equal
deleted
inserted
replaced
142:816b17db2bec | 143:fe7ff4808529 |
---|---|
8 """ | 8 """ |
9 | 9 |
10 import fife, pythonize | 10 import fife, pythonize |
11 import tools | 11 import tools |
12 from exceptions import * | 12 from exceptions import * |
13 from attrs import Attr,PointAttr,ColorAttr,BoolAttr,IntAttr | 13 from attrs import Attr,PointAttr,ColorAttr,BoolAttr,IntAttr,FloatAttr |
14 | 14 |
15 def get_manager(): | 15 def get_manager(): |
16 import pychan | 16 import pychan |
17 return pychan.manager | 17 return pychan.manager |
18 | 18 |
1579 return "Spacer(parent.name='%s')" % getattr(self._parent,'name','None') | 1579 return "Spacer(parent.name='%s')" % getattr(self._parent,'name','None') |
1580 | 1580 |
1581 def __repr__(self): | 1581 def __repr__(self): |
1582 return "<Spacer(parent.name='%s') at %x>" % (getattr(self._parent,'name','None'),id(self)) | 1582 return "<Spacer(parent.name='%s') at %x>" % (getattr(self._parent,'name','None'),id(self)) |
1583 | 1583 |
1584 class Slider(Widget): | |
1585 """ A slider widget | |
1586 | |
1587 Use a callback to read out the slider value every time the marker | |
1588 is moved. | |
1589 | |
1590 New Attributes | |
1591 ============== | |
1592 | |
1593 - orientation: 1 = horizontal, 0=vertical | |
1594 - scale_start: float: default 0.0 | |
1595 - scale_end: float: default 1.0 | |
1596 | |
1597 FIXME: | |
1598 - set new attributes for marker & step length, value | |
1599 - update docstrings | |
1600 """ | |
1601 | |
1602 HORIZONTAL = fife.Slider.HORIZONTAL | |
1603 VERTICAL = fife.Slider.VERTICAL | |
1604 | |
1605 ATTRIBUTES = Widget.ATTRIBUTES + [IntAttr('orientation'), FloatAttr('scale_start'), FloatAttr('scale_end')] | |
1606 | |
1607 def __init__(self, scaleStart=0.0, scaleEnd=1.0, orientation=HORIZONTAL, **kwargs): | |
1608 self.real_widget = fife.Slider(scaleStart, scaleEnd) | |
1609 self.orientation = orientation | |
1610 self.setOrientation(self.orientation) | |
1611 super(Slider, self).__init__(**kwargs) | |
1612 | |
1613 def _setScale(self, start, end): | |
1614 """setScale(self, double scaleStart, double scaleEnd)""" | |
1615 if type(start) != float: | |
1616 raise RuntimeError("Slider expects float for start scale") | |
1617 if type(end) != float: | |
1618 raise RuntimeError("Slider expects float for end scale") | |
1619 self.real_widget.setScale(start, end) | |
1620 | |
1621 def getScaleStart(self): | |
1622 """getScaleStart(self) -> double""" | |
1623 return self.real_widget.getScaleStart() | |
1624 | |
1625 def setScaleStart(self, start): | |
1626 """setScaleStart(self, double scaleStart)""" | |
1627 if type(start) != float: | |
1628 raise RuntimeError("Slider expects float for start scale") | |
1629 self.real_widget.setScaleStart(start) | |
1630 scale_start = property(getScaleStart, setScaleStart) | |
1631 | |
1632 def getScaleEnd(self): | |
1633 """getScaleEnd(self) -> double""" | |
1634 return self.real_widget.getScaleEnd() | |
1635 | |
1636 def setScaleEnd(self, end): | |
1637 """setScaleEnd(self, double scaleEnd)""" | |
1638 if type(end) != float: | |
1639 raise RuntimeError("Slider expects float for end scale") | |
1640 self.real_widget.setScaleEnd(end) | |
1641 scale_end = property(getScaleEnd, setScaleEnd) | |
1642 | |
1643 def getValue(self): | |
1644 """getValue(self) -> double""" | |
1645 return self.real_widget.getValue() | |
1646 | |
1647 def setValue(self, value): | |
1648 """setValue(self, double value)""" | |
1649 if type(value) != float: | |
1650 raise RuntimeError("Slider only accepts float values") | |
1651 self.real_widget.setValue(value) | |
1652 | |
1653 def setMarkerLength(self, length): | |
1654 """setMarkerLength(self, int length)""" | |
1655 if type(length) != int: | |
1656 raise RuntimeError("Slider only accepts int for Marker lenght") | |
1657 self.real_widget.setMarkerLength(length) | |
1658 | |
1659 def getMarkerLength(self): | |
1660 """getMarkerLength(self) -> int""" | |
1661 return self.real_widget.getMarkerLength() | |
1662 | |
1663 def setOrientation(self, orientation): | |
1664 """setOrientation(self, Orientation orientation)""" | |
1665 self.real_widget.setOrientation(orientation) | |
1666 | |
1667 def getOrientation(self): | |
1668 """getOrientation(self) -> int""" | |
1669 return self.real_widget.getOrientation() | |
1670 orientation = property(getOrientation, setOrientation) | |
1671 | |
1672 def setStepLength(self, length): | |
1673 """setStepLength(self, double length)""" | |
1674 if type(length) != float: | |
1675 raise RuntimeError("Slider only accepts floats for step length") | |
1676 self.real_widget.setStepLength(length) | |
1677 | |
1678 def getStepLength(self): | |
1679 """getStepLength(self) -> double""" | |
1680 return self.real_widget.getStepLength() | |
1584 | 1681 |
1585 # Global Widget Class registry | 1682 # Global Widget Class registry |
1586 | 1683 |
1587 WIDGETS = { | 1684 WIDGETS = { |
1588 # Containers | 1685 # Containers |
1605 | 1702 |
1606 #Complexer Widgets / Text io | 1703 #Complexer Widgets / Text io |
1607 "TextField" : TextField, | 1704 "TextField" : TextField, |
1608 "TextBox" : TextBox, | 1705 "TextBox" : TextBox, |
1609 "ListBox" : ListBox, | 1706 "ListBox" : ListBox, |
1610 "DropDown" : DropDown | 1707 "DropDown" : DropDown, |
1708 "Slider" : Slider | |
1611 } | 1709 } |
1612 | 1710 |
1613 def registerWidget(cls): | 1711 def registerWidget(cls): |
1614 """ | 1712 """ |
1615 Register a new Widget class for pychan. | 1713 Register a new Widget class for pychan. |