Mercurial > MadButterfly
comparison pyink/domview.py @ 1326:0a2034f490e5
Show/hide components by showing/hiding component group.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Sun, 30 Jan 2011 21:58:57 +0800 |
parents | ffbbd3aa218d |
children | ab281ec3eeec |
comparison
equal
deleted
inserted
replaced
1325:e155064f6c7e | 1326:0a2034f490e5 |
---|---|
311 layer_group = doc.createElement('svg:g') | 311 layer_group = doc.createElement('svg:g') |
312 layer_group.setAttribute('id', gid) | 312 layer_group.setAttribute('id', gid) |
313 layer_group.setAttribute('inkscape:label', layer_name) | 313 layer_group.setAttribute('inkscape:label', layer_name) |
314 layer_group.setAttribute('inkscape:groupmode', 'layer') | 314 layer_group.setAttribute('inkscape:groupmode', 'layer') |
315 comp_group.appendChild(layer_group) | 315 comp_group.appendChild(layer_group) |
316 | |
316 return layer_group | 317 return layer_group |
317 | 318 |
318 ## \brief Return group of specified layer in a component. | 319 ## \brief Return group of specified layer in a component. |
319 # | 320 # |
320 # This is here for getting layer group without switch current | 321 # This is here for getting layer group without switch current |
329 return [comp.name() for comp in self._components] | 330 return [comp.name() for comp in self._components] |
330 | 331 |
331 def has_component(self, name): | 332 def has_component(self, name): |
332 return name in self._comp_names | 333 return name in self._comp_names |
333 | 334 |
335 def hide_component(self, comp_name): | |
336 if comp_name == 'main': | |
337 comp = self._get_component(comp_name) | |
338 for layer in comp.layers: | |
339 group = layer.group | |
340 group.setAttribute('style', 'display: none') | |
341 pass | |
342 return | |
343 | |
344 comp_group = self.get_component_group(comp_name) | |
345 comp_group.setAttribute('style', 'display: none') | |
346 pass | |
347 | |
348 def show_component(self, comp_name): | |
349 if comp_name == 'main': | |
350 comp = self._get_component(comp_name) | |
351 for layer in comp.layers: | |
352 group = layer.group | |
353 group.setAttribute('style', '') | |
354 pass | |
355 return | |
356 | |
357 comp_group = self.get_component_group(comp_name) | |
358 comp_group.setAttribute('style', '') | |
359 pass | |
360 | |
334 def switch_component(self, comp_name): | 361 def switch_component(self, comp_name): |
335 old_comp = self._cur_comp | 362 old_comp = self._cur_comp |
336 | 363 |
337 comp = self._get_component(comp_name) | 364 comp = self._get_component(comp_name) |
338 self._cur_comp = comp | 365 self._cur_comp = comp |
342 self._layers_parent = self.get_component_group(comp_name) | 369 self._layers_parent = self.get_component_group(comp_name) |
343 | 370 |
344 first_name = comp.all_timeline_names()[0] | 371 first_name = comp.all_timeline_names()[0] |
345 self.switch_timeline(first_name) | 372 self.switch_timeline(first_name) |
346 | 373 |
347 # Hide layers in old component | 374 self.hide_component(old_comp.name()) |
348 for layer in old_comp.layers: | 375 self.show_component(comp.name()) |
349 group = layer.group | |
350 group.setAttribute('style', 'display: none') | |
351 pass | |
352 | |
353 # Show layers in new component | |
354 for layer in comp.layers: | |
355 group = layer.group | |
356 group.setAttribute('style', '') | |
357 pass | |
358 pass | 376 pass |
359 | 377 |
360 def add_component(self, comp_name): | 378 def add_component(self, comp_name): |
361 if self.has_component(comp_name): | 379 if self.has_component(comp_name): |
362 raise ValueError, \ | 380 raise ValueError, \ |
365 comp_group = self._create_component_group() | 383 comp_group = self._create_component_group() |
366 comp_group_id = comp_group.getAttribute('id') | 384 comp_group_id = comp_group.getAttribute('id') |
367 comp_node = self._create_component_node(comp_name, comp_group_id) | 385 comp_node = self._create_component_node(comp_name, comp_group_id) |
368 | 386 |
369 layer_group = self._create_comp_layer_group(comp_group, 'Layer1') | 387 layer_group = self._create_comp_layer_group(comp_group, 'Layer1') |
370 layer_group.setAttribute('style', 'display: none') | |
371 | 388 |
372 comp = Component(self, comp_node) | 389 comp = Component(self, comp_node) |
373 comp.parse_timelines() | 390 comp.parse_timelines() |
374 | 391 |
375 layer = Layer(layer_group) | 392 layer = Layer(layer_group) |
376 comp.layers.append(layer) | 393 comp.layers.append(layer) |
377 | 394 |
378 self._components.append(comp) | 395 self._components.append(comp) |
379 self._comp_names.add(comp_name) | 396 self._comp_names.add(comp_name) |
397 | |
398 self.hide_component(comp_name) | |
380 pass | 399 pass |
381 | 400 |
382 def add_component_node(self, comp_node): | 401 def add_component_node(self, comp_node): |
383 comp = Component(self, comp_node) | 402 comp = Component(self, comp_node) |
384 comp_name = comp.name() | 403 comp_name = comp.name() |