OpenStructure
Loading...
Searching...
No Matches
gradient_info_handler.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-2020 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
21from ost import gui
22from ost import gfx
23from ost import info
24from PyQt5 import QtCore
25from .immutable_gradient_info_handler import ImmutableGradientInfoHandler
26
27#Gradient Info Handler
29 def __init__(self, fileName):
30 ImmutableGradientInfoHandler.__init__(self, fileName)
31
32 def StoreQGradient(self,gradient,name):
33 group = self.gradients_.CreateGroup(self.GRADIENT_GROUP_NAME)
34 group.SetAttribute(self.NAME_ATTRIBUTE_NAMENAME_ATTRIBUTE_NAME, name)
35 gfx_gradient = self.ConvertToGfxGradient(gradient)
36
37 gfx_gradient.GradientToInfo(group)
38 self.handle_.Export(self.FILE_NAMEFILE_NAME)
39
40 def RemoveGradient(self, name):
41 group_list = self.gradients_.GetGroups(self.GRADIENT_GROUP_NAME)
42 for group in group_list:
43 if group.HasAttribute(self.NAME_ATTRIBUTE_NAMENAME_ATTRIBUTE_NAME):
44 groupname = group.GetAttribute(self.NAME_ATTRIBUTE_NAMENAME_ATTRIBUTE_NAME)
45 if name == groupname:
46 groupToDel = group
47 break
48
49 if groupToDel != None:
50 self.gradients_.Remove(groupToDel)
51 self.handle_.Export(self.FILE_NAMEFILE_NAME)
52
53 def RenameGradient(self, old, new):
54 group_list = self.gradients_.GetGroups(self.GRADIENT_GROUP_NAME)
55 for group in group_list:
56 if group.HasAttribute(self.NAME_ATTRIBUTE_NAMENAME_ATTRIBUTE_NAME):
57 groupname = group.GetAttribute(self.NAME_ATTRIBUTE_NAMENAME_ATTRIBUTE_NAME)
58 if old == groupname:
59 group.SetAttribute(self.NAME_ATTRIBUTE_NAMENAME_ATTRIBUTE_NAME, new)
60 self.handle_.Export(self.FILE_NAMEFILE_NAME)