File indexing completed on 2024-03-24 04:04:37
0001 # -*- coding: utf-8 -*- 0002 0003 """ 0004 Copyright (C) 2008-2016 Wolfgang Rohdewald <wolfgang@rohdewald.de> 0005 0006 SPDX-License-Identifier: GPL-2.0 0007 0008 """ 0009 0010 # pylint: disable=invalid-name 0011 0012 class Wind: 0013 """we want to use an wind for indices. 0014 0015 char is the wind as a char (native string) 0016 svgName is the name of the wind in the SVG files. 0017 """ 0018 all = list() 0019 all4 = list() 0020 0021 tile = None 0022 marker = None 0023 0024 def __new__(cls, *args): 0025 if not Wind.all: 0026 Wind.all = [object.__new__(cls) for cls in (_East, _South, _West, _North, _NoWind)] 0027 Wind.all4 = list(Wind.all[:4]) 0028 if len(args) == 1: 0029 windIdent = args[0] 0030 assert cls is Wind, '{}({}) is illegal'.format(cls.__name__, windIdent) 0031 windIdx = 'eswn'.index(windIdent.lower()) 0032 return Wind.all[windIdx] 0033 assert not args and cls is not Wind, 'Wind() must have exactly one argument' 0034 0035 for result in Wind.all: 0036 if isinstance(result, cls): 0037 return result 0038 raise Exception('Wind.__new__ failed badly') 0039 0040 def __eq__(self, other): 0041 if not other: 0042 return False 0043 if isinstance(other, self.__class__): 0044 return True 0045 if isinstance(other, Wind): 0046 return False 0047 try: 0048 return str(self.char) == other.upper() 0049 except AttributeError: 0050 return False 0051 0052 def __gt__(self, other): 0053 assert isinstance(other, Wind) 0054 return self.__index__() > other.__index__() 0055 0056 def __lt__(self, other): 0057 assert isinstance(other, Wind) 0058 return self.__index__() < other.__index__() 0059 0060 def __ge__(self, other): 0061 assert isinstance(other, Wind) 0062 return self.__index__() >= other.__index__() 0063 0064 def __le__(self, other): 0065 assert isinstance(other, Wind) 0066 return self.__index__() <= other.__index__() 0067 0068 def __hash__(self): 0069 return self.__index__() 0070 0071 def __str__(self): 0072 return self.char 0073 0074 def __repr__(self): 0075 return 'Wind.{}'.format(self.char) 0076 0077 class _East(Wind): 0078 """East""" 0079 char = 'E' 0080 svgName = 'WIND_3' 0081 markerSvgName = 'g4657' # WIND_2 etc have a border 0082 0083 def __index__(self): 0084 return 0 0085 0086 class _South(Wind): 0087 """South""" 0088 char = 'S' 0089 svgName = 'WIND_2' 0090 markerSvgName = 'g3980' 0091 0092 def __index__(self): 0093 return 1 0094 0095 class _West(Wind): 0096 """West""" 0097 char = 'W' 0098 svgName = 'WIND_4' 0099 markerSvgName = 'g3192' 0100 0101 def __index__(self): 0102 return 2 0103 0104 class _North(Wind): 0105 """North""" 0106 char = 'N' 0107 svgName = 'WIND_1' 0108 markerSvgName = 'g4290' 0109 0110 def __index__(self): 0111 return 3 0112 0113 class _NoWind(Wind): 0114 """no wind""" 0115 char = 'X' 0116 svgName = None 0117 0118 def __index__(self): 0119 return 4 0120 0121 East = _East() 0122 South = _South() 0123 West = _West() 0124 North = _North()