Ejemplo n.º 1
0
 def randomize(self):
     """Set red, green, blue and alpha to random values."""
     cpool = model_constraintpool.ConstraintPool.get_pool()
     constraints = cpool.get(self, COLOR_CONSTRAINT)
     #TODO prefer a single constraint
     #TODO Remove pushing colorconstraint_none by a more generalized solution
     if 'colorconstraint_none' in constraints and random.random() < 0.5:
         self.constraint = ka_extensionpoint.create(
             random.choice(['colorconstraint_none']), self.path)
     else:
         self.constraint = ka_extensionpoint.create(
             random.choice(constraints), self.path)
     self.rgba = self.constraint.randomize()
Ejemplo n.º 2
0
 def create(self, factory_key, *params):
     """
     pre: factory_key in self.factory_keys
     post: __return__ is not None
     """
     return ka_extensionpoint.create(self.category + '_' + factory_key,
                                     *params)
Ejemplo n.º 3
0
 def randomize(self):
     """Set radian and offset to random values."""
     cpool = model_constraintpool.ConstraintPool.get_pool()
     constraints = cpool.get(self, DIRECTION_CONSTRAINT)
     self.constraint = ka_extensionpoint.create(random.choice(constraints),
                                                self.path)
     self.radian, self.offset = self.constraint.randomize()
Ejemplo n.º 4
0
 def randomize(self):
     """Set x_pos, y_pos to random values."""
     cpool = model_constraintpool.ConstraintPool.get_pool()
     constraints = cpool.get(self, POSITION_CONSTRAINT)
     self.constraint = ka_extensionpoint.create(random.choice(constraints),
                                                self.path)
     self.x_pos, self.y_pos = self.constraint.randomize()
Ejemplo n.º 5
0
 def __init__(self, trunk, radian, offset):
     """Direction constructor
     """
     super(Direction, self).__init__(trunk)
     cpool = model_constraintpool.ConstraintPool.get_pool()
     constraint_name = cpool.get(self, DIRECTION_CONSTRAINT)[0]
     self.constraint = ka_extensionpoint.create(constraint_name, self.path)
     self.radian, self.offset = self.constraint.filter(radian, offset)
Ejemplo n.º 6
0
 def __init__(self, trunk, x_pos, y_pos):
     """Position constructor
     """
     super(Position, self).__init__(trunk)
     cpool = model_constraintpool.ConstraintPool.get_pool()
     constraint_name = cpool.get(self, POSITION_CONSTRAINT)[0]
     self.constraint = ka_extensionpoint.create(constraint_name, self.path)
     self.x_pos, self.y_pos = self.constraint.filter(x_pos, y_pos)
Ejemplo n.º 7
0
 def mutate(self):
     """Make small random changes in hue, lightness, saturation."""
     if model_random.is_mutating():
         if model_random.is_mutating():
             cpool = model_constraintpool.ConstraintPool.get_pool()
             constraints = cpool.get(self, COLOR_CONSTRAINT)
             self.constraint = ka_extensionpoint.create(
                 random.choice(constraints), self.path)
         self.rgba = self.constraint.mutate(self.rgba)
 def __init__(self, trunk, words):
     """Buzzword constructor
     pre: len(words) > 0
     """
     super(Buzzword, self).__init__(trunk)
     cpool = model_constraintpool.ConstraintPool.get_pool()
     constraint_name = cpool.get(self, BUZZWORD_CONSTRAINTS)[0]
     self.constraint = ka_extensionpoint.create(constraint_name, self.path)
     self.wordlist = words
Ejemplo n.º 9
0
 def mutate(self):
     """Make small random changes in radian and offset."""
     if model_random.is_mutating():
         if model_random.is_mutating():
             cpool = model_constraintpool.ConstraintPool.get_pool()
             constraints = cpool.get(self, DIRECTION_CONSTRAINT)
             self.constraint = ka_extensionpoint.create(
                 random.choice(constraints), self.path)
         self.radian, self.offset = self.constraint.mutate(
             self.radian, self.offset)
