Difference between revisions of "Features/GTK3/Porting/Typing Turtle"
Line 1: | Line 1: | ||
This page is being performed while I'm porting Typing Turtle Activity to Gtk3. | This page is being performed while I'm porting Typing Turtle Activity to Gtk3. | ||
− | There is a [ticket] with some useful information that I'm using on the porting and to keep tracking this port. Besides, this wiki page will be useful to write some code snippets about what are the difficulties that I'm having on the port and maybe can be useful for someone else. | + | There is a [http://bugs.sugarlabs.org/ticket/3772 ticket] with some useful information that I'm using on the porting and to keep tracking this port. Besides, this wiki page will be useful to write some code snippets about what are the difficulties that I'm having on the port and maybe can be useful for someone else. |
I will take [[User:Humitos/PortingGetBooks|this guide]] as reference on the Gtk3 porting. | I will take [[User:Humitos/PortingGetBooks|this guide]] as reference on the Gtk3 porting. | ||
+ | |||
+ | = Port to Cairo = | ||
'''README''': before to port this activity to GTK3, we should port it to Cairo as the first step and then move to GTK3. | '''README''': before to port this activity to GTK3, we should port it to Cairo as the first step and then move to GTK3. | ||
+ | |||
+ | == Code Snippets == | ||
+ | |||
+ | === Draw a rectangle === | ||
+ | |||
+ | To draw a rectangle we used to do: | ||
+ | |||
+ | gc = self.window.new_gc() | ||
+ | gc.foreground = self.area.get_colormap().alloc_color(50000, 50000, 50000) | ||
+ | self.area.window.draw_rectangle(gc, True, x, y, w, h) | ||
+ | |||
+ | The arguments for ''alloc_color'' are between 1- | ||
+ | |||
+ | now, with cairo we should do something like this | ||
+ | |||
+ | cr.set_source_rgb(0.762, 0.762, 0.762) | ||
+ | cr.rectangle(x, y, w, h) | ||
+ | cr.fill() | ||
+ | |||
+ | |||
+ | |||
+ | gc.foreground = self.area.get_colormap().alloc_color(0, 0, 0) | ||
+ | self.area.window.draw_rectangle(gc, False, x, y, w, h) | ||
= Code Snippets = | = Code Snippets = | ||
Line 50: | Line 75: | ||
Every entry was a tuple of (keycode, group, level). Now, this is an object with those attributes. | Every entry was a tuple of (keycode, group, level). Now, this is an object with those attributes. | ||
+ | |||
+ | = Useful links = | ||
+ | |||
+ | * http://cairographics.org/documentation/pycairo/2/index.html | ||
+ | * http://www.pygtk.org/docs/pygtk/pangocairo-class-reference.html | ||
+ | * http://www.pygtk.org/docs/pygtk/class-gdkdrawable.html |
Revision as of 08:09, 25 July 2012
This page is being performed while I'm porting Typing Turtle Activity to Gtk3.
There is a ticket with some useful information that I'm using on the porting and to keep tracking this port. Besides, this wiki page will be useful to write some code snippets about what are the difficulties that I'm having on the port and maybe can be useful for someone else.
I will take this guide as reference on the Gtk3 porting.
Port to Cairo
README: before to port this activity to GTK3, we should port it to Cairo as the first step and then move to GTK3.
Code Snippets
Draw a rectangle
To draw a rectangle we used to do:
gc = self.window.new_gc() gc.foreground = self.area.get_colormap().alloc_color(50000, 50000, 50000) self.area.window.draw_rectangle(gc, True, x, y, w, h)
The arguments for alloc_color are between 1-
now, with cairo we should do something like this
cr.set_source_rgb(0.762, 0.762, 0.762) cr.rectangle(x, y, w, h) cr.fill()
gc.foreground = self.area.get_colormap().alloc_color(0, 0, 0) self.area.window.draw_rectangle(gc, False, x, y, w, h)
Code Snippets
Gtk.Style.fg_gc
gc = self.get_style().fg_gc[Gtk.StateType.NORMAL]
replaced by:
gc = self.get_style().fg[Gtk.StateType.NORMAL]
Gtk.DrawingArea
self.layout = self.create_pango_layout() self.layout.set_text(self.title_original)
replaced by:
self.layout = self.create_pango_layout() self.layout.set_text(self.title_original, len(self.title_original)
self.lessonbuffer = Gtk.TextBuffer.new(self.tagtable) self.lessontext = Gtk.TextView.new_with_buffer(self.lessonbuffer)
Gtk.TextTag
instructions_tag = Gtk.TextTag('instructions')
replaced by:
instructions_tag = Gtk.TextTag.new('instructions')
Gdk.Keymap
entries = self.keymap.get_entries_for_keyval(keyval)
replaced by:
valid, entries = self.keymap.get_entries_for_keyval(keyval)
Every entry was a tuple of (keycode, group, level). Now, this is an object with those attributes.