X-Git-Url: http://git.maemo.org/git/?p=remotepc;a=blobdiff_plain;f=pcremote-client-n8x0%2Fdebian%2Fpcremote-client%2Fusr%2Fshare%2Fpcremote-client%2Fedje_objects.py;fp=pcremote-client-n8x0%2Fdebian%2Fpcremote-client%2Fusr%2Fshare%2Fpcremote-client%2Fedje_objects.py;h=a60e66347c83534807b25006f69eea0a22f2dfd4;hp=0000000000000000000000000000000000000000;hb=8eeea3225c010dea378cdc71c4e91294e04a6e9c;hpb=e8447209e336f2a6845027f50b84cc914fa2c796 diff --git a/pcremote-client-n8x0/debian/pcremote-client/usr/share/pcremote-client/edje_objects.py b/pcremote-client-n8x0/debian/pcremote-client/usr/share/pcremote-client/edje_objects.py new file mode 100755 index 0000000..a60e663 --- /dev/null +++ b/pcremote-client-n8x0/debian/pcremote-client/usr/share/pcremote-client/edje_objects.py @@ -0,0 +1,320 @@ +#!/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 + self.key_flag = False + + @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("Tablet:#stop") + self.sock.close() + ecore.main_loop_quit() + 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.sock.send_message("Keyboard:Alt+F1") + elif k == "ISO_Level3_Shift": + self.sock.send_message("Keyboard:Alt+F2") + 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("Slideshow:#stop") + self.sock.close() + ecore.main_loop_quit() + 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))