diff options
author | Gary Martin <gary@garycmartin.com> | 2009-11-01 18:03:21 (GMT) |
---|---|---|
committer | Gary Martin <gary@garycmartin.com> | 2009-11-01 18:03:21 (GMT) |
commit | b988dde66c953bae0ac3b21cdeb95ef61833dafc (patch) | |
tree | 4ac14b1d507845ff4e8cf04b6914347f7b17fa03 | |
parent | ee2930fcae31c3fb6fca1dc3e62015a742c1f88a (diff) |
Make copy button state change based on text selection.
-rw-r--r-- | labyrinthactivity.py | 41 | ||||
-rw-r--r-- | src/TextThought.py | 3 |
2 files changed, 29 insertions, 15 deletions
diff --git a/labyrinthactivity.py b/labyrinthactivity.py index cc849cf..e0a2b98 100644 --- a/labyrinthactivity.py +++ b/labyrinthactivity.py @@ -71,6 +71,8 @@ class EditToolbar(activity.EditToolbar): self.copy.get_palette().menu.append(menu_item) self.clipboard = gtk.Clipboard() + + self.copy.child.set_sensitive(False) def __undo_cb(self, button): self._parent._undo.undo_action(None) @@ -177,15 +179,15 @@ class LabyrinthActivity(activity.Activity): activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(activity_button, 0) - edit_toolbar = ToolbarButton() - edit_toolbar.props.page = EditToolbar(self) - edit_toolbar.props.icon_name = 'toolbar-edit' - edit_toolbar.props.label = _('Edit'), - toolbar_box.toolbar.insert(edit_toolbar, -1) + self.edit_toolbar = ToolbarButton() + self.edit_toolbar.props.page = EditToolbar(self) + self.edit_toolbar.props.icon_name = 'toolbar-edit' + self.edit_toolbar.props.label = _('Edit'), + toolbar_box.toolbar.insert(self.edit_toolbar, -1) self._undo = UndoManager.UndoManager (self, - edit_toolbar.props.page.undo.child, - edit_toolbar.props.page.redo.child) + self.edit_toolbar.props.page.undo.child, + self.edit_toolbar.props.page.redo.child) self.__build_main_canvas_area() @@ -225,18 +227,18 @@ class LabyrinthActivity(activity.Activity): keep_palette.menu.append(menu_item) menu_item.show() - edit_toolbar = EditToolbar(self) - toolbox.add_toolbar(_('Edit'), edit_toolbar) + self.edit_toolbar = EditToolbar(self) + toolbox.add_toolbar(_('Edit'), self.edit_toolbar) separator = gtk.SeparatorToolItem() - edit_toolbar.insert(separator, 0) - edit_toolbar.show() + self.edit_toolbar.insert(separator, 0) + self.edit_toolbar.show() - target_toolbar = edit_toolbar + target_toolbar = self.edit_toolbar tool_offset = 0 self._undo = UndoManager.UndoManager (self, - edit_toolbar.undo.child, - edit_toolbar.redo.child) + self.edit_toolbar.undo.child, + self.edit_toolbar.redo.child) self.__build_main_canvas_area() @@ -303,9 +305,20 @@ class LabyrinthActivity(activity.Activity): self._main_area.connect ("set_focus", self.__main_area_focus_cb) self._main_area.connect ("button-press-event", self.__main_area_focus_cb) self._main_area.connect ("expose_event", self.__expose) + self._main_area.connect ("text_selection_changed", self.__text_selection_cb) + self._main_area.connect ("thought_selection_changed", self.__thought_selected_cb) self.set_canvas(self._main_area) self._undo.unblock() + def __text_selection_cb(self, thought, start, end, text): + if start != end: + self.edit_toolbar.props.page.copy.child.set_sensitive(True) + else: + self.edit_toolbar.props.page.copy.child.set_sensitive(False) + + def __thought_selected_cb(self, arg, background_color, foreground_color): + self.edit_toolbar.props.page.copy.child.set_sensitive(False) + def __expose(self, widget, event): """Create canvas hint message at start """ diff --git a/src/TextThought.py b/src/TextThought.py index 59fb914..d5d5c1f 100644 --- a/src/TextThought.py +++ b/src/TextThought.py @@ -717,7 +717,6 @@ class TextThought (ResizableThought): elif event.type == gtk.gdk._2BUTTON_PRESS: self.index = len(self.text) self.end_index = 0 # and mark all - self.selection_changed () self.double_click = True elif event.button == 2: x = int ((coords[0] - self.min_x)*pango.SCALE) @@ -737,6 +736,8 @@ class TextThought (ResizableThought): self.recalc_edges() self.emit ("update_view") + self.selection_changed() + def process_button_release (self, event, transformed): if self.orig_size: if self.creating: |