Sample Code 349: How to allow reordering of thumbnail images in GtkIconView - Part 1? |
|
Written by kksou
|
|
Wednesday, 24 October 2007 |
|
Problem You have displayed a list of thumbnail images using GtkIconView in How to display a list of thumbnail images using GtkIconView?
Suppose you would like to allow users to reorder the thumbnail images using drag and drop as shown below:

Solution
- To enable reordering of tabs, use the method GtkIconView::set_reorderable (true);
Important Note: This only works for PHP-GTK2 compliled with gtk+ v2.10 and above. If you are using an older version, for linux, you may follow the step-by-step instructions to recompile php-gtk2 with gtk+ v2.10. For windows, please refer to How to install php gtk2 on windows? You may also want to take a look here to see some of the new exciting PHP-GTK2 Functionalities.
Sample Code Note: The following image files are required by the sample code below. Please save a copy of the image files and put them in the same directory where you store the sample code.
 | square_red.jpg |
 | square_yellow.jpg |
 | square_green.jpg |
 | square_blue.jpg |
 | square_blue2.jpg |
 | square_blue3.jpg |
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 33 34 35 36 37 38 39 40 41 42 43 44 45
| <?php $window = new GtkWindow(); $window->set_title($argv[0]); $window->set_size_request(400, 240); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox());
// display title
$title = new GtkLabel("Reordering thumbnail images in GtkIconView - Part 1"); $title->modify_font(new PangoFontDescription("Times New Roman Italic 10")); $title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff")); $title->set_size_request(-1, 40); $vbox->pack_start($title, 0, 0); $vbox->pack_start(new GtkLabel(), 0, 0); // add a small gap
// Set up a scroll window
$scrolled_win = new GtkScrolledWindow(); $scrolled_win->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
if (defined("GObject::TYPE_STRING")) { $model = new GtkListStore(GdkPixbuf::gtype, GObject::TYPE_STRING); } else { $model = new GtkListStore(GdkPixbuf::gtype, Gtk::TYPE_STRING); } foreach(array('square_red.jpg', 'square_yellow.jpg', 'square_green.jpg', 'square_blue.jpg', 'square_blue2.jpg', 'square_blue3.jpg') as $img) { $pixbuf = GdkPixbuf::new_from_file($img); $model->append(array($pixbuf, $img)); }
$view = new GtkIconView($model); $view->set_pixbuf_column(0); // col 0 of the model
$view->set_text_column(1); // col 1 of the model
$view->set_selection_mode(Gtk::SELECTION_MULTIPLE); $view->set_columns(0); $view->set_item_width(120);
$view->set_reorderable(true); // note 1
$scrolled_win->add($view); $vbox->pack_start($scrolled_win); $window->show_all(); Gtk::main(); ?>
|
Explanation We make use of the code from How to display a list of thumbnail images using GtkIconView?
What's new here:
- Allow reordering of the thumbnails using drag and drop.
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. |