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.alt_flag = False
160 self._service_name = service
162 # execute key command
163 def execute(self, command):
168 self.keyboard.reproduce_key_press('Control_L')
169 self.keyboard.reproduce_key_press('z')
170 self.keyboard.reproduce_key_release('z')
171 self.keyboard.reproduce_key_release('Control_L')
172 elif(self._service_name == 'Slideshow' and command == 'F6'):
173 self.keyboard.reproduce_key_press('F5')
174 self.keyboard.reproduce_key_release('F5')
175 elif(command == 'Control_R'):
176 self.control_flag = True
177 self.keyboard.reproduce_key_press('Control_R')
178 #self.keys.append(command)
179 elif(command == 'Shift_L'):
180 self.shift_flag = True
181 self.keyboard.reproduce_key_press('Shift_L')
182 #self.keys.append(command)
183 elif(command == 'Alt_L'):
185 self.keyboard.reproduce_key_press('Alt_L')
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')
191 elif(command == 'Alt+F1'):
192 self.keyboard.reproduce_key_press('Alt_L')
193 self.keyboard.reproduce_key_press('F1')
194 self.keyboard.reproduce_key_release('F1')
195 self.keyboard.reproduce_key_release('Alt_L')
196 elif(command == 'Alt+F2'):
197 self.keyboard.reproduce_key_press('Alt_L')
198 self.keyboard.reproduce_key_press('F2')
199 self.keyboard.reproduce_key_release('F2')
200 self.keyboard.reproduce_key_release('Alt_L')
201 elif(command == 'Alt+F4'):
202 self.keyboard.reproduce_key_press('Alt_L')
203 self.keyboard.reproduce_key_press('F4')
204 self.keyboard.reproduce_key_release('F4')
205 self.keyboard.reproduce_key_release('Alt_L')
206 elif(command == 'Alt+F9'):
207 self.keyboard.reproduce_key_press('Alt_L')
208 self.keyboard.reproduce_key_press('F9')
209 self.keyboard.reproduce_key_release('F9')
210 self.keyboard.reproduce_key_release('Alt_L')
211 elif(command == 'Alt+F0'):
212 self.keyboard.reproduce_key_press('Alt_L')
213 self.keyboard.reproduce_key_press('F10')
214 self.keyboard.reproduce_key_release('F10')
215 self.keyboard.reproduce_key_release('Alt_L')
216 elif(command == 'Alt+Space'):
217 self.keyboard.reproduce_key_press('Alt_L')
218 self.keyboard.reproduce_key_press('space')
219 self.keyboard.reproduce_key_release('space')
220 self.keyboard.reproduce_key_release('Alt_L')
221 elif(command == 'Tab'):
222 self.keyboard.reproduce_key_press('Tab')
223 self.keyboard.reproduce_key_release('Tab')
225 self.keyboard.reproduce_key_press(command)
226 self.keyboard.reproduce_key_release(command)
229 self.keyboard.reproduce_key_release('Shift_L')
230 #self.keys.remove('Shift_L')
231 self.shift_flag = False
232 elif self.control_flag:
233 self.keyboard.reproduce_key_release('Control_R')
234 #self.keys.remove('Control_R')
235 self.control_flag = False
237 self.keyboard.reproduce_key_release('Alt_L')
238 self.alt_flag = False
240 # clean all keys pressed
242 self.keyboard.clean_up()
244 class Player_Server():
247 if not amarok.isRunning():
248 self.player = amarok.AmarokPlayer()
251 self.player = amarok.AmarokPlayer()
252 self.labels = Labels()
254 def execute(self, command):
256 if command[1] == self.labels.PLAY:
257 if command[2] and command[3]:
258 self.player.play(track=int(command[2]), rmd=bool(command[3]))
260 arg = int(command[2])
261 if isinstance(arg, int):
262 self.player.play(track=arg)
264 arg = bool(command[2])
265 self.player.play(rmd=arg)
269 if command[1] == self.labels.STOP:
271 elif command[1] == self.labels.PLAY:
273 elif command[1] == self.labels.PAUSE:
275 elif command[1] == self.labels.NEXT:
277 elif command[1] == self.labels.PREVIOUS:
279 elif command[1] == self.labels.VOL_UP:
280 self.player.volume_up()
281 elif command[1] == self.labels.VOL_DOWN:
282 self.player.volume_down()
283 elif command[1] == self.labels.SEEK:
284 self.player.seek(int(command[2]))
285 elif command[1] == self.labels.DOWNLOAD:
286 path = self.player.file_properties()
288 amarok.send_file(addr, path)
290 elif command[1] == self.labels.LOAD_PLAYLIST:
291 # falta o metodo de trasnferencia