Browse Source

新增 About 窗口;
新增Prompt变量;
实现 nc_shell 按钮的功能;
更改 GuiType 实现 import *

mrh 3 years ago
parent
commit
b7db177387
10 changed files with 236 additions and 46 deletions
  1. 26 6
      GuiShell.py
  2. 35 17
      GuiType.py
  3. 1 1
      gui.py
  4. 14 5
      main_windows.py
  5. 1 1
      sub_windows.py
  6. 19 0
      ui/About.py
  7. 75 0
      ui/About.ui
  8. 3 7
      ui/MainWindows.ui
  9. 55 0
      ui/ui_About.py
  10. 7 9
      ui/ui_MainWindows.py

+ 26 - 6
GuiShell.py

@@ -10,10 +10,10 @@ import rlcompleter
 import traceback
 from PySide2.QtCore import QObject, QThread, Signal
 import gui 
-from GuiType import (_GuiForm,_GuiFormMulti,_GuiTreeRow,_GuiTree,_GuiWinText,
-                    _GuiWinLinedText,_GuiWinForm,_GuiWinFormMulti,_GuiWinTree,_GuiSideBar,
-                    _GuiMessages,)
-# from GuiType import *
+# from GuiType import (_GuiForm,_GuiFormMulti,_GuiTreeRow,_GuiTree,_GuiWinText,
+#                     _GuiWinLinedText,_GuiWinForm,_GuiWinFormMulti,_GuiWinTree,_GuiSideBar,
+#                     _GuiMessage, _GuiMessages,)
+from GuiType import *
 
 class _GuiMain():
     Title = "NeoConstraint"
@@ -25,12 +25,14 @@ class _GuiMain():
     TextFontSize = 10
     SysFont = "FreeMono"
     SysFontSize = 9
-
+    About = "NeoConstraint(R) 2023.03-Alpha\nChipara, Inc. Ltd"     # Help-About
+    Prompt = "nc_shell-t>"        # Console-Shell
+ 
     def __init__(self):
         super().__init__()
         self.SideBar = _GuiSideBar(
             "Hierarchy", _GuiTree(["", "DFFs", "SubModules"], []))
-        self.Messages = _GuiMessages([], [], [], [])
+        self.Messages = _GuiMessages([])
 
     def Start(self):                       # GUI Loop Entry, Please modify content
         # self.sig.emit('Start')
@@ -210,6 +212,24 @@ class _GuiMain():
     def run(self):
         self.Elaborate("top", True)
         shell_loop()
+    
+    def Exit(self):                        # File - Exit
+        os._exit(0)
+    
+    def GetHistory(self):              # Console - History
+        return ["first cmd", "last cmd"]
+    
+    def GetErrors(self):                # Console - Message
+        return _GuiMessages([["Err-123","This is an error",[_GuiMessage("This is an error!", 100, "/x/x.v"),_GuiMessage("This is an error!!", 200, "/xx/xx.v")]]])
+    
+    def GetCriticalWarnings(self): # Console - Message
+        return _GuiMessages([])
+    
+    def GetWarnings(self):            # Console - Message
+        return _GuiMessages([["Warn-234","This is a warning",[_GuiMessage("This is a warning!", 100, "/x/x.v"),_GuiMessage("This is a warning!!", 200, "/xx/xx.v")]]])
+    
+    def GetInfos(self):                  # Console - Message
+        return _GuiMessages([["Info-345","This is an info",[_GuiMessage("This is an info!", 100, "/x/x.v"),]],["Info-456","This is another info",[_GuiMessage("This is another info!", 200, "/xx/xx.v"),]]])
 
 # _GUI.Analyze([["SearchPath", "../.."],["SV2009", "file.sv"]])
 # _GUI.Elaborate("DemoDesign", True)

+ 35 - 17
GuiType.py

@@ -1,7 +1,12 @@
 ###################
 #  Gui Data Types
 ###################
-
+# from GuiType import (_GuiForm,_GuiFormMulti,_GuiTreeRow,_GuiTree,_GuiWinText,
+#                     _GuiWinLinedText,_GuiWinForm,_GuiWinFormMulti,_GuiWinTree,_GuiSideBar,
+#                     _GuiMessage, _GuiMessages,)
+__all__ = ["_GuiForm","_GuiFormMulti","_GuiTreeRow","_GuiTree","_GuiWinText",
+            "_GuiWinLinedText","_GuiWinForm","_GuiWinFormMulti","_GuiWinTree","_GuiSideBar",
+            "_GuiMessage", "_GuiMessages",]
 
 class _GuiForm():
     def __init__(self, fixed_row, rows):
