Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArt
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2011-03-14 19:05:19 (GMT)
committer Walter Bender <walter.bender@gmail.com>2011-03-14 19:05:19 (GMT)
commit36f997b9b587448f1439a89a9f4f5dfd218a42f9 (patch)
tree7bdae553a4e5c26ddb4be4aa8f99f7d2bebabf22 /TurtleArt
parente5b14faacc882a8f14d86bcda309263d9b6b3957 (diff)
fixed more logic errors; data type mismatches that prevented sharing
Diffstat (limited to 'TurtleArt')
-rw-r--r--TurtleArt/tacollaboration.py65
-rw-r--r--TurtleArt/taturtle.py2
-rw-r--r--TurtleArt/tawindow.py10
3 files changed, 45 insertions, 32 deletions
diff --git a/TurtleArt/tacollaboration.py b/TurtleArt/tacollaboration.py
index 51ba471..fb97ba7 100644
--- a/TurtleArt/tacollaboration.py
+++ b/TurtleArt/tacollaboration.py
@@ -49,7 +49,7 @@ class Collaboration():
""" A simplistic sharing model: the sharer is the master """
self._tw = tw
self._tw.send_event = self.send_event
- self._tw.turtle_dictionary = {}
+ self._tw.remote_turtle_dictionary = {}
self._activity = activity
self._setup_dispatch_table()
@@ -63,7 +63,6 @@ class Collaboration():
self.owner = owner
self._tw.buddies.append(self.owner)
self._share = ''
-
self._activity.connect('shared', self._shared_cb)
self._activity.connect('joined', self._joined_cb)
@@ -97,8 +96,7 @@ class Collaboration():
self.initiating = True
self.waiting_for_turtles = False
- self._tw.turtle_dictionary = self._get_dictionary()
- self._tw.remote_turtles = []
+ self._tw.remote_turtle_dictionary = self._get_dictionary()
debug_output('I am sharing...', self._tw.running_sugar)
@@ -170,10 +168,10 @@ class Collaboration():
self.event_received_cb)
# Now that we have the tube, we can ask for the turtle dictionary.
- if self.waiting_for_turtles:
+ if self.waiting_for_turtles: # A joiner must wait for turtles.
debug_output('Sending a request for the turtle dictionary',
self._tw.running_sugar)
- # we need to send our own nick and colors
+ # We need to send our own nick, colors, and turtle position
colors = self._get_colors()
event = 't|' + data_to_string([self._get_nick(), colors])
debug_output(event, self._tw.running_sugar)
@@ -209,37 +207,51 @@ class Collaboration():
self.chattube.SendText(entry)
def _turtle_request(self, payload):
+ ''' incoming turtle from a joiner '''
if payload > 0:
[nick, colors] = data_from_string(payload)
- if nick != self._tw.nick:
+ if nick != self._tw.nick: # It is not me.
# There may not be a turtle dictionary.
- if hasattr(self._tw, 'turtle_dictionary'):
- self._tw.turtle_dictionary[nick] = colors
+ if hasattr(self._tw, 'remote_turtle_dictionary'):
+ self._tw.remote_turtle_dictionary[nick] = colors
else:
- self._tw.turtle_dictionary = {nick: colors}
- if hasattr(self._tw, 'remote_turtles'):
- self._tw.remote_turtles.append(nick)
- else:
- self._tw.remote_turtles = [nick]
+ self._tw.remote_turtle_dictionary = self._get_dictionary()
# Add new turtle for the joiner.
self._tw.canvas.set_turtle(nick, colors)
- self._tw.label_remote_turtle(nick)
- # Sharer should send turtle dictionary.
+ self._tw.label_remote_turtle(nick, colors)
+
+ # Sharer should send the updated remote turtle dictionary to everyone.
if self.initiating:
- event_payload = data_to_string(self._tw.turtle_dictionary)
+ if not self._tw.nick in self._tw.remote_turtle_dictionary:
+ self._tw.remote_turtle_dictionary[self._tw.nick] = \
+ self._get_colors()
+ event_payload = data_to_string(self._tw.remote_turtle_dictionary)
self.send_event('T|' + event_payload)
def _receive_turtle_dict(self, payload):
+ ''' Any time there is a new joiner, an updated turtle dictionary is
+ circulated. '''
if self.waiting_for_turtles:
if len(payload) > 0:
- self._tw.turtle_dictionary = data_from_string(payload)
- for nick in self._tw.turtle_dictionary:
- if nick != self._tw.nick and \
- nick in self._tw.remote_turtles:
- colors = self._tw.turtle_dictionary[nick]
- # add new turtle for the joiner
+ # Grab the new remote turtles dictionary.
+ remote_turtle_dictionary = data_from_string(payload)
+ # Add see what is new.
+ for nick in remote_turtle_dictionary:
+ if nick == self._tw.nick:
+ debug_output('skipping my nick %s' \
+ % (nick), self._tw.running_sugar)
+ elif nick != self._tw.remote_turtle_dictionary:
+ # Add new the turtle.
+ colors = remote_turtle_dictionary[nick]
+ self._tw.remote_turtle_dictionary[nick] = colors
self._tw.canvas.set_turtle(nick, colors)
- self._tw.label_remote_turtle(nick)
+ # Label the remote turtle.
+ self._tw.label_remote_turtle(nick, colors)
+ debug_output('adding %s to remote turtle dictionary' \
+ % (nick), self._tw.running_sugar)
+ else:
+ debug_output('%s already in remote turtle dictionary' \
+ % (nick), self._tw.running_sugar)
self.waiting_for_turtles = False
def _draw_pixbuf(self, payload):
@@ -339,8 +351,7 @@ class Collaboration():
self._tw.canvas.fill_polygon(shared_poly_points)
def _get_dictionary(self):
- d = {self._get_nick(): self._get_colors()}
- return d
+ return {self._get_nick(): self._get_colors()}
def _get_nick(self):
return self._tw.nick
@@ -355,7 +366,7 @@ class Collaboration():
if colors is None:
colors = '%s,%s' % (DEFAULT_TURTLE_COLORS[0],
DEFAULT_TURTLE_COLORS[1])
- return colors
+ return colors.split(',')
class ChatTube(ExportedGObject):
diff --git a/TurtleArt/taturtle.py b/TurtleArt/taturtle.py
index 0c334dd..3123dd6 100644
--- a/TurtleArt/taturtle.py
+++ b/TurtleArt/taturtle.py
@@ -59,6 +59,8 @@ class Turtles:
else:
if colors == None:
Turtle(self, k)
+ elif type(colors) in [list, tuple]:
+ Turtle(self, k, colors)
else:
Turtle(self, k, colors.split(','))
return self.dict[k]
diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py
index bdea860..02a0469 100644
--- a/TurtleArt/tawindow.py
+++ b/TurtleArt/tawindow.py
@@ -1560,19 +1560,19 @@ class TurtleArtWindow():
''' Is this a remote turtle? '''
if name == self.nick:
return False
- if hasattr(self, 'remote_turtles') and \
- name in self.remote_turtles:
+ if hasattr(self, 'remote_turtle_dictionary') and \
+ name in self.remote_turtle_dictionary:
return True
return False
- def label_remote_turtle(self, name):
+ def label_remote_turtle(self, name, colors=['#A0A0A0', '#C0C0C0']):
''' Add a label to remote turtles '''
turtle = self.turtles.get_turtle(name)
if turtle is not None:
turtle.label_block = Block(self.block_list,
self.sprite_list, 'turtle-label', 0, 0,
- 'label', [], 1.0,
- colors=['#A0A0A0', '#C0C0C0'])
+ 'label', [], 1.0 / self.scale,
+ colors)
turtle.label_block.spr.set_label(name)
turtle.show()