Skip to content

Commit

Permalink
Added files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
David committed Apr 27, 2016
1 parent 8346d92 commit a26f980
Show file tree
Hide file tree
Showing 6 changed files with 974 additions and 908 deletions.
54 changes: 54 additions & 0 deletions adler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-

import urllib2
import shutil

class adler:
def getNewHockeyTable(self):
self.url = 'file:./offline_page/hockey_table.htm'
self.f = urllib2.urlopen(self.url)
self.table_data = [[[] for _ in range(6)] for _ in range(5)]
i = 0
self.found_line = False
while i < 500:
self.line = self.f.readline()
if '<TBODY>' in self.line:
self.found_line = True
break
i = i + 1

if self.found_line == True:
for i in range(0, 5):
self.line = self.f.readline()
self.line = self.f.readline()
self.line = self.f.readline()
# Platz
self.table_data[i][0] = self.line[(self.line.find('acenter">')+9):-(len(self.line)-self.line.find('</TD>'))]
for u in range(0,3):
self.line = self.f.readline()
# Image
self.image = self.line[(self.line.find('src="')+5):-(len(self.line)-self.line.find('"><A'))]
self.imagelocation = './offline_page/' + self.image
self.image_name = './images/' + self.table_data[i][0] + '_hockey.png'
shutil.copy(self.imagelocation, self.image_name)
# Name
self.table_data[i][1] = self.line[(self.line.find('alt="')+5):-(len(self.line)-self.line.find('" src="'))]
self.line = self.f.readline()
self.line = self.f.readline()
self.line = self.f.readline()
# Games
self.table_data[i][2] = self.line[(self.line.find('acenter">')+9):-(len(self.line)-self.line.find('</TD>'))]
for u in range(0,7):
self.line = self.f.readline()
# Points
self.table_data[i][3] = self.line[(self.line.find('highlight">')+11):-(len(self.line)-self.line.find('</TD>'))]
self.line = self.f.readline()
self.line = self.f.readline()
# Goals
self.table_data[i][4] = self.line[(self.line.find('acenter">')+9):-(len(self.line)-self.line.find('</TD>'))]
self.line = self.f.readline()
# Enemy Goal
self.table_data[i][5] = self.line[(self.line.find('acenter">')+9):-(len(self.line)-self.line.find('</TD>'))]
self.f.close()
return self.table_data
271 changes: 139 additions & 132 deletions display_class.py
Original file line number Diff line number Diff line change
@@ -1,132 +1,139 @@
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-

import sys
import glob
from rgbmatrix import RGBMatrix
from PIL import ImageFont, ImageDraw, Image

class display_class:
global AnimationCanvas

def __init__(self,rows,chain,parallel,pwmBits,brightness,luminanceCorrect):
self.matrix = RGBMatrix(rows,chain,parallel)
self.matrix.pwmBits = pwmBits
self.matrix.brightness = brightness
self.matrix.luminanceCorrect = luminanceCorrect
# The canvas to work on without chanching the Screen
self.offsetCanvas = self.matrix.CreateFrameCanvas()
# Kill the screen at programm start
self.offsetCanvas.Fill(0,0,0)
self.offsetCanvas = self.matrix.SwapOnVSync(self.offsetCanvas)

def setBrightness(self,brightness):
self.matrix.brightness = brightness
# The canvas to work on without chanching the Screen
self.offsetCanvas = self.matrix.CreateFrameCanvas()
self.offsetCanvas.Fill(0,0,0)
self.offsetCanvas = self.matrix.SwapOnVSync(self.offsetCanvas)
#print 'Brightsness is set to: ' + str(brightness)
#print 'With type: ' + str(type(brightness))

def setpwmBits(self,pwmBits):
self.matrix.pwmBits = pwmBits

def setluminaceCorrect(self,luminanceCorrect):
self.matrix.luminanceCorrect = luminanceCorrect

def updateScreen(self):
self.offsetCanvas = self.matrix.SwapOnVSync(self.offsetCanvas)

def clearoffsetScreen(self):
self.offsetCanvas.Fill(0,0,0)

# Display image on the given coordinates
def showimage(self,x,y,imagepath):
# Imports an Image from the given path, accepted are .jpg .gif .png
self.im = Image.open(imagepath)
self.xy = [0,0]
self.xymax = self.im.size
self.alpha = 255
if self.im.mode == 'RGB':
for self.xy[0] in range(0,self.xymax[0]):
for self.xy[1] in range(0,self.xymax[1]):
self.tmp = (self.xy[0],self.xy[1])
self.red, self.green, self.blue = self.im.getpixel(self.tmp)
self.offsetCanvas.SetPixel(x + self.xy[0],y + self.xy[1],self.red,self.green,self.blue)
elif self.im.mode == 'RGBA':
for self.xy[0] in range(0,self.xymax[0]):
for self.xy[1] in range(0,self.xymax[1]):
self.tmp = (self.xy[0],self.xy[1])
self.red, self.green, self.blue, self.alpha = self.im.getpixel(self.tmp)
if self.alpha > 50:
self.offsetCanvas.SetPixel(x + self.xy[0],y + self.xy[1],self.red,self.green,self.blue)

