def _paste(self, payload):
     if len(payload) > 0:
         [nick, text] = data_from_string(payload)
         if text is not None:
             self._tw.process_data(data_from_string(text),
                                   self._tw.paste_offset)
             self._tw.paste_offset += 20
Ejemplo n.º 2
0
 def _paste(self, payload):
     if len(payload) > 0:
         [nick, text] = data_from_string(payload)
         if text is not None:
             self._tw.process_data(data_from_string(text),
                                   self._tw.paste_offset)
             self._tw.paste_offset += 20
 def _draw_text(self, payload):
     if len(payload) > 0:
         [nick, [label, x, y, size, w]] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.turtles.set_turtle(nick)
             self._tw.turtles.get_active_turtle().draw_text(
                 label, x, y, size, w, False)
Ejemplo n.º 4
0
 def _receive_turtle_dict(self, payload):
     ''' Any time there is a new joiner, an updated turtle dictionary is
     circulated. Everyone must report their turtle positions so that we
     are in sync. '''
     if self.waiting_for_turtles:
         if len(payload) > 0:
             # 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.turtles.set_turtle(nick, colors)
                     # 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
     self.send_my_xy()
Ejemplo n.º 5
0
    def _turtle_request(self, payload):
        ''' incoming turtle from a joiner '''
        if payload > 0:
            [nick, colors] = data_from_string(payload)
            if nick != self._tw.nick:  # It is not me.
                # There may not be a turtle dictionary.
                if hasattr(self._tw, 'remote_turtle_dictionary'):
                    # Make sure it is not a "rejoin".
                    if not nick in self._tw.remote_turtle_dictionary:
                        # Add new turtle for the joiner.
                        self._tw.turtles.set_turtle(nick, colors)
                        self._tw.label_remote_turtle(nick, colors)
                    self._tw.remote_turtle_dictionary[nick] = colors
                else:
                    self._tw.remote_turtle_dictionary = self._get_dictionary()
                    # Add new turtle for the joiner.
                    self._tw.turtles.set_turtle(nick, colors)
                    self._tw.label_remote_turtle(nick, colors)

        # Sharer should send the updated remote turtle dictionary to everyone.
        if self.initiating:
            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)
            self.send_my_xy()  # And the sender should report her xy position.
    def _turtle_request(self, payload):
        ''' incoming turtle from a joiner '''
        if payload > 0:
            [nick, colors] = data_from_string(payload)
            if nick != self._tw.nick:  # It is not me.
                # There may not be a turtle dictionary.
                if hasattr(self._tw, 'remote_turtle_dictionary'):
                    # Make sure it is not a "rejoin".
                    if nick not in self._tw.remote_turtle_dictionary:
                        # Add new turtle for the joiner.
                        self._tw.turtles.set_turtle(nick, colors)
                        self._tw.label_remote_turtle(nick, colors)
                    self._tw.remote_turtle_dictionary[nick] = colors
                else:
                    self._tw.remote_turtle_dictionary = self._get_dictionary()
                    # Add new turtle for the joiner.
                    self._tw.turtles.set_turtle(nick, colors)
                    self._tw.label_remote_turtle(nick, colors)

        # Sharer should send the updated remote turtle dictionary to everyone.
        if self.initiating:
            if self._tw.nick not 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", {"payload": event_payload})
            self.send_my_xy()  # And the sender should report her xy position.
 def _receive_turtle_dict(self, payload):
     ''' Any time there is a new joiner, an updated turtle dictionary is
     circulated. Everyone must report their turtle positions so that we
     are in sync. '''
     if self.waiting_for_turtles:
         if len(payload) > 0:
             # 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.turtles.set_turtle(nick, colors)
                     # 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
     self.send_my_xy()
Ejemplo n.º 8
0
 def _draw_text(self, payload):
     if len(payload) > 0:
         [nick, [label, x, y, size, w]] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.turtles.set_turtle(nick)
             self._tw.turtles.get_active_turtle().draw_text(
                 label, x, y, size, w, False)
 def _speak(self, payload):
     if len(payload) > 0:
         [nick, language_option, text] = data_from_string(payload)
         if language_option == 'None':
             language_option = ''
         if text is not None:
             os.system('espeak %s "%s" --stdout | aplay' %
                       (language_option, str(text)))
Ejemplo n.º 10
0
 def _speak(self, payload):
     if len(payload) > 0:
         [nick, language_option, text] = data_from_string(payload)
         if language_option == 'None':
             language_option = ''
         if text is not None:
             os.system('espeak %s "%s" --stdout | aplay' %
                       (language_option, str(text)))
Ejemplo n.º 11
0
 def _fill_polygon(self, payload):
     # Check to make sure that the poly_point array is passed properly
     if len(payload) > 0:
         [nick, poly_points] = data_from_string(payload)
         shared_poly_points = []
         for i in range(len(poly_points)):
             shared_poly_points.append(
                 (self._tw.canvas.turtle_to_screen_coordinates
                  (poly_points[i][0], poly_points[i][1])))
         self._tw.canvas.fill_polygon(shared_poly_points)
Ejemplo n.º 12
0
 def _fill_polygon(self, payload):
     # Check to make sure that the poly_point array is passed properly
     if len(payload) > 0:
         [nick, poly_points] = data_from_string(payload)
         shared_poly_points = []
         for i in range(len(poly_points)):
             shared_poly_points.append(
                 (self._tw.canvas.turtle_to_screen_coordinates(
                     poly_points[i][0], poly_points[i][1])))
         self._tw.canvas.fill_polygon(shared_poly_points)
Ejemplo n.º 13
0
 def _speak(self, payload):
     if len(payload) > 0:
         [nick, language_option, text] = data_from_string(payload)
         if language_option == 'None':
             language_option = ''
         if text is not None:
             if self._tw.running_sugar:
                 from sugar3.speech import SpeechManager
                 sm = SpeechManager()
                 sm.say_text(text)
             else:
                 os.system('espeak %s "%s" --stdout | aplay' %
                           (language_option, str(text)))
 def _reskin_turtle(self, payload):
     if len(payload) > 0:
         [nick, [width, height, data]] = data_from_string(payload)
         if nick != self._tw.nick:
             if self._tw.running_sugar:
                 tmp_path = get_path(self._tw.activity, 'instance')
             else:
                 tmp_path = '/tmp'
             file_name = base64_to_image(data, tmp_path)
             pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(file_name,
                                                             width, height)
             self._tw.turtles.set_turtle(nick)
             self._tw.turtles.get_active_turtle().set_shapes([pixbuf])
Ejemplo n.º 15
0
 def _reskin_turtle(self, payload):
     if len(payload) > 0:
         [nick, [width, height, data]] = data_from_string(payload)
         if nick != self._tw.nick:
             if self._tw.running_sugar:
                 tmp_path = get_path(self._tw.activity, 'instance')
             else:
                 tmp_path = '/tmp'
             file_name = base64_to_image(data, tmp_path)
             pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(
                 file_name, width, height)
             self._tw.turtles.set_turtle(nick)
             self._tw.turtles.get_active_turtle().set_shapes([pixbuf])
Ejemplo n.º 16
0
 def _do_paste_cb(self, button):
     ''' Callback for paste button. '''
     clipBoard = gtk.Clipboard()
     text = clipBoard.wait_for_text()
     if text is not None:
         if self.tw.selected_blk is not None and\
            self.tw.selected_blk.name == 'string':
             for i in text:
                 self.tw.process_alphanumeric_input(i, -1)
             self.tw.selected_blk.resize()
         else:
             self.tw.process_data(data_from_string(text),
                                  self.tw.paste_offset)
             self.tw.paste_offset += 20
Ejemplo n.º 17
0
 def _draw_pixbuf(self, payload):
     if len(payload) > 0:
         [nick, [a, b, x, y, w, h, width, height, data]] =\
             data_from_string(payload)
         if nick != self._tw.nick:
             if self._tw.running_sugar:
                 tmp_path = get_path(self._tw.activity, 'instance')
             else:
                 tmp_path = '/tmp'
             file_name = base64_to_image(data, tmp_path)
             pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(file_name,
                                                           width, height)
             x, y = self._tw.canvas.turtle_to_screen_coordinates(x, y)
             self._tw.canvas.draw_pixbuf(pixbuf, a, b, x, y, w, h,
                                         file_name, False)
 def _draw_pixbuf(self, payload):
     if len(payload) > 0:
         [nick, [a, b, x, y, w, h, width, height, data]] =\
             data_from_string(payload)
         if nick != self._tw.nick:
             if self._tw.running_sugar:
                 tmp_path = get_path(self._tw.activity, 'instance')
             else:
                 tmp_path = '/tmp'
             file_name = base64_to_image(data, tmp_path)
             pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(file_name,
                                                             width, height)
             pos = self._tw.turtles.turtle_to_screen_coordinates((x, y))
             self._tw.turtles.get_active_turtle().draw_pixbuf(
                 pixbuf, a, b, pos[0], pos[1], w, h, file_name, False)
