# Read the database passed as argument to the script in_f, ou_f = sys.argv[1:3] db = Store.get('file').dbopen(in_f) # Check that the bip file actually uses the expected schema assert db.schema.id == "org.pybliographer/bibtex/0.1" # Load a standard citation definition, as an XML file. This defines # the citation of the references, the key and the ordering of the # bibliography. from Pyblio.Cite.Citator import Citator from Pyblio import Registry citator = Citator() citator.xmlload(os.path.join(Registry.RIP_dirs['system'], 'unsrt.cip')) # Citations are inserted in word processors. For the purpose of this # example, we use either a "virtual word processor" that helps writing # citations to a simple file, or the actual OpenOffice interface. if ou_f == 'OOo': # Connect to OpenOffice from Pyblio.Cite.WP.OpenOffice import OOo wp = OOo() wp.connect() elif ou_f == 'LyX': from Pyblio.Cite.WP.LyX import LyX wp = LyX()
class Connect(Utils.GladeWindow): gladeinfo = { 'file': 'wpconnect.glade', 'root': '_w_connect', 'name': 'connect' } def __init__(self, legacy_db, current_wp): Utils.GladeWindow.__init__(self) self._buttons = {} self._active = current_wp self._citator = None self._legacy = legacy_db for m, name in available: t = gtk.ToggleButton(name) t.connect('toggled', self._toggled, m, name) self._buttons[m] = t self._w_list.pack_start(t) for m, name in available: if isinstance(current_wp, m): self._buttons[m].set_active(True) self._w_connect.show_all() def _on_selection(self, chooser): self._citator = Citator() self._citator.xmlload(open(chooser.get_filename())) return def _toggled(self, w, activate, name): # when a button is pushed, we begin by locking the others. do_connect = w.get_active() for m, b in self._buttons.iteritems(): if m != activate: b.set_sensitive(not do_connect) # only then we try to connect self._active = None if do_connect: new = activate() try: new.connect() except (CommunicationError, OperationError), msg: e = gtk.MessageDialog(self._w_connect, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK) e.set_markup(_('Unable to connect to <b>%s</b>') % name) e.format_secondary_text(str(msg)) e.run() e.destroy() w.set_active(False) return self._active = new return