NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

walletUtil.py (3884B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\neocom\wallet\walletUtil.py
      2 import logging
      3 import sys
      4 import evetypes
      5 from carbonui.util.color import Color
      6 from carbonui.util.various_unsorted import SortListOfTuples
      7 from eve.client.script.ui.shared.neocom.wallet import walletConst
      8 from eve.client.script.ui.shared.neocom.wallet.walletConst import corpWalletRoles, CURRENCY_DISPLAY_LABEL
      9 from eve.client.script.ui.util.uix import ListWnd
     10 from eve.common.lib import appConst
     11 from eve.common.script.util.eveFormat import FmtCurrency
     12 from localization import GetByLabel
     13 logger = logging.getLogger(__name__)
     14 
     15 def GetSettingValue(key):
     16     return settings.char.ui.Get(key, walletConst.SETTING_DEFAULTS[key])
     17 
     18 
     19 def ToggleSetting(settingName):
     20     currVal = GetSettingValue(settingName)
     21     settings.char.ui.Set(settingName, not currVal)
     22 
     23 
     24 def FmtWalletCurrency(amt, currency = appConst.creditsISK, showFractions = None):
     25     if showFractions is None:
     26         showFractions = GetSettingValue('walletShowCents')
     27         if not showFractions and 1 < abs(amt) and abs(amt) < sys.maxint:
     28             amt = int(amt)
     29     return FmtCurrency(amt, showFractionsAlways=showFractions, currency=currency)
     30 
     31 
     32 def AmAccountantOrJuniorAccountant():
     33     return bool(session.corprole & (appConst.corpRoleJuniorAccountant | appConst.corpRoleAccountant))
     34 
     35 
     36 def AmAccountantOrTrader():
     37     return bool(session.corprole & (appConst.corpRoleAccountant | appConst.corpRoleTrader))
     38 
     39 
     40 def AmBrandManager():
     41     return bool(session.corprole & appConst.corpRoleBrandManager)
     42 
     43 
     44 def AmDirector():
     45     return bool(session.corprole & appConst.corpRoleDirector)
     46 
     47 
     48 def HaveAccessToCorpWallet():
     49     return bool(AmAccountantOrJuniorAccountant() or GetAccessibleCorpWalletDivisionIDs())
     50 
     51 
     52 def HaveAccessToCorpWalletAndActiveDivision():
     53     return bool(HaveAccessToCorpWallet() and HaveAccessToCorpWalletDivision(session.corpAccountKey))
     54 
     55 
     56 def HaveAccessToCorpEMWallet():
     57     return bool(AmBrandManager())
     58 
     59 
     60 def HaveAccessToCorpLPWallet():
     61     return bool(AmDirector())
     62 
     63 
     64 def HaveAccessToCorpWalletDivision(division):
     65     if division is None:
     66         return False
     67     return bool(session.corprole & corpWalletRoles[division])
     68 
     69 
     70 def HaveReadAccessToCorpWalletDivision(division):
     71     if division is None:
     72         return False
     73     return bool(session.corprole & corpWalletRoles[division])
     74 
     75 
     76 def GetAccessibleCorpWalletDivisionIDs():
     77     return filter(HaveAccessToCorpWalletDivision, corpWalletRoles)
     78 
     79 
     80 def GetFirstAccesibleCorpWalletDivisionID():
     81     divisionIDs = GetAccessibleCorpWalletDivisionIDs()
     82     if divisionIDs:
     83         return divisionIDs[0]
     84 
     85 
     86 def GetBalanceFormatted(amount, color = Color.WHITE, currency = appConst.creditsISK):
     87     text = FmtWalletCurrency(amount, currency)
     88     return GetByLabel(CURRENCY_DISPLAY_LABEL, color=color, currency=text)
     89 
     90 
     91 def GetDivisionName(divisionID):
     92     if not divisionID:
     93         logger.warn('Tried to get division name with no divisionID', exc_info=True)
     94         return ''
     95     names = sm.GetService('corp').GetDivisionNames()
     96     return names.get(divisionID - 1000 + 8, '')
     97 
     98 
     99 def SelectWalletDivision(*args):
    100     choices = SortListOfTuples([ (acctID, (sm.GetService('corp').GetCorpAccountName(acctID), acctID)) for acctID in GetAccessibleCorpWalletDivisionIDs() ])
    101     retval = ListWnd(choices, listtype='generic', caption=GetByLabel('UI/Wallet/WalletWindow/SelectDivision'))
    102     if retval:
    103         sm.GetService('corp').SetAccountKey(retval[1])
    104 
    105 
    106 def CheckSetDefaultWalletDivision(*args):
    107     divisionIDs = GetAccessibleCorpWalletDivisionIDs()
    108     if session.corpAccountKey is None and divisionIDs:
    109         sm.GetService('corp').SetAccountKey(divisionIDs[0])
    110 
    111 
    112 def SafeGetName(typeID):
    113     try:
    114         return evetypes.GetName(typeID)
    115     except evetypes.TypeNotFoundException:
    116         return GetByLabel('UI/Generic/Unknown')