def __init__(self, main_window, msg='Please enter a node:'): tk.Toplevel.__init__(self) self.main_window = main_window self.title('Node Entry') self.geometry('170x160') self.rowconfigure(3, weight=1) tk.Label(self, text=msg).grid(row=0, column=0, columnspan=2, sticky='NESW', padx=5, pady=5) self.posibilities = [ d['dataG_id'] for n, d in main_window.canvas.dispG.nodes_iter(data=True) ] self.entry = AutocompleteEntry(self.posibilities, self) self.entry.bind('<Return>', lambda e: self.destroy(), add='+') self.entry.grid(row=1, column=0, columnspan=2, sticky='NESW', padx=5, pady=5) tk.Button(self, text='Ok', command=self.destroy).grid(row=3, column=0, sticky='ESW', padx=5, pady=5) tk.Button(self, text='Cancel', command=self.cancel).grid(row=3, column=1, sticky='ESW', padx=5, pady=5) # Make modal self.winfo_toplevel().wait_window(self)
def __init__(self, graph, **kwargs): """Additional keyword arguments beyond graph are passed down to the GraphCanvas. See it's docs for details""" tk.Tk.__init__(self) self.geometry('1000x600') self.title('NetworkX Viewer') bottom_row = 10 self.columnconfigure(0, weight=1) self.rowconfigure(bottom_row, weight=1) self.canvas = GraphCanvas(graph, width=400, height=400, **kwargs) self.canvas.grid(row=0, column=0, rowspan=bottom_row + 2, sticky='NESW') self.canvas.onNodeSelected = self.onNodeSelected self.canvas.onEdgeSelected = self.onEdgeSelected r = 0 # Current row tk.Label(self, text='Nodes:').grid(row=r, column=1, sticky='W') self.node_entry = AutocompleteEntry(self.canvas.dataG.nodes) self.node_entry.bind('<Return>', self.add_node, add='+') self.node_entry.bind('<Control-Return>', self.buildNewShortcut, add='+') self.node_entry.grid(row=r, column=2, columnspan=2, sticky='NESW', pady=2) tk.Button(self, text='+', command=self.add_node, width=2).grid(row=r, column=4, sticky=tk.NW, padx=2, pady=2) r += 1 nlsb = tk.Scrollbar(self, orient=tk.VERTICAL) self.node_list = tk.Listbox(self, yscrollcommand=nlsb.set, height=5) self.node_list.grid(row=r, column=1, columnspan=3, sticky='NESW') self.node_list.bind('<Delete>', lambda e: self.node_list.delete(tk.ANCHOR)) nlsb.config(command=self.node_list.yview) nlsb.grid(row=r, column=4, sticky='NWS') r += 1 tk.Label(self, text='Neighbors Levels:').grid(row=r, column=1, columnspan=2, sticky=tk.NW) self.level_entry = tk.Entry(self, width=4) self.level_entry.insert(0, '1') self.level_entry.grid(row=r, column=3, sticky=tk.NW, padx=5) r += 1 tk.Button(self, text='Build New', command=self.onBuildNew).grid(row=r, column=1) tk.Button(self, text='Add to Existing', command=self.onAddToExisting).grid(row=r, column=2, columnspan=2) r += 1 line = tk.Canvas(self, height=15, width=200) line.create_line(0, 13, 250, 13) line.create_line(0, 15, 250, 15) line.grid(row=r, column=1, columnspan=4, sticky='NESW') r += 1 tk.Label(self, text='Filters:').grid(row=r, column=1, sticky=tk.W) self.filter_entry = tk.Entry(self) self.filter_entry.bind('<Return>', self.add_filter, add='+') self.filter_entry.grid(row=r, column=2, columnspan=2, sticky='NESW', pady=2) tk.Button(self, text='+', command=self.add_filter, width=2).grid(row=r, column=4, sticky=tk.NW, padx=2, pady=2) r += 1 flsb = tk.Scrollbar(self, orient=tk.VERTICAL) self.filter_list = tk.Listbox(self, yscrollcommand=flsb.set, height=5) self.filter_list.grid(row=r, column=1, columnspan=3, sticky='NESW') self.filter_list.bind('<Delete>', self.remove_filter) flsb.config(command=self.node_list.yview) flsb.grid(row=r, column=4, sticky='NWS') r += 1 tk.Button(self, text='Clear', command=self.remove_filter).grid(row=r, column=1, sticky='W') tk.Button(self, text='?', command=self.filter_help).grid(row=r, column=4, stick='NESW', padx=2) r += 1 line2 = tk.Canvas(self, height=15, width=200) line2.create_line(0, 13, 250, 13) line2.create_line(0, 15, 250, 15) line2.grid(row=r, column=1, columnspan=4, sticky='NESW') r += 1 self.lbl_attr = tk.Label(self, text='Attributes', wraplength=200, anchor=tk.SW, justify=tk.LEFT) self.lbl_attr.grid(row=r, column=1, columnspan=4, sticky='NW') r += 1 self.tbl_attr = PropertyTable(self, {}) self.tbl_attr.grid(row=r, column=1, columnspan=4, sticky='NESW') assert r == bottom_row, "Set bottom_row to %d" % r self._build_menu()