From 1d062b1e7397b9413f4f73efb451bb8d890ab296 Mon Sep 17 00:00:00 2001 From: isen Date: Fri, 09 Oct 2009 04:09:42 +0000 Subject: Merge branch 'lp426452_suite' into lp426452 lp426452_suite was the generalisation of the tail drawing (n tails) Conflicts: addons/bubblemessage.py setup.cfg tutorius/overlayer.py --- (limited to 'tutorius') diff --git a/tutorius/constraints.py b/tutorius/constraints.py index 36abdfb..455ede3 100644 --- a/tutorius/constraints.py +++ b/tutorius/constraints.py @@ -204,4 +204,22 @@ class FileConstraint(Constraint): if not os.path.isfile(value): raise FileConstraintError("Non-existing file : %s"%value) return - + + +class SameTypeConstraintError(Exception): + pass + +class SameTypeConstraint(Constraint): + """ + Ensures that the list is not empty and that properties of the list have the same type. + """ + + def validate(self, value): + if len(value)==0: + raise SameTypeConstraintError("The list is empty") + for i in value: + if i.type != value[0].type: + raise SameTypeConstraintError("Properties have diffferent type") + return + + diff --git a/tutorius/creator.py b/tutorius/creator.py index 7455ecb..82d0628 100644 --- a/tutorius/creator.py +++ b/tutorius/creator.py @@ -395,7 +395,7 @@ class EditToolBox(gtk.Window): def _list_prop_changed(self, widget, evt, action, propname, idx): try: - getattr(action, propname)[idx] = int(widget.get_text()) + getattr(action, propname)[idx] = eval(widget.get_text())#chercher autre méthode pour remplacer eval. coup de perf. non sécu except ValueError: widget.set_text(str(getattr(action, propname)[idx])) self.__parent._creator._action_refresh_cb(None, None, action) diff --git a/tutorius/overlayer.py b/tutorius/overlayer.py index 592b8f0..4ee5241 100644 --- a/tutorius/overlayer.py +++ b/tutorius/overlayer.py @@ -157,14 +157,14 @@ class TextBubble(gtk.Widget): A CanvasDrawableWidget drawing a round textbox and a tail pointing to a specified widget. """ - def __init__(self, text, speaker=None, tailpos=[0,0], tailpos2=[0,0]): + def __init__(self, text, speaker=None, tailpos=[[0,0],[0,0],[0,0]]):#list with N éléments (cf bublemessage.py) """ Creates a new cairo rendered text bubble. @param text the text to render in the bubble @param speaker the widget to compute the tail position from - @param tailpos (optional) position relative to the bubble to use as - the tail position, if no speaker + @param tailpos (optional) list of positions relative to the bubble to use as + tails position, if no speaker """ gtk.Widget.__init__(self) @@ -175,8 +175,7 @@ class TextBubble(gtk.Widget): self.label = text self.speaker = speaker - self.tailpos = tailpos - self.tailpos2= tailpos2 + self.tailpos = tailpos self.line_width = 5 self.padding = 20 @@ -199,23 +198,16 @@ class TextBubble(gtk.Widget): # # TODO fetch speaker coordinates - # draw bubble tail if present - if self.tailpos != [0,0]: - context.move_to(xradius-width/4, yradius) - context.line_to(self.tailpos[0], self.tailpos[1]) - context.line_to(xradius+width/4, yradius) - context.set_line_width(self.line_width) - context.set_source_rgb(*xo_line_color) - context.stroke_preserve() - - # draw bubble tail2 if present - if self.tailpos2 != [0,0]: - context.move_to(xradius-width/4, yradius) - context.line_to(self.tailpos2[0], self.tailpos2[1]) - context.line_to(xradius+width/4, yradius) - context.set_line_width(self.line_width) - context.set_source_rgb(*xo_line_color) - context.stroke_preserve() + + # draw bubble tails if present + for i in range(len(self.tailpos)): + if self.tailpos[i] != [0,0]: + context.move_to(xradius-width/4, yradius) + context.line_to(self.tailpos[i][0], self.tailpos[i][1]) + context.line_to(xradius+width/4, yradius) + context.set_line_width(self.line_width) + context.set_source_rgb(*xo_line_color) + context.stroke_preserve() # bubble border context.move_to(width-self.padding, 0.0) @@ -237,23 +229,16 @@ class TextBubble(gtk.Widget): context.set_source_rgb(*xo_fill_color) context.fill() - # bubble painting. Redrawing the inside after the tail will combine - if self.tailpos != [0,0]: - context.move_to(xradius-width/4, yradius) - context.line_to(self.tailpos[0], self.tailpos[1]) - context.line_to(xradius+width/4, yradius) - context.set_line_width(self.line_width) - context.set_source_rgb(*xo_fill_color) - context.fill() - - # bubble painting. Redrawing the inside after the tail will combine - if self.tailpos2 != [0,0]: - context.move_to(xradius-width/4, yradius) - context.line_to(self.tailpos2[0], self.tailpos2[1]) - context.line_to(xradius+width/4, yradius) - context.set_line_width(self.line_width) - context.set_source_rgb(*xo_fill_color) - context.fill() + + # bubble painting. Redrawing the inside after tails will combine + for i in range(len(self.tailpos)): + if self.tailpos[i] != [0,0]: + context.move_to(xradius-width/4, yradius) + context.line_to(self.tailpos[i][0], self.tailpos[i][1]) + context.line_to(xradius+width/4, yradius) + context.set_line_width(self.line_width) + context.set_source_rgb(*xo_fill_color) + context.fill() context.set_source_rgb(1.0, 1.0, 1.0) pangoctx = pangocairo.CairoContext(context) diff --git a/tutorius/properties.py b/tutorius/properties.py index 7423d25..65059b2 100644 --- a/tutorius/properties.py +++ b/tutorius/properties.py @@ -20,10 +20,7 @@ also use the TPropContainer), with the added benefit of having builtin dialog prompts and constraint validation. """ -from sugar.tutorius.constraints import Constraint, \ - UpperLimitConstraint, LowerLimitConstraint, \ - MaxSizeConstraint, MinSizeConstraint, \ - ColorConstraint, FileConstraint, BooleanConstraint, EnumConstraint +from sugar.tutorius.constraints import * from copy import copy class TPropContainer(object): @@ -207,8 +204,12 @@ class TArrayProperty(TutoriusProperty): self.type = "array" self.max_size_limit = MaxSizeConstraint(max_size_limit) self.min_size_limit = MinSizeConstraint(min_size_limit) + self.indexeur = value #stock la value, pour l'indexation self.default = self.validate(value) - + + #def __getitem__(self, key): # obligation de redéfinir l'indexation + # return self.indexeur[key] # + class TColorProperty(TutoriusProperty): """ Represents a RGB color with 3 8-bit integer values. @@ -310,5 +311,36 @@ class TAddonProperty(TutoriusProperty): if isinstance(value, TPropContainer): return super(TAddonProperty, self).validate(value) raise ValueError("Expected TPropContainer instance as TaddonProperty value") + + +class TPositionProperty(TutoriusProperty): + """ + Represents a tuple of two int. The first value is the x position and the second the y position + """ + def __init__(self, (x, y)): + TutoriusProperty.__init__(self) + self.type = "position" + self._x=x or 0 + self._y=y or 0 + self.default = self.validate((self._x,self._y)) + #voir les contraintes ou créer x en TintProperty + #convertir en int ou raise error idem sur Tintproperty + + #contrainte générique du style is 'type' qui essai de convertir les éléments d'une séquence + + #contraintes deux élements + + +class TArrayOneTypeProperty(TArrayProperty): + """ + Represents an array list of properties. Can have a maximum (and/or minimum) number of element + limit. All the elements in the list must have the same type. The list must not be empty + """ + def __init__(self, value, min_size_limit=None, max_size_limit=None): + TArrayProperty.__init__(self, value, min_size_limit, max_size_limit) + self.type = "typedlist" + self.required_type = SameTypeConstraint() + self.default = self.validate(value) + -- cgit v0.9.1