Exemple #1
0
class Citation:
    def __init__(self, title, bib, entries):
        from pygui.pyref import PyRefTable
        import pygtk
        import gtk

        self.table = PyRefTable(bib, entries, "journal", "year", "volume", "pages", "authors", "title")
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title(title)
        self.vbox = gtk.VBox()

        self.hbox = gtk.HBox()
        self.erase_button = gtk.Button("Delete selected")
        self.erase_button.connect("clicked", self.delete_refs)

        self.downarrow = gtk.Arrow(gtk.ARROW_DOWN, gtk.SHADOW_IN)
        self.uparrow = gtk.Arrow(gtk.ARROW_UP, gtk.SHADOW_IN)
        self.downbutton = gtk.Button()
        self.downbutton.set_image(self.downarrow)
        self.upbutton = gtk.Button()
        self.upbutton.set_image(self.uparrow)

        self.downbutton.connect("clicked", self.table.downRef)
        self.upbutton.connect("clicked", self.table.upRef)

        self.hbox.pack_start(self.erase_button, True)
        self.hbox.pack_start(self.upbutton, False)
        self.hbox.pack_start(self.downbutton, False)
        self.vbox.pack_start(self.hbox, False)

        self.scrollwindow = gtk.ScrolledWindow()
        self.scrollwindow.add(self.table.getTree())
        self.vbox.pack_end(self.scrollwindow, True)
        self.window.add(self.vbox)
        self.window.show_all()
        self.window.maximize()

        # self.window.connect("focus-in-event", self.start_listening)
        # self.window.connect("focus-out-event", self.stop_listening)
        self.window.connect("destroy", self.close)

        self.thread = CiteThread(self)
        self.thread.start()

    def addReferences(self, refs):
        self.table.addReferences(refs)

    def delete_refs(self, widget, data=None):
        self.table.removeSelected()

    def close(self, widget, data=None):
        import pygtk
        import gtk

        self.thread.stop()
        gtk.main_quit()

    def getEntries(self):
        return self.table.getEntries()
Exemple #2
0
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