Тема: Скрипт на Python, активирующий портретный режим экрана(вращение)
Появилось видео и скрипт для активации изменения режимов экрана(вращение) - картинка крутиться вокруг своей оси.
its just a dirty hack so far
Что нужно, чтобы такое получить:
Создаём и устанавливаем файл rotate.py - можно и скачать, смотрим прикреплённые файлы, если вы решили скачать файл, то переходим сразу к пункту 4
1. в обычном текстовом редакторе, только сохраняем с окончанием .py, создаём файл
2. Копируем ниже приведённый текст и вставляем в файл:
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)
3. Сохраняем документ, не забываем изменить тип на все файлы и вписать название rotate.py
4. Копируем на N900 в корневую папку / - (root dir /)
5. В X-терминале пишем:
root [enter]
cd / [enter]
python rotate.py [enter]
6. Окно терминала переводим в бэкграунд и пусть оно там висит (minimize window and rotate phone!)
Как предложил Mike, можно немного модернизировать скрипт:
Можно еще во все строки начинающиеся с print добавить # - т.е. закоментировать их
и потом запускать как:root [enter]
cd / [enter]
nohup python rotate.py &[enter]и можно выходить из терминала - приложение останется в памяти.
Источник:
nokian900applications.com
talk.maemo.org