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

autofinder.py (5153B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\util\autofinder.py
      2 import logging
      3 log = logging.getLogger(__name__)
      4 
      5 def find_ui_element_smart(element_path):
      6     if not element_path:
      7         return None
      8     try:
      9         from carbonui.util.autonaming import get_registered_element
     10         result = get_registered_element(element_path)
     11         if result:
     12             return result
     13     except Exception as exc:
     14         log.exception('Failed to find element via autonaming registry: %s', exc)
     15 
     16     if '.' in element_path:
     17         parts = element_path.split('.')
     18         if parts[0] == 'neocom':
     19             result = _find_neocom_button(parts[1:])
     20             if result:
     21                 return result
     22         elif parts[0].endswith('Window'):
     23             result = _find_in_window(parts[0], parts[1:])
     24             if result:
     25                 return result
     26         else:
     27             result = _find_by_hierarchy(parts)
     28             if result:
     29                 return result
     30     result = _find_by_hierarchy([element_path])
     31     if result:
     32         return result
     33     try:
     34         result = sm.GetService('uipointerSvc').FindElementToPointTo(element_path, shouldExcludeInvisible=True)
     35         if result and result.pointToElement:
     36             return result.pointToElement
     37     except Exception as exc:
     38         log.exception('Failed to find element via uipointerSvc: %s', exc)
     39 
     40 
     41 def _find_neocom_button(path_parts):
     42     try:
     43         neocom_svc = sm.GetService('neocom')
     44         if not neocom_svc or not neocom_svc.neocomContainer:
     45             return None
     46         if hasattr(neocom_svc, 'eveMenuBtnDataRoot') and neocom_svc.eveMenuBtnDataRoot:
     47             for btnData in neocom_svc.eveMenuBtnDataRoot.GetChildrenInScope():
     48                 if btnData.id == path_parts[0]:
     49                     if len(path_parts) == 1:
     50                         if hasattr(neocom_svc, 'neocomContainer') and neocom_svc.neocomContainer:
     51                             panel = neocom_svc.neocomContainer.neocomPanel
     52                             if panel and hasattr(panel, 'children'):
     53                                 for entry in panel.children:
     54                                     if hasattr(entry, 'btnData') and entry.btnData == btnData:
     55                                         return entry
     56 
     57                         return getattr(btnData, 'btnUI', None)
     58                     if len(path_parts) == 2 and hasattr(btnData, 'children'):
     59                         for child in btnData.children:
     60                             if child.id == path_parts[1]:
     61                                 if hasattr(neocom_svc, 'neocomContainer') and neocom_svc.neocomContainer:
     62                                     panel = neocom_svc.neocomContainer.neocomPanel
     63                                     if panel and hasattr(panel, 'children'):
     64                                         for entry in panel.children:
     65                                             if hasattr(entry, 'btnData') and entry.btnData == child:
     66                                                 return entry
     67 
     68                                 return getattr(child, 'btnUI', None)
     69 
     70         for btnData in neocom_svc.mainBtnDataRoot.GetChildrenInScope():
     71             if btnData.id == path_parts[0]:
     72                 if len(path_parts) == 1:
     73                     return getattr(btnData, 'btnUI', None)
     74                 if len(path_parts) == 2 and hasattr(btnData, 'children'):
     75                     for child in btnData.children:
     76                         if child.id == path_parts[1]:
     77                             return getattr(child, 'btnUI', None)
     78 
     79     except Exception as exc:
     80         log.exception('Failed to find neocom button: %s', exc)
     81 
     82 
     83 def _find_in_window(window_id, path_parts):
     84     try:
     85         from carbonui.control.window import Window
     86         window_name = window_id.replace('Window', '').lower()
     87         wnd = Window.GetIfOpen(windowID=window_name)
     88         if not wnd or wnd.destroyed:
     89             return None
     90         current = wnd
     91         for part in path_parts:
     92             current = _find_child_by_name(current, part)
     93             if not current:
     94                 return None
     95 
     96         return current
     97     except Exception as exc:
     98         log.exception('Failed to find element in window %s: %s', window_id, exc)
     99 
    100 
    101 def _find_child_by_name(parent, name):
    102     if not hasattr(parent, 'children'):
    103         return
    104     for child in parent.children:
    105         if getattr(child, 'name', None) == name:
    106             return child
    107 
    108 
    109 def _find_by_hierarchy(path_parts):
    110     try:
    111         from carbonui.uicore import uicore
    112         current = uicore.desktop
    113         for part in path_parts:
    114             current = _find_deep_by_name(current, part)
    115             if not current:
    116                 return None
    117 
    118         return current
    119     except Exception as exc:
    120         log.exception('Failed to find element by hierarchy %s: %s', path_parts, exc)
    121 
    122 
    123 def _find_deep_by_name(element, name):
    124     if getattr(element, 'name', None) == name:
    125         return element
    126     if hasattr(element, 'children'):
    127         for child in element.children:
    128             result = _find_deep_by_name(child, name)
    129             if result:
    130                 return result