| Reply | « Previous Thread | Next Thread » |
|
Hi!
i've found this: Quote:
Quote:
Code:
Code:
# Create active object
SCRIPT_LOCK = e32.Ao_lock( )
def __exit__( ):
SCRIPT_LOCK.signal( )
appuifw.app.exit_key_handler = __exit__
appuifw.app.title= u'PageBuilder base class'
text = [u'iLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do' \
'eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad' \
'minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex '\
'ea commodo consequat. Duis aute irure dolor in reprehenderit in '\
'voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur '\
'sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt '\
'mollit anim id est laborum.' ]
PageBuilder( text ).show( )
SCRIPT_LOCK.wait( )
![]() where is the problem?some one could help me? THK
Last edited by giogiogio : 2007-08-25 at 21:22.
|
|
Hi giogiogio,
First of all, please use my version, using binding instead of the keyboard class and able to resize when changing the screen size. Code:
####################################################
# Author: LEFEVRE Damien
# Version: 0.2
# Decription: Text page builder
# Copyright 2006-2007 LEFEVRE Damien contact[at]lfdm[dot]net
# License: Apache2
####################################################
import appuifw #@UnresolvedImport
from key_codes import EKeyUpArrow, EKeyDownArrow, EKeySelect #@UnresolvedImport
from graphics import Image #@UnresolvedImport
try:
from akntextutils import wrap_text_to_array #@UnresolvedImport
except:
import sys
sys.exit("akntextutils module isn't installed!")
## @brief Base class from making scrollable pages.
#
# PageBuild build a non-editable page of text wrapped inside the screen width. The
# page can be scrolled vertically.
# This UI control handle the screen resizing i.e: dimentions, protrait, landscape
# for the phone supporting this feature.
#
#
# @b Snippet:
# @code
# import appuifw, e32
# from org.pbol.UI.pageMaker import PageMaker
#
# # Create active object
# SCRIPT_LOCK = e32.Ao_lock( )
#
# def __exit__( ):
# SCRIPT_LOCK.signal( )
#
#
# def portrait():
# appuifw.app.orientation='portrait'
#
# def landscape():
# appuifw.app.orientation='landscape'
#
# appuifw.app.exit_key_handler = __exit__
# appuifw.app.title = u'PageBuilder base class'
# appuifw.app.menu = [(u'Portrait', portrait),
# (u'Landscape', landscape)]
#
# text = [u'iLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do' \
# 'eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad' \
# 'minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex '\
# 'ea commodo consequat. Duis aute irure dolor in reprehenderit in '\
# 'voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur '\
# 'sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt '\
# 'mollit anim id est laborum.' ]
#
# PageMaker( text ).show( )
#
# SCRIPT_LOCK.wait( )
# @endcode
class PageMaker( object, appuifw.Canvas):
## Background color for the list
_iBackgroundColor = 0xffffff
## Default text font
_iDefaultFont = 'dense'
## Over sized image to be scrolled
_iOSImage = None
## Lines to print on the image
_iLines = []
## Line space
_iLineSpace = 20
## When True, elements are drawn
_iReady = False
## Scrollbar cursor outline color
_iScrollbarCursorOutlineColor = 0x0000ff
## Scrollbar cursor fill color
_iScrollbarCursorFillColor = 0xc3d9ff
## Scrollbar outline color
_iScrollbarOutlineColor = 0x000000
## Scrolling factor
_iYFactor = 0
## Text x origin in pixel
_iXText = 2
## Text x origin in pixel
_iYText = _iLineSpace
## @brief The constructor
# @param self The object pointer
# @param aList List containing text to display
# @param aScrollY True by default; show the scrollbar or not
def __init__( self, aList=[], aScrollY=True ):
## If True, the scrollbar will be displayed
self._iScrollY = aScrollY
## Keyboard handler instance. self._eventCallback given will be called
# everytime a keyboard event will happen. That way it filters the
# useless events.
appuifw.Canvas.__init__( self,
self._redrawCallback,
resize_callback = self._resizeCallback )
appuifw.app.body = self
self.bind(EKeySelect, None)
self.bind( EKeyUpArrow, lambda:self._up( ) )
self.bind( EKeyDownArrow, lambda:self._down( ) )
## @brief Store the array of non wrapped string set at the construction or when
# calling the set method.
self._iRawStringArray = aList
self._iReady = True
## @brief Displays the text on the application body
# @param self The object pointer
def show( self ):
appuifw.app.body = self
## @brief Set new content for the text object
# @param self The object pointer
# @param aLong_str_array Array containing the long string to print
def set( self, aLong_str_array ):
self._iRawStringArray = aLong_str_array
self._formatData( )
self._redrawCallback( )
## @brief Key down, scrolls down
# @param self The object pointer
def _down( self ):
if ( ( self.size[1] ) + ( self._iYFactor + 1 ) * self._iLineSpace ) < \
( self._iOSImage.size[1] + self._iLineSpace ):
self._iYFactor += 1
self._redrawCallback( )
## @brief Draw the image
# @param self The object pointer
def _drawImage( self ):
if self._iOSImage:
self.blit(self._iOSImage ,target=( 0,
-self._iYFactor * self._iLineSpace ) )
## @brief Draw the scroll bar on the right
# @param self The object pointer
def _drawScrollbar( self ):
if self._iScrollY and self._iOSImage:
height = ( self._iOSImage.size[1] - self.size[1] ) / \
self._iLineSpace
# if height is negative, then the image is smaller than the cnaves
if height < 0:
height = 0
if ( self._iOSImage.size[1] - self.size[1] ) % \
self._iLineSpace != 0:
height += 1
height += 1 # +1 ince we start counting from 0
height = self.size[1] / height
y = self._iYFactor * height
height = self.size[1]
if self._iOSImage.size[1] > self.size[1]:
height = self.size[1] - (self._iOSImage.size[1] - self.size[1] ) /self._iLineSpace
if ( self._iOSImage.size[1] - self.size[1] ) % \
self._iLineSpace != 0:
height -= 1
y = self._iYFactor
self.line( ( self.size[0] - 2, 0 ,self.size[0] - 2, self.size[1] ),
# vertical right side scroll bar
outline=self._iScrollbarOutlineColor )
self.rectangle( ( self.size[0] - 3, y, ( self.size[0] ), y + height ),
outline=self._iScrollbarCursorOutlineColor,
# scroll rectangle
fill=self._iScrollbarCursorFillColor)
## @brief Redraw callback method for teh canvas
# @param self The object pointer
# @param aRect Attribute value sent by the Canvas object
def _redrawCallback( self, aRect=None): #@UnusedVariable
self.clear( self._iBackgroundColor )
if self._iReady:
self._drawImage()
self._drawScrollbar()
## @brief Key up, scrolls up
# @param self The object pointer
def _up( self ):
if self._iYFactor > 0:
self._iYFactor -= 1
self._redrawCallback( )
## @brief Generates array of line to be drawn
# @param self The object pointer
def _formatData(self):
temp = []
measures = self.measure_text(u"Tlpq", font=self._iDefaultFont, maxwidth=self.size[0]-5)
## @brief line space recalculated when the screen dimentions or orientation
# change
self._iLineSpace = abs(measures[0][1]) + abs(measures[0][3])
for long_str in self._iRawStringArray:
# long_str is a long string to be wrapped
lines = wrap_text_to_array(long_str,
self._iDefaultFont,
self.size[0]-5)
for line in lines:
temp.append(line)
# finally set the private lines variable
## Store the lines of text wrapped at the screen width
self._iLines = temp
## @brief Create an oversized image
# @param self The object pointer
def _createOversizedImage( self ):
x, y = self._iXText, self._iYText
# calculate the height (head space + img height + 1 line + x line for
# the text)
height = y + ( len( self._iLines ) * self._iLineSpace ) + \
self._iLineSpace
# create the main image
self._iOSImage = Image.new( ( self.size[0], height ) )
# add the text on it
for line in self._iLines:
self._iOSImage.text( ( x, y ), line, font=self._iDefaultFont )
y += self._iLineSpace
## @brief Callback called when the screen size has changed. It can be due to
# tilting the screen, changing apuifw.app.menu to 'normal', 'large', 'full'
# @param self The object pointer.
# @param aRect Default paramter sent with the callback
def _resizeCallback(self, aRect=None): #@UnusedVariable
try:
self._formatData()
self._createOversizedImage()
except:
pass
Quote:
Quote:
![]() LFD Devices: Nokia E61 3rd Edition - pys60 1.4.0 Tips and modules: http://www.lfdm.net/thesis |
|
ok!
of course i'll use your version!! for the problem i've done.i have to use a list not a string!... ![]() |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| cant access WML page by mobiles | hubertus | General Browsing | 0 | 2007-04-13 16:25 |
| Response.redirect hang my page | jacky1977 | General Browsing | 1 | 2006-01-15 16:29 |
| How do i pass value from an xhtml page to a php page and likewise? | vash82 | Browsing and Mark-ups | 0 | 2005-02-17 07:15 |
| FOrmat for accessing the page | praveen_bala | General Browsing | 2 | 2004-10-28 05:17 |
| File format Unknown when trying to view XHTML page on the Nokia6650 | shawn.hines | Browsing and Mark-ups | 0 | 2004-05-04 17:35 |