Bonjour à tous !!
je voudrais afficher une progressbar (pulse) pendant l'exécution d'une fonction qui prend du temps...
J'ai donc parcourue le web et j'ai choisit une solution qui consiste a lancer un thread qui va tourner en même temps que ma fonction. cela fonctionne la progress s'anime si je # l'appel de ma fonction qui dure longtemps...
J'ai teste aussi le faite que pendant l'exécution de ma fonction qui dure la boucle du thread tourne bien en parallele via un print 'toto' -> OK
Si j'appel ma fonction qui dure alors là
pas d'affichage de ma progressbar (qui pourtant et juste avant l'appel de ma fonction) avant la fin de ma fonction qui dure...
mon code fonctionne mais c'est l'affichage qui n'est pas bon.
J' ai vu que l'on peu utiliser la fonction pour rafraichir un callback mais je ne trouve pas la manière de l'adapter a mon code et si cela résoudrai mon problème :
while gtk.events_pending():
gtk.main_iteration(False)
voici un extrait de mon code :
Merci de l'aide que vous pourrez m'apporter.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
56
57
58
59 class FractionSetter(threading.Thread): """This class sets the fraction of the progressbar""" #Thread event, stops the thread if it is set. stopthread = threading.Event() def run(self): """Run method, this is the code that runs while thread is alive.""" #Importing the progressbar widget from the global scope global progressbar #While the stopthread event isn't setted, the thread keeps going on while not self.stopthread.isSet() : # Acquiring the gtk global mutex gtk.gdk.threads_enter() #Setting a random value for the fraction progressbar.pulse() # Releasing the gtk global mutex gtk.gdk.threads_leave() #Delaying 100ms until the next iteration time.sleep(0.1) def stop(self): """Stop method, sets the event to terminate the thread's main loop""" self.stopthread.set() gobject.threads_init() class window: # callback pour lancer le traitement depuis une GUI def transfer_put(self, widget): self.progressbar.show() #Creating and starting the thread global fs fs = FractionSetter() fs.start() #fonction qui dure qui dure ... self.on_button_clicked_put() #Stopping the thread and the gtk's main loop fs.stop() def on_button_clicked_put(self): #traitement qui dure longtemps for i in liste ... if ...
Partager