User Interface Suggestions? (newbie)

Peter Otten __peter__ at web.de
Thu Oct 6 08:38:24 EDT 2016


BartC wrote:

> On 05/10/2016 23:12, Akira Li wrote:
>> Beverly Howard <bev at bevhoward.com> writes:
>>
>>> ...snip...
>>> A primary question would be, "What are options for building a display
>>> that would update displayed values without scrolling?"
>>
>> To rewrite only the last character, you could use '\b':
>>
>>   import os
>>   import itertools
>>   import time
>>   for c in map(str.encode, itertools.cycle('\-/|')):
>>       os.write(1, b'\b'+c)
>>       time.sleep(.3)
>>
>> To rewrite only the last line, you could use '\r':
>>
>>   for i in range(1, 101):
>>       time.sleep(.1)
>>       print('\r{:4.0%}'.format(i/100), flush=True, end='')
>>
>> To control the full screen in the terminal e.g., to change the position,
>> you could use *blessings* module [1]:
>>
>>   from blessings import Terminal  # $ pip install blessings
>>
>>   line = 'Line in the middle of the terminal.'
>>   term = Terminal()
>>   with term.hidden_cursor(), term.fullscreen():
>>       x = (term.width - len(line)) // 2
>>       y = (term.height - 1) // 2
>>       with term.location(x, y):
>>           print(term.bold_white_on_black(line))
>>
>>       with term.location(0, term.height - 1):
>>           input('press <Enter> to exit..')
>>
>> For interactive command-line applications from a simple prompt to full
>> screen terminal applications, you could use *prompt_toolkit* module [2].
>>
>>> My first goal is to build a program that would interface with a
>>> Raspberry Pi to control a heating process.
>>>
>>
>> For flexibility, you could split your program into a server and a client
>> that controls it (text, GUI, web).
> 
> All this advice seems to be getting out of hand, with suggestions of
> 'curses' and 'blessings' and using GUI. I've tried 'ncurses' elsewhere
> and it was over the top for what I wanted to do.
> 
> The OP wants to runs on Pi which I think runs Linux.
> 
> So all they are asking is, is there a way of randomly positioning the
> cursor within the terminal window so that the next output is at that
> position. Something like an escape sequence. Terminal screens have been
> around a long time, you'd think someone would have had such a
> requirement before!
> 
> I'd quite like to know too. However I've just tried a test sequence
> ("<esc>[P1d" to move the cursor to row 1) and it didn't work. If there's
> reason why something so basic won't work (hence the need for curses etc)
> then that would be useful to know too. (And how does curses manage it?!)

Perhaps you picked the wrong escape sequence? I tried <esc><line>;<column>H 
taken from <http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x361.html>, and it 
seems to work (the test system is not a Pi though):

$ python3
Python 3.4.3 (default, Sep 14 2016, 12:36:27) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> for i in range(20, 10, -1):
...     print("\033[{0};5HHello from line {0}".format(i), end="")
... 



    Hello from line 11>>> 
    Hello from line 12
    Hello from line 13
    Hello from line 14
    Hello from line 15
    Hello from line 16
    Hello from line 17
    Hello from line 18
    Hello from line 19
    Hello from line 20





More information about the Python-list mailing list