def run(self): comtypes.CoInitializeEx(comtypes.COINIT_MULTITHREADED) while self.isUsable: self._executeEvent.wait() self._executeEvent.clear() try: self._result = self._func(*self._args, **self._kwargs) except Exception as e: self._exc_info = e ctypes.windll.kernel32.SetEvent(self._executionDoneEvent) ctypes.windll.kernel32.CloseHandle(self._executionDoneEvent)
def _win_create_quick_launch(): """Create a quicklaunch icon for windows, 7,8,8.1.""" # pylint: disable=no-name-in-module,import-error from comtypes.gen.IWshRuntimeLibrary import IWshShortcut comtypes.CoInitializeEx() shell = comtypes.client.CreateObject('WScript.Shell') shortcut = shell.CreateShortCut( os.path.expanduser(r'~\Links\CrossCloud.lnk')) shortcut = shortcut.QueryInterface(IWshShortcut) shortcut.TargetPath = config.sync_root # shortcut.Icon = ICON try: shortcut.Save() except comtypes.COMError: logger.exception('Cant create shortcut')
def get_tecnaiccd(): if client_module.tecnaiccd is None: if com_module == 'win32com': pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED) client_module.tecnaiccd = client_module.dynamic.Dispatch( 'TecnaiCCD.GatanCamera.2') elif com_module == 'comtypes': try: comtypes.CoInitializeEx(comtypes.COINIT_MULTITHREADED) except WindowsError: ''' ConinitializeEx can not change thread property when the module directly creating instance in python command gatan.Gatan(). When access remotely through Leginon client, Coinitialize is needed and does not give error. ''' comtypes.CoInitialize() client_module.tecnaiccd = client_module.CreateObject( 'TecnaiCCD.GatanCamera.2') return client_module.tecnaiccd
def _currentSong(self): import comtypes assert threading.currentThread().getName() == 'MainThread' try: song = self.client.CurrentTrack except comtypes.COMError, e: ecode = e.args[0] if ecode == -0x7ffeffff: # "Call was rejected by callee." - this happens if we ask while user is doing 'get info' on a track return getattr(self, '_lastsong', None) elif ecode == -0x7ffefef8: # "The object invoked has disconnected from its clients." - user quit iTunes self._release() return None elif ecode == -0x7ffbfe10: # 'CoInitialize has not been called.' comtypes.CoInitializeEx() return getattr(self, '_lastsong', None) else: raise e
def before_request(): if has_comtypes: comtypes.CoInitializeEx(0x0) # In multi-user mode, the user id should be read from the session cookie, though if # not we should use the null user. if MULTIUSER_MODE: user_id = session.get("user_id", null_user.id) # Otherwise, we should always use the null user since single user mode should not # be using user ids for project isolation. else: user_id = null_user.id # Use the user id to request the associated UserIdentity object from the global # identity provider. Future implementations of the IdentityProvider may cause this # action to fail, in which case this failure will need to be propagated somehow? g.user = identity_provider.new_user(user_id) # Use the per-connection cookie containing the project ID to attach the corrent # ApplicationManager instance to the context, or use the default project. project_id = int(request.cookies.get("project_id", 0)) if project_id == "": project_id = 0 associate_project_context(project_id) # Set up the context's wrappers around the ApplicationManager to # seamlessly propagate the user def add_message(message): if message.user is None: message.user = g.user g.manager.add_message(message) def add_task(task): if task.user == null_user and g.user != null_user: task.user = g.user g.manager.add_task(task) g.add_message = add_message g.add_task = add_task g.has_native_client = has_native_client()
def _read(self, file_path): options = { "foreignFile": file_path, "foreignFormat": os.path.splitext(file_path)[1], } # Starting app and Coinit before comtypes.CoInitializeEx(comtypes.COINIT_MULTITHREADED) try: options = self.startApp(options) except Exception: Logger.logException("e", "Failed to start <%s>...", self._app_name) error_message = Message( i18n_catalog.i18nc( "@info:status", "Error while starting {}!".format( self._app_friendly_name))) error_message.show() return None # Tell the 3rd party application to open a file... Logger.log("d", "Opening file with {}...".format(self._app_friendly_name)) options = self.openForeignFile(options) # Append all formats which are not preferred to the end of the list fileFormats = self._file_formats_first_choice for file_format in self._reader_for_file_format.keys(): if file_format not in fileFormats: fileFormats.append(file_format) # Trying to convert into all formats 1 by 1 and continue with the successful export Logger.log("i", "Trying to convert into: %s", fileFormats) scene_node = None for file_format in fileFormats: Logger.log("d", "Trying to convert <%s> into '%s'", file_path, file_format) options["tempType"] = file_format # Creating a unique file in the temporary directory.. options["tempFile"] = os.path.join( tempfile.tempdir, "{}.{}".format(uuid.uuid4(), file_format.upper()), ) Logger.log("d", "Using temporary file <%s>", options["tempFile"]) # In case there is already a file with this name (very unlikely...) if os.path.isfile(options["tempFile"]): Logger.log("w", "Removing already available file, called: %s", options["tempFile"]) os.remove(options["tempFile"]) Logger.log("d", "Saving as: <%s>", options["tempFile"]) try: self.exportFileAs(options) except: Logger.logException("e", "Could not export <%s> into '%s'.", file_path, file_format) continue if os.path.isfile(options["tempFile"]): Logger.log("d", "Saved as: <%s>", options["tempFile"]) else: Logger.log("d", "Temporary file not found after export!") continue # Opening the resulting file in Cura try: reader = Application.getInstance().getMeshFileHandler( ).getReaderForFile(options["tempFile"]) if not reader: Logger.log("d", "Found no reader for %s. That's strange...", file_format) continue Logger.log("d", "Using reader: %s", reader.getPluginId()) scene_node = reader.read(options["tempFile"]) except: Logger.logException( "e", "Failed to open exported <%s> file in Cura!", file_format) continue # Remove the temp_file again Logger.log("d", "Removing temporary %s file, called <%s>", file_format, options["tempFile"]) break # Closing document in the app self.closeForeignFile(options) # Closing the app again.. self.closeApp(options) comtypes.CoUninitialize() # Nuke the instance! if "app_instance" in options.keys(): del options["app_instance"] # the returned node from STL or 3MF reader can be a node or a list of nodes scene_node_list = scene_node if not isinstance(scene_node, list): scene_node_list = [scene_node] for node in scene_node_list: self.nodePostProcessing(node) return scene_node
def CoInit(): comtypes.CoInitializeEx(comtypes.COINIT_MULTITHREADED)