Merge pull request #7 from blitzmann/master

Character API improvements
This commit is contained in:
Anton Vorobyov
2013-08-31 04:30:35 -07:00
5 changed files with 100 additions and 42 deletions

View File

@@ -30,6 +30,8 @@ characters_table = Table("characters", saveddata_meta,
Column("name", String, nullable = False),
Column("apiID", Integer),
Column("apiKey", String),
Column("defaultChar", Integer),
Column("chars", String, nullable = True),
Column("defaultLevel", Integer, nullable=True),
Column("ownerID", ForeignKey("users.ID"), nullable = True))

View File

@@ -150,10 +150,9 @@ class CharacterEditor(wx.Frame):
self.btnDelete.Enable(False)
self.aview.inputID.Enable(False)
self.aview.inputKey.Enable(False)
self.aview.charChoice.Enable(False)
self.aview.btnFetchCharList.Enable(False)
self.aview.btnFetchCharList.Show()
self.aview.btnFetchSkills.Hide()
self.aview.charList.Hide()
self.aview.btnFetchSkills.Enable(False)
self.aview.stStatus.SetLabel("")
self.aview.Layout()
@@ -163,9 +162,7 @@ class CharacterEditor(wx.Frame):
self.aview.inputID.Enable(True)
self.aview.inputKey.Enable(True)
self.aview.btnFetchCharList.Enable(True)
self.aview.btnFetchCharList.Show()
self.aview.btnFetchSkills.Hide()
self.aview.charList.Hide()
self.aview.btnFetchSkills.Enable(True)
self.aview.stStatus.SetLabel("")
self.aview.Layout()
@@ -560,29 +557,33 @@ class APIView (wx.Panel):
self.inputKey = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0)
fgSizerInput.Add(self.inputKey, 0, wx.ALL | wx.EXPAND, 5)
pmainSizer.Add(fgSizerInput, 0, wx.EXPAND, 5)
self.m_staticCharText = wx.StaticText(self, wx.ID_ANY, u"Character:", wx.DefaultPosition, wx.DefaultSize, 0)
self.m_staticCharText.Wrap(-1)
fgSizerInput.Add(self.m_staticCharText, 0, wx.ALL | wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, 5)
self.btnFetchCharList = wx.Button(self, wx.ID_ANY, u"Fetch Character List")
pmainSizer.Add(self.btnFetchCharList, 0, wx.ALL, 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)
self.charChoice.Enable(False)
pmainSizer.Add(fgSizerInput, 0, wx.EXPAND, 5)
btnSizer = wx.FlexGridSizer(3, 2, 0, 0)
btnSizer.AddGrowableCol(1)
btnSizer.SetFlexibleDirection(wx.BOTH)
btnSizer.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)
self.btnFetchCharList = wx.Button(self, wx.ID_ANY, u"Get Characters")
btnSizer.Add(self.btnFetchCharList, 0, wx.ALL, 2)
self.btnFetchCharList.Bind(wx.EVT_BUTTON, self.fetchCharList)
self.charList = wx.ListCtrl(self, wx.ID_ANY, style=wx.LC_REPORT | wx.BORDER_NONE | wx.LC_SINGLE_SEL)
pmainSizer.Add(self.charList, 0, wx.EXPAND| wx.ALL, 5)
info = wx.ListItem()
info.m_text = "Character"
info.m_mask = wx.LIST_MASK_TEXT
self.charList.InsertColumnInfo(0, info)
self.charList.SetMinSize(wx.Size(-1, 100))
self.charList.Hide()
self.btnFetchSkills = wx.Button(self, wx.ID_ANY, u"Fetch Skills")
pmainSizer.Add(self.btnFetchSkills, 0, wx.ALL, 5)
self.btnFetchSkills.Hide()
btnSizer.Add(self.btnFetchSkills, 0, wx.ALL, 2)
self.btnFetchSkills.Bind(wx.EVT_BUTTON, self.fetchSkills)
self.btnFetchSkills.Enable(False)
pmainSizer.Add(btnSizer, 0, wx.EXPAND, 5)
self.stAPITip = wx.StaticText( self, wx.ID_ANY, u"You can create a key here (only character sheet access is needed):", wx.DefaultPosition, wx.DefaultSize, 0 )
self.stAPITip.Wrap( -1 )
@@ -606,9 +607,25 @@ class APIView (wx.Panel):
def charChanged(self, event):
cChar = service.Character.getInstance()
ID, key = cChar.getApiDetails(self.Parent.Parent.getActiveCharacter())
ID, key, char, chars = cChar.getApiDetails(self.Parent.Parent.getActiveCharacter())
self.inputID.SetValue(str(ID))
self.inputKey.SetValue(key)
self.charChoice.Clear()
if chars:
for charName in chars:
i = self.charChoice.Append(charName)
self.charChoice.SetStringSelection(char)
self.charChoice.Enable(True)
self.btnFetchSkills.Enable(True)
else:
self.charChoice.Append("No characters...", 0)
self.charChoice.SetSelection(0)
self.charChoice.Enable(False)
self.btnFetchSkills.Enable(False)
if event is not None:
event.Skip()
@@ -620,33 +637,28 @@ class APIView (wx.Panel):
cChar = service.Character.getInstance()
list = cChar.charList(self.Parent.Parent.getActiveCharacter(), self.inputID.GetLineText(0), self.inputKey.GetLineText(0))
self.charList.DeleteAllItems()
if not list:
self.stStatus.SetLabel("Unable to fetch characters list from EVE API!")
return
self.charChoice.Clear()
for charName in list:
self.charList.InsertStringItem(sys.maxint, charName)
self.charList.SetItemState(0,wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)
self.charList.SetColumnWidth(0, wx.LIST_AUTOSIZE_USEHEADER)
self.charList.Show()
self.btnFetchCharList.Hide()
self.btnFetchSkills.Show()
i = self.charChoice.Append(charName)
self.btnFetchSkills.Enable(True)
self.charChoice.Enable(True)
self.Layout()
self.charList.SetFocus()
self.charChoice.SetSelection(0)
def fetchSkills(self, event):
item = self.charList.GetNextItem(-1, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)
charName = self.charList.GetItemText(item)
charName = self.charChoice.GetString(self.charChoice.GetSelection())
if charName:
try:
cChar = service.Character.getInstance()
cChar.apiFetch(self.Parent.Parent.getActiveCharacter(), charName)
self.stStatus.SetLabel("Successfully fetched %s\'s skills from EVE API." % charName)
except:
self.stStatus.SetLabel("Unable to retrieve %s\'s skills!" % charName)
self.stStatus.SetLabel("Unable to retrieve %s\'s skills!" % charName)

