def tray_on_enso_exec_at_startup(systray, get_state=False): startup_dir = shell.SHGetFolderPath(0, shellcon.CSIDL_STARTUP, 0, 0) assert os.path.isdir(startup_dir) link_file = os.path.join(startup_dir, "Enso.lnk") if get_state: return os.path.isfile(link_file) else: if not os.path.isfile(link_file): try: pythoncom.CoInitialize() except: # already initialized. pass shortcut = pythoncom.CoCreateInstance( shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink) shortcut.SetPath(enso.enso_executable) enso_root_dir = os.path.dirname(enso.enso_executable) shortcut.SetWorkingDirectory(enso_root_dir) shortcut.SetIconLocation(os.path.join(enso_root_dir, "Enso.ico"), 0) shortcut.QueryInterface(pythoncom.IID_IPersistFile).Save( link_file, 0) try: pythoncom.CoUnInitialize() except: pass displayMessage( u"<p><command>Enso</command> will be automatically executed at system startup</p><caption>enso</caption>" ) else: os.remove(link_file) displayMessage( u"<p><command>Enso</command> will not start at system startup</p><caption>enso</caption>" )
# OFTEN, CALL IMMEDIATELY AFTER Connect() FAILS, WAIT A MOMENT # TO AVOID ISSUE. time.sleep(0.01) self.opc_server = opc_server if opc_host == 'localhost': opc_host = socket.gethostname() self.opc_host = opc_host # ON RECONNECT, REMOVE OLD GROUP NAMES THAT ARE NOW INVALID self._groups = {} self._group_tags = {} self._group_valid_tags = {} self._group_server_handles = {} self._group_handles_tag = {} self._group_hooks = {} try: pythoncom.CoUnInitialize() except: pass # def close(self, del_object=True): # GRACEFUL DISCONNECT FROM CURRENTLY CONNECTED OPC SERVER try: pythoncom.CoInitialize() self.remove(self.groups()) except pythoncom.com_error, err: error_msg = 'Disconnect: %s' % self._get_error_str(err) raise OPCError, error_msg except OPCError: pass finally: