pcremote-client-n8x0 -> client sources
[remotepc] / pcremote-server-desktop / debian / pcremote-server / usr / share / pcremote-server / services / .svn / text-base / ObjectServers.py.svn-base
1 # -*- coding: utf-8 -*-
2
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.
9 #
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.
14 #
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/>.
17 #
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
24 # Email        : 
25 # Version      : 1.0
26 # Package      : services
27 # Description  : Mouse Server, Keyboard Server
28 # ============================================================================
29
30 import time
31 from utils.labels import *
32 from ServerHandlers import *
33
34 class Mouse_Server:
35
36     """ Mouse Server
37     Defines all mouse behaviors.
38     Clicks and coordinates.
39     """
40
41     #Initialize the class
42     def __init__(self):
43
44         self.mouse  = Mouse()
45         self.labels = Labels()
46         self.timer  = time
47         self.timerclick = 0
48         
49         self.fg_dbclick = False
50         self.fg_move = True
51         self.x = 0      
52         self.y = 0
53
54     #Executes the action requested by the Service Manager
55     def execute(self, command):
56
57         self.mouse_counter_lclick()
58
59         if (command == self.labels.CLICK):
60             self.mouse_click()
61         elif (command == self.labels.DOUBLE_CLICK):
62             self.mouse_press_dbclick()
63         elif (command == self.labels.TRIPLE_CLICK):
64             self.mouse_release_dbclick()
65         elif (command == self.labels.LEFT_CLICK):
66             self.mouse_lclick()
67         elif (command == self.labels.MIDDLE_CLICK):
68             self.mouse_mclick()
69         elif (command == self.labels.RIGHT_CLICK):
70             self.mouse_rclick()
71         elif (command[0] == "#"):
72             self.mouse_fator(command)
73         else:
74             self.mouse_move(command)
75
76     #Gets the time the mouse pointer is pressed. If It is greater than (or equal to) 2s, The Mouse Left Click is activated.
77     def mouse_counter_lclick(self):
78                   
79         if ((not self.fg_move) and ((int(self.timer.time()) - self.timerclick) >= 2)):
80             self.mouse.right_click(True)
81             self.mouse.right_click(False)
82             self.timerclick = 0
83             self.fg_move = True
84
85     #Mouse Pointer - Single Click
86     def mouse_click(self):
87         self.timerclick = int(self.timer.time())
88         self.fg_move = False
89
90     #Mouse Pointer - Double Click
91     def mouse_press_dbclick(self):
92         self.mouse.left_click(True)
93         self.fg_dbclick = True
94
95     #Mouse Pointer - Released after a Double Click
96     def mouse_release_dbclick(self):
97         if self.fg_dbclick:
98             self.mouse.left_click(False)
99             self.fg_dbclick = False
100
101     #Mouse Left Click
102     def mouse_lclick(self):
103         self.mouse.left_click()
104
105     #Mouse Middle Click
106     def mouse_mclick(self):
107         self.mouse.middle_click()
108
109     #Mouse Right Click
110     def mouse_rclick(self):
111         self.mouse.right_click()
112
113     #Sets the factor of the Mouse Pointer Move
114     def mouse_fator(self, command):
115         num = ""
116         for i in range(1, len(command)):
117             num = num + command(i)
118
119         self.mouse.set_fator(int(num))
120
121     #Moves the Mouse Pointer
122     def mouse_move(self, command):
123         coord = command.split(",")
124
125         i = int(coord[0]) - self.x
126         if ((abs(i) == 1) or (abs(i) >= 20)):
127             i = 0
128
129         j = int(coord[1]) - self.y
130         if ((abs(j) == 1) or (abs(j) >= 20)):
131             j = 0
132
133         if not ((i == 0) and (j == 0)):            
134             if ((i >= 4) or (j >= 4)):
135                 self.fg_move = True
136             self.mouse.position(i, j)
137
138         self.x = int(coord[0])
139         self.y = int(coord[1])
140
141     def clean_up_mouse(self):
142         self.mouse.clean_up_mouse()
143
144 class KeyBoard_Server:
145
146     """ Keyboard Server
147     Defines all keyboard behaviors.
148     Map keys and events.
149     """    
150
151     def __init__(self):
152         self.keyboard = Keyboard()
153         self.shift_flag = False
154         self.control_flag = False
155         self.keys = []
156
157     # execute key command
158     def execute(self, command):
159         
160         print "\n", command
161
162         if(command == 'F8'):
163             self.keyboard.reproduce_key_press('Control_L')
164             self.keyboard.reproduce_key_press('z')
165             self.keyboard.reproduce_key_release('z')
166             self.keyboard.reproduce_key_release('Control_L')
167         elif(command == 'ISO_Level3_Shift'):
168             self.keyboard.reproduce_key_press('Escape')
169             self.keyboard.reproduce_key_release('Escape')
170             pass
171         elif(command == 'Control_R'):
172             self.control_flag = True
173             self.keyboard.reproduce_key_press('Control_R')
174             self.keys.append(command)
175         elif(command == 'Shift_L'):
176             self.shift_flag = True
177             self.keyboard.reproduce_key_press('Shift_L')
178             self.keys.append(command)
179         elif(command == 'F7'):
180             self.keyboard.reproduce_key_press('Control_L')
181             self.keyboard.reproduce_key_press('y')
182             self.keyboard.reproduce_key_release('y')
183             self.keyboard.reproduce_key_release('Control_L')
184         else:
185                         
186             self.keyboard.reproduce_key_press(command)
187             self.keyboard.reproduce_key_release(command)
188                         
189             if self.shift_flag:
190                 self.keyboard.reproduce_key_release('Shift_L')
191                 self.keys.remove('Shift_L')
192                 self.shift_flag = False
193             elif self.control_flag:
194                 self.keyboard.reproduce_key_release('Control_R')
195                 self.keys.remove('Control_R')
196                 self.control_flag = False
197         
198     # clean all keys pressed                    
199     def clean_up_keyboard(self):
200         print "\nkeys -> ", self.keys
201         list = self.keys
202         print "\nlist ->", list 
203         for i in list:
204             self.keyboard.reproduce_key_release(i)
205             self.keys.remove(i)
206             print "\nkey --> ", i, " removed."
207
208         print self.keys