And another attempt that appears to work perfectly, though it's a
little more invasive. I've tested this successfully while loading as
a homepage:
1. A valid URL
2. An invalid URL
3. A local file path
It works in all cases, without race conditions. The race condition it
beats is one which causes the focus_in event to come after the text
has been set/selected, since the event handler sets the text to the
address upon focus, which (apparently) de-selects the text. A very
curious fact is that it appears the key handler for focusing the
location bar (CTRL-L) simply calls grab_focus on the entry and nothing
else, which results in the text being selected. This is a mystery to
me, so I'd appreciate it if someone could shed light on the
difference. Perhaps the reason that this special select_text mumbo
jumbo is needed isn't what I thought it was...either way, it seems to
be necessary.
- Eben
On Wed, Jun 18, 2008 at 6:45 PM, Eben Eliason <[EMAIL PROTECTED]> wrote:
> Updated attempt...doesn't work perfectly (text doesn't get selected
> when a local file is loaded as the homepage)
>
> - Eben
>
> On Tue, Jun 17, 2008 at 8:09 PM, Eben Eliason <[EMAIL PROTECTED]> wrote:
>> This one is a little strange, since I added some code to handle the
>> non-XO case when it loads up an about:blank page instead. It's still
>> pretty small, though.
>>
>> - Eben
>>
>
diff --git a/webactivity.py b/webactivity.py
index 8ca7043..7f0001d 100755
--- a/webactivity.py
+++ b/webactivity.py
@@ -150,6 +150,8 @@ class WebActivity(activity.Activity):
# opening URIs and default docs.
self._load_homepage()
+ self._web_toolbar.entry.select_text()
+
self.messenger = None
self.connect('shared', self._shared_cb)
@@ -278,7 +280,7 @@ class WebActivity(activity.Activity):
if os.path.isfile(_LIBRARY_PATH):
self._browser.load_uri('file://' + _LIBRARY_PATH)
else:
- self._browser.load_uri('about:blank')
+ self._browser.load_uri('http://www.sugarlabs.org/start')
def _session_history_changed_cb(self, session_history, link):
_logger.debug('NewPage: %s.' %link)
diff --git a/webtoolbar.py b/webtoolbar.py
index 3cfbba3..1d0a6fd 100755
--- a/webtoolbar.py
+++ b/webtoolbar.py
@@ -41,8 +41,9 @@ class WebEntry(AddressEntry):
def __init__(self):
gobject.GObject.__init__(self)
- self._address = None
- self._title = None
+ self._address = ''
+ self._title = ''
+ self._select_on_focus = False
self._search_view = self._search_create_view()
self._search_window = gtk.Window(gtk.WINDOW_POPUP)
@@ -67,19 +68,28 @@ class WebEntry(AddressEntry):
finally:
self.handler_unblock(self._change_hid)
+ def select_text(self):
+ if self.props.has_focus:
+ self.select_region(0, -1)
+ else:
+ self._select_on_focus = True
+ self.grab_focus()
+
def activate(self, uri):
self._set_text(uri)
self._search_popdown()
self.emit('activate')
def _set_address(self, address):
+ if not self._address:
+ self._set_text(address)
self._address = address
address = gobject.property(type=str, setter=_set_address)
def _set_title(self, title):
self._title = title
- if title is not None and not self.props.has_focus:
+ if not self.props.has_focus:
self._set_text(title)
title = gobject.property(type=str, setter=_set_title)
@@ -144,6 +154,10 @@ class WebEntry(AddressEntry):
self._set_text(self._address)
self._search_popdown()
+ if self._select_on_focus:
+ self.select_region(0, -1)
+ self._select_on_focus = False
+
def __focus_out_event_cb(self, entry, event):
self._set_text(self._title)
self._search_popdown()
@@ -219,6 +233,7 @@ class WebToolbar(gtk.Toolbar):
self._browser = browser
self._loading = False
+ self._uri_initialized = False
self._back = ToolButton('go-previous-paired')
self._back.set_tooltip(_('Back'))
@@ -279,12 +294,18 @@ class WebToolbar(gtk.Toolbar):
texttosuburi = cls.getService(interfaces.nsITextToSubURI)
ui_uri = texttosuburi.unEscapeURIForUI(uri.originCharset, uri.spec)
+ if ui_uri == 'about:blank':
+ ui_uri = ''
self._set_address(ui_uri)
+ if not self._uri_initialized and ui_uri:
+ self.entry.select_text()
+ self._uri_initialized = True
+
self._update_navigation_buttons()
filepicker.cleanup_temp_files()
def _loading_start_cb(self, progress_listener):
- self._set_title(None)
+ self._set_title('')
self._set_loading(True)
self._update_navigation_buttons()
_______________________________________________
Sugar mailing list
[email protected]
http://lists.laptop.org/listinfo/sugar