From: André Ribes Date: Wed, 9 Mar 2011 14:24:08 +0000 (+0100) Subject: Déplacement de enumerate dans daUtils X-Git-Tag: V6_4_0rc3~71 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e340cb9d27a1fa156432865252a8186e6066b4ba;p=modules%2Fadao.git Déplacement de enumerate dans daUtils --- diff --git a/src/daSalome/daGUI/daGuiImpl/Makefile.am b/src/daSalome/daGUI/daGuiImpl/Makefile.am index 4f2d529..4ea27e7 100644 --- a/src/daSalome/daGUI/daGuiImpl/Makefile.am +++ b/src/daSalome/daGUI/daGuiImpl/Makefile.am @@ -29,7 +29,6 @@ mypkgpython_PYTHON = \ adaoModuleHelper.py \ adaoStudyEditor.py \ adaoLogger.py \ - adaoCase.py \ - enumerate.py + adaoCase.py diff --git a/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py b/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py index 5eb13a9..61730ad 100644 --- a/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py +++ b/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py @@ -32,7 +32,7 @@ from PyQt4 import QtGui,QtCore import SalomePyQt sgPyQt = SalomePyQt.SalomePyQt() -from daGuiImpl.enumerate import Enumerate +from daUtils.enumerate import Enumerate from daGuiImpl.adaoCase import AdaoCase from daEficasWrapper.adaoEficasWrapper import AdaoEficasWrapper diff --git a/src/daSalome/daGUI/daGuiImpl/adaoStudyEditor.py b/src/daSalome/daGUI/daGuiImpl/adaoStudyEditor.py index 52bb64c..454ce6e 100644 --- a/src/daSalome/daGUI/daGuiImpl/adaoStudyEditor.py +++ b/src/daSalome/daGUI/daGuiImpl/adaoStudyEditor.py @@ -20,7 +20,7 @@ __author__="aribes/gboulant" -from enumerate import Enumerate +from daUtils.enumerate import Enumerate from salome.kernel import studyedit diff --git a/src/daSalome/daGUI/daGuiImpl/enumerate.py b/src/daSalome/daGUI/daGuiImpl/enumerate.py deleted file mode 100644 index 6584778..0000000 --- a/src/daSalome/daGUI/daGuiImpl/enumerate.py +++ /dev/null @@ -1,168 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE -# -# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# - -__author__ = "gboulant" -__date__ = "$1 avr. 2010 09:08:02$" - -class Enumerate(object): - """ - This class emulates a C-like enum for python. - """ - def __init__(self, keys, offset=0): - """ - Canonical constructor - @keys a list of keys string to be used as the enum symbols - """ - self._dict_keynumbers = {} - for number, key in enumerate(keys): - value = offset+number - setattr(self, key, value) - self._dict_keynumbers[key] = value - - - def contains(self, key): - """ - Return true if this enumerate contains the specified key - @key a key to test - """ - return (key in self._dict_keynumbers.keys()) - - def isValid(self, value): - return (value in self._dict_keynumbers.values()) - - def listkeys(self): - list = self._dict_keynumbers.keys() - list.sort() - return list - - def listvalues(self): - list = self._dict_keynumbers.values() - list.sort() - return list - -# -# ============================================================================== -# Basic use cases and unit test functions -# ============================================================================== -# - -def TEST_simple(): - TYPES_LIST=Enumerate([ - 'SEP', - 'OTHER' - ]) - print TYPES_LIST.listvalues() - return True - -def TEST_createFromList(): - codes = Enumerate([ - 'KERNEL', # This should take the value 0 - 'GUI', # This should take the value 1 - 'GEOM', # ... - 'MED', - 'SMESH']) - - print codes.KERNEL - print codes.GEOM - if (codes.KERNEL == 0 and codes.GEOM == 2): - return True - else: - return False - -def TEST_createFromString(): - aList = "KERNEL GUI GEOM MED" - - codes = Enumerate(aList.split()) - - print codes.KERNEL - print codes.GEOM - if (codes.KERNEL == 0 and codes.GEOM == 2): - return True - else: - return False - -def TEST_contains(): - codes = Enumerate([ - 'KERNEL', # This should take the value 0 - 'GUI', # This should take the value 1 - 'GEOM', # ... - 'MED', - 'SMESH']) - - print "VISU in enumerate?", codes.contains("VISU") - if ( not codes.contains("VISU") ): - return True - else: - return False - -def TEST_isValid(): - codes = Enumerate([ - 'KERNEL', # This should take the value 0 - 'GUI', # This should take the value 1 - 'GEOM', # ... - 'MED', - 'SMESH']) - - if ( not codes.isValid(23) ): - return True - else: - return False - -def TEST_offset(): - codes = Enumerate([ - 'KERNEL', # This should take the value 0 - 'GUI', # This should take the value 1 - 'GEOM', # ... - 'MED', - 'SMESH'], offset=20) - - print codes.KERNEL - print codes.GEOM - if (codes.KERNEL == 20 and codes.GEOM == 22): - return True - else: - return False - -def TEST_listvalues(): - codes = Enumerate([ - 'KERNEL', # This should take the value 0 - 'GUI', # This should take the value 1 - 'GEOM', # ... - 'MED', - 'SMESH'], offset=20) - - print codes.listvalues() - if codes.listvalues() != [20,21,22,23,24]: - return False - return True - - -if __name__ == "__main__": - import unittester - unittester.run("enumerate","TEST_simple") - unittester.run("enumerate","TEST_createFromList") - unittester.run("enumerate","TEST_createFromString") - unittester.run("enumerate","TEST_contains") - unittester.run("enumerate","TEST_isValid") - unittester.run("enumerate","TEST_offset") - unittester.run("enumerate","TEST_listvalues") diff --git a/src/daSalome/daGUI/daUtils/Makefile.am b/src/daSalome/daGUI/daUtils/Makefile.am index db22a45..9315c40 100644 --- a/src/daSalome/daGUI/daUtils/Makefile.am +++ b/src/daSalome/daGUI/daUtils/Makefile.am @@ -23,5 +23,6 @@ mypkgpythondir =$(salomepythondir)/daUtils mypkgpython_PYTHON = \ __init__.py \ - adaoEficasEvent.py + adaoEficasEvent.py \ + enumerate.py diff --git a/src/daSalome/daGUI/daUtils/adaoEficasEvent.py b/src/daSalome/daGUI/daUtils/adaoEficasEvent.py index f739253..769aec1 100644 --- a/src/daSalome/daGUI/daUtils/adaoEficasEvent.py +++ b/src/daSalome/daGUI/daUtils/adaoEficasEvent.py @@ -30,7 +30,7 @@ class DevelException(Exception): # Interface of an eficas observer (for implementing the subject/observer pattern) # ============================================================================== # -from daGuiImpl.enumerate import Enumerate +from enumerate import Enumerate class EficasObserver: """ diff --git a/src/daSalome/daGUI/daUtils/enumerate.py b/src/daSalome/daGUI/daUtils/enumerate.py new file mode 100644 index 0000000..6584778 --- /dev/null +++ b/src/daSalome/daGUI/daUtils/enumerate.py @@ -0,0 +1,168 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +# +# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +__author__ = "gboulant" +__date__ = "$1 avr. 2010 09:08:02$" + +class Enumerate(object): + """ + This class emulates a C-like enum for python. + """ + def __init__(self, keys, offset=0): + """ + Canonical constructor + @keys a list of keys string to be used as the enum symbols + """ + self._dict_keynumbers = {} + for number, key in enumerate(keys): + value = offset+number + setattr(self, key, value) + self._dict_keynumbers[key] = value + + + def contains(self, key): + """ + Return true if this enumerate contains the specified key + @key a key to test + """ + return (key in self._dict_keynumbers.keys()) + + def isValid(self, value): + return (value in self._dict_keynumbers.values()) + + def listkeys(self): + list = self._dict_keynumbers.keys() + list.sort() + return list + + def listvalues(self): + list = self._dict_keynumbers.values() + list.sort() + return list + +# +# ============================================================================== +# Basic use cases and unit test functions +# ============================================================================== +# + +def TEST_simple(): + TYPES_LIST=Enumerate([ + 'SEP', + 'OTHER' + ]) + print TYPES_LIST.listvalues() + return True + +def TEST_createFromList(): + codes = Enumerate([ + 'KERNEL', # This should take the value 0 + 'GUI', # This should take the value 1 + 'GEOM', # ... + 'MED', + 'SMESH']) + + print codes.KERNEL + print codes.GEOM + if (codes.KERNEL == 0 and codes.GEOM == 2): + return True + else: + return False + +def TEST_createFromString(): + aList = "KERNEL GUI GEOM MED" + + codes = Enumerate(aList.split()) + + print codes.KERNEL + print codes.GEOM + if (codes.KERNEL == 0 and codes.GEOM == 2): + return True + else: + return False + +def TEST_contains(): + codes = Enumerate([ + 'KERNEL', # This should take the value 0 + 'GUI', # This should take the value 1 + 'GEOM', # ... + 'MED', + 'SMESH']) + + print "VISU in enumerate?", codes.contains("VISU") + if ( not codes.contains("VISU") ): + return True + else: + return False + +def TEST_isValid(): + codes = Enumerate([ + 'KERNEL', # This should take the value 0 + 'GUI', # This should take the value 1 + 'GEOM', # ... + 'MED', + 'SMESH']) + + if ( not codes.isValid(23) ): + return True + else: + return False + +def TEST_offset(): + codes = Enumerate([ + 'KERNEL', # This should take the value 0 + 'GUI', # This should take the value 1 + 'GEOM', # ... + 'MED', + 'SMESH'], offset=20) + + print codes.KERNEL + print codes.GEOM + if (codes.KERNEL == 20 and codes.GEOM == 22): + return True + else: + return False + +def TEST_listvalues(): + codes = Enumerate([ + 'KERNEL', # This should take the value 0 + 'GUI', # This should take the value 1 + 'GEOM', # ... + 'MED', + 'SMESH'], offset=20) + + print codes.listvalues() + if codes.listvalues() != [20,21,22,23,24]: + return False + return True + + +if __name__ == "__main__": + import unittester + unittester.run("enumerate","TEST_simple") + unittester.run("enumerate","TEST_createFromList") + unittester.run("enumerate","TEST_createFromString") + unittester.run("enumerate","TEST_contains") + unittester.run("enumerate","TEST_isValid") + unittester.run("enumerate","TEST_offset") + unittester.run("enumerate","TEST_listvalues")