|
@@ -1,6 +1,7 @@
|
|
|
import queue
|
|
import queue
|
|
|
import re
|
|
import re
|
|
|
import sys
|
|
import sys
|
|
|
|
|
+import threading
|
|
|
from PySide2.QtWidgets import QApplication, QMainWindow
|
|
from PySide2.QtWidgets import QApplication, QMainWindow
|
|
|
from PySide2.QtUiTools import QUiLoader
|
|
from PySide2.QtUiTools import QUiLoader
|
|
|
from PySide2.QtWidgets import *
|
|
from PySide2.QtWidgets import *
|
|
@@ -8,34 +9,13 @@ from PySide2.QtCore import *
|
|
|
from PySide2 import QtCore
|
|
from PySide2 import QtCore
|
|
|
from PySide2.QtGui import QTextCursor
|
|
from PySide2.QtGui import QTextCursor
|
|
|
from ui.ui_MainWindows import Ui_MainWindow
|
|
from ui.ui_MainWindows import Ui_MainWindow
|
|
|
-from ui.ui_TimingAnalyze import Ui_TimingWindow
|
|
|
|
|
-from hier import HierWin
|
|
|
|
|
from sub_windows import SubWindows
|
|
from sub_windows import SubWindows
|
|
|
|
|
|
|
|
-class NcShell(QObject):
|
|
|
|
|
- sig = Signal(str)
|
|
|
|
|
- def __init__(self, thread, GUI):
|
|
|
|
|
- super().__init__()
|
|
|
|
|
- self.stdin = ''
|
|
|
|
|
- self._GUI = GUI
|
|
|
|
|
- self._thread = thread
|
|
|
|
|
- self.queue = queue.Queue()
|
|
|
|
|
-
|
|
|
|
|
- def run(self):
|
|
|
|
|
- while 1:
|
|
|
|
|
- stdin = self.queue.get()
|
|
|
|
|
- self._GUI.Shell_Execute(stdin)
|
|
|
|
|
- # # print('que get:{}'.format(stdin))
|
|
|
|
|
- # try:
|
|
|
|
|
- # print(eval(stdin))
|
|
|
|
|
- # except Exception as e:
|
|
|
|
|
- # print(e)
|
|
|
|
|
- # print('demo> ', end='')
|
|
|
|
|
|
|
|
|
|
class Stream(QObject):
|
|
class Stream(QObject):
|
|
|
"""Redirects console output to text widget."""
|
|
"""Redirects console output to text widget."""
|
|
|
newText = Signal(str)
|
|
newText = Signal(str)
|
|
|
- def __init__(self, stdout=None):
|
|
|
|
|
|
|
+ def __init__(self):
|
|
|
super().__init__()
|
|
super().__init__()
|
|
|
self.stdout_bak = sys.stdout
|
|
self.stdout_bak = sys.stdout
|
|
|
self.buffer = self.stdout_bak.buffer
|
|
self.buffer = self.stdout_bak.buffer
|
|
@@ -75,14 +55,10 @@ class Stream(QObject):
|
|
|
if text.isspace():
|
|
if text.isspace():
|
|
|
return
|
|
return
|
|
|
self.newText.emit(str(text+'\n'))
|
|
self.newText.emit(str(text+'\n'))
|
|
|
- # self.newText.emit(str(text))
|
|
|
|
|
- # loop = QEventLoop()
|
|
|
|
|
- # QTimer.singleShot(100, loop.quit)
|
|
|
|
|
- # loop.exec_()
|
|
|
|
|
- # QApplication.processEvents()
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
class MainWindow(Ui_MainWindow, QMainWindow):
|
|
class MainWindow(Ui_MainWindow, QMainWindow):
|
|
|
- lineEdit_sig = Signal(str)
|
|
|
|
|
|
|
+ textEdit_sig = Signal(str)
|
|
|
sig = Signal(object)
|
|
sig = Signal(object)
|
|
|
def __init__(self, GUI) -> None:
|
|
def __init__(self, GUI) -> None:
|
|
|
super().__init__()
|
|
super().__init__()
|
|
@@ -93,20 +69,15 @@ class MainWindow(Ui_MainWindow, QMainWindow):
|
|
|
self.loader = QUiLoader()
|
|
self.loader = QUiLoader()
|
|
|
self.actionReport_Virtual_Timing.triggered.connect(self.add_sub_win)
|
|
self.actionReport_Virtual_Timing.triggered.connect(self.add_sub_win)
|
|
|
|
|
|
|
|
- self.lineEdit.returnPressed.connect(self.lineEdit_function)
|
|
|
|
|
|
|
+ self.textEdit.document().contentsChanged.connect(self.textEdit_change_size)
|
|
|
|
|
+ self.textEdit.document().contentsChange.connect(self.textEdit_change_contents)
|
|
|
|
|
+
|
|
|
sys.stdout = Stream()
|
|
sys.stdout = Stream()
|
|
|
sys.stdout.newText.connect(self.outputWritten)
|
|
sys.stdout.newText.connect(self.outputWritten)
|
|
|
sys.stderr = sys.stdout
|
|
sys.stderr = sys.stdout
|
|
|
- # sys.stderr.newText.connect(self.outputWritten)
|
|
|
|
|
self.GUI = GUI
|
|
self.GUI = GUI
|
|
|
self.setWindowTitle(GUI.Title)
|
|
self.setWindowTitle(GUI.Title)
|
|
|
-
|
|
|
|
|
- self.nc_shell_thread = QThread(self)
|
|
|
|
|
- self.nc_shell = NcShell(self.nc_shell_thread, GUI)
|
|
|
|
|
- self.nc_shell.moveToThread(self.nc_shell_thread)
|
|
|
|
|
- self.nc_shell_thread.started.connect(self.nc_shell.run)
|
|
|
|
|
- self.nc_shell_thread.start()
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
self.sub_win = SubWindows(self)
|
|
self.sub_win = SubWindows(self)
|
|
|
self.sub_win.sig.connect(self.sub_win.add_windows)
|
|
self.sub_win.sig.connect(self.sub_win.add_windows)
|
|
|
|
|
|
|
@@ -116,22 +87,28 @@ class MainWindow(Ui_MainWindow, QMainWindow):
|
|
|
cursor.insertText(text)
|
|
cursor.insertText(text)
|
|
|
self.LogText.setTextCursor(cursor)
|
|
self.LogText.setTextCursor(cursor)
|
|
|
self.LogText.ensureCursorVisible()
|
|
self.LogText.ensureCursorVisible()
|
|
|
-
|
|
|
|
|
- def lineEdit_function(self):
|
|
|
|
|
- stdin = self.lineEdit.text()
|
|
|
|
|
- print(stdin)
|
|
|
|
|
- # stdin = stdin.replace('_GUI', 'self._GUI')
|
|
|
|
|
- self.nc_shell.queue.put_nowait(stdin)
|
|
|
|
|
- # self.nc_shell.stdin = stdin
|
|
|
|
|
- # self.nc_shell_thread.start()
|
|
|
|
|
- # print('eval:', stdin)
|
|
|
|
|
- # stdout = eval(stdin)
|
|
|
|
|
- # print(stdout)
|
|
|
|
|
- # print('send:', self.lineEdit.text())
|
|
|
|
|
- # self.lineEdit_sig.emit(self.lineEdit.text())
|
|
|
|
|
- # sys.stdout.stdout_bak.flush()
|
|
|
|
|
- # self.gui_info
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ def textEdit_change_size(self):
|
|
|
|
|
+ height = self.textEdit.document().size().height()
|
|
|
|
|
+ self.textEdit.setMinimumHeight(height)
|
|
|
|
|
+
|
|
|
|
|
+ def textEdit_change_contents(self, from_index, charsRemoved, charsAdded):
|
|
|
|
|
+ if not charsAdded:
|
|
|
|
|
+ return
|
|
|
|
|
+ stdin = self.textEdit.toPlainText()
|
|
|
|
|
+ # 捕获回车键
|
|
|
|
|
+ if stdin[from_index] != '\n':
|
|
|
|
|
+ return
|
|
|
|
|
+ # 回车时,判断字符串代码是否结束
|
|
|
|
|
+ if self.GUI.Shell_IsCmdFinished(stdin):
|
|
|
|
|
+ # 删除回车字符
|
|
|
|
|
+ stdin = stdin[:from_index] + stdin[from_index+1:]
|
|
|
|
|
+ print(stdin)
|
|
|
|
|
+ thread = threading.Thread(target=self.GUI.Shell_Execute, args=(stdin,))
|
|
|
|
|
+ thread.start()
|
|
|
|
|
+ self.textEdit.setText('')
|
|
|
|
|
+ self.textEdit_change_size()
|
|
|
|
|
+
|
|
|
def add_sub_win(self):
|
|
def add_sub_win(self):
|
|
|
print('add sub')
|
|
print('add sub')
|
|
|
self.t = self.loader.load("ui/TimingAnalyze.ui")
|
|
self.t = self.loader.load("ui/TimingAnalyze.ui")
|