Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class ToggleButton(BasicTextWidget):
"""
A basic push button that can be toggled.
Unfortunately a bit of code duplication from ImageButton.
New Attributes
==============
- group: String: The group the button belongs to. Only one button in each group will be toggled at one time.
- toggled: Boolean: Whether the button is toggled or not.
"""
ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [
Attr('up_image'),Attr('down_image'),Attr('hover_image'),
PointAttr('offset'),Attr('group')
]
def __init__(self,up_image="",down_image="",hover_image="",offset=(0,0),group="",**kwargs):
self.real_widget = fife.ToggleButton()
super(ToggleButton,self).__init__(**kwargs)
self.group = group
self.up_image = up_image
self.down_image = down_image
self.hover_image = hover_image
self.offset = offset
def _setGroup(self,group):
self.real_widget.setGroup( group )
text = property(_getText,_setText)
def resizeToContent(self, recurse = True):
self.height = self.real_font.getHeight() + self.margins[1]*2
self.width = self.real_font.getWidth(_text2gui(self.text)) + self.margins[0]*2
class Icon(Widget):
"""
An image icon.
New Attributes
==============
- image: String or GuiImage: The source location of the Image or a direct GuiImage
"""
ATTRIBUTES = Widget.ATTRIBUTES + [Attr('image')]
def __init__(self,image="",**kwargs):
self.real_widget = fife.Icon(None)
super(Icon,self).__init__(**kwargs)
self._source = self._image = None
if image:
self.image = image
def _setImage(self,source):
if isinstance(source,str):
self._source = source
self._image = get_manager().loadImage(source)
elif isinstance(source,fife.GuiImage):
self._source = None
self._image = source
else:
class TextBox(Widget):
"""
An editable B{multiline} text edit widget.
New Attributes
==============
- text: The text in the TextBox.
- filename: A write-only attribute - assigning a filename will cause the widget to load it's text from it.
Data
====
The text can be read and set via L{distributeData} and L{collectData}.
"""
ATTRIBUTES = Widget.ATTRIBUTES + [UnicodeAttr('text'),Attr('filename')]
def __init__(self,text=u"",filename = "", **kwargs):
self.real_widget = fife.TextBox()
self.text = text
self.filename = filename
super(TextBox,self).__init__(**kwargs)
# Prepare Data collection framework
self.accepts_data = True
self.accepts_initial_data = True # Make sense in a way ...
self._realSetInitialData = self._setText
self._realSetData = self._setText
self._realGetData = self._getText
def _getFileName(self): return self._filename
def _loadFromFile(self,filename):