rendered paste body#!/usr/bin/env python
# ipc_test.py
from Tkinter import Tk
from libtovid.appdialogs import ConfirmDialog
import os, select
# Simple script to test bash > python ipc.
# From bash: mkfifo fifo
# echo "dialog|Preview OK ?|ok, cancel| /home/robert/preview.gif" > fifo
# Then run python ipc_test.py
def format_input(string):
stringlist = []
string = string.split('|')
for index, arg in enumerate(string):
stringlist.append(arg.strip())
stringlist[2] = stringlist[2].split(',')
return stringlist
def run_dialog(args):
print 'running dialog'
btns='OK'
root = Tk()
title, text, buttons, image = args
a = ConfirmDialog(root, title, text, buttons, image)
a.run()
def get_data(fifo):
while True:
select.select([fifo],[],[])
string = os.read(fifo, 1024)
if len(string):
listing = format_input(string)
print listing
run_dialog(listing)
else:
nf = os.open("fifo", os.O_NONBLOCK | os.O_RDONLY)
os.close(fifo)
fifo = nf
try:
fifo = os.open("fifo", os.O_NONBLOCK | os.O_RDONLY)
data = get_data(fifo)
except KeyboardInterrupt:
os.sys.exit(1)