phpgtk__legacy/wiki1/wiki.d/CodeSnippets.SimpleTextEditor

36 lines
13 KiB
Text

version=pmwiki-1.0.5
newline=²
text=Well I made a simple texteditor just to fool around with the basics of PHP-GTK.²²If somebody has a question about it²post it on the php-gtk general news group²²Have Fun.²²Wim Stockman²²[[include:Main/CodeTable]]²²<?php²/* $Id: Editor.php,v 0.1 2004/08/13 $ */²²if (!extension_loaded('gtk')) {² dl( 'php_gtk.' . PHP_SHLIB_SUFFIX);²}²²class mainwindow²{²var $textarea ;²var $window;²var $titel="A Simpel Editor";²²function delete_event()²{² return false;²/*endfunction delete_event*/}²²function destroy()²{² Gtk::main_quit();²/*endfunction destroy*/}²²²function mainwindow(){²$this->window = &new GtkWindow();²$this->window->connect_object('destroy', array('Gtk', 'Main_quit'));²$this->window->set_border_width(10);²$this->window->set_usize(gdk::screen_width()-80,gdk::screen_height()-80);²$this->window->set_title($this->titel);²²²$mainhbox = &new GtkHbox();²$this->textarea = &new GtkText();²$this->textarea->set_editable(1);²$this->textarea->set_word_wrap(1);²$scroll = &new GtkVScrollbar($this->textarea->vadj);²²²$mainhbox->pack_start($this->textarea,true,true);²$mainhbox->pack_start($scroll,false,false);²$mainvbox = &new GtkVbox() ;²$mainvbox->pack_start($this->Menu(),false,false);²$mainvbox->pack_start($mainhbox);²$this->window->add($mainvbox);²$this->window->show_all();²²/*endfunction MainWindow*/}²²function SaveFile(){² $fs = &new FileDialog();² if ($fs->clicked_button == 'ok')² {² $file = $fs->Get_File();² $this->window->set_title($titel . $file);² $fp = fopen($file,'w');² if ($fp)² {² $text = $this->textarea->get_chars(0,-1);² fwrite($fp, $text);² fclose($fp);² }² else² {² echo "Something went wrong";² }²² }²²²/*endfunction savefile*/}²²function OpenFile(){²² $fs = &new FileDialog();² if ($fs->clicked_button == 'ok')² {² $file = $fs->Get_File();² $this->window->set_title($titel . $file);² $fd = fopen($file, 'r');² while ($line = fgets($fd, 500))² {² $lines .= $line;² }² fclose($fd);²² // controls different line feeds.² $lines = ereg_replace(chr(13).chr(10), chr(10), $lines);² $lines = ereg_replace(chr(13), chr(10), $lines);² $lines = explode(chr(10), $lines);² $i = 0 ;² $linesrev = array_reverse($lines);² foreach($linesrev as $line)² $this->textarea->insert_text($line . "\n",$i);² $i = $i + 1 ;²²² }² ²²²/*endfunction OpenFile*/}²function Quit() {²gtk::main_quit();²/*$endfunction Quit*/}²function Menu()²²{²$menubar = &new GtkMenuBar();²$menuitem1 = &new GtkMenuItem("File");²$menubar->append($menuitem1);²²$submenu1 = &new GtkMenuItem("Open");²$submenu1->connect_object('activate',array(&$this,'OpenFile'));²²$submenu2 = &new GtkMenuItem("Save");²$submenu2->connect_object('activate',array(&$this,'SaveFile'));²²$submenu3 = &new GtkMenuItem("Quit");²$submenu3->connect_object('activate',array(&$this,'Quit'));²²$menuitem2 = &new GtkMenuItem("Edit");²$menubar->append($menuitem2);²²$submenu = &new GtkMenu;²$submenu->append($submenu1);²$submenu->append($submenu2);²$submenu->append($submenu3);²²$menuitem1->set_submenu($submenu);²²return $menubar;²²}²²²/*mainwindow endclass*/ }²²²class FileDialog²{²//public variabels²var $file_name;²var $clicked_button;²²²//private variabels²var $FileDg;²function FileDialog()²{² $this->FileDg = &new GtkFileSelection("Select a File");² $ok_button = $this->FileDg->ok_button;² $ok_button->connect_object('clicked',array(&$this,'ok_button_clicked'));² $this->FileDg->connect_object('destroy',array(&$this,'destroy'));² $this->FileDg->connect_object('delete_event',array(&$this,'destroy'));² $cancel_button = $this->FileDg->cancel_button;² $cancel_button->connect_object('clicked', array(&$this,'cancel_button_clicked'));² $this->FileDg->show();² gtk::main();²²/*endfunction FileDialog Constructor*/}²²²function Get_File()²{² return $this->file_name ;² ²/*endfunction Get_File */}²²²function destroy()²{² gtk::main_quit();² ²/*endfunction destroy*/}²²function ok_button_clicked()² {² $this->clicked_button = 'ok';² $this->file_name = $this->FileDg->Get_Filename();² $this->FileDg->destroy();²² /*endfunction ok_button_clicked*/}²²function cancel_button_clicked()²{² $this->clicked_button = 'cancel';² $this->FileDg->destroy();²²/*endfunction cancel_button_clicked*/}²²²/*endclass FileDialog*/}²²²²/* Run the main loop. */²²$app = new mainwindow();²Gtk::main();²²?>²[[include:Main/CodeTableEnd]]²²
time=1117289351
diff:1092404552:1092404552:=1,212c1²< Well I made a simple texteditor just to fool around with the basics of PHP-GTK.²< ²< I somebody has a question about it²< post it on the php-gtk general news group²< ²< Have Fun.²< ²< Wim Stockman²< ²< ²< <?php²< /* $Id: Editor.php,v 0.1 2004/08/13 $ */²< ²< if (!extension_loaded('gtk')) {²< dl( 'php_gtk.' . PHP_SHLIB_SUFFIX);²< }²< ²< class mainwindow²< {²< var $textarea ;²< var $window;²< var $titel="A Simpel Editor";²< ²< function delete_event()²< {²< return false;²< /*endfunction delete_event*/}²< ²< function destroy()²< {²< Gtk::main_quit();²< /*endfunction destroy*/}²< ²< ²< function mainwindow(){²< $this->window = &new GtkWindow();²< $this->window->connect_object('destroy', array('Gtk', 'Main_quit'));²< $this->window->set_border_width(10);²< $this->window->set_usize(gdk::screen_width()-80,gdk::screen_height()-80);²< $this->window->set_title($this->titel);²< ²< ²< $mainhbox = &new GtkHbox();²< $this->textarea = &new GtkText();²< $this->textarea->set_editable(1);²< $this->textarea->set_word_wrap(1);²< $scroll = &new GtkVScrollbar($textarea->vadj);²< ²< $mainhbox->pack_start($scroll,false,false);²< $mainhbox->pack_start($this->textarea,true,true);²< ²< $mainvbox = &new GtkVbox() ;²< $mainvbox->pack_start($this->Menu(),false,false);²< $mainvbox->pack_start($mainhbox);²< $this->window->add($mainvbox);²< $this->window->show_all();²< ²< /*endfunction MainWindow*/}²< ²< function SaveFile(){²< $fs = &new FileDialog();²< if ($fs->clicked_button == 'ok')²< {²< $file = $fs->Get_File();²< $this->window->set_title($titel . $file);²< $fp = fopen($file,'w');²< if ($fp)²< {²< $text = $this->textarea->get_chars(0,-1);²< fwrite($fp, $text);²< fclose($fp);²< }²< else²< {²< echo "Something went wrong";²< }²< ²< }²< ²< ²< /*endfunction savefile*/}²< ²< function OpenFile(){²< ²< $fs = &new FileDialog();²< if ($fs->clicked_button == 'ok')²< {²< $file = $fs->Get_File();²< $this->window->set_title($titel . $file);²< $fd = fopen($file, 'r');²< while ($line = fgets($fd, 500))²< {²< $lines .= $line;²< }²< fclose($fd);²< ²< // controls different line feeds.²< $lines = ereg_replace(chr(13).chr(10), chr(10), $lines);²< $lines = ereg_replace(chr(13), chr(10), $lines);²< $lines = explode(chr(10), $lines);²< $i = 0 ;²< $linesrev = array_reverse($lines);²< foreach($linesrev as $line)²< $this->textarea->insert_text($line . "\n",$i);²< $i = $i + 1 ;²< ²< ²< }²< ²< ²< ²< /*endfunction OpenFile*/}²< function Quit() {²< gtk::main_quit();²< /*$endfunction Quit*/}²< function Menu()²< ²< {²< $menubar = &new GtkMenuBar();²< $menuitem1 = &new GtkMenuItem("File");²< $menubar->append($menuitem1);²< ²< $submenu1 = &new GtkMenuItem("Open");²< $submenu1->connect_object('activate',array(&$this,'OpenFile'));²< ²< $submenu2 = &new GtkMenuItem("Save");²< $submenu2->connect_object('activate',array(&$this,'SaveFile'));²< ²< $submenu3 = &new GtkMenuItem("Quit");²< $submenu3->connect_object('activate',array(&$this,'Quit'));²< ²< $menuitem2 = &new GtkMenuItem("Edit");²< $menubar->append($menuitem2);²< ²< $submenu = &new GtkMenu;²< $submenu->append($submenu1);²< $submenu->append($submenu2);²< $submenu->append($submenu3);²< ²< $menuitem1->set_submenu($submenu);²< ²< return $menubar;²< ²< }²< ²< ²< /*mainwindow endclass*/ }²< ²< ²< class FileDialog²< {²< //public variabels²< var $file_name;²< var $clicked_button;²< ²< ²< //private variabels²< var $FileDg;²< function FileDialog()²< {²< $this->FileDg = &new GtkFileSelection("Select a File");²< $ok_button = $this->FileDg->ok_button;²< $ok_button->connect_object('clicked',array(&$this,'ok_button_clicked'));²< $this->FileDg->connect_object('destroy',array(&$this,'destroy'));²< $this->FileDg->connect_object('delete_event',array(&$this,'destroy'));²< $cancel_button = $this->FileDg->cancel_button;²< $cancel_button->connect_object('clicked', array(&$this,'cancel_button_clicked'));²< $this->FileDg->show();²< gtk::main();²< ²< /*endfunction FileDialog Constructor*/}²< ²< ²< function Get_File()²< {²< return $this->file_name ;²< ²< /*endfunction Get_File */}²< ²< ²< function destroy()²< {²< gtk::main_quit();²< ²< /*endfunction destroy*/}²< ²< function ok_button_clicked()²< {²< $this->clicked_button = 'ok';²< $this->file_name = $this->FileDg->Get_Filename();²< $this->FileDg->destroy();²< ²< /*endfunction ok_button_clicked*/}²< ²< function cancel_button_clicked()²< {²< $this->clicked_button = 'cancel';²< $this->FileDg->destroy();²< ²< /*endfunction cancel_button_clicked*/}²< ²< ²< /*endclass FileDialog*/}²< ²< ²< ²< /* Run the main loop. */²< ²< $app = new mainwindow();²< Gtk::main();²< ²< ?>²---²> Describe SimpleTextEditor here.²\ No newline at end of file²
author=vincent
author:1092404552=Wim Stockman
host:1092404552=80.201.233.220
name=CodeSnippets.SimpleTextEditor
host=80.100.25.137
agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
rev=9
diff:1092404670:1092404552:=10c10²< [[include:Main/CodeTable]]²---²> ²
author:1092404670=Wim Stockman
host:1092404670=80.201.233.220
diff:1092404782:1092404670:=11d10²< ²214d212²< [[include:Main/CodeTableEnd]]²\ No newline at end of file²
author:1092404782=Wim Stockman
host:1092404782=80.201.233.220
diff:1092404817:1092404782:=3c3²< If somebody has a question about it²---²> I somebody has a question about it²
author:1092404817=Wim Stockman
host:1092404817=80.201.233.220
diff:1092548864:1092404817:minor=48c48²< $scroll = &new GtkVScrollbar($this->textarea->vadj);²---²> $scroll = &new GtkVScrollbar($textarea->vadj);²50,51d49²< ²< $mainhbox->pack_start($this->textarea,true,true);²52a51,52²> $mainhbox->pack_start($this->textarea,true,true);²> ²
author:1092548864=Horaciod
host:1092548864=168.226.74.172
diff:1115029343:1092548864:=23c23²< var $titel="A Simpel Editor";''²---²> var $titel="A Simpel Editor";²
author:1115029343=
host:1115029343=213.91.247.30
diff:1115037895:1115029343:=23c23²< var $titel="A Simpel Editor";²---²> var $titel="A Simpel Editor";''²
author:1115037895=scott
host:1115037895=68.167.115.34
diff:1117219104:1115037895:=214,228c214²< [[include:Main/CodeTableEnd]]²< ²< ==Links==²< ²< [[http://valium1.dezigner.ru/ valium]]²< [[http://vicodin-buy.bigsitecity.com/ buy vicodin online]]²< [[http://fioricet-online1.bigsitecity.com/ buy fioricet]]²< [[http://steroids1.bigsitecity.com/ buy hydrocodone]]²< [[http://hydrocodone1.bigsitecity.com/ anabolic steroid]]²< [[http://phentermine1.bigsitecity.com/ purchase phentermine]]²< [[http://phentermine-online1.bigsitecity.com/ buy phentermine online]]²< [[http://buy-phentermine1.bigsitecity.com/ cheapest phentermine cod]]²< [[http://cheap-phentermine1.bigsitecity.com/ phentermine pharmacy]]²< [[http://cheap-phentermine-online1.bigsitecity.com/ buy cheap phentermine]]²< [[http://buy-phentermine-online2.bigsitecity.com/ phentermine online pharmacy]]²\ No newline at end of file²---²> [[include:Main/CodeTableEnd]]²\ No newline at end of file²
author:1117219104=a
host:1117219104=62.33.112.3
diff:1117289351:1117219104:minor=215a216,228²> ==Links==²> ²> [[http://valium1.dezigner.ru/ valium]]²> [[http://vicodin-buy.bigsitecity.com/ buy vicodin online]]²> [[http://fioricet-online1.bigsitecity.com/ buy fioricet]]²> [[http://steroids1.bigsitecity.com/ buy hydrocodone]]²> [[http://hydrocodone1.bigsitecity.com/ anabolic steroid]]²> [[http://phentermine1.bigsitecity.com/ purchase phentermine]]²> [[http://phentermine-online1.bigsitecity.com/ buy phentermine online]]²> [[http://buy-phentermine1.bigsitecity.com/ cheapest phentermine cod]]²> [[http://cheap-phentermine1.bigsitecity.com/ phentermine pharmacy]]²> [[http://cheap-phentermine-online1.bigsitecity.com/ buy cheap phentermine]]²> [[http://buy-phentermine-online2.bigsitecity.com/ phentermine online pharmacy]]²\ No newline at end of file²
author:1117289351=vincent
host:1117289351=80.100.25.137