Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WindowStyle to config options #1182

Closed
philliid opened this issue Nov 15, 2019 · 1 comment · Fixed by #1340
Closed

Add WindowStyle to config options #1182

philliid opened this issue Nov 15, 2019 · 1 comment · Fixed by #1340
Milestone

Comments

@philliid
Copy link

Add the WindowStyle to the config options as described in #639.
This opens a python shell to view output when code is running.

@fzumstein fzumstein added this to the 0.19.5 milestone Jun 16, 2020
@fzumstein
Copy link
Member

didn't manage to get this to work on mac so that:

  • terminal shows print statements
  • closes automatically

this is wip and has the issue that it doesn't seem to trigger the atexit handler for the display of the error log.

# Allows to run the script from Script Editor for testing
VbaHandler("TestString")

on VbaHandler(ParameterString)
	set {PYTHONPATH, PythonInterpreter, PythonCommand, WorkbookName, ApplicationFullName, LOG_FILE, ShowConsole} to SplitString(ParameterString, "|")
	set ShellCommand to PythonInterpreter & " -B -u -W ignore -c \"import sys, os;sys.path.extend(os.path.normcase(os.path.expandvars('" & PYTHONPATH & "')).split(';'));" & ¬
		PythonCommand & " \" \"--wb=" & WorkbookName & "\" \"--from_xl=1\" \"--app=" & ApplicationFullName
	try
		do shell script "source ~/.bash_profile"
		if (ShowConsole = "True") then
			tell application "Terminal"
				return do script "source ~/.bash_profile;" & ShellCommand & "\" 2>\"" & LOG_FILE & "\"; exit" # must not be asynchronous for shell to be able to exit - shell requires a setting to be changed to exit automatically, see:
				# https://superuser.com/questions/160473/avoiding-process-completed-prompt-after-terminal-script-ends-on-mac-os-x
			end tell
		else
			return do shell script "source ~/.bash_profile;" & ShellCommand & "\" > /dev/null 2>\"" & LOG_FILE & "\"&" # much slower when synchronous (without trailing "&")
		end if
		
	on error errMsg number errNumber
		try
			# Try again without sourcing .bash_profile
			if (ShowConsole = "True") then
				tell application "Terminal"
					return do script "source ~/.bash_profile;" & ShellCommand & "; exit" # must not be asynchronous for shell to be able to exit - shell requires a setting to be changed to exit automatically, see:
					# https://superuser.com/questions/160473/avoiding-process-completed-prompt-after-terminal-script-ends-on-mac-os-x
				end tell
			else
				return do shell script "source ~/.bash_profile;" & ShellCommand & "&" # much slower when synchronous (without trailing "&")
			end if
		on error errMsg number errNumber
			return 1
		end try
	end try
end VbaHandler

on SplitString(TheBigString, fieldSeparator)
	# From Ron de Bruin's "Mail from Excel 2016 with Mac Mail example": www.rondebruin.nl
	tell AppleScript
		set oldTID to text item delimiters
		set text item delimiters to fieldSeparator
		set theItems to text items of TheBigString
		set text item delimiters to oldTID
	end tell
	return theItems
end SplitString

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants