Commit e02ef4c12f955465b8de08985205c423ffb202b3
toolbar-compatibility fix from Sebastian Silva <icarito@sugarlabs.org>
- webactivity.py 87 -----------------------++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- webtoolbar.py 47 -------------------++++++++++++++++++++++++++++
| | | | 47 | from sugar import profile | 47 | from sugar import profile |
---|
48 | from sugar.graphics.alert import Alert | 48 | from sugar.graphics.alert import Alert |
---|
49 | from sugar.graphics.icon import Icon | 49 | from sugar.graphics.icon import Icon |
---|
50 | from sugar.graphics.toolbarbox import ToolbarButton | | from sugar.graphics.toolbarbox import ToolbarButton |
---|
51 | from sugar import mime | 50 | from sugar import mime |
---|
52 | | 51 | |
---|
| | 52 | # Attempt to import the new toolbar classes. If the import fails, |
---|
| | 53 | # fall back to the old toolbar style. |
---|
| | 54 | try: |
---|
| | 55 | from sugar.graphics.toolbarbox import ToolbarButton |
---|
| | 56 | NEW_TOOLBARS = True |
---|
| | 57 | except ImportError: |
---|
| | 58 | NEW_TOOLBARS = False |
---|
| | 59 | |
---|
53 | PROFILE_VERSION = 2 | 60 | PROFILE_VERSION = 2 |
---|
54 | | 61 | |
---|
55 | _profile_version = 0 | 62 | _profile_version = 0 |
---|
56 | _profile_path = os.path.join(activity.get_activity_root(), 'data/gecko') | 63 | _profile_path = os.path.join(activity.get_activity_root(), 'data/gecko') |
---|
57 | _version_file = os.path.join(_profile_path, 'version') | 64 | _version_file = os.path.join(_profile_path, 'version') |
---|
58 | | 65 | |
---|
| | 66 | if not NEW_TOOLBARS: |
---|
| | 67 | _TOOLBAR_EDIT = 1 |
---|
| | 68 | _TOOLBAR_BROWSE = 2 |
---|
| | 69 | |
---|
59 | if os.path.exists(_version_file): | 70 | if os.path.exists(_version_file): |
---|
60 | f = open(_version_file) | 71 | f = open(_version_file) |
---|
61 | _profile_version = int(f.read()) | 72 | _profile_version = int(f.read()) |
---|
… | | … | |
---|
219 | logging.warning('Not enabling the multiple tabs feature due' | 219 | logging.warning('Not enabling the multiple tabs feature due' |
---|
220 | ' to a bug in cairo/mozilla') | 220 | ' to a bug in cairo/mozilla') |
---|
221 | | 221 | |
---|
| | 222 | self._tray = HTray() |
---|
| | 223 | self.set_tray(self._tray, gtk.POS_BOTTOM) |
---|
| | 224 | self._tray.show() |
---|
| | 225 | |
---|
222 | self._primary_toolbar = PrimaryToolbar(self._tabbed_view, self, | 226 | self._primary_toolbar = PrimaryToolbar(self._tabbed_view, self, |
---|
223 | self._disable_multiple_tabs) | | self._disable_multiple_tabs) |
---|
| | 227 | self._disable_multiple_tabs) | | | 228 | self._edit_toolbar = EditToolbar(self) |
---|
| | 229 | self._view_toolbar = ViewToolbar(self) |
---|
| | 230 | |
---|
224 | self._primary_toolbar.connect('add-link', self._link_add_button_cb) | 231 | self._primary_toolbar.connect('add-link', self._link_add_button_cb) |
---|
225 | | 232 | |
---|
226 | self._primary_toolbar.connect('add-tab', self._new_tab_cb) | 233 | self._primary_toolbar.connect('add-tab', self._new_tab_cb) |
---|
227 | | 234 | |
---|
228 | self._primary_toolbar.connect('go-home', self._go_home_button_cb) | 235 | self._primary_toolbar.connect('go-home', self._go_home_button_cb) |
---|
229 | | 236 | |
---|
230 | self._tray = HTray() | | self._tray = HTray() |
---|
231 | self.set_tray(self._tray, gtk.POS_BOTTOM) | | self.set_tray(self._tray, gtk.POS_BOTTOM) |
---|
232 | self._tray.show() | | self._tray.show() |
---|
| | 237 | if NEW_TOOLBARS: | | | 238 | logging.debug('Using new toolbars') |
---|
| | 239 | |
---|
| | 240 | self._edit_toolbar_button = ToolbarButton( |
---|
| | 241 | page=self._edit_toolbar, |
---|
| | 242 | icon_name='toolbar-edit') |
---|
| | 243 | self._primary_toolbar.toolbar.insert( |
---|
| | 244 | self._edit_toolbar_button, 1) |
---|
233 | | 245 | |
---|
234 | self._edit_toolbar = EditToolbar(self) | | self._edit_toolbar = EditToolbar(self) |
---|
235 | self._edit_toolbar_button = ToolbarButton( | | self._edit_toolbar_button = ToolbarButton( |
---|
236 | page=self._edit_toolbar, | | page=self._edit_toolbar, |
---|
237 | icon_name='toolbar-edit') | | icon_name='toolbar-edit') |
---|
238 | self._primary_toolbar.toolbar.insert( | | self._primary_toolbar.toolbar.insert( |
---|
239 | self._edit_toolbar_button, 1) | | self._edit_toolbar_button, 1) |
---|
| | 246 | view_toolbar_button = ToolbarButton( | | | 247 | page=self._view_toolbar, |
---|
| | 248 | icon_name='toolbar-view') |
---|
| | 249 | self._primary_toolbar.toolbar.insert( |
---|
| | 250 | view_toolbar_button, 2) |
---|
240 | | 251 | |
---|
241 | self._view_toolbar = ViewToolbar(self) | | self._view_toolbar = ViewToolbar(self) |
---|
242 | view_toolbar_button = ToolbarButton( | | view_toolbar_button = ToolbarButton( |
---|
243 | page=self._view_toolbar, | | page=self._view_toolbar, |
---|
244 | icon_name='toolbar-view') | | icon_name='toolbar-view') |
---|
245 | self._primary_toolbar.toolbar.insert( | | self._primary_toolbar.toolbar.insert( |
---|
246 | view_toolbar_button, 2) | | view_toolbar_button, 2) |
---|
| | 252 | self._primary_toolbar.show_all() | | | 253 | self.set_toolbar_box(self._primary_toolbar) |
---|
| | 254 | else: |
---|
| | 255 | _logger.debug('Using old toolbars') |
---|
| | 256 | |
---|
| | 257 | toolbox = activity.ActivityToolbox(self) |
---|
247 | | 258 | |
---|
248 | self._primary_toolbar.show_all() | | self._primary_toolbar.show_all() |
---|
249 | self.set_toolbar_box(self._primary_toolbar) | | self.set_toolbar_box(self._primary_toolbar) |
---|
| | 259 | toolbox.add_toolbar(_('Edit'), self._edit_toolbar) | | | 260 | self._edit_toolbar.show() |
---|
| | 261 | |
---|
| | 262 | toolbox.add_toolbar(_('Browse'), self._primary_toolbar) |
---|
| | 263 | self._primary_toolbar.show() |
---|
| | 264 | |
---|
| | 265 | toolbox.add_toolbar(_('View'), self._view_toolbar) |
---|
| | 266 | self._view_toolbar.show() |
---|
250 | | 267 | |
---|
| | 268 | self.set_toolbox(toolbox) |
---|
| | 269 | toolbox.show() |
---|
| | 270 | |
---|
| | 271 | self.toolbox.set_current_toolbar(_TOOLBAR_BROWSE) |
---|
| | 272 | |
---|
251 | self.set_canvas(self._tabbed_view) | 273 | self.set_canvas(self._tabbed_view) |
---|
252 | self._tabbed_view.show() | 274 | self._tabbed_view.show() |
---|
253 | | 275 | |
---|
… | | … | |
---|
527 | self._add_link() | 527 | self._add_link() |
---|
528 | elif key_name == 'f': | 528 | elif key_name == 'f': |
---|
529 | _logger.debug('keyboard: Find') | 529 | _logger.debug('keyboard: Find') |
---|
530 | self._edit_toolbar_button.set_expanded(True) | | self._edit_toolbar_button.set_expanded(True) |
---|
| | 530 | if NEW_TOOLBARS: | | | 531 | self._edit_toolbar_button.set_expanded(True) |
---|
| | 532 | else: |
---|
| | 533 | self.toolbox.set_current_toolbar(_TOOLBAR_EDIT) |
---|
531 | self._edit_toolbar.search_entry.grab_focus() | 534 | self._edit_toolbar.search_entry.grab_focus() |
---|
532 | elif key_name == 'l': | 535 | elif key_name == 'l': |
---|
533 | _logger.debug('keyboard: Focus url entry') | 536 | _logger.debug('keyboard: Focus url entry') |
---|
| | 537 | if not NEW_TOOLBARS: |
---|
| | 538 | self.toolbox.set_current_toolbar(_TOOLBAR_BROWSE) |
---|
534 | self._primary_toolbar.entry.grab_focus() | 539 | self._primary_toolbar.entry.grab_focus() |
---|
535 | elif key_name == 'minus': | 540 | elif key_name == 'minus': |
---|
536 | _logger.debug('keyboard: Zoom out') | 541 | _logger.debug('keyboard: Zoom out') |
---|
… | | … | |
---|
672 | def get_document_path(self, async_cb, async_err_cb): | 672 | def get_document_path(self, async_cb, async_err_cb): |
---|
673 | browser = self._tabbed_view.props.current_browser | 673 | browser = self._tabbed_view.props.current_browser |
---|
674 | browser.get_source(async_cb, async_err_cb) | 674 | browser.get_source(async_cb, async_err_cb) |
---|
| | 675 | |
---|
| | 676 | def get_canvas(self): |
---|
| | 677 | return self._tabbed_view |
---|
| | | | 27 | from sugar.graphics.toolbutton import ToolButton | 27 | from sugar.graphics.toolbutton import ToolButton |
---|
28 | from sugar.graphics.menuitem import MenuItem | 28 | from sugar.graphics.menuitem import MenuItem |
---|
29 | from sugar._sugarext import AddressEntry | 29 | from sugar._sugarext import AddressEntry |
---|
30 | from sugar.graphics.toolbarbox import ToolbarBox | | from sugar.graphics.toolbarbox import ToolbarBox |
---|
31 | from sugar.activity.widgets import ActivityToolbarButton | | from sugar.activity.widgets import ActivityToolbarButton |
---|
32 | from sugar.activity.widgets import StopButton | | from sugar.activity.widgets import StopButton |
---|
33 | from sugar.activity import activity | | from sugar.activity import activity |
---|
| | 30 | try: | | | 31 | from sugar.graphics.toolbarbox import ToolbarBox as ToolbarBase |
---|
| | 32 | from sugar.activity.widgets import ActivityToolbarButton |
---|
| | 33 | from sugar.activity.widgets import StopButton |
---|
| | 34 | from sugar.activity import activity |
---|
| | 35 | NEW_TOOLBARS = True |
---|
| | 36 | except ImportError: |
---|
| | 37 | from gtk import Toolbar as ToolbarBase |
---|
| | 38 | NEW_TOOLBARS = False |
---|
34 | | 39 | |
---|
35 | import filepicker | 40 | import filepicker |
---|
36 | import places | 41 | import places |
---|
37 | | 42 | |
---|
38 | _MAX_HISTORY_ENTRIES = 15 | 43 | _MAX_HISTORY_ENTRIES = 15 |
---|
39 | | 44 | |
---|
40 | | | |
---|
41 | class WebEntry(AddressEntry): | 45 | class WebEntry(AddressEntry): |
---|
42 | _COL_ADDRESS = 0 | 46 | _COL_ADDRESS = 0 |
---|
43 | _COL_TITLE = 1 | 47 | _COL_TITLE = 1 |
---|
… | | … | |
---|
222 | self._search_popup() | 222 | self._search_popup() |
---|
223 | | 223 | |
---|
224 | | 224 | |
---|
225 | class PrimaryToolbar(ToolbarBox): | | class PrimaryToolbar(ToolbarBox): |
---|
| | 225 | class PrimaryToolbar(ToolbarBase): | 226 | __gtype_name__ = 'PrimaryToolbar' | 226 | __gtype_name__ = 'PrimaryToolbar' |
---|
227 | | 227 | |
---|
228 | __gsignals__ = { | 228 | __gsignals__ = { |
---|
… | | … | |
---|
238 | } | 238 | } |
---|
239 | | 239 | |
---|
240 | def __init__(self, tabbed_view, act, disable_multiple_tabs): | 240 | def __init__(self, tabbed_view, act, disable_multiple_tabs): |
---|
241 | ToolbarBox.__init__(self) | | ToolbarBox.__init__(self) |
---|
| | 241 | ToolbarBase.__init__(self) | 242 | | 242 | |
---|
243 | self._activity = act | 243 | self._activity = act |
---|
244 | | 244 | |
---|
… | | … | |
---|
246 | | 246 | |
---|
247 | self._loading = False | 247 | self._loading = False |
---|
248 | | 248 | |
---|
249 | activity_button = ActivityToolbarButton(self._activity) | | activity_button = ActivityToolbarButton(self._activity) |
---|
250 | self.toolbar.insert(activity_button, 0) | | self.toolbar.insert(activity_button, 0) |
---|
| | 249 | if NEW_TOOLBARS: | | | 250 | toolbar = self.toolbar |
---|
| | 251 | activity_button = ActivityToolbarButton(self._activity) |
---|
| | 252 | toolbar.insert(activity_button, 0) |
---|
| | 253 | else: |
---|
| | 254 | toolbar = self |
---|
251 | | 255 | |
---|
252 | self._go_home = ToolButton('go-home') | 256 | self._go_home = ToolButton('go-home') |
---|
253 | self._go_home.set_tooltip(_('Home page')) | 257 | self._go_home.set_tooltip(_('Home page')) |
---|
254 | self._go_home.connect('clicked', self._go_home_cb) | 258 | self._go_home.connect('clicked', self._go_home_cb) |
---|
255 | self.toolbar.insert(self._go_home, -1) | | self.toolbar.insert(self._go_home, -1) |
---|
| | 259 | toolbar.insert(self._go_home, -1) | 256 | self._go_home.show() | 260 | self._go_home.show() |
---|
257 | | 261 | |
---|
258 | self._stop_and_reload = ToolButton('media-playback-stop') | 262 | self._stop_and_reload = ToolButton('media-playback-stop') |
---|
259 | self._stop_and_reload.connect('clicked', self._stop_and_reload_cb) | 263 | self._stop_and_reload.connect('clicked', self._stop_and_reload_cb) |
---|
260 | self.toolbar.insert(self._stop_and_reload, -1) | | self.toolbar.insert(self._stop_and_reload, -1) |
---|
| | 264 | toolbar.insert(self._stop_and_reload, -1) | 261 | self._stop_and_reload.show() | 265 | self._stop_and_reload.show() |
---|
262 | | 266 | |
---|
263 | self.entry = WebEntry() | 267 | self.entry = WebEntry() |
---|
… | | … | |
---|
272 | entry_item.add(self.entry) | 272 | entry_item.add(self.entry) |
---|
273 | self.entry.show() | 273 | self.entry.show() |
---|
274 | | 274 | |
---|
275 | self.toolbar.insert(entry_item, -1) | | self.toolbar.insert(entry_item, -1) |
---|
| | 275 | toolbar.insert(entry_item, -1) | 276 | entry_item.show() | 276 | entry_item.show() |
---|
277 | | 277 | |
---|
278 | self._back = ToolButton('go-previous-paired') | 278 | self._back = ToolButton('go-previous-paired') |
---|
279 | self._back.set_tooltip(_('Back')) | 279 | self._back.set_tooltip(_('Back')) |
---|
280 | self._back.props.sensitive = False | 280 | self._back.props.sensitive = False |
---|
281 | self._back.connect('clicked', self._go_back_cb) | 281 | self._back.connect('clicked', self._go_back_cb) |
---|
282 | self.toolbar.insert(self._back, -1) | | self.toolbar.insert(self._back, -1) |
---|
| | 282 | toolbar.insert(self._back, -1) | 283 | self._back.show() | 283 | self._back.show() |
---|
284 | | 284 | |
---|
285 | self._forward = ToolButton('go-next-paired') | 285 | self._forward = ToolButton('go-next-paired') |
---|
286 | self._forward.set_tooltip(_('Forward')) | 286 | self._forward.set_tooltip(_('Forward')) |
---|
287 | self._forward.props.sensitive = False | 287 | self._forward.props.sensitive = False |
---|
288 | self._forward.connect('clicked', self._go_forward_cb) | 288 | self._forward.connect('clicked', self._go_forward_cb) |
---|
289 | self.toolbar.insert(self._forward, -1) | | self.toolbar.insert(self._forward, -1) |
---|
| | 289 | toolbar.insert(self._forward, -1) | 290 | self._forward.show() | 290 | self._forward.show() |
---|
291 | | 291 | |
---|
292 | if not disable_multiple_tabs: | 292 | if not disable_multiple_tabs: |
---|
… | | … | |
---|
294 | self._add_tab.set_tooltip(_('Add a tab')) | 294 | self._add_tab.set_tooltip(_('Add a tab')) |
---|
295 | self._add_tab.props.sensitive = True | 295 | self._add_tab.props.sensitive = True |
---|
296 | self._add_tab.connect('clicked', self._add_tab_cb) | 296 | self._add_tab.connect('clicked', self._add_tab_cb) |
---|
297 | self.toolbar.insert(self._add_tab, -1) | | self.toolbar.insert(self._add_tab, -1) |
---|
| | 297 | toolbar.insert(self._add_tab, -1) | 298 | self._add_tab.show() | 298 | self._add_tab.show() |
---|
299 | | 299 | |
---|
300 | self._link_add = ToolButton('emblem-favorite') | 300 | self._link_add = ToolButton('emblem-favorite') |
---|
301 | self._link_add.set_tooltip(_('Bookmark')) | 301 | self._link_add.set_tooltip(_('Bookmark')) |
---|
302 | self._link_add.connect('clicked', self._link_add_clicked_cb) | 302 | self._link_add.connect('clicked', self._link_add_clicked_cb) |
---|
303 | self.toolbar.insert(self._link_add, -1) | | self.toolbar.insert(self._link_add, -1) |
---|
| | 303 | toolbar.insert(self._link_add, -1) | 304 | self._link_add.show() | 304 | self._link_add.show() |
---|
305 | | 305 | |
---|
306 | stop_button = StopButton(self._activity) | | stop_button = StopButton(self._activity) |
---|
307 | self.toolbar.insert(stop_button, -1) | | self.toolbar.insert(stop_button, -1) |
---|
| | 306 | if NEW_TOOLBARS: | | | 307 | stop_button = StopButton(self._activity) |
---|
| | 308 | toolbar.insert(stop_button, -1) |
---|
308 | | 309 | |
---|
309 | self._progress_listener = None | 310 | self._progress_listener = None |
---|
310 | self._history = None | 311 | self._history = None |
---|
… | | … | |
---|
385 | self.entry.props.progress = progress | 385 | self.entry.props.progress = progress |
---|
386 | | 386 | |
---|
387 | def _set_address(self, uri): | 387 | def _set_address(self, uri): |
---|
388 | if uri is not None: | | if uri is not None: |
---|
| | 388 | if uri and self._browser is not None: | 389 | ui_uri = self._browser.get_url_from_nsiuri(uri) | 389 | ui_uri = self._browser.get_url_from_nsiuri(uri) |
---|
390 | else: | 390 | else: |
---|
391 | ui_uri = None | 391 | ui_uri = None |
---|