Changes

Jump to navigation Jump to search
Line 9: Line 9:  
# Comment on IRC about the Activity that you are going to Port (#sugar on irc.freenode.net)
 
# Comment on IRC about the Activity that you are going to Port (#sugar on irc.freenode.net)
 
# Run this [http://git.gnome.org/browse/pygobject/tree/pygi-convert.sh script] that will convert automatically things as much as it can. This is to avoid some stressful manually conversions that a "simple script" can do using ''sed'' :)
 
# Run this [http://git.gnome.org/browse/pygobject/tree/pygi-convert.sh script] that will convert automatically things as much as it can. This is to avoid some stressful manually conversions that a "simple script" can do using ''sed'' :)
# Convert all the <tt>from sugar. import</tt> to <tt>from sugar</tt>'''3'''<tt>. import</tt>
+
# Convert all the <tt>from sugar.* import</tt> to <tt>from sugar</tt>'''3'''<tt>.* import</tt> using [http://dev.laptop.org/~manuq/sugar-convert.sh this script]
 +
# Follow the [[Development_Team/Code_guidelines|Code Guidelines]] during all the porting process
 
# Remove all things related with '''old toolbar''' support. They are no longer maintained
 
# Remove all things related with '''old toolbar''' support. They are no longer maintained
 +
# Write comments on the code, by adding '''# README:''', '''# TODO:''' and '''# FIXME:''' explaining what are the problems that you are having with that chunk of code. Put a link if it's necessary
 +
# If you are considering to fix some ''pep8'' or ''pylint'' errors/warnings, please create two separate patch files (one for the port and one for the pylint/pep8 changes). If we follow this way it is easier to check the port patches, if not the information about the port itself it's difficult to follow
 
# Keep reading this wiki page to find out more things that you should do
 
# Keep reading this wiki page to find out more things that you should do
   Line 19: Line 22:  
It's really useful to keep the "original" version of the Activity that we are porting to know how it was working before the port. Sometimes you find an strange behaviour on the ported version of the activity and you ''think'' that you don't touch that part of the code or that the change shouldn't affect it. In these cases it's good to run the "original" version and test how it worked before the port.
 
It's really useful to keep the "original" version of the Activity that we are porting to know how it was working before the port. Sometimes you find an strange behaviour on the ported version of the activity and you ''think'' that you don't touch that part of the code or that the change shouldn't affect it. In these cases it's good to run the "original" version and test how it worked before the port.
   −
