rawpython / remi

Python REMote Interface library. Platform independent. In about 100 Kbytes, perfect for your diet.
Apache License 2.0
3.51k stars 401 forks source link

Labels do not display the correct number of whitespace #512

Closed AdrienLF closed 1 year ago

AdrienLF commented 1 year ago

Hello Davide,

I found a bug with remi, which I recreated in this short example:

import remi.gui as gui
from remi import start, App

class MyApp(App):
    def __init__(self, *args):
        super(MyApp, self).__init__(*args)

    def main(self):
        container = gui.VBox(width=120, height=100)
        self.lbl = gui.Label('Hello world!')
        self.bt = gui.Button('Press me!')

        # setting the listener for the onclick event of the button
        self.bt.onclick.do(self.on_button_pressed)

        # appending a widget to another, the first argument is a string key
        container.append(self.lbl)
        container.append(self.bt)

        # returning the root widget
        return container

    # listener function
    def on_button_pressed(self, widget):
        self.lbl.set_text('Button   pressed!')
        self.bt.set_text('Hi!')

# starts the web server
start(MyApp)

You will recognize your own example, the only difference is in Button pressed! which has three spaces between the words. However, only one space will be displayed in the browser. In our tests, we could not display more than one space character at a time, using remi with python 3.9 and Chrome as a browser.

dddomodossola commented 1 year ago

Hello @AdrienLF , here is the solution: https://github.com/rawpython/remi/issues/263#issuecomment-451724050 .

You should set the white-space property for your label or button: mylabel.css_white_space = 'pre'

'pre' stays for 'preserve'. This tells the browser to do not ignore spaces.