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.
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
)
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
)
36 gobject
.timeout_add(self
.WAIT
, self
.update_opacity
, True)
39 if self
.is_composited():
40 self
.fading_in
= False
41 gobject
.timeout_add(self
.WAIT
, self
.update_opacity
, False, True)
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
)
51 cr
.set_source_rgb( 1, 1, 1)
52 cr
.rectangle(1, 1, self
.WIDTH
-2, self
.HEIGHT
-2)
54 cr
.set_source_rgba(0,0,0,0)
55 if self
.is_composited():
56 cr
.set_operator(cairo
.OPERATOR_SOURCE
)
58 cr
.set_source_surface(self
.svgsur
, 0, 0)
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
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
)
68 cr
.move_to(SHIFT_X
+2, self
.HEIGHT
+SHIFT_Y
+2)
70 cr
.move_to(SHIFT_X
+2, self
.HEIGHT
+SHIFT_Y
)
72 cr
.move_to(SHIFT_X
, self
.HEIGHT
+SHIFT_Y
+2)
75 cr
.set_source_rgba(0, 0, 0, 1)
76 cr
.move_to(SHIFT_X
+1, self
.HEIGHT
+SHIFT_Y
+1)
81 def screen_changed(self
, widget
, old_screen
=None):
82 cm
= widget
.get_screen().get_rgba_colormap()
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)
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))
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
)