[Sugar-devel] [PATCH] Fall back to old style toolbars in old sugar
Sebastian Silva
sebastian at somosazucar.org
Thu May 26 00:46:40 EDT 2011
From: Sebastian Silva <icarito at sugarlabs.org>
Based on patch by Wade from 2009:
http://git.sugarlabs.org/~wadeb/browse/backwards-compatibility/commit/584939d3bc217b9463703e9a903caadf80c50d00
---
webactivity.py | 87 +++++++++++++++++++++++++++++++++++++++++---------------
webtoolbar.py | 47 ++++++++++++++++++------------
2 files changed, 92 insertions(+), 42 deletions(-)
diff --git a/webactivity.py b/webactivity.py
index 5f1ea5e..f43c9b4 100644
--- a/webactivity.py
+++ b/webactivity.py
@@ -47,15 +47,26 @@ from sugar.graphics.tray import HTray
from sugar import profile
from sugar.graphics.alert import Alert
from sugar.graphics.icon import Icon
-from sugar.graphics.toolbarbox import ToolbarButton
from sugar import mime
+# Attempt to import the new toolbar classes. If the import fails,
+# fall back to the old toolbar style.
+try:
+ from sugar.graphics.toolbarbox import ToolbarButton
+ NEW_TOOLBARS = True
+except ImportError:
+ NEW_TOOLBARS = False
+
PROFILE_VERSION = 2
_profile_version = 0
_profile_path = os.path.join(activity.get_activity_root(), 'data/gecko')
_version_file = os.path.join(_profile_path, 'version')
+if not NEW_TOOLBARS:
+ _TOOLBAR_EDIT = 1
+ _TOOLBAR_BROWSE = 2
+
if os.path.exists(_version_file):
f = open(_version_file)
_profile_version = int(f.read())
@@ -208,34 +219,56 @@ class WebActivity(activity.Activity):
logging.warning('Not enabling the multiple tabs feature due'
' to a bug in cairo/mozilla')
- self._primary_toolbar = PrimaryToolbar(self._tabbed_view, self,
- self._disable_multiple_tabs)
- self._primary_toolbar.connect('add-link', self._link_add_button_cb)
-
- self._primary_toolbar.connect('add-tab', self._new_tab_cb)
-
- self._primary_toolbar.connect('go-home', self._go_home_button_cb)
-
self._tray = HTray()
self.set_tray(self._tray, gtk.POS_BOTTOM)
self._tray.show()
+ self._primary_toolbar = PrimaryToolbar(self._tabbed_view, self,
+ self._disable_multiple_tabs)
self._edit_toolbar = EditToolbar(self)
- self._edit_toolbar_button = ToolbarButton(
- page=self._edit_toolbar,
- icon_name='toolbar-edit')
- self._primary_toolbar.toolbar.insert(
- self._edit_toolbar_button, 1)
-
self._view_toolbar = ViewToolbar(self)
- view_toolbar_button = ToolbarButton(
- page=self._view_toolbar,
- icon_name='toolbar-view')
- self._primary_toolbar.toolbar.insert(
- view_toolbar_button, 2)
- self._primary_toolbar.show_all()
- self.set_toolbar_box(self._primary_toolbar)
+ self._primary_toolbar.connect('add-link', self._link_add_button_cb)
+
+ self._primary_toolbar.connect('add-tab', self._new_tab_cb)
+
+ self._primary_toolbar.connect('go-home', self._go_home_button_cb)
+
+ if NEW_TOOLBARS:
+ logging.debug('Using new toolbars')
+
+ self._edit_toolbar_button = ToolbarButton(
+ page=self._edit_toolbar,
+ icon_name='toolbar-edit')
+ self._primary_toolbar.toolbar.insert(
+ self._edit_toolbar_button, 1)
+
+ view_toolbar_button = ToolbarButton(
+ page=self._view_toolbar,
+ icon_name='toolbar-view')
+ self._primary_toolbar.toolbar.insert(
+ view_toolbar_button, 2)
+
+ self._primary_toolbar.show_all()
+ self.set_toolbar_box(self._primary_toolbar)
+ else:
+ _logger.debug('Using old toolbars')
+
+ toolbox = activity.ActivityToolbox(self)
+
+ toolbox.add_toolbar(_('Edit'), self._edit_toolbar)
+ self._edit_toolbar.show()
+
+ toolbox.add_toolbar(_('Browse'), self._primary_toolbar)
+ self._primary_toolbar.show()
+
+ toolbox.add_toolbar(_('View'), self._view_toolbar)
+ self._view_toolbar.show()
+
+ self.set_toolbox(toolbox)
+ toolbox.show()
+
+ self.toolbox.set_current_toolbar(_TOOLBAR_BROWSE)
self.set_canvas(self._tabbed_view)
self._tabbed_view.show()
@@ -494,10 +527,15 @@ class WebActivity(activity.Activity):
self._add_link()
elif key_name == 'f':
_logger.debug('keyboard: Find')
- self._edit_toolbar_button.set_expanded(True)
+ if NEW_TOOLBARS:
+ self._edit_toolbar_button.set_expanded(True)
+ else:
+ self.toolbox.set_current_toolbar(_TOOLBAR_EDIT)
self._edit_toolbar.search_entry.grab_focus()
elif key_name == 'l':
_logger.debug('keyboard: Focus url entry')
+ if not NEW_TOOLBARS:
+ self.toolbox.set_current_toolbar(_TOOLBAR_BROWSE)
self._primary_toolbar.entry.grab_focus()
elif key_name == 'minus':
_logger.debug('keyboard: Zoom out')
@@ -634,3 +672,6 @@ class WebActivity(activity.Activity):
def get_document_path(self, async_cb, async_err_cb):
browser = self._tabbed_view.props.current_browser
browser.get_source(async_cb, async_err_cb)
+
+ def get_canvas(self):
+ return self._tabbed_view
diff --git a/webtoolbar.py b/webtoolbar.py
index 937136c..6a52934 100644
--- a/webtoolbar.py
+++ b/webtoolbar.py
@@ -27,17 +27,21 @@ from xpcom import components
from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.menuitem import MenuItem
from sugar._sugarext import AddressEntry
-from sugar.graphics.toolbarbox import ToolbarBox
-from sugar.activity.widgets import ActivityToolbarButton
-from sugar.activity.widgets import StopButton
-from sugar.activity import activity
+try:
+ from sugar.graphics.toolbarbox import ToolbarBox as ToolbarBase
+ from sugar.activity.widgets import ActivityToolbarButton
+ from sugar.activity.widgets import StopButton
+ from sugar.activity import activity
+ NEW_TOOLBARS = True
+except ImportError:
+ from gtk import Toolbar as ToolbarBase
+ NEW_TOOLBARS = False
import filepicker
import places
_MAX_HISTORY_ENTRIES = 15
-
class WebEntry(AddressEntry):
_COL_ADDRESS = 0
_COL_TITLE = 1
@@ -218,7 +222,7 @@ class WebEntry(AddressEntry):
self._search_popup()
-class PrimaryToolbar(ToolbarBox):
+class PrimaryToolbar(ToolbarBase):
__gtype_name__ = 'PrimaryToolbar'
__gsignals__ = {
@@ -234,7 +238,7 @@ class PrimaryToolbar(ToolbarBox):
}
def __init__(self, tabbed_view, act, disable_multiple_tabs):
- ToolbarBox.__init__(self)
+ ToolbarBase.__init__(self)
self._activity = act
@@ -242,18 +246,22 @@ class PrimaryToolbar(ToolbarBox):
self._loading = False
- activity_button = ActivityToolbarButton(self._activity)
- self.toolbar.insert(activity_button, 0)
+ if NEW_TOOLBARS:
+ toolbar = self.toolbar
+ activity_button = ActivityToolbarButton(self._activity)
+ toolbar.insert(activity_button, 0)
+ else:
+ toolbar = self
self._go_home = ToolButton('go-home')
self._go_home.set_tooltip(_('Home page'))
self._go_home.connect('clicked', self._go_home_cb)
- self.toolbar.insert(self._go_home, -1)
+ toolbar.insert(self._go_home, -1)
self._go_home.show()
self._stop_and_reload = ToolButton('media-playback-stop')
self._stop_and_reload.connect('clicked', self._stop_and_reload_cb)
- self.toolbar.insert(self._stop_and_reload, -1)
+ toolbar.insert(self._stop_and_reload, -1)
self._stop_and_reload.show()
self.entry = WebEntry()
@@ -264,21 +272,21 @@ class PrimaryToolbar(ToolbarBox):
entry_item.add(self.entry)
self.entry.show()
- self.toolbar.insert(entry_item, -1)
+ toolbar.insert(entry_item, -1)
entry_item.show()
self._back = ToolButton('go-previous-paired')
self._back.set_tooltip(_('Back'))
self._back.props.sensitive = False
self._back.connect('clicked', self._go_back_cb)
- self.toolbar.insert(self._back, -1)
+ toolbar.insert(self._back, -1)
self._back.show()
self._forward = ToolButton('go-next-paired')
self._forward.set_tooltip(_('Forward'))
self._forward.props.sensitive = False
self._forward.connect('clicked', self._go_forward_cb)
- self.toolbar.insert(self._forward, -1)
+ toolbar.insert(self._forward, -1)
self._forward.show()
if not disable_multiple_tabs:
@@ -286,17 +294,18 @@ class PrimaryToolbar(ToolbarBox):
self._add_tab.set_tooltip(_('Add a tab'))
self._add_tab.props.sensitive = True
self._add_tab.connect('clicked', self._add_tab_cb)
- self.toolbar.insert(self._add_tab, -1)
+ toolbar.insert(self._add_tab, -1)
self._add_tab.show()
self._link_add = ToolButton('emblem-favorite')
self._link_add.set_tooltip(_('Bookmark'))
self._link_add.connect('clicked', self._link_add_clicked_cb)
- self.toolbar.insert(self._link_add, -1)
+ toolbar.insert(self._link_add, -1)
self._link_add.show()
- stop_button = StopButton(self._activity)
- self.toolbar.insert(stop_button, -1)
+ if NEW_TOOLBARS:
+ stop_button = StopButton(self._activity)
+ toolbar.insert(stop_button, -1)
self._progress_listener = None
self._history = None
@@ -376,7 +385,7 @@ class PrimaryToolbar(ToolbarBox):
self.entry.props.progress = progress
def _set_address(self, uri):
- if uri is not None:
+ if uri and self._browser is not None:
ui_uri = self._browser.get_url_from_nsiuri(uri)
else:
ui_uri = None
--
1.7.2.3
More information about the Sugar-devel
mailing list