X-Git-Url: http://git.maemo.org/git/?p=remotepc;a=blobdiff_plain;f=pcremote-client-n8x0%2Fedje_objects.py;fp=pcremote-client-n8x0%2Fedje_objects.py;h=1cd52445a28fd44da88b5bcfaab7fd08dacbd60a;hp=0000000000000000000000000000000000000000;hb=8eeea3225c010dea378cdc71c4e91294e04a6e9c;hpb=e8447209e336f2a6845027f50b84cc914fa2c796 diff --git a/pcremote-client-n8x0/edje_objects.py b/pcremote-client-n8x0/edje_objects.py new file mode 100755 index 0000000..1cd5244 --- /dev/null +++ b/pcremote-client-n8x0/edje_objects.py @@ -0,0 +1,359 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# **************************************************************************** +# Copyright (c) 2008 INdT/Fucapi. +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. + +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see . + +# ============================================================================ +# Project Name :PC Remote +# Author :André Portela +# Email :andre_portela_@hotmail.com +# Version :1.0 +# Module :main +# Class :PCRemote custom Edje object with it's own call backs for the +# main screen +# ============================================================================ + +import thread +import ecore +import ecore.evas +import evas.decorators +import edje +import edje.decorators +import time +from connection.iconnection import Iconnection +from kineticlist import * + +class EvasCanvas(object): + + def __init__(self, fullscreen, engine, size): + #f = ecore.evas.SoftwareX11 + self.evas_obj = engine(w=size[0], h=size[1]) + self.evas_obj.callback_delete_request = self.on_delete_request + self.evas_obj.callback_resize = self.on_resize + + self.evas_obj.title = "PCRemote" + self.evas_obj.name_class = ('PC Remote', 'main') + self.evas_obj.fullscreen = fullscreen + self.evas_obj.size = size + self.evas_obj.show() + + def on_resize(self, evas_obj): + x, y, w, h = evas_obj.evas.viewport + size = (w, h) + for key in evas_obj.data.keys(): + evas_obj.data[key].size = size + + def on_delete_request(self, evas_obj): + ecore.main_loop_quit() + + def show(self): + self.evas_obj.show() + +class EdjeObject(edje.Edje): + + def __init__(self, canvas_class, file, group='main',name='edje'): + self.canvas_class = canvas_class + self.x11 = canvas_class.evas_obj + self.canvas = self.x11.evas + edje.Edje.__init__(self, self.canvas, file = file, group = group) + self.size = self.canvas.size + self.x11.data[name] = self + +class MainScreen(EdjeObject): + + def __init__(self, canvas, file, group, name, connection): + EdjeObject.__init__(self, canvas, file = file, group = group,name = name) + + self.file = file + self.on_key_down_add(self.key_down_cb, self.x11) + self.sock_address = None + #flag that sync the discovery device's thread + self.flag = False + #flag that sync the connecting device's thread + self.connecting_flag = False + #lista de dispositivos descobertos + self.lista_dispositivos = [] + #objeto que cria a conexao bluetooth + self.conexao = connection + self.kineticlist = False + #portela mock object + self.lista_teste = ['Andre Portela', 'Juliana Dias', 'Victor Hugo', 'Lucina Dias', 'Rosa Dias', 'James Italiano', 'Nona Izvi', 'Fergus Mao', 'Mauricio Brilhante', 'Edward Ordonez', 'Brankinhu', 'Banco Real', 'Banco Itaú', 'ABN-AMRO BANK'] + + def key_down_cb(self, bg, event, ee): + k = event.key + if k == "Escape": + ecore.main_loop_quit() + elif k == "F6": + ee.fullscreen = not ee.fullscreen + elif k == "F8": + print "-" + elif k == "F7": + print "+" + + def mkKineticList(self): + #kinetic list (the item values are tied with the part "item_background" of the "list_item" group) + #self.kineticlist = KineticList(self.canvas, file=self.file, item_width=407, item_height=38, father=self) + self.kineticlist = KineticList(self.canvas, file=self.file, item_height=57, father=self) + self.kineticlist.freeze() + #portela - test kinetic list with several devices + #for item in self.lista_teste: + #populates the list with the device's names + for item in self.lista_dispositivos: + self.kineticlist.row_add(item) + #reorganize and draw the list + self.kineticlist.thaw() + #embed the list in the edje object + self.part_swallow("list", self.kineticlist); + + @edje.decorators.signal_callback("connect_to","choice") + def connect_to(self, emission, source): + self.sock_address = self.part_text_get(source) + #flag that sync the connecting device's thread + self.connecting_flag = False + self.signal_emit("start","device_connect") + thread.start_new_thread(MainScreen.threaded_connection,(self,)) + + def threaded_connection(self): + self.conexao.create_socket('l2cap') + print 'connecting to: %s' % self.sock_address + self.conexao.set_address(self.conexao.bt_find_device_address_by_name(self.sock_address)) + self.conexao.set_port(0x1001) + self.conexao.connect() + self.connecting_flag = True + + @edje.decorators.signal_callback("connecting","device") + def connecting_check(self, emission, source): + if self.connecting_flag: + self.connecting_flag = False + self.signal_emit("stop","device_connect") + #we are sending a signal to main edje (there is time to animate the device locking) + self.signal_emit("begin","init") + + @edje.decorators.signal_callback("animation_still_loading", "loading") + def still_loading_cb(self, emission, source): + if self.flag: + self.flag = False + self.signal_emit("program,stop","loading") + if self.lista_dispositivos != []: + self.mkKineticList() + else: + self.no_device_found() + + @edje.decorators.signal_callback("animation_sair_ended", "sair") + def saida(self, signal, source): + ecore.main_loop_quit() + + @edje.decorators.signal_callback("animation_rastrear_ended", "rastrear") + def rastrear_key_down(self, signal, source): + thread.start_new_thread(MainScreen.rastrear_dispositivos,(self,None)) + + @edje.decorators.signal_callback("program,start", "novodevice") + def search_devices_again(self, signal, source): + self.part_unswallow(self.kineticlist) + del self.kineticlist + MainScreen.rastrear_key_down(self, None, None) + + def rastrear_dispositivos(self,arg): + try: + self.lista_dispositivos = self.conexao.bt_find_devices_only_names() + except: + self.lista_dispositivos = [] + self.flag = True + + def no_device_found(self): + self.signal_emit("program,start","no_device") + +class TabletScreen(EdjeObject): + + def __init__(self, canvas, file, group,name, connection): + EdjeObject.__init__(self, canvas, file = file, group = group,name = name) + self.on_key_down_add(self.key_down_cb, self.x11) + #emitt events only if the mouse is inside the touch object area + (self.part_object_get('touch')).pointer_mode_set(evas.EVAS_OBJECT_POINTER_MODE_NOGRAB) + #assign the mouse_move_cb method as a mouse move callback for the touch part of the edje object + (self.part_object_get('touch')).on_mouse_move_add(self.mouse_move_cb) + #self.on_mouse_move_add(TabletScreen.mouse_move_cb) + self.sock = connection + #this flag indicates either the user are grabing something or not on the target + self.drag_flag = False + #this float indicates the wich the method left_click_down was called, and will be + #calculated against lcu_time in left_click_up method + self.lcd_time = 0.0 + #tecla alt + self.alt_flag = False + #tecla shift + self.iso_shift_flag = False + #lista de aliases das teclas de comando Alt+F(x) + #self.fletters = ['p', 'q', 'w', '', 'r', '', '', '', '', 'o'] + self.keys_dict = {'q':1, 'w':2, 'e':3, 'r':4, 't':5, 'y':6, 'u':7, 'i':8, 'o':9, 'p':0, \ + 'a':'Shift_L+1', 's':'', 'd':'Shift_L+2', 'f':'Shift_L+3', 'g':'backslash', \ + 'h':'slash', 'j':'Shift_L+9', 'k': 'Shift_L+0', 'l':'Shift_L+8', '\'':'Shift_L+slash',\ + 'z':'', 'x':'Shift_L+6', 'c':'', 'v':'Shift_L+5', 'b':'Shift_L+7', 'n':'Shift_L+4', \ + 'm':'', ';':'', '-':'Shift_L+minus', '+':'equal'} + + @edje.decorators.signal_callback('mouse,down,1', 'tablet_bt-L_area') + def left_click_down(self, signal, source): + self.lcd_time = time.time() + #if the user are grabing something, release it + if self.drag_flag: + self.drag_flag = False + self.sock.send_message("Mouse:#left_click") + + @edje.decorators.signal_callback('mouse,up,1', 'tablet_bt-L_area') + def left_click_up(self, signal, source): + lcu_time = time.time() + #threshold of 0.5 seconds to grab something on the target + elapsed_time = lcu_time - self.lcd_time + if elapsed_time < 0.5: + #do a simple click + self.sock.send_message("Mouse:#left_click") + self.sock.send_message("Mouse:#left_click") + else: + #do mouse grab + self.sock.send_message("Mouse:#left_click") + self.drag_flag = True + + @edje.decorators.signal_callback('mouse,up,1', 'tablet_bt-R_area') + def rigth_click(self, signal, source): + self.sock.send_message("Mouse:#right_click") + self.sock.send_message("Mouse:#right_click") + + def key_down_cb(self, bg, event, ee): + k = event.key + print k + if k == "Escape": + self.sock.send_message("Keyboard:Escape") + elif k == "F6": + ee.fullscreen = not ee.fullscreen + elif k == "F8": + self.sock.send_message("Keyboard:Up") + elif k == "F7": + self.sock.send_message("Keyboard:Down") + elif k == "Return": + self.alt_flag = True + elif k == "ISO_Level3_Shift": + self.iso_shift_flag = True + else: + if self.alt_flag: + #if k in self.fletters: + # self.sock.send_message("Keyboard:Alt+F%s" % (self.fletters.index(k))) + # self.alt_flag = False + #elif k == 'space': + # self.sock.send_message("Keyboard:Alt+Space") + # self.alt_flag = False + #else: + # self.alt_flag = False + if self.keys_dict.has_key(k) and isinstance(self.keys_dict[k], int): + self.sock.send_message("Keyboard:Alt_L") + self.sock.send_message("Keyboard:F%s" % (self.keys_dict[k])) + self.alt_flag = False + elif k == 'space': + self.sock.send_message("Keyboard:Alt_L") + self.sock.send_message("Keyboard:space") + self.alt_flag = False + else: + self.alt_flag = False + #else: + #self.sock.send_message("Keyboard:%s" % k) + elif self.iso_shift_flag: + if self.keys_dict.has_key(k) and self.keys_dict[k] and isinstance(self.keys_dict[k], str): + lst = self.keys_dict[k].split('+') + for cmd in lst: + self.sock.send_message("Keyboard:%s" % cmd) + self.iso_shift_flag = False + elif self.keys_dict.has_key(k) and self.keys_dict and isinstance(self.keys_dict[k], int): + self.sock.send_message("Keyboard:%s" % self.keys_dict[k]) + self.iso_shift_flag = False + else: + self.iso_shift_flag = False + else: + self.sock.send_message("Keyboard:%s" % k) + + def mouse_move_cb(self, part, event): + x, y = event.position.output[0], event.position.output[1] + self.sock.send_message("Mouse:"+str(x)+","+str(y)) + +class SlideScreen(EdjeObject): + + def __init__(self, canvas, file, group,name, connection): + EdjeObject.__init__(self, canvas, file = file, group = group,name = name) + self.on_key_down_add(self.key_down_cb, self.x11) + #emitt events only if the mouse is inside the touch object area + (self.part_object_get('touch')).pointer_mode_set(evas.EVAS_OBJECT_POINTER_MODE_NOGRAB) + #assign the mouse_move_cb method as a mouse move callback for the touch part of the edje object + (self.part_object_get('touch')).on_mouse_move_add(self.mouse_move_cb) + #self.on_mouse_move_add(TabletScreen.mouse_move_cb) + self.sock = connection + #this flag indicates either the user are grabing something or not on the target + self.drag_flag = False + #helps to coordenate presentation + self.keyboard_flag = True + #this float indicates the wich the method left_click_down was called, and will be + #calculated against lcu_time in left_click_up method + self.lcd_time = 0.0 + + @edje.decorators.signal_callback('mouse,down,1', 'slide_bt-left_area') + def left_click_down(self, signal, source): + if self.keyboard_flag: + self.lcd_time = time.time() + #if the user are grabing something, release it + if self.drag_flag: + self.drag_flag = False + self.sock.send_message("Mouse:#left_click") + + @edje.decorators.signal_callback('mouse,up,1', 'slide_bt-left_area') + def left_click_up(self, signal, source): + if self.keyboard_flag: + lcu_time = time.time() + #threshold of 0.5 seconds to grab something on the target + elapsed_time = lcu_time - self.lcd_time + if elapsed_time < 0.5: + #do a simple click + self.sock.send_message("Mouse:#left_click") + self.sock.send_message("Mouse:#left_click") + else: + #do mouse grab + self.sock.send_message("Mouse:#left_click") + self.drag_flag = True + else: + self.sock.send_message("Keyboard:%s" % "Left") + + @edje.decorators.signal_callback('mouse,up,1', 'slide_bt-right_area') + def rigth_click(self, signal, source): + if self.keyboard_flag: + self.sock.send_message("Mouse:#right_click") + self.sock.send_message("Mouse:#right_click") + else: + self.sock.send_message("Keyboard:%s" % "Right") + + def key_down_cb(self, bg, event, ee): + k = event.key + print k + if k == "Escape": + self.sock.send_message("Keyboard:Escape") + elif k == "F6": + self.keyboard_flag = not self.keyboard_flag + self.sock.send_message("Keyboard:F5") + elif k == "F8": + self.sock.send_message("Keyboard:Up") + elif k == "F7": + self.sock.send_message("Keyboard:Down") + else: + self.sock.send_message("Keyboard:%s" % k) + + def mouse_move_cb(self, part, event): + x, y = event.position.output[0], event.position.output[1] + self.sock.send_message("Mouse:"+str(x)+","+str(y))