Domanda Problemi Issue with SikuliX API launcher - mouse blocked error

xYoh

Utente Iron
13 Agosto 2021
7
3
0
16
Salve a tutti! Ho creato delle automazioni con sikulixIDE che funzionano alla perfezione. Ho voluto migliorare la gestione delle mie automazione creando un launcher apposito con python che faccia partire le apposite automazioni tramite sikulixAPI (non ho trovato altre soluzioni nel mio caso). Selezioni la dropdown con l'opzione che ti interessa e attivi la checkbox che aprirà il file contenuto nella cartella di riferimento. Ed è qui che si verifica il problema. Il terminale non dà errori, mi riporta l'output dell'applicazione sikulix dove dice in sintesi che il mouse è bloccato. Questo non avviene quando l'automazione viene fatta partire direttamente da sikulixIDE. Inutile dire che ho provato ad eseguire come amministratore e a disattivare l'antivirus di windows (l'unico che ho). Una volta attivata la checkbox, il launcher non risponde per 3 secondi e poi il terminale (pycharm) riporta quell'errore. Ho provato a vedere anche con la versione exe del launcher, ed è la stessa cosa. Grazie in anticipo

output:
C:\Users\peppe\AppData\Local\Programs\Python\Python310\python.exe C:\Users\peppe\PycharmProjects\PokeBot\launcher.py
Checkbox status: True
Process started with PID: 7892
Output: [error] Mouse: not useable (blocked)
[error] script [ ] stopped with error at line --unknown--
[error] --UnKnown-- ( --UnKnown-- )


code:
Python:
from tkinter import *
import subprocess
from PIL import Image, ImageTk
import os
import signal
from tkinter import messagebox

root = Tk()
root.title('Mimiku Bot - 0.7')
root.geometry('300x440+50+50')
root.iconbitmap('media/img/Mimiku.ico')

frame_img = Frame(root, background="#1f1f2e")
frame_img.pack(fill=BOTH, expand=True, side=TOP)

frame_grid = Frame(root, background="#1f1f2e", highlightbackground="#1f1f2e", highlightthickness=20)
frame_grid.pack(fill=BOTH, expand=True, side=BOTTOM)

# definizione funzioni e variabili
def start_process(command, checkbox, check_widget):
    print('Checkbox status:', checkbox.get())
    if checkbox.get():
        # Se la checkbox è stata selezionata, avvia il file
        try:
            process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            pid = process.pid
            print('Process started with PID:', pid)
            # Salva l'oggetto del processo in modo da poterlo utilizzare successivamente
            start_process.process = process

            # Controllo eventuali errori durante l'apertura del file
            try:
                output, error = process.communicate(timeout=30)
            except subprocess.TimeoutExpired:
                process.kill()
                output, error = process.communicate()

            if error:
                print('Error:', error.decode())
            if output:
                print('Output:', output.decode())

        except Exception as e:
            print('Error:', e)
            checkbox.set(False)
            check_widget.deselect()
            check_widget.update()

    else:
        # Se la checkbox è stata deselezionata, termina il processo
        if hasattr(start_process, 'process'):
            pid = start_process.process.pid
            os.kill(pid, signal.SIGTERM)
            print('Process with PID', pid, 'has terminated.')
            output, error = start_process.process.communicate()
            if error:
                print('Error:', error)
            del start_process.process

    # Aggiorna lo stato della checkbox in base al processo
    if hasattr(start_process, 'process'):
        checkbox.set(True)
        if check_widget:
            check_widget.select()
    else:
        checkbox.set(False)
        if check_widget:
            check_widget.deselect()
    if check_widget:
        check_widget.update()



def action_payday():
    command = 'java -jar "sikulixapi-2.0.5.jar" -r "C:\\Users\\peppe\\PycharmProjects\\PokeBot\\bots\\Bot Payday\\' + name_city_value + '.sikuli\\payday.py"'
    start_process(command, checkbox_payday, check1)

