⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bbvis.py

📁 The library is a C++/Python implementation of the variational building block framework introduced in
💻 PY
📖 第 1 页 / 共 2 页
字号:
    def ApplyPropertySelections(self):        self.PerformOps()        self.GenerateFigure()    def ApplyIndexSelections(self, sel):        if `self.writer.indexdrops` != `sel`:            self.writer.indexdrops = copy.deepcopy(sel)            self.PerformOps()            self.GenerateFigure()class TypeSelector(Tkinter.Toplevel):    """A popup for selecting node types to display"""    def __init__(self, types, vartypes, selected, parent):        self.vartypes = vartypes        halflen = (len(types)+1)/2        self.halflen = halflen        self.parent = parent        self.origselected = selected        self.selected = selected        self.all = types        Tkinter.Toplevel.__init__(self)        self.title('Select node types to display')        self.frame = Tkinter.Frame(self)        self.frame.pack(side=TOP, fill=X)        self.select1 = Pmw.RadioSelect(self.frame,                                      buttontype = 'checkbutton',                                      orient = 'vertical',                                      labelpos = None,                                      selectmode = 'multiple')        self.select2 = Pmw.RadioSelect(self.frame,                                      buttontype = 'checkbutton',                                      orient = 'vertical',                                      labelpos = None,                                      selectmode = 'multiple')        self.select1.pack(side=LEFT, anchor=N, fill = 'x', padx = 10)        self.select2.pack(side=RIGHT, anchor=N, fill = 'x', padx = 10)        for t in types[:halflen]:            self.select1.add(t)        for t in types[halflen:]:            self.select2.add(t)        sel1 = filter(lambda x: x in types[:halflen], selected)        sel2 = filter(lambda x: x in types[halflen:], selected)        self.select1.setvalue(sel1)        self.select2.setvalue(sel2)                self.rbox = Pmw.ButtonBox(self, labelpos = None)        self.rbox.add('Reset', command = self.reset)        self.rbox.add('Select all', command = self.selall)        self.rbox.add('Clear', command = self.clear)        self.rbox.alignbuttons()        self.rbox.pack(side=TOP, fill = 'x', expand = 1,                       padx = 12, pady = 6)        self.vbox = Pmw.ButtonBox(self, labelpos = None)        self.vbox.add('Select variables', command = self.selvars)        self.vbox.alignbuttons()        self.vbox.pack(side=TOP, fill = 'x', expand = 1,                       padx = 12, pady = 6)        self.bbox = Pmw.ButtonBox(self, labelpos = None)        self.bbox.add('   OK   ', command = self.finish)        self.bbox.add('  Apply ', command = self.apply)        self.bbox.add(' Cancel ', command = self.cancel)        self.bbox.alignbuttons()        self.bbox.pack(side=TOP, fill = 'x', expand = 1,                       padx = 12, pady = 6)    def new_selection(self, selected):        self.selected = selected        sel1 = filter(lambda x: x in self.all[:self.halflen], selected)        sel2 = filter(lambda x: x in self.all[self.halflen:], selected)        self.select1.setvalue(sel1)        self.select2.setvalue(sel2)    def reset(self):        self.new_selection(self.origselected)    def selall(self):        self.new_selection(self.all)    def selvars(self):        self.new_selection(self.vartypes)    def clear(self):        self.new_selection([])    def apply(self):        self.selected = list(self.select1.getcurselection()) + \                        list(self.select2.getcurselection())        self.parent.ApplyTypeSelections(self.selected)    def finish(self):        self.selected = list(self.select1.getcurselection()) + \                        list(self.select2.getcurselection())        self.parent.ApplyTypeSelections(self.selected)        self.destroy()    def apply(self):        self.selected = list(self.select1.getcurselection()) + \                        list(self.select2.getcurselection())        self.parent.ApplyTypeSelections(self.selected)    def cancel(self):        self.selected = self.origselected        self.parent.ApplyTypeSelections(self.selected)        self.destroy()class PropertySelector(Tkinter.Toplevel):    """A popup for querying properties of node(s)"""    def __init__(self, parent, props):        self.parent = parent        self.props = props        self.origprops = props.PropertyDict()        Tkinter.Toplevel.__init__(self)        self.title('Select properties for the node(s)')        self.shapebutton =  Pmw.OptionMenu(            self, labelpos = 'w', label_text = 'Shape',            items = DotWriter.all_properties['shape'],            initialitem = self.origprops['shape'],            command = props.SetShape            )        self.shapebutton.pack(side=TOP, padx = 8, pady = 8, expand = 0)        self.stylebutton =  Pmw.OptionMenu(            self, labelpos = 'w', label_text = 'Style',            items = DotWriter.all_properties['style'],            initialitem = self.origprops['style'],            command = props.SetStyle            )        self.stylebutton.pack(side=TOP, padx = 8, pady = 8, expand = 0)        self.peripbutton =  Pmw.OptionMenu(            self, labelpos = 'w', label_text = 'Peripheries',            items = DotWriter.all_properties['peripheries'],            initialitem = self.origprops['peripheries']-1,            command = props.SetPeripheries            )        self.peripbutton.pack(side=TOP, padx = 8, pady = 8, expand = 0)        self.colorframe = Tkinter.Frame(self)        self.colorframe.pack(side=TOP, fill=X)        self.colorbutton = Tkinter.Button(self.colorframe, text='Change color',                                          command=self.SelectColor)        self.colorbutton.pack(side=LEFT, padx = 5)        self.colorlabel = Tkinter.Label(self.colorframe, bg=props.color)        self.colorlabel.pack(side=RIGHT, fill=X,expand=YES)        self.fillcframe = Tkinter.Frame(self)        self.fillcframe.pack(side=TOP, fill=X)        self.fillcbutton = Tkinter.Button(self.fillcframe, text='Change fillcolor',                                          command=self.SelectFillcolor)        self.fillcbutton.pack(side=LEFT, padx = 5)        self.fillclabel = Tkinter.Label(self.fillcframe, bg=props.fillcolor)        self.fillclabel.pack(side=RIGHT, fill=X, expand=YES)        self.bbox = Pmw.ButtonBox(self, labelpos = None)        self.bbox.add('   OK   ', command = self.finish)        self.bbox.add('  Apply ', command = self.apply)        self.bbox.add(' Cancel ', command = self.cancel)        self.bbox.alignbuttons()        self.bbox.pack(side=TOP, fill = 'x', expand = 1,                       padx = 12, pady = 6)    def SelectFillcolor(self):        newcol = tkColorChooser.askcolor()        if newcol[1]:            self.props.SetFillcolor(newcol[1])            self.fillclabel.configure(bg=newcol[1])    def SelectColor(self):        newcol = tkColorChooser.askcolor()        if newcol[1]:            self.props.SetColor(newcol[1])            self.colorlabel.configure(bg=newcol[1])    def finish(self):        self.parent.ApplyPropertySelections()        self.destroy()    def apply(self):        self.parent.ApplyPropertySelections()    def cancel(self):        if `self.props.PropertyDict()` != `self.origprops`:            self.props.SetAll(self.origprops)            self.parent.ApplyPropertySelections()        self.destroy()class IndexSelector(Tkinter.Toplevel):    """A popup for selecting number of indices to drop from labels"""    def __init__(self, parent, nodes, cursel):        self.parent = parent        self.nodes = nodes        self.origsel = cursel        self.sel = copy.deepcopy(cursel)        Tkinter.Toplevel.__init__(self)        self.title('Select label indices to drop')        self.sf = Pmw.ScrolledFrame(            self,            usehullsize = 1,            hull_width = 400,            hull_height = 500,        )        self.frame = self.sf.interior()        allnodes = nodes.keys()        allnodes.sort()        self.counters = []        self.counterdict = {}        for n in allnodes:            if nodes[n] > 0:                c = Pmw.Counter(self.frame,                                labelpos = 'w',                                label_text = '%s, max %d:' % (n, nodes[n]),                                orient = 'horizontal',                                entry_width = 2,                                entryfield_value = cursel.get(n, 0),                                entryfield_validate = {'validator' : 'integer',                                                       'min' : 0, 'max' : nodes[n]},                                entryfield_modifiedcommand = lambda x=n: self.ChangeValue(x)                                )                self.counters.append(c)                self.counterdict[n] = c        Pmw.alignlabels(self.counters)        for counter in self.counters:            counter.pack(side=TOP, fill=X, expand=1, padx=10, pady=5)        self.sf.pack(padx = 5, pady = 3, fill = 'both', expand = 1)        self.bbox = Pmw.ButtonBox(self, labelpos = None)        self.bbox.add('   OK   ', command = self.finish)        self.bbox.add('  Apply ', command = self.apply)        self.bbox.add(' Cancel ', command = self.cancel)        self.bbox.alignbuttons()        self.bbox.pack(side=TOP, fill = 'x', expand = 1,                       padx = 12, pady = 6)    def ChangeValue(self, l):        self.sel[l] = int(self.counterdict[l].getvalue())    def finish(self):        self.parent.ApplyIndexSelections(self.sel)        self.destroy()    def apply(self):        self.parent.ApplyIndexSelections(self.sel)    def cancel(self):        if `self.sel` != `self.origsel`:            self.parent.ApplyIndexSelections(self.origsel)        self.destroy()if __name__ == '__main__':    import sys    # Load a given pickled network    if len(sys.argv) > 1:        import PickleHelpers        net = PickleHelpers.LoadWithPickle(sys.argv[1])    else:        print "Usage: python %s savefile.pickle" % sys.argv[0]    # Run the GUI    try:        gui = BBVis(net.net)    except AttributeError:        gui = BBVis(net)    gui.root.mainloop()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -