def send_my_xy(self):
     ''' Set xy location so joiner can sync turtle positions. Should be
     used to sync positions after turtle drag. '''
     self._tw.turtles.set_turtle(self._get_nick())
     if self._tw.turtles.get_active_turtle().get_pen_state():
         self.send_event(
             "p", {"payload": data_to_string([self._get_nick(), False])})
         put_pen_back_down = True
     else:
         put_pen_back_down = False
     self.send_event(
         "x", {
             "payload":
             data_to_string([
                 self._get_nick(),
                 [
                     int(self._tw.turtles.get_active_turtle().get_xy()[0]),
                     int(self._tw.turtles.get_active_turtle().get_xy()[1])
                 ]
             ])
         })
     if put_pen_back_down:
         self.send_event(
             "p", {"payload": data_to_string([self._get_nick(), True])})
     self.send_event(
         "r", {
             "payload":
             data_to_string([
                 self._get_nick(),
                 int(self._tw.turtles.get_active_turtle().get_heading())
             ])
         })
示例#2
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.
示例#3
0
    def _new_tube_cb(self, id, initiator, type, service, params, state):
        """ Create a new tube. """
        debug_output(
            'New tube: ID=%d initator=%d type=%d service=%s \
                     params=%r state=%d' %
            (id, initiator, type, service, params, state),
            self._tw.running_sugar)

        if (type == telepathy.TUBE_TYPE_DBUS and service == SERVICE):
            if state == telepathy.TUBE_STATE_LOCAL_PENDING:
                self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES]\
                    .AcceptDBusTube(id)

            tube_conn = TubeConnection(
                self.conn,
                self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES],
                id,
                group_iface=self.text_chan[telepathy.CHANNEL_INTERFACE_GROUP])

            # We'll use a chat tube to send serialized stacks back and forth.
            self.chattube = ChatTube(tube_conn, self.initiating,
                                     self.event_received_cb)

            # Now that we have the tube, we can ask for the turtle dictionary.
            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, colors, and turtle position
                colors = self._get_colors()
                event = 't|' + data_to_string([self._get_nick(), colors])
                debug_output(event, self._tw.running_sugar)
                self.send_event(event)
    def _new_tube_cb(self, id, initiator, type, service, params, state):
        """ Create a new tube. """
        debug_output(
            'New tube: ID=%d initator=%d type=%d service=%s \
                     params=%r state=%d' %
            (id, initiator, type, service, params, state),
            self._tw.running_sugar)

        if (type == telepathy.TUBE_TYPE_DBUS and service == SERVICE):
            if state == telepathy.TUBE_STATE_LOCAL_PENDING:
                self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES]\
                    .AcceptDBusTube(id)

            self.collab = CollabWrapper(self)
            self.collab.message.connect(self.event_received_cb)
            self.collab.setup()

            # Now that we have the tube, we can ask for the turtle dictionary.
            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, colors, and turtle position
                colors = self._get_colors()
                event = data_to_string([self._get_nick(), colors])
                debug_output(event, self._tw.running_sugar)
                self.send_event("t", {"payload": event})
 def _do_copy_cb(self, button):
     ''' Callback for copy button. '''
     clipBoard = gtk.Clipboard()
     data = self.tw.assemble_data_to_save(False, False)
     if data is not []:
         text = data_to_string(data)
         clipBoard.set_text(text)
    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 _new_tube_cb(self, id, initiator, type, service, params, state):
        """ Create a new tube. """
        debug_output(
            'New tube: ID=%d initator=%d type=%d service=%s \
                     params=%r state=%d' %
            (id, initiator, type, service, params, state), self._tw.running_sugar)

        if (type == telepathy.TUBE_TYPE_DBUS and service == SERVICE):
            if state == telepathy.TUBE_STATE_LOCAL_PENDING:
                self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES]\
                    .AcceptDBusTube(id)

            self.collab = CollabWrapper(self)
            self.collab.message.connect(self.event_received_cb)
            self.collab.setup()

            # Now that we have the tube, we can ask for the turtle dictionary.
            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, colors, and turtle position
                colors = self._get_colors()
                event = data_to_string([self._get_nick(), colors])
                debug_output(event, self._tw.running_sugar)
                self.send_event("t", {"payload": event})