def action_levelling():
    command = 'java -jar "sikulixapi-2.0.5.jar" -r "C:\\Users\\peppe\\PycharmProjects\\PokeBot\\bots\\Bot Levelling\\' + name_city2_value + '.sikuli\\' + name_city2_value + '.py"'
    start_process(command, checkbox_levelling, check2)

def action_catching_iv():
    command = 'java -jar "sikulixapi-2.0.5.jar" -r "C:\\Users\\peppe\\PycharmProjects\\PokeBot\\bots\\Bot Catch\\Bot Catch\\(' + type_pokemon_value + ').sikuli\\' + type_pokemon_value + '.py"'
    start_process(command, checkbox_catching_iv, check3)

def action_shiny_hunt():
    command = 'java -jar "sikulixapi-2.0.5.jar" -r "C:\\Users\\peppe\\PycharmProjects\\PokeBot\\bots\\Bot Shiny Hunt\\'+ type_pokemon_shiny_value +'.sikuli\\'+ type_pokemon_shiny_value +'.py"'
    start_process(command, checkbox_shiny_hunt, check4)

def action_market():
    command = 'java -jar "sikulixapi-2.0.5.jar" -r "C:\\Users\\peppe\\PycharmProjects\\PokeBot\\bots\\Bot Market.sikuli\\market(' + value_market_value + ').py"'
    start_process(command, checkbox_market, check5)

def check_status():
    processes = {
        'payday': (checkbox_payday, action_payday),
        'levelling': (checkbox_levelling, action_levelling),
        'catching_iv': (checkbox_catching_iv, action_catching_iv),
        'shiny_hunt': (checkbox_shiny_hunt, action_shiny_hunt),
        'market': (checkbox_market, action_market)
    }
    for process_name, (checkbox_obj, process_obj) in processes.items():
        if checkbox_obj.get() and hasattr(process_obj, 'process'):
            if process_obj.process.poll() is not None:
                # Il processo è terminato
                del process_obj.process
                checkbox_obj.set(False)
            else:
                # Il processo è ancora in esecuzione
                root.after(1000, check_status)  # Ripete la funzione ogni 1 secondo
                return
    # Se la funzione arriva qui, significa che tutti i processi sono stati terminati
    root.after(1000, check_status)  # Ripete la funzione ogni 1 secondo

name_city_value = ''
def on_city_select(event):
    global name_city_value
    name_city_value = name_city.get()

name_city2_value = ''
def on_city2_select(event):
    global name_city2_value
    name_city2_value = name_city2.get()

type_pokemon_value = ''
def on_pokemon_select(event):
    global type_pokemon_value
    type_pokemon_value = type_pokemon.get()

type_pokemon_shiny_value = ''
def on_pokemon_shiny_select(event):
    global type_pokemon_shiny_value
    type_pokemon_shiny_value = type_pokemon_shiny.get()

value_market_value = ''
def on_market_select(event):
    global value_market_value
    value_market_value = value_market.get()


def popup_info_from_file(file_path):
    # Verifico che il file esista
    if not os.path.isfile(file_path):
        messagebox.showerror("Errore", "Il file specificato non esiste")
        return

    # Leggo il contenuto del file
    with open(file_path, "r") as f:
        text = f.read()

    # Mostro il popup con il testo del file
    messagebox.showinfo("Informazioni", text)

