Package elisa :: Package plugins :: Package bad :: Package raval_frontend :: Module location_view
[hide private]
[frames] | no frames]

Source Code for Module elisa.plugins.bad.raval_frontend.location_view

  1  # -*- coding: utf-8 -*- 
  2  # Elisa - Home multimedia server 
  3  # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 
  4  # All rights reserved. 
  5  # 
  6  # This file is available under one of two license agreements. 
  7  # 
  8  # This file is licensed under the GPL version 3. 
  9  # See "LICENSE.GPL" in the root of this distribution including a special 
 10  # exception to use Elisa with Fluendo's plugins. 
 11  # 
 12  # The GPL part of Elisa is also available under a commercial licensing 
 13  # agreement from Fluendo. 
 14  # See "LICENSE.Elisa" in the root directory of this distribution package 
 15  # for details on that license. 
 16   
 17   
 18  __maintainer__ = 'Florian Boucault <florian@fluendo.com>' 
 19   
 20   
 21  from elisa.core.observers.list import ListObserver 
 22  from elisa.core import common 
 23  from elisa.extern.translation import Translatable 
 24  import constants 
 25   
 26  import pgm 
 27  from pgm.graph.group import Group 
 28  from pgm.graph.image import Image 
 29  from pgm.graph.text import Text 
 30  from pgm.timing import implicit 
 31   
 32  from raval_widgets.status_bar import StatusBar 
 33   
34 -class PathElement(Group):
35
36 - def __init__(self):
37 Group.__init__(self) 38 39 self._background = Image() 40 self._background.fg_color = (255, 255, 255, 255) 41 self._background.bg_color = (100, 200, 100, 0) 42 self._background.size = (1.0, 1.0) 43 self._background.layout = pgm.IMAGE_SCALED 44 45 self._background.visible = True 46 47 self._label = Text() 48 self._label.font_family = "Bitstream DejaVu" 49 self._label.font_height = 0.225 50 self._label.fg_color = (255, 255, 255, 255) 51 self._label.bg_color = (100, 100, 200, 0) 52 self._label.ellipsize = pgm.TEXT_ELLIPSIZE_END 53 self._label.size = (1.0, 1.0) 54 55 self.add(self._background) 56 self.add(self._label) 57 58 def loaded(image): 59 ratio = float(image.aspect_ratio[0])/float(image.aspect_ratio[1]) 60 image.width = image.height*ratio 61 62 margin = 0.20 63 self._label.width = image.width*(1.0-margin) 64 self._label.x = image.width*margin 65 66 height = 2.0/3.0 67 self._label.y = image.height*(1.0-height)/2.0 68 self._label.height = image.height*height 69 self._label.font_height = image.height/1.4 70 71 self._label.z = 0.01 72 self._label.visible = True
73 74 self._background.connect("pixbuf-loaded", loaded)
75
76 - def label__set(self, label):
77 self._label.label = label
78
79 - def background_file__set(self, background_file):
80 self._background.set_from_file(background_file)
81 82 # FIXME: these are big hacks ensuring that the font height will always be 83 # what we want; a proper fix for Pigment is ready.
84 - def size__set(self, size):
85 Group.size__set(self, size) 86 self._label.font_height = self._background.height/1.4
87
88 - def height__set(self, height):
89 Group.height__set(self, height) 90 self._label.font_height = self._background.height/1.4
91 92 plugin_registry = common.application.plugin_registry 93 PigmentView = plugin_registry.get_component_class('pigment:pigment_view') 94
95 -class LocationView(PigmentView, ListObserver):
96 97 supported_controllers = ('raval:location_controller',) 98
99 - def clean(self):
100 super(LocationView, self).clean() 101 self._status_bar.canvas = None
102
103 - def create_widgets(self):
104 theme = self.frontend.theme 105 canvas = self.frontend.context.viewport_handle.get_canvas() 106 107 self._status_bar = StatusBar() 108 self._status_bar.background = theme.get_media("location_bg") 109 110 self._status_bar.size = (canvas.width, canvas.height * 111 (constants.status_bar_height/100)) 112 self._status_bar.y = canvas.height * \ 113 (constants.context_bar_height/100.0)-self._status_bar.height 114 # -0.3 is chosen here because the first location path element is set at 115 # -0.2. see raval_widgets/status_bar.py 116 self._status_bar.z = -0.3 117 self._status_bar.opacity = 0 118 self._status_bar.visible = True 119 120 self.context_handle.add(self._status_bar) 121 122 self._animated_status_bar = implicit.AnimatedObject(self._status_bar) 123 settings = {'duration': 500, 124 'transformation': implicit.DECELERATE} 125 self._animated_status_bar.setup_next_animations(**settings) 126 self._animated_status_bar.mode = implicit.REPLACE
127
128 - def inserted(self, elements, position):
129 # append elements in the status bar 130 for model in elements: 131 item = self.create_item(model) 132 self._status_bar.append(item) 133 134 if len(self._status_bar) == 0: 135 self._hide_location_bar() 136 else: 137 self._show_location_bar()
138
139 - def removed(self, elements, position):
140 if len(self._status_bar) > 0: 141 for model in elements: 142 self._status_bar.pop(position) 143 144 if len(self._status_bar) == 0: 145 self._hide_location_bar() 146 else: 147 self._show_location_bar()
148
149 - def modified(self, position, value):
150 print "modified", position, value
151
152 - def dirtied(self):
153 print "dirtied"
154
155 - def controller_changed(self, old_controller, new_controller):
156 if new_controller == None: 157 return 158 159 self.inserted(self.controller.model, 0)
160
161 - def create_item(self, model):
162 theme = self.frontend.theme 163 background_file = theme.get_media("location_item") 164 item = PathElement() 165 item.label = self.frontend.translate_text(model.text) 166 item.background_file = background_file 167 item.visible = True 168 return item
169
170 - def _hide_location_bar(self):
171 self.debug("Hiding location bar") 172 canvas = self.frontend.context.viewport_handle.get_canvas() 173 self._animated_status_bar.y = canvas.height * \ 174 (constants.context_bar_height/100.0)-self._status_bar.height 175 self._animated_status_bar.opacity = 0
176
177 - def _show_location_bar(self):
178 self.debug("Showing location bar") 179 canvas = self.frontend.context.viewport_handle.get_canvas() 180 self._animated_status_bar.y = canvas.height * \ 181 (constants.context_bar_height/100.0) 182 self._animated_status_bar.opacity = 255
183