|
Problem This is in response to Mote's post titled "2 questions about GtkImage".
He has set up an application that allows drag-and-drop of 12 different images. And he would like to be able to retrieve the URI (or filenames) of these 12 images at some later time for processing.
In Part 1, you can only drag and drop one image at a time.
In this Part 2, you can now drag and drop multiple files at one go as shown below:

Solution
- The technique used is exactly the same as that in Part 1.
- The only difference is that we now process all the dropped files in one go.
Sample Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| <?php $app = new App; $app->go();
class App {
var $num_rows = 4; var $num_cols = 3; var $img_width = 100; var $img_height = 100; var $img = array(); var $img_filename = array();
public function __construct() {
$window = new GtkWindow(); $window->set_size_request(400, 400); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox());
// display title
$title = new GtkLabel(" Drag and drog your images\n". " into any of the 12 image positions\n". "Part 2 - drag and drop multiple imags"); $title->modify_font(new PangoFontDescription("Times New Roman Italic 10")); $title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff")); $title->set_size_request(-1, 60); $vbox->pack_start($title, 0); $vbox->pack_start(new GtkLabel(), 0);
// add a process button
$hbox = new GtkHBox(); $vbox->pack_start($hbox, 0); $process_button = new GtkButton('Process Images'); $process_button->connect('clicked', array(&$this, 'on_process_button')); $hbox->pack_start($process_button, 0);
// init the filenames
for($i=0; $i<$this->num_rows*$this->num_cols; ++$i) { $this->img_filename[$i] = ''; }
// set up the images
$scrolled_win = new GtkScrolledWindow(); $scrolled_win->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); $vbox->pack_start($scrolled_win); $img_vbox = new GtkVBox(); $scrolled_win->add_with_viewport($img_vbox);
for ($row=0; $row<$this->num_rows; ++$row) { $hbox = new GtkHBox(); $img_vbox->pack_start($hbox, 0); for ($col=0; $col<$this->num_cols; ++$col) { $k = $row*$this->num_cols + $col; $img = new GtkImage(); $img->set_size_request($this->img_width, $this->img_height); $img->drag_dest_set(Gtk::DEST_DEFAULT_ALL, array( array( 'text/uri-list', 0, 0)), Gdk::ACTION_COPY); $img->connect('drag-data-received', array(&$this, 'on_drop'), $k); $this->img[$k] = $img; $frame = new GtkFrame(); $frame->add($img); $hbox->pack_start($frame, 0); $this->add_margin($hbox, 10); } }
$window->show_all(); }
public function go() { Gtk::main();
|
- Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
- Registration is free and immediate.
- Have some doubt about the registration? Please read this forum article.
Explanation We make use of the code from Part 1.
What's new here:
- Process all dropped images.
- Increment the $id so that the next image will be displayed in the next image position.
Related Links
User reviews There are no user reviews yet. Note: You have to be a registered member to leave a comment. Free registration here. |