Skip to main content

Allows for deferred instantiation of class attributes.

Project description

AttriBox - Python Descriptors the Easy Way

Installation

Install AttriBox easily with pip:

pip install attribox
## Quick Start

Imagine having nested custom classes with a requirement of descriptor
protocol implementation. The AI advices you to rethink the design, before
they present you with hundreds of lines of syntactic broccoli. Meanwhile,
your friends are asking you what you are doing with your life. Well, the
AttriBox is here to help!

```python
class SomeGraphics:
  """Imagine you wish to encapsulate a graphical problem in a class. You 
  already have custom classes for the components, but now you wish you 
  had implemented them as descriptors, but of course descriptors are 
  unique to the class and not to the instance. The memories are coming. 
  With them tears begin to form. Never fear! AttriBox is here!"""

  fillColor = AttriBox[RGB](144, 255, 0)
  borderColor = AttriBox[RGB](0, 0, 0)
  centeredDiv = AttriBox[GetRect](69, 420)

The above code implements the class attributes as descriptors. The AttriBox holds on to the class for you, until one of your instances invokes __get__ at which point AttriBox creates a dedicated specimen for just your instance.

A More Ambitious Example

Suppose you are designing a graphical user interface. You wish to use the descriptor protocol to expose the I/O communication directly to the user interface. You see all of those wonderful numbers over there on the robot or whatever, and you see those tempting 'set' methods on your descriptors.

class MainApp(QMainWindow):
  """The basic application window."""

  mainMenuBar = AttriBox[MenuBar](this)  # yes, 'this' is a thing
  mainStatusBar = AttriBox[StatusBar](this)  # fr

  baseLayout = AttriBox[Grid]()
  baseWidget = AttriBox[QWidget]()
  indicator = AttriBox[Indicator]()
  button = AttriBox[Button]()
  slider = AttriBox[Slider]()

  def initUi(self) -> None:
    """Initializes the user interface."""
    self.baseLayout.addWidget(self.indicator, 0, 0)
    self.baseLayout.addWidget(self.button, 1, 0)
    self.baseLayout.addWidget(self.slider, 2, 0)
    self.baseWidget.setLayout(self.baseLayout)
    self.setCentralWidget(self.baseWidget)
    self.setMenuBar(self.mainMenuBar)
    self.setStatusBar(self.mainStatusBar)

  def connectSignals(self) -> None:
    """Connects the signals to the slots."""
    self.button.clicked.connect(self.indicator.toggle)
    self.slider.valueChanged.connect(self.indicator.setValue)
    self.slider.valueChanged.connect(self.mainStatusBar.setValue)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

attribox-0.1.23.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

attribox-0.1.23-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file attribox-0.1.23.tar.gz.

File metadata

  • Download URL: attribox-0.1.23.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for attribox-0.1.23.tar.gz
Algorithm Hash digest
SHA256 60a3d64682ebfd616fa5bf993475c64745607d91e93f89b7c02512f42ff2a115
MD5 f3b3a5c5b1c62c52fe71b3b43a634d24
BLAKE2b-256 5bda99982ca38b2d62833d8f432fe142e51a2b4f479fac29b1663b7c5959e8bc

See more details on using hashes here.

File details

Details for the file attribox-0.1.23-py3-none-any.whl.

File metadata

  • Download URL: attribox-0.1.23-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for attribox-0.1.23-py3-none-any.whl
Algorithm Hash digest
SHA256 6d44dcce7d1ec6591528dffd7198735b754c5fadd20c7e87c40e1ebf6690e346
MD5 b13a03f11e7495892bacaba6e79da440
BLAKE2b-256 a3d5dfe5c4e4840609df16dbb472687d06e4de25284f6ce0e0f8a1aeb07cc744

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page