Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
An abstract class for a component in guizero.
"""
super(Component, self).__init__(tk)
self._master = master
self._description = description
self._events = EventManager(self, tk)
self._displayable = displayable
# check the master
if self.master is not None:
if isinstance(master, Container):
self.master._add_child(self)
else:
utils.raise_error("{}\nMaster is not an [App], [Window] or [Box]".format(description))
def _create_waffle(self):
if self._height == "fill" or self._width == "fill":
utils.raise_error("{}\nCannot use 'fill' for width and height.".format(self.description))
self._create_canvas()
self._size_waffle()
self._draw_waffle()
def _load_image(self):
if self._height == "fill" or self._width == "fill":
utils.raise_error("{}\nCannot use 'fill' for width and height.".format(self.description))
if self._image_source is not None:
# stop any animation which might still be playing
if self._image_player:
self._image_player.stop()
# load the image and set its properties
self._image = utils.GUIZeroImage(self._image_source, self._width, self._height)
self._width = self._image.width
self._height = self._image.height
# if its an animation, start it up
if self._image.animation:
self._image_player = utils.AnimationPlayer(self, self._image, self._update_tk_image)
def _load_image(self):
if self._height == "fill" or self._width == "fill":
utils.raise_error("{}\nCannot use 'fill' for width and height when using a image.".format(self.description))
# stop any animation which might still be playing
if self._image_player:
self._image_player.stop()
self._image = utils.GUIZeroImage(self._image_source, self._width, self._height)
# update the tk image
# if its an animation, start it up
if self._image.animation:
self._image_player = utils.AnimationPlayer(self, self._image, self._update_tk_image)
else:
self._update_tk_image(self._image.tk_image)
# set the width and height of the widget to match the image if they are None
super(PushButton, self.__class__).resize(