Re: file selection interacting with drawing area





Amadeus W. M. wrote:

On Sun, 14 May 2006 11:25:13 -0600, Timothy M. Shead wrote:

On Sun, 2006-05-14 at 12:42 -0400, Amadeus W. M. wrote:
I have an unusual problem. I have a window (MainWindow) which contains a
drawing area (Darea) and some buttons. The user can draw various things
with the mouse. E.g. a segment is being drawn/updated continuously when
the user moves the mouse with button 1 pressed. The final position of the
segment is recorded when button 1 is released, so there is an
on_Darea_button_release() callback, which also draws the segment.

Enter the file selection dialog. When the user selects a file by
double-clicking, the dialog terminates upon the second button PRESS. The
event immediately following the second button press is a button RELEASE,
but that's now caught by the Darea, because the file selector is gone.
Bad things happen: the Darea, of course, tries to store and draw a segment,
because on_Darea_button_release() has been called.

What do I do?

I'm thinking about introducing a

bool loading_file;

which is set to 1 when the file chooser is being popped up,
and inspected within on_Darea_button_release(): only draw/store the
segment if and only if loading_file=0; if loading_file happens to be 1,
set it to 0. Something like this:

bool on_Darea_button_release(GdkEventButton * ev)
{

   if(loading_file){
      loading_file=0;
      return 0;
   }

   // if we've survived...

   // set the segment from ev->x, ev->y.
Darea.queue_draw(); return 0;
}

This seems awkward and prone to error though. Is there a more natural/Gtk
way?
I wouldn't make this conditional on the file dialog, since other
dialog(s) added later may cause the same problem.

That's exactly why I didn't like it.

You just need to keep
track of whether you caught a button press event, and ignore the button
release if you didn't - add an on_Darea_button_press() handler and set a
flag there - then test it in on_Darea_button_release().


Yes, it's more robust to set the bool flag to 1 in
on_Darea_button_press_event(), rather than make it contingent upon the
file selection dialog. Then, in on_Darea_button_release_event(), just
return if the flag is not 1. But I can't avoid the flag thing, can I?

You could set the sensitivity of your widget to button_press events in your load file method.

But the more I think about this, the more I'm unsure if it'd work.

I'd go with the flag.

Thanks!


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




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