# carica l'immagine e ridimensionala
img: Image = Image.open('media/img/Mimiku.png')
img_resized = img.resize((img.size[0]//3, img.size[1]//3)) # ridimensiona l'immagine a 1/3 delle dimensioni originali

# crea un oggetto ImageTk dall'immagine ridimensionata
img_tk = ImageTk.PhotoImage(img_resized)

# crea una label nel frame e imposta l'immagine come suo contenuto
label_img = Label(frame_img, image=img_tk, bd=0)
label_img.pack()

#DROPLIST
name_city = StringVar()
name_city.set('')
name_city2 = StringVar()
name_city2.set('')
type_pokemon = StringVar()
type_pokemon.set('')
type_pokemon_shiny = StringVar()
type_pokemon_shiny.set('')
value_market = StringVar()
value_market.set('')

city_dropdown = OptionMenu(frame_grid, name_city, 'Unova')
city_dropdown.grid(row=1, column=0, padx=5, pady=5, sticky=W)
city_dropdown.config(width=5, height=1)

city_dropdown2 = OptionMenu(frame_grid, name_city2, 'Unova')
city_dropdown2.grid(row=2, column=0, padx=5, pady=5, sticky=W)
city_dropdown2.config(width=5, height=1)

pokemon_dropdown = OptionMenu(frame_grid, type_pokemon, 'All', 'Axew')
pokemon_dropdown.grid(row=3, column=0, padx=5, pady=5, sticky=W)
pokemon_dropdown.config(width=5, height=1)

pokemon_shiny_dropdown = OptionMenu(frame_grid, type_pokemon_shiny, 'Rapidash', 'Poliwag')
pokemon_shiny_dropdown.grid(row=4, column=0, padx=5, pady=5, sticky=W)
pokemon_shiny_dropdown.config(width=5, height=1)

value_dropdown = OptionMenu(frame_grid, value_market, '14k')
value_dropdown.grid(row=5, column=0, padx=5, pady=5, sticky=W)
value_dropdown.config(width=5, height=1)

#CHECKBOX
checkbox_payday = BooleanVar()
checkbox_payday.set(False)
checkbox_levelling = BooleanVar()
checkbox_levelling.set(False)
checkbox_catching_iv = BooleanVar()
checkbox_catching_iv.set(False)
checkbox_shiny_hunt = BooleanVar()
checkbox_shiny_hunt.set(False)
checkbox_market = BooleanVar()
checkbox_market.set(False)

check1 = Checkbutton(frame_grid, text="Payday", variable=checkbox_payday, command=action_payday, width=10, bg='#9595b7', activebackground='green').grid(row=1, column=1, sticky=W, padx=15)
check2 = Checkbutton(frame_grid, text="Levelling", variable=checkbox_levelling, command=action_levelling, width=10, bg='#9595b7', activebackground='green').grid(row=2, column=1, sticky=W, padx=15)
check3 = Checkbutton(frame_grid, text="Catch IV", variable=checkbox_catching_iv, command=action_catching_iv, width=10, bg='#9595b7', activebackground='green').grid(row=3, column=1, sticky=W, padx=15)
check4 = Checkbutton(frame_grid, text="Shiny Hunt", variable=checkbox_shiny_hunt, command=action_shiny_hunt, width=10, bg='#9595b7', activebackground='green').grid(row=4, column=1, sticky=W, padx=15)
check5 = Checkbutton(frame_grid, text="Market", variable=checkbox_market, command=action_market, width=10, bg='#9595b7', activebackground='green').grid(row=5, column=1, sticky=W, padx=15)


#LABEL
label_option1 = Label(frame_grid, text='OPTIONS', fg='white', bg='#1f1f2e').grid(row=0, column=0, padx=5, pady=5, sticky=W)
label_option2 = Label(frame_grid, text='ON / OFF', fg='white', bg='#1f1f2e').grid(row=0, column=1, padx=10, pady=5, sticky=W)

#BUTTONS
button_payday_info = Button(frame_grid, text="info", command=lambda: popup_info_from_file('media/text/payday_info.txt'))
button_payday_info.grid(row=1, column=2, sticky=W, padx=15)

button_levelling_info = Button(frame_grid, text="info", command=lambda: popup_info_from_file())
button_levelling_info.grid(row=2, column=2, sticky=W, padx=15)

button_catching_iv_info = Button(frame_grid, text="info", command=lambda: popup_info_from_file())
button_catching_iv_info.grid(row=3, column=2, sticky=W, padx=15)

button_shiny_hunt_info = Button(frame_grid, text="info", command=lambda: popup_info_from_file())
button_shiny_hunt_info.grid(row=4, column=2, sticky=W, padx=15)

button_market_info = Button(frame_grid, text="info", command=lambda: popup_info_from_file())
button_market_info.grid(row=5, column=2, sticky=W, padx=15)


root.mainloop()