Skip to main content

Widgets for Python programming beginners

Project description

PIHAT Widgets

About

The purpose of this module is to provide a set of programmable visual gadgets designed to make learning programming more fun.

Rather than just creating data and displaying text on the screen you can create traffic light sequences or display number countdown sequences or even create your own color pixelated grid.

The module contains three gadgets

  • LedMatrix
  • TrafficLight
  • LEDCharacter
  • LEDMultiCharacter

Details

All control have to be called from within the scope of a main clause:

 def main():
       # Do something with a pihat control

if __name__ == "__main__":

    main()

Safely creating widgets

When you create a widget you should always call the close() method when you are complete otherwise the widget may continue to display on the screen.

light = TrafficLight()
light.set_state("100")
light.close()

Another way to do the same thing that will automatically close the widget would be to do this instead:

with TrafficLight() as light:
    light.set_state("100")

LedMatrix

Displays an LED grid of lights. The colour of each light can be controlled using an RGB tuple

if __name__ == "__main__":
    import pihat_widget as ph
    import time
    # Create the Matrix with 8 rows and columns at screen pos 5, 5 (x, y)
    matrix = ph.LEDMatrix(rows = 8, cols = 8, origin_x = 5, origin_y = 5)
    matrix.clear() # Clear all pixels
    red_color = 255, 0, 0 # RGB red
    black_color = 0, 0, 0 # RGB Black
    # Set the pixel at (x, y) pos 0, 0 the RGB color red
    matrix.set_pixel(x = 0, y = 0, color =  red_color)
    time.sleep(5) # Sleep for 5 seconds
    matrix.set_pixel(x = 0, y = 0, color =  black_color)
    matrix.set_pixel(x=0, y=1, color=red_color)
    time.sleep(3)
    matrix.close()```

set_pixel(x, y , color)

Sets the color of a pixel. color is an rgb tuple

set_pixels(matrix)

Pass a two dimensional array or rgb color tuples

For a 2 x 2 board the top left pixel would be yellow and the bottom right red. The other pixels would be black

matrix = [ [ (255,255,0), (0, 0, 0) ], [(0, 0, 0), (255,0,0)  ]]
board.set_pixels(matrix)

To simplify the tuple you could also code:

matrix = [ [ (255,255,0), 0 ], [0, 255]]
board.set_pixels(matrix)

set_pixels_color(matrix, color)

Pass a two dimensional array of bit flags and a color parameter.

For a 2 x 2 board the top left pixel would be yellow and the bottom right red. The other pixels would be black

matrix = [ [ 1, 0 ], [0, 1]]
board.set_pixels_color(matrix, (255,0, 0))

TrafficLight

if __name__ == "__main__":
    import pihat_widget as ph
    import time

    light = ph.TrafficLight()
    count =0
    while count<1:
        light.set_state("100")

        time.sleep(5)
        light.set_state("110")
        time.sleep(2.7)
        light.set_state("001")
        time.sleep(5)
        light.set_state("010")
        time.sleep(2.7)
        count+=1
    light.close()

LEDCharacter

Creates a single character segmented numeric display.

Set the number property to display the number

if __name__ == "__main__":
   import pihat_widget as ph
   import time

   c = ph.LEDCharacter(x = 150, y = 150)
   for i in range(10):
       c.Number = i
       time.sleep(0.5)
   time.sleep(3)
   c.close()

LEDMultiCharacter

Creates a multi character segmented numeric display.

Set the number property to display the number

if __name__ == "__main__":
   import pihat_widget as ph
   import time

   c = ph.LEDMultiCharacter(digits = 3, y=120)
   for i in range(105):
       c.Number =i
   c.close()

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

pihat-widget-1.4.1.tar.gz (169.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pihat_widget-1.4.1-py3-none-any.whl (171.2 kB view details)

Uploaded Python 3

File details

Details for the file pihat-widget-1.4.1.tar.gz.

File metadata

  • Download URL: pihat-widget-1.4.1.tar.gz
  • Upload date:
  • Size: 169.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

File hashes

Hashes for pihat-widget-1.4.1.tar.gz
Algorithm Hash digest
SHA256 d49943644e129e56b955a3cd474d91246b3dc55677fc78b05c76439190590402
MD5 5b1fd22627d31b3a3c0c9f106008ae3f
BLAKE2b-256 f9a9ee44826d552d2e6d7a7e5ad12c8046c406e55c8a0d3edf151791bdc6b3bc

See more details on using hashes here.

File details

Details for the file pihat_widget-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: pihat_widget-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 171.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

File hashes

Hashes for pihat_widget-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f43d0dc0f89b9e02d14ccf786c8f14a27bc7d072e791283f84b9924a4d71008a
MD5 db151def9814f9eea15887e6749171af
BLAKE2b-256 ef7e72b4547dcd8d5ee4b651b5096c766a258322ca86ed3e44c7f755b111cf06

See more details on using hashes here.

Supported by

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