Bonjour après 2 jours de recherche infructueuse je me décide à demander de l'aide....
Voici mon problème :
Je désire suivre l'évolution d'une fonction par le biais d'une ProgressBar, la fonction en question est complètement externe à GTK, elle fait partie d'une de mes bibliothèque et peut être modifiée à ma guise.
Pour lancer cette fonction j'utilise un bouton (dans ma fenetre principale), sont callback me permet de lancer une nouvelle fenêtre qui affiche la barre de progression et la fonction.
Ma question est comment faire en sorte que ma fonction retourne régulièrement une valeur pour que la progressbar évolue ?
J'ajoute un peu de code, en espérant que sa pourra aider à comprendre se que je veux faire.
<CModule.h>
<CModule.cpp>Code:
1
2
3
4
5
6
7
8
9
10 /// declarations .... class CModule { protected: public: int m_iAvancement; bool Fonction(data) ; bool ComputeAff(data); bool Compute(data); }
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 /// declarations .... bool ComputeAff(gpointer data) { ///// data une structure contenant des pointeurs sur différents parametres et des Widget // La Fenetre data->pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(data->pWindow), "GtkProgressBar"); gtk_window_set_default_size(GTK_WINDOW(pWindow), 320, 100); gtk_container_set_border_width(GTK_CONTAINER(data->pWindow), 4); // Le decoupage vertical GtkWidget * pMainVBox = gtk_vbox_new(TRUE, 0); gtk_container_add(GTK_CONTAINER(pWindow), pMainVBox); /* Creation de la barre de progression Principale*/ data->pProgressP = gtk_progress_bar_new(); gtk_box_pack_start(GTK_BOX(pMainVBox), data->pProgressP, TRUE, FALSE, 0); g_signal_connect(G_OBJECT(data->pWindow), "show", G_CALLBACK(Compute), (gpointer*)data); gtk_widget_show_all(data->pWindow); gtk_main(); return TRUE; } bool Compute (gpointer data) { ///// data une structure contenant des pointeurs sur différents parametres et des Widget //// Initialisation de la progressbar (pas de pb) // Je veux lancer ma fonction CModule core_module; core_module.m_iAvancement=0; //fixe avancement à zéro et au cours de la fonction Avancement évolue. core_module. bool Fonction(data); // lancement de la function //// Comment faire évoluer la progressbar ????? }
<Main.cpp>
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 /// declarations .... void Callback_Lancement (GtkWidget* widget, gpointer data) { // Relayage vers FONCTION CModule().Compute(data); } void main() { /********************* * Initialisation GTK * *********************/ //Init du multithreading if(!g_thread_supported()) g_thread_init(NULL); //Init le multithreading pour GDK gdk_threads_init(); //Zone critique du thread pour le programme principal gdk_threads_enter(); /*************************** * L'application principale * ***************************/ //Taille de la fenetre principale int m_nSizeX = 200; int m_nSizeY = 100; //Cree la fenêtre GtkWidget* m_pWindowSecondaire = gtk_window_new(GTK_WINDOW_TOPLEVEL); p_struc_gtkpointer->p_Widget1 = m_pWindowSecondaire; //Fixe la taille de la fenêtre gtk_window_set_default_size(GTK_WINDOW(m_pWindowSecondaire),m_nSizeX,m_nSizeY); //Fixe l'affichage de la fenêtre au centre gtk_window_set_position(GTK_WINDOW(m_pWindowSecondaire),GTK_WIN_POS_CENTER); // Contenaire et ajout a la fenetre GtkWidget* m_pV = gtk_vbox_new(FALSE,0); gtk_container_add(GTK_CONTAINER(m_pWindowSecondaire),m_pV); ///// DIVERS WIDGET de RéGLAGES /// Boutton APPLIQUER GtkWidget* pApply=gtk_button_new_from_stock(GTK_STOCK_EXECUTE); gtk_box_pack_start(GTK_BOX(m_pV),pApply,FALSE,FALSE,0); /// Lance calcul g_signal_connect(G_OBJECT(pApply),"clicked",G_CALLBACK(Callback_Lancement),(gpointer*)data); //Affichage principal gtk_widget_show_all(m_pWindowSecondaire); //Entre dans la boucle infinie gtk_main(); //Fin de la zone critique du thread du programme principal gdk_threads_leave(); }