PHP-GTK2 Cookbook Forum
Welcome, Guest
Please Login or Register.    Lost Password?
2 questions about GtkImage kksou sample code (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: 2 questions about GtkImage kksou sample code
#462
motenai (User)
Fresh Boarder
Posts: 12
graphgraph
User Offline Click here to see the profile of this user
2 questions about GtkImage kksou sample code 2 Months, 2 Weeks ago Karma: 0  
Hi,

First : If it's possible, how can I extract the URI address ? Because I need to attribute it to Pears File_PDF subclass image() to print the image in my PDF file and at the same time I need to have the image preview in my PHP little soft like now.

I think in an easy solution; to write a special on_drop function to attribute URI address in a PHPGTK object like GtkLabel. Unfortunately, I have 12 images to transfer and it means to write 12 special on_drop functions (thanks to copypaste way ^_^; ) but it's not the best way at my sense. I'm hopping that PHPGTK have a method to extract the URI address from the GtkImage or in this case from the GdkPixBuf.

Second : How can I simply erase an image drag n dropped by error ? Because it's not possible to drag n drop out an image, we can only change it by an other drag n dropped image. I have an idea to write a delete function with the right click on the dropped image but why to do the work if it exist already a method ? ;)

Thanks

Mote
 
 
Last Edit: 2008/07/23 13:59 By motenai. Reason: just a change
  The administrator has disabled public write access.
#463
kksou (Admin)
Admin
Posts: 323
graph
User Online Now Click here to see the profile of this user
Re:2 questions about GtkImage kksou sample code 2 Months, 2 Weeks ago Karma: 8  
motenai wrote:

First : If it's possible, how can I extract the URI address ? Because I need to attribute it to Pears File_PDF subclass image() to print the image in my PDF file and at the same time I need to have the image preview in my PHP little soft like now.

I think in an easy solution; to write a special on_drop function to attribute URI address in a PHPGTK object like GtkLabel. Unfortunately, I have 12 images to transfer and it means to write 12 special on_drop functions (thanks to copypaste way ^_^; ) but it's not the best way at my sense. I'm hopping that PHPGTK have a method to extract the URI address from the GtkImage or in this case from the GdkPixBuf.


Hi Mote,

No, GtkImage does not store the URI of the image file anywhere.

By the way, is you're drop-and-drop image program similar to the following sample code:

Sample Code 98: How to create a simple drag and drop image viewer?

If it is, then if you have 12 similar drag-and-drop GtkImage's, you only need to have one callback function for the drag-and-drop. In the drag-and-drop function, you can store the URI of the image file in a simple array.

If you're a bit confused, I'll try to write a sample code for this tonight. Please check here again tomorrow.

Second : How can I simply erase an image drag n dropped by error ? Because it's not possible to drag n drop out an image, we can only change it by an other drag n dropped image. I have an idea to write a delete function with the right click on the dropped image but why to do the work if it exist already a method ?

There's no built-in method for this too.

You can use the method similar to the following sample code to popup a menu on right-click:
Sample Code 69: How to display context sensitive popup menu with right mouse click in GtkTreeView?

or

Sample Code 277: How to set up an application to run in the system tray using GtkStatusIcon - Part 4 - display popup menu on right click?

Then when the use selects "delete" from the popup menu, clear the image with $img->clear() where $img is your GtkImage.

Regards,
/kksou
 
 
Last Edit: 2008/07/23 15:19 By kksou.
  The administrator has disabled public write access.
#465
motenai (User)
Fresh Boarder
Posts: 12
graphgraph
User Offline Click here to see the profile of this user
Re:2 questions about GtkImage kksou sample code 2 Months, 2 Weeks ago Karma: 0  
Hi kksou,

Yes, I'm confused :) Fault of PHPGTK uncompleted manual, lol ^_^; Yeah, I was thinking to use your two sample to create a delete image right-click function

I'm starting to write a delete image right-click function and matters starts too :( When I right-click on the image, the event signal seems not to be emitted because the result doesn't printed on the prompt.

Code:
$window = new GtkWindow();
$box = new GtkVBox();
$img01 = new GtkImage();
$img01 -> drag_dest_set(Gtk::DEST_DEFAULT_ALL, 
array(array('text/uri-list',0,0)),
Gdk::ACTION_COPY);
$img01 -> connect('drag-data-received', 'dragNdrop', $img01);
$img01 -> connect('button-release-event', 'delDropImg', $img01);
$box->add($img01);

function dragNdrop($widget, $context, $x, $y, $data, $info, 
$time, $img) {
    $uri_list = explode("\n",$data->data);
    $img_file = $uri_list[0];
    $img_file2 = str_replace("file:///", "", $img_file);
    $img_file2 = str_replace("%20", " ", $img_file2);
    $img_file2 = str_replace("\r", "", $img_file2);
    $pixbuf = GdkPixbuf::new_from_file($img_file2);
    $width = (($pixbuf->get_width())/100)*20;
    $height = (($pixbuf->get_height())/100)*20;
    $newpixbuf = $pixbuf -> scale_simple($width, $height,
Gdk::INTERP_BILINEAR);
    $img -> set_from_pixbuf($newpixbuf);
}

function delDropImg($widget, $event, $img) {
    if ($event->button==3) {
        print 'it works'; /* while I click
on the right button */
        return true;
    }
}
No results now, I continue to work on it. Thanks kksou ! Mote
 
 
Last Edit: 2008/07/23 18:27 By motenai. Reason: pagination breaked 2
  The administrator has disabled public write access.
#466
kksou (Admin)
Admin
Posts: 323
graph
User Online Now Click here to see the profile of this user
Re:2 questions about GtkImage kksou sample code 2 Months, 2 Weeks ago Karma: 8  
Hi Mote,

Don't worry. Take a look at the two sample codes I'll give you tomorrow. I think it will make things clearer for you.

Sample code 1: to show drag and drop of 12 GtkImage's handled by one callback function (and storing their respective URIs)

Sample code 2: to clear image with right mouse click

Regards,
/kksou
 
  The administrator has disabled public write access.
#467
motenai (User)
Fresh Boarder
Posts: 12
graphgraph
User Offline Click here to see the profile of this user
Re:2 questions about GtkImage kksou sample code 2 Months, 2 Weeks ago Karma: 0  
Thanks kksou...

and shame on me ^_^; but i'll continue to try to do something by myself about the clear image... it's for my ego, lol ^_^;

thanks again and have nice dreams

Mote
 
  The administrator has disabled public write access.
#470
kksou (Admin)
Admin
Posts: 323
graph
User Online Now Click here to see the profile of this user
Re:2 questions about GtkImage kksou sample code 2 Months, 2 Weeks ago Karma: 8  
 
  The administrator has disabled public write access.
#472
motenai (User)
Fresh Boarder
Posts: 12
graphgraph
User Offline Click here to see the profile of this user
Re:2 questions about GtkImage kksou sample code 2 Months, 2 Weeks ago Karma: 0  
Hi kksou !!!

Thanks a lot about your samples ! I never think in GtkEventBox... and I don't know it :( Crap ! I have few things to learn before to can say "I know PHPGTK"

Your samples are very interesting but not easy to exploit in my case because the 12 images aren't in the same place/window. I rewrite it by my way and add an insert image to the right-click function.

Code:
<?php
////////////////////
if(!class_exists('GTK')) {
	if(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
		dl('php_gtk.dll');
	} else {
		dl('php_gtk.so');
	}
}
///////////////////
function killprocess() {
	Gtk :: main_quit();
}

///////////////////
$window = new GtkWindow(); 
$window -> connect('destroy', 'killprocess');
$window -> set_size_request(150,150);
///////////////////
$imgBox = new GtkVBox();
///////////////////
$img01 = new GtkImage();
$img01 -> set_from_file('');
$uriImg01 = new GtkLabel('');
$img01 -> drag_dest_set(Gtk::DEST_DEFAULT_ALL,
 array(array('text/uri-list',0,0)),Gdk::ACTION_COPY);
$img01 -> connect('drag-data-received', 'copypaste',
 $img01, $uriImg01);
$eventImg = new GtkEventBox();
$eventImg -> add($img01);
$eventImg -> connect('button-release-event', 'deleteImage',
 $img01, $uriImg01);
$imgBox->add($eventImg);
$window->add($imgBox);
//////////////////////
function copypaste($widget, $context, $x, $y, $data, $info,
 $time, $img, $uri) {
    $uri_list = explode("\n",$data->data);
    $img_file = $uri_list[0];
    $img_file2 = str_replace("file:///", "", $img_file);
	$img_file2 = str_replace("%20", " ", $img_file2);
    $img_file2 = str_replace("\r", "", $img_file2);
    $pixbuf = GdkPixbuf::new_from_file($img_file2);
    $width = (($pixbuf->get_width())/100)*20;
    $height = (($pixbuf->get_height())/100)*20;
	$newpixbuf = $pixbuf -> scale_simple($width, $height,
	 Gdk::INTERP_BILINEAR);
    $img -> set_from_pixbuf($newpixbuf);
	$uri -> set_label("$img_file2");
}
/////////////////////
function deleteImage($widget, $event, $img, $uri) {
    if ($event->button==3) {
		print $uri->get_label();
        popup_menu($img, $uri);
        return true;
    }
}
////////////////////
function popup_menu($img, $uri) {
	$menu_definition = array('Insert an image', '<hr>',
	'Delete image');
	$menu = new GtkMenu();
	foreach($menu_definition as $menuitem_definition) {
		if ($menuitem_definition=='<hr>') {
			$menu->append(new GtkSeparatorMenuItem());
		} else {
			$menu_item = new GtkMenuItem($menuitem_definition);
			$menu->append($menu_item);
			$menu_item->connect('activate', 'on_popup_menu_select',
			 $img, $uri);
		}
	}
	$menu->show_all();
	$menu->popup();
}
//////////////////////
function on_popup_menu_select($menu_item, $img, $uri) {
	$item = $menu_item->child->get_label();
	switch($item) {
		case 'Insert an image':
			selectNewImg($img, $uri);
			break;
		case 'Delete image':
			$img->set_from_file('');
			$uri->set_label('');
			break;
	}
}
///////////////////////
function selectNewImg($img, $uri) {
	$dialog = new GtkFileChooserDialog("File Open", null, 
		Gtk::FILE_CHOOSER_ACTION_OPEN, 
		array(Gtk::STOCK_OK, Gtk::RESPONSE_OK), null);
	
	$dialog->show_all();
	if ($dialog->run() == Gtk::RESPONSE_OK) {
		$selected_file = $dialog->get_filename();
		$newFile = str_replace("\\", "/", $selected_file);
		$pixbuf = GdkPixbuf::new_from_file($newFile);
    	$width = (($pixbuf->get_width())/100)*20;
    	$height = (($pixbuf->get_height())/100)*20;
		$newpixbuf = $pixbuf -> scale_simple($width, $height,
		Gdk::INTERP_BILINEAR);
    	$img -> set_from_pixbuf($newpixbuf);
		$uri -> set_label("$newFile");
	}
	$dialog->destroy();
}
////////////////////
$window->show_all();
////////////////////
Gtk :: main();
?>
Thanks again kksou ! Mote
 
 
Last Edit: 2008/07/25 10:58 By motenai. Reason: forget the regards :)
  The administrator has disabled public write access.
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop

Copyright © 2006-2008. kksou.com. All Rights Reserved