gnope php gtk gui gnope.org  

gtkscrolledwindow scrolling bottom

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



Joined: 01 Apr 2006
Posts: 14

PostPosted: Tue May 30, 2006 11:54 pm    Post subject: gtkscrolledwindow scrolling bottom Reply with quote

hello, i tryed in all the ways (using the gtkadjustment and setting the iter at last) to move the vertical scrolling to bottom without succed, here is the sample:

Code:
<?php

function quit() {
   gtk::main_quit();
}

$buffer = new GtkTextBuffer();
$buffer->set_text("adsfasdfdsf
asdfasdfsadfsadf
sadfadsfadsfdsaf
sadfdsafsadfsadf
sadfsadfasdfasdf
sadfdsfgdsfgsfdg
sdfgsdfgsdfgfdsg
sdfgsdfgsfdgsdfg
sfdgsdfgdsfdsfgg
sdfgdsfdsdsfgfds
sfdgdsfgfdsgfdsg
sdfgsdfgdsfgdsfg
sdfgsfdgdsfgdsgg
dsfgsdfgsdfgsdff
sdfgsdfgdsfgdsfg
sdfgsfdgdsfgdsfg
sdgsdgsdfgdsfgds
dsfgsdgdsfgdsfgg
sfdgsfdgsdfgsdfg");
$buffer->place_cursor($buffer->get_end_iter());
$viewer = new GtkTextView();
$viewer->set_buffer($buffer);
$scrolled_window = new GtkScrolledWindow();
$scrolled_window->set_policy("GTK_POLICY_AUTOMATIC", "GTK_POLICY_AUTOMATIC");
$scrolled_window->set_vadjustment(new GtkAdjustment(1.0, 1.0, 1.0, 0.0, 0.0, 0.0));
// $scrolled_window->set_focus_vadjustment(new GtkAdjustment(1.0, 1.0, 1.0, 0.0, 0.0, 0.0));
$scrolled_window->add($viewer);
$window = new GtkWindow();
$window->add($scrolled_window);
$window->set_size_request("300", "150");
$window->connect("destroy", "quit");
$window->show_all();

gtk::main();

?>
Back to top
cweiske



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

PostPosted: Wed May 31, 2006 7:01 am    Post subject: Reply with quote

I am just adding an iterator to the end of the text buffer and am scrolling to there:
Code:
        $buffer = $this->txtLog->get_buffer();
        $end = $buffer->get_end_iter();
        $buffer->insert($end, $strText);

        $this->txtLog->scroll_to_iter($buffer->get_end_iter(), 0.49);
Back to top
ragnar



Joined: 01 Apr 2006
Posts: 14

PostPosted: Wed May 31, 2006 9:58 am    Post subject: Reply with quote

thanks cweiske but... WTF?!?

the viewer is the one that have the control above the scroller?? Confused

BTW i added $viewer->scroll_to_iter($buffer->get_end_iter(), 0) before the gtk::main() and it just scrolls a bit down?!?!

but ok... at least is a begining...
Back to top
cweiske



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

PostPosted: Wed May 31, 2006 10:09 am    Post subject: Reply with quote

Do you still use your own adjustments? don't do this.
Back to top
ragnar



Joined: 01 Apr 2006
Posts: 14

PostPosted: Wed May 31, 2006 11:13 am    Post subject: Reply with quote

no, i commented the adjustments, take a look yourself:

Code:
<?php

function quit() {
   gtk::main_quit();
}

$buffer = new GtkTextBuffer();
$buffer->set_text("adsfasdfdsf
asdfasdfsadfsadf
sadfadsfadsfdsaf
sadfdsafsadfsadf
sadfsadfasdfasdf
sadfdsfgdsfgsfdg
sdfgsdfgsdfgfdsg
sdfgsdfgsfdgsdfg
sfdgsdfgdsfdsfgg
sdfgdsfdsdsfgfds
sfdgdsfgfdsgfdsg
sdfgsdfgdsfgdsfg
sdfgsfdgdsfgdsgg
dsfgsdfgsdfgsdff
sdfgsdfgdsfgdsfg
sdfgsfdgdsfgdsfg
sdgsdgsdfgdsfgds
dsfgsdgdsfgdsfgg
sfdgsfdgsdfgsdfg");
// $buffer->place_cursor($buffer->get_end_iter());
$viewer = new GtkTextView();
$viewer->set_buffer($buffer);
$scrolled_window = new GtkScrolledWindow();
$scrolled_window->set_policy("GTK_POLICY_AUTOMATIC", "GTK_POLICY_AUTOMATIC");
// $scrolled_window->set_vadjustment(new GtkAdjustment(1.0, 1.0, 1.0, 0.0, 0.0, 0.0));
// $scrolled_window->set_focus_vadjustment(new GtkAdjustment(1.0, 1.0, 1.0, 0.0, 0.0, 0.0));
$scrolled_window->add($viewer);
$window = new GtkWindow();
$window->add($scrolled_window);
$window->set_size_request("300", "150");
$window->connect("destroy", "quit");
$window->show_all();

$viewer->scroll_to_iter($buffer->get_end_iter(), 0);

gtk::main();

?>
Back to top
ron_t



Joined: 11 Dec 2005
Posts: 78
Location: Gatineau, Quebec

PostPosted: Wed May 31, 2006 12:47 pm    Post subject: Reply with quote

ragnar wrote:
no, i commented the adjustments, take a look yourself:

Code:


$viewer->scroll_to_iter($buffer->get_end_iter(), 0);


?>


Change this line to read:

Code:

$viewer->scroll_to_iter($buffer->get_end_iter(), 0, true);


-Ron T.
Back to top
ragnar



Joined: 01 Apr 2006
Posts: 14

PostPosted: Thu Jun 01, 2006 11:00 am    Post subject: Reply with quote

thanks ron_t but it still doesnt work Sad
Back to top
ron_t



Joined: 11 Dec 2005
Posts: 78
Location: Gatineau, Quebec

PostPosted: Thu Jun 01, 2006 1:22 pm    Post subject: Reply with quote

ragnar wrote:
thanks ron_t but it still doesnt work Sad


Strange. I tested it here and it worked fine. Still does (I just ran it again.)

Are you using the latest php_gtk2.dll (v. 1.2.2)? If not, take a look under Announcements in this forum where Christien gives instructions for downloading/installing it.

-Ron T.
Back to top
scott



Joined: 16 Feb 2006
Posts: 35

PostPosted: Thu Jun 01, 2006 2:54 pm    Post subject: Reply with quote

From the Gtk+ docs:
Quote:
NOTE: This function uses the currently-computed height of the lines in the text buffer. Note that line heights are computed in an idle handler; so this function may not have the desired effect if it's called before the height computations.


Since you are calling it before the main loop starts, the height calculations aren't done quite yet. You need to wait until the calculations are done. In the example below, I did this by connecting a signal handler to the "select-all" signal. Run the example and then hit 'CTRL-A'. The view will scroll to the bottom. I realize that forcing the user to select all the text just to get the view to scroll is not the best solution, but maybe you can use this to point you in the right direction.

Code:
<?php
function scroll($view, $buffer)
{
        $view->scroll_to_iter($buffer->get_end_iter(), 0);
}

$buffer = new GtkTextBuffer();
$buffer->set_text('adsfasdfdsf
asdfasdfsadfsadf
sadfadsfadsfdsaf
sadfdsafsadfsadf
sadfsadfasdfasdf
sadfdsfgdsfgsfdg
sdfgsdfgsdfgfdsg
sdfgsdfgsfdgsdfg
sfdgsdfgdsfdsfgg
sdfgdsfdsdsfgfds
sfdgdsfgfdsgfdsg
sdfgsdfgdsfgdsfg
sdfgsfdgdsfgdsgg
dsfgsdfgsdfgsdff
sdfgsdfgdsfgdsfg
sdfgsfdgdsfgdsfg
sdgsdgsdfgdsfgds
dsfgsdgdsfgdsfgg
sfdgsfdgsdfgsdfg');

$viewer = new GtkTextView();
$viewer->set_buffer($buffer);
$scrolled_window = new GtkScrolledWindow();
$scrolled_window->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);

$scrolled_window->add($viewer);
$window = new GtkWindow();
$window->add($scrolled_window);
$window->set_size_request('150', '150');
$window->connect_simple('destroy', array('Gtk', 'main_quit'));
$window->show_all();

$viewer->connect_simple('select-all', 'scroll', $viewer, $buffer);

gtk::main();
?>


P.S. Note some of the other changes that I made. (set_policy and connecting to the destroy signal)
Back to top
cweiske



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

PostPosted: Fri Jun 02, 2006 12:02 am    Post subject: Reply with quote

Classic situation for
Code:
while(Gtk::events_pending()) { Gtk::main_iteration();}
Back to top
ragnar



Joined: 01 Apr 2006
Posts: 14

PostPosted: Fri Jun 02, 2006 10:40 am    Post subject: Reply with quote

thanks a lot guys!!!!!! at last it works perfectly!!!!

i wanted to keep in secret until the basic things r done, but this code is for a tool im developing for manage Mysql server, and this is preciselly for emulating the console, u can take a look at [url]sourceforge.net/projects/lirio[/url] and im sorry but right now is only in spanish, soon ill look for translators and ull have it also in many languages

cheers
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.