CodeSnippets.GtkFileSelectionDialog 6.4 KB

123456789101112131415
  1. version=pmwiki-1.0.5
  2. newline=²
  3. text=!!! FileSelectionDialog main methods :²* hide()²* show()²* get_selection() : return file section if OK pressed, return false if cancel button is pressed. (see usage below)²²!!! Quick overview (usage)²-> you ca see how it easy to get a file ; all you need to do is to create a FileSelectionDialog instance and call the get_selection() method.²²[[include:Main/CodeTable]]²<?php² $fs = new FileSelectionDialog('test');² $fs->run();²² $file = $fs->get_selection();² if($file === false)² echo "canceled\n";² else² echo "selected file $file\n";²?>²[[include:Main/CodeTableEnd]]²²!!! complete code²²[[include:Main/CodeTable]]²<?php²²error_reporting(E_ALL);²²#²# author Marc Quinton / september 2006.²#²# ------------- library class (need to be extended ----------------²define('FS_ACTIVATE', 0);²define('FS_CANCEL', 1);²²class FileSelectionDialog{²² private $fs; # file selection dialog widget² private $title;²² private $status;²²² public function __construct($title){² $this->title = $title;² $this->fs = new GtkFileSelection($title);² $this->status = null;²² $this->fs->ok_button->connect_simple( 'clicked' , array($this, 'activate'));² $this->fs->cancel_button->connect_simple( 'clicked' , array($this, 'cancel'));²² # need to catch double-click in list widget² }²² public function show(){² $this->fs->show();² }²² public function hide(){² $this->fs->hide();² }²² function activate(){² $this->status = FS_ACTIVATE;² $this->hide();² Gtk::main_quit();² }²² function cancel(){² $this->status = FS_CANCEL;² $this->hide();² Gtk::main_quit();² }²² public function run(){² $this->show();² gtk::main();² }²² public function get_selection(){² if($this->status == FS_ACTIVATE)² return $this->fs->get_filename();² else² return false;² }²}²²class MyFileSelectionDialog extends FileSelectionDialog{² function activate(){² parent::activate();² # do what you need here ...² echo "activate\n";² }²² function cancel(){² parent::cancel();² echo "cancel\n";² }²}²²# -------------------------------- test script ---------------------------------------------²function activate_fs_ok($fs){² echo "fs_ok\n";² $fs->hide();²}²²function activate_select(){²² # $fs = new MyFileSelectionDialog('test'); # to handle cancel and OK button ; not really needed² $fs = new FileSelectionDialog('test');² $fs->run();²² $file = $fs->get_selection();² if($file === false)² echo "canceled\n";² else² echo "selected file $file\n";²²}²²//standard stuff for window creation²$wnd = new GtkWindow();²$wnd->connect_simple('destroy', array('Gtk', 'main_quit'));²$wnd->set_position(Gtk::WIN_POS_CENTER);²$wnd->set_size_request(100, 100);²²²$btn = new GtkButton('select');²$btn->connect_simple('clicked', 'activate_select');²²²$wnd->add($btn);²²$wnd->show_all();²Gtk::main();²²²²?>²[[include:Main/CodeTableEnd]]²
  4. time=1158822006
  5. diff:1158762709:1158762709:=1,123c1²< !!! FileSelectionDialog example with methods :²< * hide()²< * show()²< * get_selection() : return file section if OK pressed, return false if cancel button is pressed. (see usage below)²< ²< ²< [[include:Main/CodeTable]]²< <?php²< ²< error_reporting(E_ALL);²< ²< #²< # author Marc Quinton / september 2006.²< #²< # ------------- library class (need to be extended ----------------²< define('FS_ACTIVATE', 0);²< define('FS_CANCEL', 1);²< ²< class FileSelectionDialog{²< ²< private $fs; # file selection dialog widget²< private $title;²< ²< private $status;²< ²< ²< public function __construct($title){²< $this->title = $title;²< $this->fs = new GtkFileSelection($title);²< $this->status = null;²< ²< $this->fs->ok_button->connect_simple( 'clicked' , array($this, 'activate'));²< $this->fs->cancel_button->connect_simple( 'clicked' , array($this, 'cancel'));²< ²< # need to catch double-click in list widget²< }²< ²< public function show(){²< $this->fs->show();²< }²< ²< public function hide(){²< $this->fs->hide();²< }²< ²< function activate(){²< $this->status = FS_ACTIVATE;²< $this->hide();²< Gtk::main_quit();²< }²< ²< function cancel(){²< $this->status = FS_CANCEL;²< $this->hide();²< Gtk::main_quit();²< }²< ²< public function run(){²< $this->show();²< gtk::main();²< }²< ²< public function get_selection(){²< if($this->status == FS_ACTIVATE)²< return $this->fs->get_filename();²< else²< return false;²< }²< }²< ²< class MyFileSelectionDialog extends FileSelectionDialog{²< function activate(){²< parent::activate();²< # do what you need here ...²< echo "activate\n";²< }²< ²< function cancel(){²< parent::cancel();²< echo "cancel\n";²< }²< }²< ²< # -------------------------------- test script ---------------------------------------------²< function activate_fs_ok($fs){²< echo "fs_ok\n";²< $fs->hide();²< }²< ²< function activate_select(){²< ²< # $fs = new MyFileSelectionDialog('test'); # to handle cancel and OK button ; not really needed²< $fs = new FileSelectionDialog('test');²< $fs->run();²< ²< $file = $fs->get_selection();²< if($file === false)²< echo "canceled\n";²< else²< echo "selected file $file\n";²< ²< }²< ²< //standard stuff for window creation²< $wnd = new GtkWindow();²< $wnd->connect_simple('destroy', array('Gtk', 'main_quit'));²< $wnd->set_position(Gtk::WIN_POS_CENTER);²< $wnd->set_size_request(100, 100);²< ²< ²< $btn = new GtkButton('select');²< $btn->connect_simple('clicked', 'activate_select');²< ²< ²< $wnd->add($btn);²< ²< $wnd->show_all();²< Gtk::main();²< ²< ²< ²< ?>²< [[include:Main/CodeTableEnd]]²---²> Describe GtkFileSelectionDialog here.²\ No newline at end of file²
  6. author=Marc Quinton
  7. author:1158762709=Marc Quinton
  8. host:1158762709=143.196.162.107
  9. name=CodeSnippets.GtkFileSelectionDialog
  10. host=82.234.62.122
  11. agent=Mozilla/5.0 (X11; U; Linux i686; fr-FR; rv:1.7.12) Gecko/20060216 Debian/1.7.12-1.1ubuntu2
  12. rev=2
  13. diff:1158822006:1158762709:=1c1²< !!! FileSelectionDialog main methods :²---²> !!! FileSelectionDialog example with methods :²6,22d5²< !!! Quick overview (usage)²< -> you ca see how it easy to get a file ; all you need to do is to create a FileSelectionDialog instance and call the get_selection() method.²< ²< [[include:Main/CodeTable]]²< <?php²< $fs = new FileSelectionDialog('test');²< $fs->run();²< ²< $file = $fs->get_selection();²< if($file === false)²< echo "canceled\n";²< else²< echo "selected file $file\n";²< ?>²< [[include:Main/CodeTableEnd]]²< ²< !!! complete code²
  14. author:1158822006=Marc Quinton
  15. host:1158822006=82.234.62.122