@@ -112,19 +117,32 @@ class _GuiSideBar():
         assert isinstance(formrow, list)
         return _GuiWinForm(str(formname)+" Properties", _GuiForm(["Name", "Property"], [[x, "property"] for x in treenames+formrow]))
 
-
-class _GuiMessages():  # to be further defined
-    def __init__(self):
-        self.Infos = []
-        self.Warnings = []
-        self.CriticalWarnings = []
-        self.Errors = []
-
-    def CrossProbe(self, filename, line):
-        return _GuiWinLinedText(filename, ("Text Start\n\n"+'\n'.join(['generated line '+str(x) for x in range(line*2)])+"\n\nText End").split("\n"), line)
-
-    def __init__(self, info, warn, crit, err):
-        self.Infos = info
-        self.Warnings = warn
-        self.CriticalWarnings = crit
-        self.Errors = err
+class _GuiMessage():  # _GuiMessage("This is an error!!!", 100, "/x/xx.v")
+    def __init__(self, text, line, filepath):
+        self.Text = text
+        self.Line = line
+        self.FilePath = filepath
+    def GetHint(self):
+        return "line: "+str(self.Line)+", file: "+self.FilePath
+    def CrossProbe(self):
+        return _GuiWinLinedText(self.FilePath, ("Text Start\n\n"+'\n'.join(['generated line '+str(x) for x in range(3, self.Line*2)])+"\n\nText End").split("\n"), self.Line)
+    def Properties(self):
+        return _GuiWinForm("Message Properties", _GuiForm(["Name", "Property"], [["File", self.FilePath], ["Line", str(self.Line)]]))
+
+class _GuiMessages():  # _GuiMessages([["Err-123","This is an error",[_GuiMessage("This is an error!", 100, "/x/x.v"),_GuiMessage("This is an error!!", 200, "/xx/xx.v")]]])
+    def __init__(self, id_messages):
+        self.Size = 0
+        self._summary = []
+        self._messages = {}
+        for idm in id_messages:
+            assert len(idm) == 3
+            assert isinstance(idm[0], str) and idm[0] != ""      # "Err-123"
+            assert isinstance(idm[1], str)                       # "This is an error"
+            assert isinstance(idm[2], list) and len(idm[2]) > 0  # [_GuiMessage(), _GuiMessage()]
+            self.Size += len(idm[2])
+            self._summary.append([idm[0], len(idm[2]), idm[1]])
+            self._messages[idm[0]] = idm[2]
+    def GetSummary(self):      # [["Err-123", 2, "This is an error"],]
+        return self._summary
+    def GetMsgByID(self, ID):  # [_GuiMessage(), _GuiMessage()]
+        return self._messages[ID]

+ 1 - 1
gui.py

@@ -4,6 +4,7 @@ import time
 # sys.path.append(os.path.dirname(__file__))
 # 必须要把 ui 目录添加到系统路径,否则子目录文件 ui_MainWindows.py 无法 import 资源文件
 sys.path.append(os.path.join(os.path.dirname(__file__), 'ui'))
+sys.path.append(os.path.join(os.path.dirname(__file__), 'test_u'))
 import threading
 from PySide2.QtWidgets import QApplication
 from PySide2.QtCore import QObject
@@ -23,7 +24,6 @@ def run_forever(GUI):
     app = QApplication(sys.argv)
     mainWindows = MainWindow(GUI)
     mainWindows.sig.connect(handle_signal)
-    mainWindows.show_analyze_window()
     app.exec_()
     
 def run_in_thread(GUI:QObject):

+ 14 - 5
main_windows.py

@@ -11,7 +11,7 @@ from PySide2.QtGui import QTextCursor
 from ui.ui_MainWindows import Ui_MainWindow
 from ui.Analyze import AnalyzeWindow
 from sub_windows import SubWindows
-
+from ui.About import AboutWindow
         
 class Stream(QObject):
     """Redirects console output to text widget."""
@@ -63,10 +63,12 @@ class MainWindow(Ui_MainWindow, QMainWindow):
         self.setupUi(self)
         # 这里显示一下是为了能获取到 mdiArea 的尺寸,给 sub_windows 使用
         self.show()
-        
+        self.btn_shell.setText(GUI.Prompt)
+        self.btn_shell.clicked.connect(self.click_btn_sell)
         self.loader = QUiLoader()
         self.actionReport_Virtual_Timing.triggered.connect(self.add_sub_win)
-
+        self.actionAbout.triggered.connect(self.about)
+        self.actionAnalyze.triggered.connect(self.show_analyze_window)
         self.textEdit.document().contentsChanged.connect(self.textEdit_change_size)
         self.textEdit.document().contentsChange.connect(self.textEdit_change_contents)
         sys.stdout = Stream()