Ejemplo n.º 19
0
 def _draw_pixbuf(self, payload):
     if len(payload) > 0:
         [nick, [a, b, x, y, w, h, width, height, data]] =\
             data_from_string(payload)
         if nick != self._tw.nick:
             if self._tw.running_sugar:
                 tmp_path = get_path(self._tw.activity, 'instance')
             else:
                 tmp_path = '/tmp'
             file_name = base64_to_image(data, tmp_path)
             pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(
                 file_name, width, height)
             pos = self._tw.turtles.turtle_to_screen_coordinates((x, y))
             self._tw.turtles.get_active_turtle().draw_pixbuf(
                 pixbuf, a, b, pos[0], pos[1], w, h, file_name, False)
Ejemplo n.º 20
0
 def _fill_polygon(self, payload):
     if len(payload) > 0:
         [nick, poly_points] = data_from_string(payload)
         shared_poly_points = []
         for i in range(len(poly_points)):
             x, y = self._tw.turtles.screen_to_turtle_coordinates(
                      (poly_points[i][1], poly_points[i][2]))
             if poly_points[i][0] in ['move', 'line']:
                 shared_poly_points.append((poly_points[i][0], x, y))
             elif poly_points[i][0] in ['rarc', 'larc']:
                 shared_poly_points.append((poly_points[i][0], x, y,
                      poly_points[i][3], poly_points[i][4],
                      poly_points[i][5]))
         if nick != self._tw.nick:
             self._tw.turtles.set_turtle(nick)
             self._tw.turtles.get_active_turtle().set_poly_points(
                 shared_poly_points)
             self._tw.turtles.get_active_turtle().stop_fill(False)
Ejemplo n.º 21
0
 def _fill_polygon(self, payload):
     if len(payload) > 0:
         [nick, poly_points] = data_from_string(payload)
         shared_poly_points = []
         for i in range(len(poly_points)):
             x, y = self._tw.turtles.screen_to_turtle_coordinates(
                 (poly_points[i][1], poly_points[i][2]))
             if poly_points[i][0] in ['move', 'line']:
                 shared_poly_points.append((poly_points[i][0], x, y))
             elif poly_points[i][0] in ['rarc', 'larc']:
                 shared_poly_points.append(
                     (poly_points[i][0], x, y, poly_points[i][3],
                      poly_points[i][4], poly_points[i][5]))
         if nick != self._tw.nick:
             self._tw.turtles.set_turtle(nick)
             self._tw.turtles.get_active_turtle().set_poly_points(
                 shared_poly_points)
             self._tw.turtles.get_active_turtle().stop_fill(False)
Ejemplo n.º 22
0
 def _do_paste_cb(self, button):
     ''' Callback for paste button. '''
     self.tw.copying_blocks = False
     self.tw.saving_blocks = False
     self.tw.deleting_blocks = False
     self.win.get_window().set_cursor(gtk.gdk.Cursor(gtk.gdk.LEFT_PTR))
     clipboard = gtk.Clipboard()
     text = clipboard.wait_for_text()
     if text is not None:
         if self.tw.selected_blk is not None and \
            self.tw.selected_blk.name == 'string' and \
            text[0:2] != '[[':  # Don't paste block data into a string
             self.tw.paste_text_in_block_label(text)
             self.tw.selected_blk.resize()
         else:
             self.tw.process_data(data_from_string(text),
                                  self.tw.paste_offset)
             self.tw.paste_offset += PASTE_OFFSET
Ejemplo n.º 23
0
 def _do_paste_cb(self, button):
     ''' Callback for paste button. '''
     self.tw.copying_blocks = False
     self.tw.saving_blocks = False
     self.tw.deleting_blocks = False
     self.win.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.LEFT_PTR))
     clipboard = Gtk.Clipboard()
     text = clipboard.wait_for_text()
     if text is not None:
         if self.tw.selected_blk is not None and \
            self.tw.selected_blk.name == 'string' and \
            text[0:2] != '[[':  # Don't paste block data into a string
             self.tw.paste_text_in_block_label(text)
             self.tw.selected_blk.resize()
         else:
             self.tw.process_data(data_from_string(text),
                                  self.tw.paste_offset)
             self.tw.paste_offset += PASTE_OFFSET
