Coder Social home page Coder Social logo

Comments (8)

peterbrittain avatar peterbrittain commented on August 25, 2024

As you will see in all of the samples, you can handle resizing by creating a new Screen object. The bars demo (https://github.com/peterbrittain/asciimatics/blob/master/samples/bars.py) in particular shows how to handle resizing for a desired size.

I get that this isn't ideal, but the knock-on impact on the other objects that need to be resized and re-positioned means that you effectively go through the whole initialization sequence again. I have been thinking about changing this, but it will radically change the implementation and so will almost certainly not be back compatible. See #24.

from asciimatics.

peterbrittain avatar peterbrittain commented on August 25, 2024

I've updated the docs (see bb6ce87) to try to address this confusion.

Am assuming that this covers it. Please let me know if there was anything else that could help clarify it further.

from asciimatics.

lduczmal avatar lduczmal commented on August 25, 2024

This way cannot be used with

screen.print_at(...)
screen.refresh()

screen.refresh() does not have argument stop_on_resize

from asciimatics.

peterbrittain avatar peterbrittain commented on August 25, 2024

@lduczmal If you are not using the Screen.play() method you have full control of when things happen in your application and you can just call Screen.has_resized() to see if things have changed whenever you like.

from asciimatics.

lduczmal avatar lduczmal commented on August 25, 2024

@peterbrittain Thank you for you answer.
Problem is that Screen.has_resized() seems to do not work... I create such simple script which open new terminal windows and shows current screen dimensions, some changing value and info whether screen dimensions was changed. Maybe I make something wrong, but printed dimensions will not change when I change terminal window size during script is running. One note: I run it on Windows 10 and on Python downloaded from www.python.org/downloads

from asciimatics.screen import Screen
from asciimatics.exceptions import ResizeScreenError
import time

screen_changes = []
screen_changes.append("start")

def demo(screen):
    x = 0
    while True:
        x += 1
        mytext = "[Screen height: {0}, width: {1}] changing value: {2}".format(screen.height,screen.width,x)
        mytext2 = "Screen was resized? {0}".format(Screen.has_resized(screen))
        screen_changes.append(Screen.has_resized(screen))
        screen.print_at(mytext, 1, 1, colour=7, bg=0)
        if Screen.has_resized(screen):
            screen.print_at(mytext2, 1, 2, colour=1, bg=0)
        else:
            screen.print_at(mytext2, 1, 2, colour=2, bg=0)
        ev = screen.get_key()
        if ev in (ord('Q'), ord('q')):
            return
        screen.refresh()
        time.sleep(0.5)

Screen.wrapper(demo)
print(screen_changes)
sys.exit(0)

Best regards

from asciimatics.

peterbrittain avatar peterbrittain commented on August 25, 2024

@lduczmal That's because has_resized is not a static method, you just need to call screen.has_resized(). Note that this only guarantees to check if there has been a resize since the last time you checked. For Windows, it will continue to tell you on each call, but that's not a cross-platform guarantee and so you should fix your code. What should work is this:

    mytext2 = "Screen was resized? {0}".format(screen.has_resized())
    screen_changes.append(mytext2)

from asciimatics.

lduczmal avatar lduczmal commented on August 25, 2024

@peterbrittain Hi, thank you - now it works! almost... ;-) When I'm resizing terminal window during script run it sometimes returns to previous dimensions...
My code:

from asciimatics.screen import Screen
from asciimatics.exceptions import ResizeScreenError
import time
import sys

screen_changes = []
screen_changes.append("start")
quit_script = False
x = 0
def demo(screen):
    global quit_script
    global x
    while True:
        x += 1
        mytext = "[Screen height: {0}, width: {1}] changing value: {2}".format(screen.height,screen.width,x)
        #screen_changes.append(screen.dimensions)
        screen.print_at(mytext, 1, 1, colour=7, bg=0)
        if screen.has_resized():
            return
        ev = screen.get_key()
        if ev in (ord('Q'), ord('q')):
            quit_script = True
            return
        screen.refresh()
        time.sleep(0.5)

k = 0
while not quit_script:
    Screen.wrapper(demo)
    time.sleep(0.5)

I have one more question: function demo in code above has the only one argument screen. What about situation if I would like to add others arguments to this function and how use wrapper to pass additional params to function demo

from asciimatics.

peterbrittain avatar peterbrittain commented on August 25, 2024

Quick answers are that I think you're hitting a race condition in the Windows Console where you are delaying any processing for half a second. Simply removing this delay prevents the issue. And look at the samples for how to use the arguments parameter on wrapper to pass in other parameters to thde demo function.

Finally, could I ask that you please continue any questions in Gitter instead of in this closed issue? For example, go to: https://gitter.im/asciimatics/Lobby

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.