1 # -*- coding: utf-8 -*-
3 # ****************************************************************************
4 # Copyright (c) 2008 INdT/Fucapi.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # ============================================================================
19 # Project Name : PC Remote
20 # Author : Nilson Silva, Jonatas Isvi, Andre Portela
21 # Email : fergus.mao@gmail.com, jonatas.nona@gmail.com,
22 # andre_portela_@hotmail.com
23 # Reviewer : Jônatas Isvi
27 # Description : Mouse Server, Keyboard Server
28 # ============================================================================
31 from utils.labels import *
32 from ServerHandlers import *
33 from players import amarok
38 Defines all mouse behaviors.
39 Clicks and coordinates.
43 def __init__(self, service):
44 self._service_name = service
46 self.labels = Labels()
50 self.fg_dbclick = False
55 #Executes the action requested by the Service Manager
56 def execute(self, command):
58 self.mouse_counter_lclick()
60 if (command == self.labels.CLICK):
62 elif (command == self.labels.DOUBLE_CLICK):
63 self.mouse_press_dbclick()
64 elif (command == self.labels.TRIPLE_CLICK):
65 self.mouse_release_dbclick()
66 elif (command == self.labels.LEFT_CLICK):
68 elif (command == self.labels.MIDDLE_CLICK):
70 elif (command == self.labels.RIGHT_CLICK):
72 elif (command[0] == "#"):
73 self.mouse_fator(command)
75 self.mouse_move(command)
77 #Gets the time the mouse pointer is pressed. If It is greater than (or equal to) 2s, The Mouse Left Click is activated.
78 def mouse_counter_lclick(self):
80 if ((not self.fg_move) and ((int(self.timer.time()) - self.timerclick) >= 2)):
81 self.mouse.right_click(True)
82 self.mouse.right_click(False)
86 #Mouse Pointer - Single Click
87 def mouse_click(self):
88 self.timerclick = int(self.timer.time())
91 #Mouse Pointer - Double Click
92 def mouse_press_dbclick(self):
93 self.mouse.left_click(True)
94 self.fg_dbclick = True
96 #Mouse Pointer - Released after a Double Click
97 def mouse_release_dbclick(self):
99 self.mouse.left_click(False)
100 self.fg_dbclick = False
103 def mouse_lclick(self):
104 self.mouse.left_click()
107 def mouse_mclick(self):
108 self.mouse.middle_click()
111 def mouse_rclick(self):
112 self.mouse.right_click()
114 #Sets the factor of the Mouse Pointer Move
115 def mouse_fator(self, command):
117 for i in range(1, len(command)):
118 num = num + command(i)
120 self.mouse.set_fator(int(num))
122 #Moves the Mouse Pointer
123 def mouse_move(self, command):
124 coord = command.split(",")
126 i = int(coord[0]) - self.x
127 if ((abs(i) == 1) or (abs(i) >= 20)):
130 j = int(coord[1]) - self.y
131 if ((abs(j) == 1) or (abs(j) >= 20)):
134 if not ((i == 0) and (j == 0)):
135 if ((i >= 4) or (j >= 4)):
137 if self._service_name == "Tablet":
138 self.mouse.position(i, j)
140 self.mouse.position(-j, i)
142 self.x = int(coord[0])
143 self.y = int(coord[1])
146 self.mouse.clean_up()
148 class KeyBoard_Server:
151 Defines all keyboard behaviors.
155 def __init__(self, service):
156 self.keyboard = Keyboard()
157 self.shift_flag = False
158 self.control_flag = False
159 self._service_name = service
161 # execute key command
162 def execute(self, command):
167 self.keyboard.reproduce_key_press('Control_L')
168 self.keyboard.reproduce_key_press('z')
169 self.keyboard.reproduce_key_release('z')
170 self.keyboard.reproduce_key_release('Control_L')
171 elif(self._service_name == 'Slideshow' and command == 'F6'):
172 self.keyboard.reproduce_key_press('F5')
173 self.keyboard.reproduce_key_release('F5')
174 elif(command == 'ISO_Level3_Shift'):
175 self.keyboard.reproduce_key_press('Escape')
176 self.keyboard.reproduce_key_release('Escape')
178 elif(command == 'Control_R'):
179 self.control_flag = True
180 self.keyboard.reproduce_key_press('Control_R')
181 #self.keys.append(command)
182 elif(command == 'Shift_L'):
183 self.shift_flag = True
184 self.keyboard.reproduce_key_press('Shift_L')
185 #self.keys.append(command)
186 elif(command == 'F7'):
187 self.keyboard.reproduce_key_press('Control_L')
188 self.keyboard.reproduce_key_press('y')
189 self.keyboard.reproduce_key_release('y')
190 self.keyboard.reproduce_key_release('Control_L')
193 self.keyboard.reproduce_key_press(command)
194 self.keyboard.reproduce_key_release(command)
197 self.keyboard.reproduce_key_release('Shift_L')
198 #self.keys.remove('Shift_L')
199 self.shift_flag = False
200 elif self.control_flag:
201 self.keyboard.reproduce_key_release('Control_R')
202 #self.keys.remove('Control_R')
203 self.control_flag = False
205 # clean all keys pressed
207 self.keyboard.clean_up()
209 class Player_Server():
212 if not amarok.isRunning():
213 self.player = amarok.AmarokPlayer()
216 self.player = amarok.AmarokPlayer()
217 self.labels = Labels()
219 def execute(self, command):
221 if command[1] == self.labels.PLAY:
222 if command[2] and command[3]:
223 self.player.play(track=int(command[2]), rmd=bool(command[3]))
225 arg = int(command[2])
226 if isinstance(arg, int):
227 self.player.play(track=arg)
229 arg = bool(command[2])
230 self.player.play(rmd=arg)
234 if command[1] == self.labels.STOP:
236 elif command[1] == self.labels.PLAY:
238 elif command[1] == self.labels.PAUSE:
240 elif command[1] == self.labels.NEXT:
242 elif command[1] == self.labels.PREVIOUS:
244 elif command[1] == self.labels.VOL_UP:
245 self.player.volume_up()
246 elif command[1] == self.labels.VOL_DOWN:
247 self.player.volume_down()
248 elif command[1] == self.labels.SEEK:
249 self.player.seek(int(command[2]))
250 elif command[1] == self.labels.DOWNLOAD:
251 path = self.player.file_properties()
253 amarok.send_file(addr, path)
255 elif command[1] == self.labels.LOAD_PLAYLIST:
256 # falta o metodo de trasnferencia