Ejemplo n.º 24
0
 def _do_paste_cb(self, button):
     ''' Callback for paste button. '''
     self.tw.copying_blocks = False
     self.tw.saving_blocks = False
     self.tw.deleting_blocks = False
     self.win.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.LEFT_PTR))
     clipBoard = Gtk.Clipboard()
     text = clipBoard.wait_for_text()
     if text is not None:
         if self.tw.selected_blk is not None and \
            self.tw.selected_blk.name == 'string':
             self.tw.text_buffer.set_text(
                 self.tw.text_buffer.get_text() + text)
             self.tw.text_entry.set_buffer(self.tw.text_buffer)
             self.tw.selected_blk.resize()
         elif text[0:2] == '[[':
             self.tw.process_data(data_from_string(text),
                                  self.tw.paste_offset)
             self.tw.paste_offset += 20
Ejemplo n.º 25
0
 def _rotate_turtle(self, payload):
     if len(payload) > 0:
         [nick, h] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.turtles.set_turtle(nick)
             self._tw.turtles.get_active_turtle().set_heading(h, False)
Ejemplo n.º 26
0
 def _move_in_arc(self, payload):
     if len(payload) > 0:
         [nick, [a, r]] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.turtles.set_turtle(nick)
             self._tw.turtles.get_active_turtle().arc(a, r, False)
Ejemplo n.º 27
0
 def _move_forward(self, payload):
     if len(payload) > 0:
         [nick, x] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.turtles.set_turtle(nick)
             self._tw.turtles.get_active_turtle().forward(x, False)
Ejemplo n.º 28
0
 def _rotate_turtle(self, payload):
     if len(payload) > 0:
         [nick, h] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.canvas.set_turtle(nick)
             self._tw.canvas.seth(h, False)
Ejemplo n.º 29
0
 def _setxy(self, payload):
     if len(payload) > 0:
         [nick, [x, y]] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.canvas.set_turtle(nick)
             self._tw.canvas.setxy(x, y, False)
Ejemplo n.º 30
0
 def _draw_text(self, payload):
     if len(payload) > 0:
         [nick, [label, x, y, size, w]] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.canvas.draw_text(label, x, y, size, w, False)
 def _rotate_turtle(self, payload):
     if len(payload) > 0:
         [nick, h] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.turtles.set_turtle(nick)
             self._tw.turtles.get_active_turtle().set_heading(h, False)
 def _move_forward(self, payload):
     if len(payload) > 0:
         [nick, x] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.turtles.set_turtle(nick)
             self._tw.turtles.get_active_turtle().forward(x, False)
Ejemplo n.º 33
0
 def _draw_text(self, payload):
     if len(payload) > 0:
         [nick, [label, x, y, size, w]] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.canvas.draw_text(label, x, y, size, w, False)
 def _move_in_arc(self, payload):
     if len(payload) > 0:
         [nick, [a, r]] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.turtles.set_turtle(nick)
             self._tw.turtles.get_active_turtle().arc(a, r, False)
Ejemplo n.º 35
0
 def _set_xy(self, payload):
     if len(payload) > 0:
         [nick, [x, y]] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.turtles.set_turtle(nick)
             self._tw.turtles.get_active_turtle().set_xy(x, y, share=False)
Ejemplo n.º 36
0
 def _set_pen_state(self, payload):
     if len(payload) > 0:
         [nick, x] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.canvas.set_turtle(nick)
             self._tw.canvas.setpen(x, False)
 def _set_xy(self, payload):
     if len(payload) > 0:
         [nick, [x, y]] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.turtles.set_turtle(nick)
             self._tw.turtles.get_active_turtle().set_xy(x, y, share=False)
Ejemplo n.º 38
0
 def _set_pen_state(self, payload):
     if len(payload) > 0:
         [nick, x] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.turtles.set_turtle(nick)
             self._tw.turtles.get_active_turtle().set_pen_state(x, False)
Ejemplo n.º 39
0
 def _setxy(self, payload):
     if len(payload) > 0:
         [nick, [x, y]] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.canvas.set_turtle(nick)
             self._tw.canvas.setxy(x, y, False)
 def _set_pen_state(self, payload):
     if len(payload) > 0:
         [nick, x] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.turtles.set_turtle(nick)
             self._tw.turtles.get_active_turtle().set_pen_state(x, False)
Ejemplo n.º 41
0
 def _rotate_turtle(self, payload):
     if len(payload) > 0:
         [nick, h] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.canvas.set_turtle(nick)
             self._tw.canvas.seth(h, False)
Ejemplo n.º 42
0
 def _set_pen_state(self, payload):
     if len(payload) > 0:
         [nick, x] = data_from_string(payload)
         if nick != self._tw.nick:
             self._tw.canvas.set_turtle(nick)
             self._tw.canvas.setpen(x, False)