Features/GTK3/Porting/Typing Turtle: Difference between revisions

Humitos (talk | contribs)
Humitos (talk | contribs)
 
(15 intermediate revisions by 2 users not shown)
Line 7: Line 7:
= Port to Cairo =
= 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. Here is the [http://bugs.sugarlabs.org/attachment/ticket/3772/0001-Port-to-Cairo.2.patch PATCH]


== Code Snippets ==
== Code Snippets ==
Line 108: Line 108:
  cr.paint()
  cr.paint()


= Code Snippets =
==== Gtk3 version ====


== Gtk.Style.fg_gc ==
Gdk.cairo_set_source_pixbuf(cr, self.backgroundpixbuf, 0, 0)
cr.rectangle(x, 0, self.backgroundpixbuf.get_width(),
              self.backgroundpixbuf.get_height())
cr.paint()


  gc = self.get_style().fg_gc[Gtk.StateType.NORMAL]
= Port to Gtk3 -> Code Snippets =
 
== Gtk.TextBuffer ==
 
  self.lessonbuffer = gtk.TextBuffer(self.tagtable)
self.lessontext = gtk.TextView(self.lessonbuffer)


replaced by:
replaced by:


  gc = self.get_style().fg[Gtk.StateType.NORMAL]
  self.lessonbuffer = Gtk.TextBuffer.new(self.tagtable)
self.lessontext = Gtk.TextView.new_with_buffer(self.lessonbuffer)


== Gdk.Event ==


== Gtk.DrawingArea ==
event.state


self.layout = self.create_pango_layout('')
replaced by:
self.layout.set_text(self.title_original)


replaced by:
event.get_state()
 
== Rsvg ==


  self.layout = self.create_pango_layout('')
  import rsvg
  self.layout.set_text(self.title_original, len(self.title_original)
  image = rsvg.Handle(file=filename)


----
replaced by:


  self.lessonbuffer = Gtk.TextBuffer.new(self.tagtable)
  from gi.repository import Rsvg
  self.lessontext = Gtk.TextView.new_with_buffer(self.lessonbuffer)
  image = Rsvg.Handle.new_from_file(filename)


= Gtk.TextTag =
== Gtk.TextTag ==


  instructions_tag = Gtk.TextTag('instructions')
  instructions_tag = Gtk.TextTag('instructions')
Line 142: Line 153:
  instructions_tag = Gtk.TextTag.new('instructions')
  instructions_tag = Gtk.TextTag.new('instructions')


= Gdk.Keymap =
== Gdk.Keymap ==


  entries = self.keymap.get_entries_for_keyval(keyval)
  entries = self.keymap.get_entries_for_keyval(keyval)
for e in entries:
    e[0], e[1], e[2]


replaced by:
replaced by:


  valid, entries = self.keymap.get_entries_for_keyval(keyval)
  valid, entries = self.keymap.get_entries_for_keyval(keyval)
for e in entries:
    e.keycode, e.group, e.level


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.
== GdkPixbuf.PixbufLoader ==
Change this:
pxb_loader = gtk.gdk.PixbufLoader(image_type='png')
by:
pxb_loader = GdkPixbuf.PixbufLoader.new_with_type('png')
== KEY_PRESS ==
This should be done by the '''pygi-convert.sh''' script.
gtk.gdk.KEY_PRESS
gtk.gdk.KEY_RELEASE
replaced by
Gdk.EventType.KEY_PRESS
Gdk.EventType.KEY_RELEASE
== Gdk.Keymap.translate_keyboard_state ==
* http://developer.gnome.org/gdk/stable/gdk-Keyboard-Handling.html#gdk-keymap-translate-keyboard-state
* http://www.pygtk.org/docs/pygtk/class-gdkkeymap.html#method-gdkkeymap--translate-keyboard-state
Old way:
t = self.keymap.translate_keyboard_state(key['key-scan'], self.active_state, self.active_group)
New way:
success, keyval, effective_group, level, consumed_modifiers = \
    self.keymap.translate_keyboard_state(key['key-scan'], self.active_state,
                                          self.active_group)
== 'expose-event' & 'draw' event ==
The new ''draw'' event that refers to the old ''expose-event'' into a Gtk.DrawingArea now receive the widget and the context instead the widget and the event:
''expose-event''
def expose_cb(self, area, event):
    self.draw()
''draw'' event
def draw_cb(self, area, cr):
    self.draw(cr)
= Notes =
* I found this chunk of code in the source (''keyboard.py'' '''L515''') and I didn't understand what it means
# Hack to get the current modifier state - which will not be represented by the event.
state = gtk.gdk.device_get_core_pointer().get_state(self.window)[1]
* I used a HACK related to Pango fonts and DPI:
<pre>
# Set correct DPI for Rsvg and Screen
from gi.repository import PangoCairo
def _get_screen_dpi():
    xft_dpi = Gtk.Settings.get_default().get_property('gtk-xft-dpi')
    dpi = float(xft_dpi / 1024)
    logging.debug('Setting dpi to: %f', dpi)
    # HACK: if the DPI detected is 200.0 it seems we are on an XO, so
    # we return 133 because the XO manage its resolution in a complex
    # way. More information here:
    #    http://wiki.laptop.org/go/Display
    if 200 == int(dpi):
        return 133
    return dpi
dpi = _get_screen_dpi()
font_map_default = PangoCairo.font_map_get_default()
font_map_default.set_resolution(dpi)
</pre>
= Missing / problematic things =
* [<span style="color: green;">SOLVED</span>] <del>This method, ''set_source_pixbuf'', is not available.</del>
* [<span style="color: green;">SOLVED</span>] <del>We should find the correct way to scale Left and Right hands that are drawn over the keyboard, because I just put values that I thought they were correct. We should calculate them according to the screen</del>
* [<span style="color: green;">SOLVED</span>] <del>PangoCairo fonts are not being drawn because of this: https://bugzilla.gnome.org/show_bug.cgi?id=680680</del>
* [<span style="color: green;">SOLVED</span>] <del>Font Scale is wrong: https://bugzilla.gnome.org/show_bug.cgi?id=680663</del>
* SHIFT and ALT GR keys do not show the correct keys


= Useful links =
= Useful links =