예제 #1
0
	def ProcessArgs(self, args, dde = None):
		# If we are going to talk to a remote app via DDE, then
		# activate it!
		if dde is not None: dde.Exec("self.Activate()")
		if len(args) and args[0] in ['/nodde','/newinstance']: del args[0] # already handled.
		if len(args)<1 or not args[0]: # argv[0]=='' when started without args, just like Python.exe!
			return
		try:
			if args[0] and args[0][0]!='/':
				argStart = 0
				argType = win32ui.GetProfileVal("Python","Default Arg Type","/edit").lower()
			else:
				argStart = 1
				argType = args[0]
			if argStart >= len(args):
				raise TypeError("The command line requires an additional arg.")
			if argType=="/edit":
				# Load up the default application.
				if dde:
					fname = win32api.GetFullPathName(args[argStart])
					dde.Exec("win32ui.GetApp().OpenDocumentFile(%s)" % (repr(fname)))
				else:
					win32ui.GetApp().OpenDocumentFile(args[argStart])
			elif argType=="/rundlg":
				if dde:
					dde.Exec("from pywin.framework import scriptutils;scriptutils.RunScript('%s', '%s', 1)" % (args[argStart], ' '.join(args[argStart+1:])))
				else:
					import scriptutils
					scriptutils.RunScript(args[argStart], ' '.join(args[argStart+1:]))
			elif argType=="/run":
				if dde:
					dde.Exec("from pywin.framework import scriptutils;scriptutils.RunScript('%s', '%s', 0)" % (args[argStart], ' '.join(args[argStart+1:])))
				else:
					import scriptutils
					scriptutils.RunScript(args[argStart], ' '.join(args[argStart+1:]), 0)
			elif argType=="/app":
				raise RuntimeError("/app only supported for new instances of Pythonwin.exe")
			elif argType=='/new': # Allow a new instance of Pythonwin
				return 1
			elif argType=='/dde': # Send arbitary command
				if dde is not None:
					dde.Exec(args[argStart])
				else:
					win32ui.MessageBox("The /dde command can only be used\r\nwhen Pythonwin is already running")
			else:
				raise TypeError("Command line arguments not recognised")
		except:
			# too early for print anything.
			win32ui.DisplayTraceback(sys.exc_info(), " - error processing command line args")
예제 #2
0
	def _DoOrStart(self, doMethod, startFlag):
		d=self._GetDebugger()
		if d is not None and d.IsDebugging():
			method = getattr(d, doMethod)
			method()
		else:
			scriptutils.RunScript(defName=None, defArgs=None, bShowDialog = 0, debuggingType=startFlag)
예제 #3
0
파일: intpyapp.py 프로젝트: hnur/pywin32
 def OnFileRun(self, id, code):
     " Called when a FileRun message is received. "
     import scriptutils
     showDlg = win32api.GetKeyState(win32con.VK_SHIFT) >= 0
     scriptutils.RunScript(None, None, showDlg)
예제 #4
0
파일: intpyapp.py 프로젝트: beiske/play
 def ProcessArgs(self, args, dde=None):
     # If we are going to talk to a remote app via DDE, then
     # activate it!
     if dde is not None: dde.Exec("self.Activate()")
     if len(args) and args[0] in ['/nodde', '/newinstance']:
         del args[0]  # already handled.
     if len(args) < 1 or not args[
             0]:  # argv[0]=='' when started without args, just like Python.exe!
         return
     try:
         if args[0] and args[0][0] != '/':
             argStart = 0
             argType = string.lower(
                 win32ui.GetProfileVal("Python", "Default Arg Type",
                                       "/edit"))
         else:
             argStart = 1
             argType = args[0]
         if argStart >= len(args):
             raise TypeError, "The command line requires an additional arg."
         if argType == "/edit":
             # Load up the default application.
             if dde:
                 fname = win32api.GetFullPathName(args[argStart])
                 dde.Exec("win32ui.GetApp().OpenDocumentFile(%s)" %
                          ( ` fname `))
             else:
                 win32ui.GetApp().OpenDocumentFile(args[argStart])
         elif argType == "/rundlg":
             if dde:
                 dde.Exec(
                     "import scriptutils;scriptutils.RunScript('%s', '%s', 1)"
                     % (args[argStart], string.join(args[argStart + 1:])))
             else:
                 import scriptutils
                 scriptutils.RunScript(args[argStart],
                                       string.join(args[argStart + 1:]))
         elif argType == "/run":
             if dde:
                 dde.Exec(
                     "import scriptutils;scriptutils.RunScript('%s', '%s', 0)"
                     % (args[argStart], string.join(args[argStart + 1:])))
             else:
                 import scriptutils
                 scriptutils.RunScript(args[argStart],
                                       string.join(args[argStart + 1:]), 0)
         elif argType == "/app":
             raise RuntimeError, "/app only supported for new instances of Pythonwin.exe"
         elif argType == '/new':  # Allow a new instance of Pythonwin
             return 1
         elif argType == '/dde':  # Send arbitary command
             if dde is not None:
                 dde.Exec(args[argStart])
             else:
                 win32ui.MessageBox(
                     "The /dde command can only be used\r\nwhen Pythonwin is already running"
                 )
         else:
             raise TypeError, "Command line arguments not recognised"
     except:
         typ, val, tb = sys.exc_info()
         print "There was an error processing the command line args"
         traceback.print_exception(typ, val, tb, None, sys.stdout)
         win32ui.OutputDebug(
             "There was a problem with the command line args - %s: %s" %
             ( ` typ `, ` val `))
         tb = None  # Prevent a cycle