ok here i have something i just made up for ya
I think you may like it.
these lines
LINELENGTH = 50
TRANSPARENCY = 220
FADESTEPS = 50
OSDTIMEOUT = 30
MONITOR = 0
DISPLAYSIZE = 0.60
you can change
LINELENGTH is how long the display text should be. use this is you have text overrun on the OSD. make the number smaller
TRANSPARENCY is how see through the OSD is set this number from 40 to 230 nothing higher or lower
FADESTEPS this all depends on the computer its running on, if things are running slow then shrink the number
OSDTIMEOUT is when the OSD will dissapear, it's in seconds.
MONITOR is for a multi-monitor setup. 0 being the default for a single monitor
DISPLAYSIZE this is a decimal representation of the % of the screen you want to cover so the 0.60 will cover 60% of the screen (on that monitor)
copy and paste the code below into a python script. you will have to get rid of everything in the macro except the event and the TextGrabber. and both of those have to be located before the script.
there seems to be one glitch. i have to poke around and see if i can find it. but it's when the menu goes to shutdown on occasion it will throw an exception. one time i had the osd get stuck on. not sure what is causing it and why it's so random
i will add other features like being able to change the colors but this is a nice start.
Code: Select all
LINELENGTH = 50
TRANSPARENCY = 220
FADESTEPS = 50
OSDTIMEOUT = 30
MONITOR = 0
DISPLAYSIZE = 0.60
ERROR_REASON = (
"We failed to reach a server.\n"
"Reason: %s"
)
ERROR_CODE = (
"The server couldn't fulfill the request.\n"
"Error code: %d"
)
URL = 'http://www.omdbapi.com/?t='
KEYS = [
'Title',
'Released',
'Season',
'Episode',
'Runtime',
'Plot'
]
import wx
import urllib2
from urllib2 import HTTPError, URLError
from ast import literal_eval
from PIL import Image
from time import sleep
from eg.WinApi.Utils import GetMonitorDimensions
class ScrapedOSD(wx.Frame):
def __init__(self, osdtext, poster):
self.fontInfo = '0;-41;0;0;0;700;255;0;0;0;3;2;1;82;Lucoda Handwriting'
self.ProcessFont()
print osdtext
xPos, yPos, xSize, ySize = self.GetDimensions()
poster = Image.open(urllib2.urlopen(poster)).resize((xSize, ySize), Image.ANTIALIAS)
print xSize, ySize
image = wx.EmptyImage(poster.size[0], poster.size[1])
image.SetData(poster.convert("RGB").tobytes())
image.SetAlphaData(poster.convert("RGBA").tobytes()[3::4])
self.poster = wx.BitmapFromImage(image)
self.osdtext = osdtext
wx.Frame.__init__(
self,
parent=None,
size=(xSize, ySize),
pos=(xPos, yPos),
style = wx.STAY_ON_TOP | wx.FRAME_NO_TASKBAR | wx.NO_BORDER,
)
self.fadeinvalue = 0
self.fadeoutvalue = TRANSPARENCY
self.menutimer = wx.Timer(self)
self.fadeintimer = wx.Timer(self)
self.fadeouttimer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnTimer, self.menutimer)
self.Bind(wx.EVT_TIMER, self.OnFadeIn, self.fadeintimer)
self.Bind(wx.EVT_TIMER, self.OnFadeOut, self.fadeouttimer)
self.Bind(wx.EVT_CLOSE, self.OnClose)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
wx.CallAfter(self.FadeIn, TRANSPARENCY)
wx.CallAfter(self.menutimer.Start, OSDTIMEOUT * 1000)
self.Show()
def GetDimensions(self):
try:
screen = GetMonitorDimensions()[MONITOR]
except IndexError:
screen = GetMonitorDimensions()[0]
xpos, ypos, xmon, ymon = screen
xsize = int(float(xmon) * DISPLAYSIZE)
ysize = int(float(ymon - 90) * DISPLAYSIZE)
xpos += (xmon - xsize) / 2
ypos += (ymon - ysize) / 2
return xpos, ypos, xsize, ysize
def OnPaint(self, evt):
bmp = self.poster
xPos, yPos, xSize, ySize = self.GetDimensions()
#bmp = wx.EmptyBitmap(xSize, ySize)
dc = wx.MemoryDC()
dc.SelectObject(bmp)
dc = wx.GCDC(dc)
dc.SetFont(self.font)
dc.SetBrush(wx.Brush(wx.Colour(0, 0, 0, TRANSPARENCY - 30)))
dc.SetPen(wx.Pen(wx.Colour(255, 0, 0, TRANSPARENCY - 30), 3))
dc.DrawRoundedRectangle(25, 25, xSize-50, ySize-50, 5)
dc.SetTextForeground(wx.Colour(0, 255, 0, 225))
print self.osdtext
dc.DrawText(self.osdtext, 45, 45)
pdc = wx.PaintDC(self)
pdc.DrawBitmap(bmp, 0, 0)
def ProcessFont(self):
self.font = wx.Font(18, wx.FONTFAMILY_TELETYPE,wx.NORMAL,wx.BOLD, faceName="Arial")
nativeFontInfo = wx.NativeFontInfo()
nativeFontInfo.FromString(self.fontInfo)
self.font.SetNativeFontInfo(nativeFontInfo)
def OnEraseBackground(self, event):
pass # do nothing to avoid flicker
def OnTimer(self, evt):
self.menutimer.Stop()
wx.CallAfter(self.FadeOut, TRANSPARENCY)
evt.Skip()
def OnClose(self, dummyEvent):
def stop(t):
try:
t.Stop()
except:
pass
stop(self.menutimer)
stop(self.fadeouttimer)
stop(self.fadeintimer)
self.Show(False)
self.Destroy()
def OnFadeIn(self, evt):
self.FadeIn()
evt.Skip()
def OnFadeOut(self, evt):
self.FadeOut()
evt.Skip()
def FadeOut(self, fadeoutsteps=None):
if fadeoutsteps is not None:
self.fadeoutincrement = TRANSPARENCY / fadeoutsteps
wx.CallAfter(self.fadeouttimer.Start, 1)
else:
self.fadeoutvalue -= self.fadeoutincrement
if self.fadeoutvalue < 0:
self.fadeoutvalue = 0
self.fadeouttimer.Stop()
wx.CallAfter(self.OnClose, None)
self.SetTransparent(self.fadeoutvalue)
def FadeIn(self, fadeinsteps=None):
if fadeinsteps is not None:
self.fadeinincrement = TRANSPARENCY / fadeinsteps
wx.CallAfter(self.fadeintimer.Start, 1)
else:
self.fadeinvalue += self.fadeinincrement
if self.fadeinvalue > TRANSPARENCY:
self.fadeinvalue = TRANSPARENCY
self.fadeintimer.Stop()
self.SetTransparent(self.fadeinvalue)
def Scrape():
try:
response = urllib2.urlopen(URL)
except HTTPError as httpError:
eg.PrintError(ERROR_REASON % httpError.reason)
eg.PrintError(ERROR_CODE % httpError.code)
except URLError as urlError:
eg.PrintError(ERROR_REASON % urlError.reason)
else:
return literal_eval(response.read())
text = eg.globals.grabbedText.split('(')
title = text[0].split('.')[0].replace(' ', '%20')
URL += title
try:
episodedata = text[1].split(')')[0]
episodedata = episodedata.upper()[1:].split('E')
URL += '&Season=%d&Episode=%d' % (int(episodedata[0]), int(episodedata[1]))
except IndexError:
pass
URL += '&y=&plot=full&r=json'
data = Scrape()
if data is not None:
print data
text = 'Title: %s\n' % title.replace('%20', ' ')
for key in KEYS:
try:
scrapedata = list(data[key])
if len(scrapedata) > LINELENGTH:
for i in range(LINELENGTH, len(scrapedata), LINELENGTH):
scrapedata.insert(i, '\n')
else:
scrapedata.append('\n')
if 'Season' in data:
if key == 'Title':
key = 'Episode Title'
text += '%s: %s' % (key, ''.join(scrapedata))
except KeyError:
pass
ScrapedOSD(text, data['Poster'])