×

Discussion Board

Results 1 to 6 of 6

Thread: Wrap text

  1. #1
    Regular Contributor
    Join Date
    May 2008
    Posts
    86

    Wrap text

    I tried to recreate the wrapping text effect like in akntextutils module (wrapping without cut words), but something goes wrong
    This is my code
    Code:
    def text_wrap(text,lung):
    	text_array =[]
    	flag = lg = 0
    	while len(text) > lg:
    		try:
    		    for k in range(0,lung):
    			   if text[k] == " ":
    				flag = lg + k
    		except:
    			flag = len(text)
    		lines = text[lg:flag]
    		lg = flag
    		text_array.append(lines)
    	return text_array
    and then I call the function to have an array of my lines
    Code:
    all = text_wrap(text_show, 32)
    for lines in all:
    	show.text((10, top), unicode(lines), font='title', fill = color)
    	top += 20
    but I have two problems:
    1. sometimes the new line starts with a white space. I even tried to add 1 to the first character of new line, but in this way sometimes I get a missing character.
    I know there is something missing, but I can't figure out what it is.
    2. how can I get the number of character that can fit in canvas? I put 32, but I think in larger screen I can have a lot of white space on the right.

    Thanks in advance.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    386

    Re: Wrap text

    First of all, you can't wrap on a fixed size of a row if you're not using a fixed-width font. Think about it, 32 "W" letters are much wider than 32 "i" letters.

    Therefore, you have to use the measure_text() method of PyS60 drawable objects to measure the width of text depending on the font you're using. Your wrapping function will have to be somewhat more complicated.

    And use the appuifw.app.layout(appuifw.EMainPane)[0] to get width and height of the canvas.

  3. #3
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,796

    Re: Wrap text

    Previously, There was a post related to this !

    May be seaching the forum might do some good.

    Br,
    Croozeus
    Pankaj Nathani
    www.croozeus.com

  4. #4
    Regular Contributor
    Join Date
    May 2008
    Posts
    86

    Re: Wrap text

    I did. I only found this post but I couldn't get it work.
    Other posts were related to akntextutils that it's impossible to include in the .sis file, so I had to avoid to use it.
    BTW if I'm the only one having problems with the class in the first post, I'll check my code and try to make it works.

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    386

    Re: Wrap text

    This class looks good to me. Check it and tell us what problems are you having exactly. We'll try to help.

  6. #6
    Regular Contributor
    Join Date
    May 2008
    Posts
    86

    Re: Wrap text

    It was something related to number of items.
    Now it works fine.
    Thanks for you support!

Similar Threads

  1. Wrap text using drawString ?
    By artemg in forum Mobile Java General
    Replies: 6
    Last Post: 2009-06-25, 10:25
  2. Wrap text using soft return in cell on CAKnGrid
    By heuven in forum Symbian User Interface
    Replies: 3
    Last Post: 2008-04-01, 06:46
  3. Need help to Wrap and Display long text
    By dc-huang in forum Symbian User Interface
    Replies: 0
    Last Post: 2005-08-30, 13:47
  4. Replies: 0
    Last Post: 2004-11-24, 18:49
  5. Nokia 7650 Anchor element text does not wrap
    By voxsurf in forum Browsing and Mark-ups
    Replies: 1
    Last Post: 2003-02-28, 08:53

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×