python para maemo
DESCRIPTION
Slides usados no treinamento de Python para Maemo ministrado pela Triveos Tecnologia Ltda (http://triveos.com) em parceria com o Instituto Nokia de Tecnologia (INdT)TRANSCRIPT
![Page 1: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/1.jpg)
Python para MaemoOsvaldo Santana [email protected]
Baseado nas apresentações de:Lauro Moura <[email protected]>Raul Fernandes <[email protected]>
![Page 2: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/2.jpg)
Instituto Nokia de Tecnologia
• Instituição sem fins lucrativos, fundada pela Nokia em 2002
• Investimentos da lei de informática
• Escritórios em Manaus, Brasília e Recife
• Pesquisa e Desenvolvimento em Mecânica e Produtos Eletrônicos, Software, Multimídia, Telecomunicações e em Operações e Logística
![Page 3: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/3.jpg)
Osvaldo Santana Neto
• Sócio fundador da Triveos Tecnologia Ltda.
• Trabalhou para as empresas: Conectiva (Mandriva), Instituto Nokia de Tecnologia, Objective Solutions, Haxent, ...
• Responsável pela criação do projeto Python para Maemo no INdT em 2005
• http://www.pythonologia.org/
![Page 4: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/4.jpg)
Requisitos
• Conhecimentos em Python
• Conhecimentos em Linux
• VMWare
• Imagem Maemo SDK obtida em:http://maemovmware.garage.maemo.org/
![Page 5: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/5.jpg)
Desejável
• Conhecimentos de PyGTK
• Um Internet Tablet (N770, N800, N810)
![Page 6: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/6.jpg)
Internet Tablets
Dispositivos portáteis voltados para uso da Internet.
![Page 7: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/7.jpg)
Nokia N800
• OMAP 2420
• ARM11 330MHz
• 800x480x16
• WLAN, Bluetooth, USB
• Câmera VGA
• 2x cartões SD
![Page 8: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/8.jpg)
Nokia N810• OMAP 2420
• ARM11 400MHz
• 800x480x16
• WLAN, Bluetooth, USB
• Câmera VGA
• 1x cartão miniSD
• GPS
• Teclado
![Page 9: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/9.jpg)
• Plataforma desenvolvida pela Nokia para equipar a sua linha de Internet Tablets
• Baseada no Debian Linux
• Utiliza uma série de componentes conhecidos no universo do Software Livre
![Page 10: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/10.jpg)
Ambiente de Desenvolvimento
• Scratchbox
• Ambiente para cross-compiling
• SDK_X86 - arquitetura ‘host’
• SDK_ARMEL - arquitetura do dispositivo
• Xephyr
• Servidor X para emulação da interface gráfica
![Page 11: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/11.jpg)
Iniciando o ambiente
• Entrando no Scratchbox:
•/scratchbox/login ou
• Iniciando os serviços:
•af-sb-init.sh start
• Executando aplicações gráficas:
•run-standalone.sh programa
![Page 12: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/12.jpg)
A primeira impressão...
![Page 13: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/13.jpg)
Python para Maemo
• Principal alternativa à linguagem C para desenvolvimento na plataforma
• Bastante difundida no mundo do Software Livre
• Mantido pelo INdT de Recife
• http://pymaemo.garage.maemo.org
![Page 14: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/14.jpg)
Projetos em PythonCanola
![Page 15: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/15.jpg)
Projetos em PythonCarman
![Page 16: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/16.jpg)
Bibliotecas Python• Gerais
• PyGTK/Gobject
• D-BUS
• GStreamer
• Bluez
• Pyrex
• PIL
• Gnome VFS/GConf
• Específicas Maemo
• Hildon
• LibOSSO
• OSSO-Addressbook
![Page 17: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/17.jpg)
Easy
• Facilita ainda mais o desenvolvimento para Maemo
• Desenvolvido pela UFCG com apoio do INdT
• Incorpora a biblioteca Eagle para desenho de Interfaces gráficas
• http://easy.garage.maemo.org/
![Page 18: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/18.jpg)
Vamos começar...
![Page 19: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/19.jpg)
Aplicação de exemplo
• Lista de tarefas
• Adicionar Tarefas
• Remover Tarefas
• Editar Tarefas
• Marcá-las como ‘prontas’
• Gravar as informações automaticamente
![Page 20: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/20.jpg)
Lembretes importantes
• Use sempre:
•python2.5• O easy não vem instalado por padrão
• Adicione...deb http://repository.maemo.org/extras-devel diablo free non-free
• ... no /etc/apt/sources.list•apt-get install easy
![Page 21: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/21.jpg)
Módulos & Armazenamento
#!/usr/bin/env python2.5
import shelvefrom easy import ui
storage = shelve.open("tasks.dat", 'c')
![Page 22: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/22.jpg)
Definindo a Tabela
table = ui.Table( id="todo_table", headers=("Done", "Description"), types=(bool, str), editable=True, data_changed_callback=change_task,)
![Page 23: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/23.jpg)
Manipulando a tabela
def change_task(app, table, data): global storage
key, task = data
if task is None: del storage[str(key)] else: storage[str(key)] = tuple(task) storage.sync()
![Page 24: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/24.jpg)
Tela principal
ui.App( id="todo_app", title="To Do List", center=(table,), bottom=( ui.Button( id="quit_button", label="_Quit", expand_policy=ui.ExpandPolicy.All(), callback=exit)))
![Page 25: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/25.jpg)
Fechar a aplicação
def exit(app, widget): storage.close() app.close()
![Page 26: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/26.jpg)
Populando a tabela
def populate_table(): global storage global table
ks = int(k) for k in storage.keys() for k in sorted(ks): table.append( storage[str(k)] )
![Page 27: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/27.jpg)
Rodando
if __name__ == "__main__": populate_table() ui.run()
![Page 28: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/28.jpg)
Hora de executar...
SDK_X86:~> run-standalone.sh python2.5 tasks.py
![Page 29: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/29.jpg)
... e pronto.
![Page 30: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/30.jpg)
Portando uma aplicação
![Page 31: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/31.jpg)
A Aplicação
Desktop
![Page 32: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/32.jpg)
A Aplicação
Maemo sem adaptação...
![Page 33: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/33.jpg)
Passo a passo do porte
• Substituir gtk.Window(gtk.WINDOW_TOPLEVEL) por hildon.Window()
• Fazer ‘reparent’ dos menus e toolbars
• Substituir diálogos GTK+ pelos do Hildon
• Adaptações para espaço reduzido na tela
![Page 34: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/34.jpg)
Substituindo a Window@@ -26,6 +26,7 @@ pygtk.require('2.0') import gtk import gtk.gdk+import hildon import os import sys, getopt import ConfigParser@@ -478,7 +479,7 @@ """ # Create interface- self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)+ self.window = hildon.Window() self.update_title() icon_path = self.find_path('mirage.png') try:
![Page 35: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/35.jpg)
Novos pais para o Menu
@@ -498,7 +498,10 @@ self.refresh_recent_files_menu() self.window.add_accel_group(self.UIManager.get_accel_group()) self.menubar = self.UIManager.get_widget('/MainMenu')- vbox.pack_start(self.menubar, False, False, 0)+ self.menu = gtk.Menu()+ for item in self.menubar:+ item.reparent(self.menu)+ self.window.set_menu(self.menu) self.set_slideshow_sensitivities() self.toolbar = self.UIManager.get_widget('/MainToolbar') vbox.pack_start(self.toolbar, False, False, 0)
![Page 36: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/36.jpg)
A barra de ferramentas
@@ -504,7 +504,7 @@ self.window.set_menu(self.menu) self.set_slideshow_sensitivities() self.toolbar = self.UIManager.get_widget('/MainToolbar')- vbox.pack_start(self.toolbar, False, False, 0)+ self.window.add_toolbar(self.toolbar) self.layout = gtk.Layout() self.vscroll = gtk.VScrollbar(None) self.vscroll.set_adjustment(self.layout.get_vadjustment())
![Page 37: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/37.jpg)
O diálogo correto
@@ -1353,7 +1353,7 @@ self.save_image_now(self.currimg_name, gtk.gdk.pixuf_... def save_image_as(self, action):- dialog = gtk.FileChooserDialog(title=_("Save As"),action=gtk.FILE_CHOOSER_ACTION_SAVE,buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_SAVE,gtk.RESPONSE_OK))+ dialog = hildon.FileChooserDialog(self.window,gtk.FILE_CHOOSER_ACTION_SAVE) dialog.set_default_response(gtk.RESPONSE_OK) filename = os.path.basename(self.currimg_name) filetype = None
![Page 38: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/38.jpg)
Versão final
![Page 39: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/39.jpg)
Distribuição
Pacotes Debian
distutils
Progama &Biblioteca Python
![Page 40: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/40.jpg)
Ajustando os arquivos
setup.py@@ -23,7 +23,7 @@ ext_modules = [Extension('imgfuncs', ['imgfuncs.c'])], scripts = ['mirage'], data_files=[('share/mirage', ['README', 'COPYING',...- ('share/applications', ['mirage.desktop']),+ ('share/applications/hildon', ['mirage.desktop']), ('share/pixmaps', ['mirage.png']), ('share/locale/ru/LC_MESSAGES', ['locale/ru/LC_M... ('share/locale/pl/LC_MESSAGES', ['locale/pl/LC_M...
![Page 41: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/41.jpg)
Arquivo .desktop
mirage.desktop@@ -1,10 +1,10 @@ [Desktop Entry] Name=Mirage Comment=A fast GTK+ Image Viewer-Exec=mirage %U+Exec=mirage Terminal=false Type=Application-Icon=mirage.png+Icon=mirage Categories=GTK;Application;Graphics; Version=0.8.3 Encoding=UTF-8
![Page 42: Python Para Maemo](https://reader035.vdocuments.pub/reader035/viewer/2022062512/5537fbe54a7959016b8b469b/html5/thumbnails/42.jpg)
Mais Informações
• http://www.maemo.org
• http://pymaemo.garage.maemo.org
• http://easy.garage.maemo.org
• http://www.pygtk.org
• http://code.google.com/p/eagle-py
• http://openbossa.indt.org/canola
• http://openbossa.indt.org/carman