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

segmentedGauge.py (2574B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\control\segmentedGauge.py
      2 import math
      3 import uthread2
      4 from carbonui import uiconst
      5 from carbonui.primitives.container import Container
      6 from carbonui.util.color import Color
      7 from eve.client.script.ui.control.gauge import Gauge
      8 
      9 class SegmentedGauge(Container):
     10     default_gapWidth = 1
     11     default_nsegments = 2
     12     default_color = Color.BLUE
     13     default_height = 6
     14     default_state = uiconst.UI_NORMAL
     15 
     16     def __init__(self, nsegments = default_nsegments, gapWidth = default_gapWidth, color = default_color, **kwargs):
     17         super(SegmentedGauge, self).__init__(**kwargs)
     18         self.nsegments = nsegments
     19         self.gapWidth = gapWidth
     20         self.color = color
     21         self.leadSegment = 0
     22         self.segments = [ self.CreateSegment(i) for i in range(0, nsegments) ]
     23 
     24     def CreateSegment(self, segmentNumber):
     25         return Gauge(parent=self, name='gauge_segment_{}'.format(segmentNumber), align=uiconst.TOLEFT_NOPUSH, state=uiconst.UI_DISABLED, color=self.color)
     26 
     27     def _OnSizeChange_NoBlock(self, newWidth, newHeight):
     28         segmentWidth = math.floor((newWidth - self.nsegments * self.gapWidth) / self.nsegments)
     29         remainder = (newWidth - self.nsegments * self.gapWidth) % self.nsegments
     30         for i in range(self.nsegments):
     31             segment = self.segments[i]
     32             segment.width = segmentWidth
     33             segment.left = i * (self.gapWidth + segmentWidth) + min(i, remainder)
     34 
     35     def SetValue(self, value, animate = True, duration = 1.0):
     36         self.value = value
     37         if animate:
     38             uthread2.StartTasklet(self._SetValueAsync, value, animate=animate, duration=duration)
     39         else:
     40             self._SetValueAsync(value, animate=animate, duration=duration)
     41 
     42     def _SetValueAsync(self, value, animate = True, duration = 0.3):
     43         valueForLeadSegment, newLeadSegment = math.modf(value / (1.0 / self.nsegments))
     44         newLeadSegment = int(newLeadSegment)
     45         distance = newLeadSegment - self.leadSegment
     46         if distance:
     47             segmentDuration = duration / distance
     48         else:
     49             segmentDuration = duration
     50         for i in range(self.leadSegment, newLeadSegment):
     51             self.segments[i].SetValue(1, animate=animate, duration=segmentDuration)
     52             if animate:
     53                 uthread2.sleep(max(0, segmentDuration - 0.3))
     54 
     55         self.segments[newLeadSegment].SetValue(valueForLeadSegment, animate=animate, duration=segmentDuration)
     56         self.leadSegment = newLeadSegment