gnope php gtk gui gnope.org  

Sample for Start of Applications with Menu Bar

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



Joined: 10 Apr 2006
Posts: 15
Location: Minnesota, USA

PostPosted: Sun Apr 23, 2006 10:11 am    Post subject: Sample for Start of Applications with Menu Bar Reply with quote

This is a test bed applicaiton. Been trying to put the pieces of this together for a bit. It has a Menu Bar, About Box, and a Text Buffer window with Scrolling capability. Hope this helps out the next user.

Code:
<?php
function about_box()
   {
   $dlg = new GtkAboutDialog();
   $dlg->set_name('My first Menu Driven Application');
   $dlg->set_version('0.0.1');
   $dlg->set_comments('Test bed' . "\nMenu Driven");
   $dlg->set_copyright('None');
   $dlg->set_license("Use at your own risk.\n"
    . "I hope it works for you.");//Button
   $dlg->set_logo(
  $dlg->render_icon(Gtk::STOCK_ABOUT, Gtk::ICON_SIZE_LARGE_TOOLBAR)
);
   //$dlg->set_website('http://website.example.org');
//   $dlg->set_translator_credits("German version - My Friend\n"
    //. "French version - Another Friend");
    $dlg->run();
   }
function quit_menu()
   {
   Gtk::main_quit();
   }

$wnd = new GtkWindow();
$wnd->set_default_size(400, 400);
$wnd->set_position(GTK::WIN_POS_CENTER);
$table = new GtkTable(2, 1, false);
$wnd->add($table);

$menu_frame = &new GtkFrame();

$menu_box = &new GtkHBox();
$menu_frame ->add($menu_box);


//Create a simple menu bar
$menubar = new GtkMenuBar();
$menu_box->pack_start($menubar,false,false);

$table->attach($menu_frame, 0, 1, 0, 1,Gtk::FILL,Gtk::SHRINK,Gtk::FILL,Gtk::SHRINK );

$scrwnd = new GtkScrolledWindow();
$scrwnd->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
$scrwnd->set_size_request(570,350);
$table->attach($scrwnd, 0, 1, 1, 2);
$textBuffer = new GtkTextBuffer();
$textView   = new GtkTextView();
$textView->set_buffer($textBuffer);
// make window not editable
$textView->set_editable(false);
$textBuffer->set_text("Hello World1!\r\n");
$i=2;
while ($i<30) {
   $textBuffer->insert_at_cursor("Hello World".$i."!\r\n");
   $i++;
   }
$scrwnd->add($textView);


$j=0;
while ($j<100) {
   $textBuffer->insert_at_cursor($j % 10);
   $j++;
   }
 
//Add File menu item with a dropdown menu
$file = new GtkMenuItem('_File');
$menubar->append($file);
 
//Quit item
$quit = new GtkMenuItem('_Quit');

//This menu will popup when the File menu is activated
$mnuFile = new GtkMenu();
//Add the Quit item to the File popup menu
$mnuFile->append($quit);
 
//Set the popupmenu of the File menu item
$file->set_submenu($mnuFile);

//Add Help menu item with a dropdown menu
$help = new GtkMenuItem('_Help');

$menubar->append($help);

$mnuHelp = new GtkMenu();

//About item
$about = new GtkMenuItem('_About');
$mnuHelp->append($about);

//Set the popupmenu of the Help menu item
$help->set_submenu($mnuHelp);
 
 
$wnd->connect_simple('destroy', array('Gtk', 'main_quit'));
$quit->connect_simple('activate', 'quit_menu', $wnd);
$about->connect_simple('activate', 'about_box', $wnd);

$wnd->show_all();
Gtk::main();
?>
Back to top
rgljr



Joined: 10 Apr 2006
Posts: 15
Location: Minnesota, USA

PostPosted: Mon Apr 24, 2006 6:56 am    Post subject: Reply with quote

Here is a Function Image Viewer Application.
Menus, About box, Scrolled Window with automatic scrollbars, and zoom in and zoom out capability.

