codekingpro/portable-devtools
115k
1######################################################################2##3## The Pychecker MDI Plug-In UserModule for Pythonwin4##5## contributed by Robert Kiendl6##7## Style is similar to (and inherited) from the SGrepMDI UserModule8##9## Usage:10##11## Start Pychecker on current file: Menu/File/New../Pychecker.12## Use it: Jump to Pychecker warning source lines by double-click.13## Auto-add "#$pycheck_no" / "#$pycheck_no=specific-re-pattern" tags14## to source lines by context/right-mouse-click on warning lines.15##16## It requires pychecker installed and the pychecker.bat to be on17## the PATH. Example pychecker.bat:18##19## REM pychecker.bat20## C:\bin\python.exe C:\PYTHON23\Lib\site-packages\pychecker\checker.py %1 %2 %3 %4 %5 %6 %7 %8 %921##22## Adding it as default module in PythonWin:23##24## +++ ./intpyapp.py 2006-10-02 17:59:32.974161600 +020025## @@ -272,7 +282,7 @@26## def LoadUserModules(self, moduleNames = None):27## # Load the users modules.28## if moduleNames is None:29## - default = "sgrepmdi"30## + default = "sgrepmdi,mdi_pychecker"31## moduleNames=win32ui.GetProfileVal('Python','Startup Modules',default)32## self.DoLoadModules(moduleNames)33##34######################################################################35 36import glob37import os38import re39import sys40import time41 42import win32api43import win32con44import win32ui45from pywin.mfc import dialog, docview, window46 47from . import scriptutils48 49 50def getsubdirs(d):51 dlist = []52 flist = glob.glob(d + "\\*")53 for f in flist:54 if os.path.isdir(f):55 dlist.append(f)56 dlist = dlist + getsubdirs(f)57 return dlist58 59 60class dirpath:61 def __init__(self, str, recurse=0):62 dp = str.split(";")63 dirs = {}64 for d in dp:65 if os.path.isdir(d):66 d = d.lower()67 if d not in dirs:68 dirs[d] = None69 if recurse:70 subdirs = getsubdirs(d)71 for sd in subdirs:72 sd = sd.lower()73 if sd not in dirs:74 dirs[sd] = None75 elif os.path.isfile(d):76 pass77 else:78 x = None79 if d in os.environ:80 x = dirpath(os.environ[d])81 elif d[:5] == "HKEY_":82 keystr = d.split("\\")83 try:84 root = eval("win32con." + keystr[0])85 except:86 win32ui.MessageBox(87 "Can't interpret registry key name '%s'" % keystr[0]88 )89 try:90 subkey = "\\".join(keystr[1:])91 val = win32api.RegQueryValue(root, subkey)92 if val:93 x = dirpath(val)94 else:95 win32ui.MessageBox(96 "Registry path '%s' did not return a path entry" % d97 )98 except:99 win32ui.MessageBox(100 "Can't interpret registry key value: %s" % keystr[1:]101 )102 else:103 win32ui.MessageBox("Directory '%s' not found" % d)104 if x:105 for xd in x:106 if xd not in dirs:107 dirs[xd] = None108 if recurse:109 subdirs = getsubdirs(xd)110 for sd in subdirs:111 sd = sd.lower()112 if sd not in dirs:113 dirs[sd] = None114 self.dirs = []115 for d in dirs.keys():116 self.dirs.append(d)117 118 def __getitem__(self, key):119 return self.dirs[key]120 121 def __len__(self):122 return len(self.dirs)123 124 def __setitem__(self, key, value):125 self.dirs[key] = value126 127 def __delitem__(self, key):128 del self.dirs[key]129 130 def __getslice__(self, lo, hi):131 return self.dirs[lo:hi]132 133 def __setslice__(self, lo, hi, seq):134 self.dirs[lo:hi] = seq135 136 def __delslice__(self, lo, hi):137 del self.dirs[lo:hi]138 139 def __add__(self, other):140 if type(other) == type(self) or type(other) == type([]):141 return self.dirs + other.dirs142 143 def __radd__(self, other):144 if type(other) == type(self) or type(other) == type([]):145 return other.dirs + self.dirs146 147 148# Group(1) is the filename, group(2) is the lineno.149# regexGrepResult=regex.compile("^\\([a-zA-Z]:.*\\)(\\([0-9]+\\))")150# regexGrep=re.compile(r"^([a-zA-Z]:[^(]*)\((\d+)\)")151regexGrep = re.compile(r"^(..[^\(:]+)?[\(:](\d+)[\):]:?\s*(.*)")152 153# these are the atom numbers defined by Windows for basic dialog controls154 155BUTTON = 0x80156EDIT = 0x81157STATIC = 0x82158LISTBOX = 0x83159SCROLLBAR = 0x84160COMBOBOX = 0x85161 162 163class TheTemplate(docview.RichEditDocTemplate):164 def __init__(self):165 docview.RichEditDocTemplate.__init__(166 self, win32ui.IDR_TEXTTYPE, TheDocument, TheFrame, TheView167 )168 self.SetDocStrings(169 "\nPychecker\nPychecker\nPychecker params (*.pychecker)\n.pychecker\n\n\n"170 )171 win32ui.GetApp().AddDocTemplate(self)172 self.docparams = None173 174 def MatchDocType(self, fileName, fileType):175 doc = self.FindOpenDocument(fileName)176 if doc:177 return doc178 ext = os.path.splitext(fileName)[1].lower()179 if ext == ".pychecker":180 return win32ui.CDocTemplate_Confidence_yesAttemptNative181 return win32ui.CDocTemplate_Confidence_noAttempt182 183 def setParams(self, params):184 self.docparams = params185 186 def readParams(self):187 tmp = self.docparams188 self.docparams = None189 return tmp190 191 192class TheFrame(window.MDIChildWnd):193 # The template and doc params will one day be removed.194 def __init__(self, wnd=None):195 window.MDIChildWnd.__init__(self, wnd)196 197 198class TheDocument(docview.RichEditDoc):199 def __init__(self, template):200 docview.RichEditDoc.__init__(self, template)201 self.dirpattern = ""202 self.filpattern = ""203 self.greppattern = ""204 self.casesensitive = 1205 self.recurse = 1206 self.verbose = 0207 208 def OnOpenDocument(self, fnm):209 # this bizarre stuff with params is so right clicking in a result window210 # and starting a new grep can communicate the default parameters to the211 # new grep.212 try:213 params = open(fnm, "r").read()214 except:215 params = None216 self.setInitParams(params)217 return self.OnNewDocument()218 219 def OnCloseDocument(self):220 try:221 win32ui.GetApp().DeleteIdleHandler(self.idleHandler)222 except:223 pass224 return self._obj_.OnCloseDocument()225 226 def saveInitParams(self):227 # Only save the flags, not the text boxes.228 paramstr = "\t\t\t%d\t%d" % (self.casesensitive, self.recurse)229 win32ui.WriteProfileVal("Pychecker", "Params", paramstr)230 231 def setInitParams(self, paramstr):232 if paramstr is None:233 paramstr = win32ui.GetProfileVal("Pychecker", "Params", "\t\t\t1\t0\t0")234 params = paramstr.split("\t")235 if len(params) < 3:236 params = params + [""] * (3 - len(params))237 if len(params) < 6:238 params = params + [0] * (6 - len(params))239 self.dirpattern = params[0]240 self.filpattern = params[1]241 self.greppattern = params[2] or "-#1000 --only"242 self.casesensitive = int(params[3])243 self.recurse = int(params[4])244 self.verbose = int(params[5])245 # setup some reasonable defaults.246 if not self.dirpattern:247 try:248 editor = win32ui.GetMainFrame().MDIGetActive()[0].GetEditorView()249 self.dirpattern = os.path.abspath(250 os.path.dirname(editor.GetDocument().GetPathName())251 )252 except (AttributeError, win32ui.error):253 self.dirpattern = os.getcwd()254 if not self.filpattern:255 try:256 editor = win32ui.GetMainFrame().MDIGetActive()[0].GetEditorView()257 self.filpattern = editor.GetDocument().GetPathName()258 except AttributeError:259 self.filpattern = "*.py"260 261 def OnNewDocument(self):262 if self.dirpattern == "":263 self.setInitParams(greptemplate.readParams())264 d = TheDialog(265 self.dirpattern,266 self.filpattern,267 self.greppattern,268 self.casesensitive,269 self.recurse,270 self.verbose,271 )272 if d.DoModal() == win32con.IDOK:273 self.dirpattern = d["dirpattern"]274 self.filpattern = d["filpattern"]275 self.greppattern = d["greppattern"]276 # self.casesensitive = d['casesensitive']277 # self.recurse = d['recursive']278 # self.verbose = d['verbose']279 self.doSearch()280 self.saveInitParams()281 return 1282 return 0 # cancelled - return zero to stop frame creation.283 284 def doSearch(self):285 self.dp = dirpath(self.dirpattern, self.recurse)286 self.SetTitle(287 "Pychecker Run '%s' (options: %s)" % (self.filpattern, self.greppattern)288 )289 # self.text = []290 self.GetFirstView().Append(291 "#Pychecker Run in " + self.dirpattern + " %s\n" % time.asctime()292 )293 if self.verbose:294 self.GetFirstView().Append("# =" + repr(self.dp.dirs) + "\n")295 self.GetFirstView().Append("# Files " + self.filpattern + "\n")296 self.GetFirstView().Append("# Options " + self.greppattern + "\n")297 self.fplist = self.filpattern.split(";")298 self.GetFirstView().Append(299 "# Running... ( double click on result lines in order to jump to the source code ) \n"300 )301 win32ui.SetStatusText("Pychecker running. Please wait...", 0)302 self.dpndx = self.fpndx = 0303 self.fndx = -1304 if not self.dp:305 self.GetFirstView().Append(306 "# ERROR: '%s' does not resolve to any search locations"307 % self.dirpattern308 )309 self.SetModifiedFlag(0)310 else:311 ##self.flist = glob.glob(self.dp[0]+'\\'+self.fplist[0])312 import operator313 314 self.flist = reduce(operator.add, list(map(glob.glob, self.fplist)))315 # import pywin.debugger;pywin.debugger.set_trace()316 self.startPycheckerRun()317 318 def idleHandler(self, handler, count):319 import time320 321 time.sleep(0.001)322 if self.result != None:323 win32ui.GetApp().DeleteIdleHandler(self.idleHandler)324 return 0325 return 1 # more326 327 def startPycheckerRun(self):328 self.result = None329 old = win32api.SetCursor(win32api.LoadCursor(0, win32con.IDC_APPSTARTING))330 win32ui.GetApp().AddIdleHandler(self.idleHandler)331 import _thread332 333 _thread.start_new(self.threadPycheckerRun, ())334 ##win32api.SetCursor(old)335 336 def threadPycheckerRun(self):337 result = ""338 rc = -1339 try:340 options = self.greppattern341 files = " ".join(self.flist)342 # Recently MarkH has failed to run pychecker without it having343 # been explicitly installed - so we assume it is and locate it344 # from its default location.345 # Step1 - get python.exe346 py = os.path.join(sys.prefix, "python.exe")347 if not os.path.isfile(py):348 if "64 bit" in sys.version:349 py = os.path.join(sys.prefix, "PCBuild", "amd64", "python.exe")350 else:351 py = os.path.join(sys.prefix, "PCBuild", "python.exe")352 try:353 py = win32api.GetShortPathName(py)354 except win32api.error:355 py = ""356 # Find checker.py357 import sysconfig358 359 pychecker = os.path.join(360 sysconfig.get_paths()["purelib"], "pychecker", "checker.py"361 )362 if not os.path.isfile(py):363 result = "Can't find python.exe!\n"364 elif not os.path.isfile(pychecker):365 result = (366 "Can't find checker.py - please install pychecker "367 "(or run 'setup.py install' if you have the source version)\n"368 )369 else:370 cmd = '%s "%s" %s %s 2>&1' % (py, pychecker, options, files)371 ##fin,fout,ferr=os.popen3(cmd)372 ##result=ferr.read()+fout.read()373 result = os.popen(cmd).read()374 ##rc=f.close()375 self.GetFirstView().Append(result)376 finally:377 self.result = result378 print("== Pychecker run finished ==")379 self.GetFirstView().Append("\n" + "== Pychecker run finished ==")380 self.SetModifiedFlag(0)381 382 def _inactive_idleHandler(self, handler, count):383 self.fndx = self.fndx + 1384 if self.fndx < len(self.flist):385 f = self.flist[self.fndx]386 if self.verbose:387 self.GetFirstView().Append("# .." + f + "\n")388 win32ui.SetStatusText("Searching " + f, 0)389 lines = open(f, "r").readlines()390 for i in range(len(lines)):391 line = lines[i]392 if self.pat.search(line) != None:393 self.GetFirstView().Append(f + "(" + repr(i + 1) + ") " + line)394 else:395 self.fndx = -1396 self.fpndx = self.fpndx + 1397 if self.fpndx < len(self.fplist):398 self.flist = glob.glob(399 self.dp[self.dpndx] + "\\" + self.fplist[self.fpndx]400 )401 else:402 self.fpndx = 0403 self.dpndx = self.dpndx + 1404 if self.dpndx < len(self.dp):405 self.flist = glob.glob(406 self.dp[self.dpndx] + "\\" + self.fplist[self.fpndx]407 )408 else:409 win32ui.SetStatusText("Search complete.", 0)410 self.SetModifiedFlag(0) # default to not modified.411 try:412 win32ui.GetApp().DeleteIdleHandler(self.idleHandler)413 except:414 pass415 return 0416 return 1417 418 def GetParams(self):419 return (420 self.dirpattern421 + "\t"422 + self.filpattern423 + "\t"424 + self.greppattern425 + "\t"426 + repr(self.casesensitive)427 + "\t"428 + repr(self.recurse)429 + "\t"430 + repr(self.verbose)431 )432 433 def OnSaveDocument(self, filename):434 # print 'OnSaveDocument() filename=',filename435 savefile = open(filename, "wb")436 txt = self.GetParams() + "\n"437 # print 'writing',txt438 savefile.write(txt)439 savefile.close()440 self.SetModifiedFlag(0)441 return 1442 443 444ID_OPEN_FILE = 0xE500445ID_PYCHECKER = 0xE501446ID_SAVERESULTS = 0x502447ID_TRYAGAIN = 0x503448ID_ADDCOMMENT = 0x504449ID_ADDPYCHECKNO2 = 0x505450 451 452class TheView(docview.RichEditView):453 def __init__(self, doc):454 docview.RichEditView.__init__(self, doc)455 self.SetWordWrap(win32ui.CRichEditView_WrapNone)456 self.HookHandlers()457 458 def OnInitialUpdate(self):459 rc = self._obj_.OnInitialUpdate()460 format = (-402653169, 0, 200, 0, 0, 0, 49, "Courier New")461 self.SetDefaultCharFormat(format)462 return rc463 464 def HookHandlers(self):465 self.HookMessage(self.OnRClick, win32con.WM_RBUTTONDOWN)466 self.HookCommand(self.OnCmdOpenFile, ID_OPEN_FILE)467 self.HookCommand(self.OnCmdThe, ID_PYCHECKER)468 self.HookCommand(self.OnCmdSave, ID_SAVERESULTS)469 self.HookCommand(self.OnTryAgain, ID_TRYAGAIN)470 self.HookCommand(self.OnAddComment, ID_ADDCOMMENT)471 self.HookCommand(self.OnAddComment, ID_ADDPYCHECKNO2)472 self.HookMessage(self.OnLDblClick, win32con.WM_LBUTTONDBLCLK)473 474 def OnLDblClick(self, params):475 line = self.GetLine()476 regexGrepResult = regexGrep.match(line)477 if regexGrepResult:478 fname = regexGrepResult.group(1)479 line = int(regexGrepResult.group(2))480 scriptutils.JumpToDocument(fname, line)481 return 0 # dont pass on482 return 1 # pass it on by default.483 484 def OnRClick(self, params):485 menu = win32ui.CreatePopupMenu()486 flags = win32con.MF_STRING | win32con.MF_ENABLED487 lineno = self._obj_.LineFromChar(-1) # selection or current line488 line = self._obj_.GetLine(lineno)489 regexGrepResult = regexGrep.match(line)490 charstart, charend = self._obj_.GetSel()491 if regexGrepResult:492 self.fnm = regexGrepResult.group(1)493 self.lnnum = int(regexGrepResult.group(2))494 menu.AppendMenu(flags, ID_OPEN_FILE, "&Open " + self.fnm)495 menu.AppendMenu(496 flags, ID_ADDCOMMENT, "&Add to source: Comment Tag/#$pycheck_no .."497 )498 menu.AppendMenu(499 flags,500 ID_ADDPYCHECKNO2,501 "&Add to source: Specific #$pycheck_no=%(errtext)s ..",502 )503 menu.AppendMenu(win32con.MF_SEPARATOR)504 menu.AppendMenu(flags, ID_TRYAGAIN, "&Try Again")505 menu.AppendMenu(flags, win32ui.ID_EDIT_CUT, "Cu&t")506 menu.AppendMenu(flags, win32ui.ID_EDIT_COPY, "&Copy")507 menu.AppendMenu(flags, win32ui.ID_EDIT_PASTE, "&Paste")508 menu.AppendMenu(flags, win32con.MF_SEPARATOR)509 menu.AppendMenu(flags, win32ui.ID_EDIT_SELECT_ALL, "&Select all")510 menu.AppendMenu(flags, win32con.MF_SEPARATOR)511 menu.AppendMenu(flags, ID_SAVERESULTS, "Sa&ve results")512 menu.TrackPopupMenu(params[5])513 return 0514 515 def OnAddComment(self, cmd, code):516 addspecific = cmd == ID_ADDPYCHECKNO2517 _ = list(self.GetSel())518 _.sort()519 start, end = _520 line_start, line_end = self.LineFromChar(start), self.LineFromChar(end)521 first = 1522 for i in range(line_start, line_end + 1):523 line = self.GetLine(i)524 m = regexGrep.match(line)525 if m:526 if first:527 first = 0528 cmnt = dialog.GetSimpleInput(529 "Add to %s lines" % (line_end - line_start + 1),530 addspecific531 and " #$pycheck_no=%(errtext)s"532 or " #$pycheck_no",533 )534 if not cmnt:535 return 0536 ##import pywin.debugger;pywin.debugger.set_trace()537 fname = m.group(1)538 line = int(m.group(2))539 view = scriptutils.JumpToDocument(fname, line)540 pos = view.LineIndex(line) - 1541 if view.GetTextRange(pos - 1, pos) in ("\r", "\n"):542 pos -= 1543 view.SetSel(pos, pos)544 errtext = m.group(3)545 if start != end and line_start == line_end:546 errtext = self.GetSelText()547 errtext = repr(re.escape(errtext).replace("\ ", " "))548 view.ReplaceSel(addspecific and cmnt % locals() or cmnt)549 return 0550 551 def OnCmdOpenFile(self, cmd, code):552 doc = win32ui.GetApp().OpenDocumentFile(self.fnm)553 if doc:554 vw = doc.GetFirstView()555 # hope you have an editor that implements GotoLine()!556 try:557 vw.GotoLine(int(self.lnnum))558 except:559 pass560 return 0561 562 def OnCmdThe(self, cmd, code):563 curparamsstr = self.GetDocument().GetParams()564 params = curparamsstr.split("\t")565 params[2] = self.sel566 greptemplate.setParams("\t".join(params))567 greptemplate.OpenDocumentFile()568 return 0569 570 def OnTryAgain(self, cmd, code):571 greptemplate.setParams(self.GetDocument().GetParams())572 greptemplate.OpenDocumentFile()573 return 0574 575 def OnCmdSave(self, cmd, code):576 flags = win32con.OFN_OVERWRITEPROMPT577 dlg = win32ui.CreateFileDialog(578 0, None, None, flags, "Text Files (*.txt)|*.txt||", self579 )580 dlg.SetOFNTitle("Save Results As")581 if dlg.DoModal() == win32con.IDOK:582 pn = dlg.GetPathName()583 self._obj_.SaveFile(pn)584 return 0585 586 def Append(self, strng):587 numlines = self.GetLineCount()588 endpos = self.LineIndex(numlines - 1) + len(self.GetLine(numlines - 1))589 self.SetSel(endpos, endpos)590 self.ReplaceSel(strng)591 592 593class TheDialog(dialog.Dialog):594 def __init__(self, dp, fp, gp, cs, r, v):595 style = (596 win32con.DS_MODALFRAME597 | win32con.WS_POPUP598 | win32con.WS_VISIBLE599 | win32con.WS_CAPTION600 | win32con.WS_SYSMENU601 | win32con.DS_SETFONT602 )603 CS = win32con.WS_CHILD | win32con.WS_VISIBLE604 tmp = [605 ["Pychecker Run", (0, 0, 210, 90), style, None, (8, "MS Sans Serif")],606 ]607 tmp.append([STATIC, "Files:", -1, (7, 7, 50, 9), CS])608 tmp.append(609 [610 EDIT,611 gp,612 103,613 (52, 7, 144, 11),614 CS | win32con.WS_TABSTOP | win32con.ES_AUTOHSCROLL | win32con.WS_BORDER,615 ]616 )617 tmp.append([STATIC, "Directories:", -1, (7, 20, 50, 9), CS])618 tmp.append(619 [620 EDIT,621 dp,622 102,623 (52, 20, 128, 11),624 CS | win32con.WS_TABSTOP | win32con.ES_AUTOHSCROLL | win32con.WS_BORDER,625 ]626 )627 tmp.append(628 [629 BUTTON,630 "...",631 110,632 (182, 20, 16, 11),633 CS | win32con.BS_PUSHBUTTON | win32con.WS_TABSTOP,634 ]635 )636 tmp.append([STATIC, "Options:", -1, (7, 33, 50, 9), CS])637 tmp.append(638 [639 EDIT,640 fp,641 101,642 (52, 33, 128, 11),643 CS | win32con.WS_TABSTOP | win32con.ES_AUTOHSCROLL | win32con.WS_BORDER,644 ]645 )646 tmp.append(647 [648 BUTTON,649 "...",650 111,651 (182, 33, 16, 11),652 CS | win32con.BS_PUSHBUTTON | win32con.WS_TABSTOP,653 ]654 )655 # tmp.append([BUTTON,'Case sensitive', 104, (7, 45, 72, 9), CS | win32con.BS_AUTOCHECKBOX | win32con.BS_LEFTTEXT| win32con.WS_TABSTOP])656 # tmp.append([BUTTON,'Subdirectories', 105, (7, 56, 72, 9), CS | win32con.BS_AUTOCHECKBOX | win32con.BS_LEFTTEXT| win32con.WS_TABSTOP])657 # tmp.append([BUTTON,'Verbose', 106, (7, 67, 72, 9), CS | win32con.BS_AUTOCHECKBOX | win32con.BS_LEFTTEXT| win32con.WS_TABSTOP])658 tmp.append(659 [660 BUTTON,661 "OK",662 win32con.IDOK,663 (166, 53, 32, 12),664 CS | win32con.BS_DEFPUSHBUTTON | win32con.WS_TABSTOP,665 ]666 )667 tmp.append(668 [669 BUTTON,670 "Cancel",671 win32con.IDCANCEL,672 (166, 67, 32, 12),673 CS | win32con.BS_PUSHBUTTON | win32con.WS_TABSTOP,674 ]675 )676 dialog.Dialog.__init__(self, tmp)677 self.AddDDX(101, "greppattern")678 self.AddDDX(102, "dirpattern")679 self.AddDDX(103, "filpattern")680 # self.AddDDX(104,'casesensitive')681 # self.AddDDX(105,'recursive')682 # self.AddDDX(106,'verbose')683 self._obj_.data["greppattern"] = gp684 self._obj_.data["dirpattern"] = dp685 self._obj_.data["filpattern"] = fp686 # self._obj_.data['casesensitive'] = cs687 # self._obj_.data['recursive'] = r688 # self._obj_.data['verbose'] = v689 self.HookCommand(self.OnMoreDirectories, 110)690 self.HookCommand(self.OnMoreFiles, 111)691 692 def OnMoreDirectories(self, cmd, code):693 self.getMore("Pychecker\\Directories", "dirpattern")694 695 def OnMoreFiles(self, cmd, code):696 self.getMore("Pychecker\\File Types", "filpattern")697 698 def getMore(self, section, key):699 self.UpdateData(1)700 # get the items out of the ini file701 ini = win32ui.GetProfileFileName()702 secitems = win32api.GetProfileSection(section, ini)703 items = []704 for secitem in secitems:705 items.append(secitem.split("=")[1])706 dlg = TheParamsDialog(items)707 if dlg.DoModal() == win32con.IDOK:708 itemstr = ";".join(dlg.getItems())709 self._obj_.data[key] = itemstr710 # update the ini file with dlg.getNew()711 i = 0712 newitems = dlg.getNew()713 if newitems:714 items = items + newitems715 for item in items:716 win32api.WriteProfileVal(section, repr(i), item, ini)717 i = i + 1718 self.UpdateData(0)719 720 def OnOK(self):721 self.UpdateData(1)722 for id, name in (723 (101, "greppattern"),724 (102, "dirpattern"),725 (103, "filpattern"),726 ):727 if not self[name]:728 self.GetDlgItem(id).SetFocus()729 win32api.MessageBeep()730 win32ui.SetStatusText("Please enter a value")731 return732 self._obj_.OnOK()733 734 735class TheParamsDialog(dialog.Dialog):736 def __init__(self, items):737 self.items = items738 self.newitems = []739 style = (740 win32con.DS_MODALFRAME741 | win32con.WS_POPUP742 | win32con.WS_VISIBLE743 | win32con.WS_CAPTION744 | win32con.WS_SYSMENU745 | win32con.DS_SETFONT746 )747 CS = win32con.WS_CHILD | win32con.WS_VISIBLE748 tmp = [749 [750 "Pychecker Parameters",751 (0, 0, 205, 100),752 style,753 None,754 (8, "MS Sans Serif"),755 ],756 ]757 tmp.append(758 [759 LISTBOX,760 "",761 107,762 (7, 7, 150, 72),763 CS764 | win32con.LBS_MULTIPLESEL765 | win32con.LBS_STANDARD766 | win32con.LBS_HASSTRINGS767 | win32con.WS_TABSTOP768 | win32con.LBS_NOTIFY,769 ]770 )771 tmp.append(772 [773 BUTTON,774 "OK",775 win32con.IDOK,776 (167, 7, 32, 12),777 CS | win32con.BS_DEFPUSHBUTTON | win32con.WS_TABSTOP,778 ]779 )780 tmp.append(781 [782 BUTTON,783 "Cancel",784 win32con.IDCANCEL,785 (167, 23, 32, 12),786 CS | win32con.BS_PUSHBUTTON | win32con.WS_TABSTOP,787 ]788 )789 tmp.append([STATIC, "New:", -1, (2, 83, 15, 12), CS])790 tmp.append(791 [792 EDIT,793 "",794 108,795 (18, 83, 139, 12),796 CS | win32con.WS_TABSTOP | win32con.ES_AUTOHSCROLL | win32con.WS_BORDER,797 ]798 )799 tmp.append(800 [801 BUTTON,802 "Add",803 109,804 (167, 83, 32, 12),805 CS | win32con.BS_PUSHBUTTON | win32con.WS_TABSTOP,806 ]807 )808 dialog.Dialog.__init__(self, tmp)809 self.HookCommand(self.OnAddItem, 109)810 self.HookCommand(self.OnListDoubleClick, 107)811 812 def OnInitDialog(self):813 lb = self.GetDlgItem(107)814 for item in self.items:815 lb.AddString(item)816 return self._obj_.OnInitDialog()817 818 def OnAddItem(self, cmd, code):819 eb = self.GetDlgItem(108)820 item = eb.GetLine(0)821 self.newitems.append(item)822 lb = self.GetDlgItem(107)823 i = lb.AddString(item)824 lb.SetSel(i, 1)825 return 1826 827 def OnListDoubleClick(self, cmd, code):828 if code == win32con.LBN_DBLCLK:829 self.OnOK()830 return 1831 832 def OnOK(self):833 lb = self.GetDlgItem(107)834 self.selections = lb.GetSelTextItems()835 self._obj_.OnOK()836 837 def getItems(self):838 return self.selections839 840 def getNew(self):841 return self.newitems842 843 844try:845 win32ui.GetApp().RemoveDocTemplate(greptemplate)846except NameError:847 pass848 849greptemplate = TheTemplate()850 