Utils.py

Go to the documentation of this file.
00001 """
00002 Copyright 2008 Free Software Foundation, Inc.
00003 This file is part of GNU Radio
00004 
00005 GNU Radio Companion is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 GNU Radio Companion is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
00018 """
00019 ##@package grc.gui.Utils
00020 #Utility methods and classes.
00021 #@author Josh Blum
00022 
00023 from UserDict import DictMixin
00024 
00025 class odict(DictMixin):
00026 
00027         def __init__(self, d={}):
00028                 self._keys = list(d.keys())
00029                 self._data = dict(d.copy())
00030 
00031         def __setitem__(self, key, value):
00032                 if key not in self._data:
00033                         self._keys.append(key)
00034                 self._data[key] = value
00035 
00036         def __getitem__(self, key):
00037                 return self._data[key]
00038 
00039         def __delitem__(self, key):
00040                 del self._data[key]
00041                 self._keys.remove(key)
00042 
00043         def keys(self):
00044                 return list(self._keys)
00045 
00046         def copy(self):
00047                 copy_dict = odict()
00048                 copy_dict._data = self._data.copy()
00049                 copy_dict._keys = list(self._keys)
00050                 return copy_dict
00051 
00052 def exists_or_else(d, key, alt):
00053         if d.has_key(key): return d[key]
00054         else: return alt
00055 
00056 def listify(d, key):
00057         obj = exists_or_else(d, key, [])
00058         if isinstance(obj, list): return obj
00059         return [obj]
00060 

Generated on Sat Aug 23 02:00:11 2008 for GNU Radio Companion by  doxygen 1.5.4