コード例 #1
0
def main():
    # start with a simple message box
    io.alert("This is the user interaction demo")

    # request a choice
    if not io.requestYesNo("Do you wish to do the demo?"):
        # proceed anyway ;-) show message to the user, alter the button text
        io.alert("too bad, no canceling possible", "Okay then")

    # start a complex user request object
    request = io.UserRequest("please provide some data")
    # add a string input: message, default value(optional)
    request.addString("your name", "Embedded System")
    # add an integer: message, default(optional), min(optional), max(optional)
    request.addInteger("your age", 30, 1, 120)
    # add an bool input: message, default(optional), yesName(optional) noName(optional)
    request.addBool("Are you married?", False, "Yep", "Nope")
    #add a floating point input: message, default(optinal)
    request.addFloat("enter PI", 3.14)

    #now, add some buttons
    BuyChoice = 1

    # add button: name, id(optional)
    request.addButton("I want to buy", BuyChoice)
    request.addButton("Abort")

    # now show the request, the method waits for the user input
    buttonId = request.execute()

    if buttonId == BuyChoice:
        print(request.values())
    else:
        print("aborted")
コード例 #2
0
def main():
	# start with a simple message box
	io.alert("This is the user interaction demo");
	
	# request a choice
	if not io.requestYesNo("Do you wish to do the demo?"):
		# proceed anyway ;-) show message to the user, alter the button text
		io.alert("too bad, no canceling possible", "Okay then");
		
	# start a complex user request object
	request = io.UserRequest("please provide some data");
	# add a string input: message, default value(optional)
	request.addString("your name", "Embedded System"); 
	# add an integer: message, default(optional), min(optional), max(optional)
	request.addInteger("your age", 30, 1, 120); 
	# add an bool input: message, default(optional), yesName(optional) noName(optional)
	request.addBool("Are you married?", False, "Yep", "Nope");
	#add a floating point input: message, default(optinal)
	request.addFloat("enter PI", 3.14);
	
	#now, add some buttons
	BuyChoice = 1
	
	# add button: name, id(optional)
	request.addButton("I want to buy", BuyChoice);
	request.addButton("Abort");
	
	# now show the request, the method waits for the user input
	buttonId = request.execute();
	
	if buttonId == BuyChoice:
		print(request.values());
	else:
		print("aborted");
コード例 #3
0
ファイル: progressBar.py プロジェクト: ondrocks/Framework
def main():
	# silly example, print out a word of a string each half second and show progress
	string = "Hello out there, is everything alright? Please wait for this demo to finish."
	parts = string.split(" ");
	
	# provide a name and the total number of steps to the progress bar
	progress = io.ProgressBar("print progress", len(parts));
	for i in range(len(parts)):
		print(parts[i], end=' ');
		# set the progress
		progress.setProgress(i+1);
		time.sleep(0.5);
	print(""); # provide a newline
	io.alert("Finished", "End this silly demo");
コード例 #4
0
def main():
    # first, setup a user request
    request = io.UserRequest("Hurry, time is running!")
    request.addFloat("15*22.5-133.2")
    result = 15 * 22.5 - 133.2
    # execute the request in an extra thread

    threaded = util.ThreadExecute(request.execute)

    # give the user 10 seconds to answer
    duration = 10

    # create a progress bar
    progress = io.ProgressBar("seconds elapsed", duration)

    hasAnswered = False

    for i in range(duration):
        time.sleep(1)
        progress.setProgress(i + 1)
        # check if the thread is finished: if so the user clicked
        if threaded.finished():
            hasAnswered = True
            break

    if not hasAnswered:
        request.abort()
        # hides the user input screen
        io.alert("Sorry, time is up")
    else:
        if request.values()[0] == result:
            io.alert("Amazing, your a genius", "Yeae")
        else:
            io.alert("Sorry, wrong answer", "Damn it")
コード例 #5
0
def main():
	# first, setup a user request
	request = io.UserRequest("Hurry, time is running!");
	request.addFloat("15*22.5-133.2");
	result = 15*22.5-133.2;
	# execute the request in an extra thread
	
	threaded = util.ThreadExecute(request.execute);
	
	# give the user 10 seconds to answer
	duration = 10;
	
	# create a progress bar
	progress = io.ProgressBar("seconds elapsed", duration);
	
	hasAnswered = False;
	
	for i in range(duration):
		time.sleep(1);
		progress.setProgress(i+1);
		# check if the thread is finished: if so the user clicked
		if threaded.finished():
			hasAnswered = True;
			break;
	
	if not hasAnswered:
		request.abort(); # hides the user input screen
		io.alert("Sorry, time is up");
	else:
		if request.values()[0] == result:
			io.alert("Amazing, your a genius", "Yeae");
		else:
			io.alert("Sorry, wrong answer", "Damn it");