pythondialog
pythondialog copied to clipboard
Length of extended ASCII chars are counted wrong towards width
Using extended ASCII chars like █ are counted with a larger width as displayed in the terminal. Meaning, the dialog window extends itself more than needed. Width can't be set to a lower setting, as it will throw a DialogError and the note Can't make sub-window at (42,9), size (1,194)
This picture can only be obtained through setting width=0:

Here is the original ASCII art, for testing of course :sweat_smile:.
xx______________________________________________________________xx
xx______________________________________________________________xx
xx________________________________________████████████__________xx
xx______________________________________██////////////██________xx
xx___________________________________ ██////////////////██______xx
xx_________________________________ ██//// __ ////// __ //██____xx
xx_________________________________ ██////__██//////██__//██____xx
xx__________________________________██////__██//////██__//██____xx
xx__________________________________██//////////██////////██____xx
xx__________________________________██////████//////████//██____xx
xx________________________________██////██//////██//////██______xx
xx______________________██████████////////████//////████________xx
xx____________________██//////██////////██//////////██__██______xx
xx__________________██////////////////////////////////██________xx
xx________________██//////////////////////////////////██________xx
xx____████████__██//////////////////////////////////██__________xx
xx__██////////████////////////////██////////////////██████______xx
xx██////██////////////////////////██//////////██//██//////████__xx
xx__████//////////██////////////██//////////██//██//////██////██xx
xx██////////////██████////////██████////////████__████////////██xx
xx__████████████______██████████//////////██__________████████__xx
xx______________________________██████████______________________xx
xx______________________________________________________________xx
xx______________________________________________________________xx
(It also suffice to just use a long enough line with extended ASCII symbols of course :speak_no_evil:)
EDIT: I figured out how to circumvent this: Setting tab_len=1 for this window allows setting the size, but also forces one to set it manually for this window.
Hello,
Sorry for the delay. It is possible that width=0 doesn't correctly detect the display width of non-ASCII chars (yes, every Unicode code point > 127 is beyond ASCII). Unfortunately, I fear that would be a problem between dialog, underlying libraries (most notably libncursesw), the terminal in use and how it is configured. In other words, nothing that can be fixed in pythondialog, I'm afraid.
That being said, I'm a bit surprised by the statement at the end of your first paragraph. At least, on my system with dialog 1.3-20201126 linked to libncursesw6 6.2+20201114-2 (Debian package version number), inside an appropriately-sized xterm running under locale en_US.UTF-8 (set using the LANG environment variable), the following program works fine and gives the screenshot below:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import sys, locale
from dialog import Dialog
# This is almost always a good thing to do at the beginning of your programs.
locale.setlocale(locale.LC_ALL, '')
d = Dialog(dialog="dialog")
ascii_art = """\
xx______________________________________________________________xx
xx______________________________________________________________xx
xx________________________________________████████████__________xx
xx______________________________________██////////////██________xx
xx___________________________________ ██////////////////██______xx
xx_________________________________ ██//// __ ////// __ //██____xx
xx_________________________________ ██////__██//////██__//██____xx
xx__________________________________██////__██//////██__//██____xx
xx__________________________________██//////////██////////██____xx
xx__________________________________██////████//////████//██____xx
xx________________________________██////██//////██//////██______xx
xx______________________██████████////////████//////████________xx
xx____________________██//////██////////██//////////██__██______xx
xx__________________██////////////////////////////////██________xx
xx________________██//////////////////////////////////██________xx
xx____████████__██//////////////////////////////////██__________xx
xx__██////////████////////////////██////////////////██████______xx
xx██////██////////////////////////██//////////██//██//////████__xx
xx__████//////////██////////////██//////////██//██//////██////██xx
xx██////////////██████////////██████////////████__████////////██xx
xx__████████████______██████████//////////██__________████████__xx
xx______________________________██████████______________________xx
xx______________________________________________________________xx
xx______________________________________________________________xx"""
d.msgbox(ascii_art, width=70, height=26, title="'msgbox' example")
sys.exit(0)

Your “ASCII” art being 66 chars wide, since there is a border of 2+2 chars (left+right, one blank and one rule on each side), 70 chars is indeed the minimum dialog box width to properly display this artwork.