View File

@@ -43,10 +43,23 @@ class CharacterSelection(wx.Panel):
mainSizer.Add(self.skillReqsStaticBitmap, 0, wx.ALIGN_CENTER_VERTICAL | wx.TOP | wx.RIGHT | wx.LEFT, 3)
self.cleanSkills = bitmapLoader.getBitmap("skill_big", "icons")
self.redSkills = bitmapLoader.getBitmap("skillRed_big", "icons")
self.redSkills = bitmapLoader.getBitmap("skillRed_big", "icons")
self.greenSkills = bitmapLoader.getBitmap("skillGreen_big", "icons")
self.refresh = bitmapLoader.getBitmap("refresh", "icons")
self.skillReqsStaticBitmap.SetBitmap(self.cleanSkills)
self.btnRefresh = wx.BitmapButton(self, wx.ID_ANY, self.refresh)
size = self.btnRefresh.GetSize()
self.btnRefresh.SetMinSize(size)
self.btnRefresh.SetMaxSize(size)
self.btnRefresh.SetToolTipString("Refresh API")
self.btnRefresh.Bind(wx.EVT_BUTTON, self.refreshApi)
self.btnRefresh.Enable(False)
mainSizer.Add(self.btnRefresh, 0, wx.ALIGN_CENTER_VERTICAL | wx.TOP | wx.RIGHT | wx.LEFT, 2)
self.Bind(wx.EVT_CHOICE, self.charChanged)
self.mainFrame.Bind(GE.CHAR_LIST_UPDATED, self.refreshCharacterList)
self.mainFrame.Bind(GE.FIT_CHANGED, self.fitChanged)
@@ -87,9 +100,26 @@ class CharacterSelection(wx.Panel):
if event is not None:
event.Skip()
def refreshApi(self, event):
cChar = service.Character.getInstance()
ID, key, charName, chars = cChar.getApiDetails(self.getActiveCharacter())
if charName:
try:
cChar.apiFetch(self.getActiveCharacter(), charName)
except:
# can we do a popup, notifying user of API error?
pass
self.refreshCharacterList()
def charChanged(self, event):
fitID = self.mainFrame.getActiveFit()
charID = self.getActiveCharacter()
cChar = service.Character.getInstance()
if cChar.getCharName(charID) not in ("All 0", "All 5") and cChar.apiEnabled(charID):
self.btnRefresh.Enable(True)
else:
self.btnRefresh.Enable(False)
cFit = service.Fit.getInstance()
cFit.changeChar(fitID, charID)
@@ -133,9 +163,12 @@ class CharacterSelection(wx.Panel):
if newCharID == None:
cChar = service.Character.getInstance()
self.selectChar(cChar.all5ID())
elif currCharID != newCharID:
self.selectChar(newCharID)
self.charChanged(None)
event.Skip()
def _buildSkillsTooltip(self, reqs, currItem = "", tabulationLevel = 0):

BIN
icons/refresh.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 685 B

View File

@@ -24,7 +24,7 @@ import service
import itertools
from eos import eveapi
import config
import json
import os.path
import locale
import threading
@@ -228,19 +228,30 @@ class Character(object):
def getApiDetails(self, charID):
char = eos.db.getCharacter(charID)
return (char.apiID or "", char.apiKey or "")
if char.chars is not None:
chars = json.loads(char.chars)
else:
chars = None
return (char.apiID or "", char.apiKey or "", char.defaultChar or "", chars or [])
def apiEnabled(self, charID):
id, key, default, _ = self.getApiDetails(charID)
return id is not "" and key is not "" and default is not ""
def charList(self, charID, userID, apiKey):
char = eos.db.getCharacter(charID)
try:
char.apiID = userID
char.apiKey = apiKey
return char.apiCharList(proxy = service.settings.ProxySettings.getInstance().getProxySettings())
charList = char.apiCharList(proxy = service.settings.ProxySettings.getInstance().getProxySettings())
char.chars = json.dumps(charList)
return charList
except:
return None
def apiFetch(self, charID, charName):
char = eos.db.getCharacter(charID)
char.defaultChar = charName
char.apiFetch(charName, proxy = service.settings.ProxySettings.getInstance().getProxySettings())
eos.db.commit()