forked from ricgambino/XNAT-PIC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
progress_bar.py
82 lines (68 loc) · 3.04 KB
/
progress_bar.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 21 2022
@author: Riccardo Gambino
"""
"""
Progress bar class.
"""
import tkinter as tk
#import tkinter.ttk as ttk
import ttkbootstrap as ttk
from ttkbootstrap import Style
from ttkbootstrap.constants import *
from tkinter import HORIZONTAL
# from threading import Thread
# import time
PATH_IMAGE = "images\\"
class ProgressBar():
def __init__(self, root, bar_title):
self.title = bar_title
self.popup = tk.Toplevel(root)
self.popup.grab_set() # when you show the popup
self.popup.geometry("%dx%d+%d+%d" % (500, 100, 700, 500))
self.popup.resizable(False, False)
self.popup.iconbitmap(PATH_IMAGE + "logo3.ico")
self.popup.title(bar_title)
self.progress_var = tk.DoubleVar()
self.bar_length = 400
self.bar_maximum = 100
self.label = ttk.Label(self.popup, text='Loading ...', anchor=tk.CENTER, style="SubTitle.TLabel")
self.label.pack(side='top', fill='x', anchor=tk.CENTER, padx=10)
self.caption = ttk.Label(self.popup, text='', font=("Calibri", 10), anchor=tk.CENTER)
self.caption.pack(side='bottom', fill='x', anchor=tk.CENTER, padx=10)
def show_step(self, index, total):
self.step.config(text=str(index) + ' / ' + str(total))
self.popup.update()
def set_caption(self, text):
self.caption.config(text='')
self.caption.config(text=text)
self.popup.update()
def start_determinate_bar(self):
print('Starting progress bar...')
self.progressbar = ttk.Progressbar(self.popup, variable=self.progress_var,
orient=HORIZONTAL,
length=self.bar_length, mode='determinate', maximum=self.bar_maximum)
self.progressbar.pack(side='left', expand=True, anchor=tk.CENTER, padx=10)
self.step = ttk.Label(self.popup, text="", font=("Calibri", 10), anchor=tk.CENTER)
self.step.pack(side='left', anchor=tk.CENTER, padx=10, expand=True)
def start_indeterminate_bar(self):
print('Starting progress bar...')
self.progressbar = ttk.Progressbar(self.popup,
orient=HORIZONTAL,
length=self.bar_length, mode='indeterminate')
self.progressbar.pack(side='left', expand=True, anchor=tk.CENTER, padx=10)
self.step = ttk.Label(self.popup, text="", font=("Calibri", 10), anchor=tk.CENTER)
self.step.pack(side='left', anchor=tk.CENTER, padx=10, expand=True)
self.progressbar.start()
def update_bar(self, step=0.001):
self.progressbar.step(step)
self.progressbar.update()
def update_progressbar(self, current_step, max_step):
progress = int(current_step * self.bar_maximum / max_step)
self.progress_var.set(progress)
self.popup.update()
def stop_progress_bar(self):
print("Stopping progress bar...")
self.progressbar.stop()
self.popup.destroy()