Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pifacecad
- import transmissionrpc
- # Transmission Client Settings
- ADDRESS = "127.0.0.1"
- PORT = 9091
- USER = "transmission"
- PASSWORD = "sean123456"
- def shorten_string(str):
- str = (str[:14] + '..') if len(str) > 16 else str
- return str
- if __name__ == "__main__":
- cad = pifacecad.PiFaceCAD()
- cad.lcd.backlight_on()
- cad.lcd.blink_off()
- cad.lcd.cursor_off()
- cad.lcd.write(shortenString(torrent.name))
- cad.lcd.write('\n')
- cad.lcd.write(str(int(round(torrent.progress))) + '% | ' + str(torrent.rateDownload / 1000) + 'KB/s')
- class TransmissionDisplay(object):
- def __init__(self, cad, torrents, index=0):
- self.cad = cad
- self.cad.lcd.backlight_on()
- self.cad.lcd.blink_off()
- self.cad.lcd.cursor_off()
- def update(self):
- self.cad.lcd.clear()
- self.display_torrent(0)
- def display_torrent(index):
- torrent = torrents[index]
- cad.lcd.write(shorten_string(torrent.name))
- cad.lcd.write("\n")
- cad.lcd.write(str(int(round(torrent.progress))) + '% | ' + str(torrent.rateDownload / 1000) + 'KB/s')
- def next_torrent(self):
- index = index + 1
- display_torrent(index)
- def previous_torrent(self):
- index = index - 1
- display_torrent(index)
- if __name__ == "__main__":
- transmission_client = transmissionrpc.Client(address=ADDRESS, port=PORT, user=USER, password=PASSWORD)
- torrents = transmission_client.get_torrents()
- cad = pifacecad.PiFaceCAD()
- global transmission_display
- transmission_display = TransmissionDisplay(cad, torrents)
- transmission_display.update()
- # listener cannot deactivate itself so we have to wait until it has
- # finished using a barrier.
- global end_barrier
- end_barrier = threading.Barrier(2)
- # wait for button presses
- global switchlistener
- switchlistener = pifacecad.SwitchEventListener(chip=cad)
- switchlistener.register(
- 0, pifacecad.IODIR_ON, traintimedisplay.previous_board)
- switchlistener.register(
- 1, pifacecad.IODIR_ON, traintimedisplay.next_board)
- switchlistener.activate()
- end_barrier.wait() # wait unitl exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement