Mac aleart всплывающие окна в openCV - PullRequest
0 голосов
/ 29 октября 2019

Я пытаюсь заставить Mac всплывающие окна работать для моего маленького проекта openCV с использованием applecript, но я не могу заставить его работать, я прокомментировал, как это должно быть сделано в Windows, но продолжаю получать неверную синтаксическую ошибку длямое возвращаемое значение applecript

    __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 ==

1 Ответ

1 голос
/ 29 октября 2019

У вас есть синтаксическая ошибка, когда вы определяете 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"}
    """

Кроме того, этот синтаксис с квадратными скобками вызывает больше ошибок. Я не уверен, каково их намерение, но я предполагаю, что это для введения переменных в строку, и в этом случае ваш окончательный код будет выглядеть примерно так:

returnValue = applescript + """
    display dialog "%s %s"
    with title "%s %s"
    with icon caution 
    buttons  {"OK"}
    """ % (None,self.name,self.type, 1)

Вам нужно будет решить, гдеПеременные будут идти и как они должны быть отформатированы для отображения в соответствии с вашими потребностями, но это, по крайней мере, поможет вам в этом.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...