bigboard r7257 - in trunk: . bigboard bigboard/libbig bigboard/stocks/people
- From: otaylor svn gnome org
- To: svn-commits-list gnome org
- Subject: bigboard r7257 - in trunk: . bigboard bigboard/libbig bigboard/stocks/people
- Date: Fri, 8 Feb 2008 22:44:02 +0000 (GMT)
Author: otaylor
Date: Fri Feb 8 22:44:02 2008
New Revision: 7257
URL: http://svn.gnome.org/viewvc/bigboard?rev=7257&view=rev
Log:
accounts_dialog.py google.py main.py: Replace gtk.gdk.threads_init()
with gobject.threads_init() - we don't need GDK threading and we weren't
following the GDK threading rules.
format_escaped.py: Little utility from reinteract.
peoplewidgets.py: Add some error handling, allow adding address to contacts
without previously clicking "add to network".
Added:
trunk/bigboard/libbig/format_escaped.py
Modified:
trunk/bigboard/accounts_dialog.py
trunk/bigboard/google.py
trunk/bigboard/stocks/people/peoplewidgets.py
trunk/main.py
Modified: trunk/bigboard/accounts_dialog.py
==============================================================================
--- trunk/bigboard/accounts_dialog.py (original)
+++ trunk/bigboard/accounts_dialog.py Fri Feb 8 22:44:02 2008
@@ -131,7 +131,7 @@
if __name__ == '__main__':
- import gtk, gtk.gdk
+ import gtk, gobject
import bigboard.libbig
try:
@@ -143,7 +143,7 @@
import bigboard.google as google
- gtk.gdk.threads_init()
+ gobject.threads_init()
libbig.logutil.init('DEBUG', ['AsyncHTTP2LibFetcher', 'bigboard.Keyring', 'bigboard.Google', 'bigboard.Accounts', 'bigboard.AccountsDialog'])
Modified: trunk/bigboard/google.py
==============================================================================
--- trunk/bigboard/google.py (original)
+++ trunk/bigboard/google.py Fri Feb 8 22:44:02 2008
@@ -619,7 +619,7 @@
if __name__ == '__main__':
- import gtk, gtk.gdk
+ import gtk, gobject
import bigboard.libbig
try:
@@ -627,8 +627,8 @@
except:
import bignative
- gtk.gdk.threads_init()
-
+ gobject.threads_init()
+
libbig.logutil.init('DEBUG', ['AsyncHTTP2LibFetcher', 'bigboard.Keyring', 'bigboard.Google'])
bignative.set_application_name("BigBoard")
Added: trunk/bigboard/libbig/format_escaped.py
==============================================================================
--- (empty file)
+++ trunk/bigboard/libbig/format_escaped.py Fri Feb 8 22:44:02 2008
@@ -0,0 +1,30 @@
+#
+# Very, very partial implementation of g_markup_printf_escaped(). Doesn't
+# handling things like a %c with an integer argument that evaluates to
+# a markup special character, or special characters in the repr() or str()
+# of an object. It also doesn't handle %(name)s type arguments with
+# keyword arguments.
+#
+# To do better at escaping everything, you'd probably want to apply the
+# implementation technique of g_markup_printf_escaped(). The main difficulty
+# of that is that you need then to be able to split the format string into
+# format specifiers and other sections, which means
+# a big regular expression encoding the format specifers defined by
+# http://docs.python.org/lib/typesseq-strings.html
+#
+
+from gobject import markup_escape_text
+
+def _escape(o):
+ if isinstance(o, basestring):
+ return markup_escape_text(o)
+ else:
+ return o
+
+def format_escaped(fmt, *args):
+ return fmt % tuple((_escape(x) for x in args))
+
+if __name__ == '__main__':
+ assert format_escaped("%s %.4f", "&foo", 4.3) == "&foo 4.3000"
+
+
Modified: trunk/bigboard/stocks/people/peoplewidgets.py
==============================================================================
--- trunk/bigboard/stocks/people/peoplewidgets.py (original)
+++ trunk/bigboard/stocks/people/peoplewidgets.py Fri Feb 8 22:44:02 2008
@@ -14,6 +14,8 @@
import bigboard.libbig as libbig
import bigboard.globals as globals
+from bigboard.libbig.format_escaped import format_escaped
+
from ddm import DataModel
_logger = logging.getLogger("bigboard.stocks.PeopleStock")
@@ -693,30 +695,61 @@
dialog.show()
- def __create_contact(self, addressType, address):
+ def __add_dialog_error_handler(self, query, message):
+ def on_error(err_type, err_message):
+ dialog = gtk.MessageDialog(type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_OK)
+ dialog.set_markup(format_escaped("<b>%s</b>", message))
+ dialog.format_secondary_text(format_escaped("%s", err_message))
+ dialog.run()
+ dialog.destroy()
+
+ query.add_error_handler(on_error)
+
+ def __create_contact(self, addressType, address, after_add, after_add_args):
+ def on_success(contact):
+ _logger.debug("Succesfully created contact %s", contact.resource_id)
+ if after_add:
+ after_add(contact, *after_add_args)
+
_logger.debug("creating contact %s %s" % (addressType, address))
model = globals.get_data_model()
query = model.update(("http://mugshot.org/p/contacts", "createContact"),
+ fetch="+",
+ single_result=True,
addressType=addressType,
address=address)
+ query.add_handler(on_success)
+ self.__add_dialog_error_handler(query, "Couldn't add %s to your contact list" % (address,))
query.execute()
- def __create_user_contact(self, user_resource):
+ def __create_user_contact(self, user_resource, after_add, after_add_args):
+ def on_success(contact):
+ _logger.debug("Succesfully created contact %s", contact.resource_id)
+ if after_add:
+ after_add(contact, *after_add_args)
+
_logger.debug("creating contact %s" % (str(user_resource)))
model = globals.get_data_model()
query = model.update(("http://mugshot.org/p/contacts", "createUserContact"),
+ fetch="+",
+ single_result=True,
user=user_resource);
+ query.add_handler(on_success)
+ self.__add_dialog_error_handler(query, "Couldn't add %s to your contact list" % (user_resource.name,))
query.execute()
- def __add_to_network_clicked(self, link):
+ def __add_to_network(self, after_add=None, *after_add_args):
if self.person.aims:
- self.__create_contact('aim', self.person.aims[0])
+ self.__create_contact('aim', self.person.aims[0], after_add, after_add_args)
elif self.person.xmpps:
- self.__create_contact('xmpp', self.person.xmpps[0])
+ self.__create_contact('xmpp', self.person.xmpps[0], after_add, after_add_args)
elif self.person.local_buddies:
- self.__create_user_contact(self.person.local_buddies[0].user)
+ self.__create_user_contact(self.person.local_buddies[0].user, after_add, after_add_args)
+
+ def __add_to_network_clicked(self, link):
+ self.__add_to_network()
# action_taken = False to leave the stock open which seems nicer in this case
self.emit("close", False)
@@ -880,13 +913,19 @@
_logger.debug("adding address for this person")
address = entry.get_text()
- addressType = combo_get_address_type(type_combo)
+ address_type = combo_get_address_type(type_combo)
- model = globals.get_data_model()
- query = model.update(("http://mugshot.org/p/contacts", "addContactAddress"),
- contact=person.contact, addressType=addressType, address=address)
- query.execute()
+ def do_add_address(contact):
+ model = globals.get_data_model()
+ query = model.update(("http://mugshot.org/p/contacts", "addContactAddress"),
+ contact=contact, addressType=address_type, address=address)
+ self.__add_dialog_error_handler(query, "Couldn't add address %s to contact" % (address,))
+ query.execute()
+ if person.contact:
+ do_add_address(person.contact)
+ else:
+ self.__add_to_network(do_add_address)
else:
_logger.debug("not adding_address")
Modified: trunk/main.py
==============================================================================
--- trunk/main.py (original)
+++ trunk/main.py Fri Feb 8 22:44:02 2008
@@ -917,7 +917,7 @@
def logger(domain, priority, msg):
print msg
- gtk.gdk.threads_init()
+ gobject.threads_init()
dbus.glib.threads_init()
gnome.program_init("bigboard", "0.3")
@@ -981,10 +981,8 @@
bigboard.google.init()
- gtk.gdk.threads_enter()
_logger.debug("Enter mainloop")
gtk.main()
- gtk.gdk.threads_leave()
_logger.debug("Exiting BigBoard")
sys.exit(0)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]