Model View Controller. How to implement?
- From: Peter <volkov_peter list ru>
- To: gtk-list gnome org
- Subject: Model View Controller. How to implement?
- Date: Thu, 10 Mar 2005 16:50:57 +0300
Hello.
I need suggestion to implement MVC in gtk+. I'm not a programmer, actually
I'm physicist and I would like to program some physical process, that will
be shown in different views. So I've already implemented model object
(with methods to manipulate with it) and view widget (that do some
drawing). I open new views in the new windows for now. Also I have main
window with controllers (buttons). But my implementation has problems I
don't know how to solve, without your help :)
Pressing play button in my controller starts new process that simulates
some process. (BTW. Should I create a new process? In other way, program
will return from callback function when my process finishes. I think
this is bad, when process takes a very long time. Also I want to stop,
pause process.)
void
iterations_run(RyModel * self){
process_state = PROCESS_RUN; /* global variable */
g_thread_create( computation, (gpointer)self, FALSE, NULL);
}
I have to stop process every small time interval of time (this is done
inside of long_cpu_process function using GTimer) and emit changed signal
to update views.
gpointer
computation(gpointer data)
{
RyModel *ry=RY_MODEL(data);
while (process_state == PROCESS_RUN){
long_cpu_process(ry);
g_signal_emit (ry, GET_RY_MODEL_CLASS(ry)->changed_signal_id,
0 /* details */, NULL);
}
return 0;
}
The problem here is that although "changed" signal recieved, it's not
procesed by view, as computation function in other thread, continue it's
work, and so do not allow to update views and sends another signal.
Standart approach like this:
while (gtk_events_pending ())
gtk_main_iteration ();
do not work for me.
I thought about some base class for my view with the method like
update_all_views(). But how to implement this? How to account active views?
May be there exist better solutions?
Thank you all, for your attention,
Peter.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]