Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS 

Nokia - User Agent

// User Agent

Modello 3230
"Nokia3230/2.0 (5.0614.0) SymbianOS/7.0s Series60/2.1 Profile/MIDP-2.0
Configuration/CLDC-1.0"

Modello 6260
"Nokia6260/2.0 (3.0448.0) SymbianOS/7.0s Series60/2.1 Profile/MIDP-2.0
Configuration/CLDC-1.0"

Modello 6600
"Nokia6600/1.0 (5.27.0) SymbianOS/7.0s Series60/2.0 Profile/MIDP-2.0
Configuration/CLDC-1.0"

Modello 6620
"Nokia6620/2.0 (4.22.1) SymbianOS/7.0s Series60/2.1 Profile/MIDP-2.0
Configuration/CLDC-1.0"

Modello 6630
"Nokia6630/1.0 (5.03.08) SymbianOS/8.0 Series60/2.6 Profile/MIDP-2.0
Configuration/CLDC-1.1"

Modello 6670
"Nokia6670/2.0 (6.0540.0) SymbianOS/7.0s Series60/2.1 Profile/MIDP-2.0
Configuration/CLDC-1.0"

Modello 6680
"Nokia6680/1.0 (4.04.07) SymbianOS/8.0 Series60/2.6 Profile/MIDP-2.0
Configuration/CLDC-1.1"

Modello 6681
"Nokia6681/2.0 (5.37.01) SymbianOS/8.0 Series60/2.6 Profile/MIDP-2.0
Configuration/CLDC-1.1"

Modello 9300
"Mozilla/4.0 (compatible; MSIE 5.0; Series80/2.0 Nokia9300/05.22
Profile/MIDP-2.0 Configuration/CLDC-1.1)"

Modello 9500
"Mozilla/4.0 (compatible; MSIE 5.0; Series80/2.0 Nokia9500/4.51
Profile/MIDP-2.0 Configuration/CLDC-1.1)"

PyS60 - BabelFish

// Translate from language A to language B
// code not complete but it works

import urllib

####################################################################################### <BabelFish>
class BabelFish(object):
    
    def translate(self, lang, message):
        
        try:
            url = urllib.URLopener()
        
            query = urllib.urlencode({
                                      'doit':'done',
                                      'intl':'1',
                                      'lp':lang,
                                      'tt':'urltext',
                                      'urltext':message
                                      })
        
            responde = url.open('http://babelfish.altavista.com/tr', query).read()
        
            start = responde.find('<div style=padding:10px;>') + 25
            stop = responde.find('</div>', start)
        
            return responde[start:stop]
        
        except Exception, error:
            return '-' + str(error)
####################################################################################### </BabelFish>

####################################################################################### <BabelFishUI>
from graphics import *

import appuifw
import e32

class BabelFishUI(object):
    
    def __init__(self):
        
        self.__lock = e32.Ao_lock()
        self.__img = Image.new((176, 144))
        self.__language = 'it_en'
        self.__textUI = None
        
        appuifw.app.exit_key_handler = lambda:self.__lock.signal()
        
        appuifw.app.title = u'BabelFish v1.0'
        appuifw.app.body = self.__canvas = appuifw.Canvas(redraw_callback=self.updateScreen)
        
        appuifw.app.menu = [(u'Translate', lambda:self.__translateUI()), (u'About', lambda:appuifw.note(u'BabelFish: v1.0", "Created by\nWhite Tiger\n<Z-TEAM@Libero.it>', 'info')), (u'Exit', lambda:self.__lock.signal)]
        
        self.updateScreen(None)
        
        self.__menuMain = appuifw.app.menu
        self.__bgMain = appuifw.app.body
        
        self.__lock.wait()
    
    def updateScreen(self, rect):
        
        self.__canvas.blit(self.__img)
    
    def __back(self):
        
        appuifw.app.menu = self.__menuMain
        appuifw.app.body = self.__bgMain
        
        appuifw.app.set_tabs([u'Back'], lambda x:None)
    
    def __translateUI(self):
        
        self.__textUI = appuifw.Text()
                
        appuifw.app.menu = [(u'Translate', lambda:self.__translate()), (u'Language', lambda:self.__setLanguage()), (u'Clear', lambda:self.__textUI.clear()), (u'Back', lambda:self.__back())]
                   
        appuifw.app.body = self.__textUI
                
    def __setLanguage(self):
        
        resp = appuifw.selection_list([u'italiano-inglese', u'inglese-italiano', u'inglese-francese', u'francese-inglese', u'inglese-tedesco', u'tedesco-inglese',
                                       u'francese-italiano', u'italiano-francese'], 1)
        
        if resp == 0:
            self.__language = 'it_en'
        elif resp == 1:
            self.__language = 'en_it'
        elif resp == 2:
            self.__language = 'en_fr'
        elif resp == 3:
            self.__language = 'fr_en'
        elif resp == 4:
            self.__language = 'en_de'
        elif resp == 5:
            self.__language = 'de_en'
        elif resp == 6:
            self.__language = 'fr_it'
        elif resp == 7:
            self.__language = 'it_fr'
            
    def __translate(self):
        
        babel = BabelFish()
        
        resp = babel.translate(self.__language, self.__textUI.get())
        
        if resp[0] == '-':
            self.__textUI.set(unicode(resp[1:]))
        else:
            self.__textUI.set(unicode(': ' +self.__textUI.get() + '\n: ' + resp))
                
        appuifw.note(u'Translate', 'conf')
