OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
preset_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 
21 from ost import gui
22 from ost import gfx
23 from ost import info
24 from .immutable_preset_info_handler import ImmutablePresetInfoHandler
25 
26 #Preset Info Handler
27 class PresetInfoHandler(ImmutablePresetInfoHandler):
28  def __init__(self, file_name):
29  ImmutablePresetInfoHandler.__init__(self, file_name)
30 
31  def StorePreset(self,preset):
32  group = self.presets_.CreateGroup(ImmutablePresetInfoHandler.PRESET_GROUP_NAME)
33  preset.ToInfo(group)
34  self.handle_.Export(self.file_name_)
35 
36  def RemovePreset(self, name):
37  group_list = self.presets_.GetGroups(ImmutablePresetInfoHandler.PRESET_GROUP_NAME)
38  group_to_del = None
39  for group in group_list:
40  if group.HasAttribute(ImmutablePresetInfoHandler.NAME_ATTRIBUTE_NAME):
41  groupname = group.GetAttribute(ImmutablePresetInfoHandler.NAME_ATTRIBUTE_NAME)
42  if name == groupname:
43  group_to_del = group
44  break
45 
46  if group_to_del != None:
47  self.presets_.Remove(group_to_del)
48  self.handle_.Export(self.file_name_)
49 
50  def RenamePreset(self, old, new):
51  group_list = self.presets_.GetGroups(ImmutablePresetInfoHandler.PRESET_GROUP_NAME)
52  for group in group_list:
53  if group.HasAttribute(ImmutablePresetInfoHandler.NAME_ATTRIBUTE_NAME):
54  groupname = group.GetAttribute(ImmutablePresetInfoHandler.NAME_ATTRIBUTE_NAME)
55  if old == groupname:
56  group.SetAttribute(ImmutablePresetInfoHandler.NAME_ATTRIBUTE_NAME, new)
57  self.handle_.Export(self.file_name_)