Is there a way to make the xbmcgui.ControlLabel wordwrap?
#1
Is there a way to make the xbmcgui.ControlLabel wordwrap within the set width? Currently, when the label gets to the end of the "width" with more text to display, it just puts three dots and moves to the next paragraph.

CURRENT CODE:
    def display_description(self, description_text):
        # Create a Kodi label control with the provided description text
        description_label = xbmcgui.ControlLabel(
            x=self.button_width + 100,
            y=self.button_height + 100,
            width=self.screen_width - (self.button_width + 150),
            height=self.button_height + (self.button_vert_gap*2),  # Adjust the height as needed
            label=description_text,
            font="font13",
            textColor="FFFFFFFF",  # White text color
            alignment=1
        )
        # Add the description label control to the Kodi window
        self.parent_window.addControl(description_label)
Reply
#2
explicitly wrapped to a certain length regardless of spaces

python:
messagestr="The quick brown fox jumps over the lazy dog is an English-language pangram – a sentence that contains all the letters of the alphabet. The phrase is commonly used for touch-typing practice, testing typewriters and computer keyboards, displaying examples of fonts, and other applications involving text where the use of all letters in the alphabet is desired."
n = 40
chunks = [messagestr[i:i+n] for i in range(0, len(messagestr), n)]
print('\n'.join(chunks))
Reply
#3
Thanks for the help. Definitely progress. But for some reason some of the lines still don't wrap.

    # Display the description on Kodi window
    # region
    def display_description(self, description_text):
        paragraphs = description_text.split('\n')  # Assuming paragraphs are separated by a newline character
       
        label_x = self.button_width + 100
        label_y = self.button_height + 100
        label_width = self.screen_width - (self.button_width + 150)
        line_height = 40  # Adjust as needed
       
        for paragraph in paragraphs:
            lines = self.split_text_into_chunks(paragraph, 150)  # Adjust the chunk size as needed
           
            for line in lines:
                description_label = xbmcgui.ControlLabel(
                    x=label_x,
                    y=label_y,
                    width=label_width,
                    height=line_height,
                    label=line,
                    font="font13",
                    textColor="FFFFFFFF",  # White text color
                    alignment=0  # Left alignment
                )
               
                self.parent_window.addControl(description_label)
                label_y += line_height  # Move to the next line
    def split_text_into_chunks(self, text, chunk_size):
        chunks = [text[i:i+chunk_size] for i in range(0, len(text), chunk_size)]
        return chunks
    # endregion


NEVERMIND. IT WAS MY OWN STUPIDITY. I WAS MAKING THE LINES A COUPLE CHARACTERS OVER THE LIMIT OF THE SCREEN WHICH CAUSED SOME LINES TO NOT WRAP.

THANKS FOR YOUR SUGGESTION AND HELP!
Reply
#4
youre welcome

if you decide later you want it wrapped to spaces it would just be a little bit more code but same idea
Reply
#5
You are misusing ControlLabel. It is meant for fixed short text labels. For longer text there are ControlFadeLabel with horizontal autoscrolling and ConrolTextBox with horizontal wrapping and vertical autoscrolling.
Reply

Logout Mark Read Team Forum Stats Members Help
Is there a way to make the xbmcgui.ControlLabel wordwrap?0
This forum uses Lukasz Tkacz MyBB addons.