示例#1
0
 def occur(self, what, regex=False):
     content = self.toPlainText().split('\n')
     if regex:
         regexp = QRegExp(what, Qt.CaseInsensitive)
         content = [line for line in content if regexp.indexIn(line) >= 0]
     else:
         what = what.lower()
         content = [line for line in content if what in line.lower()]
     content = '\n'.join(content)
     window = QMainWindow(self)
     window.resize(600, 800)
     window.setWindowTitle('Lines matching %r' % what)
     widget = QTextEdit(window)
     widget.setFont(self.font())
     window.setCentralWidget(widget)
     widget.setText(content)
     window.show()
示例#2
0
文件: elog.py 项目: ess-dmsc/nicos
 def on_page_unsupportedContent(self, reply):
     if reply.url().scheme() != 'file':
         return
     filename = reply.url().path()
     if filename.endswith('.dat'):
         content = open(filename, encoding='utf-8', errors='replace').read()
         window = QMainWindow(self)
         window.resize(600, 800)
         window.setWindowTitle(filename)
         widget = QTextEdit(window)
         widget.setFontFamily('monospace')
         window.setCentralWidget(widget)
         widget.setText(content)
         window.show()
     else:
         # try to open the link with host computer default application
         try:
             QDesktopServices.openUrl(reply.url())
         except Exception:
             pass