jueves, 6 de enero de 2011

Application that displays the coordinates of cell phone in Desktop with google maps

In this post I use 2 previous articles about create web browser and howto capture cell phone location.


The idea is capture the information of GPS from cell phone and display location in application with gtk, webkit and python with Google Maps.


The glade interface shown below.


It's actually the same application web browser but, I remove the text entry and button "go ".


Below the code:




#!/usr/bin/env python2.6
# -*- coding: utf-8 -*-
"""
Nombre:Geolocalizacion
Descripción: Program that capture the location of cell phone
     shown in google maps on the Linux desktop.
Versión:0.1
Licence:GPLv3
Author: Ernesto Crespo
Email: ecrespo@gmail.com
"""
#Import gtk and webkit


import gtk
import webkit
#Import android and time
import android
from time import sleep


    
#class App
class App:
    def __init__(self):
        #init function
        #Binding glade file with Builder
        self.glade_file = "geolocalizcion.glade"
        self.glade = gtk.Builder()
        self.glade.add_from_file(self.glade_file)
        #Bind window geo
        self.window = self.glade.get_object('geo')
        #Bind button exit
        self.exit = self.glade.get_object('salir')
        #Bind scrolledwindow
        self.scrolledwindow1 = self.glade.get_object('scrolledwindow1')
        #
        #Linking destroy event with function
        self.window.connect("destroy",self.on_geo_destroy)
        #Linking clicked event with function
        self.exit.connect('clicked', self.on_salir_clicked)
        #Open google maps site
        #create Object webview
        self.webview = webkit.WebView()
        #Add webview in scrolledwindow
        self.scrolledwindow1.add(self.webview)
        #Capture location
        tupla = localizacion()
        #Open  google maps URL win  longitude and latitude
        self.__go("http://maps.google.com/maps?q=%s,%s" %tupla)
        
        #Show window
        self.window.show_all()
    
    
    def __go(self,url):
        #Open URL
        self.webview.open(url)
        
        
    def on_geo_destroy(self,*args):
        #close application
        gtk.main_quit()
    
    def on_exit_clicked(self,*args):
     #close application
        gtk.main_quit()
    
    
    def main(self):
        #Start application
        gtk.main()
        
    
def localizacion():
    
        #create android object
        droid = android.Android()
        #start location
        droid.startLocating()
        #wait 15 seconds
        sleep(15)
        #capture latitude and longitude
        latitude = droid.readLocation().result["network"]["latitude"]
        longitude = droid.readLocation().result["network"]["longitude"]
        #Stop location
        droid.stopLocating()
        #return latitude and longitude
        return (latitude,longitude)


if __name__ == '__main__':
    app = App()
    app.main()



The figure showing the app running with google maps site.

Create a basic web browser with python+webkit+gtk

Returning to the programming with python, glade and gtknow explain how to make a simple browser using python webkit.

This post is based on Marcelo's blog article, I create interface with glade.



The figure shows the GUI application.


The application simply has a EntryText, the URL where you can enter to load the page when push button go, the page is loaded into the frame with sliders in the center of the interface and has a button  exit. The default is to load a page to start the application.

The application code is shown below:



#!/usr/bin/env python
# -*- coding: utf-8 -*-
#Import gtk and webkit



import gtk
import webkit



    
#class App
class App:
    def __init__(self):
     #function init 
        #bind glade file with Builder object
        self.glade_file = "browser.glade"
        self.glade = gtk.Builder()
        self.glade.add_from_file(self.glade_file)
        #Binding  window with browser
        self.window = self.glade.get_object('browser')
        #Button exit
        self.exit = self.glade.get_object('bexit')
        #Button browser
        self.go = self.glade.get_object('browse')
        #EntryText URL
        self.link = self.glade.get_object('url')
        #Scrolledwindows where you can see a site
        self.scrolledwindow1 = self.glade.get_object('scrolledwindow1')
        #
        #Linking destroy browser with function
        self.window.connect("destroy",self.on_browser_destroy)
        #Linking clicked exit button
        self.exit.connect('clicked', self.on_bexit_clicked)
        #Linking clicked browse button
        self.go.connect('clicked',self.on_browse_clicked)
        #Linking activate with URL entrytext
        self.link.connect('activate',self.on_url_activate)
        #Open  default site
        #Instant class webview 
        self.webview = webkit.WebView()
        #Add webview in scrolledwindow
        self.scrolledwindow1.add(self.webview)
        #Open default page
        self.__go("http://www.debian.org")
        
        #Show window 
        self.window.show_all()
    
    
    def on_url_activate(self,*args):
        #catch url to open page
        url = "http://" + self.enlace.get_text()
        self.__go(url)



    
    def __go(self,url):
        self.webview.open(url)
        
        
    def on_browser_destroy(self,*args):
        #close application
        gtk.main_quit()
    
    def on_bexit_clicked(self,*args):
     #close application
        gtk.main_quit()
    
    def on_browse_clicked(self,*args):
        #Open site
        url = "http://" + self.link.get_text()
        self.__go(url)
    
    def main(self):
     #star application
        gtk.main()


















if __name__ == '__main__':
    app = App()
    app.main()




The following figure shows the browser.



lunes, 3 de enero de 2011

2010

The year just ended had its joys and sorrows, and most important is that my father is no longer with us. The greatest happiness was being with the person who I want in Valencia coincidences of life, but for 3 days, enjoy hanging out with her and just hope that this year will be a comprehensive approach ... 


  About the blog almost repeat the same number of articles written in 2009 by only one not equal the figure.


I had promised to write 48 articles but for various reasons could not meet that goal, well, this year will try to meet that goal, apart from writing in Spanish will begin to write in English on my other blog to leave this for only items Castilian, so I translate the articles will be playing old that are still not updated and updated and translated.

I'll keep writing about android and python, I'll finish the series onpython + gtk + glade and start writing about PyQt. Also look for thetime to write about Django, I will continue writing on packaging for Debian python-oriented, some things about network managementand security with Linux.
Now for the summary of the blog: 

  • In 2010 I wrote 35 articles (36 would be this article.) 
  • The month when more people visited the blog was in December with 1721 visits.
  • The most read article was python on Android with 665 hits, followed by basic command adb (Android) with 317 visits and third graphics application development with python + gtk + glade with 235 visits. 
  • There are 3 important references that have the blog, the wiki for Python, wiki SL4A tutorials found on google code. 
  • Countries where more people visit the blog are: Spain 2657, Venezuela 1195, Argentina 949, Mexico 828, U.S. 413, Colombia 363, Chile 283, Germany 201, Netherlands 186, Peru 133, with some connections in Russia China, South Korea, Japan, United Kingdom, France, etc. 

Well, the month will initiate the technical articles I send you a happy new year to all who follow me, thank you for it !!!!.