Comments (8)
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.
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.
This way cannot be used with
screen.print_at(...)
screen.refresh()
screen.refresh() does not have argument stop_on_resize
from asciimatics.
@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.
@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.
@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.
@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.
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)
- Asciimatics doesn't print anything. HOT 3
- Custom subprocess integration HOT 2
- Rain test fails randomly HOT 10
- Load another form after initialization HOT 5
- RayCaster sample "swallows" key when commenting out RayCaster effect HOT 6
- DarkGray access on Windows/Powershell? HOT 7
- Automate user inputs HOT 4
- Leave and re-enter asciimatics mode? HOT 2
- Emojis with "hidden characters"? HOT 11
- particles HOT 4
- Mouse Events in Win11 HOT 4
- Implementing Widget's Custom Color Palettes HOT 4
- Can we donate to the project via Paypal? HOT 3
- New release? HOT 3
- Incompatible with Python 3.12 (imp module removed)
- Support multi-line text rolling in a rect HOT 3
- The effect of selecting the check box in version 1.15.0 is different from that in version 1.14.0 HOT 1
- Right side will not align if you use Unicode character. HOT 1
- Add a way to let the user provide a custom text wrapping function HOT 8
- `RadioButtons` does not consider the right pallet when item is selected without focus HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asciimatics.