class LintGui: """Build and control a window to interact with pylint""" def __init__(self, root=None): self.root = root or Tk() self.root.title('Pylint') top_frame = Frame(self.root) res_frame = Frame(self.root) btn_frame = Frame(self.root) top_frame.pack(side=TOP, fill=X) res_frame.pack(side=TOP, fill=BOTH, expand=True) btn_frame.pack(side=TOP, fill=X) Label(top_frame, text='Module or package').pack(side=LEFT) self.txtModule = Entry(top_frame, background='white') self.txtModule.bind('<Return>', self.run_lint) self.txtModule.pack(side=LEFT, expand=True, fill=X) Button(top_frame, text='Run', command=self.run_lint).pack(side=LEFT) scrl = Scrollbar(res_frame) self.results = Listbox(res_frame, background='white', font='fixedsys', selectmode='browse', yscrollcommand=scrl.set) scrl.configure(command=self.results.yview) self.results.pack(side=LEFT, expand=True, fill=BOTH) scrl.pack(side=RIGHT, fill=Y) Button(btn_frame, text='Quit', command=self.quit).pack(side=BOTTOM) #self.root.bind('<ctrl-q>', self.quit) self.txtModule.focus_set() def mainloop(self): """lauch the mainloop of the application""" self.root.mainloop() def quit(self, _=None): """quit the application""" self.root.quit() def run_lint(self, _=None): """lauches pylint""" colors = {'W:':'red1', 'E:': 'red4', 'W:': 'red3', '**': 'navy'} self.root.configure(cursor='watch') self.results.focus_set() self.results.delete(0, END) self.results.update() module = self.txtModule.get() pout = os.popen('%s %s' % (PYLINT, module), 'r') for line in pout.xreadlines(): line = line.rstrip() self.results.insert(END, line) fg_color = colors.get(line[:2], 'black') self.results.itemconfigure(END, fg=fg_color) self.results.update() self.root.configure(cursor='')
class LintGui: """Build and control a window to interact with pylint""" def __init__(self, root=None): self.root = root or Tk() self.root.title('Pylint') top_frame = Frame(self.root) res_frame = Frame(self.root) btn_frame = Frame(self.root) top_frame.pack(side=TOP, fill=X) res_frame.pack(side=TOP, fill=BOTH, expand=True) btn_frame.pack(side=TOP, fill=X) Label(top_frame, text='Module or package').pack(side=LEFT) self.txtModule = Entry(top_frame, background='white') self.txtModule.bind('<Return>', self.run_lint) self.txtModule.pack(side=LEFT, expand=True, fill=X) Button(top_frame, text='Run', command=self.run_lint).pack(side=LEFT) scrl = Scrollbar(res_frame) self.results = Listbox(res_frame, background='white', font='fixedsys', selectmode='browse', yscrollcommand=scrl.set) scrl.configure(command=self.results.yview) self.results.pack(side=LEFT, expand=True, fill=BOTH) scrl.pack(side=RIGHT, fill=Y) Button(btn_frame, text='Quit', command=self.quit).pack(side=BOTTOM) #self.root.bind('<ctrl-q>', self.quit) self.txtModule.focus_set() def mainloop(self): """launch the mainloop of the application""" self.root.mainloop() def quit(self, _=None): """quit the application""" self.root.quit() def run_lint(self, _=None): """launches pylint""" colors = {'W:':'red1', 'E:': 'red4', 'W:': 'red3', '**': 'navy'} self.root.configure(cursor='watch') self.results.focus_set() self.results.delete(0, END) self.results.update() module = self.txtModule.get() pout = os.popen('%s %s' % (PYLINT, module), 'r') for line in pout.xreadlines(): line = line.rstrip() self.results.insert(END, line) fg_color = colors.get(line[:2], 'black') self.results.itemconfigure(END, fg=fg_color) self.results.update() self.root.configure(cursor='')
class SelectionListbox(Toplevel): def __init__(self, parent, objectList): Toplevel.__init__(self, parent) self.protocol('WM_DELETE_WINDOW', self.destroy) self._objectList = objectList self._lb = Listbox(self, selectmode = SINGLE) self._lb.pack() self._buttons = PanedWindow(self) for i in objectList.getKeysInOrder(): self._lb.insert(END, i) addButton = Button(self._buttons, text="Add", command=self.onAdd) addButton.pack(side=LEFT) modifyButton = Button(self._buttons, text="Modify", command=self.onModify) modifyButton.pack(side=LEFT) deleteButton = Button(self._buttons, text="Delete", command=self.onDelete) deleteButton.pack(side=LEFT) cancelButton = Button(self._buttons, text="Cancel", command=self.onCancel) cancelButton.pack(side=RIGHT) self._buttons.pack(side=BOTTOM) def onAdd(self): self._inputPanel = InputPanel(self, self._objectList.getElementKeys(), self.addCallBack) def onModify(self): ctr = self._lb.curselection() key = self._lb.get(ctr) print key print self._objectList self._inputPanel = InputPanel(self, self._objectList.getElementKeys(), self.modifyCallBack, key, self._objectList._resources[key]) def onDelete(self): idx = self._lb.curselection() self.deleteCallBack(idx) def onCancel(self): self.destroy() def destroy(self): Toplevel.destroy(self) def addCallBack(self, cdict, key): print "Add new element" key = self._objectList.addFromDict(cdict) self._lb.insert(END, key) self._lb.update() # self._inputPanel.destroy() def modifyCallBack(self, cdict, key): print "Modify Existing Element" print cdict print key self._objectList.modifyElement(cdict, key) print self._objectList._resources[key] self._lb.update() # self._inputPanel.destroy() def deleteCallBack(self, idx): print "Delete" print idx key = self._lb.get(idx) self._objectList.deleteElement(key) self._lb.delete(idx) self._lb.update()