forked from fdanesse/Bichos
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Widgets.py
executable file
·105 lines (85 loc) · 3.73 KB
/
Widgets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GObject
from EventTraductor.EventTraductor import MousemotionTraduce
from EventTraductor.EventTraductor import Traduce_button_press_event
from EventTraductor.EventTraductor import Traduce_button_release_event
def color_parser(color):
rgba = Gdk.RGBA()
rgba.parse(color)
return rgba
class Escenario(Gtk.DrawingArea):
__gsignals__ = {
"new-size": (GObject.SignalFlags.RUN_LAST,
None, (GObject.TYPE_PYOBJECT, )),
"mouse-enter": (GObject.SignalFlags.RUN_LAST,
None, (GObject.TYPE_BOOLEAN, ))}
def __init__(self):
GObject.GObject.__init__(self)
self.override_background_color(Gtk.StateType.NORMAL, color_parser("#000000"))
self.set_events(Gdk.EventType.EXPOSE |
#Gdk.KEY_PRESS | Gdk.KEY_RELEASE |
#Gdk.EventMask.KEY_RELEASE_MASK | Gdk.EventMask.KEY_PRESS_MASK |
Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.POINTER_MOTION_HINT_MASK |
Gdk.EventMask.BUTTON_MOTION_MASK | Gdk.EventMask.BUTTON_PRESS_MASK |
Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK
| Gdk.EventMask.ENTER_NOTIFY_MASK)
self.connect("size-allocate", self.__size_request)
self.connect("draw", self.__draw_cb)
self.connect("button_press_event", self.__button_press_event)
self.connect("button_release_event", self.__button_release_event)
self.connect("motion-notify-event", self.__mouse_motion)
self.connect("enter-notify-event", self.__mouse_enter)
self.connect("leave-notify-event", self.__mouse_leave)
self.show_all()
def __mouse_enter(self, widget, event):
self.emit("mouse-enter", True)
def __mouse_leave(self, widget, event):
self.emit("mouse-enter", False)
def __button_press_event(self, widget, event):
try:
if self.get_toplevel().juego:
Traduce_button_press_event(event,
self.get_allocation(),
self.get_toplevel().juego.RESOLUCION_INICIAL)
except:
# Para Sugar
if self.get_toplevel().interfaz.juego:
Traduce_button_press_event(event,
self.get_allocation(),
self.get_toplevel().interfaz.juego.RESOLUCION_INICIAL)
return False
def __button_release_event(self, widget, event):
try:
if self.get_toplevel().juego:
Traduce_button_release_event(event,
self.get_allocation(),
self.get_toplevel().juego.RESOLUCION_INICIAL)
except:
# Para Sugar
if self.get_toplevel().interfaz.juego:
Traduce_button_release_event(event,
self.get_allocation(),
self.get_toplevel().interfaz.juego.RESOLUCION_INICIAL)
return False
def __mouse_motion(self, widget, event):
try:
if self.get_toplevel().juego:
MousemotionTraduce(event,
self.get_allocation(),
self.get_toplevel().juego.RESOLUCION_INICIAL)
except:
# Para Sugar
if self.get_toplevel().interfaz.juego:
MousemotionTraduce(event,
self.get_allocation(),
self.get_toplevel().interfaz.juego.RESOLUCION_INICIAL)
return False
def __size_request(self, widget, event):
rect = self.get_allocation()
self.emit("new-size", (rect.width, rect.height))
def __draw_cb(self, widget, event):
rect = self.get_allocation()
self.emit("new-size", (rect.width, rect.height))