####################################################################################### </BabelFishUI>

if __name__ == '__main__':
    
    BabelFishUI()

Python - eggs

1)

import __hello__

2)

from __future__ import braces

PyS60 - Gallery Thumbnail Ver. 2

// Versione riveduta e corretta di Gallery Thumbnail postata da korakot ^_^

import appuifw
import e32
import graphics
import key_codes
import os

class FlickrS60Error(Exception): pass

class FlickrS60Thumb:

	def __init__(self, path):

		self.path = unicode(path)
		self.listFile = []
		self.ldivx = 0
		self.ldivy = 0
		self.lock = e32.Ao_lock()
		self.canvas = None
		self.img = graphics.Image.new((176, 144))
		self.img_tmp = graphics.Image.new((42, 36))
		self.x, self.y = 0, 0
		self.p = 0
		self.pages = 0
		self.currpages = 0
		self.mpath = 0

	def OnRun(self):

		appuifw.app.exit_key_handler = self.lock.signal
	
		self._createList()
		
		self.canvas = appuifw.Canvas(redraw_callback=self.OnUpdate)
		appuifw.app.body = self.canvas

		self.canvas.bind(key_codes.EKeyRightArrow, lambda: self.move(1, 0))
		self.canvas.bind(key_codes.EKeyLeftArrow, lambda: self.move(-1, 0))
		self.canvas.bind(key_codes.EKeyUpArrow, lambda: self.move(0, -1))
		self.canvas.bind(key_codes.EKeyDownArrow, lambda: self.move(0, 1))
		self.canvas.bind(key_codes.EKeySelect, self.IMG)

		self._drawIMG()
		
		self.lock.wait()

	def OnUpdate(self, rect):

		self.canvas.blit(self.img)
		self.canvas.rectangle([(self.p+(42*self.x), 36*self.y), (self.p+(42*self.x)+42, (36*self.y)+36)], width=2, outline=0x123456)

	def move(self, x, y):

		self.x = (self.x+x)%4
		self.y = (self.y+y)

		if x == 1: self.p = (self.p+2)%8
		if x == -1: self.p = (self.p-2)%8

		if self.y == 4:
			if self.currpages < self.pages-1:
				self.y = 0
				self.currpages += 1
				self._drawIMG(start=self.currpages)
			else:
				self.y = 3
			
		if self.y == -1:
			if self.currpages > 0:
				self.y = 3
				self.currpages -= 1
				self._drawIMG(start=self.currpages)
			else:
				self.y = 0
	
		self.mpath = (4*self.y + self.x)+(16*self.currpages)
		
		self.OnUpdate(None)
	
	def IMG(self):

		try:
			m = self.listFile[self.mpath].replace('_PalbTN\\', '')
			appuifw.Content_handler().open(m)
		except:
			pass
		
	def _drawIMG(self, start=0):

		self.img.clear(0xffffff)
		z = 0
		
		for id in range(start*16, (start+1)*16):
			j, i = divmod(id-(start*16), 4)
			try:
				self.img_tmp.load(self.listFile[id])
				self.img.blit(self.img_tmp, target=(z+(42*i)+(z+1), 36*j))
				z = (z+1)%4
			except:
				break

		self.OnUpdate(None)

	def _createList(self):

		try:
			for id in os.listdir(self.path):
				self.listFile.append(self.path + id)

			self.ldivx, self.ldivy = divmod(len(self.listFile), 16)

			self.pages = self.ldivx
			if self.ldivy <> 0: self.pages += 1
		except:
			raise FlickrS60Error('Errore nella creazione della lista.')

if __name__ == '__main__':

	FlickrS60Thumb('E:\\Images\\_PalbTN\\').OnRun()

Python - Get id3 from MP3 File

// Cattura i tag id3 da un file MP3

def getID3(filename):
    fp = open(filename, 'r')
    fp.seek(-128, 2)

    fp.read(3) # TAG iniziale
    title   = fp.read(30)
    artist  = fp.read(30)
    album   = fp.read(30)
    anno    = fp.read(4)
    comment = fp.read(28)

    fp.close()

    return {'title':title, 'artist':artist, 'album':album, 'anno':anno}
« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS