From 02a6079af2c2335382e21c78203758f8f5a11e36 Mon Sep 17 00:00:00 2001 From: Lionel LASKE Date: Thu, 29 Dec 2011 15:14:57 +0000 Subject: Add full Napoleon sample, handle mime type, redo localisation --- diff --git a/MANIFEST b/MANIFEST index cf77e50..29db4f6 100644 --- a/MANIFEST +++ b/MANIFEST @@ -4,6 +4,8 @@ vboxcolor.py COPYING activity/roots-icon.svg activity/activity.info +activity/application-x-roots-activity.svg +activity/mimetypes.xml src/union.py src/person.py src/tree.py @@ -20,6 +22,17 @@ images/addchild.svg images/addparent.svg images/addunion.svg images/delete.svg +images/napo_p1.jpg +images/napo_p2.jpg +images/napo_p3.jpg +images/napo_p4.jpg +images/napo_p5.jpg +images/napo_p6.jpg +images/napo_p7.jpg +images/napo_p8.jpg +images/napo_p9.jpg +images/napo_p10.jpg +images/napo_p11.jpg locale/fr/activity.linfo locale/fr/LC_MESSAGES/org.olpcfrance.Roots.mo po/fr.po diff --git a/activity.py b/activity.py index 7b8767a..a799da6 100644 --- a/activity.py +++ b/activity.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + # Base import import gtk import pango @@ -18,6 +21,7 @@ import src.const as const try: from sugar.activity import activity from sugar.graphics.toolbutton import ToolButton + from sugar.presence import presenceservice from gtk import Toolbar const.inSugar = True except ImportError: @@ -26,8 +30,8 @@ except ImportError: # Init position -const.tree_initx = 200 -const.tree_inity = 200 +const.tree_initx = (875 - const._person_width) / 2 +const.tree_inity = (780 - const._person_height) / 2 const.bg_color = (0.7, 0.7, 0.7) @@ -40,6 +44,10 @@ _consolehandler.setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(level _logger.addHandler(_consolehandler) +# Init presence +presenceService = presenceservice.get_instance() +buddyName = presenceService.get_owner().props.nick + # Activity class class RootsActivity(activity.Activity): @@ -74,7 +82,7 @@ class RootsActivity(activity.Activity): tool.connect('clicked', self.sample1) toolbarsample.insert(tool, -1) tool = ToolButton('sample2') - tool.set_tooltip(_('Napoleon')) + tool.set_tooltip(_('Napoléon')) tool.connect('clicked', self.sample2) toolbarsample.insert(tool, -1) toolbox.add_toolbar(_('Samples'), toolbarsample) @@ -84,7 +92,7 @@ class RootsActivity(activity.Activity): # Create drawing area self.zoomlevel = 0 self.area = gtk.DrawingArea() - self.area.set_size_request(750, 600) + self.area.set_size_request(875, 780) self.area.set_events(gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK|gtk.gdk.BUTTON_MOTION_MASK|gtk.gdk.POINTER_MOTION_MASK) self.area.connect("expose_event", self.area_expose_cb) self.area.connect("button_press_event", self.press_button) @@ -94,9 +102,9 @@ class RootsActivity(activity.Activity): # Create detail view self.fixed = VBoxColor(const.bg_color) - self.fixed.set_size_request(200, 300) + self.fixed.set_size_request(325, 780) self.imagezone = gtk.DrawingArea() - self.imagezone.set_size_request(200, 240) # WARNING: Should preserve the 1/3 ratio + self.imagezone.set_size_request(325, 240) self.imagezone.set_events(gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK) self.imagezone.connect("expose_event", self.image_expose) self.imagezone.connect("button_press_event", self.image_release_button) @@ -118,13 +126,13 @@ class RootsActivity(activity.Activity): scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolled.set_border_width(2) self.detail_description = gtk.TextView() - self.detail_description.set_wrap_mode(True) + self.detail_description.set_wrap_mode(gtk.WRAP_WORD) self.detail_description.set_size_request(200, 100) self.detail_description.set_cursor_visible(True) self.detail_description.get_buffer().connect("changed", self.description_changed) scrolled.add(self.detail_description) self.fixed.pack_start(scrolled, False, False, 5) - self.detail_btnaddparent = self.create_button(_("Add parent"), "images/addparent.svg", self.addparent_clicked) + self.detail_btnaddparent = self.create_button(_("Add parents"), "images/addparent.svg", self.addparent_clicked) self.detail_btnaddbrother = self.create_button(_("Add brother/sister"), "images/addbrother.svg", self.addbrother_clicked) self.detail_btnaddunion = self.create_button(_("Add union"), "images/addunion.svg", self.addunion_clicked) self.detail_btnaddchild = self.create_button(_("Add child"), "images/addchild.svg", self.addchild_clicked) @@ -142,7 +150,7 @@ class RootsActivity(activity.Activity): # Create empty tree self.tree = None self.selected = None - self.init_tree(empty_tree()) + self.init_tree(empty_tree(buddyName)) # Show all self.show_all() @@ -195,6 +203,7 @@ class RootsActivity(activity.Activity): self.detail_name.set_sensitive(False) self.detail_description.set_sensitive(False) self.detail_name.set_text("") + self.detail_description.get_buffer().set_text("") self.detail_chkmale.set_active(True) self.detail_chkmale.set_sensitive(False) self.detail_chkfemale.set_sensitive(False) @@ -453,12 +462,12 @@ class RootsActivity(activity.Activity): text = _("Click a person to edit it") else: text = _("Click here to paste an image") - metrics = pc.get_metrics(self.imagezone.get_style().font_desc) - w = pango.PIXELS(metrics.get_approximate_char_width() * len(text)) layout = pango.Layout(pc) layout.set_text(text) + layout.set_width(rect.width*pango.SCALE) + layout.set_alignment(pango.ALIGN_CENTER) gc.set_source_rgb(0, 0, 0) - gc.move_to((rect.width - w)/2, y + image.get_height()) + gc.move_to(0, y + image.get_height()) gc.show_layout(layout) @@ -487,15 +496,23 @@ class RootsActivity(activity.Activity): # Match image to rectangle rect = self.imagezone.allocation - if image.get_width() > rect.width or image.get_height() > rect.height: - image = image.scale_simple(rect.width, rect.height, gtk.gdk.INTERP_HYPER) + image_width = image.get_width() + image_height = image.get_height() + if image_width > rect.width or image_height > rect.height: + if image_width > image_height: + target_width = rect.width + target_height = (image_height * target_width) / image_width + else: + target_height = rect.height + target_width = (image_width * target_height) / image_height + image = image.scale_simple(target_width, target_height, gtk.gdk.INTERP_HYPER) self.selected.image = image self.redraw() def emptytree(self, event): "Init with an empty tree" - self.init_tree(empty_tree()) + self.init_tree(empty_tree(buddyName)) def sample1(self, event): diff --git a/activity/activity.info b/activity/activity.info index 12d3c5b..cecef06 100644 --- a/activity/activity.info +++ b/activity/activity.info @@ -4,4 +4,5 @@ activity_version = 1 bundle_id = org.olpcfrance.Roots exec = sugar-activity activity.RootsActivity icon = roots-icon +mime_types = application/x-roots-activity; license = GPLv2+ diff --git a/activity/application-x-roots-activity.svg b/activity/application-x-roots-activity.svg new file mode 100644 index 0000000..9b5f136 --- /dev/null +++ b/activity/application-x-roots-activity.svg @@ -0,0 +1,413 @@ + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/activity/mimetypes.xml b/activity/mimetypes.xml new file mode 100644 index 0000000..1543110 --- /dev/null +++ b/activity/mimetypes.xml @@ -0,0 +1,7 @@ + + + + Roots Activity + + + \ No newline at end of file diff --git a/images/napo_p1.jpg b/images/napo_p1.jpg new file mode 100644 index 0000000..42b2e1b --- /dev/null +++ b/images/napo_p1.jpg Binary files differ diff --git a/images/napo_p10.jpg b/images/napo_p10.jpg new file mode 100644 index 0000000..691c5c2 --- /dev/null +++ b/images/napo_p10.jpg Binary files differ diff --git a/images/napo_p11.jpg b/images/napo_p11.jpg new file mode 100644 index 0000000..5cf6fa9 --- /dev/null +++ b/images/napo_p11.jpg Binary files differ diff --git a/images/napo_p2.jpg b/images/napo_p2.jpg new file mode 100644 index 0000000..10df401 --- /dev/null +++ b/images/napo_p2.jpg Binary files differ diff --git a/images/napo_p3.jpg b/images/napo_p3.jpg new file mode 100644 index 0000000..3d0df6d --- /dev/null +++ b/images/napo_p3.jpg Binary files differ diff --git a/images/napo_p4.jpg b/images/napo_p4.jpg new file mode 100644 index 0000000..6da365e --- /dev/null +++ b/images/napo_p4.jpg Binary files differ diff --git a/images/napo_p5.jpg b/images/napo_p5.jpg new file mode 100644 index 0000000..b0f6bad --- /dev/null +++ b/images/napo_p5.jpg Binary files differ diff --git a/images/napo_p6.jpg b/images/napo_p6.jpg new file mode 100644 index 0000000..1b31a35 --- /dev/null +++ b/images/napo_p6.jpg Binary files differ diff --git a/images/napo_p7.jpg b/images/napo_p7.jpg new file mode 100644 index 0000000..2b7747a --- /dev/null +++ b/images/napo_p7.jpg Binary files differ diff --git a/images/napo_p8.jpg b/images/napo_p8.jpg new file mode 100644 index 0000000..d929862 --- /dev/null +++ b/images/napo_p8.jpg Binary files differ diff --git a/images/napo_p9.jpg b/images/napo_p9.jpg new file mode 100644 index 0000000..96dbaac --- /dev/null +++ b/images/napo_p9.jpg Binary files differ diff --git a/po/POTFILES.in b/po/POTFILES.in index cf2abd2..2b3689f 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,2 +1,3 @@ encoding: UTF-8 activity.py +src/tree.py diff --git a/po/fr.po b/po/fr.po index b18112d..dab4661 100644 --- a/po/fr.po +++ b/po/fr.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-12-21 22:55+0200\n" -"PO-Revision-Date: 2011-12-21 23:05+0200\n" +"POT-Creation-Date: 2011-12-28 22:55+0200\n" +"PO-Revision-Date: 2011-12-28 23:05+0200\n" "Last-Translator: user \n" "Language-Team: French\n" "MIME-Version: 1.0\n" @@ -16,74 +16,143 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" -#: activity/activity.info:2 -msgid "Roots" -msgstr "Racines" - -#: activity.py:43 +#: activity.py:65 msgid "Zoom out" -msgstr "Zoom avant" +msgstr "Zoom arrière" -#: activity.py:44 +#: activity.py:66 msgid "minus" msgstr "moins" -#: activity.py:48 +#: activity.py:70 msgid "Zoom in" -msgstr "Zoom arrière" +msgstr "Zoom avant" -#: activity.py:49 +#: activity.py:71 msgid "equal" msgstr "égal" -#: activity.py:52 +#: activity.py:74 msgid "View" -msgstr "Vue" +msgstr "Affichage" -#: activity.py:55 +#: activity.py:77 msgid "Empty tree" msgstr "Arbre vide" -#: activity.py:59 +#: activity.py:81 msgid "Test" msgstr "Test" -#: activity.py:63 -msgid "Napoleon" +#: activity.py:85 +msgid "Napoléon" msgstr "Napoléon" -#: activity.py:66 +#: activity.py:88 msgid "Samples" msgstr "Exemples" -#: activity.py:84 -msgid "Name:" -msgstr "Nom:" - -#: activity.py:89 +#: activity.py:118 msgid "Male" msgstr "Mâle" -#: activity.py:92 +#: activity.py:121 msgid "Female" msgstr "Femelle" -#: activity.py:95 -msgid "Add parent" -msgstr "Ajouter parent" +#: activity.py:135 +msgid "Add parents" +msgstr "Ajouter parents" -#: activity.py:97 +#: activity.py:136 +msgid "Add brother/sister" +msgstr "Ajouter frère/soeur" + +#: activity.py:137 msgid "Add union" msgstr "Ajouter union" -#: activity.py:99 +#: activity.py:138 msgid "Add child" msgstr "Ajouter enfant" -#: activity.py:101 +#: activity.py:139 msgid "Delete" msgstr "Supprimer" -#: activity.py:147 -msgid "Click one a node to select it" -msgstr "Cliquer sur un noeud pour le sélectionner" +#: activity.py:462 +msgid "Click a person to edit it" +msgstr "Cliquer sur une personne pour la modifier" + +#: activity.py:464 +msgid "Click here to paste an image" +msgstr "Cliquer ici pour coller une image" + +#: src/tree.py:407 +msgid "" +"(1746-1785) This young Corsican aristocrat studied law in Italy and Corsica." +msgstr "(1746-1785) Jeune noble corse, il étudie le droit en Italie et en Corse." + +#: src/tree.py:410 +msgid "" +"(1750-1836) She married very young, at 14 years old. In Corsica, she was " +"known as the 'little marvel', famed for her beauty far and wide." +msgstr "(1750-1836) Mariée très jeune, à 14 ans, on l'appelle 'la petite mervielle' car sa beauté est reconnue de tous." + +#: src/tree.py:414 +msgid "" +"(1769-1821) He was born on 15 August 1769 in Ajaccio, Corsica. At the age of " +"10, he left Corsica with his older brother Joseph to study at the Ecole " +"Militaire in Paris." +msgstr "(1769-1821) Né le 15 août 1769 à Ajaccio en Corse, il quitte la Corse à 10 ans avec son frère Joseph pour faire des études à l'Ecole Militaire à Paris." + +#: src/tree.py:417 +msgid "" +"(1778-1846) While still a child, Louis joined his brother Napoleon in Paris. " +"He accompanied his brother on his early military campaigns and became King " +"of Holland at the age of 28." +msgstr "(1778-1846) Enfant, Louis rejoint son frère Napoléon à Paris. Il l'accompagne dans ses campagnes et devient roi de Hollande à 28 ans." + +#: src/tree.py:422 +msgid "" +"(1763-1814) She was born in Martinique and arrived in Paris at the age of " +"16. Her first hushband Alexandre de Beauharnais was guillotined during the " +"French Revolution." +msgstr "(1763-1814) Née à la Martinique elle arrive à Paris à 16 ans et épouse son premier mari Alexandre de Beauharnais guillotiné pendant la Révolution." + +#: src/tree.py:426 +msgid "" +"(1791-1847) She was daughter of the king of Austria and became Napoleon's " +"second wife." +msgstr "(1791-1847) Fille du roi d'Autriche, c'est la deuxième épouse de Napoléon." + +#: src/tree.py:431 +msgid "" +"(1811-1832) When the French Empire fell once and for all, he followed his " +"mother to Austria and died at a very young age, only 21 years old." +msgstr "(1811-1832) Il est censé reigner à la suite de son père mais à la chute de l'Empire, il suit sa mère en Autriche où il meurt très jeune à 21 ans" + +#: src/tree.py:436 +msgid "" +"(1783-1837) She had a gift for music and wrote and composed romantic songs. " +"She married Louis and became Queen of Holland." +msgstr "(1783-1837) Douée pour la musique elle écrit et compose des chansons. En épousant Louis, elle devient reine de Hollande." + +#: src/tree.py:440 +msgid "" +"(1808-1873) He had to spend a large part of his childhood in Switzerland " +"with his mother. He became officer then president in 1848." +msgstr "(1808-1873) Exilé en Suisse avec sa mère, il devient officier puis est élu président en France en 1848." + +#: src/tree.py:445 +msgid "" +"(1826-1920) Daughter of a Spanish count, she became Empress through her " +"marriage in 1853." +msgstr "(1826-1920) Fille d'un comte espagnol, elle devient impératrice par son mariage en 1853." + +#: src/tree.py:449 +msgid "" +"(1856-1879) When the French army was beaten by the Prussian army, he had to " +"leave France. He chose to become a soldier for the English and was killed in " +"South Africa." +msgstr "(1856-1879) Une fois son père battu par l'armée prussienne, il quitte la France pour devenir soldat anglais et est tué en Afrique du Sud." diff --git a/src/tree.py b/src/tree.py index e8183a3..189b712 100644 --- a/src/tree.py +++ b/src/tree.py @@ -1,8 +1,12 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + # Base import import pickle import tempfile import os import gtk +from gettext import gettext as _ # Local import from person import Person @@ -333,9 +337,9 @@ class Tree: # Create the samples family -def empty_tree(): +def empty_tree(xoOwner): tree = Tree() - tree.root = tree.Person("", "M") + tree.root = tree.Person(xoOwner, "M") tree.root.isroot = True return tree @@ -367,19 +371,19 @@ def sample_family1(): ub = tree.Union(jo, j) ub.append_child(tree.Person("Charlie", "F")) - rs = tree.Person("Renee", "F") + rs = tree.Person("Renée", "F") vm = tree.Person("Vivien", "M") urv = tree.Union(vm, rs) urv.append_child(j) - jr = tree.Person("Jean-Rene", "M") + jr = tree.Person("Jean-René", "M") ua = tree.Union(jr, tree.Person("Micheline", "F")) ua.append_child(a) - i = tree.Person("Irene", "F") + i = tree.Person("Irène", "F") ua.append_child(i) ui = tree.Union(tree.Person("Nathan", "M"), i) ui.append_child(tree.Person("Marie", "F")) - ui.append_child(tree.Person("Noel", "M")) + ui.append_child(tree.Person("Noël", "M")) ui.append_child(tree.Person("Thierry", "M")) uc = tree.Union(c, tree.Person("Clarah", "F")) @@ -399,29 +403,51 @@ def sample_family1(): def sample_family2(): # Napoleon family tree = Tree() - tree.root = p1 = tree.Person("Chales-Marie Bonaparte", "M") + tree.root = p1 = tree.Person("Charles-Marie Bonaparte", "M") + p1.description = _("(1746-1785) This young Corsican aristocrat studied law in Italy and Corsica.") + p1.image = gtk.gdk.pixbuf_new_from_file("images/napo_p1.jpg") p2 = tree.Person("Letizia Ramolino", "F") + p2.description = _("(1750-1836) She married very young, at 14 years old. In Corsica, she was known as the 'little marvel', famed for her beauty far and wide.") + p2.image = gtk.gdk.pixbuf_new_from_file("images/napo_p2.jpg") u1 = tree.Union(p2, p1) - p4 = tree.Person("Napoleon", "M") + p4 = tree.Person("Napoléon Ier", "M") + p4.description = _("(1769-1821) He was born on 15 August 1769 in Ajaccio, Corsica. At the age of 10, he left Corsica with his older brother Joseph to study at the Ecole Militaire in Paris.") + p4.image = gtk.gdk.pixbuf_new_from_file("images/napo_p4.jpg") p6 = tree.Person("Louis Bonaparte", "M") + p6.description = _("(1778-1846) While still a child, Louis joined his brother Napoleon in Paris. He accompanied his brother on his early military campaigns and became King of Holland at the age of 28.") + p6.image = gtk.gdk.pixbuf_new_from_file("images/napo_p6.jpg") u1.append_child(p4) u1.append_child(p6) - p3 = tree.Person("Josephine", "F") + p3 = tree.Person("Joséphine", "F") + p3.description = _("(1763-1814) She was born in Martinique and arrived in Paris at the age of 16. Her first hushband Alexandre de Beauharnais was guillotined during the French Revolution.") + p3.image = gtk.gdk.pixbuf_new_from_file("images/napo_p3.jpg") u2 = tree.Union(p4, p3) p5 = tree.Person("Marie-Louise d'Autriche", "F") + p5.description = _("(1791-1847) She was daughter of the king of Austria and became Napoleon's second wife.") + p5.image = gtk.gdk.pixbuf_new_from_file("images/napo_p5.jpg") u3 = tree.Union(p4, p5) - p10 = tree.Person("Napoleon II", "M") + p10 = tree.Person("Napoléon II", "M") + p10.description = _("(1811-1832) When the French Empire fell once and for all, he followed his mother to Austria and died at a very young age, only 21 years old.") + p10.image = gtk.gdk.pixbuf_new_from_file("images/napo_p10.jpg") u3.append_child(p10) p7 = tree.Person("Hortense de Beauharnais", "F") + p7.description = _("(1783-1837) She had a gift for music and wrote and composed romantic songs. She married Louis and became Queen of Holland.") + p7.image = gtk.gdk.pixbuf_new_from_file("images/napo_p7.jpg") u4 = tree.Union(p6, p7) - p8 = tree.Person("Napoleon III", "M") + p8 = tree.Person("Napoléon III", "M") + p8.description = _("(1808-1873) He had to spend a large part of his childhood in Switzerland with his mother. He became officer then president in 1848.") + p8.image = gtk.gdk.pixbuf_new_from_file("images/napo_p8.jpg") u4.append_child(p8) p9 = tree.Person("Eugenie de Palafox-Guzman", "F") + p9.description = _("(1826-1920) Daughter of a Spanish count, she became Empress through her marriage in 1853.") + p9.image = gtk.gdk.pixbuf_new_from_file("images/napo_p9.jpg") u5 = tree.Union(p8, p9) - p11 = tree.Person("Louis Napoleon", "M") + p11 = tree.Person("Louis Napoléon", "M") + p11.description = _("(1856-1879) When the French army was beaten by the Prussian army, he had to leave France. He chose to become a soldier for the English and was killed in South Africa.") + p11.image = gtk.gdk.pixbuf_new_from_file("images/napo_p11.jpg") u5.append_child(p11) tree.root.isroot = True diff --git a/sugardummy.py b/sugardummy.py index 5ebea5e..58f8151 100644 --- a/sugardummy.py +++ b/sugardummy.py @@ -12,6 +12,7 @@ class activity: def __init__(self, handle): self.window = gtk.Window() + self.window.set_size_request(1200, 900) self.window.set_title("Roots") self.window.connect("destroy", self.on_close) self.metadata = {} @@ -33,6 +34,7 @@ class activity: def set_toolbox(self, toolbox): self._toolbox = toolbox + self._toolbox.set_size_request(1200, 120) def read_file(self, file_path): pass @@ -92,4 +94,39 @@ class ToolButton: def connect(self, event, callback): self.methods[event] = callback + +# Dummy class for presence +class PresenceService: + "Class used to generate unique identifier" + + class __impl: + "Singleton class" + def __init__(self): + self.props = Props() + + def get_instance(self): + return self + + def get_owner(self): + return self + + __instance=None + + def __init__(self): + "Constructor, create Singleton if don't exist" + if PresenceService.__instance is None: + PresenceService.__instance = PresenceService.__impl() + + self.__dict__['_PresenceService__instance'] = PresenceService.__instance + + def __getattr__(self, attr): + "Pass attr retrieving to Singleton" + return getattr(self.__instance, attr) + +# Dummy class for presence props +class Props: + + def __init__(self): + self.nick = "XO name" +presenceservice = PresenceService() -- cgit v0.9.1