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

various_unsorted.py (7072B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\util\various_unsorted.py
      2 import logging
      3 import sys
      4 import numbers
      5 from functools import wraps
      6 import blue
      7 import mathext
      8 from stringutil import strx
      9 from carbonui.uicore import uicore
     10 from carbonui.util import sortUtil
     11 log = logging.getLogger(__name__)
     12 
     13 def GetBuffersize(size):
     14     if size <= 8:
     15         return 8
     16     if size <= 16:
     17         return 16
     18     if size <= 32:
     19         return 32
     20     if size <= 64:
     21         return 64
     22     if size <= 128:
     23         return 128
     24     if size <= 256:
     25         return 256
     26     if size <= 512:
     27         return 512
     28     if size <= 1024:
     29         return 1024
     30     if size <= 2048:
     31         return 2048
     32     return 128
     33 
     34 
     35 def StringColorToHex(color):
     36     colors = {'Black': '0xff000000',
     37      'Green': '0xff008000',
     38      'Silver': '0xffC0C0C0',
     39      'Lime': '0xff00FF00',
     40      'Gray': '0xff808080',
     41      'Grey': '0xff808080',
     42      'Olive': '0xff808000',
     43      'White': '0xffFFFFFF',
     44      'Yellow': '0xffFFFF00',
     45      'Maroon': '0xff800000',
     46      'Navy': '0xff000080',
     47      'Red': '0xffFF0000',
     48      'Blue': '0xff0000FF',
     49      'Purple': '0xff800080',
     50      'Teal': '0xff008080',
     51      'Fuchsia': '0xffFF00FF',
     52      'Aqua': '0xff00FFFF',
     53      'Orange': '0xffFF8000',
     54      'Transparent': '0x00000000',
     55      'Lightred': '0xffcc3333',
     56      'Lightblue': '0xff7777ff',
     57      'Lightgreen': '0xff80ff80'}
     58     return colors.get(color.capitalize(), None)
     59 
     60 
     61 def Sort(lst):
     62     return sortUtil.Sort(lst)
     63 
     64 
     65 def SortListOfTuples(lst, reverse = 0):
     66     return sortUtil.SortListOfTuples(lst, reverse)
     67 
     68 
     69 def Flush(parent):
     70     parent.Flush()
     71 
     72 
     73 def FlushList(lst):
     74     for each in lst[:]:
     75         if each is not None and not getattr(each, 'destroyed', 0):
     76             each.Close()
     77 
     78     del lst[:]
     79 
     80 
     81 def GetWindowAbove(item):
     82     if item == uicore.desktop:
     83         return None
     84     if uicore.registry.IsWindow(item):
     85         return item
     86     if item.parent and not item.parent.destroyed:
     87         return GetWindowAbove(item.parent)
     88 
     89 
     90 def IsUnderActiveWindow(item):
     91     if IsUnder(item, uicore.layer.modal):
     92         return True
     93     active_window = uicore.registry.GetActive()
     94     return active_window and active_window == GetWindowAbove(item)
     95 
     96 
     97 def GetDesktopObject(item):
     98     if not item.parent:
     99         if item.destroyed:
    100             return None
    101         else:
    102             return item
    103     else:
    104         return GetDesktopObject(item.parent)
    105 
    106 
    107 def GetBrowser(item):
    108     if item == uicore.desktop:
    109         return
    110     if getattr(item, 'IsBrowser', None):
    111         return item
    112     from carbonui.control.edit import EditCore
    113     if isinstance(item, EditCore):
    114         return item
    115     if item.parent:
    116         return GetBrowser(item.parent)
    117 
    118 
    119 def GetAttrs(obj, *names):
    120     for name in names:
    121         obj = getattr(obj, name, None)
    122         if obj is None:
    123             return
    124 
    125     return obj
    126 
    127 
    128 def Transplant(wnd, newParent, idx = None):
    129     if wnd is None or wnd.destroyed or newParent is None or newParent.destroyed:
    130         return
    131     if idx in (-1, None):
    132         idx = len(newParent.children)
    133     wnd.SetParent(newParent, idx)
    134 
    135 
    136 def IsUnder(child, ancestor_maybe, retfailed = False):
    137     return child.IsUnder(ancestor_maybe, retfailed)
    138 
    139 
    140 def MapIcon(sprite, iconPath, ignoreSize = 0):
    141     if hasattr(sprite, 'LoadIcon'):
    142         return sprite.LoadIcon(iconPath, ignoreSize)
    143     import warnings
    144     warnings.warn('Called MapIcon for an instance of a non-icon class. Implement LoadIcon on the relevant class instead.', DeprecationWarning)
    145     from eve.client.script.ui.control import eveIcon
    146     return eveIcon.Icon.LoadIcon(sprite, iconPath, ignoreSize)
    147 
    148 
    149 def ConvertDecimal(qty, fromChar, toChar, numDecimals = None):
    150     ret = qty
    151     if isinstance(ret, numbers.Real):
    152         if numDecimals is not None:
    153             ret = '%.*f' % (numDecimals, qty)
    154         else:
    155             ret = repr(qty)
    156     ret = ret.replace(fromChar, toChar)
    157     return ret
    158 
    159 
    160 def GetClipboardData():
    161     try:
    162         return blue.clipboard.GetClipboardUnicode()
    163     except (blue.error, WindowsError):
    164         return ''
    165 
    166 
    167 def GetTrace(item, trace = '', div = '/'):
    168     trace = div + item.name + trace
    169     if getattr(item, 'parent', None) is None:
    170         return trace
    171     return GetTrace(item.parent, trace, div)
    172 
    173 
    174 def ParseHTMLColor(colorstr, asTuple = 0, error = 0):
    175     colors = {'Black': '0x000000',
    176      'Green': '0x008000',
    177      'Silver': '0xC0C0C0',
    178      'Lime': '0x00FF00',
    179      'Gray': '0x808080',
    180      'Grey': '0x808080',
    181      'Olive': '0x808000',
    182      'White': '0xFFFFFF',
    183      'Yellow': '0xFFFF00',
    184      'Maroon': '0x800000',
    185      'Navy': '0x000080',
    186      'Red': '0xFF0000',
    187      'Blue': '0x0000FF',
    188      'Purple': '0x800080',
    189      'Teal': '0x008080',
    190      'Fuchsia': '0xFF00FF',
    191      'Aqua': '0x00FFFF',
    192      'Transparent': '0x00000000'}
    193     try:
    194         colorstr = colors.get(colorstr.capitalize(), colorstr).lower()
    195     except:
    196         sys.exc_clear()
    197         return colorstr
    198 
    199     if colorstr.startswith('#'):
    200         colorstr = colorstr.replace('#', '0x')
    201     r, g, b, a = (0.0, 255.0, 0.0, 255.0)
    202     if colorstr.startswith('0x'):
    203         try:
    204             if len(colorstr) == 8:
    205                 r = eval('0x' + colorstr[2:4])
    206                 g = eval('0x' + colorstr[4:6])
    207                 b = eval('0x' + colorstr[6:8])
    208             elif len(colorstr) == 10:
    209                 a = eval('0x' + colorstr[2:4])
    210                 r = eval('0x' + colorstr[4:6])
    211                 g = eval('0x' + colorstr[6:8])
    212                 b = eval('0x' + colorstr[8:10])
    213             else:
    214                 log.warning('Invalid color string, has to be in form of 0xffffff or 0xffffffff (with alpha). 0x can be replaced with # (%s)' % colorstr)
    215                 if error:
    216                     return
    217         except:
    218             log.warning('Invalid color string, has to be in form of 0xffffff or 0xffffffff (with alpha). 0x can be replaced with # (%s)' % colorstr)
    219             if error:
    220                 return
    221 
    222     else:
    223         log.error('Unknown color (' + colorstr + '), I only know: ' + strx(', '.join(colors.keys())))
    224         if error:
    225             return
    226     col = (r / 255.0,
    227      g / 255.0,
    228      b / 255.0,
    229      a / 255.0)
    230     if asTuple:
    231         return col
    232     import trinity
    233     return trinity.TriColor(*col)
    234 
    235 
    236 def ParanoidDecoMethod(fn, attrs):
    237     check = []
    238     if attrs is None:
    239         check = ['sr']
    240     else:
    241         check.extend(attrs)
    242 
    243     @wraps(fn)
    244     def deco(self, *args, **kw):
    245         if GetAttrs(self, *check) is None:
    246             return
    247         if self.destroyed:
    248             return
    249         return fn(self, *args, **kw)
    250 
    251     return deco
    252 
    253 
    254 def NiceFilter(func, list):
    255     ret = []
    256     for x in list:
    257         if func(x):
    258             ret.append(x)
    259         blue.pyos.BeNice()
    260 
    261     return ret
    262 
    263 
    264 def divide_evenly(value, index, total_count):
    265     remainder = value % total_count
    266     fraction = remainder / float(total_count)
    267     if (index + 1) / float(total_count) > fraction:
    268         return int(mathext.floor(value / float(total_count)))
    269     else:
    270         return int(mathext.ceil(value / float(total_count)))