diff options
author | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-06-20 03:46:35 (GMT) |
---|---|---|
committer | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-06-20 03:46:35 (GMT) |
commit | 39a82dfa2d59a9751263cf3578335026e0beef7a (patch) | |
tree | 305a06d688a55dad559461ab3e581761fcc65240 | |
parent | c548bbea4b71fb91875da4fcf993abb303321048 (diff) |
Fixing try again bugs
-rw-r--r-- | activity.py | 6 | ||||
-rw-r--r-- | canvas.py | 46 | ||||
-rw-r--r-- | utils.py | 8 |
3 files changed, 33 insertions, 27 deletions
diff --git a/activity.py b/activity.py index 2aba45a..8330720 100644 --- a/activity.py +++ b/activity.py @@ -20,7 +20,6 @@ import gtk import gobject -import utils gtk.gdk.threads_init() @@ -38,9 +37,6 @@ from gettext import gettext as _ from canvas import Canvas -# Update the list -utils.update_list() - class InstallActivity(activity.Activity): @@ -122,6 +118,8 @@ class InstallActivity(activity.Activity): self.set_toolbar_box(toolbarbox) self.show_all() + try_again_btn.hide() + canvas.set_page(0) @@ -19,6 +19,7 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import gtk +import gobject import pango import threading import utils @@ -79,40 +80,43 @@ class List(gtk.VBox): self.download_list = DownloadList() self._parent = parent - self.thread = None self.words = '' - self.can_search = False - self.can_download_again = True self.show_all() def setup(self, search_entry, try_again_btn): try_again_btn.hide() - if not self.can_download_again: - label_box = gtk.VBox() - label = gtk.Label(_("Loading...")) - label.modify_font(pango.FontDescription("25")) - label_box.pack_start(label, True, True, 0) - - self.pack_start(label_box, True, True, 0) - self.can_download_again = False - threading.Thread(target=utils.update_list, - args=(self.set_list, - search_entry, - label, - try_again_btn)).start() - - def set_list(self, search_entry, label, try_again_btn): + + self._try_again_btn = try_again_btn + self._search_entry = search_entry + + label_box = gtk.VBox() + self._label = gtk.Label(_("Loading...")) + self._label.modify_font(pango.FontDescription("25")) + label_box.pack_start(self._label, True, True, 0) + + self.pack_start(label_box, True, True, 0) + thread = threading.Thread(target=utils.update_list) + gobject.timeout_add(100, self._is_ready, thread) + + thread.start() + + def _is_ready(self, thread): + if utils.downloading: + self.set_list() + + def set_list(self): self._list = utils.get_store_list() + _logger.info('LISTAAA: %s' % self._list) if self._list: - search_entry.set_sensitive(True) + self._search_entry.set_sensitive(True) self.can_search = True self.clear() else: - label.set_text(_("Failed to download the list")) - try_again_btn.show() + self._label.set_text(_("Failed to download the list")) + self._try_again_btn.show() def _add_activity(self, widget): self.pack_start(widget, False, False, 7) @@ -31,6 +31,8 @@ LIST_DOWNLOAD = "http://www.fing.edu.uy/~aaguiar/files/store.lst" LIST_PATH = os.path.join(activity.get_activity_root(), 'data', 'store.lst') TMP_DIR = os.path.join(activity.get_activity_root(), "tmp") +downloading = False + # Logging _logger = logging.getLogger('install-activity') _logger.setLevel(logging.DEBUG) @@ -41,9 +43,11 @@ def get_logger(): return _logger -def update_list(func, search_entry, label, try_again_btn): +def update_list(): """Download the latest list version""" + global downloading try: + downloading = True remote_file = urllib.urlopen(LIST_DOWNLOAD) _file = open(LIST_PATH, 'w') _file.write(remote_file.read()) @@ -52,7 +56,7 @@ def update_list(func, search_entry, label, try_again_btn): except: pass - func(search_entry, label, try_again_btn) + downloading = False def get_store_list(): |