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

pricehistorychart.py (8199B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\market\pricehistorychart.py
      2 import localization
      3 import uthread
      4 import utillib
      5 from carbon.common.script.util.format import FmtAmt, FmtDate
      6 from carbonui import uiconst
      7 from carbonui.button.const import HEIGHT_NORMAL
      8 from carbonui.control.combo import Combo
      9 from carbonui.graphs.datafortesting import GetTestData
     10 from carbonui.primitives.container import Container
     11 from carbonui.util.various_unsorted import FlushList
     12 from eve.client.script.ui.control import eveScroll
     13 from carbonui.control.button import Button
     14 from eve.client.script.ui.control.entries.generic import Generic
     15 from eve.client.script.ui.control.entries.util import GetFromClass
     16 from eve.client.script.ui.shared.market.marketGraph import MarketGraph
     17 from eve.common.lib import appConst as const
     18 from eve.common.script.util.eveFormat import FmtCurrency
     19 from eveprefs import prefs
     20 
     21 class PriceHistoryParent(Container):
     22     __guid__ = 'xtriui.PriceHistoryParent'
     23     __nonpersistvars__ = []
     24     inited = 0
     25 
     26     def Startup(self):
     27         self.sr.pricehistory = PriceHistory(name='ph', parent=self, align=uiconst.TOALL, pos=(const.defaultPadding,
     28          0,
     29          const.defaultPadding,
     30          0))
     31         self.inited = 1
     32 
     33     def LoadType(self, invType):
     34         self.sr.pricehistory.Render(invType)
     35 
     36 
     37 class PriceHistory(Container):
     38     __guid__ = 'xtriui.PriceHistory'
     39     __nonpersistvars__ = []
     40     __update_on_reload__ = 1
     41 
     42     def ApplyAttributes(self, attributes):
     43         Container.ApplyAttributes(self, attributes)
     44         self.line = None
     45         self.marker = None
     46         self.highlow = None
     47         self.underlay = None
     48         self.markerparent = None
     49         self.wantrefresh = 1
     50         self.rendering = 0
     51         self.typerecord = None
     52         self.optionsCont = Container(name='options', parent=self, align=uiconst.TOBOTTOM, height=HEIGHT_NORMAL, padTop=16)
     53         self.optionsinited = 0
     54         self.sr.updateTimer = None
     55         self.currentGraph = None
     56 
     57     def InitOptions(self):
     58         self.optionsCont.Flush()
     59         showingPriceHistoryType = settings.user.ui.Get('pricehistorytype', 0)
     60         if showingPriceHistoryType:
     61             buttonLabel = localization.GetByLabel('UI/PriceHistory/ShowGraph')
     62             buttonHint = localization.GetByLabel('Tooltips/Market/MarketDetailsHistoryGraph')
     63         else:
     64             buttonLabel = localization.GetByLabel('UI/PriceHistory/ShowTable')
     65             buttonHint = localization.GetByLabel('Tooltips/Market/MarketDetailsHistoryTable')
     66         btn = Button(parent=self.optionsCont, label=buttonLabel, align=uiconst.TOLEFT, func=self.ToggleView, args='self', hint=buttonHint)
     67         timeOptions = [[localization.GetByLabel('/Carbon/UI/Common/WrittenDateTimeQuantity/Day', units=5), 5],
     68          [localization.GetByLabel('/Carbon/UI/Common/WrittenDateTimeQuantity/Day', units=10), 10],
     69          [localization.GetByLabel('UI/Common/DateWords/Month'), 30],
     70          [localization.GetByLabel('/Carbon/UI/Common/WrittenDateTimeQuantity/Month', units=3), 90],
     71          [localization.GetByLabel('/Carbon/UI/Common/WrittenDateTimeQuantity/Month', units=6), 180],
     72          [localization.GetByLabel('UI/Common/DateWords/Year'), 365]]
     73         timeLabel = localization.GetByLabel('/Carbon/UI/Common/Time')
     74         pos = btn.width + btn.left + 10
     75         self.timeCombo = Combo(label=timeLabel, parent=self.optionsCont, align=uiconst.TOLEFT, options=timeOptions, name='pricehistorytime', select=settings.user.ui.Get('pricehistorytime', 90), callback=self.ChangeOption, padLeft=8)
     76         if showingPriceHistoryType:
     77             self.timeCombo.state = uiconst.UI_NORMAL
     78         else:
     79             self.timeCombo.state = uiconst.UI_HIDDEN
     80         self.optionsinited = 1
     81 
     82     def ToggleView(self, btn, *args):
     83         settings.user.ui.Set('pricehistorytype', not settings.user.ui.Get('pricehistorytype', 0))
     84         showingPriceHistoryType = settings.user.ui.Get('pricehistorytype', 0)
     85         if showingPriceHistoryType:
     86             btnLabel = localization.GetByLabel('UI/PriceHistory/ShowGraph')
     87             buttonHint = localization.GetByLabel('Tooltips/Market/MarketDetailsHistoryGraph')
     88             self.timeCombo.state = uiconst.UI_NORMAL
     89         else:
     90             btnLabel = localization.GetByLabel('UI/PriceHistory/ShowTable')
     91             buttonHint = localization.GetByLabel('Tooltips/Market/MarketDetailsHistoryTable')
     92             self.timeCombo.state = uiconst.UI_HIDDEN
     93         btn.hint = buttonHint
     94         btn.SetLabel(btnLabel)
     95         btn.width = 100
     96         if self.typerecord:
     97             uthread.new(self.Render, self.typerecord)
     98 
     99     def ChangeOption(self, entry, header, value, *args):
    100         settings.user.ui.Set('pricehistorytime', value)
    101         self.InitOptions()
    102         if self.typerecord:
    103             uthread.new(self.Render, self.typerecord)
    104 
    105     def GetSize(self):
    106         abswidth, absheight = self.absoluteRight - self.absoluteLeft, self.absoluteBottom - self.absoluteTop
    107         if not abswidth or not absheight:
    108             abswidth, absheight = self.absoluteRight - self.absoluteLeft, self.absoluteBottom - self.absoluteTop
    109         return (abswidth, absheight - self.optionsCont.height)
    110 
    111     def RenderTable(self):
    112         scroll = eveScroll.Scroll(parent=self, padding=(1, 1, 1, 1))
    113         scroll.sr.id = 'pricehistoryscroll'
    114         scroll.smartSort = 0
    115         scroll.OnColumnChanged = self.OnColumnChanged
    116         history = sm.GetService('marketQuote').GetPriceHistory(self.typerecord)
    117         windowData = settings.user.ui.Get('pricehistorytime', 90)
    118         if len(history) > windowData:
    119             history = history[-(windowData + 1):]
    120         scrolllist = []
    121         for rec in history:
    122             text = '%s<t>%s<t>%s<t>%s<t>%s<t>%s' % (FmtDate(rec[0]),
    123              FmtAmt(rec[5]),
    124              FmtAmt(rec[4]),
    125              FmtCurrency(rec[1], currency=None),
    126              FmtCurrency(rec[2], currency=None),
    127              FmtCurrency(rec[3], currency=None))
    128             data = utillib.KeyVal()
    129             data.label = text
    130             data.Set('sort_%s' % localization.GetByLabel('UI/Market/PriceHistory/Quantity'), rec[4])
    131             data.Set('sort_%s' % localization.GetByLabel('UI/Market/PriceHistory'), rec[5])
    132             data.Set('sort_%s' % localization.GetByLabel('UI/Market/PriceHistory/LowestPrice'), rec[1])
    133             data.Set('sort_%s' % localization.GetByLabel('UI/Market/PriceHistory/HighestPrice'), rec[2])
    134             data.Set('sort_%s' % localization.GetByLabel('UI/Market/PriceHistory/AveragePrice'), rec[3])
    135             data.Set('sort_%s' % localization.GetByLabel('UI/Common/Date'), rec[0])
    136             scrolllist.append(GetFromClass(Generic, data))
    137 
    138         headers = [localization.GetByLabel('UI/Common/Date'),
    139          localization.GetByLabel('UI/Market/PriceHistory'),
    140          localization.GetByLabel('UI/Market/PriceHistory/Quantity'),
    141          localization.GetByLabel('UI/Market/PriceHistory/LowestPrice'),
    142          localization.GetByLabel('UI/Market/PriceHistory/HighestPrice'),
    143          localization.GetByLabel('UI/Market/PriceHistory/AveragePrice')]
    144         scroll.Load(fixedEntryHeight=18, contentList=scrolllist, headers=headers)
    145 
    146     def OnColumnChanged(self, *args):
    147         if self.typerecord:
    148             uthread.new(self.Render, self.typerecord)
    149 
    150     def GetGraph(self, typeID):
    151         if prefs.GetValue('priceHistoryTestData', False):
    152             data = GetTestData()
    153         else:
    154             data = sm.GetService('marketQuote').GetPriceHistory(typeID)
    155         data = data[-365:]
    156         graph = MarketGraph(parent=self, data=data, typeID=typeID)
    157         self.currentGraph = graph
    158         return graph
    159 
    160     def Render(self, typeRecord):
    161         if self.rendering:
    162             return
    163         self.typerecord = typeRecord
    164         if not self.optionsinited:
    165             self.InitOptions()
    166         FlushList(self.children[1:])
    167         if settings.user.ui.Get('pricehistorytype', 0):
    168             self.RenderTable()
    169             return
    170         self.rendering = 1
    171         try:
    172             self.currentGraph = self.GetGraph(self.typerecord)
    173         finally:
    174             self.rendering = 0