def openBibFile(file): bibobj = None if file.endswith("xml"): bibobj = Bibliography() bibobj.buildRecords(file) else: from skynet.pysave import load, save try: bibobj = PySave.load(file) except Exception, error: pass
def walkForBibs(path, check=False, fields=[]): def checkFolder(args, dirname, files): import glob topdir = os.getcwd() os.chdir(dirname) allbib = args xmlfiles = [elem for elem in files if elem.endswith(".xml")] for file in xmlfiles: allbib.buildRecords(file, check, fields) os.chdir(topdir) if os.path.isfile(path): bib = Bibliography() bib.buildRecords(path, check, fields) return bib # folder, do the walk allbib = Bibliography() os.path.walk(path, checkFolder, allbib) return allbib
def __init__(self): import pygtk import gtk import pygui from pylatex.pybib import Bibliography from pygui.pyref import PyRefTable self.bib = Bibliography() self.table = PyRefTable( self.bib, self.bib.labels(), "label", "journal", "year", "volume", "pages", "authors", "title" ) self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("destroy", self.close) self.window.set_title("References") hbox = gtk.HBox(False) # file buttons load_button = gtk.Button("Reload") load_button.connect("clicked", self.load) hbox.pack_start(load_button, False) upd_button = gtk.Button("Update Bibliography") upd_button.connect("clicked", self.update) hbox.pack_start(upd_button, False) self.entry = gtk.Entry(100) self.entry.connect("key-release-event", self.filter) self.filterstr = "" hbox.pack_start(self.entry, True) button = gtk.Button("Insert References") button.connect("clicked", self.insert_refs) hbox.pack_end(button, False) vbox = gtk.VBox() vbox.pack_start(hbox, False) self.scrollwindow = gtk.ScrolledWindow() self.scrollwindow.add(self.table.getTree()) vbox.pack_start(self.scrollwindow) self.window.add(vbox) self.window.show_all() self.window.maximize() self.tables = [TableFilter(self.table, self.filterstr)]
def loadCitation(cword): import os import pyvim.pyvim as vim import re import pygtk import gtk import os.path from pylatex.pybib import Record Record.unsetFormat() Record.setDefaults() entries = [] if "~" in cword: cword = "~" + cword.split("~")[-1] if "\cite{" in cword: # we are currently on a citation # get the entries within the citation innards = re.compile(r"cite[{](.*?)[}]").search(cword).groups()[0].strip() if innards: entries = map(lambda x: x.strip(), innards.split(",")) else: entries = [] else: # no citation, but put one in vim.appendAtWord("~\cite{}", ",", ".") cword = "~\cite{}" # build the citation import os.path if not hasattr(PyTexGlobals, "bib"): # import PyGui # filesel = PyGui.FileSelect(os.path.join(os.path.expanduser("~"), "Documents"), setBibliography, main=True) # gtk.main() from pylatex.pybib import Bibliography empty = Bibliography() empty.buildRecords(Bibliography.ENDNOTE_XML_LIB) setattr(PyTexGlobals, "bib", empty) bib = getattr(PyTexGlobals, "bib") title = "Reference at line %d" % vim.PyVimGlobals.line # title = "test" citeobj = Citation(title, bib, entries) gtk.gdk.threads_init() gtk.gdk.threads_enter() gtk.main() gtk.gdk.threads_leave() # use the citation object to generate the new reference entries = citeobj.getEntries() labels = [] for entry in entries: labels.append(str(entry.getAttribute("label"))) newtext = "" if labels: newtext = "~\cite{%s}" % ",".join(labels) vim.replace(cword, newtext)
class CiteManager: REF_LISTEN_PORT = 21567 def __init__(self): import pygtk import gtk import pygui from pylatex.pybib import Bibliography from pygui.pyref import PyRefTable self.bib = Bibliography() self.table = PyRefTable( self.bib, self.bib.labels(), "label", "journal", "year", "volume", "pages", "authors", "title" ) self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("destroy", self.close) self.window.set_title("References") hbox = gtk.HBox(False) # file buttons load_button = gtk.Button("Reload") load_button.connect("clicked", self.load) hbox.pack_start(load_button, False) upd_button = gtk.Button("Update Bibliography") upd_button.connect("clicked", self.update) hbox.pack_start(upd_button, False) self.entry = gtk.Entry(100) self.entry.connect("key-release-event", self.filter) self.filterstr = "" hbox.pack_start(self.entry, True) button = gtk.Button("Insert References") button.connect("clicked", self.insert_refs) hbox.pack_end(button, False) vbox = gtk.VBox() vbox.pack_start(hbox, False) self.scrollwindow = gtk.ScrolledWindow() self.scrollwindow.add(self.table.getTree()) vbox.pack_start(self.scrollwindow) self.window.add(vbox) self.window.show_all() self.window.maximize() self.tables = [TableFilter(self.table, self.filterstr)] def filter(self, widget, data=None): text = self.entry.get_text() cmds = text.strip().split(",") filterstrs = [] for cmd in cmds: splitcmd = cmd.split("=") if len(splitcmd) != 2: continue attr, val = splitcmd if not attr or not val: continue # also not valid filterstrs.append("%s=%s" % (attr, val)) filterstr = ",".join(filterstrs) if filterstr == self.filterstr: return # nothing to do else: self.filterstr = filterstr self.scrollwindow.remove(self.table.getTree()) # check to see if the filterstr exists in the current set exists = False for table in self.tables: if table.matches(filterstr): exists = True break if exists: # pop back until we get the match match = False while self.tables: filter = self.tables.pop() if filter.matches(filterstr): self.table = filter.getTable() self.scrollwindow.add(self.table.getTree()) self.window.show_all() self.tables.append(filter) return else: # does not exist, make a new one from pylatex.pybib import BadMatchAttribute newtable = None try: newtable = self.table.filter(filterstr) except BadMatchAttribute, error: # build blank table newtable = self.table.subset([]) # build null table newfilter = TableFilter(newtable, filterstr) self.table = newtable self.tables.append(newfilter) self.scrollwindow.add(self.table.getTree()) self.window.show_all() return