On 10/22/17 10:41, Martin Gregorie wrote:
> On Sun, 22 Oct 2017 13:10:39 -0400, Dennis Lee Bieber wrote:
>
>> On Sun, 22 Oct 2017 14:34:31 +0100, T M Smith
>> declaimed the following:
>>
>>> I am altering a python program and just wish to display readings of
>>> temperature etc. in the same place on screen after each update.
>>>
>> You'd probably get better suggestions by showing the relevant
> snippet
>> of existing code.
>>
>> Since your original post implies the existing program is
> scrolling, I'm
>> going to assume it is a simple console application (I don't see anyone
>> going through the effort of creating a GUI application with a scrolling
>> output, where a single line text widget would suffice).
>>
>> -=-=-=-=-
>> """
>> Simple demo for scroll vs non-scroll (Python 2.7, hence xrange and
>> paren-less print)
>> """
>>
>> import sys import time
>>
>> if "scroll" in sys.argv:
>> print print for x in xrange(100):
>> print "Pseudo-Temperature: %10.3f" % (x * 3.14159 - 25.5)
>> time.sleep(1)
>> elif "overwrite" in sys.argv:
>> print print for x in xrange(100):
>> sys.stdout.write("\rPseudo-Temperature: %10.3f"
>> % (x * 3.14159 - 25.5))
>> time.sleep(1)
>> else:
>> print "\nPlease supply either 'scroll' or 'overwrite' on the command
>> line"
>>
>>
>> -=-=-=-=-
>> C:\Users\Wulfraed\Documents\Python Progs>so.py
>>
> This solution doesn't seem to be OS-agnostic, unfortunately.
yeah I think it's working too hard. see my example (as in the other post)
import time
import sys
for xx in range(0,500) :
print "here I am ", xx, "\x1b[1G",
sys.stdout.flush()
time.sleep(0.1)
scrolling is easy. this shows how to use an ANSI sequence to move the
cursor. In theory, you can move it wherever you want. In this case
it's to the beginning of the current line, and the ',' at the end of
'print' keeps the line feed from being sent. then there's the 'flush'.
NOW you can use 'print' (instead of 'sys.stdout.write') and take
advantage of the built-in data output stuff, and send ANSI sequences to
move the cursor to the next spot (whatever that might be), or you could
move it to that spot BEFORE you output anything, whatever. All very
flexible. Requires an ANSI terminal. Fortunately, that works for ssh
and Linux X11 desktop consoles.
or if you want use "\r" (should work, didn't try it)
print "here I am ", xx, "\r",
--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)
|