Hello World app

From eyeOS Developers Wiki

Jump to: navigation, search

Contents

[edit] Introduction

In this first example we'll create a "Hello World" app, a simple application with a small window, a "Hello World" Label and a Textbox/Button in one side to modify the "Hello World" title.

[edit] Files

[edit] File: app.eyecode

<?php
function HelloWorld_run($params=null) {
	// We create the window:
	$myWindow1 = new Window(array(
		'name' => 'HelloWorld_wnd',
		'father' => 'eyeApps',
		'cent' => 1,
		'width' => 250,
		'height' => 150,
		'title' => 'Hello World example'
	));
	$myWindow1->show();
 
	// We add the initial "Hello World!" Label:
	$myLabel1 = new Label(array(
		'name' => 'HelloWorld_lbl',
		'father' => 'HelloWorld_wnd_Content',
		'x' => 20,
		'y' => 20,
		'text' => 'Hello World!'
	));
	$myLabel1->show(0);
 
	// We create the Textarea where the user 
	// will add the new "Hello World!" message:
	$myTextbox1 = new Textbox(array(
		'name'=>'HelloWorld_txt',
		'father'=>'HelloWorld_wnd_Content',
		'x' => 20,
		'y' => 50,
		'width' => 150
	));
	$myTextbox1->show();
	// We focus it, so the user can start typing 
	// from the moment he opens the app without 
	// having to click into the textarea:
	$myTextbox1->focus();
 
	$myButton1 = new Button(array(
		'name'=>'HelloWorld_btn',
		'father'=>'HelloWorld_wnd_Content',
		'caption'=>'Change Label Text',
		'x'=>20,
		'y'=>80
	));
	// We add the Textbox as friend of the button, 
	// so the user when clicks the button will be 
	// sending the textbox input text. A button can 
	// have as many friends as user wants:
	$myButton1->addFriend($myTextbox1);
	$myButton1->show();
}
 
function HelloWorld_end($params=null) {
	reqLib('eyeWidgets','unserialize');
}
?>

[edit] File: events.eyecode

<?php
// We create the NAMEOFAPP_on_NAMEOFBUTTON function.
// In this case, the app is HelloWorld and the button 
// is HelloWorld_BTN:
function HelloWorld_on_HelloWorld_btn($params="") {
	// We grab the current text inside the textbox:
	$myCurrentText = $GLOBALS['HelloWorld_txt']->text;
	// We set the text in the textbox in the Label:
	$GLOBALS['HelloWorld_lbl']->setText($myCurrentText);
	// Finally, we clean the textbox and focus it again
	// so the user can continue writting:
	$GLOBALS['HelloWorld_txt']->setText('');
	$GLOBALS['HelloWorld_txt']->focus();
}
 
// This function is executed in each received message BEFORE 
// Execute the message.
// The widget library need to update the contents of the widgets,
// and there is the correct place for do the update.
// The updated is performed calling to updateContent.
// It's an automatic function, so you can just copy it over
// your apps that use messages by simply changing the app's name:
function HelloWorld_on_Message($params="") {
	reqLib('eyeWidgets','updateContent',$params);
}
 
// Finally, the NAMEOFAPP_on_Close() function will be executed when
// the user closes the application using the "x" button in the window bar. 
// This code defines what happens when the "x" button is pressed, normally
// The app should remove itself from the system table (kill)
function HelloWorld_on_Close(){
	global $myPid;
	service('proc','close',array($myPid));
}
?>
Personal tools