speedchat: slice functions are deprecated in python 3.x

This commit is contained in:
John Cote 2020-01-01 18:26:45 -05:00
parent 987716f94c
commit fa882f5f48

View file

@ -362,11 +362,20 @@ class SCMenu(SCObject, NodePath):
return len(self.__members) return len(self.__members)
def __getitem__(self, index): def __getitem__(self, index):
if isinstance(index, slice):
if isinstance(self.__members, tuple):
self.__members = list(self.__members)
return self.__members[index.start:index.stop]
return self.__members[index] return self.__members[index]
def __setitem__(self, index, value): def __setitem__(self, index, value):
if isinstance(self.__members, tuple): if isinstance(self.__members, tuple):
self.__members = list(self.__members) self.__members = list(self.__members)
if isinstance(index, slice):
removedMembers = self.__members[index.start:index.stop]
self.__members[index.start:index.stop] = list(value)
self.privMemberListChanged(added=list(value), removed=removedMembers)
else:
removedMember = self.__members[index] removedMember = self.__members[index]
self.__members[index] = value self.__members[index] = value
self.privMemberListChanged(added=[value], removed=[removedMember]) self.privMemberListChanged(added=[value], removed=[removedMember])
@ -374,29 +383,15 @@ class SCMenu(SCObject, NodePath):
def __delitem__(self, index): def __delitem__(self, index):
if isinstance(self.__members, tuple): if isinstance(self.__members, tuple):
self.__members = list(self.__members) self.__members = list(self.__members)
if isinstance(index, slice):
removedMembers = self.__members[index.start:index.stop]
del self.__members[index.start:index.stop]
self.privMemberListChanged(removed=removedMembers)
else:
removedMember = self.__members[index] removedMember = self.__members[index]
del self.__members[index] del self.__members[index]
self.privMemberListChanged(removed=[removedMember]) self.privMemberListChanged(removed=[removedMember])
def __getslice__(self, i, j):
if isinstance(self.__members, tuple):
self.__members = list(self.__members)
return self.__members[i:j]
def __setslice__(self, i, j, s):
if isinstance(self.__members, tuple):
self.__members = list(self.__members)
removedMembers = self.__members[i:j]
self.__members[i:j] = list(s)
self.privMemberListChanged(added=list(s), removed=removedMembers)
def __delslice__(self, i, j):
if isinstance(self.__members, tuple):
self.__members = list(self.__members)
removedMembers = self.__members[i:j]
del self.__members[i:j]
self.privMemberListChanged(removed=removedMembers)
def __iadd__(self, other): def __iadd__(self, other):
if isinstance(self.__members, tuple): if isinstance(self.__members, tuple):
self.__members = list(self.__members) self.__members = list(self.__members)