| 151 | self.runSignal.emit(text) |
| 152 | |
| 153 | def openFile(self, file): |
| 154 | try: |
| 155 | with open(file, "rb") as fp: |
| 156 | text = fp.read() |
| 157 | encoding = chardet.detect(text) or {} |
| 158 | encoding = encoding.get( |
| 159 | "encoding", "utf-8") or "utf-8" |
| 160 | text = text.decode(encoding) |
| 161 | try: |
| 162 | text = json.dumps( |
| 163 | json.loads(text, encoding=encoding, |
| 164 | object_pairs_hook=OrderedDict), |
| 165 | ensure_ascii=False, indent=4) |
| 166 | except Exception as e: |
| 167 | print(e) |
| 168 | self.setText(text) |
| 169 | except Exception as e: |
| 170 | QMessageBox.critical(self, "错误", str(e)) |
| 171 | |
| 172 | def setText(self, text): |
| 173 | self.codeScintilla.setText(text) |