#!/usr/bin/env python # coding: latin-1 # Import library functions we need import wiringpi2 as wiringpi wiringpi.wiringPiSetup() import pygtk pygtk.require('2.0') import gtk # Setup software PWMs on the GPIO pins PIN_RED = 0 PIN_GREEN = 2 PIN_BLUE = 3 LED_MAX = 100 wiringpi.softPwmCreate(PIN_RED, 0, LED_MAX) wiringpi.softPwmCreate(PIN_GREEN, 0, LED_MAX) wiringpi.softPwmCreate(PIN_BLUE, 0, LED_MAX) wiringpi.softPwmWrite(PIN_RED, 0) wiringpi.softPwmWrite(PIN_GREEN, 0) wiringpi.softPwmWrite(PIN_BLUE, 0) # A function to set the LedBorg colours def SetLedBorg(red, green, blue): wiringpi.softPwmWrite(PIN_RED, int(red * LED_MAX)) wiringpi.softPwmWrite(PIN_GREEN, int(green * LED_MAX)) wiringpi.softPwmWrite(PIN_BLUE, int(blue * LED_MAX)) # A function to turn the LedBorg off def LedBorgOff(): SetLedBorg(0, 0, 0) # A function to handle the colour selection dialog change event def ColourChangedEvent(widget): global colourSelectionDialog # Get current colour colour = colourSelectionDialog.colorsel.get_current_color() # Read the red, green, and blue levels to use red = colour.red_float green = colour.green_float blue = colour.blue_float # Set the LedBorg colours SetLedBorg(red, green, blue) # Create colour selection dialog global colourSelectionDialog colourSelectionDialog = gtk.ColorSelectionDialog("Select LedBorg colour") # Get the ColorSelection widget colourSelection = colourSelectionDialog.colorsel colourSelection.set_has_palette(True) # Connect to the "color_changed" signal to our function colourSelection.connect("color_changed", ColourChangedEvent) # Show the dialog response = colourSelectionDialog.run() # Turn LedBorg off after we are finished LedBorgOff()