~marcoscarpetta/+junk/scopy

« back to all changes in this revision

Viewing changes to usr/share/scopy-files/src/signals.py

  • Committer: Marco Scarpetta
  • Date: 2011-09-07 09:21:13 UTC
  • Revision ID: marcoscarpetta02@gmail.com-20110907092113-ykzf7lhc3kwzcwy6
start

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
##
 
4
# Project: gumpy
 
5
# Author: Marco Scarpetta <marcoscarpetta02@gmail.com>
 
6
# Copyright: 2011 Marco Scarpeta
 
7
# License: GPL-3+
 
8
# This program is free software; you can redistribute it and/or modify it
 
9
# under the terms of the GNU General Public License as published by the Free
 
10
# Software Foundation; either version 3 of the License, or (at your option)
 
11
# any later version.
 
12
#
 
13
# This program is distributed in the hope that it will be useful, but WITHOUT
 
14
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
15
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 
16
# more details.
 
17
#
 
18
# On Debian GNU/Linux systems, the full text of the GNU General Public License
 
19
# can be found in the file /usr/share/common-licenses/GPL-3.
 
20
##
 
21
 
 
22
def collide(Object):
 
23
        tol = Object.speed/100
 
24
        x1=Object.x
 
25
        x2=Object.x+Object.width
 
26
        y1=Object.y
 
27
        y2=Object.y+Object.height
 
28
        if Object.game.height-tol<y2<Object.game.height+tol:
 
29
                Object.connected_events['collide'][0]('bottom',-1)
 
30
        if -tol<y1<tol:
 
31
                Object.connected_events['collide'][0]('top',-1)
 
32
        if -tol<x1<tol:
 
33
                Object.connected_events['collide'][0]('left',1)
 
34
        if Object.game.width-tol<x2<Object.game.width+tol:
 
35
                Object.connected_events['collide'][0]('right',1)
 
36
        for dif_Object in Object.game.Objects:
 
37
                if dif_Object != Object:
 
38
                        X1=dif_Object.x
 
39
                        X2=dif_Object.x+dif_Object.width
 
40
                        Y1=dif_Object.y
 
41
                        Y2=dif_Object.y+dif_Object.height
 
42
                        if Y2-tol<y1<Y2+tol or Y1-tol<y2<Y1+tol:
 
43
                                if X1<=x1<=X2 or X1<=x2<=X2:
 
44
                                        Object.connected_events['collide'][0](dif_Object,-1)
 
45
                        if X2-tol<x1<X2+tol or X1-tol<x2<X1+tol:
 
46
                                if Y1<=y1<=Y2 or Y1<=y2<=Y2:
 
47
                                        Object.connected_events['collide'][0](dif_Object,1)
 
48
def position(Object):
 
49
        tol = Object.speed/100
 
50
        x1=Object.x
 
51
        y1=Object.y
 
52
        x=Object.connected_events['position'][1][0]
 
53
        y=Object.connected_events['position'][1][1]
 
54
        if y-tol<y1<y+tol and x-tol<x1<x+tol:
 
55
                Object.disconnect('position')
 
56
                Object.connected_events['position'][0](Object)
 
57
def key_press_event(widget, data, options, Object, game):
 
58
        function_data = Object.gtk_connected_events['key-press-event'][options]
 
59
        if keys[options] == data.keyval:
 
60
                function_data[0](function_data[1])
 
61
def key_release_event(widget, data, options, Object, game):
 
62
        function_data = Object.gtk_connected_events['key-release-event'][options]
 
63
        if keys[options] == data.keyval:
 
64
                function_data[0](function_data[1])
 
65
def button_press_event(widget, data, options, Object, game):
 
66
        if Object in game.Objects:
 
67
                x1=int(Object.x)*Object.game.scale_ratio
 
68
                x2=int(Object.x+Object.width)*Object.game.scale_ratio
 
69
                y1=int(Object.y)*Object.game.scale_ratio
 
70
                y2=int(Object.y+Object.height)*Object.game.scale_ratio
 
71
                function_data = Object.gtk_connected_events['button-press-event'][options]
 
72
                if x1<data.x<x2 and y1<data.y<y2:
 
73
                        function_data[0](Object, function_data[1])
 
74
def motion_notify_event(widget, data, options, Object, game):
 
75
        function_data = Object.gtk_connected_events['motion-notify-event'][options]
 
76
        function_data[0](function_data[1], data.x, data.y)
 
77
signals = {
 
78
        'collide':collide,
 
79
        'position':position
 
80
        }
 
81
 
 
82
gtk_signals = {
 
83
        'key-press-event':key_press_event,
 
84
        'key-release-event':key_release_event,
 
85
        'button-press-event':button_press_event,
 
86
        'motion-notify-event':motion_notify_event
 
87
        }
 
88
 
 
89
def gtk_signals_dict():
 
90
        gtk_dict = {}
 
91
        for event in gtk_signals:
 
92
                gtk_dict[event]={}
 
93
        return gtk_dict
 
94
 
 
95
keys = {
 
96
        'Escape':65307,
 
97
        'F1':65470,
 
98
        'F2':65471,
 
99
        'F3':65472,
 
100
        'F4':65473,
 
101
        'F5':65474,
 
102
        'F6':65475,
 
103
        'F7':65476,
 
104
        'F8':65477,
 
105
        'F9':65478,
 
106
        'F10':65479,
 
107
        'L1':65480,
 
108
        'F11':65480,
 
109
        'L2':65481,
 
110
        'F12':65481,
 
111
        'Scroll_Lock':65300,
 
112
        'Pause':65299,
 
113
        'backslash':92,
 
114
        '1':49,
 
115
        '2':50,
 
116
        '3':51,
 
117
        '4':52,
 
118
        '5':53,
 
119
        '6':54,
 
120
        '7':55,
 
121
        '8':56,
 
122
        '9':57,
 
123
        '0':48,
 
124
        'quoteright':39,
 
125
        'apostrophe':39,
 
126
        'igrave':236,
 
127
        'BackSpace':65288,
 
128
        'Insert':65379,
 
129
        'Home':65360,
 
130
        'Page_Up':65365,
 
131
        'Prior':65365,
 
132
        'Num_Lock':65407,
 
133
        'KP_Divide':65455,
 
134
        'KP_Multiply':65450,
 
135
        'KP_Subtract':65453,
 
136
        'Tab':65289,
 
137
        'q':113,
 
138
        'w':119,
 
139
        'e':101,
 
140
        'r':114,
 
141
        't':116,
 
142
        'y':121,
 
143
        'u':117,
 
144
        'i':105,
 
145
        'o':111,
 
146
        'p':112,
 
147
        'egrave':232,
 
148
        'plus':43,
 
149
        'ugrave':249,
 
150
        'Delete':65535,
 
151
        'VoidSymbol':65535,
 
152
        'End':65367,
 
153
        'Page_Down':65366,
 
154
        'Next':65366,
 
155
        'KP_7':65463,
 
156
        'KP_8':65464,
 
157
        'KP_9':65465,
 
158
        'KP_Add':65451,
 
159
        'Caps_Lock':65509,
 
160
        'A':65,
 
161
        'S':83,
 
162
        'D':68,
 
163
        'F':70,
 
164
        'G':71,
 
165
        'H':72,
 
166
        'J':74,
 
167
        'K':75,
 
168
        'L':76,
 
169
        'Ograve':210,
 
170
        'Agrave':192,
 
171
        'Return':65293,
 
172
        'Q':81,
 
173
        'W':87,
 
174
        'E':69,
 
175
        'R':82,
 
176
        'T':84,
 
177
        'Y':89,
 
178
        'U':85,
 
179
        'I':73,
 
180
        'O':79,
 
181
        'P':80,
 
182
        'Z':90,
 
183
        'X':88,
 
184
        'C':67,
 
185
        'V':86,
 
186
        'B':66,
 
187
        'N':78,
 
188
        'M':77,
 
189
        'Ograve':210,
 
190
        'Agrave':192,
 
191
        'Return':65293,
 
192
        'Shift_R':65506,
 
193
        'minus':45,
 
194
        'period':46,
 
195
        'comma':44,
 
196
        'ISO_Level3_Shift':65027,
 
197
        'Super_R':65516,
 
198
        'Menu':65383,
 
199
        'Control_R':65508,
 
200
        'space':32,
 
201
        'Alt_L':65513,
 
202
        'Super_L':65515,
 
203
        'Control_L':65507,
 
204
        'Shift_L':65505,
 
205
        'Caps_Lock':65509,
 
206
        'less':60,
 
207
        'z':122,
 
208
        'x':120,
 
209
        'c':99,
 
210
        'v':118,
 
211
        'b':98,
 
212
        'n':110,
 
213
        'm':109,
 
214
        'l':108,
 
215
        'k':107,
 
216
        'j':106,
 
217
        'h':104,
 
218
        'g':103,
 
219
        'f':102,
 
220
        'd':100,
 
221
        's':115,
 
222
        'a':97,
 
223
        'Left':65361,
 
224
        'Down':65364,
 
225
        'Right':65363,
 
226
        'Up':65362,
 
227
        'KP_0':65456,
 
228
        'KP_Decimal':65454,
 
229
        'KP_Enter':65421,
 
230
        'KP_3':65459,
 
231
        'KP_6':65462,
 
232
        'KP_5':65461,
 
233
        'KP_4':65460,
 
234
        'KP_1':65457,
 
235
        'KP_2':65458
 
236
        }