1
2
3
4 """
5 A grapihical window implemented using the
6 U{clutter<http://www.clutter-project.org/>} library, for interactive
7 displays.
8
9 F11 toggles fullscreen.
10 """
11
12 import gtk
13 import clutter
14
15 from twisted.internet import reactor
16
17 from sparked import events
18
19
20 -class Stage (clutter.Stage):
21 """
22 Stage class.
23
24 @ivar keys: Keymap with commonly used keys and their actions.
25 @ivar debug: Whether debugging is enabled. This is retrieved from the --debug flag from the sparkd runner.
26 """
27
28 keys = {'fullscreen': gtk.keysyms.F11,
29 'quit': (clutter.CONTROL_MASK, gtk.keysyms.q)}
30 debug = False
31
52
53
55 """
56 Callback function when the construction of the stage is
57 complete and it is ready to be shown at the screen.
58 """
59
60
62 """
63 Add a widget to the stage which shows when one of the monitors
64 reports an error.
65 """
66 self.app.monitors.events.addObserver("updated", self.updateMonitors)
67 self._monitorText = clutter.Text()
68 self._monitorText.set_font_name("helvetica bold 18px")
69 self._monitorText.set_color(clutter.color_from_string("#ff0000"))
70 self._monitorText.set_x(3)
71 self.add(self._monitorText)
72
73
75 if container.ok():
76 self._monitorText.hide()
77 return
78 txt = "ERROR: "
79 for m in container.monitors:
80 if not m.ok:
81 txt += m.title+", "
82 txt = txt[:-2]
83 self._monitorText.set_text(txt)
84 self._monitorText.show()
85 self._monitorText.raise_top()
86
87
96
97
98 - def isKey(self, event, keydef):
99 if type(keydef) != tuple:
100 return event.keyval == keydef
101
102 for m in keydef[:-1]:
103 if not (event.modifier_state & m):
104 return False
105 return event.keyval == keydef[-1]
106
107
108
110 """
111 Toggle this stage fullscreen or not.
112 """
113 self.set_fullscreen(not self.get_fullscreen())
114 stageEvents.dispatch("stage-fullscreentoggled", stage=self)
115 self.show_cursor()
116
117 if not self.get_fullscreen():
118
119 if not self.debug:
120 self.hide_cursor()
121
122 self.app.screensaverInhibit("Fullscreen presentation")
123 else:
124 self.app.screensaverUnInhibit()
125
126
128 """
129 Given an actor and a box (also an actor), position the actor
130 inside the box, adjusting its position and size, while preserving
131 the aspect ratio of the actor.
132 """
133 aw, ah = actor.get_width(), actor.get_height()
134 bw, bh = box.get_width(), box.get_height()
135
136 aspect = ah/float(aw)
137
138 if bw*aspect <= bh:
139 actor.set_width(bw)
140 actor.set_height(bw*aspect)
141 actor.set_x(box.get_x())
142 actor.set_y(box.get_y()+(bh-bw*aspect)*0.5)
143 else:
144 actor.set_height(bh)
145 actor.set_width(bh/aspect)
146 actor.set_y(box.get_y())
147 actor.set_x(box.get_x()+(bw-bh/aspect)*0.5)
148
149
150 stageEvents = events.EventDispatcher()
151