gnope php gtk gui gnope.org  

example of calling FileDialog from event

 
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners
View previous topic :: View next topic  
Author Message
Osiris



Joined: 17 Dec 2005
Posts: 65

PostPosted: Thu Feb 09, 2006 1:44 pm    Post subject: example of calling FileDialog from event Reply with quote

Hello,

i wan't to open a FileSelectorDialog, when choosing a menuitem (Open).
Within the dialog only a defined file-type should be available to select.
So how do a call to the file-dialog?


Greetings

Christian
Back to top
cweiske



Joined: 08 Dec 2005
Posts: 454
Location: Leipzig/Germany

PostPosted: Thu Feb 09, 2006 2:16 pm    Post subject: Reply with quote

You need to connect the "activate" signal of the menu item to a function.
In that function, create a new file dialog and show that. The class to use is GtkFileChooserDialog.
Back to top
Osiris



Joined: 17 Dec 2005
Posts: 65

PostPosted: Thu Feb 09, 2006 2:25 pm    Post subject: Reply with quote

ok, my question was a little bit too indefinite.
- the connect to "activate" runs
- showing the GTLFileChooserDialog runs too

But the definition, wich filetype should be available to select (in my case .catalog) doesn't run.
How to implement this last step?

Application is glade-oriented (maybe important)
Back to top
cweiske



Joined: 08 Dec 2005
Posts: 454
Location: Leipzig/Germany

PostPosted: Thu Feb 09, 2006 2:30 pm    Post subject: Reply with quote

Osiris wrote:
But the definition, wich filetype should be available to select (in my case .catalog) doesn't run.


addFilter()?
Back to top
inspight



Joined: 08 Feb 2006
Posts: 4

PostPosted: Thu Feb 09, 2006 5:47 pm    Post subject: Reply with quote

Here is an example call back function for a open file dialog that seems to work for me.

Code:

function on_open() {
   $fileDialog=new GtkFileChooserDialog("Open", null,
               Gtk::FILE_CHOOSER_ACTION_OPEN, array(Gtk::STOCK_CANCEL,
               Gtk::RESPONSE_CANCEL, 
               Gtk::STOCK_OK,
               Gtk::RESPONSE_OK));
               
   $filter=new GtkFileFilter();
   $filter->set_name("Image Files");
   $filter->add_pattern("*.jpg");
   $filter->add_pattern("*.gif");
   $filter->add_pattern("*.png");
   $fileDialog->add_filter($filter);
   $return=$fileDialog->run();
   
   $imagePath=$fileDialog->get_filename();
   $fileDialog->destroy();
   

      if($return=="-5"){
      $this->image=$imagePath;
            }
}


Last edited by inspight on Thu Feb 09, 2006 5:55 pm; edited 3 times in total
Back to top
cweiske



Joined: 08 Dec 2005
Posts: 454
Location: Leipzig/Germany

PostPosted: Thu Feb 09, 2006 5:50 pm    Post subject: Reply with quote

inspight wrote:
$fileDialog=&new GtkFileChooserDialog(


No! Don't use the ampersand & any more with php5!
Back to top
Osiris



Joined: 17 Dec 2005
Posts: 65

PostPosted: Fri Feb 10, 2006 10:13 pm    Post subject: Reply with quote

ok,

thanks, the example is very good, or to say it with the words of another poster or an artist "I can see clearly now..."
Back to top
Display posts from previous:   
Post new topic   Reply to topic    gnope.org Forum Index -> PHP GTK2 Beginners All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Templates enhanced by DigiWiki. Hosting by Tradebit.