MCPcopy Create free account
hub / github.com/mhammond/pywin32 / RunScript

Function RunScript

Pythonwin/pywin/framework/scriptutils.py:189–369  ·  view source on GitHub ↗
(defName=None, defArgs=None, bShowDialog = 1, debuggingType=None)

Source from the content-addressed store, hash-verified

187lastDebuggingType = RS_DEBUGGER_NONE
188
189def RunScript(defName=None, defArgs=None, bShowDialog = 1, debuggingType=None):
190 global lastScript, lastArgs, lastDebuggingType
191 _debugger_stop_frame_ = 1 # Magic variable so the debugger will hide me!
192
193 # Get the debugger - may be None!
194 debugger = GetDebugger()
195
196 if defName is None:
197 try:
198 pathName = GetActiveFileName()
199 except KeyboardInterrupt:
200 return # User cancelled save.
201 else:
202 pathName = defName
203 if not pathName:
204 pathName = lastScript
205 if defArgs is None:
206 args = ''
207 if pathName==lastScript:
208 args = lastArgs
209 else:
210 args = defArgs
211 if debuggingType is None: debuggingType = lastDebuggingType
212
213 if not pathName or bShowDialog:
214 dlg = DlgRunScript(debugger is not None)
215 dlg['script'] = pathName
216 dlg['args'] = args
217 dlg['debuggingType'] = debuggingType
218 if dlg.DoModal() != win32con.IDOK:
219 return
220 script=dlg['script']
221 args=dlg['args']
222 debuggingType = dlg['debuggingType']
223 if not script: return
224 if debuggingType == RS_DEBUGGER_GO and debugger is not None:
225 # This may surprise users - they select "Run under debugger", but
226 # it appears not to! Only warn when they pick from the dialog!
227 # First - ensure the debugger is activated to pickup any break-points
228 # set in the editor.
229 try:
230 # Create the debugger, but _dont_ init the debugger GUI.
231 rd = debugger._GetCurrentDebugger()
232 except AttributeError:
233 rd = None
234 if rd is not None and len(rd.breaks)==0:
235 msg = "There are no active break-points.\r\n\r\nSelecting this debug option without any\r\nbreak-points is unlikely to have the desired effect\r\nas the debugger is unlikely to be invoked..\r\n\r\nWould you like to step-through in the debugger instead?"
236 rc = win32ui.MessageBox(msg, win32ui.LoadString(win32ui.IDR_DEBUGGER), win32con.MB_YESNOCANCEL | win32con.MB_ICONINFORMATION)
237 if rc == win32con.IDCANCEL:
238 return
239 if rc == win32con.IDYES:
240 debuggingType = RS_DEBUGGER_STEP
241
242 lastDebuggingType = debuggingType
243 lastScript = script
244 lastArgs = args
245 else:
246 script = pathName

Callers

nothing calls this directly

Calls 15

ParseArgsFunction · 0.90
GetActiveFileNameFunction · 0.85
DlgRunScriptClass · 0.85
LocatePythonFileFunction · 0.85
IsOnPythonPathFunction · 0.85
_HandlePythonFailureFunction · 0.85
appendMethod · 0.80
insertMethod · 0.80
PumpWaitingMessagesMethod · 0.80
EnsureNoPromptMethod · 0.80
AppendToPromptMethod · 0.80
GetDebuggerFunction · 0.70

Tested by

no test coverage detected