More work on the theme manager

This commit is contained in:
noisymime 2007-12-16 12:21:40 +00:00
parent a08cc14f83
commit 5267952947
2 changed files with 55 additions and 8 deletions

View File

@ -27,7 +27,9 @@ from myth.MythMySQL import mythDB
#Load the theme manager #Load the theme manager
themeMgr = ThemeMgr() themeMgr = ThemeMgr()
themeMgr.get_texture("dslkjf") elem = themeMgr.get_texture("selector_bar")
print themeMgr.find_child_value(elem.childNodes, "dimensions.width")
class MainApp: class MainApp:
def __init__ (self): def __init__ (self):

View File

@ -1,4 +1,5 @@
import os import os
import clutter
from xml.dom import minidom from xml.dom import minidom
class ThemeMgr: class ThemeMgr:
@ -38,25 +39,69 @@ class ThemeMgr:
def get_texture(self, name): def get_texture(self, name):
texture_src = None texture_src = None
texture = clutter.Texture()
element = self.search_docs("texture", name)
#Quick check to make sure we found something
if element is None:
return None
return element
def setup_actor(self, actor, element):
pass
#Loops through firstly the current theme files, then the default ones looking for an element of 'element_type' with an ID of 'element_id'
def search_docs(self, element_type, element_id):
texture_element = None texture_element = None
#First loop through the current theme docs #First loop through the current theme docs
for doc in self.docs: for doc in self.docs:
temp_element = self.find_element(doc.getElementsByTagName("texture"), "id", "selector_bar") temp_element = self.find_element(doc.getElementsByTagName(element_type), "id", element_id)
if not temp_element is None: if not temp_element is None:
texture_element = temp_element texture_element = temp_element
#If texture_element is still equal to None, we check the defuault theme #If texture_element is still equal to None, we check the default theme
if (texture_element is None) and (not self.docs == self.default_docs): if (texture_element is None) and (not self.docs == self.default_docs):
for doc in self.default_docs: for doc in self.default_docs:
temp_element = self.find_element(doc.getElementsByTagName("texture"), "id", "selector_bar") temp_element = self.find_element(doc.getElementsByTagName(element_type), "id", element_id)
if not temp_element is None: if not temp_element is None:
texture_element = temp_element texture_element = temp_element
return texture_element
#Simple utity function that is used by 'search_docs' to find a matching element in an array of elements
def find_element(self, elements, attribute, value): def find_element(self, elements, attribute, value):
for element in elements: for element in elements:
val = element.getAttribute(attribute) val = element.getAttribute(attribute)
if val == value: if val == value:
print val #print val
return element return element
return None return None
#Search through an element to find a value
#Specifying the element name in the format 'level1. value' will result in the function looping
def find_child_value(self, nodeList, value):
print "No Nodes: " + str(len(nodeList))
#Check whether the value is in the form "xxx.y"
values = value.find(".")
if not values == -1:
desiredTagName = value[:values]
#print "test " + value[(values+1):]
#print "blah" + tagName
for subnode in nodeList:
if subnode.nodeType == subnode.ELEMENT_NODE:
print "Tag Name: " + subnode.tagName
if subnode.tagName == desiredTagName:
# call function again to get children
return self.find_child_value(subnode.childNodes, value[(values+1):])
else:
for subnode in nodeList:
if subnode.nodeType == subnode.TEXT_NODE:
subnode = subnode.nextSibling
if subnode.localName == value:
valueNode = subnode.childNodes[0]
#print subnode.localName + ": " + valueNode.data
return valueNode.data