Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

alissong

erro ASCII=92

Recommended Posts

Pessoal,

 

Peguei esse código na site php-gtk brasil, mas exibe esse erro:

Warning: Unexpected character in input: '\' (ASCII=92) state=1 na linha 3

Veja o código abaixo:

 

<?php

class ExemploFormularioValidacao
{
    private $janela;
    private $entrada_1;
    private $entrada_2;
    private $entrada_3;
    private $entrada_4;
    private $entrada_5;
    private $entrada_6;
    private $botao;

public function __construct(){

// Cria a janela
$this->janela= new GtkWindow();
// Define título da janela
$this->janela->set_title('Validação de Formulário');
// Define tamanho da janela
$this->janela->set_size_request(300,250);
//Define espaçamento de borda
$this->janela->set_border_width(10);

// Cria uma caixa vertical
$vbox1 = new GtkVbox();

// Cria rótulos do formulário
$label_1 = new GtkLabel("Nome * ");
$label_1->set_size_request(80,-1);
$label_1->set_alignment(1, 0.5);
$label_2 = new GtkLabel("Endereço * ");
$label_2->set_alignment(1, 0.5);
$label_2->set_size_request(80,-1);
$label_3 = new GtkLabel("Bairro * ");
$label_3->set_size_request(80,-1);
$label_3->set_alignment(1, 0.5);
$label_4 = new GtkLabel("Cidade * ");
$label_4->set_size_request(80,-1);
$label_4->set_alignment(1, 0.5);
$label_5 = new GtkLabel("Tel ");
$label_5->set_size_request(80,-1);
$label_5->set_alignment(1, 0.5);
$label_6 = new GtkLabel("Email ");
$label_6->set_size_request(80,-1);
$label_6->set_alignment(1, 0.5);

// Cria caixas de entrada
$this->entrada_1 = new GtkEntry();
$this->entrada_2 = new GtkEntry();
$this->entrada_3 = new GtkEntry();
$this->entrada_4 = new GtkEntry();
$this->entrada_5 = new GtkEntry();
$this->entrada_6 = new GtkEntry();

//Empacota formulário - Nome
$hbox_1 = new GtkHbox();
$hbox_1->pack_start($label_1, false, false);
$hbox_1->pack_start($this->entrada_1, false, false);
$hbox_1->pack_start(new GtkLabel(""), true, true);

//Empacota formulário - Endereço
$hbox_2 = new GtkHbox();
$hbox_2->pack_start($label_2, false, false);
$hbox_2->pack_start($this->entrada_2, false, false);
$hbox_2->pack_start(new GtkLabel(""), true, true);

//Empacota formulário - Bairro
$hbox_3 = new GtkHbox();
$hbox_3->pack_start($label_3, false, false);
$hbox_3->pack_start($this->entrada_3, false, false);
$hbox_3->pack_start(new GtkLabel(""), true, true);

//Empacota formulário - Cidade
$hbox_4 = new GtkHbox();
$hbox_4->pack_start($label_4, false, false);
$hbox_4->pack_start($this->entrada_4, false, false);
$hbox_4->pack_start(new GtkLabel(""), true, true);

//Empacota formulário - Tel
$hbox_5 = new GtkHbox();
$hbox_5->pack_start($label_5, false, false);
$hbox_5->pack_start($this->entrada_5, false, false);
$hbox_5->pack_start(new GtkLabel(""), true, true);

//Empacota formulário - Email
$hbox_6 = new GtkHbox();
$hbox_6->pack_start($label_6, false, false);
$hbox_6->pack_start($this->entrada_6, false, false);
$hbox_6->pack_start(new GtkLabel(""), true, true);

//Define botão
$this->botao = new GtkButton("Finalizar Registro");
// Conecta botão à função finaliza registro
$this->botao->connect_simple("clicked",array($this,'onFinalizaRegistro'));

//Define caixa horizontal
$hbox_7 = new GtkHbox();
$hbox_7->pack_start(new GtkLabel(""), true, true);
$hbox_7->pack_start($this->botao, false, false);
$hbox_7->pack_start(new GtkLabel(""), true, true);

//Empacota layout
$vbox1->pack_start($hbox_1, false, false);
$vbox1->pack_start($hbox_2, false, false);
$vbox1->pack_start($hbox_3, false, false);
$vbox1->pack_start($hbox_4, false, false);
$vbox1->pack_start($hbox_5, false, false);
$vbox1->pack_start($hbox_6, false, false);
$vbox1->pack_start($hbox_7, false, false);

//Adiciona layout a janela
$this->janela->add($vbox1);
// Mostra janela e widgets
$this->janela->show_all();
// Conecta o X da janela a função de sair
$this->janela->connect_simple("destroy",array('Gtk','main_quit'));
}

// Função que verifica campos em branco
function onFinalizaRegistro() {
    
//Pega dados do formulario
$campos['NOME'] = $NOME = $this->entrada_1->get_text();
$campos['ENDERECO'] = $ENDER = $this->entrada_2->get_text();
$campos['BAIRRO'] = $BAIRRO = $this->entrada_3->get_text();
$campos['CIDADE'] = $MUNICIPIO = $this->entrada_4->get_text();
$TEL = $this->entrada_5->get_text();
$EMAIL = $this->entrada_6->get_text();

// Verifica campos em branco
if(sizeof($campos) > 0){
$em_branco = array();
foreach($campos as $valida => $valor){
if(!$valor){
$em_branco[] = $valida;
}}

// Verifica tamanho do array
$tam = sizeof($em_branco);

// Converte array em string
$ad = implode("
",$em_branco);
}

// Cria array de substitui os valores em branco por nomes em extenso
$anterior = array("NOME","ENDERECO","BAIRRO","CIDADE");
$nova = array("Nome ","Endereço","Bairro","Cidade");

// Substitui nomes da string
$aviso = str_replace($anterior, $nova , $ad);

if($tam >1){
//Exibe popup informando sobre campos nulos
$dialog = new GtkMessageDialog(null, Gtk::DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK);
$dialog->set_position(Gtk::WIN_POS_CENTER_ALWAYS);
$dialog->set_border_width(10);
$dialog->set_modal(true);
$dialog->set_transient_for($wnd);
$dialog->set_markup('<span foreground="black">Os seguintes campos<b><i> são obrigatórios</i></b></span><span foreground="black"> e não devem ser deixados em branco: </span>'. "

" . '<b>' . $aviso . '</b>' . "

" . '<span foreground="black">Preencha estes campos antes de salvar o registro atual.</span>');
$dialog->modify_font(new PangoFontDescription('Arial 10'));
$dialog->run();
$dialog->destroy();

}else{
if($tam == 1){
//Exibe popup informando sobre campos nulos
$dialog = new GtkMessageDialog(null, Gtk::DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK);
$dialog->set_position(Gtk::WIN_POS_CENTER_ALWAYS);
$dialog->set_border_width(10);
$dialog->set_modal(true);
$dialog->set_transient_for($wnd);
$dialog->set_markup('<span foreground="black">O seguinte campo<b><i> é obrigatório</i></b></span><span foreground="black"> e não deve ser deixado em branco: </span>'. "

" . '<b>' . $aviso . '</b>' . "

" . '<span foreground="black">Preencha estes campos antes de salvar o registro atual.</span>');
$dialog->modify_font(new PangoFontDescription('Arial 10'));
$dialog->run();
$dialog->destroy();

}else{
//Exibe popup informando sobre campos nulos
$dialog = new GtkMessageDialog(null, Gtk::DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK);
$dialog->set_position(Gtk::WIN_POS_CENTER_ALWAYS);
$dialog->set_border_width(10);
$dialog->set_modal(true);
$dialog->set_transient_for($wnd);
$dialog->set_markup('<span foreground="black">Todos os dados foram preenchidos corretamente.</span>');
$dialog->modify_font(new PangoFontDescription('Arial 10'));
$dialog->run();
$dialog->destroy();
}}}
// fecha a função onFinalizaRegistro

} <?

class ExemploFormularioValidacao
{
    private $janela;
    private $entrada_1;
    private $entrada_2;
    private $entrada_3;
    private $entrada_4;
    private $entrada_5;
    private $entrada_6;
    private $botao;

public function __construct(){

// Cria a janela
$this->janela= new GtkWindow();
// Define título da janela
$this->janela->set_title('Validação de Formulário');
// Define tamanho da janela
$this->janela->set_size_request(300,250);
//Define espaçamento de borda
$this->janela->set_border_width(10);

// Cria uma caixa vertical
$vbox1 = new GtkVbox();

// Cria rótulos do formulário
$label_1 = new GtkLabel("Nome * ");
$label_1->set_size_request(80,-1);
$label_1->set_alignment(1, 0.5);
$label_2 = new GtkLabel("Endereço * ");
$label_2->set_alignment(1, 0.5);
$label_2->set_size_request(80,-1);
$label_3 = new GtkLabel("Bairro * ");
$label_3->set_size_request(80,-1);
$label_3->set_alignment(1, 0.5);
$label_4 = new GtkLabel("Cidade * ");
$label_4->set_size_request(80,-1);
$label_4->set_alignment(1, 0.5);
$label_5 = new GtkLabel("Tel ");
$label_5->set_size_request(80,-1);
$label_5->set_alignment(1, 0.5);
$label_6 = new GtkLabel("Email ");
$label_6->set_size_request(80,-1);
$label_6->set_alignment(1, 0.5);

// Cria caixas de entrada
$this->entrada_1 = new GtkEntry();
$this->entrada_2 = new GtkEntry();
$this->entrada_3 = new GtkEntry();
$this->entrada_4 = new GtkEntry();
$this->entrada_5 = new GtkEntry();
$this->entrada_6 = new GtkEntry();

//Empacota formulário - Nome
$hbox_1 = new GtkHbox();
$hbox_1->pack_start($label_1, false, false);
$hbox_1->pack_start($this->entrada_1, false, false);
$hbox_1->pack_start(new GtkLabel(""), true, true);

//Empacota formulário - Endereço
$hbox_2 = new GtkHbox();
$hbox_2->pack_start($label_2, false, false);
$hbox_2->pack_start($this->entrada_2, false, false);
$hbox_2->pack_start(new GtkLabel(""), true, true);

//Empacota formulário - Bairro
$hbox_3 = new GtkHbox();
$hbox_3->pack_start($label_3, false, false);
$hbox_3->pack_start($this->entrada_3, false, false);
$hbox_3->pack_start(new GtkLabel(""), true, true);

//Empacota formulário - Cidade
$hbox_4 = new GtkHbox();
$hbox_4->pack_start($label_4, false, false);
$hbox_4->pack_start($this->entrada_4, false, false);
$hbox_4->pack_start(new GtkLabel(""), true, true);

//Empacota formulário - Tel
$hbox_5 = new GtkHbox();
$hbox_5->pack_start($label_5, false, false);
$hbox_5->pack_start($this->entrada_5, false, false);
$hbox_5->pack_start(new GtkLabel(""), true, true);

//Empacota formulário - Email
$hbox_6 = new GtkHbox();
$hbox_6->pack_start($label_6, false, false);
$hbox_6->pack_start($this->entrada_6, false, false);
$hbox_6->pack_start(new GtkLabel(""), true, true);

//Define botão
$this->botao = new GtkButton("Finalizar Registro");
// Conecta botão à função finaliza registro
$this->botao->connect_simple("clicked",array($this,'onFinalizaRegistro'));

//Define caixa horizontal
$hbox_7 = new GtkHbox();
$hbox_7->pack_start(new GtkLabel(""), true, true);
$hbox_7->pack_start($this->botao, false, false);
$hbox_7->pack_start(new GtkLabel(""), true, true);

//Empacota layout
$vbox1->pack_start($hbox_1, false, false);
$vbox1->pack_start($hbox_2, false, false);
$vbox1->pack_start($hbox_3, false, false);
$vbox1->pack_start($hbox_4, false, false);
$vbox1->pack_start($hbox_5, false, false);
$vbox1->pack_start($hbox_6, false, false);
$vbox1->pack_start($hbox_7, false, false);

//Adiciona layout a janela
$this->janela->add($vbox1);
// Mostra janela e widgets
$this->janela->show_all();
// Conecta o X da janela a função de sair
$this->janela->connect_simple("destroy",array('Gtk','main_quit'));
}

// Função que verifica campos em branco
function onFinalizaRegistro() {
    
//Pega dados do formulario
$campos['NOME'] = $NOME = $this->entrada_1->get_text();
$campos['ENDERECO'] = $ENDER = $this->entrada_2->get_text();
$campos['BAIRRO'] = $BAIRRO = $this->entrada_3->get_text();
$campos['CIDADE'] = $MUNICIPIO = $this->entrada_4->get_text();
$TEL = $this->entrada_5->get_text();
$EMAIL = $this->entrada_6->get_text();

// Verifica campos em branco
if(sizeof($campos) > 0){
$em_branco = array();
foreach($campos as $valida => $valor){
if(!$valor){
$em_branco[] = $valida;
}}

// Verifica tamanho do array
$tam = sizeof($em_branco);

// Converte array em string
$ad = implode("
",$em_branco);
}

// Cria array de substitui os valores em branco por nomes em extenso
$anterior = array("NOME","ENDERECO","BAIRRO","CIDADE");
$nova = array("Nome ","Endereço","Bairro","Cidade");

// Substitui nomes da string
$aviso = str_replace($anterior, $nova , $ad);

if($tam >1){
//Exibe popup informando sobre campos nulos
$dialog = new GtkMessageDialog(null, Gtk::DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK);
$dialog->set_position(Gtk::WIN_POS_CENTER_ALWAYS);
$dialog->set_border_width(10);
$dialog->set_modal(true);
$dialog->set_transient_for($wnd);
$dialog->set_markup('<span foreground="black">Os seguintes campos<b><i> são obrigatórios</i></b></span><span foreground="black"> e não devem ser deixados em branco: </span>'. "

" . '<b>' . $aviso . '</b>' . "

" . '<span foreground="black">Preencha estes campos antes de salvar o registro atual.</span>');
$dialog->modify_font(new PangoFontDescription('Arial 10'));
$dialog->run();
$dialog->destroy();

}else{
if($tam == 1){
//Exibe popup informando sobre campos nulos
$dialog = new GtkMessageDialog(null, Gtk::DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK);
$dialog->set_position(Gtk::WIN_POS_CENTER_ALWAYS);
$dialog->set_border_width(10);
$dialog->set_modal(true);
$dialog->set_transient_for($wnd);
$dialog->set_markup('<span foreground="black">O seguinte campo<b><i> é obrigatório</i></b></span><span foreground="black"> e não deve ser deixado em branco: </span>'. "

" . '<b>' . $aviso . '</b>' . "

" . '<span foreground="black">Preencha estes campos antes de salvar o registro atual.</span>');
$dialog->modify_font(new PangoFontDescription('Arial 10'));
$dialog->run();
$dialog->destroy();

}else{
//Exibe popup informando sobre campos nulos
$dialog = new GtkMessageDialog(null, Gtk::DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK);
$dialog->set_position(Gtk::WIN_POS_CENTER_ALWAYS);
$dialog->set_border_width(10);
$dialog->set_modal(true);
$dialog->set_transient_for($wnd);
$dialog->set_markup('<span foreground="black">Todos os dados foram preenchidos corretamente.</span>');
$dialog->modify_font(new PangoFontDescription('Arial 10'));
$dialog->run();
$dialog->destroy();
}}}
// fecha a função onFinalizaRegistro

} 
?>

Alissong

Compartilhar este post


Link para o post
Compartilhar em outros sites

Opa

 

 

cara, dei uma olhada por cima, e o que acontece....

 

 

Primeiro, qual o sistema q você usa?

 

 

Nesse programa, naum tem só esse erro, tem vários erros de declaração de classes, e como to no trampo agora, nem dah pra fazer esse programa rodar certo.

 

 

Se você quer ver alguns exemplos funcionais tanto pra windows e linux, entra nesse site, que tem exemplos comentados (em ingles)

 

www.kksou.com

Compartilhar este post


Link para o post
Compartilhar em outros sites

Bem

 

 

Segue um exemplo, de php-gtk2 em funcionamento, com a interface criada na "unha"..... Normalmente uso Glade, -- menos demorado ---

 

<?php

class ExemploTreeSimples
{	
private $window;
private $tree;
private $model;

// metodo construtor, cria a janela principal
public function __construct()
{
	// cria a janela principal
	$this->window = new GtkWindow;
	$this->window->set_title('Arvores');
	//$this->window->connect_simple('destroy', array('gtk', 'main-quit'));
	$this->window->set_default_size(320, 280);
	$this->window->set_position(GTK::WIN_POS_CENTER);

	// cria janela de rolagem
	$scroll = new GtkScrolledWindow;
	$scroll->set_policy(GTK::POLICY_AUTOMATIC, GTK::POLICY_ALWAYS);

	// cria arvore e adiciona no scroll
	$this->tree = new GtkTreeView;
	$scroll->add($this->tree);

	// define a ação para o duplo clique
	$this->tree->connect('row-activated', array($this, 'onDoubleClick'));

	// cria modelo de dados e atribui à arvore
	$this->model = new GtkTreeStore(Gtk::TYPE_OBJECT, Gtk::TYPE_STRING, Gtk::TYPE_STRING);
	$this->tree->set_model($this->model);

	// cria uma coluna e define o titulo
	$column1 = new GtkTreeViewColumn();
	$column1->set_title('Pasta');

	// cria 1 renderizador para Pixbuf e 1 para o texto
	$cell_renderer1 = new GtkCellRendererPixbuf();
	$cell_renderer2 = new GtkCellRendererText();

	// empacota os 2 renderizadores na mesma coluna
	$column1->pack_start($cell_renderer1, false);
	$column1->pack_start($cell_renderer2, false);

	// define qual renderizador corresponde a qual coluna do modelo
	$column1->set_attributes($cell_renderer1, 'pixbuf', 0);
	$column1->set_attributes($cell_renderer2, 'text', 1);

	// adiciona a coluna na arvore
	$this->tree->append_column($column1);

	// le algumas imagens do disco
	$folder = GdkPixbuf::new_from_file('icons/folder.png');
	$ico_mp3 = GdkPixbuf::new_from_file('icons/mp3.png');
	$ico_doc = GdkPixbuf::new_from_file('icons/doc.png');
	$ico_png = GdkPixbuf::new_from_file('icons/picture.png');
	$ico_zip = GdkPixbuf::new_from_file('icons/backup.png');

	// adiciona iteradores no modelo
	$iter1 = $this->model->append();
	$this->model->set($iter1, 0, $folder);
	$this->model->set($iter1, 1, 'Home');

	$iter1a = $this->model->append($iter1);
	$this->model->set($iter1a, 0, $ico_mp3);
	$this->model->set($iter1a, 1, 'Musicas');
	$this->model->set($iter1a, 2, '/home/songs');

	$iter1b = $this->model->append($iter1);
	$this->model->set($iter1b, 0, $ico_png);
	$this->model->set($iter1b, 1, 'Imagens');
	$this->model->set($iter1b, 2, '/home/images');

	// adiciona iteradores no modelo
	$iter2 = $this->model->append();
	$this->model->set($iter2, 0, $folder);
	$this->model->set($iter2, 1, 'Trabalho');

	$iter2a = $this->model->append($iter2);
	$this->model->set($iter2a, 0, $ico_doc);
	$this->model->set($iter2a, 1, 'Documentos');
	$this->model->set($iter2a, 2, '/work/docs');

	$iter2b = $this->model->append($iter2);
	$this->model->set($iter2b, 0, $ico_zip);
	$this->model->set($iter2b, 1, 'Backups');
	$this->model->set($iter2b, 2, '/work/backups');

	// expande a arvore e exibe a janela
	$this->tree->expand_all();
	$this->window->add($scroll);
	$this->window->show_all();
}

// metodo onDoubleClick, executado ao duplo clique
function onDoubleClick()
{
	// obtem a seleção 
	$selection = $this->tree->get_selection();

	// recupera o modelo do iterador
	list($model, $iter) = $selection->get_selected();

	// se ha dados selecionados
	if($iter)
	{
		// obtem dados da terceira coluna do modelo
		$caminho = $this->model->get_value($iter, 2);

		// cria o dialogo
		$dialog = new GtkMessageDialog(null, Gtk::DIALOG_MODAL, Gtk::MESSAGE_INFO, Gtk::BUTTONS_OK, $caminho);
		$dialog->run();
		$dialog->destroy();
	}
}
}

new ExemploTreeSimples;
Gtk::main();

?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.