MCPcopy Create free account
hub / github.com/PyQt5/PyQt / CodeWidget

Class CodeWidget

Test/ChartView/ChatWidget.py:133–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131
132
133class CodeWidget(QWidget):
134 runSignal = pyqtSignal(str)
135
136 def __init__(self, *args, **kwargs):
137 super(CodeWidget, self).__init__(*args, **kwargs)
138 layout = QVBoxLayout(self, spacing=0)
139 layout.setContentsMargins(0, 0, 0, 0)
140
141 self.runButton = QPushButton(
142 "运行", self, objectName="RunButton", clicked=self.onRunButton)
143 self.codeScintilla = CodeScintilla(self)
144 layout.addWidget(self.runButton)
145 layout.addWidget(self.codeScintilla)
146
147 def onRunButton(self):
148 text = self.text()
149 if not text:
150 return QMessageBox.information(self, "提示", "json数据不能为空")
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)
174
175 def text(self):
176 return self.codeScintilla.text().strip()
177
178
179class ChartWidget(QWidget):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected