Difference between revisions of "Features/GTK3/Porting/Implode"

From Sugar Labs
< Features‎ | GTK3‎ | Porting
Jump to: navigation, search
(Focus)
(New signals)
Line 4: Line 4:
  
 
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.
 +
 +
= Porting Gtk.DrawingArea =
 +
 +
There are some things related with <tt>gtk.DrawingArea</tt> that we have to change when we are porting an activity to Gtk3. The names of the signals change and the way that they work as well.
 +
 +
== Signals ==
 +
 +
=== expose-event ===
 +
 +
* http://developer.gnome.org/gtk3/3.5/GtkWidget.html#GtkWidget-draw
 +
 +
This signal was override by '''draw''' and it have to be connected with the method that was connected with the ''expose-event'' before. The method itself does not change but the arguments that it receives do. This is the new definition of the function in my case:
 +
 +
def _draw_event_cb(self, widget, cr):
 +
 +
=== size-allocate ===
 +
 +
* http://developer.gnome.org/gtk3/3.5/GtkWidget.html#GtkWidget-configure-event
 +
 +
This signal was used to resize the gtk.DrawingArea every time the window grows and at the startup of the activity. This is useful to re-draw the widget for different resolutions (desktops and XOs for example).
 +
 +
I used the same function connected to this signal but I change the signal connected by '''configure-event'''. Here is the definition of the callback:
 +
 +
def _configure_event_cb(self, widget, event):
 +
 +
I just used the ''size-allocate'' signal to save the the dimensions of the widget (width and height), so I can use them later on the '''draw''' signal.
 +
 +
def _size_allocate_cb(self, widget, rect):
 +
    self.width = rect.width
 +
    self.height = rect.height
  
 
= Focus =
 
= Focus =

Revision as of 06:38, 28 June 2012

This page is being performed while I'm porting Implode 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.

Porting Gtk.DrawingArea

There are some things related with gtk.DrawingArea that we have to change when we are porting an activity to Gtk3. The names of the signals change and the way that they work as well.

Signals

expose-event

This signal was override by draw and it have to be connected with the method that was connected with the expose-event before. The method itself does not change but the arguments that it receives do. This is the new definition of the function in my case:

def _draw_event_cb(self, widget, cr):

size-allocate

This signal was used to resize the gtk.DrawingArea every time the window grows and at the startup of the activity. This is useful to re-draw the widget for different resolutions (desktops and XOs for example).

I used the same function connected to this signal but I change the signal connected by configure-event. Here is the definition of the callback:

def _configure_event_cb(self, widget, event):

I just used the size-allocate signal to save the the dimensions of the widget (width and height), so I can use them later on the draw signal.

def _size_allocate_cb(self, widget, rect):
    self.width = rect.width
    self.height = rect.height

Focus

Replace:

self.set_flags(Gtk.CAN_FOCUS)

by

self.set_can_focus(True)

import rsgv
from gi.repository import Rsvg
rsvg.Handle(data=data)
Rsvg.Handle.new_from_data(data)

.focus_child
.get_focus_child()

'size-allocation' signal to save the size of the widget

gtk signals

  • "draw" / "expose" / "size-"