def load(self, pmgapp=None, force=0): ''' Load and initialize plugin. If pmgapp == -1, do not initialize. ''' import time assert not self.is_temporary starttime = time.time() if pmgapp is None: pmgapp = get_pmgapp() verbose = pref_get('verbose', False) try: # overload cmd.extend to register commands extend_orig = cmd.extend def extend_overload(a, b=None): self.commands.append(a if b else a.__name__) return extend_orig(a, b) cmd.extend = extend_overload # do not use self.loaded here if force and self.module is not None: from importlib import reload reload(self.module) else: __import__(self.mod_name, level=0) if pmgapp != -1: self.legacyinit(pmgapp) cmd.extend = extend_orig self.loadtime = time.time() - starttime if verbose and pymol.invocation.options.show_splash: print(' Plugin "%s" loaded in %.2f seconds' % (self.name, self.loadtime)) except QtNotAvailableError: colorprinting.warning("Plugin '%s' only available with PyQt GUI." % (self.name, )) except: e = sys.exc_info()[1] if verbose: colorprinting.print_exc([__file__]) elif 'libX11' in str(e) and sys.platform == 'darwin': colorprinting.error( 'Please install XQuartz (https://www.xquartz.org/)') else: colorprinting.error(e) colorprinting.warning("Unable to initialize plugin '%s' (%s)." % (self.name, self.mod_name)) return False return True
def load(self, pmgapp=None, force=0): ''' Load and initialize plugin. If pmgapp == -1, do not initialize. ''' import time assert not self.is_temporary starttime = time.time() if pmgapp is None: pmgapp = get_pmgapp() verbose = pref_get('verbose', False) try: # overload cmd.extend to register commands extend_orig = cmd.extend def extend_overload(a, b=None): self.commands.append(a if b else a.__name__) return extend_orig(a, b) cmd.extend = extend_overload # do not use self.loaded here if force and self.module is not None: if sys.version_info[0] > 2: from importlib import reload else: from __builtin__ import reload reload(self.module) else: __import__(self.mod_name, level=0) if pmgapp != -1: self.legacyinit(pmgapp) cmd.extend = extend_orig self.loadtime = time.time() - starttime if verbose and pymol.invocation.options.show_splash: print(' Plugin "%s" loaded in %.2f seconds' % (self.name, self.loadtime)) except QtNotAvailableError: colorprinting.warning("Plugin '%s' only available with PyQt GUI." % (self.name,)) except: e = sys.exc_info()[1] if verbose: colorprinting.print_exc([__file__]) elif 'libX11' in str(e) and sys.platform == 'darwin': colorprinting.error('Please install XQuartz (https://www.xquartz.org/)') else: colorprinting.error(e) colorprinting.warning("Unable to initialize plugin '%s' (%s)." % (self.name, self.mod_name)) return False return True
def exec_deferred(self): ''' Execute the stuff from invocations.options.deferred ''' try: from socket import error as socket_error except ImportError: socket_error = None print('import socket failed') cmd = self.cmd _pymol = cmd._pymol # read from stdin (-p) if self.invocation.options.read_stdin and not _pymol._stdin_reader_thread: try: t = _pymol._stdin_reader_thread = \ threading.Thread(target=cmd._parser.stdin_reader) t.setDaemon(1) t.start() except: traceback.print_exc() # do the deferred stuff try: if cmd.ready(): cmd.config_mouse(quiet=1) for a in self.invocation.options.deferred: if a[0:4] == "_do_": cmd.do(a[4:]) else: cmd.load(a, quiet=0) except CmdException as e: colorprinting.error(str(e)) colorprinting.error( " Error: Argument processing aborted due to exception (above).") except socket_error: # this (should) only happen if we're opening a PWG file on startup # and the port is busy. For now, simply bail... cmd.wizard("message",["Socket.error: ","", "\\999Assigned socket in use.","", "\\779Is PyMOL already launched?","", "\\966Shutting down..."]) cmd.refresh() cmd.do("time.sleep(2);cmd.quit()")