comparison pyink/domview.py @ 1327:ab281ec3eeec

Add a layers group for components The children of the layers group of a components is layers of the component. All layers are children of a layers group instead of a component group.
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 30 Jan 2011 23:04:06 +0800
parents 0a2034f490e5
children 407f321f0d7c
comparison
equal deleted inserted replaced
1326:0a2034f490e5 1327:ab281ec3eeec
265 tl = self._main_comp.get_timeline('default') 265 tl = self._main_comp.get_timeline('default')
266 self._cur_timeline = tl 266 self._cur_timeline = tl
267 self._scenes_node = tl.scenes_node 267 self._scenes_node = tl.scenes_node
268 pass 268 pass
269 269
270 ## \brief Create component group
271 #
272 # A component group is a group with a layers group as child.
273 # The layers group is where layer groups is in.
274 #
270 def _create_component_group(self): 275 def _create_component_group(self):
271 doc = self._doc 276 doc = self._doc
272 group = doc.createElement('svg:g') 277 group = doc.createElement('svg:g')
273 gid = self.new_id() 278 gid = self.new_id()
274 group.setAttribute('id', gid) 279 group.setAttribute('id', gid)
275 280
276 self._components_group.appendChild(group) 281 self._components_group.appendChild(group)
282
283 # Create layers group
284 layers_group = doc.createElement('svg:g')
285 gid = self.new_id()
286 layers_group.setAttribute('id', gid)
287 layers_group.setAttribute('inkscape:label', 'layers')
288 group.appendChild(layers_group)
289
277 return group 290 return group
278 291
279 ## \brief Create a ns0:component node for a given name. 292 ## \brief Create a ns0:component node for a given name.
280 # 293 #
281 # \param comp_name is the name of the created component. 294 # \param comp_name is the name of the created component.
302 pass 315 pass
303 raise ValueError, 'can not find component node - %s' % (comp_name) 316 raise ValueError, 'can not find component node - %s' % (comp_name)
304 317
305 ## \brief Create a layer group for give layer of a component. 318 ## \brief Create a layer group for give layer of a component.
306 # 319 #
307 def _create_comp_layer_group(self, comp_group, layer_name): 320 def _create_comp_layer_group(self, layers_group, layer_name):
308 doc = self._doc 321 doc = self._doc
309 gid = self.new_id() 322 gid = self.new_id()
310 323
311 layer_group = doc.createElement('svg:g') 324 layer_group = doc.createElement('svg:g')
312 layer_group.setAttribute('id', gid) 325 layer_group.setAttribute('id', gid)
313 layer_group.setAttribute('inkscape:label', layer_name) 326 layer_group.setAttribute('inkscape:label', layer_name)
314 layer_group.setAttribute('inkscape:groupmode', 'layer') 327 layer_group.setAttribute('inkscape:groupmode', 'layer')
315 comp_group.appendChild(layer_group) 328 layers_group.appendChild(layer_group)
316 329
317 return layer_group 330 return layer_group
318 331
319 ## \brief Return group of specified layer in a component. 332 ## \brief Return group of specified layer in a component.
320 # 333 #
323 # 336 #
324 def _get_group_of_component_layer(self, comp_name, layer_idx): 337 def _get_group_of_component_layer(self, comp_name, layer_idx):
325 comp = self._get_component(comp_name) 338 comp = self._get_component(comp_name)
326 layer = comp.layers[layer_idx] 339 layer = comp.layers[layer_idx]
327 return layer.group 340 return layer.group
341
342 def _get_layers_group_of_component(self, comp_name):
343 if comp_name == 'main':
344 return self._root
345
346 comp_group = self.get_component_group(comp_name)
347 layers_group = comp_group.firstChild()
348 assert layers_group.getAttribute('inkscape:label') == 'layers'
349
350 return layers_group
328 351
329 def all_comp_names(self): 352 def all_comp_names(self):
330 return [comp.name() for comp in self._components] 353 return [comp.name() for comp in self._components]
331 354
332 def has_component(self, name): 355 def has_component(self, name):
364 comp = self._get_component(comp_name) 387 comp = self._get_component(comp_name)
365 self._cur_comp = comp 388 self._cur_comp = comp
366 self._layers = comp.layers 389 self._layers = comp.layers
367 comp_name = self._cur_comp.name() 390 comp_name = self._cur_comp.name()
368 # for domview 391 # for domview
369 self._layers_parent = self.get_component_group(comp_name) 392 self._layers_parent = self._get_layers_group_of_component(comp_name)
370 393
371 first_name = comp.all_timeline_names()[0] 394 first_name = comp.all_timeline_names()[0]
372 self.switch_timeline(first_name) 395 self.switch_timeline(first_name)
373 396
374 self.hide_component(old_comp.name()) 397 self.hide_component(old_comp.name())
377 400
378 def add_component(self, comp_name): 401 def add_component(self, comp_name):
379 if self.has_component(comp_name): 402 if self.has_component(comp_name):
380 raise ValueError, \ 403 raise ValueError, \
381 'try add a component with existed name %s' % (comp_name) 404 'try add a component with existed name %s' % (comp_name)
382 405
383 comp_group = self._create_component_group() 406 comp_group = self._create_component_group()
384 comp_group_id = comp_group.getAttribute('id') 407 comp_group_id = comp_group.getAttribute('id')
385 comp_node = self._create_component_node(comp_name, comp_group_id) 408 comp_node = self._create_component_node(comp_name, comp_group_id)
386
387 layer_group = self._create_comp_layer_group(comp_group, 'Layer1')
388 409
389 comp = Component(self, comp_node) 410 comp = Component(self, comp_node)
390 comp.parse_timelines() 411 comp.parse_timelines()
391 412
413 self._components.append(comp)
414 self._comp_names.add(comp_name)
415
416 # Create Layer1 (at least one layer for a component)
417 layers_group = self._get_layers_group_of_component(comp_name)
418 layer_group = self._create_comp_layer_group(layers_group, 'Layer1')
392 layer = Layer(layer_group) 419 layer = Layer(layer_group)
393 comp.layers.append(layer) 420 comp.layers.append(layer)
394 421
395 self._components.append(comp)
396 self._comp_names.add(comp_name)
397
398 self.hide_component(comp_name) 422 self.hide_component(comp_name)
399 pass 423 pass
400 424
401 def add_component_node(self, comp_node): 425 def add_component_node(self, comp_node):
402 comp = Component(self, comp_node) 426 comp = Component(self, comp_node)