Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Label size problems with changing content #40

Open
GoogleCodeExporter opened this issue Sep 1, 2015 · 0 comments
Open

Label size problems with changing content #40

GoogleCodeExporter opened this issue Sep 1, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
>>> from pgu import gui
>>> label = gui.Label("mytext",width=300)
>>> label.style.width
55

What is the expected output? What do you see instead?
(expected 300)


What version of the product are you using? On what operating system?
pgu-0.18 on ubuntu

Please provide any additional information below.

The reason that I feel this is needed is that I want to be able to change the 
label value in a fixed size container. Label.set_text was very slow.
(attempting to display the value of a moving slider caused lag)

I created a workaround that allows you to set a number of characters that you 
would like to be able to display, and if it is set, then the label will use 
that number of 'M' characters to estimate the size of the field.

===================================
#new Label.__init__()
    def __init__(self, value="", **params):
        params.setdefault('focusable', False)
        params.setdefault('cls', 'label')
        widget.Widget.__init__(self, **params)
        self.style.check("font")
        self.value = value
        self.font = self.style.font
        params.setdefault('chars')
        self.chars=params['chars']

        if self.chars is None:
            self.style.width, self.style.height = self.font.size(self.value)
        else:
            self.style.width, self.style.height = self.font.size("M" * self.chars)

#new set_text()
    def set_text(self, txt):
        """Set the text of this label."""
        self.value = txt
        # Signal to the application that we need to resize this widget
        if self.chars is None:
            self.chsize()
        else:
            self.repaint()


#new Label.resize()
    def resize(self,width=None,height=None):
        # Calculate the size of the rendered text
        if self.chars is None:
            self.style.width, self.style.height = self.font.size(self.value)
        else:
            (self.style.width, self.style.height) = self.font.size("M" * self.chars)
        return (self.style.width, self.style.height)


==========================================================
#showing differences
>>> from pgu import gui
>>> oldlabel = gui.Label("mytext")
>>> oldlabel.style.width
55
>>> sizelabel = gui.Label("mytext", width=100)
>>> sizelabel.style.width
55
>>> newlabel = gui.Label("mytext", chars=10)
>>> newlabel.style.width
130

Original issue reported on code.google.com by [email protected] on 30 Jul 2013 at 10:30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant