2 # -*- coding: utf-8 -*-
4 # ****************************************************************************
5 # Copyright (c) 2008 INdT/Fucapi.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Lesser General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # ============================================================================
20 # Project Name :PC Remote
21 # Author :André Portela
22 # Email :andre_portela_@hotmail.com
25 # Class :PCRemote custom Edje object with it's own call backs for the
27 # ============================================================================
32 import evas.decorators
34 import edje.decorators
36 from connection.iconnection import Iconnection
37 from kineticlist import *
39 class EvasCanvas(object):
41 def __init__(self, fullscreen, engine, size):
42 #f = ecore.evas.SoftwareX11
43 self.evas_obj = engine(w=size[0], h=size[1])
44 self.evas_obj.callback_delete_request = self.on_delete_request
45 self.evas_obj.callback_resize = self.on_resize
47 self.evas_obj.title = "PCRemote"
48 self.evas_obj.name_class = ('PC Remote', 'main')
49 self.evas_obj.fullscreen = fullscreen
50 self.evas_obj.size = size
53 def on_resize(self, evas_obj):
54 x, y, w, h = evas_obj.evas.viewport
56 for key in evas_obj.data.keys():
57 evas_obj.data[key].size = size
59 def on_delete_request(self, evas_obj):
60 ecore.main_loop_quit()
65 class EdjeObject(edje.Edje):
67 def __init__(self, canvas_class, file, group='main',name='edje'):
68 self.canvas_class = canvas_class
69 self.x11 = canvas_class.evas_obj
70 self.canvas = self.x11.evas
71 edje.Edje.__init__(self, self.canvas, file = file, group = group)
72 self.size = self.canvas.size
73 self.x11.data[name] = self
75 class MainScreen(EdjeObject):
77 def __init__(self, canvas, file, group, name, connection):
78 EdjeObject.__init__(self, canvas, file = file, group = group,name = name)
81 self.on_key_down_add(self.key_down_cb, self.x11)
82 self.sock_address = None
83 #flag that sync the discovery device's thread
85 #flag that sync the connecting device's thread
86 self.connecting_flag = False
87 #lista de dispositivos descobertos
88 self.lista_dispositivos = []
89 #objeto que cria a conexao bluetooth
90 self.conexao = connection
91 self.kineticlist = False
93 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']
95 def key_down_cb(self, bg, event, ee):
98 ecore.main_loop_quit()
100 ee.fullscreen = not ee.fullscreen
106 def mkKineticList(self):
107 #kinetic list (the item values are tied with the part "item_background" of the "list_item" group)
108 #self.kineticlist = KineticList(self.canvas, file=self.file, item_width=407, item_height=38, father=self)
109 self.kineticlist = KineticList(self.canvas, file=self.file, item_height=57, father=self)
110 self.kineticlist.freeze()
111 #portela - test kinetic list with several devices
112 #for item in self.lista_teste:
113 #populates the list with the device's names
114 for item in self.lista_dispositivos:
115 self.kineticlist.row_add(item)
116 #reorganize and draw the list
117 self.kineticlist.thaw()
118 #embed the list in the edje object
119 self.part_swallow("list", self.kineticlist);
121 @edje.decorators.signal_callback("connect_to","choice")
122 def connect_to(self, emission, source):
123 self.sock_address = self.part_text_get(source)
124 #flag that sync the connecting device's thread
125 self.connecting_flag = False
126 self.signal_emit("start","device_connect")
127 thread.start_new_thread(MainScreen.threaded_connection,(self,))
129 def threaded_connection(self):
130 self.conexao.create_socket('l2cap')
131 print 'connecting to: %s' % self.sock_address
132 self.conexao.set_address(self.conexao.bt_find_device_address_by_name(self.sock_address))
133 self.conexao.set_port(0x1001)
134 self.conexao.connect()
135 self.connecting_flag = True
137 @edje.decorators.signal_callback("connecting","device")
138 def connecting_check(self, emission, source):
139 if self.connecting_flag:
140 self.connecting_flag = False
141 self.signal_emit("stop","device_connect")
142 #we are sending a signal to main edje (there is time to animate the device locking)
143 self.signal_emit("begin","init")
145 @edje.decorators.signal_callback("animation_still_loading", "loading")
146 def still_loading_cb(self, emission, source):
149 self.signal_emit("program,stop","loading")
150 if self.lista_dispositivos != []:
153 self.no_device_found()
155 @edje.decorators.signal_callback("animation_sair_ended", "sair")
156 def saida(self, signal, source):
157 ecore.main_loop_quit()
159 @edje.decorators.signal_callback("animation_rastrear_ended", "rastrear")
160 def rastrear_key_down(self, signal, source):
161 thread.start_new_thread(MainScreen.rastrear_dispositivos,(self,None))
163 @edje.decorators.signal_callback("program,start", "novodevice")
164 def search_devices_again(self, signal, source):
165 self.part_unswallow(self.kineticlist)
167 MainScreen.rastrear_key_down(self, None, None)
169 def rastrear_dispositivos(self,arg):
171 self.lista_dispositivos = self.conexao.bt_find_devices_only_names()
173 self.lista_dispositivos = []
176 def no_device_found(self):
177 self.signal_emit("program,start","no_device")
179 class TabletScreen(EdjeObject):
181 def __init__(self, canvas, file, group,name, connection):
182 EdjeObject.__init__(self, canvas, file = file, group = group,name = name)
183 self.on_key_down_add(self.key_down_cb, self.x11)
184 #emitt events only if the mouse is inside the touch object area
185 (self.part_object_get('touch')).pointer_mode_set(evas.EVAS_OBJECT_POINTER_MODE_NOGRAB)
186 #assign the mouse_move_cb method as a mouse move callback for the touch part of the edje object
187 (self.part_object_get('touch')).on_mouse_move_add(self.mouse_move_cb)
188 #self.on_mouse_move_add(TabletScreen.mouse_move_cb)
189 self.sock = connection
190 #this flag indicates either the user are grabing something or not on the target
191 self.drag_flag = False
192 #this float indicates the wich the method left_click_down was called, and will be
193 #calculated against lcu_time in left_click_up method
195 self.key_flag = False
197 @edje.decorators.signal_callback('mouse,down,1', 'tablet_bt-L_area')
198 def left_click_down(self, signal, source):
199 self.lcd_time = time.time()
200 #if the user are grabing something, release it
202 self.drag_flag = False
203 self.sock.send_message("Mouse:#left_click")
205 @edje.decorators.signal_callback('mouse,up,1', 'tablet_bt-L_area')
206 def left_click_up(self, signal, source):
207 lcu_time = time.time()
208 #threshold of 0.5 seconds to grab something on the target
209 elapsed_time = lcu_time - self.lcd_time
210 if elapsed_time < 0.5:
212 self.sock.send_message("Mouse:#left_click")
213 self.sock.send_message("Mouse:#left_click")
216 self.sock.send_message("Mouse:#left_click")
217 self.drag_flag = True
219 @edje.decorators.signal_callback('mouse,up,1', 'tablet_bt-R_area')
220 def rigth_click(self, signal, source):
221 self.sock.send_message("Mouse:#right_click")
222 self.sock.send_message("Mouse:#right_click")
224 def key_down_cb(self, bg, event, ee):
228 self.sock.send_message("Tablet:#stop")
230 ecore.main_loop_quit()
232 ee.fullscreen = not ee.fullscreen
234 self.sock.send_message("Keyboard:Up")
236 self.sock.send_message("Keyboard:Down")
238 self.sock.send_message("Keyboard:Alt+F1")
239 elif k == "ISO_Level3_Shift":
240 self.sock.send_message("Keyboard:Alt+F2")
242 self.sock.send_message("Keyboard:%s" % k)
244 def mouse_move_cb(self, part, event):
245 x, y = event.position.output[0], event.position.output[1]
246 self.sock.send_message("Mouse:"+str(x)+","+str(y))
248 class SlideScreen(EdjeObject):
250 def __init__(self, canvas, file, group,name, connection):
251 EdjeObject.__init__(self, canvas, file = file, group = group,name = name)
252 self.on_key_down_add(self.key_down_cb, self.x11)
253 #emitt events only if the mouse is inside the touch object area
254 (self.part_object_get('touch')).pointer_mode_set(evas.EVAS_OBJECT_POINTER_MODE_NOGRAB)
255 #assign the mouse_move_cb method as a mouse move callback for the touch part of the edje object
256 (self.part_object_get('touch')).on_mouse_move_add(self.mouse_move_cb)
257 #self.on_mouse_move_add(TabletScreen.mouse_move_cb)
258 self.sock = connection
259 #this flag indicates either the user are grabing something or not on the target
260 self.drag_flag = False
261 #helps to coordenate presentation
262 self.keyboard_flag = True
263 #this float indicates the wich the method left_click_down was called, and will be
264 #calculated against lcu_time in left_click_up method
267 @edje.decorators.signal_callback('mouse,down,1', 'slide_bt-left_area')
268 def left_click_down(self, signal, source):
269 if self.keyboard_flag:
270 self.lcd_time = time.time()
271 #if the user are grabing something, release it
273 self.drag_flag = False
274 self.sock.send_message("Mouse:#left_click")
276 @edje.decorators.signal_callback('mouse,up,1', 'slide_bt-left_area')
277 def left_click_up(self, signal, source):
278 if self.keyboard_flag:
279 lcu_time = time.time()
280 #threshold of 0.5 seconds to grab something on the target
281 elapsed_time = lcu_time - self.lcd_time
282 if elapsed_time < 0.5:
284 self.sock.send_message("Mouse:#left_click")
285 self.sock.send_message("Mouse:#left_click")
288 self.sock.send_message("Mouse:#left_click")
289 self.drag_flag = True
291 self.sock.send_message("Keyboard:%s" % "Left")
293 @edje.decorators.signal_callback('mouse,up,1', 'slide_bt-right_area')
294 def rigth_click(self, signal, source):
295 if self.keyboard_flag:
296 self.sock.send_message("Mouse:#right_click")
297 self.sock.send_message("Mouse:#right_click")
299 self.sock.send_message("Keyboard:%s" % "Right")
301 def key_down_cb(self, bg, event, ee):
305 self.sock.send_message("Slideshow:#stop")
307 ecore.main_loop_quit()
309 self.keyboard_flag = not self.keyboard_flag
310 self.sock.send_message("Keyboard:F5")
312 self.sock.send_message("Keyboard:Up")
314 self.sock.send_message("Keyboard:Down")
316 self.sock.send_message("Keyboard:%s" % k)
318 def mouse_move_cb(self, part, event):
319 x, y = event.position.output[0], event.position.output[1]
320 self.sock.send_message("Mouse:"+str(x)+","+str(y))