Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "attrs in functional component" in Python

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'attrs' in functional components in Python. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

"""
	A basic radiobutton (an exclusive checkbox).

	New Attributes
	==============

	  - marked: Boolean: Whether the checkbox is checked or not.
	  - group: String: All RadioButtons with the same group name
	  can only be checked exclusively.

	Data
	====
	The marked status can be read and set via L{distributeData} and L{collectData}
	"""

	ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [BoolAttr('marked'),Attr('group')]

	def __init__(self,group="_no_group_",**kwargs):
		self.real_widget = fife.RadioButton()
		super(RadioButton,self).__init__(**kwargs)

		self.group = group

		# Prepare Data collection framework
		self.accepts_data = True
		self._realGetData = self._isMarked
		self._realSetData = self._setMarked

		# Initial data stuff inherited.

	def _isMarked(self): return self.real_widget.isSelected()
	def _setMarked(self,mark): self.real_widget.setSelected(mark)
posi = widget.position
	   widget.position = (10, posi[1])

	Here they are.

	   - x: Integer: The horizontal part of the position attribute.
	   - y: Integer: The vertical part of the position attribute.
	   - width: Integer: The horizontal part of the size attribute.
	   - height: Integer: The vertical part of the size attribute.

	"""

	ATTRIBUTES = [ Attr('name'), PointAttr('position'),
		PointAttr('min_size'), PointAttr('size'), PointAttr('max_size'),
		ColorAttr('base_color'),ColorAttr('background_color'),ColorAttr('foreground_color'),ColorAttr('selection_color'),
		Attr('style'), Attr('font'),IntAttr('border_size'),Attr('position_technique'),
		UnicodeAttr('helptext')
		]

	DEFAULT_NAME = '__unnamed__'

	HIDE_SHOW_ERROR = """\
		You can only show/hide the top widget of a hierachy.
		Use 'addChild' or 'removeChild' to add/remove labels for example.
		"""

	def __init__(self,parent = None, name = DEFAULT_NAME,
				 size = (-1,-1), min_size=(0,0), max_size=(5000,5000),
				 helptext=u"",
				 style = None, **kwargs):

		assert( hasattr(self,'real_widget') )
# Set X position, leave Y alone
	   widget.x = 10
	   # Same here
	   posi = widget.position
	   widget.position = (10, posi[1])

	Here they are.

	   - x: Integer: The horizontal part of the position attribute.
	   - y: Integer: The vertical part of the position attribute.
	   - width: Integer: The horizontal part of the size attribute.
	   - height: Integer: The vertical part of the size attribute.

	"""

	ATTRIBUTES = [ Attr('name'), PointAttr('position'),
		PointAttr('min_size'), PointAttr('size'), PointAttr('max_size'),
		ColorAttr('base_color'),ColorAttr('background_color'),ColorAttr('foreground_color'),ColorAttr('selection_color'),
		Attr('style'), Attr('font'),IntAttr('border_size'),Attr('position_technique'),
		UnicodeAttr('helptext')
		]

	DEFAULT_NAME = '__unnamed__'

	HIDE_SHOW_ERROR = """\
		You can only show/hide the top widget of a hierachy.
		Use 'addChild' or 'removeChild' to add/remove labels for example.
		"""

	def __init__(self,parent = None, name = DEFAULT_NAME,
				 size = (-1,-1), min_size=(0,0), max_size=(5000,5000),
				 helptext=u"",
class ImageButton(BasicTextWidget):
	"""
	A basic push button with three different images for the up, down and hover state.

	B{Work in progress.}

	New Attributes
	==============

	  - up_image: String: The source location of the Image for the B{unpressed} state.
	  - down_image: String: The source location of the Image for the B{pressed} state.
	  - hover_image: String: The source location of the Image for the B{unpressed hovered} state.
	"""

	ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [Attr('up_image'),Attr('down_image'),PointAttr('offset'),Attr('hover_image')]

	def __init__(self,up_image="",down_image="",hover_image="",offset=(0,0),**kwargs):
		self.real_widget = fife.TwoButton()
		super(ImageButton,self).__init__(**kwargs)

		self.up_image = up_image
		self.down_image = down_image
		self.hover_image = hover_image
		self.offset = offset

	def _setUpImage(self, source):
		if isinstance(source,str):
			self._upimage_source = source
			try:
				self._upimage = get_manager().loadImage(source)
				self.real_widget.setUpImage( self._upimage )
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 )
be position via the position attribute. If you want to use the layout engine,
	you have to use derived containers with vertical or horizontal orientation
	(L{VBox} or L{HBox})

	New Attributes
	==============

	  - padding - Integer: Not used in the Container class istelf, distance between child widgets.
	  - background_image - Set this to a GuiImage or a resource location (simply a filename).
	    The image will be tiled over the background area.
	  - opaque - Boolean: Whether the background should be drawn at all. Set this to False
	    to make the widget transparent.
	  - children - Just contains the list of contained child widgets. Do NOT modify.
	"""

	ATTRIBUTES = Widget.ATTRIBUTES + [ IntAttr('padding'), Attr('background_image'), BoolAttr('opaque'),PointAttr('margins') ]

	def __init__(self,padding=5,margins=(5,5),_real_widget=None, **kwargs):
		self.real_widget = _real_widget or fife.Container()
		self.children = []
		self.margins = margins
		self.padding = padding
		self._background = []
		self._background_image = None
		super(Container,self).__init__(**kwargs)

	def addChild(self, widget):
		widget.parent = self
		self.children.append(widget)
		self.real_widget.add(widget.real_widget)

	def removeChild(self,widget):
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):
ADVERTISED = [Attrs.CradleService]
  # SERVICES = [Attrs.DeviceService]
  SERVICES = [Attrs.CradleService]
  CHARACTERISTICS = [Attrs.AuthenticationCode, Attrs.Command, Attrs.Response, Attrs.ShareMessageReceiver, Attrs.ShareMessageResponse, Attrs.HeartBeat, Attrs.DeviceService, Attrs.PowerLevel]

  UART_SERVICE_UUID = Attrs.CradleService
  TX_CHAR_UUID = Attrs.Command
  RX_CHAR_UUID = Attrs.Response
  pass
class Share2UART (OriginalUART):
  # ADVERTISED = [Attrs.CradleService2]
  # ADVERTISED = [Attrs.VENDOR_UUID]
  ADVERTISED = [Attrs.VENDOR_UUID]
  # SERVICES = [Attrs.DeviceService]
  # SERVICES = [Attrs.CradleService2, Attrs.VENDOR_UUID]
  SERVICES = [Attrs.VENDOR_UUID, Attrs.DeviceService]
  # CHARACTERISTICS = [Attrs.AuthenticationCode2, Attrs.Command2, Attrs.Response2, Attrs.ShareMessageReceiver2, Attrs.ShareMessageResponse2, Attrs.HeartBeat2, Attrs.DeviceService, Attrs.PowerLevel]
  CHARACTERISTICS = [ ]

  HEARTBEAT_UUID = Attrs.HeartBeat2
  # UART_SERVICE_UUID = Attrs.CradleService2
  UART_SERVICE_UUID = Attrs.VENDOR_UUID
  TX_CHAR_UUID = Attrs.ShareMessageReceiver2
  RX_CHAR_UUID = Attrs.ShareMessageResponse2
  SendDataUUID = Attrs.ShareMessageReceiver2
  RcveDataUUID = Attrs.ShareMessageResponse2
  CommandUUID  = Attrs.Command2
  ResponseUUID = Attrs.Response2
  AUTH_UUID    = Attrs.AuthenticationCode2
  def __init__(self, device, **kwds):
      """Initialize UART from provided bluez device."""
      # Find the UART service and characteristics associated with the device.
ADVERTISED = [Attrs.VENDOR_UUID]
  # SERVICES = [Attrs.DeviceService]
  # SERVICES = [Attrs.CradleService2, Attrs.VENDOR_UUID]
  SERVICES = [Attrs.VENDOR_UUID, Attrs.DeviceService]
  # CHARACTERISTICS = [Attrs.AuthenticationCode2, Attrs.Command2, Attrs.Response2, Attrs.ShareMessageReceiver2, Attrs.ShareMessageResponse2, Attrs.HeartBeat2, Attrs.DeviceService, Attrs.PowerLevel]
  CHARACTERISTICS = [ ]

  HEARTBEAT_UUID = Attrs.HeartBeat2
  # UART_SERVICE_UUID = Attrs.CradleService2
  UART_SERVICE_UUID = Attrs.VENDOR_UUID
  TX_CHAR_UUID = Attrs.ShareMessageReceiver2
  RX_CHAR_UUID = Attrs.ShareMessageResponse2
  SendDataUUID = Attrs.ShareMessageReceiver2
  RcveDataUUID = Attrs.ShareMessageResponse2
  CommandUUID  = Attrs.Command2
  ResponseUUID = Attrs.Response2
  AUTH_UUID    = Attrs.AuthenticationCode2
  def __init__(self, device, **kwds):
      """Initialize UART from provided bluez device."""
      # Find the UART service and characteristics associated with the device.
      log = logging.getLogger(__name__)
      self.log = log.getChild('uart')
      self._uart = device.find_service(self.UART_SERVICE_UUID)
      log.info("UART %s", self._uart)
      self._queue = Queue.Queue()
      r = device.is_paired
      self.serial = kwds.pop('SERIAL', None)
      log.info("paired? %s", r)
      if not r:
        log.info("pairing...")
        # help(device._device)
        # help(device._device.Pair)

Is your System Free of Underlying Vulnerabilities?
Find Out Now