Vizible’s Blog

XBMC – Currency

Posted in Uncategorized by wearetherock on June 18, 2009
from lib import feedparser
import os
import re

import xbmcgui

class FeedParser:
	def __init__(self, feedUrl):

		self.info = feedparser.parse(feedUrl)
	def getEntries(self):

		return self.info.entries
	def getTitles(self):

		titles = []
		entries = self.getEntries()

		for entry in entries:
			title = entry.title

			titles.append(title)
		return titles

# window
class CurrencyWindow(xbmcgui.Window):

    def __init__(self):
        # don't understand where have to replace
        self.rootDir = os.getcwd().replace(";", "");

        self.imageDir = self.rootDir + "/image/"
        #self.loadCurrency()

    def addButton(self, text, x, y):

        self.addControl(xbmcgui.ControlButton(x, y, 200, 50, text, font='font14'))

    def addLabel(self, text, x, y, size):

        self.addControl(xbmcgui.ControlLabel(x, y, 500, 50, text, font=size))

    def addBackgroundImage(self, name, x, y):

        imageLocation = self.imageDir + name
        self.addControl(xbmcgui.ControlImage(x, y, 720, 480, imageLocation))

    def addImage(self, name, x, y, width, height):

        imageLocation = self.imageDir + name
        self.addControl(xbmcgui.ControlImage(x, y, width, height, imageLocation))


# not use for this time
def getCountriesCodeMap():
    contries = {}
    contries['EUR'] = 'Eurozone Euro'

    contries['JPY'] = 'Japan Yen'
    contries['INR'] = 'India Rupee'

    contries['MXN'] = 'Mexican Peso'
    contries['ZAR'] = 'South African Rand'

    contries['THB'] = 'Thai Baht'
    contries['CAD'] = 'Canada Dollar'

    contries['AUD'] = "Australian Dollar"
    contries['CHF'] = 'Awiss Franc'

    contries['SGD'] = 'Sigapore Dollar'
    contries['GBP'] = 'Pound Sterling'

    return contries

# not use for this time
def getDisplayFormatAndFileName(title):
    contries = getCountriesCodeMap()

    # tile pattern = 1 USD = EUR (0.724700)
    # digitPattern [1,0,724700]
    digitPattern = '[-+]?\d+'
    # stringPattern ['1','USD','=','EUR', '(0.724700)']
    stringPattern = '\S+'

    digitReg = re.compile(digitPattern);
    stringReg = re.compile(stringPattern);

    digitText = digitReg.findall(title);
    stringText = stringReg.findall(title);

    contryCode = stringText[3];

    newFormat = digitText[1] + '.' + digitText[2][0:3] + ' ' + contryCode + ' (' + contries[contryCode] + ')'

    fileName = contryCode + ".gif"

    return newFormat, fileName



def loadCurrency():
    currencyFeed = 'http://themoneyconverter.com/USD/rss.xml'
    parser = FeedParser(currencyFeed)

    #titles = parser.getTitles()
    entries = parser.getEntries()
    return entries

def main():
    window = CurrencyWindow()
    entries = loadCurrency()

    window.addBackgroundImage("world-map-background.jpg", 0, 0)
   
    #window.addImage("thb.gif", 100, 300, 150, 100)

    window.addLabel("CURRENCY EXCHAGE RATE for US Dollar" , 10, 70, 'font40')

    window.addImage("usd.gif", 70, 100, 100, 70)

    window.addLabel(entries[0].modified,20,180, 'font40')

    xTitlePosition = 350
    yTitlePosition = 70

    xDescPosition = 330

    yDescPosition = 90

    count = 0
    for entry in entries:

        #text, fileName = getDisplayFormatAndFileName(title);
        if count > 6 :
            break
            
        title = entry.title

        description = entry.description

        window.addLabel(title , xTitlePosition, yTitlePosition, 'font40')

        window.addLabel(description, xDescPosition,yDescPosition, 'font15')

        
        window.addImage(title[0:3].lower()+'.gif', xTitlePosition+80, yTitlePosition-10, 50, 30)

        
        yTitlePosition += 50
        yDescPosition +=50
        count += 1

    window.doModal()
    del window

if __name__ == "__main__":

    main()
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: