Re: ListStore iteration



Amadeus,

The trick is to think of it in terms of control.  You don't want to leave gtkmm in control as much as possible.  Using a sleep() causes the program to halt in your signal handler.

Its not about how fast the update happens. That'd be the time between changing the selection and seeing the effect on screen. (At least how I would think of it).

I don't have time to finish it, but i've attached most of an example.

enough_time_has_passed() was just my way of saying I didn't want to look up the methods for doing time calculation. but it'd be something like:

bool
MainWindow::enough_time_has_passed()
{
    struct timeval now ;

   gettimeofday( &now, NULL ) ;

   unsigned long nowusecs = now.tv_sec * 1000000 + now.tv_usec ;
   unsigned long startusecs = _start.tv_sec * 1000000 + _start.tv_usec ; //_start is a member variable that was updated in the on_SaveAll_clicked()

   if( nowusecs - startusecs >= _timeoutdurationusecs ) //some member variable in microseconds
   {
      return true ;
   }

   return false ;
}

On 10/6/06, Amadeus W. M. <amadeus84 verizon net> wrote:
On Thu, 05 Oct 2006 23:12:02 -0500, Paul Davis wrote:

> Amadeus,
>
> You're not allowing the update function to be run.  You change the selection
> which causes the image to be loaded and put into the pixbuf for display, but
> you don't return and let gtk iterate through the event loop and redraw the
> image.
>
> The first way to accomplish this that comes to mind is to register an
> on_idle function.  Then you use a timeout that updates the selection.
>
> Something like this:
>
> bool MainWindow::on_idle()
> {
>    if( _iterating )
>    {
>       if( enough_time_has_passed() )
>       {
>            _row_iter++ ;
>            _selection->select( row_iter ) ;
>        }
>     }
>
>    return true ;
> }
>
> And connect it like so:
>
> Glib::signal_idle().connect( sigc::mem_fun( *main_window_ptr,
> &MainWindow::on_idle ) ) ;
>
> And then your button handler:
>
> void
> MainWindow::on_SaveAllButton_clicked()
> {
>       _selection = ItemSelector->get_selection() ;
>       _row_iter = _selection->children()->begin() ;
>      _iterating = true ;
>      _selection->select( _row_iter ) ;
>      init_enough_time_passed_function() ;
> }
>
> Paul
>


So the idea is to have each iteration triggered by some sort of timer,
right? A simple sleep() won't do (because I tried that). Except that
unlike a timeout, with an on_idle() function, the update happens as
quickly as possible. As in Chapter 17 in the book.

What exactly is the enought_time_has_passed() function. Sorry, I'm a
little tired myself.




_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list

#include <sys/time.h>
#include <time.h>

#include <gtkmm.h>

class Window : public Gtk::Window
{
	public:

		Window()
		{
			set_title( "OnIdle Example" ) ;
			set_size_request( 640, 480 ) ;
			_darea = Gtk::manage( new Gtk::DrawingArea() ) ;
			_darea->signal_expose_event().connect( sigc::mem_fun( *this, &Window::exposed ) ) ;

			Gtk::VBox* vbox = Gtk::manage( new Gtk::VBox() ) ;

			vbox->pack_start( *_darea, Gtk::PACK_EXPAND_WIDGET ) ;

			Gtk::HButtonBox* hbbox = Gtk::manage( new Gtk::HButtonBox() ) ;
			vbox->pack_start( *hbbox, Gtk::PACK_SHRINK ) ;

			Gtk::Button* button = Gtk::manage( new Gtk::Button( "Start" ) ) ;
			button->signal_clicked().connect( sigc::mem_fun( *this, &Window::start ) ) ;
			hbbox->pack_start( *button, Gtk::PACK_EXPAND_WIDGET ) ;

			button = Gtk::manage( new Gtk::Button( "Stop" ) ) ;
			button->signal_clicked().connect( sigc::mem_fun( *this, &Window::start ) ) ;
			hbbox->pack_start( *button, Gtk::PACK_EXPAND_WIDGET ) ;

			add( *vbox ) ;

			show_all_children() ;

			_width = 0 ;
			_height = 0 ;
		}

	private:

		bool
		exposed( GdkEventExpose* event )
		{
			//draw here.
		}

		bool
		on_idle()
		{
			if( _updating )
			{
				struct timeval now ;
				gettimeofday( &now, NULL ) ;

				unsigned long nowusecs = now.tv_sec * 1000000 + now.tv_usec ;
				unsigned long startusecs = _start.tv_sec * 1000000 + _start.tv_usec ;

				if( startusecs - nowusecs >= 1000000 )
				{
					_width = ( _width + 1 % 640 ) ;
					_height = ( _height + 1 % 480 ) ;

					_start = now ;
				}
			}

			return false ;
		}

		void
		start()
		{
			gettimeofday( &_start, NULL ) ;
			_updating = true ;
		}

		void
		stop()
		{
			_updating = false ;
		}


		Gtk::DrawingArea* 	_darea ;

		bool				_updating ;
		struct timeval		_start ;
		int					_width ;
		int					_height ;
} ;

int
main( int argc, char* argv[] )
{
	Gtk::Main kit( argc, argv ) ;

	Window w ;
	Gtk::Main::run( w ) ;

	return 0 ;
}




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]