def mySearch(self, rexp): ok, filelist = getfilelist(globalvalue.chmpath) if not ok: return extlist = [] for a, b in globalvalue.globalcfg.searchext.iteritems(): if b: extlist.append(a) sflist = self.__filt(filelist, extlist) prgrs = QtGui.QProgressDialog(u'Searching ...', u'Abort', 0, len(sflist), self) prgrs.forceShow() rt = [] for i, f in enumerate(sflist): prgrs.setValue(i) if i % 5 == 0: if prgrs.wasCanceled(): break fctt = globalvalue.chmFile.GetFileAsStrByUrl( f.decode('utf-8', 'ignore')) if not fctt: continue rrt = detenc.search(fctt) if rrt: enc = rrt.group(1) elif globalvalue.encoding: enc = globalvalue.encoding else: enc = 'utf-8' rc = re.compile(unicode(rexp).encode(enc)) ttt = rc.search(fctt) if ttt: rt.append( (f.decode('utf-8', 'ignore'), ttt.group(0).decode(enc, 'ignore'))) self.tree.clear() for url, name in rt: item = QTreeWidgetItem(self.tree) item.url = url item.setText(0, name) item.setText(1, url) self.tree.update() prgrs.setValue(len(sflist))
def onExtractChm(self): od = QtGui.QFileDialog.getExistingDirectory( self, 'select a directory to store files', '', QtGui.QFileDialog.ShowDirsOnly | QtGui.QFileDialog.DontResolveSymlinks) if len(od) == 0: return ok, filelist = getfilelist(globalvalue.chmpath) if not ok: return prgrs = QtGui.QProgressDialog(u'Extract chm file', u'Abort', 0, len(filelist), self) prgrs.forceShow() od = unicode(od).encode(sys.getfilesystemencoding()) for i, opath in enumerate(filelist): prgrs.setValue(i) if i % 5 == 0: if prgrs.wasCanceled(): break fpath = opath.decode('utf-8').encode(sys.getfilesystemencoding()) if fpath[0] != '/': fpath = '/' + fpath fpath = os.path.normpath(fpath) fpath = fpath[1:] fpath = os.path.join(od, fpath) fdir, file = os.path.split(fpath) try: os.makedirs(fdir) except: pass s = globalvalue.chmFile.GetFileAsStrByUrl(opath.decode('utf-8')) if s == None: #print 'extract',opath,'failed' continue try: file = open(fpath, 'wb') file.write(s) file.flush() file.close() print 'extract:', opath.decode('utf-8') except: print 'cannot open', fpath prgrs.setValue(len(filelist))
def onExtractChm(self): od=QtGui.QFileDialog.getExistingDirectory(self, 'select a directory to store files', '', QtGui.QFileDialog.ShowDirsOnly|QtGui.QFileDialog.DontResolveSymlinks) if len(od)==0: return ok,filelist=getfilelist(globalvalue.chmpath) if not ok: return prgrs=QtGui.QProgressDialog(u'Extract chm file',u'Abort', 0, len(filelist),self) prgrs.forceShow() od=unicode(od).encode(sys.getfilesystemencoding()) for i,opath in enumerate(filelist): prgrs.setValue(i) if i%5==0: if prgrs.wasCanceled(): break fpath=opath.decode('utf-8').encode(sys.getfilesystemencoding()) if fpath[0]!='/': fpath='/'+fpath fpath=os.path.normpath(fpath) fpath=fpath[1:] fpath=os.path.join(od,fpath) fdir,file=os.path.split(fpath) try: os.makedirs(fdir) except: pass s=globalvalue.chmFile.GetFileAsStrByUrl(opath.decode('utf-8')) if s==None: #print 'extract',opath,'failed' continue try: file=open(fpath,'wb') file.write(s) file.flush() file.close() print 'extract:',opath.decode('utf-8') except: print 'cannot open',fpath prgrs.setValue(len(filelist))
def mySearch(self,rexp): ok,filelist=getfilelist(globalvalue.chmpath) if not ok: return extlist=[] for a,b in globalvalue.globalcfg.searchext.iteritems(): if b: extlist.append(a) sflist=self.__filt(filelist,extlist) prgrs=QtGui.QProgressDialog(u'Searching ...',u'Abort', 0, len(sflist),self) prgrs.forceShow() rt=[] for i,f in enumerate(sflist): prgrs.setValue(i) if i%5==0: if prgrs.wasCanceled(): break fctt=globalvalue.chmFile.GetFileAsStrByUrl(f.decode('utf-8','ignore')) if not fctt: continue rrt=detenc.search(fctt) if rrt: enc=rrt.group(1) elif globalvalue.encoding: enc=globalvalue.encoding else: enc='utf-8' rc=re.compile(unicode(rexp).encode(enc)) ttt=rc.search(fctt) if ttt: rt.append((f.decode('utf-8','ignore'),ttt.group(0).decode(enc,'ignore'))) self.tree.clear() for url,name in rt: item=QTreeWidgetItem(self.tree) item.url=url item.setText(0,name) item.setText(1,url) self.tree.update() prgrs.setValue(len(sflist))