OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
loader_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-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 gui
22 from ost import gfx
23 from ost import info
24 from PyQt4 import QtCore, QtGui
25 from immutable_loader_info_handler import ImmutableLoaderInfoHandler
26 
27 #Generic Loader Info Handler
28 class LoaderInfoHandler(ImmutableLoaderInfoHandler):
29 
30  def __init__(self, file_name):
31  ImmutableLoaderInfoHandler.__init__(self, file_name)
32 
33  def StoreLoader(self,name, loader):
34  group = self.loaders_.CreateGroup(ImmutableLoaderInfoHandler.LOADER_GROUP_NAME)
35  group.SetAttribute(ImmutableLoaderInfoHandler.NAME_ATTRIBUTE_NAME, str(name))
36  loader.ToInfo(group)
37  self.handle_.Export(self.file_name_)
38 
39  def RemoveLoader(self, name):
40  group_list = self.loaders_.GetGroups(ImmutableLoaderInfoHandler.LOADER_GROUP_NAME)
41  group_to_del = None
42  for group in group_list:
43  if group.HasAttribute(ImmutableLoaderInfoHandler.NAME_ATTRIBUTE_NAME):
44  groupname = group.GetAttribute(ImmutableLoaderInfoHandler.NAME_ATTRIBUTE_NAME)
45  if name == groupname:
46  group_to_del = group
47  break
48 
49  if group_to_del != None:
50  self.loaders_.Remove(group_to_del)
51  self.handle_.Export(self.file_name_)
52 
53  def RenameLoader(self, old, new):
54  group_list = self.loaders_.GetGroups(ImmutableLoaderInfoHandler.LOADER_GROUP_NAME)
55  for group in group_list:
56  if group.HasAttribute(ImmutableLoaderInfoHandler.NAME_ATTRIBUTE_NAME):
57  groupname = group.GetAttribute(ImmutableLoaderInfoHandler.NAME_ATTRIBUTE_NAME)
58  if old == groupname:
59  group.SetAttribute(ImmutableLoaderInfoHandler.NAME_ATTRIBUTE_NAME, new)
60  self.handle_.Export(self.file_name_)