# Textrenderer to display Text
def drawtext(self,x,y,text,fonttype,red,green,blue,clear):
self.fonthight = fonttype[fonttype.find('x')+1:len(fonttype)]
if not self.fonthight.isdigit():
self.fonthight = self.fonthight[0:len(self.fonthight)-1]
self.fontwidth = fonttype[0:fonttype.find('x')]

self.im = Image.new("I", (len(text)*int(self.fontwidth),int(self.fonthight)-1))
self.draw = ImageDraw.Draw(self.im)
self.font = ImageFont.load("/programs/rpi-rgb-led-matrix-master/fonts/" + fonttype + ".pil")
self.draw.text((0, -1), text, font=self.font)
self.xy = [0,0]
self.xymax = self.im.size
for self.xy[0] in range(0,self.xymax[0]):
for self.xy[1] in range(0,self.xymax[1]):
self.tmp = (self.xy[0],self.xy[1])
if self.im.getpixel(self.tmp) > 0:
self.offsetCanvas.SetPixel(x + self.xy[0],y + self.xy[1],red,green,blue)
elif clear == True:
self.offsetCanvas.SetPixel(x + self.xy[0],y + self.xy[1],0,0,0)


def load_animations(self,path):
# load and preprocess animations to speed up things as fast as possibel!
global AnimationCanvas

self.animation_length = [0]
self.frame_delay = [0]
self.anim_counter = 0
AnimationCanvas = []
path = path + '/*.gif'

for self.infile in glob.glob(path):
AnimationCanvas.append([])
if self.anim_counter > 0:
self.animation_length.append(1)
self.frame_delay.append(1)
self.animation_length[self.anim_counter] = self.anim_counter + 1
self.im = Image.open(self.infile)
self.frame_delay[self.anim_counter] = self.im.info['duration']
self.frame_counter = 0

try:
while 1:
AnimationCanvas[self.anim_counter].append(0)
AnimationCanvas[self.anim_counter][self.frame_counter] = self.matrix.CreateFrameCanvas()
self.xy = [0,0]
self.xymax = self.im.size
self.image = self.im.convert('RGB')
for self.xy[0] in range(0,self.xymax[0]):
for self.xy[1] in range(0,self.xymax[1]):
self.tmp = (self.xy[0],self.xy[1])
self.red, self.green, self.blue = self.image.getpixel(self.tmp)
AnimationCanvas[self.anim_counter][self.frame_counter].SetPixel(self.xy[0],self.xy[1],
self.red,self.green,self.blue)
self.im.seek(self.im.tell()+1)
self.frame_counter = self.im.tell()
except:
pass

self.animation_length[self.anim_counter] = self.frame_counter
self.anim_counter += 1

return self.animation_length, self.frame_delay

def show_animation_image(self,animation_number,frame_number,Loop_play):
global AnimationCanvas
self.matrix.Swa (AnimationCanvas[animation_number][frame_number])
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-

import sys
import glob
from rgbmatrix import RGBMatrix
from PIL import ImageFont, ImageDraw, Image

class display_class:
global AnimationCanvas

def __init__(self,rows,chain,parallel,pwmBits,brightness,luminanceCorrect):
self.matrix = RGBMatrix(rows,chain,parallel)
self.matrix.pwmBits = pwmBits
self.matrix.brightness = brightness
self.matrix.luminanceCorrect = luminanceCorrect
# The canvas to work on without chanching the Screen
self.offsetCanvas = self.matrix.CreateFrameCanvas()
# Kill the screen at programm start
self.offsetCanvas.Fill(0,0,0)
self.offsetCanvas = self.matrix.SwapOnVSync(self.offsetCanvas)

def setBrightness(self,brightness):
self.matrix.brightness = brightness
# The canvas to work on without chanching the Screen
self.offsetCanvas = self.matrix.CreateFrameCanvas()
self.offsetCanvas.Fill(0,0,0)
self.offsetCanvas = self.matrix.SwapOnVSync(self.offsetCanvas)
#print 'Brightsness is set to: ' + str(brightness)
#print 'With type: ' + str(type(brightness))

def setpwmBits(self,pwmBits):
self.matrix.pwmBits = pwmBits

def setluminaceCorrect(self,luminanceCorrect):
self.matrix.luminanceCorrect = luminanceCorrect

def updateScreen(self):
# This function is to show the canvas and update the screen
self.offsetCanvas = self.matrix.SwapOnVSync(self.offsetCanvas)

