Convert pubsub to wx events

This commit is contained in:
blitzmann
2015-11-08 11:07:01 -05:00
parent 4baf65c0c7
commit 83adadd71f
6 changed files with 129 additions and 73 deletions

View File

@@ -3,15 +3,16 @@ import webbrowser
import json
import wx
from wx.lib.pubsub import setupkwargs
from wx.lib.pubsub import pub
import service
from service.crest import CrestModes
import gui.display as d
from eos.types import Cargo
from eos.db import getItem
import gui.display as d
import gui.globalEvents as GE
class CrestFittings(wx.Frame):
def __init__(self, parent):
@@ -67,7 +68,9 @@ class CrestFittings(wx.Frame):
self.importBtn.Bind(wx.EVT_BUTTON, self.importFitting)
self.deleteBtn.Bind(wx.EVT_BUTTON, self.deleteFitting)
pub.subscribe(self.ssoLogout, 'logout_success')
self.mainFrame.Bind(GE.EVT_SSO_LOGOUT, self.ssoLogout)
self.mainFrame.Bind(GE.EVT_SSO_LOGIN, self.ssoLogin)
self.Bind(wx.EVT_CLOSE, self.OnClose)
self.statusbar = wx.StatusBar(self)
self.statusbar.SetFieldsCount()
@@ -81,6 +84,10 @@ class CrestFittings(wx.Frame):
self.Centre(wx.BOTH)
def ssoLogin(self, event):
self.updateCharList()
event.Skip()
def updateCharList(self):
sCrest = service.Crest.getInstance()
chars = sCrest.getCrestCharacters()
@@ -88,6 +95,7 @@ class CrestFittings(wx.Frame):
if len(chars) == 0:
self.Close()
self.charChoice.Clear()
for char in chars:
self.charChoice.Append(char.name, char.ID)
@@ -102,8 +110,17 @@ class CrestFittings(wx.Frame):
sTime = time.strftime("%H:%M:%S", t)
self.statusbar.SetStatusText("Cached for %s"%sTime, 0)
def ssoLogout(self, message):
self.Close()
def ssoLogout(self, event):
if event.type == CrestModes.IMPLICIT:
self.Close()
else:
self.updateCharList()
event.Skip() # continue event
def OnClose(self, event):
self.mainFrame.Unbind(GE.EVT_SSO_LOGOUT, handler=self.ssoLogout)
self.mainFrame.Unbind(GE.EVT_SSO_LOGIN, handler=self.ssoLogin)
event.Skip()
def getActiveCharacter(self):
sCrest = service.Crest.getInstance()
@@ -182,7 +199,9 @@ class ExportToEve(wx.Frame):
self.statusbar.SetFieldsCount(2)
self.statusbar.SetStatusWidths([100, -1])
pub.subscribe(self.ssoLogout, 'logout_success')
self.mainFrame.Bind(GE.EVT_SSO_LOGOUT, self.ssoLogout)
self.mainFrame.Bind(GE.EVT_SSO_LOGIN, self.ssoLogin)
self.Bind(wx.EVT_CLOSE, self.OnClose)
self.SetSizer(hSizer)
self.SetStatusBar(self.statusbar)
@@ -197,13 +216,26 @@ class ExportToEve(wx.Frame):
if len(chars) == 0:
self.Close()
self.charChoice.Clear()
for char in chars:
self.charChoice.Append(char.name, char.ID)
self.charChoice.SetSelection(0)
def ssoLogout(self, message):
self.Close()
def ssoLogin(self, event):
self.updateCharList()
event.Skip()
def ssoLogout(self, event):
if event.type == CrestModes.IMPLICIT:
self.Close()
else:
self.updateCharList()
event.Skip() # continue event
def OnClose(self, event):
self.mainFrame.Unbind(GE.EVT_SSO_LOGOUT, handler=self.ssoLogout)
event.Skip()
def getActiveCharacter(self):
sCrest = service.Crest.getInstance()
@@ -235,7 +267,7 @@ class CrestMgmt(wx.Dialog):
def __init__( self, parent ):
wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = "CREST Character Management", pos = wx.DefaultPosition, size = wx.Size( 550,250 ), style = wx.DEFAULT_DIALOG_STYLE )
self.mainFrame = parent
mainSizer = wx.BoxSizer( wx.HORIZONTAL )
self.lcCharacters = wx.ListCtrl( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LC_REPORT)
@@ -260,15 +292,16 @@ class CrestMgmt(wx.Dialog):
self.addBtn.Bind(wx.EVT_BUTTON, self.addChar)
self.deleteBtn.Bind(wx.EVT_BUTTON, self.delChar)
pub.subscribe(self.ssoLogin, 'login_success')
self.mainFrame.Bind(GE.EVT_SSO_LOGIN, self.ssoLogin)
self.SetSizer( mainSizer )
self.Layout()
self.Centre( wx.BOTH )
def ssoLogin(self, type):
def ssoLogin(self, event):
self.popCharList()
event.Skip()
def popCharList(self):
sCrest = service.Crest.getInstance()
@@ -291,10 +324,11 @@ class CrestMgmt(wx.Dialog):
def delChar(self, event):
item = self.lcCharacters.GetFirstSelected()
charID = self.lcCharacters.GetItemData(item)
sCrest = service.Crest.getInstance()
sCrest.delCrestCharacter(charID)
self.popCharList()
if item > -1:
charID = self.lcCharacters.GetItemData(item)
sCrest = service.Crest.getInstance()
sCrest.delCrestCharacter(charID)
self.popCharList()
class FittingsTreeView(wx.Panel):

