PHP-GTK2 Cookbook Forum
Welcome, Guest
Please Login or Register.    Lost Password?
Re:My PHP-GTK2 questions (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Re:My PHP-GTK2 questions


#5311
cubii (User)
Fresh Boarder
Posts: 6
graphgraph
User Offline Click here to see the profile of this user
My PHP-GTK2 questions 11 Months, 2 Weeks ago Karma: 0  
Hello!

I'm having some problems with PHP-GTK for a project that I'm doing for work. I was wondering if you could help me with the following questions. To save forum clutter, I'll use this thread for my questions when possible.

1) I have been using this tutorial, which shows how to hide labels in a GTKIconView. Part of my jobs' project is to make a picture viewer so it says what it does on the tin.

The hidden text that I'm hiding via the set_text_column() function is actually the filename of the image that makes up the icon. How would one get the contents of that "string", so I can pass it to my apps image buffering function as a variable? For example, that tutorial has a square that is loaded from a file called "square_red.jpg". What is needed to get the string of "square_red.jpg" if the person clicks that image?

2. Is it possible to make a function that will jump up/down a row in a GTKTreeView (as seen in something like this example)? For example, one clicks a button and it jumps down a row? One clicks another button and jumps up a row?

Those are my questions for now. I await your answers.

Cheers,
Cubii.
 
  The administrator has disabled public write access.

#5313
kksou (Admin)
Admin
Posts: 1676
graph
User Online Now Click here to see the profile of this user
Re:My PHP-GTK2 questions 11 Months, 2 Weeks ago Karma: 27  
Hi Cubii,

1) The GtkIconView uses the same concept as the GtkTreeView - both has an underlying model. When you click on an icon, you will also get a pointer to the model. In the model, in the sample code, I use 2 columns only. The first column to store the image and the second to store the filename. If you need the filename, even though it's not displayed, you can still access it in column 1 of the model.

So first add the callback function that responds to user selection. The callback function will sends you a pointer to the selection. From the selection, you can get access to the $model and $iter. With these 2 variable, you can access column 1 of the model.

2) It can be done, but you have to code everything.

Please refer to the following sample code: Sample Code 347: How to scroll to newly inserted item in a linear list using GtkTreeView - Part 1 - using GtkTreeView scroll_to_cell?

a) Basically, you need a pointer to manually keep track of the current row number. Suppose this is $n.
b) When uesr presses the Up button, $n = $n - 1;
c) When user presses the Down button, $n = $n + 1;
d) Then use GtkTreeView::scroll_to_cell() to scroll to the $nth row

Hope this helps.

Regards,
/kksou
 
 
Last Edit: 2012/06/03 16:16 By kksou.
  The administrator has disabled public write access.

#5314
cubii (User)
Fresh Boarder
Posts: 6
graphgraph
User Offline Click here to see the profile of this user
Re:My PHP-GTK2 questions 11 Months, 2 Weeks ago Karma: 0  
Thanks a bunch, it's starting to lift the fog. However, what do you mean by "So first add the callback function that responds to user selection"? Do you mean something like $myVar->connect_simple('on_changed',doSomething()); ? If so, this is what I have:

Code:
(...)
$myVar->connect_simple('item-activated',myFunc($myVar->get_selected_items()));

function myFunc($what){
  print_r($what);
}
This works initially (it outputs Array( ) in the console) but when you click on a icon, it doesn't do anything. Could you post a little function skeleton that I could then expand? Thanks again for your assistance.
 
  The administrator has disabled public write access.
#5315
kksou (Admin)
Admin
Posts: 1676
graph
User Online Now Click here to see the profile of this user
Re:My PHP-GTK2 questions 11 Months, 2 Weeks ago Karma: 27  
Hi Cubii,

1) Please make sure you read the documentation on GtkIconView: http://gtk.php.net/manual/en/gtk.gtkiconview.php

2) Use the signal "selection-changed" and not 'item-activated'
http://gtk.php.net/manual/en/gtk.gtkiconview.signal.selection-changed.php

3) Then use the function GtkIconView::get_selected_items() to retrieve the selection
http://gtk.php.net/manual/en/gtk.gtkiconview.method.get_selected_items.php

This function will return an arrary of paths for the selected items. From the path, you can retrieve column 1 from the model.

Regards,
/kksou
 
  The administrator has disabled public write access.
#5316
kksou (Admin)
Admin
Posts: 1676
graph
User Online Now Click here to see the profile of this user
Re:My PHP-GTK2 questions 11 Months, 2 Weeks ago Karma: 27  
By the way, you might want to take a look at the sample code:
3.1 Signal basics

to see how we usually setup up callbacks for signals.

e.g. we usually do something like:
$iconview->connect('selection-changed', 'process_selection');

function process_selection($widget){
$selection = $widget->get_selected_items();
}

If you need some sample code on GtkIconView with selection, you can refer to the following:

Sample Code 460: How to drag and drop between two thumbnail images using GtkIconView with GtkTreeModelFilter - Part 2 - left to right insert?

Regards,
/kksou
 
  The administrator has disabled public write access.
#5317
cubii (User)
Fresh Boarder
Posts: 6
graphgraph
User Offline Click here to see the profile of this user
Re:My PHP-GTK2 questions 11 Months, 2 Weeks ago Karma: 0  
Thanks for that - it worked, more or less. Managed to get the result I wanted anyway.

Another question - is it possible to make rows in a table have variable font sizes for lines within a cell? Let me put a image of what I'd like:

Note: each line below the text means end of row/cell.



One method I thought about was using an HTML widget embedded into the row, so that I could use HTML to display what I want in various sizes, etc.

Is it possible to do something like this or what would you suggest? The design I'm following for my project ideally wants one row, one column per item.

Thanks!
 
 
Last Edit: 2012/06/05 13:18 By cubii. Reason: clarify
  The administrator has disabled public write access.
#5320
cubii (User)
Fresh Boarder
Posts: 6
graphgraph
User Offline Click here to see the profile of this user
Re:My PHP-GTK2 questions 11 Months, 2 Weeks ago Karma: 0  
No responses?
 
  The administrator has disabled public write access.
#5324
kksou (Admin)
Admin
Posts: 1676
graph
User Online Now Click here to see the profile of this user
Re:My PHP-GTK2 questions 11 Months, 2 Weeks ago Karma: 27  
Hi,

Don't think this is possible. You can only have one font size within each cell, as shown in the following sample code:

Sample Code 512: How to change the font of some rows or columns in treeview?

Regards,
/kksou
 
  The administrator has disabled public write access.
#5397
cubii (User)
Fresh Boarder
Posts: 6
graphgraph
User Offline Click here to see the profile of this user
Re:My PHP-GTK2 questions 10 Months, 2 Weeks ago Karma: 0  
I'm back. I'm making some excellent progress, both thanks to my PHP skills and your code snippets. However, I have another interesting challenge for you.

I have two buttons that change the data that a TreeView shows. The single column of the TreeView says what date it is, for example, "Orders for X/Y/2012". This part is working fine at the start of the app, initial data is fed into the drawing function and it creates the columns, populates data, etc.

However, what I'd like to achieve is that if you click on the Newer/Older buttons, then it will modify the column header accordingly. Say for example, "Orders for 3/7/2012" would change to "Orders for 2/7/2012".

Is this possible? If it's not possible to do so, I'm up against a brick wall.

Cheers!
 
  The administrator has disabled public write access.



Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop

Blog - Forum - Privacy Policy - Contact Us
Links - Classes - Social Business - BPM - Web - General
Copyright © 2006-2013. kksou.com. All Rights Reserved