Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/labyrinthactivity.py
diff options
context:
space:
mode:
Diffstat (limited to 'labyrinthactivity.py')
-rw-r--r--labyrinthactivity.py101
1 files changed, 67 insertions, 34 deletions
diff --git a/labyrinthactivity.py b/labyrinthactivity.py
index 3340bc6..a17eb93 100644
--- a/labyrinthactivity.py
+++ b/labyrinthactivity.py
@@ -37,14 +37,16 @@ from sugar.datastore import datastore
from port.tarball import Tarball
try:
- # >= 0.86 toolbars
- from sugar.graphics.toolbarbox import ToolbarButton, ToolbarBox
- from sugar.activity.widgets import ActivityToolbarButton
- from sugar.activity.widgets import StopButton
+ from sugar.graphics.toolbarbox import ToolbarBox
+ HASTOOLBARBOX = True
except ImportError:
- # <= 0.84 toolbars
+ HASTOOLBARBOX = False
pass
+if HASTOOLBARBOX:
+ from sugar.graphics.toolbarbox import ToolbarButton
+ from sugar.activity.widgets import ActivityToolbarButton
+ from sugar.activity.widgets import StopButton
# labyrinth sources are shipped inside the 'src' subdirectory
sys.path.append(os.path.join(activity.get_bundle_path(), 'src'))
@@ -128,14 +130,23 @@ class ViewToolbar(gtk.Toolbar):
def __zoom_in_cb(self, button):
self._main_area.scale_fac *= 1.2
self._main_area.invalidate()
+ if len(self._main_area.selected) == 1:
+ if hasattr(self._main_area.selected[0], 'textview'):
+ self._main_area.selected[0].remove_textview()
def __zoom_out_cb(self, button):
self._main_area.scale_fac /= 1.2
self._main_area.invalidate()
+ if len(self._main_area.selected) == 1:
+ if hasattr(self._main_area.selected[0], 'textview'):
+ self._main_area.selected[0].remove_textview()
def __zoom_original_cb(self, button):
self._main_area.scale_fac = 1.0
self._main_area.invalidate()
+ if len(self._main_area.selected) == 1:
+ if hasattr(self._main_area.selected[0], 'textview'):
+ self._main_area.selected[0].remove_textview()
def __zoom_tofit_cb(self, button):
bounds = self.__get_thought_bounds()
@@ -143,6 +154,9 @@ class ViewToolbar(gtk.Toolbar):
self._main_area.translation[1] = bounds['y']
self._main_area.scale_fac = bounds['scale']
self._main_area.invalidate()
+ if len(self._main_area.selected) == 1:
+ if hasattr(self._main_area.selected[0], 'textview'):
+ self._main_area.selected[0].remove_textview()
def __get_thought_bounds(self):
if len(self._main_area.thoughts) == 0:
@@ -326,6 +340,7 @@ class TextAttributesToolbar(gtk.Toolbar):
self._main_area.set_foreground_color(color)
def change_active_font(self):
+ current_font_name = None
current_font = str(self.__attribute_values()["font"])
for index, size in enumerate(self.__font_sizes):
index_size = current_font.find(size)
@@ -397,8 +412,7 @@ class LabyrinthActivity(activity.Activity):
def __init__(self, handle):
activity.Activity.__init__(self, handle)
- try:
- # Use new >= 0.86 toolbar design
+ if HASTOOLBARBOX:
self.max_participants = 1
toolbar_box = ToolbarBox()
activity_button = ActivityToolbarButton(self)
@@ -447,9 +461,6 @@ class LabyrinthActivity(activity.Activity):
toolbar_box.toolbar.insert(self.text_format_toolbar, -1)
self._main_area.set_text_attributes(self.text_format_toolbar)
- separator = gtk.SeparatorToolItem()
- toolbar_box.toolbar.insert(separator, -1)
-
self.mods = [None] * 6
self.thought_toolbar = ToolbarButton()
self.thought_toolbar.props.page = ThoughtsToolbar(self)
@@ -457,22 +468,12 @@ class LabyrinthActivity(activity.Activity):
self.thought_toolbar.props.label = _('Thought Type')
toolbar_box.toolbar.insert(self.thought_toolbar, -1)
- separator = gtk.SeparatorToolItem()
- separator.props.draw = False
- separator.set_expand(True)
- separator.show()
- toolbar_box.toolbar.insert(separator, -1)
-
target_toolbar = toolbar_box.toolbar
- tool_offset = 6
-
- tool = StopButton(self)
- toolbar_box.toolbar.insert(tool, -1)
toolbar_box.show_all()
self.set_toolbar_box(toolbar_box)
- except NameError:
+ else:
# Use old <= 0.84 toolbar design
toolbox = activity.ActivityToolbox(self)
self.set_toolbox(toolbox)
@@ -497,7 +498,6 @@ class LabyrinthActivity(activity.Activity):
self.edit_toolbar.show()
target_toolbar = self.edit_toolbar
- tool_offset = 0
self._undo = UndoManager.UndoManager(self,
self.edit_toolbar.undo.child,
@@ -518,23 +518,39 @@ class LabyrinthActivity(activity.Activity):
self.mods[0] = ToolButton('select-mode')
self.mods[0].set_tooltip(_('Edit mode'))
- self.mods[0].set_accelerator(_('<ctrl>e'))
+ # self.mods[0].set_accelerator(_('<ctrl>e'))
self.mods[0].connect('clicked', self.mode_cb, MMapArea.MODE_NULL)
- target_toolbar.insert(self.mods[0], tool_offset)
-
- #separator = gtk.SeparatorToolItem()
- #target_toolbar.insert(separator, tool_offset + 5)
+ target_toolbar.insert(self.mods[0], -1)
tool = ToolButton('link')
tool.set_tooltip(_('Link/unlink two selected thoughts'))
- tool.set_accelerator(_('<ctrl>l'))
+ # tool.set_accelerator(_('<ctrl>l'))
tool.connect('clicked', self.__link_cb)
- target_toolbar.insert(tool, tool_offset + 1)
+ target_toolbar.insert(tool, -1)
+
+ self.move_button = ToolButton('move')
+ self.move_button.set_tooltip(_('Move selected though'))
+ # tool.set_accelerator(_('<ctrl>m'))
+ self.move_button.connect('clicked', self.__move_cb)
+ target_toolbar.insert(self.move_button, -1)
+
+ separator = gtk.SeparatorToolItem()
+ target_toolbar.insert(separator, -1)
tool = ToolButton('edit-delete')
tool.set_tooltip(_('Erase selected thought(s)'))
tool.connect('clicked', self.__delete_cb)
- target_toolbar.insert(tool, tool_offset + 2)
+ target_toolbar.insert(tool, -1)
+
+ if HASTOOLBARBOX:
+ separator = gtk.SeparatorToolItem()
+ separator.props.draw = False
+ separator.set_expand(True)
+ separator.show()
+ toolbar_box.toolbar.insert(separator, -1)
+
+ tool = StopButton(self)
+ toolbar_box.toolbar.insert(tool, -1)
self.show_all()
self._mode = MMapArea.MODE_TEXT
@@ -543,6 +559,10 @@ class LabyrinthActivity(activity.Activity):
self.set_focus_child(self._main_area)
def __build_main_canvas_area(self):
+ self.fixed = gtk.Fixed()
+ self.fixed.show()
+ self.set_canvas(self.fixed)
+
self._undo.block()
self._main_area = MMapArea.MMapArea(self._undo)
self._main_area.connect("set_focus", self.__main_area_focus_cb)
@@ -553,12 +573,19 @@ class LabyrinthActivity(activity.Activity):
self.__text_selection_cb)
self._main_area.connect("thought_selection_changed",
self.__thought_selected_cb)
- self.set_canvas(self._main_area)
+
+ self._vbox = gtk.VBox()
+ self._vbox.set_size_request(gtk.gdk.screen_width(),
+ gtk.gdk.screen_height())
+ self._vbox.pack_end(self._main_area, True, True)
+ self.fixed.put(self._vbox, 0, 0)
+ self._vbox.show()
self._undo.unblock()
def __text_selection_cb(self, thought, start, end, text):
"""Update state of copy button based on text selection
"""
+ logging.debug('text_selection_cb %d %d %s' % (start, end, text))
if start != end:
self.__change_copy_state(True)
self.text_format_toolbar.props.page.change_active_font()
@@ -707,7 +734,9 @@ class LabyrinthActivity(activity.Activity):
del fileObject
def __main_area_focus_cb(self, arg, event, extended=False):
- self._main_area.grab_focus()
+ # Don't steal focus from textview
+ # self._main_area.grab_focus()
+ pass
def read_file(self, file_path):
tar = Tarball(file_path)
@@ -730,8 +759,6 @@ class LabyrinthActivity(activity.Activity):
x, y = utils.parse_coords(tmp)
self._main_area.translation = [x, y]
- self.thought_toolbar.props.page.mods[self._mode].set_active(True)
-
tar.close()
def write_file(self, file_path):
@@ -745,6 +772,8 @@ class LabyrinthActivity(activity.Activity):
tar.write('MANIFEST', manifest)
self._main_area.save_thyself(tar)
+ self.mods[self._mode].set_active(True)
+
tar.close()
def serialize_to_xml(self, doc, top_element):
@@ -765,5 +794,9 @@ class LabyrinthActivity(activity.Activity):
def __link_cb(self, widget):
self._main_area.link_menu_cb()
+ def __move_cb(self, widget):
+ self.move_button.set_icon('move-active')
+ self._main_area.move_menu_cb(self.move_button)
+
def __delete_cb(self, widget):
self._main_area.delete_selected_elements()