View File

@@ -3,3 +3,6 @@ import wx.lib.newevent
FitChanged, FIT_CHANGED = wx.lib.newevent.NewEvent()
CharListUpdated, CHAR_LIST_UPDATED = wx.lib.newevent.NewEvent()
CharChanged, CHAR_CHANGED = wx.lib.newevent.NewEvent()
SsoLogin, EVT_SSO_LOGIN = wx.lib.newevent.NewEvent()
SsoLogout, EVT_SSO_LOGOUT = wx.lib.newevent.NewEvent()

View File

@@ -64,8 +64,6 @@ from time import gmtime, strftime
if not 'wxMac' in wx.PlatformInfo or ('wxMac' in wx.PlatformInfo and wx.VERSION >= (3,0)):
from service.crest import CrestModes
from gui.crestFittings import CrestFittings, ExportToEve, CrestMgmt
from wx.lib.pubsub import setupkwargs
from wx.lib.pubsub import pub
try:
from gui.propertyEditor import AttributeEditor
@@ -210,8 +208,8 @@ class MainFrame(wx.Frame):
self.sUpdate.CheckUpdate(self.ShowUpdateBox)
if not 'wxMac' in wx.PlatformInfo or ('wxMac' in wx.PlatformInfo and wx.VERSION >= (3,0)):
pub.subscribe(self.onSSOLogin, 'login_success')
pub.subscribe(self.onSSOLogout, 'logout_success')
self.Bind(GE.EVT_SSO_LOGIN, self.onSSOLogin)
self.Bind(GE.EVT_SSO_LOGOUT, self.onSSOLogout)
self.titleTimer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.updateTitle, self.titleTimer)
@@ -448,8 +446,8 @@ class MainFrame(wx.Frame):
self.Bind(wx.EVT_MENU, self.eveFittings, id = menuBar.eveFittingsId)
# Export to EVE
self.Bind(wx.EVT_MENU, self.exportToEve, id = menuBar.exportToEveId)
# Login to EVE
self.Bind(wx.EVT_MENU, self.ssoLogin, id = menuBar.ssoLoginId)
# Handle SSO event (login/logout/manage characters, depending on mode and current state)
self.Bind(wx.EVT_MENU, self.ssoHandler, id = menuBar.ssoLoginId)
# Open attribute editor
self.Bind(wx.EVT_MENU, self.showAttrEditor, id = menuBar.attrEditorId)
@@ -532,15 +530,48 @@ class MainFrame(wx.Frame):
newTitle = "%s | %s - %s"%(self.title, char.name, sTime)
self.SetTitle(newTitle)
def onSSOLogin(self, type):
if type == 0:
def onSSOLogin(self, event):
menu = self.GetMenuBar()
menu.Enable(menu.eveFittingsId, True)
menu.Enable(menu.exportToEveId, True)
if event.type == CrestModes.IMPLICIT:
menu.SetLabel(menu.ssoLoginId, "Logout Character")
self.titleTimer.Start(1000)
def onSSOLogout(self, message):
def onSSOLogout(self, event):
self.titleTimer.Stop()
self.SetTitle(self.title)
def ssoLogin(self, event):
menu = self.GetMenuBar()
if event.type == CrestModes.IMPLICIT or event.numChars == 0:
menu.Enable(menu.eveFittingsId, False)
menu.Enable(menu.exportToEveId, False)
if event.type == CrestModes.IMPLICIT:
menu.SetLabel(menu.ssoLoginId, "Login to EVE")
def updateCrestMenus(self, type):
# in case we are logged in when switching, change title back
self.titleTimer.Stop()
self.SetTitle(self.title)
menu = self.GetMenuBar()
sCrest = service.Crest.getInstance()
if type == CrestModes.IMPLICIT:
print 'impl'
menu.SetLabel(menu.ssoLoginId, "Login to EVE")
menu.Enable(menu.eveFittingsId, False)
menu.Enable(menu.exportToEveId, False)
else:
print 'user'
menu.SetLabel(menu.ssoLoginId, "Manage Characters")
enable = len(sCrest.getCrestCharacters()) == 0
menu.Enable(menu.eveFittingsId, not enable)
menu.Enable(menu.exportToEveId, not enable)
def ssoHandler(self, event):
sCrest = service.Crest.getInstance()
if sCrest.settings.get('mode') == CrestModes.IMPLICIT:
if sCrest.implicitCharacter is not None:

