Coder Social home page Coder Social logo

Comments (4)

peterbrittain avatar peterbrittain commented on July 23, 2024

The problem that you've got is that I've yet to expose a method to draw the next frame, so you need to reverse the logic and put your status into an Effect. For example:

from asciimatics.effects import Print
from asciimatics.renderers import BarChart
from asciimatics.scene import Scene
from asciimatics.screen import Screen
from asciimatics.exceptions import ResizeScreenError, StopApplication
import sys
from random import randint

# Simple progress indicator - from 0 to 100
progress = 0


def get_progress():
    global progress
    if randint(0, 100) > 10:
        progress += 1
    return progress


class ProgressBar(Print):
    def __init__(self, screen):
        super(ProgressBar, self).__init__(
            screen,
            BarChart(
                7, 60, [get_progress],
                char=">",
                scale=100.0,
                labels=True,
                axes=BarChart.X_AXIS),
            x=(screen.width - 60) // 2,
            y=(screen.height - 7) // 2,
            transparent=False, speed=2)

    def _update(self, frame_no):
        global progress
        if progress >= 100:
            raise StopApplication("100% complete")
        else:
            super(ProgressBar, self)._update(frame_no)


def demo(screen):
    scenes = []
    effects = [
        ProgressBar(screen)
    ]
    scenes.append(Scene(effects, -1))
    screen.play(scenes, stop_on_resize=True)

while True:
    try:
        Screen.wrapper(demo)
        sys.exit(0)
    except ResizeScreenError:
        pass

from asciimatics.

peterbrittain avatar peterbrittain commented on July 23, 2024

@erturpin was that helpful? Can I close this down now?

from asciimatics.

peterbrittain avatar peterbrittain commented on July 23, 2024

with no response in 2 weeks, I'm assuming that this can now be closed...

from asciimatics.

cigani avatar cigani commented on July 23, 2024

Thanks was helpful for me

from asciimatics.

Related Issues (20)

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.