1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 from elisa.core import common
18
19 import pgm
20 from pgm.graph.group import Group
21 from pgm.graph.image import Image
22 from pgm.timing import implicit
23 from pgm.widgets import const
24
25 from raval_widgets.context_bar import ContextBar
26 import constants
27
28 plugin_registry = common.application.plugin_registry
29 PigmentView = plugin_registry.get_component_class('pigment:pigment_view')
30
31 from elisa.core.observers.list import ListObserver
32 -class ContextView(PigmentView, ListObserver):
33
34 supported_controllers = ('raval:context_controller',)
35 bindings = {'current_index': 'current_index',
36 'icon': 'icon', 'text':'text'}
37
39 super(ContextView, self).clean()
40 self._context_bar.context = None
41
42 - def current_index__set(self, value):
43
44 if value == -1:
45 self._context_bar.button_panel.current_index = value
46 else:
47
48 if (value - self._context_bar.button_panel.current_index) > 0:
49 next_action_index = self._get_next_action_index(value)
50 else:
51 next_action_index = self._get_previous_action_index(value)
52
53
54 if next_action_index == -1:
55 next_action_index = self._context_bar.button_panel.current_index
56
57 if self.controller.current_index != next_action_index:
58 self.controller.current_index = next_action_index
59 else:
60 self._context_bar.button_panel.current_index = next_action_index
61
62
63 - def _get_next_action_index(self, current_index):
64
65 if current_index >= len(self.controller.model):
66 current_index = len(self.controller.model) -1
67
68 for i in range(current_index, len(self.controller.model)):
69 next_model = self.controller.model[i]
70 if next_model.activate_action:
71 return i
72
73 return -1
74
75 - def _get_previous_action_index(self, current_index):
76
77
78 if current_index < 0:
79 current_index = 0
80
81 for i in reversed( range(0, current_index+1) ):
82 next_model = self.controller.model[i]
83 if next_model.activate_action:
84 return i
85
86 return -1
87
88
102
103
104 - def controller_changed(self, old_controller, new_controller):
105 if new_controller == None:
106 return
107
108 for model in new_controller.model:
109 if model.theme_icon:
110 img_path = self.frontend.theme.get_media(model.theme_icon)
111 else:
112 img_path = None
113 self._context_bar.button_panel.add_button(img_path, 128)
114
115 self._context_bar.button_panel.index_changed.connect(
116 self._widget_index_clicked_cb)
117
118 self.compute_layout()
119
123
124 - def compute_layout(self):
125 canvas = self.frontend.context.viewport_handle.get_canvas()
126 self._context_bar.size = (canvas.width, canvas.height *
127 (constants.context_bar_height/100) )
128 self._context_bar.y = -self._context_bar.height * 2.0
129 self._context_bar.compute_layout()
130
131
132 - def inserted(self, elements, position):
135
136 - def active__set(self, value):
137 self._context_bar.button_panel.active = value
138
139 - def icon__set(self, icon):
140 if icon:
141 icon_file = self.frontend.theme.get_media(icon)
142 self._context_bar.icon.set_from_file(icon_file, 64)
143 self.show()
144 else:
145 self.hide()
146
147 - def text__set(self, text):
148 if text:
149 frontend = self.frontend
150 self._context_bar.label = frontend.translate_text(text)
151 self.show()
152 else:
153 self._context_bar.label = ""
154 self.hide()
155
157 self.debug("Showing context bar")
158 self._context_bar.visible = True
159 self._animated_context_bar.y = 0.0
160
162 self.debug("Hiding context bar")
163 self._animated_context_bar.y = -self._context_bar.height*2.0
164