From 6bfd9001d3776e72c58eddc64adcbde9f4038629 Mon Sep 17 00:00:00 2001 From: noisymime Date: Wed, 9 Jan 2008 12:27:33 +0000 Subject: [PATCH] Apart from regressions, am now finished with the menu theming --- GlossMgr.py | 2 +- Menu.py | 16 +++--- gloss.py | 5 +- themeMgr.py | 93 ++++++++++++++++++++++++---------- transitions/menu_items/fade.py | 3 ++ ui/default/main.xml | 21 +++++++- 6 files changed, 101 insertions(+), 39 deletions(-) diff --git a/GlossMgr.py b/GlossMgr.py index f98261e..9ad7137 100644 --- a/GlossMgr.py +++ b/GlossMgr.py @@ -79,7 +79,7 @@ class GlossMgr: if event.keyval == clutter.keysyms.Down: #Down button pressed self.currentMenu.selectNext() if event.keyval == clutter.keysyms.q: - self.stage.hide_cursor() + self.stage.show_cursor() clutter.main_quit() if event.keyval == clutter.keysyms.Return: # Need to decide what action to take diff --git a/Menu.py b/Menu.py index 1eec7b3..e019558 100644 --- a/Menu.py +++ b/Menu.py @@ -44,7 +44,7 @@ class Menu(clutter.Group): # (label_width, label_height) = self.menuItems[0].get_size() label_y = len(self.menuItems) * (self.label_height + self.item_gap) - print "Label height: " + str(self.label_height) + #print "Label height: " + str(self.label_height) newItem = ListItem(self, itemLabel, label_y) self.menuItems.append(newItem) @@ -305,6 +305,7 @@ class ListItem (clutter.Label): #ItemTexturesGroup is what shows any images / reflections associated with the item self.itemTexturesGroup = clutter.Group() + self.itemTexturesGroup.set_position(menu.menu_image_x, menu.menu_image_y) #setup the label @@ -393,14 +394,15 @@ class ListItem (clutter.Label): if texture is None: print "NO TEXTURE!" - #Scale the image down by half - #xy_ratio = tempTexture.get_width() / self.tempTexture.get_height() - #self.tempTexture.set_width(int(self.stage.get_width() * 0.20)) #30% of the stages width - #self.tempTexture.set_height(self.tempTexture.get_width() * xy_ratio ) #Just makes sure the sizes stay the same - + #Set the image to the size in the theme + if not self.menu.menu_image_height is None: + print "changing size: " + str(self.menu.menu_image_width) + texture.set_size(self.menu.menu_image_width, self.menu.menu_image_height) + #Rotate appropriately texture.set_depth(texture.get_width()/2) - texture.set_rotation(clutter.Y_AXIS, 45, (texture.get_width()/2), 0, 0) + rotation = self.menu.menu_image_rotation + texture.set_rotation(clutter.Y_AXIS, rotation, (texture.get_width()/2), 0, 0) self.itemTexturesGroup.add(texture) #texture.hide() #For some reason this line is occasionally removing the pixbuf from the texture. diff --git a/gloss.py b/gloss.py index a0c08db..7f820fe 100644 --- a/gloss.py +++ b/gloss.py @@ -44,8 +44,10 @@ class MainApp: #Display a loading / splash screen self.splashScreen = SplashScr(self.stage) self.splashScreen.display() + #clutter.threads_enter() gobject.timeout_add(500, self.loadGloss) - #clutter.threads_add_timeout(500,self.loadGloss()) + #clutter.threads_leave() + #clutter.threads_add_timeout(500, self.loadGloss()) def loadGloss(self): @@ -85,6 +87,7 @@ class MainApp: MainMenu.display() MainMenu.selectFirst(True) + return False #print self.menuMgr.get_selector_bar().get_abs_position() #self.menuMgr.get_selector_bar().set_spinner(True) diff --git a/themeMgr.py b/themeMgr.py index 68cc4b8..1c62975 100644 --- a/themeMgr.py +++ b/themeMgr.py @@ -123,6 +123,15 @@ class ThemeMgr: #If we get to here, we hath failed return None + #Given an element, returns a subset of it based on the tag name of the subset + def get_subnode(self, element, tag_name): + for node in element: + if node.nodeType == node.ELEMENT_NODE: + if node.tagName == tag_name: + return node.childNodes + #Fail! + return None + #********************************************************************* # The methods below all relate to fulfilling requests for actors @@ -147,6 +156,30 @@ class ThemeMgr: elif not (relativeTo == "relativeToParent"): parent = None + (width, height) = self.get_dimensions(element, parent) + if (not width is None) and (not width == "default"): actor.set_width(width) + if (not height is None) and (not height == "default"): actor.set_height(height) + + #Set the position of the actor + (x,y) = (0,0) + #Get the parent + relativeTo = str(self.find_attribute_value(element, "position", "type")) + if relativeTo == "relativeToStage": + parent = self.stage + elif not (relativeTo == "relativeToParent"): + parent = None + + + (x, y) = self.get_position(element, parent) + actor.set_position(int(x), int(y)) + + #now set the opacity + opacity = self.find_child_value(element, "opacity") + if not opacity is None: + opacity = int(opacity) + actor.set_opacity(opacity) + + def get_dimensions(self, element, parent): width = self.find_child_value(element, "dimensions.width") if (not width == "default") and (not width is None): if width[-1] == "%": @@ -163,19 +196,11 @@ class ThemeMgr: if height[-1] == "%": height = (float(height[:-1]) / 100.0) * parent.get_height() height = int(height) - - if (not width is None) and (not width == "default"): actor.set_width(width) - if (not height is None) and (not height == "default"): actor.set_height(height) - - #Set the position of the actor - (x,y) = (0,0) - #Get the parent - relativeTo = str(self.find_attribute_value(element, "position", "type")) - if relativeTo == "relativeToStage": - parent = self.stage - elif not (relativeTo == "relativeToParent"): - parent = None + return (width, height) + + #Given an element, returns (x, y) coords for it + def get_position(self, element, parent): #set the x coord x = self.find_child_value(element, "position.x") if (not x == "default") and (not x is None): @@ -215,14 +240,8 @@ class ThemeMgr: y = (parent.get_height() - actor.get_height)/2 else: y = 0 - - actor.set_position(int(x), int(y)) - - #now set the opacity - opacity = self.find_child_value(element, "opacity") - if not opacity is None: - opacity = int(opacity) - actor.set_opacity(opacity) + + return (int(x), int(y)) def get_texture(self, name, parent, texture): texture_src = None @@ -280,13 +299,10 @@ class ThemeMgr: menu.item_gap = int(self.find_child_value(element, "item_gap")) menu.displayMax = int(self.find_child_value(element, "num_visible_elements")) - menu.useReflection = bool(self.find_child_value(element, "use_image_reflections")) #Grab the font - for node in element: - if node.nodeType == node.ELEMENT_NODE: - if node.tagName == "font": - fontString = self.get_font("main", node.childNodes) #print node.tagName + font_node = self.get_subnode(element, "font") + fontString = self.get_font("main", font_node) menu.font = fontString #Set the selection effect steps @@ -297,11 +313,32 @@ class ThemeMgr: menu.opacityStep1 = int(self.find_child_value(element, "opacity_step1")) menu.opacityStep2 = int(self.find_child_value(element, "opacity_step2")) - #Setup the menu transition - image_transition = "fade" - transition_path = "transitions/menu_items/" + image_transition + #setup the menu_image properties + menu.useReflection = bool(self.find_child_value(element, "menu_item_texture.use_image_reflections")) + menu.menu_image_rotation = int(self.find_child_value(element, "menu_item_texture.image_y_rotation")) + menu_image_node = self.get_subnode(element, "menu_item_texture") + if not menu_image_node is None: + #Set the position + (x, y) = self.get_position(menu_image_node, self.stage) + menu.menu_image_x = int(x) + menu.menu_image_y = int(y) + + #Set the size + (width, height) = self.get_dimensions(menu_image_node, self.stage) + if width is None: + menu.menu_image_width = None + menu.menu_image_height = None + else: + menu.menu_image_width = int(width) + menu.menu_image_height = int(height) + + #Setup the menu image transition + image_transition = self.find_child_value(element, "menu_item_texture.image_transition.name") + transition_options = self.find_child_value(element, "menu_item_texture.image_transition.options") + transition_path = "transitions/menu_items/" + str(image_transition) try: menu.menu_item_transition = __import__(transition_path).Transition(self.glossMgr) + menu.menu_item_transition.set_options(transition_options) except ImportError: print "Theme Error: No menu_item transition titled '" + str(image_transition) + "'" menu.menu_item_transition = None diff --git a/transitions/menu_items/fade.py b/transitions/menu_items/fade.py index bdacd7c..13ad1ae 100644 --- a/transitions/menu_items/fade.py +++ b/transitions/menu_items/fade.py @@ -32,4 +32,7 @@ class Transition: def on_transition_complete(self, data, oldGroup): oldGroup.get_parent().remove(oldGroup) + pass + + def set_options(self, options): pass \ No newline at end of file diff --git a/ui/default/main.xml b/ui/default/main.xml index 5699b02..99d2141 100644 --- a/ui/default/main.xml +++ b/ui/default/main.xml @@ -19,8 +19,25 @@ 0 6 - True - fade + + + + True + 45 + + fade + None + + + + 5% + 30% + + + 30% + 30% + +