Browse Source

Adding a much-needed complete example

Matt Sparks 14 years ago
parent
commit
155b779d73
3 changed files with 50 additions and 1 deletions
  1. 43 0
      alphasign/__init__.py
  2. 5 1
      alphasign/string.py
  3. 2 0
      docs/index.rst

+ 43 - 0
alphasign/__init__.py

@@ -1,3 +1,44 @@
+"""
+Here is a simple example for controlling a Betabrite Prism via USB::
+
+  import time
+  import alphasign
+
+
+  def main():
+    sign = alphasign.USB(alphasign.devices.USB_BETABRITE_PRISM)
+    sign.connect()
+    sign.clear_memory()
+
+    # create logical objects to work with
+    counter_str = alphasign.String(size=14, label="1")
+    counter_txt = alphasign.Text("counter value: %s%s" % (alphasign.colors.RED,
+                                                          counter_str.call()),
+                                 label="A",
+                                 mode=alphasign.modes.HOLD)
+
+    # allocate memory for these objects on the sign
+    sign.allocate((counter_str, counter_txt))
+
+    # tell sign to only display the counter text
+    sign.set_run_sequence((counter_txt,))
+
+    # write objects
+    for obj in (counter_str, counter_txt):
+      self.write(obj)
+
+    # (strictly) monotonically increasing counter
+    counter_value = 0
+    while True:
+      counter_str.data = counter_value
+      sign.write(counter_str)
+      counter_value += 1
+      time.sleep(1)
+
+
+  if __name__ == "__main__":
+    main()
+"""
 import datetime
 import os
 import sys
@@ -22,3 +63,5 @@ import extchars
 import modes
 import positions
 import speeds
+
+

+ 5 - 1
alphasign/string.py

@@ -3,7 +3,11 @@ from packet import Packet
 
 
 class String(object):
-  """Class representing a STRING file."""
+  """Class representing a STRING file.
+
+  :ivar data: string contained within object
+  :ivar label: label of string object
+  """
 
   def __init__(self, data=None, label=None, size=None):
     """

+ 2 - 0
docs/index.rst

@@ -7,6 +7,8 @@ The alphasign package is a Python API for the
 .. automodule:: alphasign
   :members:
 
+The full API is documented with examples in the pages below:
+
 .. toctree::
   :maxdepth: 2