Understood and thank you. Had to really weigh it all out... well... everything I was able to find... and saw that the only courses available in Toronto, Ontario, Canada for college are HTML5 focused in which should be more than enough to start my very own rather unique online business venture along with a few other fascinating projects in mind. I really want to be a part of the Nokia's huge "Surprise Uprise" as there seems much the potential... so I've really challenged myself to learn a whole lot, but it's difficult to tell if my progression is adequate enough as to why I thought to post nearly every type of valuable snippet I can muster... mostly hoping to get further guidance while sharing it altogether.
Just began writing a code 2 months ago to have a pythonicized swipe keyboard of my very own and discovered how an application that looks really simple is actually has 2 and a half very difficult hurdles. The half... since I sort of came up with a solution... the dragging event lags a bit too much, so I created an list array to record after each different loop then do a loop segment of the distances of 40 pixels to read what's in between... however, I imagine a quick redirection of swiping will put off the accuracy. Then there's trying to figure out how to write an algorithm to truncate my personalized "listofwords.txt". Anyhow, I can now probably say the next troublesome task "was" trying to screen capture the canvased keyboard and text screen simultaneously in a way to avoid poor flickering by learning how to buffer/thread images, until I realized that maybe touching near the top section of the screen should switch the mode from graphic to text... and the "Exit" button to switch back. Anyhow, in my earlier attempt to create a graphic text wrap module... I came up with this conjured from a mix of examples that took me too long to customize...
Code:
# text2fit.py
from appuifw import *
from graphics import *
import e32
app.directional_pad=False
app.screen='large'
lock=e32.Ao_lock()
app.body=canvas=Canvas()
app.exit_key_handler=lock.signal
img=Image.new(canvas.size) # create an image
width=canvas.size[0]-20
img.clear(0x555555ff)
setfont=(u"dense",30,None)
txtEntry=[u'This is a "measure_text" wrap method example whereas...']
words=[u'blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah',
u'should',u'appear',u'segmented',u'to',u'stay',u'within',u'the',u'given',u'boundary.']
def text_wrap(txtEntry=None):
global linewrap
w2=word[:]
try:
if linewrap:
pass
except:
linewrap=[u'']
try:
txtEntry=''.join(txtEntry)
txtEntry=txtEntry.split() # needed to be converted to a string
for line in txtEntry:
active=linewrap[0]+line
fits=canvas.measure_text(active,font=setfont)[1]
if fits > width:
while 1:
fits=canvas.measure_text(line,font=setfont)[1]
kb=canvas.measure_text(line,font=setfont,maxwidth=width)[2]
if fits > width:
linewrap.insert(0,line[:kb])
line=line[kb:]
else:
break
linewrap.insert(0,line+' ')
else: # fits entire entry
linewrap[0]+=line+' '
except:
pass
active=linewrap[0]+w2
fits=canvas.measure_text(active,font=setfont)[1]
if fits > width:
while 1:
fits=canvas.measure_text(w2,font=setfont)[1]
kb=canvas.measure_text(w2,font=setfont,maxwidth=width)[2]
if fits > width:
linewrap.insert(0,w2[:kb])
w2=w2[kb:]
else:
break
linewrap.insert(0,w2+' ')
else: # fits entire entry
linewrap[0]+=w2+' '
y=40
LnWr=linewrap[:]
LnWr.reverse()
img.clear(0x555555ff)
for line in LnWr:
img.text((10,y),line,font=setfont,fill=0xffffff) # text on blue img
y += 36
### demo
for word in words:
text_wrap(txtEntry)
canvas.blit(img)
canvas.blit(img)
lock.wait()