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