From 5267952947ff012060cc368ba20b61a4dfb120ff Mon Sep 17 00:00:00 2001 From: noisymime Date: Sun, 16 Dec 2007 12:21:40 +0000 Subject: [PATCH] More work on the theme manager --- gloss.py | 4 +++- themeMgr.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/gloss.py b/gloss.py index 92a0809..20edde7 100644 --- a/gloss.py +++ b/gloss.py @@ -27,7 +27,9 @@ from myth.MythMySQL import mythDB #Load the theme manager themeMgr = ThemeMgr() -themeMgr.get_texture("dslkjf") +elem = themeMgr.get_texture("selector_bar") +print themeMgr.find_child_value(elem.childNodes, "dimensions.width") + class MainApp: def __init__ (self): diff --git a/themeMgr.py b/themeMgr.py index e504888..ec35d13 100644 --- a/themeMgr.py +++ b/themeMgr.py @@ -1,4 +1,5 @@ import os +import clutter from xml.dom import minidom class ThemeMgr: @@ -38,25 +39,69 @@ class ThemeMgr: def get_texture(self, name): 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 + #First loop through the current theme 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: 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): 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: 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): for element in elements: val = element.getAttribute(attribute) if val == value: - print val + #print val return element - - return None \ No newline at end of file + + 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 + \ No newline at end of file