View File

@@ -28,9 +28,6 @@ import service
if not 'wxMac' in wx.PlatformInfo or ('wxMac' in wx.PlatformInfo and wx.VERSION >= (3,0)):
from service.crest import CrestModes
from wx.lib.pubsub import setupkwargs
from wx.lib.pubsub import pub
class MainMenuBar(wx.MenuBar):
def __init__(self):
self.characterEditorId = wx.NewId()
@@ -138,10 +135,6 @@ class MainMenuBar(wx.MenuBar):
editMenu.AppendSeparator()
editMenu.Append(self.toggleOverridesId, "Turn Overrides On")
pub.subscribe(self.ssoLogin, 'login_success')
pub.subscribe(self.ssoLogout, 'logout_success')
pub.subscribe(self.updateCrest, 'crest_changed')
# Help menu
helpMenu = wx.Menu()
self.Append(helpMenu, "&Help")
@@ -172,24 +165,4 @@ class MainMenuBar(wx.MenuBar):
event.Skip()
def ssoLogin(self, type):
if self.sCrest.settings.get('mode') == CrestModes.IMPLICIT:
self.SetLabel(self.ssoLoginId, "Logout Character")
self.Enable(self.eveFittingsId, True)
self.Enable(self.exportToEveId, True)
def ssoLogout(self, message):
if self.sCrest.settings.get('mode') == CrestModes.IMPLICIT:
self.SetLabel(self.ssoLoginId, "Login to EVE")
self.Enable(self.eveFittingsId, False)
self.Enable(self.exportToEveId, False)
def updateCrest(self, message):
bool = self.sCrest.settings.get('mode') == CrestModes.IMPLICIT or len(self.sCrest.getCrestCharacters()) == 0
self.Enable(self.eveFittingsId, not bool)
self.Enable(self.exportToEveId, not bool)
if self.sCrest.settings.get('mode') == CrestModes.IMPLICIT:
self.SetLabel(self.ssoLoginId, "Login to EVE")
else:
self.SetLabel(self.ssoLoginId, "Manage Characters")