diff options
Diffstat (limited to 'ka_incoming.py')
-rw-r--r-- | ka_incoming.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/ka_incoming.py b/ka_incoming.py new file mode 100644 index 0000000..a97dbc4 --- /dev/null +++ b/ka_incoming.py @@ -0,0 +1,68 @@ +# coding: UTF8 +# Copyright 2009 Thomas Jourdan +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import ka_debug + +class KandidIncoming(object): + """ + inv: 0 <= len(self.incoming) <= self.capacity + inv: self.capacity > 0 + """ + + def __init__(self, capacity): + self.capacity = capacity + self.incoming = [] + + def append_protozoon(self, incoming_protozoon): + """ Append protozoon from incoming list and manage capacity. + pre: incoming_protozoon is not None + """ + ka_debug.info('Append protozoon') + while len(self.incoming) >= self.capacity: + self.incoming[0:1] = [] + self.incoming.append(incoming_protozoon) + + def accept_protozoon(self, model, index): + """ Move protozoon from incoming list to image population. + pre: 0 <= index < self.capacity + """ + new_at = -1 + if index < len(self.incoming): + ka_debug.info('accept incoming protozoon %u' % index) + new_at = model.replace(self.incoming[index]) + self.incoming[index:1] = [] + return new_at + + def decline_protozoon(self, index): + """ Remove protozoon from incoming list + pre: 0 <= index < self.capacity + """ + if index < len(self.incoming): + ka_debug.info('decline incoming protozoon %u' % index) + self.incoming[index:1] = [] + + def draw(self, index, ctx, width, height): + """ Repaint all protozoon images inside incoming area. + pre: 0 <= index < self.capacity + pre: ctx is not None + pre: width > 0 + pre: height > 0 + """ + if index < len(self.incoming): + # draw protozoon + self.incoming[index].draw(ctx, width, height) + |