Re: emitting a signal for refeshing entries



>You may be doing this already, but if you're not, I'd strongly urge you to res
>tructure as a model/view design. If I understand you right, you have a big opt

i always appreciate people recommending MVC programming. however:

>typedef struct _Model {
>  GtkWidget *spin;
>  double spin_value;
>
>  ... etc.
>} Model;

ethis is absolutely not MVC. a GtkWidget is a View element. it has no
place in the Model. What you need is:

struct Model {
       double value;
       ...
       .. some g_signal types ...
}

void
change_model (Model* m, double newval)
{
       m->value = m;
       g_signal_emit ("the signal the model emits when changed");
}       	

struct View {
       GtkWidget* spin;
       ...
};

void
refresh_view (Model* m, void *arg)
{
    View* v = (View *) arg;
    gtk_spin_button_set_value( GTK_WIDGET(v->spin ), m->value );
}

and then somewhere, call

    g_signal_connect ("the signal that the model emits when changed",
                      refresh_view,
		      my_view);

NOTE: this is all pseudo code. the syntax for the g_signal stuff in
particular is just meant to be hand-waving :)

remember that if all the model has as state is a numerical value, then
you can use a GtkAdjustment as your model, and it has all the right
signals ready to use.

--p



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