Archivo

Entradas Etiquetadas ‘scripts’

Script para activar el modo portrait

Lunes, 8 de Febrero de 2010 6 comentarios

En nokiaspace.net han publicado un script en python para que mientras se está ejecutando cambien la forma de ver las aplicaciones en función de la posición del terminal, es decir, si está ejecutándose el script y estamos viendo la agenda, la aplicación cambiará de modo horizontal a vertical en función de la posición del teléfono.
Para crear el script podéis copiar el código que hay más abajo o descargar el fichero con el programa: rotate.py

from ctypes import *
import os
import sys
import time
from math import atan2
from pprint import pprint

xlib = cdll.LoadLibrary(“libX11.so.6″)
rr = cdll.LoadLibrary(“libXrandr.so.2″)

def get_rotation():
f = open(“/sys/class/i2c-adapter/i2c-3/3-001d/coord”, ‘r’ )
coords = [int(w) for w in f.readline().split()]
f.close()
return coords

print get_rotation()

def rotate(angle):
rr.XRRSetScreenConfigAndRate(display,config,root,size,angle,rate,timestamp)

display = xlib.XOpenDisplay(os.getenv(“DISPLAY”))
screen = xlib.XDefaultScreen(display)
root = xlib.XDefaultRootWindow(display, screen)

class XRRScreenConfiguration(Structure):
pass

gsi = rr.XRRGetScreenInfo
gsi.restype = POINTER(XRRScreenConfiguration)
config = gsi(display, root)

current_time = c_ulong()
rr.XRRTimes.restpye = c_ulong
timestamp = rr.XRRTimes(display, screen, byref(current_time))

xccr = rr.XRRConfigCurrentRate
xccr.restype = c_int
rate = xccr(config)

rotation = c_ushort()
size = rr.XRRConfigCurrentConfiguration(config, byref(rotation))

while True:
[x,y,z] = get_rotation()
print x,y,z
if y < -500: rotate(1) elif y > 500:
rotate(4)

elif x < -500: rotate(2) elif x > 500:
rotate(8)

time.sleep(1)

Para ejecutarlo sólo tenéis que abrir el xterminal y desde el directorio donde lo habéis guardado teclear: python rotate.py


Únete a nuestra página en Facebook.


Entradas relacionadas

Categories: Software Tags:
Get Adobe Flash playerPlugin by wpburn.com wordpress themes