Changeset 19814 in vbox for trunk/src/VBox/Frontends/VBoxShell
- Timestamp:
- May 19, 2009 11:57:59 AM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 47464
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxShell/mscom/vboxshell.py
r19783 r19814 22 22 import pythoncom 23 23 import win32api 24 import traceback25 24 26 25 from shellcommon import interpret 27 26 28 27 class LocalManager: 29 def getSessionObject(self, vb): 30 return win32com.client.Dispatch("{3C02F46D-C9D2-4f11-A384-53F0CF917214}") 28 def getSessionObject(self, vb): 29 return win32com.client.Dispatch("{3C02F46D-C9D2-4f11-A384-53F0CF917214}") 30 31 class ConstantFake: 32 def __init__(self, parent, name): 33 self.__dict__['_parent'] = parent 34 self.__dict__['_name'] = name 35 self.__dict__['_consts'] = {} 36 try: 37 self.__dict__['_depth']=parent.__dict__['_depth']+1 38 except: 39 self.__dict__['_depth']=0 40 if self.__dict__['_depth'] > 4: 41 raise AttributeError 42 43 def __getattr__(self, attr): 44 if attr.startswith("__"): 45 raise AttributeError 46 47 consts = self.__dict__['_consts'] 48 fake = consts.get(attr, None) 49 if fake != None: 50 return fake 51 try: 52 name = makeFullName(self, attr) 53 return win32com.client.constants.__getattr__(name) 54 except AttributeError,e: 55 fake = ConstantFake(self, attr) 56 consts[attr] = fake 57 return fake 58 59 def makeFullName(fake, attr): 60 name = fake._name 61 parent = fake._parent 62 while parent != None: 63 if parent._name is not None: 64 name = parent._name+'_'+name 65 parent = parent._parent 66 67 if name: 68 name += "_" + attr 69 else: 70 name = attr 71 return name 72 73 74 class InterfacesWrapper: 75 def __init__(self): 76 self.__dict__['_rootFake'] = ConstantFake(None, None) 77 78 def __getattr__(self, a): 79 if a.startswith("__"): 80 raise AttributeError 81 try: 82 return win32com.client.constants.__getattr__(a) 83 except AttributeError,e: 84 return self.__dict__['_rootFake'].__getattr__(a) 85 31 86 32 87 vbox = None 33 88 mgr = LocalManager() 34 89 try: 90 win32com.client.gencache.EnsureDispatch('VirtualBox.Session') 35 91 vbox = win32com.client.Dispatch("{B1A7A4F2-47B9-4A1E-82B2-07CCD5323C3F}") 36 win32com.client.gencache.EnsureDispatch('VirtualBox.Session')37 92 except Exception,e: 38 print "COM exception: ",e39 traceback.print_exc()40 sys.exit(1)93 print "COM exception: ",e 94 traceback.print_exc() 95 sys.exit(1) 41 96 42 class ConstantFake:43 def __init__(self, parent, name):44 self.__dict__['_parent'] = parent45 self.__dict__['_name'] = name46 try:47 self.__dict__['_depth']=parent.__dict__['_depth']+148 except:49 self.__dict__['_depth']=050 self.__dict__['_klazz'] = self.__class__51 if self.__dict__['_depth'] > 4:52 raise AttributeError53 54 def __getattr__(self, attr):55 if attr.startswith("__"):56 raise AttributeError57 58 try:59 n = makeFullName(self) + "_" + attr60 v = win32com.client.constants.__getattr__(n)61 return v62 except AttributeError,e:63 return ConstantFake(self, attr)64 65 def makeFullName(fake):66 name = fake._name67 parent = fake._parent68 while parent != None:69 name = parent._name+'_'+name70 parent = parent._parent71 return name72 73 74 class InterfacesWrapper:75 """COM constants name translator76 """77 def __init__(self):78 pass79 80 def __getattr__(self, a):81 try:82 return win32com.client.constants.__getattr__(a)83 except AttributeError,e:84 if a.startswith("__"):85 raise e86 return ConstantFake(None, a)87 97 88 98 ctx = {'mgr':mgr, 'vb':vbox, 'ifaces':InterfacesWrapper(),
Note:
See TracChangeset
for help on using the changeset viewer.