@@ -77,7 +79,11 @@ class MainWindow(Ui_MainWindow, QMainWindow):
                 
         self.sub_win = SubWindows(self)
         self.sub_win.sig.connect(self.sub_win.add_windows)
-        self.actionAnalyze.triggered.connect(self.show_analyze_window)
+    
+    
+    def about(self):
+        d = AboutWindow(self, self.GUI.About)
+        d.exec_()
     
     def show_analyze_window(self):
         d = AnalyzeWindow(self, self.GUI.Shell_Execute)
@@ -93,7 +99,10 @@ class MainWindow(Ui_MainWindow, QMainWindow):
     def textEdit_change_size(self):
         height = self.textEdit.document().size().height()
         self.textEdit.setMinimumHeight(height)
-        
+    
+    def click_btn_sell(self):
+        self.textEdit.append('\n')
+    
     def textEdit_change_contents(self, from_index, charsRemoved, charsAdded):
         if not charsAdded:
             return

+ 1 - 1
sub_windows.py

@@ -9,7 +9,7 @@ from ui.ui_SideBar import Ui_SideBar
 from ui.lineNumberWidget import LineNumberWidget
 from ui.ui_LineEdit import Ui_LineEdit
 from ui.Analyze import AnalyzeWindow
-import GuiType
+import GuiType as GuiType
 
 def get_sub_win(mdiArea:QMdiArea, class_type, title=''):
     for mid_sub_win in mdiArea.subWindowList():

+ 19 - 0
ui/About.py

@@ -0,0 +1,19 @@
+from PySide2.QtWidgets import *
+from PySide2.QtCore import *
+from PySide2.QtGui import *
+from ui.ui_About import Ui_AboutDialog
+
+class AboutWindow(Ui_AboutDialog, QDialog):
+    def __init__(self, mainWindow, txt) -> None:
+        super().__init__()
+        self.setupUi(self)
+        index = 1
+        for line in txt.split("\n"):
+            label = QLabel(self)
+            label.setText(line)
+            label.setAlignment(Qt.AlignmentFlag.AlignHCenter)
+            self.verticalLayout.insertWidget(index, label)
+            index += 1
+        self.move(mainWindow.x()+(mainWindow.width()-self.width())/2,mainWindow.y()+(mainWindow.height()-self.height())/2)
+        self.show()
+        self.setHidden(False)

+ 75 - 0
ui/About.ui

@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>AboutDialog</class>
+ <widget class="QDialog" name="AboutDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>358</width>
+    <height>240</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>About</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <layout class="QVBoxLayout" name="verticalLayout">
+     <item>
+      <spacer name="verticalSpacer">
+       <property name="orientation">
+        <enum>Qt::Vertical</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>20</width>
+         <height>40</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <spacer name="verticalSpacer_2">
+       <property name="orientation">
+        <enum>Qt::Vertical</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>20</width>
+         <height>40</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item alignment="Qt::AlignHCenter">
+      <widget class="QPushButton" name="pushButton">
+       <property name="text">
+        <string>Close</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>pushButton</sender>
+   <signal>clicked()</signal>
+   <receiver>AboutDialog</receiver>
+   <slot>close()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>178</x>
+     <y>218</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>178</x>
+     <y>119</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>

+ 3 - 7
ui/MainWindows.ui

@@ -29,7 +29,7 @@
         <enum>QTabWidget::South</enum>
        </property>
        <property name="currentIndex">
-        <number>2</number>
+        <number>0</number>
        </property>
        <widget class="QWidget" name="LogPage">
         <attribute name="title">
@@ -51,11 +51,7 @@
         </attribute>
         <layout class="QGridLayout" name="gridLayout_3">
          <item row="0" column="0">
-          <widget class="QTextEdit" name="HistoryText">
-           <property name="readOnly">
-            <bool>true</bool>
-           </property>
-          </widget>
+          <widget class="QTableWidget" name="tableHistory"/>
          </item>
         </layout>
        </widget>
@@ -75,7 +71,7 @@
     <item row="1" column="0">
      <layout class="QHBoxLayout" name="horizontalLayout_2">
       <item>
-       <widget class="QPushButton" name="pushButton">
+       <widget class="QPushButton" name="btn_shell">
         <property name="text">
          <string>nc_shell-p&gt;</string>
         </property>

+ 55 - 0
ui/ui_About.py

