diff options
Diffstat (limited to 'titlescene.py')
-rw-r--r-- | titlescene.py | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/titlescene.py b/titlescene.py index 4dc6ae4..9739152 100644 --- a/titlescene.py +++ b/titlescene.py @@ -18,12 +18,15 @@ import random from gettext import gettext as _ -# Import PyGTK. -import gobject, pygtk, gtk, pango -import pangocairo +from gi.repository import Gtk +from gi.repository import Gdk +from gi.repository import GObject +from gi.repository import Pango +from gi.repository import PangoCairo +from gi.repository import GdkPixbuf -class TitleScene(gtk.DrawingArea): +class TitleScene(Gtk.DrawingArea): # Maximum portion of the screen the background can fill vertically. BACKGROUND_HEIGHT_RATIO = 0.6 @@ -34,58 +37,61 @@ class TitleScene(gtk.DrawingArea): TITLE_FONT = 'Times 45' def __init__(self): - gtk.DrawingArea.__init__(self) + Gtk.DrawingArea.__init__(self) - pbuf = gtk.gdk.pixbuf_new_from_file('images/main-background.jpg') + pbuf = GdkPixbuf.Pixbuf.new_from_file('images/main-background.jpg') - width_ratio = float(gtk.gdk.screen_width()) / pbuf.get_width() - height_ratio = float(gtk.gdk.screen_height()*TitleScene.BACKGROUND_HEIGHT_RATIO) / pbuf.get_height() + width_ratio = float(Gdk.Screen.width()) / pbuf.get_width() + height_ratio = float(Gdk.Screen.height()*TitleScene.BACKGROUND_HEIGHT_RATIO) / pbuf.get_height() ratio = min(width_ratio, height_ratio) - self.backgroundpixbuf = pbuf.scale_simple(int(pbuf.get_width()*ratio), int(pbuf.get_height()*ratio), gtk.gdk.INTERP_BILINEAR) + self.backgroundpixbuf = pbuf.scale_simple(int(pbuf.get_width()*ratio), int(pbuf.get_height()*ratio), GdkPixbuf.InterpType.BILINEAR) self.set_size_request(self.backgroundpixbuf.get_width(), self.backgroundpixbuf.get_height()) - self.connect("expose-event", self.expose_cb) + self.connect("draw", self.draw_cb) self.title_original = _('Typing Turtle') self.title_src = self.title_original self.title_text = '' - def expose_cb(self, area, event): + def draw_cb(self, area, cr): bounds = self.get_allocation() - cr = self.window.cairo_create() - # Background picture. x = (bounds.width - self.backgroundpixbuf.get_width())/2 - cr.set_source_pixbuf(self.backgroundpixbuf, 0, 0) + + Gdk.cairo_set_source_pixbuf(cr, self.backgroundpixbuf, 0, 0) cr.rectangle(x, 0, self.backgroundpixbuf.get_width(), self.backgroundpixbuf.get_height()) cr.paint() - cr = pangocairo.CairoContext(cr) cr.set_source_rgb(0, 0, 0) - self.pango_layout = cr.create_layout() + self.pango_layout = PangoCairo.create_layout(cr) self.pango_layout.set_font_description( - pango.FontDescription(TitleScene.TITLE_FONT)) - self.pango_layout.set_text(unicode(self.title_original)) + Pango.FontDescription(TitleScene.TITLE_FONT)) + self.pango_layout.set_text(unicode(self.title_original), + len(self.title_original)) original_size = self.pango_layout.get_size() - self.x_text = (bounds.width - original_size[0] / pango.SCALE) - \ + self.x_text = (bounds.width - original_size[0] / Pango.SCALE) - \ TitleScene.TITLE_OFFSET[0] self.y_text = TitleScene.TITLE_OFFSET[1] - gobject.timeout_add(50, self.timer_cb) + GObject.timeout_add(50, self.timer_cb) def draw_text(self): # Animated Typing Turtle title. - cr = self.window.cairo_create() + window = self.get_window() + if window is None: + return + cr = window.cairo_create() cr.move_to(self.x_text, self.y_text) - self.pango_layout.set_text(unicode(self.title_text)) - cr.show_layout(self.pango_layout) - cr.stroke() + self.pango_layout.set_text(unicode(self.title_text), + len(self.title_text)) + PangoCairo.update_layout(cr, self.pango_layout) + PangoCairo.show_layout(cr, self.pango_layout) def timer_cb(self): if len(self.title_src) > 0: |