我试图让mac弹出窗口使用applescript为我的小openCV项目工作,但我似乎无法让它工作,我已经评论了它是如何在windows中完成的,但我的返回值不断出现无效的语法错误苹果脚本
__author__ = 'x'
# Required for tkinter module graphics including GUI
from tkinter import *
# ttk is a sub-module of tkinter providing more 'themed' widgets - can be mixed with tkinter widgets
from tkinter import ttk
# Import OpenCV "Open Source Computer Vision"
import subprocess
# import subprocess for Mac alert pop up windows
# This is a simulation of workflow execution
@docStringDecorator
def executeXML_Workflow(self):
''' ctypes is a Python library that includes message boxes ... solution from ...
http://win32com.goermezer.de/content/view/288/243/ '''
import ctypes
# Declare a messagebox
# msgbox = ctypes.windll.user32.MessageBoxW
msgbox = applescript
# Declare and initialise a counter
count = 0
# Declare and initialise variable to detect messagebox button press types thereby break if 2 (Quit) clicked
returnValue = 0
# Iterate over XML tree object and output to message box
# NOTE: regarding Iterator Patterns, Python has built in iterators to all collections using for-in
for wfStep in self.root.findall('wfStep'):
# Increment the counter of workflow steps
count += 1
# .get is used to obtain attributes
self.type = wfStep.get('type')
self.API_call= wfStep.find('API_call').text
print("self.API_call is .....................", self.API_call)
self.name = "Step Number ... "+str(count)+"\n\nName: "+ wfStep.find('name').text+ "\n\nDescription: "+wfStep.find('description').text+"\n\nParameters: "+wfStep.find('parameters').text+ "\n\nAPI INSTRUCTION: "+wfStep.find('API_call').text
#Create a strategy selection object delegate resolving step functions to this
wfs = WfStepStrategyContext.BuildWfObject(self.type)
wfs.processActions(self.API_call)
#returnValue = msgbox(None, self.name, self.type, 1)
returnValue = applescript """
display dialog"""+(None,self.name,self.type, 1)"""
with title "this is a mac pop up""
with icon caution
buttons {"OK"}
"""
print("Return Value is ...", returnValue)
if returnValue ==
最佳答案
您在定义 returnValue
时遇到语法错误.
你的代码:
returnValue = applescript """
display dialog"""+(None,self.name,self.type, 1)"""
with title "this is a mac pop up""
with icon caution
buttons {"OK"}
"""
它缺少一些导致您的语法错误的连接。它应该是这样的:
returnValue = applescript + """
display dialog"""+(None,self.name,self.type, 1)+"""
with title "this is a mac pop up""
with icon caution
buttons {"OK"}
"""
此外,这种带括号的语法会导致更多错误。我不确定这些的意图究竟是什么,但我假设它用于将变量注入(inject)到字符串中,在这种情况下,您的最终代码将类似于以下内容:
returnValue = applescript + """
display dialog "%s %s"
with title "%s %s"
with icon caution
buttons {"OK"}
""" % (None,self.name,self.type, 1)
您需要决定变量的去向以及需要如何格式化它们才能满足您的需求,但这至少应该能让您顺利上路。
关于python - openCV中的Mac警报弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58605814/