From ea576330818699e188d7226b8bc6643efc38af26 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sat, 30 Jun 2012 14:49:33 +0000 Subject: new copy button behavior --- diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py index 15a0b45..8f37de7 100644 --- a/TurtleArt/tawindow.py +++ b/TurtleArt/tawindow.py @@ -1268,6 +1268,10 @@ class TurtleArtWindow(): # From the sprite at x, y, look for a corresponding block blk = self.block_list.spr_to_block(spr) + ''' If we were copying and didn't click on a block... ''' + if self.running_sugar and self.activity.copying: + if blk is None or blk.type != 'block': + self.activity.restore_cursor() if blk is not None: if blk.type == 'block': self.selected_blk = blk @@ -1514,10 +1518,6 @@ class TurtleArtWindow(): self.lc.trace = 1 self.showblocks() self.run_button(3) - elif spr.name == 'debugoff': - self.lc.trace = 1 - self.showblocks() - self.run_button(6) elif spr.name == 'stopiton': self.stop_button() self.display_coordinates() @@ -1651,10 +1651,13 @@ class TurtleArtWindow(): self.drag_group = find_group(blk) (sx, sy) = blk.spr.get_xy() self.drag_pos = x - sx, y - sy - for blk in self.drag_group: - if blk.status != 'collapsed': - blk.spr.set_layer(TOP_LAYER) - blk.highlight() + if self.running_sugar and self.activity.copying: + for blk in self.drag_group: + if blk.status != 'collapsed': + blk.spr.set_layer(TOP_LAYER) + blk.highlight() + self.block_operation = 'copying' + self.activity.send_to_clipboard() if self.running_sugar and self._sharing and \ hasattr(self.activity, 'share_button'): self.activity.share_button.set_tooltip( @@ -2164,6 +2167,11 @@ class TurtleArtWindow(): abs(self.dx) < MOTION_THRESHOLD and \ abs(self.dy < MOTION_THRESHOLD))): self._click_block(x, y) + elif self.block_operation == 'copying': + self.drag_group = find_group(blk) + for gblk in self.drag_group: + gblk.unhighlight() + self.drag_group = None def remote_turtle(self, name): ''' Is this a remote turtle? ''' @@ -2839,7 +2847,7 @@ class TurtleArtWindow(): return True if keyname in ['KP_End', 'End']: - self.run_button(0) + self.run_button(self.step_time) elif self.selected_spr is not None: if not self.lc.running and block_flag: blk = self.block_list.spr_to_block(self.selected_spr) diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py index 777bd79..86991da 100644 --- a/TurtleArtActivity.py +++ b/TurtleArtActivity.py @@ -868,6 +868,10 @@ class TurtleArtActivity(activity.Activity): else: # ...or else, load a Start Block onto the canvas. self.tw.load_start() + if self.has_toolbarbox: + self._old_cursor = self.get_window().get_cursor() + self.copying = False + def _setup_sharing(self): ''' Setup the Collabora stack. ''' self._collaboration = Collaboration(self.tw, self) @@ -1096,8 +1100,25 @@ in order to use the plugin.')) error_handler=self._internal_jobject_error_cb) self._jobject.destroy() + def restore_cursor(self): + ''' No longer copying, so restore standard cursor. ''' + self.copying = False + if self.has_toolbarbox: + self.get_window().set_cursor(self._old_cursor) + def _copy_cb(self, button): ''' Copy to the clipboard. ''' + if self.copying: + self.restore_cursor() + else: + self.copying = True + if self.has_toolbarbox: + self._old_cursor = self.get_window().get_cursor() + self.get_window().set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND1)) + + def send_to_clipboard(self): + ''' Send selected stack to clipboard. ''' + self.restore_cursor() clipboard = gtk.Clipboard() _logger.debug('Serialize the project and copy to clipboard.') data = self.tw.assemble_data_to_save(False, False) @@ -1106,20 +1127,10 @@ in order to use the plugin.')) clipboard.set_text(text) self.tw.paste_offset = 20 - def _share_cb(self, button): - ''' Share a stack of blocks. ''' - if not self.tw.sharing(): - return - _logger.debug('Serialize a stack and send as event.') - data = self.tw.assemble_data_to_save(False, False) - if data is not []: - text = data_to_string(data) - event = 'B|%s' % (data_to_string([self.tw.nick, text])) # Paste - self.tw.send_event(event) - self.tw.paste_offset = 20 - def _paste_cb(self, button): ''' Paste from the clipboard. ''' + if self.copying: + self.restore_cursor() clipboard = gtk.Clipboard() _logger.debug('Paste to the project.') text = clipboard.wait_for_text() @@ -1134,6 +1145,18 @@ in order to use the plugin.')) self.tw.paste_offset) self.tw.paste_offset += 20 + def _share_cb(self, button): + ''' Share a stack of blocks. ''' + if not self.tw.sharing(): + return + _logger.debug('Serialize a stack and send as event.') + data = self.tw.assemble_data_to_save(False, False) + if data is not []: + text = data_to_string(data) + event = 'B|%s' % (data_to_string([self.tw.nick, text])) # Paste + self.tw.send_event(event) + self.tw.paste_offset = 20 + def _add_label(self, string, toolbar, width=None): ''' Add a label to a toolbar. ''' label = gtk.Label(string) -- cgit v0.9.1