Updated Spanish translation
[gpodder/nikosapi.git] / doc / dev / splash-logo.py
blob9140acde77482099ca27f7725d22f4bef84f39ef
2 # WIP. We might use this some time in the future.
3 # -- Thomas Perl, 2008-03-19
5 # Released under the same license as gPodder.
7 import gtk
8 import gobject
9 import cairo
11 class gPodderSplashScreen(gtk.Window):
12 (WIDTH, HEIGHT) = (250, 250)
13 (WAIT, STEP) = (100, 20)
15 def __init__(self, filename, caption):
16 gtk.Window.__init__(self)
17 self.caption = caption
18 self.set_decorated(False)
19 self.set_skip_taskbar_hint(True)
20 self.set_keep_above(True)
21 self.set_app_paintable(True)
22 self.set_position(gtk.WIN_POS_CENTER)
23 self.set_opacity(1)
24 self.connect('expose-event', self.expose_event)
25 self.connect('screen-changed', self.screen_changed)
26 self.resize(self.WIDTH, self.HEIGHT)
28 self.fading_in = False
30 self.svgsur = self.load_surface_from_file(filename)
31 self.screen_changed(self)
32 self.show_all()
34 def fade_in(self):
35 self.fading_in = True
36 gobject.timeout_add(self.WAIT, self.update_opacity, True)
38 def fade_out(self):
39 if self.is_composited():
40 self.fading_in = False
41 gobject.timeout_add(self.WAIT, self.update_opacity, False, True)
42 else:
43 self.destroy()
45 def expose_event(self, widget, event):
46 cr = widget.window.cairo_create()
47 if not self.is_composited():
48 cr.set_source_rgb(0, 0, 0)
49 cr.rectangle(0, 0, self.WIDTH, self.HEIGHT)
50 cr.stroke()
51 cr.set_source_rgb( 1, 1, 1)
52 cr.rectangle(1, 1, self.WIDTH-2, self.HEIGHT-2)
53 cr.fill()
54 cr.set_source_rgba(0,0,0,0)
55 if self.is_composited():
56 cr.set_operator(cairo.OPERATOR_SOURCE)
57 cr.paint()
58 cr.set_source_surface(self.svgsur, 0, 0)
59 cr.paint()
60 cr.set_operator(cairo.OPERATOR_OVER)
61 cr.select_font_face("sans-serif", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
62 texting = self.caption
63 cr.set_font_size(30)
64 cr.set_source_rgba(1, 1, 1, .5)
65 (SHIFT_X, SHIFT_Y) = (20, -30)
66 cr.move_to(SHIFT_X, self.HEIGHT+SHIFT_Y)
67 cr.show_text(texting)
68 cr.move_to(SHIFT_X+2, self.HEIGHT+SHIFT_Y+2)
69 cr.show_text(texting)
70 cr.move_to(SHIFT_X+2, self.HEIGHT+SHIFT_Y)
71 cr.show_text(texting)
72 cr.move_to(SHIFT_X, self.HEIGHT+SHIFT_Y+2)
73 cr.show_text(texting)
74 cr.fill()
75 cr.set_source_rgba(0, 0, 0, 1)
76 cr.move_to(SHIFT_X+1, self.HEIGHT+SHIFT_Y+1)
77 cr.show_text(texting)
78 cr.fill()
79 return True
81 def screen_changed(self, widget, old_screen=None):
82 cm = widget.get_screen().get_rgba_colormap()
83 if cm is not None:
84 widget.set_colormap(cm)
86 def load_surface_from_file(self, filename):
87 pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(filename, self.WIDTH, self.HEIGHT)
89 format = cairo.FORMAT_RGB24
90 if pixbuf.get_has_alpha():
91 format = cairo.FORMAT_ARGB32
92 width = pixbuf.get_width()
93 height = pixbuf.get_height()
94 image = cairo.ImageSurface(format, width, height)
96 context = cairo.Context(image)
97 gdkcontext = gtk.gdk.CairoContext(context)
98 gdkcontext.set_source_pixbuf(pixbuf, 0, 0)
99 gdkcontext.paint()
100 return image
102 def update_opacity(self, increase=True, close_after=False):
103 if increase and self.fading_in:
104 opacity = min(1.0, max(0.1, self.get_opacity()*1.1))
105 else:
106 opacity = self.get_opacity()-0.05
107 self.set_opacity(max(0.0, min(1.0, opacity)))
108 if opacity >= 0.0 and opacity <= 1.0:
109 gobject.timeout_add(self.STEP, self.update_opacity, increase, close_after)
110 elif close_after:
111 self.destroy()
113 return False