VirtualBox

Changeset 19783 in vbox


Ignore:
Timestamp:
May 18, 2009 12:03:26 PM (16 years ago)
Author:
vboxsync
Message:

Python: MSCOM constants support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxShell/mscom/vboxshell.py

    r19239 r19783  
    2828class LocalManager:
    2929    def getSessionObject(self, vb):
    30         return win32com.client.Dispatch("{3C02F46D-C9D2-4f11-A384-53F0CF917214}")
     30        return win32com.client.Dispatch("{3C02F46D-C9D2-4f11-A384-53F0CF917214}")
    3131
    3232vbox = None
    3333mgr = LocalManager()
    3434try:
    35         vbox = win32com.client.Dispatch("{B1A7A4F2-47B9-4A1E-82B2-07CCD5323C3F}")
     35        vbox = win32com.client.Dispatch("{B1A7A4F2-47B9-4A1E-82B2-07CCD5323C3F}")
     36        win32com.client.gencache.EnsureDispatch('VirtualBox.Session')
    3637except Exception,e:
    3738    print "COM exception: ",e
     
    3940    sys.exit(1)
    4041
    41 # fake constants, while get resolved constants issues for real
    42 # win32com.client.constants doesn't work for some reasons
    43 class DummyInterfaces: pass
    44 class SessionState:pass
     42class ConstantFake:
     43  def __init__(self, parent, name):
     44        self.__dict__['_parent'] = parent
     45        self.__dict__['_name'] = name
     46        try:
     47             self.__dict__['_depth']=parent.__dict__['_depth']+1
     48        except:
     49             self.__dict__['_depth']=0
     50        self.__dict__['_klazz'] = self.__class__
     51        if self.__dict__['_depth'] > 4:
     52                raise AttributeError
    4553
    46 DummyInterfaces.SessionState=SessionState()
    47 DummyInterfaces.SessionState.Open = 2
     54  def __getattr__(self, attr):
     55    if attr.startswith("__"):
     56        raise AttributeError
     57       
     58    try:
     59        n = makeFullName(self) + "_" + attr
     60        v = win32com.client.constants.__getattr__(n)
     61        return v
     62    except AttributeError,e:
     63        return ConstantFake(self, attr)
    4864
    49 ctx = {'mgr':mgr, 'vb':vbox, 'ifaces':DummyInterfaces(),
    50 #'ifaces':win32com.client.constants,
     65def makeFullName(fake):
     66        name = fake._name
     67        parent = fake._parent
     68        while parent != None:
     69                name   = parent._name+'_'+name
     70                parent = parent._parent
     71        return name
     72
     73
     74class InterfacesWrapper:
     75  """COM constants name translator
     76  """
     77  def __init__(self):
     78    pass
     79
     80  def __getattr__(self, a):
     81    try:
     82        return win32com.client.constants.__getattr__(a)
     83    except AttributeError,e:
     84        if a.startswith("__"):
     85                raise e
     86        return ConstantFake(None, a)
     87
     88ctx = {'mgr':mgr, 'vb':vbox, 'ifaces':InterfacesWrapper(),
    5189       'remote':False, 'type':'mscom' }
    5290
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette