Skip to content

run/kill a python script with another python script with help of EVDEV : bounce effect #232

Description

@bbd666

this is a basic python script to draw a frame , toto.py

from tkinter import *
from tkinter import ttk
from tkinter import font as tkFont
from PIL import Image, ImageTk
import os
os.environ['DISPLAY'] = ':0'
decal_x=410
decal_y=360
root=Tk()
root.configure(bg='blue')
window_height=350
window_width=400
style_1 = ttk.Style()
style_1.configure('TFrame',background='yellow') screen_width=root.winfo_screenwidth()
screen_height=root.winfo_screenheight()
x_cordinate = int((screen_width/2) - (window_width/2))
y_cordinate = int((screen_height/2) - (window_height/2))
root.geometry("{}x{}+{}+{}".format(window_width, window_height, x_cordinate+40, y_cordinate))
content = ttk.Frame(root,style='new.TFrame')
content.place(x=decal_x, y=decal_y, anchor="se", width=window_width, height=window_height)
root.mainloop()

This a python script to run and kill (alternately) toto.py by typing 0-key of the remote ctrl

import time
import evdev
import os
import subprocess
def get_ir_device():
devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
for device in devices:
if (device.name == "gpio_ir_recv"): return device def trig_ir():
global last_call
global s
event = dev.read_one()
result = None if event is None:
return
else: if not(event.code==0): t = time.perf_counter() if t - last_call > 0.5:
print('ok')
last_call = t
value = event.value
return value
dev = get_ir_device()
process_pid=0
os.system('sh remote.sh')
last_call =time.perf_counter() while True:
key=trig_ir()
if (key==0):
#print('0-key typed')
if process_pid>0:
os.system("pkill -f 'toto.py'")
time.sleep(2)
print('1 process killed')
process_pid=0
else:
print('1 process launched')
process = subprocess.Popen(["python", "toto.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process_pid=process.pid

when I press 0-key it runs toto.py
if I press again 0-key, very often (not always) it stops toto.py then it restarts toto.py
pls tell me what's wrong there

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions