Python for Symbian: Enhanced Graphics

 Extended version of the official PyS60 graphics module.

Enhanced Graphics

Enhanced Graphics -module is a modified graphics module for Python running on your Symbian mobile phone. The focus is to improve the text drawing functions of the excellent Python for S60. Initially my goal was to to bring support for text drawing to the S60 3rd edition, but after browsing the S60 C++ API, I realized I could improve the module even more. The new module has functions to measure text boundaries and allows you to create scalable interfaces to make your application work on devices with varying display sizes. The module works on S60 2nd and 3rd edition and UIQ3 devices. UIQ2 support is not tested, but it should work also.

NEWSFLASH: The font issue has been fixed since PyS60 1.3.22 and it also provides function for measuring text. This module is still useful, if you happen to need zoom, twips, ascent and/or descent support.

S60 2nd

EmulatorN70

S60 3rd

Emulator

 

UIQ 3

Emulator


Patch vs. Enhancement

The difference between 'patch' and 'enhanced' module is that the patch is compatible with the official version. In short, your Python applications using the official text drawing functions should work on both platforms. Enhanced module changes the API so that the text() -function takes only position coordinates and the text to draw. Other settings, like text color is separated to its own function unlike in the original version.

There are no plans to keep the patched -version updated. I have no need, will and time to do so. Latest patch can be downloaded here. The original patch can be found from PyS60's sourceforge page under tracker->patches.

Discussion

You can send feedback(bug reports) and other posts to this thread in Forum Nokia. To keep everybody informed about bugs and stuff: DO NOT SEND ME AN EMAIL. It will most likely be trashed instantly. Post your message to the forums instead.

Download

Sources

As PyS60, this module is completely Open Source, of course. Under Apache 2.0 license as PyS60. Download the source here.

Contains:

  • graphicsmodule.cpp & graphics.mmp.in
    • Goes to src\ext\graphics\
  • font_leaktest.py
    • Demonstration of use and proof that the module is not leaking memory.
  • snake.py & ball.py
    • Updated to use the new API

Precompiled

None of these packages contain the font_leaktest.py, which is the best example of how to use this module. So it is recommended to download the source zip also.

S60

  • 2nd edition
    • PYD - EnhancedGraphics_2nd_1.0.zip
      • Just unzip, send to phone and replace the original _graphics.pyd ( make backup just in case) in c:\system\libs\ using FExplorer or some other filemanager.

 

The API

In this chapter, I show the changed and added functions. Download the full PyS60 API documentation from SourceForge to see the other functions. The new API uses different functions to, for example, set font attributes while the official module uses the single 'text' -function to draw text with different settings. These two graphics modules are not compatible with each other. By separating the functionality, it is easier to create applications that work on both platforms. The module is basically same as the official graphics -module except the text -function is different and it has few additional functions.

text( position, text)

Draws text starting from given coordinates.

  • position
    • Position to start writing.
    • Type 2-tuple( x, y)
  • text
    • Text to write.
    • Type: unicode

setFont( font, fill, size, bold, italic, zoom, bitmaptype, twips )

Sets font attributes.

  • font
    • Font to set. To create platform independent code, it is recommended to use one of the predefined fonts: 'normal', 'dense', 'annotation', 'legend' or 'title'. These non-unicode font names get a standard font from the underlying UI environment. Other fonts must be given in unicode. Use appuifw.available_fonts() to get exact names of all available fonts.
    • Type: str or unicode
  • fill
    • Used font color.
    • Type: 3-tuple( r, g, b)
  • size
    • Font's size in pixels
    • Type: int
  • bold
    • Set bold
    • Type: True or False
  • italic
    • Set italic
    • Type: True or False
  • zoom
    • Zooms the font. Must be > 0.0.
    • Type: float
  • bitmaptype
    • Determines the way the font is drawn.
      • 0 = default, 1=bitmap, 2=antialiasing
    • Type: int
    • Note: If you use TrueType fonts on 2nd edition, you'll need to give the bitmaptype also.
  • twips
    • Font's size in twips
    • Type: int

getFontHeight()

Returns the height of the currently active font in pixels.

getTextWidth( text )

Measures width of given text

  • text
    • Text to measure.
    • Type: unicode

Returns the width in pixels.

maxTextWidth( text, maxwidth )

Returns amount of characters that can be displayed without exceeding the specified width.

  • text
    • Text to measure.
    • Type: unicode
  • maxwidth
    • Maximum width of the text in pixels
    • Type: int

textsize( text )

Combines the getFontHeight() and getTextWidth().

  • text
    • Text to measure.
    • Type: unicode

Returns 2-tuple ( width, height ).

getFontDescent()

Returns descent height of the currently active font in pixels.

See this wiki about TypeFaces.

getFontAscent()

Returns ascent height of the currently active font in pixels.

See this wiki about TypeFaces.