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

Humitos (talk | contribs)
Humitos (talk | contribs)
 
(6 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 ====
 
Gdk.cairo_set_source_pixbuf(cr, self.backgroundpixbuf, 0, 0)
cr.rectangle(x, 0, self.backgroundpixbuf.get_width(),
              self.backgroundpixbuf.get_height())
cr.paint()
 
= Port to Gtk3 -> Code Snippets =


== Gtk.TextBuffer ==
== Gtk.TextBuffer ==
Line 182: Line 189:
  Gdk.EventType.KEY_RELEASE
  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://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
* 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 expose_cb(self, area, event):
  def draw_cb(self, area, cr):
-        self.draw()
    self.draw(cr)
+    def draw_cb(self, area, cr):
+        self.draw(cr)


= Notes =
= Notes =
Line 200: Line 224:
  # Hack to get the current modifier state - which will not be represented by the event.
  # 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]
  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 =
= Missing / problematic things =
Line 205: Line 253:
* [<span style="color: green;">SOLVED</span>] <del>This method, ''set_source_pixbuf'', is not available.</del>
* [<span style="color: green;">SOLVED</span>] <del>This method, ''set_source_pixbuf'', is not available.</del>


cr = self.get_window().cairo_create()
* [<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>
# README: http://developer.gnome.org/gdk/stable/gdk-Cairo-Interaction.html#gdk-cairo-set-source-pixbuf
# Although this methos is not available in Python
cr.set_source_pixbuf(self.backgroundpixbuf, 0, 0)
 
Gdk.cairo_set_source_pixbuf(cr, self.backgroundpixbuf, 0, 0)


* 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
* [<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>


* PangoCairo fonts are not being drawn because of this: https://bugzilla.gnome.org/show_bug.cgi?id=680680
* [<span style="color: green;">SOLVED</span>] <del>Font Scale is wrong: https://bugzilla.gnome.org/show_bug.cgi?id=680663</del>


* Font Scale is wrong: https://bugzilla.gnome.org/show_bug.cgi?id=680663
* SHIFT and ALT GR keys do not show the correct keys


= Useful links =
= Useful links =