OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
visibility_op.py
Go to the documentation of this file.
1 #------------------------------------------------------------------------------
2 # This file is part of the OpenStructure project <www.openstructure.org>
3 #
4 # Copyright (C) 2008-2011 by the OpenStructure authors
5 #
6 # This library is free software; you can redistribute it and/or modify it under
7 # the terms of the GNU Lesser General Public License as published by the Free
8 # Software Foundation; either version 3.0 of the License, or (at your option)
9 # any later version.
10 # This library is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 # details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this library; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #------------------------------------------------------------------------------
19 # -*- coding: utf-8 -*-
20 
21 from ost import info
22 from ost import gfx
23 from PyQt4 import QtGui
24 
26  VISIBLE_ATTRIBUTE_NAME = "Visible"
27  FLAGS_ATTRIBUTE_NAME = "Flags"
28 
29  def __init__(self, selection, flags, visible=False):
30  self.selection_ = selection
31  self.visible_ = visible
32  self.flags_ = flags
33 
34  def GetName(self):
35  return "Visible: %s"%str(self.IsVisible())
36 
37  def SetSelection(self, selection):
38  self.selection_ = selection
39 
40  def GetSelection(self):
41  return self.selection_
42 
43  def SetVisible(self, visible):
44  self.visible_ = visible
45 
46  def SetSelectionFlags(self, flags):
47  self.flags_ = flags
48 
49  def GetSelectionFlags(self):
50  return self.flags_
51 
52  def IsVisible(self):
53  return self.visible_
54 
55  def ApplyOn(self, entity):
56  if (entity is not None) and isinstance(entity, gfx.Entity):
57  entity.SetVisible(entity.view.Select(self.GetSelection(),self.GetSelectionFlags()),self.IsVisible())
58 
59  def ToInfo(self,group):
60  group.SetAttribute(VisibilityOp.VISIBLE_ATTRIBUTE_NAME, str(int(self.IsVisible())))
61  group.SetAttribute(VisibilityOp.FLAGS_ATTRIBUTE_NAME, str(self.GetSelectionFlags()))
62  group.SetTextData(str(self.GetSelection()))
63 
64  @staticmethod
65  def FromInfo(group):
66  visible_op = None
67  if group.HasAttribute(VisibilityOp.VISIBLE_ATTRIBUTE_NAME):
68  visible = bool(int(group.GetAttribute(VisibilityOp.VISIBLE_ATTRIBUTE_NAME)))
69  flags = 0
70  if group.HasAttribute(VisibilityOp.FLAGS_ATTRIBUTE_NAME):
71  flags = int(group.GetAttribute(VisibilityOp.FLAGS_ATTRIBUTE_NAME))
72  selection = group.GetTextData()
73  visible_op = VisibilityOp(selection,flags,visible)
74  return visible_op
graphical rendering of mol::EntityHandle entites
Definition: entity.hh:63