Re: "Bottlenecking" connections



On Sat, 2001-08-25 at 13:07, Haoran Un wrote:
> Hi,
> 
> I have a programming question with GTK.
> 
> I have an application with a whole stack of radio buttons (but they 
> could be anything) and there is a Connection from each RadioButton to 
> a point X. (it doesn't really matter what X is, either).
> 
> Now what happens is that I want to be able to block ALL of the 
> connections to point X at various times. What I'd prefer is that 
> instaed of, doing signal_handler_unblock/block n times for n radio 
> buttons, instead I could have:
> 
> n connctions going to point Y, and then 1 connection from point Y to 
> point X. Then I could simply block the connection between Y and X.
> 
> IS there some sort of way of "bottlenecking" all these connections so 
> that I can block and unlock once, instead of n times?

Can't you just code the solution you propose yourself?  Create an object
(or callback or whatever) and let it listen to events and dispatch them
to whoever needs to hear see them.  You can then change the state of the
dispatcher to change the behaviour of your code.

You could perhaps use something like the attached code.  A (potential)
problem with that solution is the tight copling between dispatcher and
operations. Sometimes you need the dispatcher to know about the
operations so it can chose which operations to call, othertimes you just
want it to broadcast an event to whoever is listening.  The later
solution you can achive by letting the dispatcher signal rather than
call functions, and then let the operations listen for that signal.(*)
Other than that I think it would work the same way.

	/mailund

(*) I can hack up an example of that if it is unclear what I am trying
to explain here.


-- 
Two things I learned for sure during a particularly intense acid trip
in my own lost youth: (1) everything is a trivial special case of
something else; and, (2) death is a bunch of blue spheres.
                                      --- Tim Peters, 1 May 1998
#include <gtk/gtk.h>

static void
op_1 (void)
{
  g_print ("op 1\n");
}

static void
op_2 (void)
{
  g_print ("op 2\n");
}

static void
op_3 (void)
{
  g_print ("op 3\n");
}


static gboolean blocked = FALSE;
static void
dispatch(GtkWidget *dummy, int op_id)
{
  if (!blocked)
    {
      switch (op_id)
	{
	case 1:
	  op_1();
	  break;
	case 2:
	  op_2();
	  break;
	case 3:
	  op_3();
	  break;
	}
    }
}

static void
toggle_block(void)
{
  blocked = ! blocked;
}

int
main(int argc, char *argv[])
{
  GtkWidget *win;
  GtkWidget *vbox;
  GtkWidget *button;

  gtk_init (&argc, &argv);

  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  
  vbox = gtk_vbox_new (TRUE, 0);
  gtk_container_add (GTK_CONTAINER (win), vbox);

  button = gtk_button_new_with_label ("op 1");
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
  gtk_signal_connect (GTK_OBJECT (button), "clicked",
		      GTK_SIGNAL_FUNC (dispatch),
		      GINT_TO_POINTER (1));

  button = gtk_button_new_with_label ("op 2");
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
  gtk_signal_connect (GTK_OBJECT (button), "clicked",
		      GTK_SIGNAL_FUNC (dispatch),
		      GINT_TO_POINTER (2));

  button = gtk_button_new_with_label ("op 3");
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
  gtk_signal_connect (GTK_OBJECT (button), "clicked",
		      GTK_SIGNAL_FUNC (dispatch),
		      GINT_TO_POINTER (3));

  button = gtk_button_new_with_label ("toggle block");
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
  gtk_signal_connect (GTK_OBJECT (button), "clicked",
		      GTK_SIGNAL_FUNC (toggle_block),
		      NULL);




  gtk_widget_show_all (win);

  gtk_main ();

  return 0;
}


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