@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+
+################################################################################
+## Form generated from reading UI file 'About.ui'
+##
+## Created by: Qt User Interface Compiler version 5.15.0
+##
+## WARNING! All changes made in this file will be lost when recompiling UI file!
+################################################################################
+
+from PySide2.QtCore import (QCoreApplication, QDate, QDateTime, QMetaObject,
+    QObject, QPoint, QRect, QSize, QTime, QUrl, Qt)
+from PySide2.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont,
+    QFontDatabase, QIcon, QKeySequence, QLinearGradient, QPalette, QPainter,
+    QPixmap, QRadialGradient)
+from PySide2.QtWidgets import *
+
+
+class Ui_AboutDialog(object):
+    def setupUi(self, AboutDialog):
+        if not AboutDialog.objectName():
+            AboutDialog.setObjectName(u"AboutDialog")
+        AboutDialog.resize(358, 240)
+        self.gridLayout = QGridLayout(AboutDialog)
+        self.gridLayout.setObjectName(u"gridLayout")
+        self.verticalLayout = QVBoxLayout()
+        self.verticalLayout.setObjectName(u"verticalLayout")
+        self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
+
+        self.verticalLayout.addItem(self.verticalSpacer)
+
+        self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
+
+        self.verticalLayout.addItem(self.verticalSpacer_2)
+
+        self.pushButton = QPushButton(AboutDialog)
+        self.pushButton.setObjectName(u"pushButton")
+
+        self.verticalLayout.addWidget(self.pushButton, 0, Qt.AlignHCenter)
+
+
+        self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1)
+
+
+        self.retranslateUi(AboutDialog)
+        self.pushButton.clicked.connect(AboutDialog.close)
+
+        QMetaObject.connectSlotsByName(AboutDialog)
+    # setupUi
+
+    def retranslateUi(self, AboutDialog):
+        AboutDialog.setWindowTitle(QCoreApplication.translate("AboutDialog", u"About", None))
+        self.pushButton.setText(QCoreApplication.translate("AboutDialog", u"Close", None))
+    # retranslateUi
+

+ 7 - 9
ui/ui_MainWindows.py

@@ -84,7 +84,6 @@ class Ui_MainWindow(object):
         icon6.addFile(u":/icon/resource/Read Power Intent.png", QSize(), QIcon.Normal, QIcon.On)
         self.actionRead_Power_Intent.setIcon(icon6)
         font = QFont()
-        font.setStrikeOut(False)
         self.actionRead_Power_Intent.setFont(font)
         self.actionReload_Design = QAction(MainWindow)
         self.actionReload_Design.setObjectName(u"actionReload_Design")
@@ -147,11 +146,10 @@ class Ui_MainWindow(object):
         self.HistoryPage.setObjectName(u"HistoryPage")
         self.gridLayout_3 = QGridLayout(self.HistoryPage)
         self.gridLayout_3.setObjectName(u"gridLayout_3")
-        self.HistoryText = QTextEdit(self.HistoryPage)
-        self.HistoryText.setObjectName(u"HistoryText")
-        self.HistoryText.setReadOnly(True)
+        self.tableHistory = QTableWidget(self.HistoryPage)
+        self.tableHistory.setObjectName(u"tableHistory")
 
-        self.gridLayout_3.addWidget(self.HistoryText, 0, 0, 1, 1)
+        self.gridLayout_3.addWidget(self.tableHistory, 0, 0, 1, 1)
 
         self.tabWidget.addTab(self.HistoryPage, "")
         self.MessagePage = QWidget()
@@ -170,10 +168,10 @@ class Ui_MainWindow(object):
 
         self.horizontalLayout_2 = QHBoxLayout()
         self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
-        self.pushButton = QPushButton(self.centralwidget)
-        self.pushButton.setObjectName(u"pushButton")
+        self.btn_shell = QPushButton(self.centralwidget)
+        self.btn_shell.setObjectName(u"btn_shell")
 
-        self.horizontalLayout_2.addWidget(self.pushButton)
+        self.horizontalLayout_2.addWidget(self.btn_shell)
 
         self.textEdit = QTextEdit(self.centralwidget)
         self.textEdit.setObjectName(u"textEdit")
@@ -321,7 +319,7 @@ class Ui_MainWindow(object):
         self.tabWidget.setTabText(self.tabWidget.indexOf(self.LogPage), QCoreApplication.translate("MainWindow", u"Log", None))
         self.tabWidget.setTabText(self.tabWidget.indexOf(self.HistoryPage), QCoreApplication.translate("MainWindow", u"History", None))
         self.tabWidget.setTabText(self.tabWidget.indexOf(self.MessagePage), QCoreApplication.translate("MainWindow", u"Message", None))
-        self.pushButton.setText(QCoreApplication.translate("MainWindow", u"nc_shell-p>", None))
+        self.btn_shell.setText(QCoreApplication.translate("MainWindow", u"nc_shell-p>", None))
         self.menuFile.setTitle(QCoreApplication.translate("MainWindow", u"File", None))
         self.menuEdit.setTitle(QCoreApplication.translate("MainWindow", u"Edit", None))
         self.menuView.setTitle(QCoreApplication.translate("MainWindow", u"View", None))