示例#8
0
    def _new_tube_cb(self, id, initiator, type, service, params, state):
        """ Create a new tube. """
        debug_output(
            'New tube: ID=%d initator=%d type=%d service=%s \
                     params=%r state=%d' %
            (id, initiator, type, service, params, state), self._tw.running_sugar)

        if (type == telepathy.TUBE_TYPE_DBUS and service == SERVICE):
            if state == telepathy.TUBE_STATE_LOCAL_PENDING:
                self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES]\
                    .AcceptDBusTube(id)

            tube_conn = TubeConnection(
                self.conn,
                self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES],
                id,
                group_iface=self.text_chan[telepathy.CHANNEL_INTERFACE_GROUP])

            # We'll use a chat tube to send serialized stacks back and forth.
            self.chattube = ChatTube(tube_conn, self.initiating,
                                     self.event_received_cb)

            # Now that we have the tube, we can ask for the turtle dictionary.
            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, colors, and turtle position
                colors = self._get_colors()
                event = 't|' + data_to_string([self._get_nick(), colors])
                debug_output(event, self._tw.running_sugar)
                self.send_event(event)
示例#9
0
def myblock(tw, x):  # second argument is ignored
    ''' Copy heap to clipboard '''

    from gtk import Clipboard
    from TurtleArt.tautils import data_to_string

    Clipboard().set_text(data_to_string(tw.lc.heap))
示例#10
0
 def _joined_cb(self, collab):
     # Now that we have the tube, we can ask for the turtle dictionary.
     debug_output('Sending a request for the turtle dictionary',
                  self._tw.running_sugar)
     # We need to send our own nick, colors, and turtle position
     colors = self._get_colors()
     event = data_to_string([self._get_nick(), colors])
     debug_output(event, self._tw.running_sugar)
     self.send_event('t', event)
 def send_my_xy(self):
     ''' Set xy location so joiner can sync turtle positions. Should be
     used to sync positions after turtle drag. '''
     self._tw.turtles.set_turtle(self._get_nick())
     if self._tw.turtles.get_active_turtle().get_pen_state():
         self.send_event("p", {"payload": data_to_string([self._get_nick(),
                                                          False])})
         put_pen_back_down = True
     else:
         put_pen_back_down = False
     self.send_event("x",
                     {"payload": data_to_string([self._get_nick(),
                                                 [int(self._tw.turtles.get_active_turtle().get_xy()[0]),
                                                  int(self._tw.turtles.get_active_turtle().get_xy()[1])]])})
     if put_pen_back_down:
         self.send_event("p", {"payload": data_to_string([self._get_nick(),
                                                          True])})
     self.send_event("r", {"payload": data_to_string(
         [self._get_nick(),
          int(self._tw.turtles.get_active_turtle().get_heading())])})
 def send_my_xy(self):
     ''' Set xy location so joiner can sync turtle positions. Should be
     used to sync positions after turtle drag. '''
     self._tw.canvas.set_turtle(self._get_nick())
     if self._tw.canvas.pendown:
         self.send_event('p|%s' % (data_to_string([self._get_nick(),
                                                   False])))
         put_pen_back_down = True
     else:
         put_pen_back_down = False
     self.send_event('x|%s' %
                     (data_to_string([self._get_nick(),
                                      [int(self._tw.canvas.xcor),
                                       int(self._tw.canvas.ycor)]])))
     if put_pen_back_down:
         self.send_event('p|%s' % (data_to_string([self._get_nick(),
                                                   True])))
     self.send_event('r|%s' %
                     (data_to_string([self._get_nick(),
                                      int(self._tw.canvas.heading)])))
 def send_my_xy(self):
     ''' Set xy location so joiner can sync turtle positions. Should be
     used to sync positions after turtle drag. '''
     self._tw.canvas.set_turtle(self._get_nick())
     if self._tw.canvas.pendown:
         self.send_event('p|%s' %
                         (data_to_string([self._get_nick(), False])))
         put_pen_back_down = True
     else:
         put_pen_back_down = False
     self.send_event('x|%s' % (data_to_string([
         self._get_nick(),
         [int(self._tw.canvas.xcor),
          int(self._tw.canvas.ycor)]
     ])))
     if put_pen_back_down:
         self.send_event('p|%s' %
                         (data_to_string([self._get_nick(), True])))
     self.send_event('r|%s' % (data_to_string(
         [self._get_nick(), int(self._tw.canvas.heading)])))