I put this together using several examples that I found on the internet. some from the manual, some from posted messages and blogs.

Haven't figured it all out yet but it works.

Code:
<?php
function about_box()
   {
   $dlg = new GtkAboutDialog();
   $dlg->set_name('PHP-GTK2 ImageViewer');
   $dlg->set_version('0.0.1');
   $dlg->set_comments('View: JPegs,PNGs, BMPs, and Gifs');
   $dlg->set_copyright('None');
   $dlg->set_license("Use at your own risk.\n"
    . "I hope it works for you.");//Button
   $dlg->set_logo(
  $dlg->render_icon(Gtk::STOCK_ABOUT, Gtk::ICON_SIZE_LARGE_TOOLBAR)
);
    $dlg->run();
   }
function quit_menu()
   {
   Gtk::main_quit();
   }

function zoom($scale){
//same zoom on width and on height
    global $image,$original_pixbuf;
    $height = $original_pixbuf->get_height();
    $width = $original_pixbuf->get_width();
    $new_width = $width*$scale;
    $new_height = $height*$scale;
    $new_pixbuf =     
$original_pixbuf->scale_simple($new_width,$new_height,'GDK_INTERP_BILINEAR');
    $image->set_from_pixbuf($new_pixbuf);
}

function zoom_in(){
    global $zoom,$got_image;
    if ($got_image) {
       $zoom = $zoom * 2;
       zoom($zoom);
    }
}

function zoom_out(){
    global $zoom,$got_image;
    if ($got_image) {
       $zoom = $zoom / 2;
       zoom($zoom);
    }
}

function file_open(){
   global $image,$got_image,$original_pixbuf;
   $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");
   $filter->add_pattern("*.bmp");
   $fileDialog->add_filter($filter);
   $return=$fileDialog->run();
   $imagePath=$fileDialog->get_filename();
   $fileDialog->destroy();
    if($return=="-5"){
      $image->set_from_file("$imagePath");
      $got_image=TRUE;
      $original_pixbuf = $image->get_pixbuf();   
    }    
}
$wnd = new GtkWindow();
$wnd->set_default_size(400, 400);
$wnd->set_position(GTK::WIN_POS_CENTER);
$table = new GtkTable(2, 1, false);
$wnd->add($table);
$menu_frame = &new GtkFrame();
$menu_box = &new GtkHBox();
$menu_frame ->add($menu_box);
//Create a simple menu bar
$menubar = new GtkMenuBar();
$menu_box->pack_start($menubar,false,false);
$table->attach($menu_frame, 0, 1, 0, 1,Gtk::FILL,Gtk::SHRINK,Gtk::FILL,Gtk::SHRINK );
$scrwnd = new GtkScrolledWindow();
$scrwnd->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
$scrwnd->set_size_request(570,350);
$table->attach($scrwnd, 0, 1, 1, 2);

$image = GtkImage::new_from_stock (Gtk::STOCK_MISSING_IMAGE,Gtk::ICON_SIZE_DIALOG);
$got_image=FALSE;
$original_pixbuf = $image->get_pixbuf();
$scrwnd->add_with_viewport($image);
$zoom = 1;

