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