Giter VIP home page Giter VIP logo

progresspanel's Introduction

Progresspanel

The Progresspanel is a custom tkinter widget that displays a progress bar and buttons (Start/Resume, Pause, Terminate) to control a user-defined task that runs in a separate thread. The widget is implemented in progresspanel.py.

Installation

You can install Progresspanel using pip for the Python environment:

pip install progresspanel

Usage

To use the Progress Panel, you need to create an instance of the Progresspanel class and pass it a parent widget, a total number of iterations, and a task function to be run in a loop.

Here below is an example code that creates a window with a progress bar and buttons to control the task as shown in the GIF:

progress_demo

import tkinter as tk
from progresspanel import Progresspanel
from time import sleep

root = tk.Tk()
panel = Progresspanel(root, title="Sample Task")
panel.pack()

def sample_task():
    total = 5
    panel.set_total(total)
    for i in range(total):
        panel.update(i)
        print("Running iteration: {}".format(i))
        sleep(1)

panel.set_task(sample_task)
root.mainloop()

The task function simply sleeps for one second five times and updates the progress bar each time.

You can customize the task function to do whatever you want. You can also customize the title of the progress panel and enable/disable verbose mode to print status updates to the console. There're also advanced features that let you pause execution in between time-consuming methods in your own task, and features that let you repeat the last iteration right after resuming from a pausing. Check below APIs for more details.

API

Progresspanel(parent, total=1, task=None, title=None, verbose=True)

Create a new Progresspanel widget.

  • parent: the parent widget.
  • total: the total number of iterations for the task.
  • task: the task function to be run in a loop.
  • title: the title of the progress panel.
  • display_time_left: a bool to determine whether to display the remaining time in the status label, default to True.
  • verbose: whether to print status updates to the console.

set_total(total)

Set the total number of iterations for the task.

set_task(task)

Set the task function.

update(i)

Update the progress bar with the current iteration number.

set_verbose(verbose)

Enable/disable verbose mode to print status updates to the console.

is_pausing_or_terminating()

Check if the task is in a pausing or terminating state. This is useful for user to stop promptly before running other time-consuming operations in user-defined task after user clicks pause or terminate button.

is_pause_resumed()

Check whether the task was just resumed after a pause. It returns True if the progress is just resumed after it was paused, until the next iteration in which it returns False again. It also returns False in all other cases. This is useful if user wants to repeat current iteration after the work was resumed from pause, especially when the user configured to jump over some customized time-comsuming operations in task() using is_pausing_or_terminating() after the pause button was clicked.

after_started()

Placeholder for user-defined function to be run when the task is started.

after_resumed()

Placeholder for user-defined function to be run when the task is resumed.

after_paused()

Placeholder for user-defined function to be run when the task is paused.

after_terminated()

Placeholder for user-defined function to be run when the task is terminated.

after_completed()

Placeholder for user-defined function to be run when the task is completed.

License

Progresspanel is released under the MIT License. See LICENSE for more information.

progresspanel's People

Contributors

xuejianma avatar

Watchers

 avatar

progresspanel's Issues

Make progress bar total instead of time left and total.

Hey! Cool program! This solved a problem that I was having with regular progressbars in tkinter. I am curious if you could make the "Time Left" option a keyword argument to turn it off so that the text could just be a percent?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.