//Add File menu item with a dropdown menu
$file = new GtkMenuItem('_File');
$menubar->append($file);
//This menu will popup when the File menu is activated
$mnuFile = new GtkMenu();
//Quit item
$openfile = new GtkMenuItem('_Open');
//Add the Quit item to the File popup menu
$mnuFile->append($openfile);
$quit = new GtkMenuItem('_Quit');
//Add the Quit item to the File popup menu
$mnuFile->append($quit);
//Set the popupmenu of the File menu item
$file->set_submenu($mnuFile);
//Add View menu item with a dropdown menu
$view = new GtkMenuItem('_View');
$menubar->append($view);
$mnuView = new GtkMenu();
//Zoom In item
$zoom_in_menu = new GtkMenuItem('Zoom _In');
$mnuView->append($zoom_in_menu);
//Zoom Out item
$zoom_out_menu = new GtkMenuItem('Zoom _Out');
$mnuView->append($zoom_out_menu);
//Set the popupmenu of the Help menu item
$view->set_submenu($mnuView);
//Add Help menu item with a dropdown menu
$help = new GtkMenuItem('_Help');
$menubar->append($help);
$mnuHelp = new GtkMenu();
//About item
$about = new GtkMenuItem('_About');
$mnuHelp->append($about);
//Set the popupmenu of the Help menu item
$help->set_submenu($mnuHelp);
$wnd->connect_simple('destroy', array('Gtk', 'main_quit'));
$openfile->connect_simple('activate', 'file_open', $wnd);
$quit->connect_simple('activate', 'quit_menu', $wnd);
$about->connect_simple('activate', 'about_box', $wnd);
$zoom_in_menu->connect_simple('activate', 'zoom_in', $wnd);
$zoom_out_menu->connect_simple('activate', 'zoom_out', $wnd);

$wnd->show_all();
Gtk::main();
?>


Why do I get a No Disk Error popup when the File Chooser Dialog Box open?

Also get the same error on any application from PHP-Gtk2 Application Runner but only the first time I run an App.

Run 1st App get error. Close App, Run 2nd App without closing Application Runner -- No error.

Close Application Runner, and Open it again. Run Application Get Error.

It takes two cancel for me to get past the No Disk Error message pop up.
Back to top
cweiske



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

PostPosted: Mon Apr 24, 2006 7:11 am    Post subject: Reply with quote

Working image browser (no zoom, though):
http://cvs.php.net/viewcvs.cgi/php-gtk/demos/imgbrowser.php?view=markup

Can you try to reduce your code until the error stops appearing? Then find out which line the error is caused by, and tell that. Which OS are you on? Do you have a special setup (harddisks)?

Btw, it helps to mark the code as code in bbcode (forum markup), making it more readable.
Back to top
rgljr



Joined: 10 Apr 2006
Posts: 15
Location: Minnesota, USA

PostPosted: Tue Apr 25, 2006 7:09 am    Post subject: Reply with quote

This code gives me the No Disk error. Seems to be something in my PC's configuration.

Windows XP. All Microsoft patches applied.

Uninstalled GNOPE, renamed C:\PHP-GTK2 directory, rebooted, and Installed GNOPE and still get the same error. Had XAMPP on this same machine as it is my development PC and Removed that. Still get No Disk Error.

AS for No Zoom.

After you load an image with the File open Dialog the zoom should work. I haven't figured out yet how to gray out the zoom in and zoom out menu choices until after an image is loaded

Plan to add a command line option as well.

Really posted the message to help others with getting started, but "Window-No Disk, There is no disk in the drive. Please insert a disk into the drive" dialog message is getting annoying. Would be nice to know which drive and how to set it to look for some other default drive.

Message comes up on my development machine, but not my other PC.

I will keep trying to figure out why development machine is unique. Any hints would be appreciated.

<?php

function file_open(){
global $image,$got_image,$original_pixbuf;
$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");
$filter->add_pattern("*.bmp");
$fileDialog->add_filter($filter);
$return=$fileDialog->run();
$imagePath=$fileDialog->get_filename();
$fileDialog->destroy();
if($return=="-5"){
$image->set_from_file("$imagePath");
$got_image=TRUE;
$original_pixbuf = $image->get_pixbuf();
}
}
file_open();
Gtk::main();
?>
Back to top
Thomas



Joined: 25 Dec 2005
Posts: 6

PostPosted: Thu May 04, 2006 8:13 pm    Post subject: Reply with quote

The Image Viewer crashes when I want to zoom in an animated gif
Quote:
Fatal error: Call to a member function get_height() on a non-object in C:\Webserver\wwwroot\extern\tmp\test.phpwd on line 24
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.