[PythonReports-checkins] PythonReports/PythonReports design.py, 1.11, 1.12
Brought to you by:
a1s
From: alexander s. <a1...@us...> - 2006-12-06 16:35:26
|
Update of /cvsroot/pythonreports/PythonReports/PythonReports In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31541 Modified Files: design.py Log Message: fix errors and some warnings reported by pylint Index: design.py =================================================================== RCS file: /cvsroot/pythonreports/PythonReports/PythonReports/design.py,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** design.py 7 Nov 2006 13:32:02 -0000 1.11 --- design.py 6 Dec 2006 16:35:20 -0000 1.12 *************** *** 1,6 **** #! /usr/bin/env python """PythonReports Template Designer""" - """History (most recent first): 07-Nov-2006 [phd] Added shebang. 04-nov-2006 [als] added About dialog --- 1,9 ---- #! /usr/bin/env python + # pylint: disable-msg=R0901,R0904 + # R0901: Too many ancestors in all classes derived from Tix widgets + # R0904: ditto, Too many public methods """PythonReports Template Designer""" """History (most recent first): + 05-dec-2006 [als] fix errors and some warnings reported by pylint 07-Nov-2006 [phd] Added shebang. 04-nov-2006 [als] added About dialog *************** *** 90,93 **** --- 93,99 ---- # since we're not interactive, sys does not have ps1 and ps2 try: + # pylint: disable-msg=E1101,W0104 + # E1101: Module 'sys' has no 'ps1' member - that's what we're trying here + # W0104: Statement seems to have no effect sys.ps1 except AttributeError: *************** *** 97,103 **** --- 103,113 ---- class Interpreter(InteractiveInterpreter): + """Python interpreter shell substituting standard streams for code run""" + def __init__(self, locals, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr ): + # pylint: disable-msg=W0622 + # W0622: Redefining built-in 'locals' - the name comes from base class InteractiveInterpreter.__init__(self, locals) self.stdin = stdin *************** *** 106,109 **** --- 116,120 ---- def runcode(self, code): + """Execute a code object""" # save current standard streams _stdin = sys.stdin *************** *** 146,152 **** --- 157,165 ---- @staticmethod def isatty(): + """Return True: the file is connected to a tty-like device""" return True def write(self, text): + """Output a text to the window""" self.window.insert("end", text, self.tag) # window must be refreshed in case we fall into raw_input somewhere *************** *** 155,158 **** --- 168,172 ---- def writelines(self, iterable): + """Write a sequence of strings to the window""" _write = self.write for _line in iterable: *************** *** 163,176 **** --- 177,201 ---- """Interactive shell widget""" + # pylint: disable-msg=E0102 + # E0102: redefinition of the Shell class imported from Tix + @property def shell_greeting(self): + """Interpreter greeting text""" return self._("Python %s on %s\n") % (sys.version, sys.platform) @property def greeting(self): + """PythonReports greeting text""" return self._( "Set \"data\" variable to report data sequence for preview.\n") def __init__(self, master=None, cnf={}, **kw): + # pylint: disable-msg=W0102,W0231,W0233 + # W0102: Dangerous default value {} as argument - that's Tk + # W0231: __init__ method from base class 'ScrolledText' is not called + # W0233: __init__ method from a non direct base class 'ScrolledText' + # is called + # perhaps pylint got confused by Tk/Tix widget hierarchy? ScrolledText.__init__(self, master, cnf=cnf, **kw) _toplevel = self.winfo_toplevel() *************** *** 200,203 **** --- 225,229 ---- def OnKeyPress(self, event): + """Handle window keypress events""" # don't process control and navigation keys if event.char == "": *************** *** 229,236 **** def prompt(self, prompt=sys.ps1): """Write new input prompt""" self.mark_set("insert", "end") if self.compare("insert", "!=", "insert linestart"): self.insert("insert", "\n") ! self.insert("insert", sys.ps1, "prompt") self.see("end") --- 255,264 ---- def prompt(self, prompt=sys.ps1): """Write new input prompt""" + # pylint: disable-msg=E1101 + # E1101: Module 'sys' has no 'ps1' member - assigned at toplevel if so self.mark_set("insert", "end") if self.compare("insert", "!=", "insert linestart"): self.insert("insert", "\n") ! self.insert("insert", prompt, "prompt") self.see("end") *************** *** 246,249 **** --- 274,279 ---- """ + # pylint: disable-msg=E1101 + # E1101: Module 'sys' has no 'ps1' member - assigned at toplevel if so if "input" in self.tag_names(index + " lineend -1c"): # the line contains input area *************** *** 295,299 **** --- 325,333 ---- class CodeSelection(ComboBox): + """Code value selection""" + def __init__(self, master=None, cnf={}, **kw): + # pylint: disable-msg=W0102 + # W0102: Dangerous default value {} as argument - that's Tk self.values = kw.pop("values", ()) ComboBox.__init__(self, master=master, cnf=cnf, **kw) *************** *** 313,317 **** --- 347,354 ---- class ColorSelection(Frame): + """Color value selection""" + def __init__(self, master=None, cnf={}, **kw): + # pylint: disable-msg=W0102 self.var = kw.pop("variable") Frame.__init__(self, master=master, cnf=cnf, **kw) *************** *** 329,335 **** --- 366,374 ---- def updateColor(self, value=NOTHING): """Validate the combo box value; update color indicator""" + _rv = value if value is NOTHING: _color = Color.fromValue(self.var.get()) else: + # got an entered value - must return validated string try: _color = Color.fromValue(value) *************** *** 337,342 **** self.bell() # validation will return current value ! value = self.var.get() ! _color = Color.fromValue(value) else: self.var.set(value) --- 376,381 ---- self.bell() # validation will return current value ! _rv = self.var.get() ! _color = Color.fromValue(_rv) else: self.var.set(value) *************** *** 346,352 **** else: self.indicator.grid_forget() ! return value def OnButton(self): # askcolor returns ((r, g, b), "#rrggbb") or (None, None) _color = askcolor(Color.fromValue(self.var.get()))[1] --- 385,392 ---- else: self.indicator.grid_forget() ! return _rv def OnButton(self): + """Run standard color selection dialog""" # askcolor returns ((r, g, b), "#rrggbb") or (None, None) _color = askcolor(Color.fromValue(self.var.get()))[1] *************** *** 357,360 **** --- 397,402 ---- class PropertyEntry(Frame): + """Generic value entry box""" + # Entry member of the ComboBox is offset to the right. # We need to compensate all other widgets too. *************** *** 372,375 **** --- 414,418 ---- def __init__(self, master=None, cnf={}, **kw): + # pylint: disable-msg=W0102 Frame.__init__(self, master) Frame(self, width=self.LPAD).pack(side=LEFT) *************** *** 381,384 **** --- 424,428 ---- def OnSetFocus(self, event): + """Automatically pass the focus to the inner widget""" self.widget.focus_set() self.widget.select_range(0, "end") *************** *** 386,389 **** --- 430,435 ---- class IntegerSelection(PropertyEntry): + """Spinner box for integer value entry""" + WIDGET = Control DEFAULT_OPTIONS = (("step", 1),) *************** *** 395,398 **** --- 441,445 ---- def OnSetFocus(self, event): + """Pass the focus to the entry widget""" _entry = self.widget.entry _entry.focus_set() *************** *** 401,404 **** --- 448,453 ---- class BooleanSelection(PropertyEntry): + """Checkbox for boolean value entry""" + WIDGET = Checkbutton DEFAULT_OPTIONS = ( *************** *** 413,416 **** --- 462,466 ---- def __init__(self, master=None, cnf={}, **kw): + # pylint: disable-msg=W0102 PropertyEntry.__init__(self, master, cnf, **kw) # XXX on windows, these checkbuttons get white background *************** *** 419,422 **** --- 469,473 ---- # checkbuttons have no .select_range method def OnSetFocus(self, event): + """Pass the focus to the checkbutton""" self.widget.focus_set() *************** *** 424,427 **** --- 475,480 ---- """Widget factory for an attribute data type""" + # pylint: disable-msg=R0903 + # R0903: Too few public methods # instantiated factories *************** *** 482,485 **** --- 535,540 ---- """Data object representing an attribute editable in the properties list""" + # pylint: disable-msg=R0903 + # R0903: Too few public methods class TreeNodeData(list): *************** *** 551,556 **** self.tag = element.tag if nodeid is None: ! nodeid = "%s@%X" % (self.tag, id(self)) ! self.id = nodeid self.parent = parent self.canvas_object = None --- 606,612 ---- self.tag = element.tag if nodeid is None: ! self.id = "%s@%X" % (self.tag, id(self)) ! else: ! self.id = nodeid self.parent = parent self.canvas_object = None *************** *** 708,711 **** --- 764,768 ---- def __init__(self, master=None, cnf={}, **kw): + # pylint: disable-msg=W0102 for (_option, _default) in self.DEFAULTS: kw.setdefault(_option, _default) *************** *** 714,717 **** --- 771,775 ---- def OnClick(self, event): + """Run URL handler program on the URL""" _url = self["text"] if _url: *************** *** 858,862 **** fill=X) # File menu ! _popup = self._build_menu_item(_menu, ''"_File", type="cascade") self._build_menu_item(_popup, ''"_New", command=self.OnMenuFileNew) self._build_menu_item(_popup, ''"_Open", command=self.OnMenuFileOpen) --- 916,920 ---- fill=X) # File menu ! _popup = self._build_menu_item(_menu, ''"_File", item_type="cascade") self._build_menu_item(_popup, ''"_New", command=self.OnMenuFileNew) self._build_menu_item(_popup, ''"_Open", command=self.OnMenuFileOpen) *************** *** 868,879 **** self._build_menu_item(_popup, ''"E_xit", command=self.OnMenuQuit) # Edit menu ! _popup = self._build_menu_item(_menu, ''"_Edit", type="cascade") self._build_menu_item(_popup, ''"Cu_t", event="<<Cut>>") self._build_menu_item(_popup, ''"_Copy", event="<<Copy>>") self._build_menu_item(_popup, ''"_Paste", event="<<Paste>>") # Report menu ! _popup = self._build_menu_item(_menu, ''"_Report", type="cascade") self.report_menu = _popup ! self._build_menu_item(_popup, ''"_Insert...", type="cascade", menu="") self._build_menu_item(_popup, ''"_Delete element", command=lambda: self.deleteNode(self.current_node)) --- 926,938 ---- self._build_menu_item(_popup, ''"E_xit", command=self.OnMenuQuit) # Edit menu ! _popup = self._build_menu_item(_menu, ''"_Edit", item_type="cascade") self._build_menu_item(_popup, ''"Cu_t", event="<<Cut>>") self._build_menu_item(_popup, ''"_Copy", event="<<Copy>>") self._build_menu_item(_popup, ''"_Paste", event="<<Paste>>") # Report menu ! _popup = self._build_menu_item(_menu, ''"_Report", item_type="cascade") self.report_menu = _popup ! self._build_menu_item(_popup, ''"_Insert...", item_type="cascade", ! menu="") self._build_menu_item(_popup, ''"_Delete element", command=lambda: self.deleteNode(self.current_node)) *************** *** 884,888 **** self._build_menu_item(_popup, ''"Print Pre_view", command=self.preview) # Help menu ! _popup = self._build_menu_item(_menu, ''"_Help", type="cascade") self._build_menu_item(_popup, ''"_About...", command=self.OnMenuAbout) # set window menu to created tree --- 943,947 ---- self._build_menu_item(_popup, ''"Print Pre_view", command=self.preview) # Help menu ! _popup = self._build_menu_item(_menu, ''"_Help", item_type="cascade") self._build_menu_item(_popup, ''"_About...", command=self.OnMenuAbout) # set window menu to created tree *************** *** 921,924 **** --- 980,987 ---- else: _underline = -1 + # pylint: disable-msg=W0631 + # W0631: Using possibly undefined loop variable _underline + # if the loop is empty, the variable is initialized + # in the else clause. self._build_menu_item(_menu, _child.tag, underline=_underline, command=lambda tag=_child.tag: self.insertNode(tag)) *************** *** 934,938 **** return (_underline, _text) ! def _build_menu_item(self, parent, label, type="command", event=None, **options ): --- 997,1001 ---- return (_underline, _text) ! def _build_menu_item(self, parent, label, item_type="command", event=None, **options ): *************** *** 946,950 **** one underscore character, second and following underscores are displayed. ! type: item type - "command", "cascade" etc. Default: "command". event: optional name of virtual event to post --- 1009,1013 ---- one underscore character, second and following underscores are displayed. ! item_type: item type - "command", "cascade" etc. Default: "command". event: optional name of virtual event to post *************** *** 953,957 **** additional keyword arguments will be passed right to Tk. ! If type is "cascade", return associated submenu widget. Otherwise return None. --- 1016,1020 ---- additional keyword arguments will be passed right to Tk. ! If item_type is "cascade", return associated submenu widget. Otherwise return None. *************** *** 963,970 **** options["command"] = lambda evt=event: self._post_event(evt) try: ! _make = getattr(parent, "add_" + type) except AttributeError: ! raise ValueError("Unsupported menu object type: %s" % type) ! if type == "cascade": # create submenu unless passed in options if "menu" not in options: --- 1026,1033 ---- options["command"] = lambda evt=event: self._post_event(evt) try: ! _make = getattr(parent, "add_" + item_type) except AttributeError: ! raise ValueError("Unsupported menu object type: %s" % item_type) ! if item_type == "cascade": # create submenu unless passed in options if "menu" not in options: *************** *** 1151,1154 **** --- 1214,1218 ---- @staticmethod def gettext(msg): + """Return msg translated to selected language""" return msg *************** *** 1157,1160 **** --- 1221,1227 ---- @staticmethod def ngettext(singular, plural, n): + """Translate a message with plural forms lookup""" + # pylint: disable-msg=C0103 + # C0103: Invalid name "n" - I quite agree. if n == 1: return singular *************** *** 1245,1249 **** for (_child, _restrict) in validator.children: if _restrict in (validator.ONE, validator.ONE_OR_MORE): ! _create_template_element(_element, _child) return _element --- 1312,1319 ---- for (_child, _restrict) in validator.children: if _restrict in (validator.ONE, validator.ONE_OR_MORE): ! # pylint: disable-msg=W0212 ! # W0212: Access to a protected member _create_template_element ! # of a client class - it's not a client, it's this own class. ! Designer._create_template_element(_element, _child) return _element *************** *** 1269,1272 **** --- 1339,1344 ---- # and "before" position may shift up or down. # force append to the end of list. + # pylint: disable-msg=C0103 + # C0103: Invalid name "before" before = sys.maxint # find contained group or detail element - *************** *** 1303,1307 **** self.tree.open(_node.path) if before < (len(_node) - 1): ! _child.addToTree(self.tree, before=_node[_before + 1].path) else: _child.addToTree(self.tree) --- 1375,1379 ---- self.tree.open(_node.path) if before < (len(_node) - 1): ! _child.addToTree(self.tree, before=_node[before + 1].path) else: _child.addToTree(self.tree) *************** *** 1328,1331 **** --- 1400,1405 ---- def loadFile(self, filename): """Load report file""" + # pylint: disable-msg=W0703 + # W0703: Catch "Exception" - yep, that's what we do here try: self.report = prt.load(filename) *************** *** 1368,1371 **** --- 1442,1447 ---- return False if not filename: + # pylint: disable-msg=C0103 + # C0103: Invalid name "filename" filename = tkFileDialog.asksaveasfilename(**self.fileoptions) if not filename: *************** *** 1393,1397 **** self.data.updateProperties(recursive=True, errors=errors) except AttributeConversionError, _err: ! self.select(_err_path) self.update_idletasks() Message(self, icon="error", type="ok", --- 1469,1473 ---- self.data.updateProperties(recursive=True, errors=errors) except AttributeConversionError, _err: ! self.select(_err.path) self.update_idletasks() Message(self, icon="error", type="ok", *************** *** 1463,1471 **** @staticmethod def _validate(tree, validator): ! # run Template/Printout validator on an ElementTree _root = tree.getroot() validator(tree, _root, "/" + _root.tag) def _run_preview(self): if not self.updateTree(): return --- 1539,1548 ---- @staticmethod def _validate(tree, validator): ! """Run Template/Printout validator on an ElementTree""" _root = tree.getroot() validator(tree, _root, "/" + _root.tag) def _run_preview(self): + """Build and show the report""" if not self.updateTree(): return *************** *** 1525,1528 **** --- 1602,1607 ---- def preview(self): """Show Report Preview for current template""" + # pylint: disable-msg=W0703 + # W0703: Catch "Exception" - yep, that's what we do here _focus = self.focus_get() or self.tree.hlist try: *************** *** 1541,1544 **** --- 1620,1624 ---- def run(argv=sys.argv): + """Command line executable""" if len(argv) > 2: print "Usage: %s [template]" % argv[0] |