Re: Friday Finking: initialising values and implied tuples

2021-04-03 Thread Rob Cliffe via Python-list



On 03/04/2021 04:09, 2qdxy4rzwzuui...@potatochowder.com wrote:

On 2021-04-03 at 02:41:59 +0100,
Rob Cliffe via Python-list  wrote:


     x1 = 42; y1 =  3;  z1 = 10
     x2 = 41; y2 = 12; z2 = 9
     x3 =  8;  y3 =  8;  z3 = 10
(please imagine it's in a fixed font with everything neatly vertically
aligned).
This has see-at-a-glance STRUCTURE: the letters are aligned vertically
and the "subscripts" horizontally.  Write it as 9 lines and it becomes
an amorphous mess in which mistakes are harder to spot.

I agree that writing it as 9 lines is an accident waiting to happen, but
if you must see that structure, then go all in:

 (x1, y1, z1) = (43,  3, 10)
 (x2, y2, z2) = (41, 12,  9)
 (x3, y3, z3) = ( 8,  8, 10)
Agreed, that is even easier to read.  (It would be kinda nice if the 
compiler could optimise the tuples away, for those of us who are 
paranoid about performance.)


Or even:

 ((x1, y1, z1)
  (x2, y2, z2)
  (x3, y3, z3)) = ((43,  3, 10)
   (41, 12,  9)
   ( 8,  8, 10))

Or not.  YMMV.  I guess this doesn't come up enough in my own code to
worry about it.


--
https://mail.python.org/mailman/listinfo/python-list


RE: Python curses question: How to separate foreground and background colors from the value returned by inch()?

2021-04-03 Thread pjfarley3
> -Original Message-
> From: pjfarl...@earthlink.net 
> Sent: Saturday, April 3, 2021 1:25 AM
> To: python-list@python.org
> Subject: Python curses question: How to separate foreground and background
> colors from the value returned by inch()?
> 
> The window.inch(([y, x])) function returns the character and attributes of
> the character at the current or specified window position.  But how does
one
> separate the foreground and background colors from the resulting value?
> 
> colors = window.inch(0.0) & A_ATTRIBUTES
> 
> That should return the combined color + attributes value, but how to
> separate the foreground and background color values from that result?
> Should the following reliably work?
> 
> fg, bg = curses.pair_content (curses.pair_number(window.inch(0,0) &
> A_ATTRIBUTES))
> 
> Peter

Following up my own question because I experimented and found my own answer.
The snippet below reliably extracts the foreground and background colors on
both Ubuntu 20.04 (WSL2) and in a Win 10 console or Terminal window
(addstr() displays added to show intermediate values):

y, x = stdscr.getyx()
attr = stdscr.inch(6, 0)
stdscr.move(y, x)
stdscr.addstr("inch(6,0)={:08X}={}\n".format(attr, attr))
pair = curses.pair_number(attr)
if platform.system() == "Windows":
pair = pair >> 16
stdscr.addstr("pair(6,0)={:08X}={}\n".format(pair, pair))
fg, bg = curses.pair_content (pair)
stdscr.addstr("color(6,0) fg={:08X}={},bg={:08X}={}\n".format(fg, fg,
bg, bg))

The same sequence (minus the getyx() and move() operations) also works for
the window.getbkgd() function:

attr = stdscr.getbkgd()
stdscr.addstr("scrbkgd={:08X}={}\n".format(attr, attr))
pair = curses.pair_number(attr)
if platform.system() == "Windows":
pair = pair >> 16
fg, bg = curses.pair_content (pair)
stdscr.addstr("color(scrbkgd) fg={:08X}={},bg={:08X}={}\n".format(fg,
fg, bg, bg))

Windows snippet results:

inch(6,0)=5A30=1509949488 
pair(6,0)=005A=90 
color(6,0) fg=0059=89,bg==0
scrbkgd=0020=32
color(scrbkgd) fg=0007=7,bg==0

Ubuntu results:

inch(6,0)=5A30=23088
pair(6,0)=005A=90
color(6,0) fg=0059=89,bg=-001=-1
scrbkgd==0
color(scrbkgd) fg=-001=-1,bg=-001=-1

Test environments were:

1.  Ubuntu 20.04 (WSL2), python 3.8.5 and 3.9.0+, ncurses6/focal,now
6.2-0ubuntu2 amd64
2.  Win10 console and Terminal windows, python 3.8.7, windows-curses
2.2.0

ISTM that maybe I ought to figure out how to file a documentation bug /
enhancement request.  The official documentation of the returned values of
these functions is woefully incomplete, including that ncurses returns -1
values for "default" colors in the *ix environment while the Windows version
returns actual color values for default values.  Obviously an implementation
difference between ncurses and PDCurses, but worth noting somewhere.

I'm not sure if the necessity of shifting the "pair" result for Windows is a
necessary documentation addition or an actual bug in the underlying code.
Without the shift, the code aborts with these errors in Windows:

Traceback (most recent call last):
  File "C:\Users\MyUser\test\curses-color.py", line 126, in 
curses.wrapper(main)
  File "C:\Python38\lib\curses\__init__.py", line 105, in wrapper
return func(stdscr, *args, **kwds)
  File "C:\Users\MyUser\test\curses-color.py", line 72, in main
fg, bg = curses.pair_content (pair)
OverflowError: signed short integer is greater than maximum

Guidance on how to file requests for documentation corrections /
clarifications would be appreciated.  I do already have a generic module
that reliably shows the results using both of the above snippets.

Peter
--


-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Python curses question: How to separate foreground and background colors from the value returned by inch()?

2021-04-03 Thread pjfarley3
I figured out how to file a couple of issues on the python tracker site.

43715   inch() and scrbkgd() documentation omissions
43716   curses.pair_number() value issue

Peter

> -Original Message-
> From: pjfarl...@earthlink.net 
> Sent: Saturday, April 3, 2021 2:25 PM
> To: 'python-list@python.org' 
> Subject: RE: Python curses question: How to separate foreground and
> background colors from the value returned by inch()?
> 
 
> Guidance on how to file requests for documentation corrections /
clarifications
> would be appreciated.  I do already have a generic module that reliably
shows
> the results using both of the above snippets.
--


-- 
https://mail.python.org/mailman/listinfo/python-list


ENC: About \033[m

2021-04-03 Thread Fábio Pereira



 print("{}".format("\033[0;30;43m*\033[m"*40))
 print("{:^40}".format("v"))
 print("{:^54}".format("\033[7;30;43mProgramac,ao Python\033[m"))
 print("{:^54}".format("\033[7;30;43mFabio JS Pereira\033[m"))
 print("{:^40}".format("\033[7;30;43mProgramac,ao Python\033[m"))
 print("{:^40}".format("\033[7;30;43mFabio JS Pereira\033[m"))
 print("{:^40}".format("1234567890123456789012345678901234567890"))
 print("{:^40}".format("^"))





   Saida :







   Porque quando se usa formatac,ao de cores, o python nao consegue
   centralizar dentro da cadeia de 40 caracteres ?

   Tive que colocar 54 no parametro pois de alguma forma esta sendo
   considerado os caracteres de dentro do comando \033[m





   Enviado do [1]Email para Windows 10





References

   Visible links
   1. https://go.microsoft.com/fwlink/?LinkId=550986
-- 
https://mail.python.org/mailman/listinfo/python-list