Implement working character associations with SSO character

This commit is contained in:
Ryan Holmes
2018-03-14 17:53:48 -04:00
parent f52f39984f
commit 9d379d966c
5 changed files with 77 additions and 17 deletions

View File

@@ -205,11 +205,14 @@ class HandledImplantBoosterList(HandledList):
HandledList.append(self, thing)
class HandledSsoCharacterList(HandledList):
class HandledSsoCharacterList(list):
def append(self, character):
for x in self:
print(x)
HandledList.append(self, character)
old = next((x for x in self if x.client == character.client), None)
if old is not None:
pyfalog.warning("Removing SSO Character with same hash: {}".format(repr(old)))
list.remove(self, old)
list.append(self, character)
class HandledProjectedModList(HandledList):

View File

@@ -163,6 +163,18 @@ class Character(object):
def name(self, name):
self.savedName = name
def setSsoCharacter(self, character, clientHash):
if character is not None:
self.__ssoCharacters.append(character)
else:
for x in self.__ssoCharacters:
if x.client == clientHash:
self.__ssoCharacters.remove(x)
def getSsoCharacter(self, clientHash):
return next((x for x in self.__ssoCharacters if x.client == clientHash), None)
@property
def alphaCloneID(self):
return self.__alphaCloneID

View File

@@ -49,3 +49,9 @@ class SsoCharacter(object):
self.accessTokenExpires - datetime.datetime.utcnow()
).total_seconds()
}
def __repr__(self):
return "SsoCharacter(ID={}, name={}, client={}) at {}".format(
self.ID, self.characterName, self.client, hex(id(self))
)

View File

@@ -33,6 +33,7 @@ from gui.builtinViews.implantEditor import BaseImplantEditorView
from gui.builtinViews.entityEditor import EntityEditor, BaseValidator, TextEntryValidatedDialog
from service.fit import Fit
from service.character import Character
from service.esi import Esi
from service.network import AuthenticationError, TimeoutError
from service.market import Market
from logbook import Logger
@@ -174,7 +175,7 @@ class CharacterEditor(wx.Frame):
self.viewsNBContainer.AddPage(self.sview, "Skills")
self.viewsNBContainer.AddPage(self.iview, "Implants")
self.viewsNBContainer.AddPage(self.aview, "API")
self.viewsNBContainer.AddPage(self.aview, "EVE SSO")
mainSizer.Add(self.viewsNBContainer, 1, wx.EXPAND | wx.ALL, 5)
@@ -746,7 +747,6 @@ class APIView(wx.Panel):
fgSizerInput.Add(self.m_staticCharText, 0, wx.ALL | wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, 5)
self.charChoice = wx.Choice(self, wx.ID_ANY, style=0)
self.charChoice.Append("No Selection", 0)
fgSizerInput.Add(self.charChoice, 1, wx.ALL | wx.EXPAND, 5)
pmainSizer.Add(fgSizerInput, 0, wx.EXPAND, 5)
@@ -759,28 +759,51 @@ class APIView(wx.Panel):
self.charEditor.entityEditor.Bind(wx.EVT_CHOICE, self.charChanged)
self.charChoice.Bind(wx.EVT_CHOICE, self.ssoCharChanged)
self.SetSizer(pmainSizer)
self.Layout()
self.charChanged(None)
def charChanged(self, event):
def ssoCharChanged(self, event):
sChar = Character.getInstance()
activeChar = self.charEditor.entityEditor.getActiveEntity()
sChar.setSsoCharacter(activeChar.ID, self.getActiveCharacter())
event.Skip()
ID, key, char, chars = sChar.getApiDetails(activeChar.ID)
def getActiveCharacter(self):
selection = self.charChoice.GetCurrentSelection()
return self.charChoice.GetClientData(selection) if selection is not -1 else None
def charChanged(self, event):
sChar = Character.getInstance()
sEsi = Esi.getInstance()
activeChar = self.charEditor.entityEditor.getActiveEntity()
sso = sChar.getSsoCharacter(activeChar.ID)
ssoChars = sEsi.getSsoCharacters()
self.charChoice.Clear()
if chars:
for charName in chars:
self.charChoice.Append(charName)
self.charChoice.SetStringSelection(char)
self.charChoice.Enable(True)
else:
self.charChoice.Append("No characters...", 0)
self.charChoice.SetSelection(0)
self.charChoice.Enable(False)
noneID = self.charChoice.Append("None", None)
for char in ssoChars:
currId = self.charChoice.Append(char.characterName, char.ID)
if sso is not None and char.ID == sso.ID:
self.charChoice.SetSelection(currId)
if sso is None:
self.charChoice.SetSelection(noneID)
#
# if chars:
# for charName in chars:
# self.charChoice.Append(charName)
# self.charChoice.SetStringSelection(char)
# else:
# self.charChoice.Append("No characters...", 0)
# self.charChoice.SetSelection(0)
#
if activeChar.name in ("All 0", "All 5"):
self.Enable(False)
self.stDisabledTip.Show()

View File

@@ -347,6 +347,22 @@ class Character(object):
chars = None
return char.apiID or "", char.apiKey or "", char.defaultChar or "", chars or []
@staticmethod
def getSsoCharacter(charID):
char = eos.db.getCharacter(charID)
sso = char.getSsoCharacter(config.getClientSecret())
return sso
@staticmethod
def setSsoCharacter(charID, ssoCharID):
char = eos.db.getCharacter(charID)
if ssoCharID is not None:
sso = eos.db.getSsoCharacter(ssoCharID, config.getClientSecret())
char.setSsoCharacter(sso, config.getClientSecret())
else:
char.setSsoCharacter(None, config.getClientSecret())
eos.db.commit()
def apiFetch(self, charID, callback):
thread = UpdateAPIThread(charID, (self.apiFetchCallback, callback))
thread.start()