Re: Design Issues - Getting started with GUI interfaces.




Tyler Hepworth said:
      How can I add this
      new widget to the HPaned without setting Global variables (our)
      and other types of ugliness.

   -return the tree to mainLoop
}

Am I going about this the right way?  Any suggestions on what to
change or how to improve?

basically, you're wanting to replace the contents of some container with an
editor widget for the currently selected row of the tree.

firstly: GtkTreeView is designed to allow in-place or direct editing of data,
with CellRenderers that support editing.  your users may be somewhat confused
by the cumbersome nature of a separate pane; is the editor widget going to be
so complicated that you need it to be separate?  (i presume the main reason
it's separate is so that you can minimize traffic with the database?)

then: since you want to replace the contents of the HPaned, you need to keep a
handle to it.  the most common way to do this is to store a reference to the
widgets you need in the toplevel window instance.  then you have them
whereever you need them, one for each window, without using globals and
without walking the widget tree.  i'd even go so far as to store a frame or
scrolled window or something instead of the HPaned, so there's less code to
change when you decide to use a VPaned or floating dialog or whatever else.

  # in create_tree:
    ...
    $main_window->{editor_container} = Gtk2::Frame->new;

  # then you can make these:
  sub get_row_editor_widget {
     my $main_window = shift;
     return $main_window->{editor_container}->get_child;
  }
  sub set_row_editor_widget {
     my ($main_window, $new_widget) = @_;
     my $old = $main_window->get_row_editor_widget;
     if ($old) {
         $old->hide;
         $old->destroy;
     }
     $main_window->{editor_container}->add ($new_widget);
     $new_widget->show;
  }


if you turn your main window into a typical perl object, then this becomes
even easier...

-- 
muppet <scott at asofyet dot org>



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