def clearoffsetScreen(self):
# This is the normal way to clear the canvas
self.offsetCanvas.Fill(0,0,0)

# Display image on the given coordinates
def showimage(self,x,y,imagepath):
# Imports an Image from the given path, accepted are .jpg .gif .png
self.im = Image.open(imagepath)
self.xy = [0,0]
self.xymax = self.im.size
self.alpha = 255
if (not self.im.mode == 'RGB') or (not self.im.mode == 'RGBA'):
self.im = self.im.convert('RGBA')
if self.im.mode == 'RGB':
for self.xy[0] in range(0,self.xymax[0]):
for self.xy[1] in range(0,self.xymax[1]):
self.tmp = (self.xy[0],self.xy[1])
self.red, self.green, self.blue = self.im.getpixel(self.tmp)
self.offsetCanvas.SetPixel(x + self.xy[0],y + self.xy[1],self.red,self.green,self.blue)
elif self.im.mode == 'RGBA':
for self.xy[0] in range(0,self.xymax[0]):
for self.xy[1] in range(0,self.xymax[1]):
self.tmp = (self.xy[0],self.xy[1])
self.red, self.green, self.blue, self.alpha = self.im.getpixel(self.tmp)
if self.alpha > 50:
self.offsetCanvas.SetPixel(x + self.xy[0],y + self.xy[1],self.red,self.green,self.blue)

# Textrenderer to display Text
def drawtext(self,x,y,text,fonttype,red,green,blue,clear):
self.fonthight = fonttype[fonttype.find('x')+1:len(fonttype)]
if not self.fonthight.isdigit():
self.fonthight = self.fonthight[0:len(self.fonthight)-1]
self.fontwidth = fonttype[0:fonttype.find('x')]
self.im = Image.new("I", (len(text)*int(self.fontwidth),int(self.fonthight)-1))
self.draw = ImageDraw.Draw(self.im)
# all .bdf files are converted to .pil for easy access
self.font = ImageFont.load("/programs/rpi-rgb-led-matrix-master/fonts/" + fonttype + ".pil")
if isinstance(text, str):
self.draw.text((0, -1), text.decode("utf8").encode("iso-8859-1"), font=self.font)
elif isinstance(text, unicode):
self.draw.text((0, -1), text.encode("iso-8859-1"), font=self.font)
self.xy = [0,0]
self.xymax = self.im.size
for self.xy[0] in range(0,self.xymax[0]):
for self.xy[1] in range(0,self.xymax[1]):
self.tmp = (self.xy[0],self.xy[1])
if self.im.getpixel(self.tmp) > 0:
self.offsetCanvas.SetPixel(x + self.xy[0],y + self.xy[1],red,green,blue)
elif clear == True:
self.offsetCanvas.SetPixel(x + self.xy[0],y + self.xy[1],0,0,0)

def load_animations(self,path):
# load and preprocess animations to speed up things
global AnimationCanvas

self.animation_length = [0]
self.frame_delay = [0]
self.anim_counter = 0
AnimationCanvas = []
path = path + '/*.gif'
# go through all . gif files in the given folder
for self.infile in glob.glob(path):
AnimationCanvas.append([])
if self.anim_counter > 0:
self.animation_length.append(1)
self.frame_delay.append(1)
self.animation_length[self.anim_counter] = self.anim_counter + 1
self.im = Image.open(self.infile)
self.frame_delay[self.anim_counter] = self.im.info['duration']
self.frame_counter = 0

try: #go through all frames in the gif file, at the end the loop will fail
# for each frame a canvas is created in an 2D array which can be accessed with the animation and frame number
while 1:
AnimationCanvas[self.anim_counter].append(0)
AnimationCanvas[self.anim_counter][self.frame_counter] = self.matrix.CreateFrameCanvas()
self.xy = [0,0]
self.xymax = self.im.size
self.image = self.im.convert('RGB')
for self.xy[0] in range(0,self.xymax[0]):
for self.xy[1] in range(0,self.xymax[1]):
self.tmp = (self.xy[0],self.xy[1])
self.red, self.green, self.blue = self.image.getpixel(self.tmp)
AnimationCanvas[self.anim_counter][self.frame_counter].SetPixel(self.xy[0],self.xy[1],
self.red,self.green,self.blue)
self.im.seek(self.im.tell()+1)
self.frame_counter = self.im.tell()
except:
pass
self.animation_length[self.anim_counter] = self.frame_counter
self.anim_counter += 1
# after all gif files put back the animation length and the frame numbers to the program
return self.animation_length, self.frame_delay


def show_animation_image(self,animation_number,frame_number):
global AnimationCanvas
self.matrix.SwapOnVSync(AnimationCanvas[animation_number][frame_number])
Loading

0 comments on commit a26f980

Please sign in to comment.