diff options
author | Thomas Jourdan <b.vehikel@googlemail.com> | 2009-09-04 16:02:30 (GMT) |
---|---|---|
committer | Thomas Jourdan <b.vehikel@googlemail.com> | 2009-09-04 16:02:30 (GMT) |
commit | 05f2a6684a42209e30fa2fcd0d7cb014c4663a39 (patch) | |
tree | 6b3cfd307e94f6b640ff985d141daa82b8fef7c1 /ka_controller.py | |
parent | 7ee9a0b36814d90954929a4fead2bf9ff4314c19 (diff) |
Additional samplers added. Using set_sensitive to disable GUI elements.
Diffstat (limited to 'ka_controller.py')
-rw-r--r-- | ka_controller.py | 75 |
1 files changed, 47 insertions, 28 deletions
diff --git a/ka_controller.py b/ka_controller.py index 1163e80..3ea46b8 100644 --- a/ka_controller.py +++ b/ka_controller.py @@ -74,15 +74,16 @@ class KandidController(object): key = 'on_incoming_#_popup'.replace('#', strix) events[key] = self.on_incoming_popup self._canvas.widgetTree.signal_autoconnect(events) - self._update_gui() + self._update_population_gui() + self._update_incomming_gui() def _update_model(self, in_model): if in_model: self.model = in_model self.model._state = model_population.STATE_EVOLVED - self._update_gui() + self._update_population_gui() - def _update_gui(self): + def _update_population_gui(self): for cell_index in range(self.model.size): strix = str(cell_index) key = 'fitness_#'.replace('#', strix) @@ -90,10 +91,20 @@ class KandidController(object): set_value(self.model.fitness[cell_index]) self._canvas.widgetTree.get_widget('flurrySpinButton'). \ set_value(self.model.flurry_rate) + good, moderate, poor = self.model.classify() + self._canvas.widgetTree.get_widget('breedGenerationButton'). \ + set_sensitive(len(poor) > 0) + self._canvas.widgetTree.get_widget('randomGenerationButton'). \ + set_sensitive(len(poor) > 0) + + def _update_incomming_gui(self): + for index in range(self.incoming.capacity): + self._canvas.widgetTree.get_widget('incomingbutton_' + str(index)). \ + set_sensitive(len(self.incoming.incoming_protozoans) > index) def _draw_from_cache(self, widget, cell_index): if self.surface_cache.has_key(cell_index): - ka_debug.info('_draw_from_cache: ' + widget.name + ' ' + str(cell_index)) +# ka_debug.info('_draw_from_cache: ' + widget.name + ' ' + str(cell_index)) ctx = self._create_context(widget) ctx.set_operator(cairo.OPERATOR_SOURCE) ctx.set_source_surface(self.surface_cache[cell_index]) @@ -104,18 +115,18 @@ class KandidController(object): pre: widget is not None """ # draw precalculated protozoon stored in the surface cache. - ka_debug.info('on_drawingarea_expose: ' + widget.name + ' ' - + str(widget.allocation.width) - + 'x' + str(widget.allocation.height)) +# ka_debug.info('on_drawingarea_expose: ' + widget.name + ' ' +# + str(widget.allocation.width) +# + 'x' + str(widget.allocation.height)) self._draw_from_cache(widget, _name_to_index(widget.name)) def on_drawingarea_size_allocate(self, widget, event): """ New size for drawing area available. pre: widget is not None """ - ka_debug.info('on_drawingarea_size_allocate: ' + widget.name + ' ' - + str(widget.allocation.width) - + 'x' + str(widget.allocation.height)) +# ka_debug.info('on_drawingarea_size_allocate: ' + widget.name + ' ' +# + str(widget.allocation.width) +# + 'x' + str(widget.allocation.height)) self._start_calculation([_name_to_index(widget.name)]) def _create_context(self, widget): @@ -136,13 +147,14 @@ class KandidController(object): (args[0].get_value(), args[0].get_name())) self.model.fitness[_name_to_index(args[0].get_name())] \ = args[0].get_value() + self._update_population_gui() def on_breed_generation(self, *args): if ka_task.is_completed(): - ka_debug.info('on_breed_generation entry') +# ka_debug.info('on_breed_generation entry') ka_task.GeneratorTask(self.task_breed_generation, self.on_model_completed).start() - ka_debug.info('on_breed_generation exit') +# ka_debug.info('on_breed_generation exit') else: ka_debug.info('on_breed_generation ignored') @@ -159,12 +171,12 @@ class KandidController(object): """ pre: len(args) == 1 """ - ka_debug.info('on_model_completed entry') +# ka_debug.info('on_model_completed entry') for cell_index in args[0]: self._canvas.widgetTree.get_widget('vbox_' + str(cell_index)). \ set_sensitive(False) self._start_calculation(args[0]) - ka_debug.info('on_model_completed exit') +# ka_debug.info('on_model_completed exit') def _start_calculation(self, concerned): """ @@ -174,7 +186,7 @@ class KandidController(object): for cell_index in concerned: widget = self._canvas.widgetTree.get_widget('drawingarea_' + str(cell_index)) - task = ka_task.GeneratorTask(self.task_draw, + task = ka_task.GeneratorTask(self.task_render, self.on_image_completed) task.start(self.model.protozoans[cell_index], cell_index, widget.allocation.width, widget.allocation.height) @@ -183,35 +195,35 @@ class KandidController(object): """ pre: len(args) == 0 """ - ka_debug.info('task_breed_generation entry') +# ka_debug.info('task_breed_generation entry') new_indices = self.model.breed() - ka_debug.info('task_breed_generation exit') +# ka_debug.info('task_breed_generation exit') return new_indices def task_random_generation(self, *args, **kwargs): """ pre: len(args) == 0 """ - ka_debug.info('task_random_generation entry') +# ka_debug.info('task_random_generation entry') new_indices = self.model.random() - ka_debug.info('task_random_generation exit') +# ka_debug.info('task_random_generation exit') return new_indices - def task_draw(self, *args, **kwargs): + def task_render(self, *args, **kwargs): """ pre: len(args) == 4 """ protozoon, cell_index, width, height = args[0], args[1], args[2], args[3] - ka_debug.info('task_draw entry: ' + str(cell_index)) +# ka_debug.info('task_render entry: ' + str(cell_index)) surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) ctx = cairo.Context(surface) - protozoon.draw(ctx, width, height) + protozoon.render(ctx, width, height) self.surface_cache[cell_index] = surface - ka_debug.info('task_draw exit: ' + str(cell_index)) +# ka_debug.info('task_render exit: ' + str(cell_index)) return cell_index def on_image_completed(self, *args): - ka_debug.info('on_image_completed: ' + str(args[0])) +# ka_debug.info('on_image_completed: ' + str(args[0])) cell_index = args[0] widget = self._canvas.widgetTree.get_widget('drawingarea_' + str(cell_index)) @@ -249,7 +261,7 @@ class KandidController(object): """ ka_debug.info('on_favorite_activate [%s]' % args[0].get_name()) self.model.raise_fitness(_name_to_index(args[0].get_name())) - self._update_gui() + self._update_population_gui() def on_awfull_activate(self, *args): """Set last ranking for this protozoon. @@ -257,7 +269,7 @@ class KandidController(object): """ ka_debug.info('on_awfull_activate [%s]' % args[0].get_name()) self.model.reduce_fitness(_name_to_index(args[0].get_name())) - self._update_gui() + self._update_population_gui() def on_received(self, code_type, code_element, code_md5): """Update population or protozoon preview when received from others.""" @@ -274,6 +286,7 @@ class KandidController(object): elif code_type == kandidtube.SEND_PROTOZOON: self.incoming.append_protozoon(model_population.from_buffer(code_element)) inbox_widget.queue_draw() + self._update_incomming_gui() else: ka_debug.err('Somebody called me using an illegal type [%s]' % code_type) @@ -296,6 +309,11 @@ class KandidController(object): def _show_popup(self, widget, event, menu): ka_debug.info('%s [%s]' % (menu, widget.name)) + index = _name_to_index(menu) + self._canvas.widgetTree.get_widget('favorite_menuitem_' + str(index)). \ + set_sensitive(self.model.fitness[index] < 9.0) + self._canvas.widgetTree.get_widget('awfull_menuitem_' + str(index)). \ + set_sensitive(self.model.fitness[index] > 0.0) popup_menu = self._canvas.widgetTree.get_widget(menu) popup_menu.popup(None, None, None, event.button, event.time) @@ -304,21 +322,22 @@ class KandidController(object): new_at = self.incoming.accept_protozoon(self.model, \ _name_to_index(menu_item.parent.name)) self._start_calculation([new_at]) -# self._update_gui() inbox_widget = self._canvas.widgetTree.get_widget('incomingBox') + self._update_incomming_gui() inbox_widget.queue_draw() def on_decline_incoming(self, menu_item): ka_debug.info('on_decline_incoming [%s]' % menu_item.parent.name) self.incoming.decline_protozoon(_name_to_index(menu_item.parent.name)) inbox_widget = self._canvas.widgetTree.get_widget('incomingBox') + self._update_incomming_gui() inbox_widget.queue_draw() def on_incomingarea_expose(self, widget, event): """ Repaint image of a single protozoon inside incoming area. pre: widget is not None """ - ka_debug.info('on_incomingarea_expose: ' + widget.name) +# ka_debug.info('on_incomingarea_expose: ' + widget.name) self.incoming.draw(_name_to_index(widget.name), \ self._create_context(widget), \ widget.allocation.width, widget.allocation.height) |