MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / runClick

Function runClick

src/gamesbyexample/__init__.py:93–117  ·  view source on GitHub ↗
(*args)

Source from the content-addressed store, hash-verified

91
92
93def runClick(*args):
94 i = CURRENT_SELECTED_INDEX
95 filename = os.path.join(FOLDER_OF_THIS_FILE, PROGRAMS[i]['filename'])
96 TERMINAL_OPENER_FILENAME = os.path.join(FOLDER_OF_THIS_FILE, '__terminalopener__.py')
97 CRASH_DETECTOR_FILENAME = os.path.join(FOLDER_OF_THIS_FILE, '__crashdetector__.py')
98
99 # Figure out which program to run to open a new terminal window and then run the .py file:
100 if sys.platform == 'win32':
101 # 'start cmd' opens a new Command Prompt terminal window
102 # '/K' tells the Command Prompt to run this command:
103 # We want to run the same Python executable that is running this __init__.py script.
104 # That Python should run __crashdetector__.py, with __version__ and filename as arguments
105 # Crash detector will run filename as a Python script, and __version__ is used in the debug output if that program crashes.
106
107 #os.system('start cmd /K ' + sys.executable + ' ' + CRASH_DETECTOR_FILENAME + ' ' + __version__ + ' ' + filename)
108 # If we run the following line instead of the previous, Ctrl-C will work on Windows but we don't get crash reporting.
109 os.system('start cmd /K ' + sys.executable + ' ' + filename)
110 elif sys.platform == 'darwin':
111 os.system('''osascript -e 'tell application "Terminal" to do script "''' + sys.executable + ' ' + CRASH_DETECTOR_FILENAME + ' ' + __version__ + ' ' + filename + '"' + "'")
112 elif _executable_exists('gnome-terminal'):
113 # gnome-terminal is used on Ubuntu Linux:
114 subprocess.call(['gnome-terminal', '--', sys.executable, TERMINAL_OPENER_FILENAME, __version__, filename])
115 elif _executable_exists('lxterminal'):
116 # LXTerminal is used on Raspberry Pis:
117 subprocess.call(['lxterminal', '-e', sys.executable, TERMINAL_OPENER_FILENAME, __version__, filename])
118
119
120def viewSourceClick(*args):

Callers

nothing calls this directly

Calls 1

_executable_existsFunction · 0.85

Tested by

no test coverage detected