From 3e5dbd4e5bd63b08fc952065537c09b3a5acaf43 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Fri, 28 Dec 2012 19:11:41 +0000 Subject: [PATCH] Added timeout to urllib open; added URL path to addons to Preferences; added URL path to addons to config; refined layout in Preferences on first panel svn: r20865 --- src/config.py | 1 + src/gui/configure.py | 14 ++++++++------ src/gui/viewmanager.py | 21 +++++++++++++-------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/config.py b/src/config.py index cf938edbc..c2f3ff352 100644 --- a/src/config.py +++ b/src/config.py @@ -151,6 +151,7 @@ register('behavior.surname-guessing', 0) register('behavior.use-tips', False) register('behavior.welcome', 100) register('behavior.web-search-url', 'http://google.com/#&q=%(text)s') +register('behavior.addons-url', "http://gramps-addons.svn.sourceforge.net/viewvc/gramps-addons/branches/gramps34/") register('export.proxy-order', [ ["privacy", 0], diff --git a/src/gui/configure.py b/src/gui/configure.py index ad4eaee52..3dee8e880 100644 --- a/src/gui/configure.py +++ b/src/gui/configure.py @@ -307,7 +307,7 @@ class ConfigureDialog(ManagedWindow.ManagedWindow): table.attach(hbox, 2, 3, index, index+1, yoptions=0) def add_entry(self, table, label, index, constant, callback=None, - config=None): + config=None, col_attach=0): if not config: config = self.__config if not callback: @@ -316,9 +316,9 @@ class ConfigureDialog(ManagedWindow.ManagedWindow): entry = gtk.Entry() entry.set_text(config.get(constant)) entry.connect('changed', callback, constant) - table.attach(lwidget, 0, 1, index, index+1, yoptions=0, + table.attach(lwidget, col_attach, col_attach+1, index, index+1, yoptions=0, xoptions=gtk.FILL) - table.attach(entry, 1, 2, index, index+1, yoptions=0) + table.attach(entry, col_attach+1, col_attach+2, index, index+1, yoptions=0) def add_pos_int_entry(self, table, label, index, constant, callback=None, config=None, col_attach=1): @@ -1039,7 +1039,7 @@ class GrampsPreferences(ConfigureDialog): return _('Dates'), table def add_behavior_panel(self, configdialog): - table = gtk.Table(3, 6) + table = gtk.Table(2, 8) table.set_border_width(12) table.set_col_spacings(6) table.set_row_spacings(6) @@ -1097,16 +1097,18 @@ class GrampsPreferences(ConfigureDialog): table.attach(lwidget, 1, 2, 7, 8, yoptions=0) table.attach(self.whattype_box, 2, 3, 7, 8, yoptions=0) + self.add_entry(table, _('Where to check'), 8, 'behavior.addons-url', col_attach=1) + checkbutton = gtk.CheckButton( _("Do not ask about previously notified addons")) checkbutton.set_active(config.get('behavior.do-not-show-previously-seen-updates')) checkbutton.connect("toggled", self.toggle_hide_previous_addons) - table.attach(checkbutton, 0, 3, 8, 9, yoptions=0) + table.attach(checkbutton, 1, 2, 9, 10, yoptions=0) button = gtk.Button(_("Check now")) button.connect("clicked", lambda obj: \ self.uistate.viewmanager.check_for_updates(force=True)) - table.attach(button, 3, 4, 8, 9, yoptions=0) + table.attach(button, 2, 3, 9, 10, yoptions=0) return _('General'), table diff --git a/src/gui/viewmanager.py b/src/gui/viewmanager.py index 310320d5b..72ee3ece1 100644 --- a/src/gui/viewmanager.py +++ b/src/gui/viewmanager.py @@ -227,7 +227,6 @@ UIDEFAULT = ''' WIKI_HELP_PAGE_FAQ = '%s_-_FAQ' % const.URL_MANUAL_PAGE WIKI_HELP_PAGE_KEY = '%s_-_Keybindings' % const.URL_MANUAL_PAGE WIKI_HELP_PAGE_MAN = '%s' % const.URL_MANUAL_PAGE -ADDONS_URL = "http://gramps-addons.svn.sourceforge.net/viewvc/gramps-addons/branches/gramps34/" #------------------------------------------------------------------------- # @@ -357,7 +356,7 @@ class ViewManager(CLIManager): elif howoften == 4: # always update = True if update: - import urllib, locale + import urllib2, locale LOG.debug("Checking for updated addons...") langs = [] lang = locale.getlocale()[0] # not None @@ -370,10 +369,10 @@ class ViewManager(CLIManager): # now we have a list of languages to try: fp = None for lang in langs: - URL = "%s/listings/addons-%s.txt" % (ADDONS_URL, lang) + URL = "%s/listings/addons-%s.txt" % (config.get("behavior.addons-url"), lang) LOG.debug(" trying: %s" % URL) try: - fp = urllib.urlopen(URL) + fp = urllib2.urlopen(URL, timeout=10) # wait up to 10 seconds except: # some error LOG.debug(" IOError!") fp = None @@ -407,7 +406,7 @@ class ViewManager(CLIManager): plugin_dict["i"] not in config.get('behavior.previously-seen-updates')): addon_update_list.append((_("Updated"), "%s/download/%s" % - (ADDONS_URL, + (config.get("behavior.addons-url"), plugin_dict["z"]), plugin_dict)) else: @@ -419,14 +418,20 @@ class ViewManager(CLIManager): plugin_dict["i"] not in config.get('behavior.previously-seen-updates')): addon_update_list.append((_("New"), "%s/download/%s" % - (ADDONS_URL, + (config.get("behavior.addons-url"), plugin_dict["z"]), plugin_dict)) config.set("behavior.last-check-for-updates", datetime.date.today().strftime("%Y/%m/%d")) count += 1 - if fp: - fp.close() + else: + from QuestionDialog import OkDialog + OkDialog(_("Checking Addons Failed"), + _("The addon repository appears to be unavailable. Please try again later."), + self.window) + if fp: + fp.close() + return LOG.debug("Done checking!") # List of translated strings used here # Dead code for l10n