Ejemplo n.º 10
0
 def mutate(self):
     """Make small random changes in position."""
     if model_random.is_mutating():
         if model_random.is_mutating():
             cpool = model_constraintpool.ConstraintPool.get_pool()
             constraints = cpool.get(self, POSITION_CONSTRAINT)
             self.constraint = ka_extensionpoint.create(
                 random.choice(constraints), self.path)
         self.x_pos, self.y_pos = self.constraint.mutate(
             self.x_pos, self.y_pos)
Ejemplo n.º 11
0
 def on_exportpng_activate(self, *args):
     """Publish single protozoon to all other buddies.
     pre: len(args) >= 1
     """
     ka_debug.info('on_exportpng_activate [%s]' % args[0].get_name())
     pix = ka_controller.name_to_index(args[0].get_name())
     exporter = ka_extensionpoint.create('exporter_png',
                                         self.model.protozoans[pix],
                                         self._activity_root)
     preference = ka_preference.Preference.instance()
     export_size = preference.get(ka_preference.EXPORT_SIZE)
     exporter.export(*export_size)
Ejemplo n.º 12
0
 def __init__(self, trunk, red, green, blue, alpha):
     """Color constructor
     pre: 0.0 <= red <= 1.0
     pre: 0.0 <= green <= 1.0
     pre: 0.0 <= blue <= 1.0
     pre: 0.0 <= alpha <= 1.0
     """
     super(Color, self).__init__(trunk)
     cpool = model_constraintpool.ConstraintPool.get_pool()
     constraint_name = cpool.get(self, COLOR_CONSTRAINT)[0]
     self.constraint = ka_extensionpoint.create(constraint_name, self.path)
     self.rgba = self.constraint.filter((red, green, blue, alpha))
     self.base_diff_hue = 0
     self.base_diff_lightness = 0
     self.base_diff_saturation = 0
Ejemplo n.º 13
0
 def task_explain(self, task, *args, **kwargs):
     """Render zoom view of protozoon.
     pre: len(args) >= 1
     """
     protozoon = args[0]
     #        ka_debug.info('task_explain entry: ')
     folder = os.path.join(self._activity_root, 'tmp')
     ep_key = 'html'
     formater = ka_extensionpoint.create('formater_' + ep_key, 'index',
                                         protozoon.get_unique_id(), folder)
     protozoon.explain(task, formater)
     file_path = formater.get_absolutename(ep_key)
     formater.write_html_file(file_path)
     self._produced_files_list.extend(formater.produced_files_list)
     self._produced_files_list.append(formater.get_pathname())
     self.set_uri('file://' + file_path)
Ejemplo n.º 14
0
 def create_pages(self):
     """
     Add optional pages to kandid notebook
     """
     page_names = ka_extensionpoint.list_extensions('page')
     for name in page_names:
         page_controller = ka_extensionpoint.create(name, self,
                                                    self._widget_list,
                                                    self._activity_root,
                                                    self._started_anew)
         self._pages.append(page_controller)
     self._pages.sort(cmp=KandidController.numeric_compare)
     for page_controller in self._pages:
         self._widget._notebook.append_page(*page_controller.create_gui())
         page_controller.autoconnect_events()
         page_controller.localize()
         page_controller.activate_gui()
Ejemplo n.º 15
0
    def randomize(self):
        """Create a random word list.
        Result is a subset of the word list from
        extension point 'ep_buzzwordconstraint'.
        """
        cpool = model_constraintpool.ConstraintPool.get_pool()
        constraints = cpool.get(self, BUZZWORD_CONSTRAINTS)
        self.constraint = ka_extensionpoint.create(random.choice(constraints),
                                                   self.path)

        full_wordlist = self.constraint.get_wordlist()
        approximate_count = random.randint(1, len(full_wordlist) - 1)
        self.wordlist = []
        self.wordlist.append(random.choice(full_wordlist))
        for dummy in range(approximate_count):
            candidate = random.choice(full_wordlist)
            if candidate not in self.wordlist:
                self.wordlist.append(candidate)