I [http://lists.sugarlabs.org/archive/sugar-devel/2012-June/037996.html ask to the Sugar Developers mailing list] about how to do this and they told me that I should change the ''bundle_id''. In fact, we have to change the '''bundle_id''' and the '''name''' from the ''activity/activity.info'' file. I used:
+
I [http://lists.sugarlabs.org/archive/sugar-devel/2012-June/037996.html asked to the Sugar Developers mailing list] about how to do this and they told me that I should change the ''bundle_id''. In fact, we have to change the '''bundle_id''' and the '''name''' from the ''activity/activity.info'' file. I used:
    
  name = Get Books Gtk3
 
  name = Get Books Gtk3
Line 54: Line 57:     
If you have an XO, I'm sure you want to take a look at [[User:Humitos/x2x|this]]...
 
If you have an XO, I'm sure you want to take a look at [[User:Humitos/x2x|this]]...
 +
 +
== Use Extended Python debugger ==
 +
 +
There is a library called '''epdb''' and it's useful to inspect the code while the Activity is running. I'm using this module when I'm not sure about the type of an object or I can test some different things that the code says in some point. So, I installed this package on my Fedora 17 by running this command
 +
 +
sudo yum install python-epdb
 +
 +
After that I put some trace point in the code where I can stop and make my tests by doing this:
 +
 +
import epdb;epdb.set_trace()
 +
 +
Finally I run Get Books Activity from the Terminal Activity to be able to write some code on a shell. This is the command that I use:
 +
 +
sugar-launch org.laptop.sugar.GetBooksActivity
 +
 +
See also [[Development Team/Debugging]].
 +
 +
== Check logs with ''multitail'' ==
 +
 +
Here is a really useful command to open new logs automatically: [[User:Humitos/MultiTail]]
 +
 +
 +
== Use the pygobject code as example ==
 +
 +
[https://live.gnome.org/PyGObject pygobject] is what we use to make Gtk3 activities. So, it's really useful to take a look at the code examples that are there. Even more, you can run some demo application that show how to use something specific about the library.
 +
 +
* Clone the code:
 +
 +
git clone git://git.gnome.org/pygobject
 +
 +
[[File:Screenshot_from_2012-06-14_13-26-50.png|100px|thumb|right|]]
 +
 +
* Run an example
 +
 +
cd pygobject
 +
cd demos/gtk-demo/demos
 +
python pixbuf.py
 +
 +
* Grep the code to search for something useful
 +
 +
cd pygobject
 +
git grep GdkPixbuf
 +
 +
== Monitoring DBus ==
 +
 +
Not sure how this command works, but it can give us an interesting information. If you run this command and plug an USB drive you will see useful information
 +
 +
dbus-monitor --system
    
= Code Snippets =
 
= Code Snippets =
Line 75: Line 126:  
  from gi.repository import GObject
 
  from gi.repository import GObject
   −
  class ExtListViewColumn(Gtk.TreeViewColumn):
+
  class ExtListView(Gtk.TreeView):
 
     __gsignals__ = {
 
     __gsignals__ = {
 
       'extlistview-modified': (GObject.SignalFlags.RUN_LAST, None,
 
       'extlistview-modified': (GObject.SignalFlags.RUN_LAST, None,
Line 101: Line 152:     
In that case we are creating a new instance of <tt>Gdk.Cursor</tt> every time that this chunk of code is called. I think that we could define all the cursor used by the Activity once at the beginning of the file maybe. ''We should discuss about this.''
 
In that case we are creating a new instance of <tt>Gdk.Cursor</tt> every time that this chunk of code is called. I think that we could define all the cursor used by the Activity once at the beginning of the file maybe. ''We should discuss about this.''
 +
 +
== Use Gtk.Box instead Gtk.HBox / Gtk.VBox | Gtk.HSeparator / Gtk.VSeparator ==
 +
 +
As [http://developer.gnome.org/gtk3/3.5/GtkHBox.html#GtkHBox.description its documentation says], Gtk.VBox and Gtk.HBox have been deprecated. So, we should use Gtk.Box instead them. Replacing:
 +
 +
self.list_box = gtk.HBox()
 +
 +
by:
 +
 +
self.list_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
 +
 +
and,
 +
 +
self.list_box = gtk.VBox()
 +
 +
by:
 +
 +
self.list_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
 +
 +
The same happens with Gtk.Separator: [http://developer.gnome.org/gtk3/3.5/GtkVSeparator.html#GtkVSeparator.description link to the documentation]
 +
 +
== Using Pixbuf ==
 +
 +
As I said, this is what I did, but maybe is not the correct way to do it or there is a better way. I think that if we are porting an Activity we can take advantage of this and improve the code. manuq told me that the image handling now is done with Cairo, so we should port that to cairo. Although, I didn't do this because I consider that the image handling done in Get Books is really simple and we don't have the necessity to use Cairo here.
 +
 +
So, what I did is keep using Pixbuf with Gtk3 version of the Activity. We need to replace and import some things:
 +
 +
from gi.repository import GdkPixbuf
 +
 +
Replace:
 +
 +
gtk.gdk.PixbufLoader()
 +
 +
by:
 +
 +
GdkPixbuf.PixbufLoader()
 +
 +
and,
 +
 +
gtk.gdk.pixbuf_new_from_file(file_path)
 +
 +
by:
 +
 +
GdkPixbuf.Pixbuf.new_from_file(file_path)
 +
 +
and,
 +
 +
gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,
 +
                pixbuf.get_has_alpha(),
 +
                pixbuf.get_bits_per_sample(),
 +
                image_width, image_height)
 +
 +
by:
 +
 +
GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB,
 +
                      pixbuf.get_has_alpha(),
 +
                      pixbuf.get_bits_per_sample(),
 +
                      image_width, image_height)
 +
 +
''note the '''.new''' and the '''colorspace''' in the replacement.''
 +
 +
and,
 +
 +
gtk.gdk.INTERP_BILINEAR
 +
 +
by:
 +
 +
GdkPixbuf.InterpType.BILINEAR
 +
 +
 +
=== Save the GdkPixbuf into a buffer ===
 +
 +
This was very difficult to find out. The gtk2 version of the code was using <tt>pixbuf.save_to_callback</tt> to save the Image on the Journal's Preview Entry but that function no longer exist in Gtk3. So, I found a similar one called <tt>pixbuf.save_to_callbackv</tt> that I couldn't find out how to use it. Even more, I realized that this function call another callback function that doesn't do so much. Reading I found an alternative (and easier) way to do this using <tt>pibuxf.save_to_bufferv</tt>:
 +
 +
succes, data = pixbuf2.save_to_bufferv('png', [], [])
 +
 +
= Notes =
 +
 +
There are some things that I realized while I was doing the port. I will mention them here:
 +
 +
* <tt>Gtk.Widget.hide_all()</tt> doesn't exist anymore. We should use just <tt>.hide</tt>: http://developer.gnome.org/gtk3/3.5/GtkWidget.html#gtk-widget-hide
 +
* This is not necessary because the code will work anyway but I think that it's better. I replaced <tt>GObject.TYPE_STRING</tt> by '''<tt>str</tt>''' on the definition of the <tt>Gtk.ListStore</tt>
 +
 +
self.treemodel = Gtk.ListStore(GObject.TYPE_STRING)
 +
 +
self.treemodel = Gtk.ListStore(str)
 +
* There is something related with <tt>.pack_start</tt> that I couldn't find it out and understand either: http://wiki.sugarlabs.org/go/Features/GTK3/Porting#HBox.2C_VBox.2C_pack_start_and_pack_end
 +
* I didn't find a solution for this yet: '''gtk.gdk.Pixbuf.save_to_callback'''. So, at the moment, I'm not saving the preview cover for the books
 +
* If the code creates some own object, and it defines some properties, you should use '''__gproperties__''' dictionary: http://python-gtk-3-tutorial.readthedocs.org/en/latest/objects.html#GObject.GObject.__gproperties__
 +
* I removed this (<tt>UDISK_DEVICE_PATH = 'org.freedesktop.UDisks.Device'</tt>) because I don't know what it does and it was crashing the Activity
 +
* <tt>Gtk.ListStore</tt> doesn't have the method '''.reorder'''. There is a [https://bugzilla.gnome.org/show_bug.cgi?id=677941 ticket] reported upstream about this.
 +
* Should I use the Sugar's Palette instead of Gtk.Menu?
 +
* I replaced the use of <tt>dbus</tt> by [http://developer.gnome.org/gio/unstable/pt02.html Gio] to monitor the (dis)connection of pen drives
 +
 +
= Missing / Problematic things (not ported yet) =
 +
 +
* [<span style="color: green;">DONE</span>] <del>When a book is downloaded, the cover is not saved in the Journal Entry</del>
 +
* [<span style="color: green;">DONE</span>] <del>Switch the results to '''Internet Archive''' doesn't work</del>
 +
* [<span style="color: orange;">ALTERNATIVE</span>] When the "generic book image" is shown (at the bottom left), the gray color used to fill it is not the same as the background. ''I changed the color with is the GdkPixbuf filled to match with the darker one (style.COLOR_BUTTON_GREY) because I couldn't find how to fill the alpha of the "generic_cover.png" with the old color (style.COLOR_PANEL_GREY)'': http://bugs.sugarlabs.org/ticket/3723
 +
* [<span style="color: green;">DONE</span>] <del>I'm not sure what is ''org.freedesktop.UDisks.Device'' for? I don't understand it very well but I had to remove it because it was failing</del>. I replaced this by GIO
 +
* The ''Catalogs'' column title is bigger than the other column titles
 +
* Right clicking on the column titles doesn't show the Gtk.Menu popup
 +
 +
== Theme related things ==
 +
 +
* <del>Cancel search button. It shows a really big '''X''' when you start typing: http://bugs.sugarlabs.org/ticket/3385</del>
 +
* <del>Clicking some things on the screen makes the ListView grows a bit and it doesn't fit on the screen (the right scroll-bar goes outside the window): http://bugs.sugarlabs.org/ticket/3722</del>
 +
* <del>Some time when I click on the Search Entry all the toolbar is moved a bit</del>
 +
* <del>After searching and selecting a book, if we change the format to ''EPUB'' the ''Get Book'' button is moved a bit: http://bugs.sugarlabs.org/ticket/3724</del>
 +
* W<del>hen the book download starts, a ''Cancel'' is shown but it doesn't have the '''X''' icon: http://bugs.sugarlabs.org/ticket/3725</del>
 +
* The background of the rows on the ListView do not cycle between ''white'' and ''gray'': http://bugs.sugarlabs.org/ticket/3726
 +
* The column width should be re-sized to fit with the text inside them with a max width pre-set
    
= References / Useful links =
 
= References / Useful links =
Line 113: Line 276:  
** Gdk3: http://developer.gnome.org/gdk/2.24/
 
** Gdk3: http://developer.gnome.org/gdk/2.24/
 
* OLPC Documentation: http://wiki.laptop.org/go/Activities/PortingToGtk3
 
* OLPC Documentation: http://wiki.laptop.org/go/Activities/PortingToGtk3
 +
* Patch file of Clock's port to Cairo: http://bugs.sugarlabs.org/attachment/ticket/3454/0001-Port-to-Cairo.2.patch
 +
* GetBooks' diff (these .diff doesn't reflect the final port):
 +
** First version: http://bugs.sugarlabs.org/attachment/ticket/3681/Port-Gtk3-backup.diff
 +
** Second version: http://bugs.sugarlabs.org/attachment/ticket/3681/Port-Gtk3-backup.2.diff
 +
* Used to know the arguments of <tt>GdkPixbuf.Pixbuf.save_to_bufferv</tt> https://mail.gnome.org/archives/javascript-list/2011-March/msg00001.html
 +
* pdb Python's module docs: http://docs.python.org/library/pdb.html
 +
* Monitor Volumes / GNOME Input-Output http://developer.gnome.org/gio/unstable/pt02.html

Navigation menu