瀏覽代碼

Report 表格中没有选择时, Report Visual Timing 按钮点击无效
Hierarchy关闭改为隐藏
尝试修正 LineEdit 窗口行号换行的问题

mrh 3 年之前
父節點
當前提交
7e02f6b8ad
共有 8 個文件被更改,包括 80 次插入76 次删除
  1. 0 1
      GuiShell.py
  2. 11 4
      gui.py
  3. 43 47
      sub_windows.py
  4. 6 9
      ui/Form.ui
  5. 6 0
      ui/SideBar.ui
  6. 3 2
      ui/lineNumberWidget.py
  7. 9 13
      ui/ui_Form.py
  8. 2 0
      ui/ui_SideBar.py

+ 0 - 1
GuiShell.py

@@ -32,7 +32,6 @@ class _GuiMain():
         self.Messages = _GuiMessages([])
 
     def Start(self):                       # GUI Loop Entry, Please modify content
-        # self.sig.emit('Start')
         return gui.signale('start')
         
 

+ 11 - 4
gui.py

@@ -7,24 +7,31 @@ 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
+from PySide2.QtCore import QObject,Signal
 from PySide2 import QtCore
 from main_windows import MainWindow
-
+# 兼容4K屏幕
 QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
 QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)
 app = None
 mainWindows:MainWindow = None
+GUI_instan = None
 sub_thread = None
 exit_flag = False
 
+class Application(QApplication):
+    sig = Signal(object)
+    def __init__(self, argv):
+        super().__init__(argv)
+
 def run_forever(GUI):
-    global app,mainWindows
+    global app,mainWindows,GUI_instan
     QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_ShareOpenGLContexts)
-    app = QApplication(sys.argv)
+    app = Application(sys.argv)
     mainWindows = MainWindow(GUI)
     mainWindows.sig.connect(handle_signal)
     GUI.Elaborate("top", True)
+    GUI_instan = GUI
     app.exec_()
     
 def run_in_thread(GUI:QObject):

+ 43 - 47
sub_windows.py

@@ -87,23 +87,22 @@ class FormWindow(Ui_Form, MdiActionWindow):
         self.reportButton.clicked.connect(self.report_virtual_timing)
         self.reportButton.setHidden(not instan._hasReportVirtualTimingButton)
         if instan._hasCrossProbeMenu:
-            self.tableView.customContextMenuRequested.connect(self.right_click_menu)
+            self.tableWidget.customContextMenuRequested.connect(self.right_click_menu)
 
-        self.tableView.setModel(FormWindow.get_form_model(self.instan.Form))
-        self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
+        self.tableWidget.setModel(FormWindow.get_form_model(self.instan.Form))
+        self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
         
         self.mdisubwin:QMdiSubWindow = mainWindow.mdiArea.addSubWindow(self)
         self.mdisubwin.setAttribute(Qt.WA_DeleteOnClose)
         self.mdisubwin.setWindowIcon(QIcon(":/icon/resource/todo-line.png"))
         # mdisubwin.move(mdiArea.x()+(mdiArea.width()-self.width())/2 + self.width()*0.8,mdiArea.y()+(mdiArea.height()-self.height())/2)
         self.mdisubwin.show()
-        width = FormWindow.get_table_width(self.tableView, self)
+        width = FormWindow.get_table_width(self.tableWidget, self)
         self.mdisubwin.resize(width, self.height())
         # 必须要show之后才能 ensure_subwin_in_midarea,因为没有显示时Form窗口大小是不正确的
         # 移动到鼠标 pos 位置
         if pos:
             self.mdisubwin.move(ensure_subwin_in_midarea(mdiArea, self, pos))
-        self.reportButton.clicked.connect(lambda: print(self.geometry()))
     
     def get_form_model(form:GuiType._GuiForm):
         model = QStandardItemModel(0, len(form.FixedRow))
@@ -113,11 +112,11 @@ class FormWindow(Ui_Form, MdiActionWindow):
             model.appendRow(row_items)
         return model
 
-    def get_table_width(tableView:QTableView, win):
+    def get_table_width(tableWidget:QTableWidget, win:MdiActionWindow):
         # 表格与窗口的边距宽度
         width = 28
-        for i in range(tableView.horizontalHeader().count()):
-            width += tableView.columnWidth(i)
+        for i in range(tableWidget.horizontalHeader().count()):
+            width += tableWidget.columnWidth(i)
         if width < win.width():
             width = win.width()
         return width
@@ -128,62 +127,67 @@ class FormWindow(Ui_Form, MdiActionWindow):
         pop_menu.triggered.connect(self.crossprobe)
         pop_menu.exec_(QCursor.pos())
 
-    def get_row(tableView:QTableView):
+    def get_row(tableWidget:QTableView):
         form_row = []
-        for col in range(tableView.model().columnCount()):
-            form_row.append(tableView.model().index(tableView.currentIndex().row(), col).data())
+        for col in range(tableWidget.model().columnCount()):
+            form_row.append(tableWidget.model().index(tableWidget.currentIndex().row(), col).data())
         return form_row
     
     def crossprobe(self, action):
-        form_row = FormWindow.get_row(self.tableView)
+        form_row = FormWindow.get_row(self.tableWidget)
         line_text_win = self.instan.CrossProbe(form_row)
         LineEditWin(self.mainWindow, line_text_win)
     
     def report_virtual_timing(self):
-        form_row = FormWindow.get_row(self.tableView)
+        if self.tableWidget.currentIndex().row() == -1:
+            return
+        form_row = FormWindow.get_row(self.tableWidget)
         thread = threading.Thread(target=self.instan.ReportVirtualTiming, args=(form_row, self.mainWindow.GUI,))
         thread.start()
         
+        
 class MultiFormWin(Ui_Form, MdiActionWindow):
     def __init__(self, mainWindow, instan:GuiType._GuiWinFormMulti) -> None:
         super().__init__(mainWindow)
         self.setupUi(self)
         self.init_multi_form_ui()
         self.setWindowTitle(instan.Title)
-        MultiFormWin.set_form_multi(self.tableView, self.sheets, instan.Forms)
+        MultiFormWin.set_form_multi(self.tableWidget, self.sheets, instan.Forms)
         
         self.instan = instan
-        self.sheets.activated.connect(lambda index: MultiFormWin.activate_table_sheet(self.tableView, self.instan.Forms, index))
+        self.sheets.activated.connect(lambda index: MultiFormWin.activate_table_sheet(self.tableWidget, self.instan.Forms, index))
         self.reportButton.clicked.connect(self.report_virtual_timing)
 
         mdiArea:QMdiArea = mainWindow.mdiArea
         mdisub = mdiArea.addSubWindow(self)
-        width = self.tableView.horizontalHeader().width() * self.tableView.horizontalHeader().count() + 25
+        width = self.tableWidget.horizontalHeader().width() * self.tableWidget.horizontalHeader().count() + 25
         mdisub.setWindowIcon(QIcon(":/icon/resource/todo-line.png"))
         mdisub.resize(width, self.height())
         mdisub.show()
         
-    def set_form_multi(tableView:QTableView, sheets:QComboBox, multi_form:GuiType._GuiFormMulti):
+    def set_form_multi(tableWidget:QTableView, sheets:QComboBox, multi_form:GuiType._GuiFormMulti):
         sheets.clear()
         for sheet_name in multi_form.Names:
             sheets.addItem(sheet_name)
         if sheets.count() > 0:
             form = multi_form.GetForm(sheets.currentIndex())
             model = FormWindow.get_form_model(form)
-            tableView.setModel(model)
+            tableWidget.setModel(model)
 
-    def activate_table_sheet(tableView, form_multi_instan, index):
+    def activate_table_sheet(tableWidget, form_multi_instan, index):
         model = FormWindow.get_form_model(form_multi_instan.GetForm(index))
-        tableView.setModel(model)
+        tableWidget.setModel(model)
     
     def crossprobe(self, action):
-        form_row = FormWindow.get_row(self.tableView)
+        form_row = FormWindow.get_row(self.tableWidget)
         form_name = self.sheets.currentText()
         line_text_win = self.instan.CrossProbe(form_name, form_row)
         LineEditWin(self.mainWindow, line_text_win)
     
     def report_virtual_timing(self):
-        form_row = FormWindow.get_row(self.tableView)
+        if self.tableWidget.currentIndex().row() == -1:
+            return
+        form_row = FormWindow.get_row(self.tableWidget)
         thread = threading.Thread(target=self.instan.ReportVirtualTiming, args=(self.sheets.currentText(), form_row, self.mainWindow.GUI,))
         thread.start()
     
@@ -191,17 +195,7 @@ class MultiFormWin(Ui_Form, MdiActionWindow):
         self.horizontalLayout_2 = QHBoxLayout()
         self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
         self.sheets = QComboBox(self.centralwidget)
-        self.sheets.setObjectName(u"sheets")
-        sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
-        sizePolicy.setHorizontalStretch(0)
-        sizePolicy.setVerticalStretch(0)
-        sizePolicy.setHeightForWidth(self.sheets.sizePolicy().hasHeightForWidth())
-        self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
-        self.tableView.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
-        self.tableView.customContextMenuRequested.connect(self.right_click_menu)
-        
-        self.sheets.setSizePolicy(sizePolicy)
-
+        self.sheets.setObjectName(u"sheets")       
         self.horizontalLayout_2.addWidget(self.sheets)
 
         self.horizontalSpacer_3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
@@ -213,6 +207,10 @@ class MultiFormWin(Ui_Form, MdiActionWindow):
 
         self.verticalLayout.insertLayout(0,self.horizontalLayout_2)
 
+        self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
+        self.tableWidget.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
+        self.tableWidget.customContextMenuRequested.connect(self.right_click_menu)
+
     def right_click_menu(self, pos):
         pop_menu  = QMenu()
         pop_menu.addAction(QAction('Crossprobe', pop_menu))
@@ -315,6 +313,11 @@ class SideBarWin(Ui_SideBar, MdiActionWindow):
         self.mdisubwin.resize(self.width(), mdiArea.height())
         self.mdisubwin.show()
     
+    def closeEvent(self, event: QCloseEvent):
+        event.ignore()
+        self.mdisubwin.hide()
+        self.menuWindow_action.setChecked(False)
+    
     def right_click_menu(self, pos):
         sender = self.sender()
         pop_menu  = QMenu()
@@ -419,26 +422,16 @@ class SideBarWin(Ui_SideBar, MdiActionWindow):
             sub_tree_rows = item.tree_row.GetSubTreeRows()
             for row in sub_tree_rows:
                 self.set_tree_row(item, row)
-    
-    # def activate_table_sheet(self, index):
-    #     model = FormWindow.get_form_model(self.form_multi_instan.GetForm(index))
-    #     self.tableView.setModel(model)
-    # def set_form_multi(self, multi_form:GuiType._GuiFormMulti):
-    #     self.sheets.clear()
-    #     for sheet_name in multi_form.Names:
-    #         self.sheets.addItem(sheet_name)
-    #     if self.sheets.count() > 0:
-    #         form = multi_form.GetForm(self.sheets.currentIndex())
-    #         model = FormWindow.get_form_model(form)
-    #         self.tableView.setModel(model)
-    
+        
     def set_tree_row(self, parent:TreeWidgetItem, tree_row:GuiType._GuiTreeRow):
         tree_widget_item = self.add_tree_row(parent, tree_row)
         if tree_row.HasSubTreeRows:
             # 只添加一个子节点,让父节点变成可展开形式
             sub_tree_row:GuiType._GuiTreeRow = tree_row.GetSubTreeRows()[0]
             self.add_tree_row(tree_widget_item, sub_tree_row)
+        return tree_widget_item
     
+    # 树形控件设置数据
     def set_tree(self, tree:GuiType._GuiTree):
         # 树
         header_item = self.treeWidget.headerItem()
@@ -447,8 +440,11 @@ class SideBarWin(Ui_SideBar, MdiActionWindow):
         for tree_row in tree.TreeRows:
             # 根节点
             self.set_tree_row(self.treeWidget, tree_row)
-        
+        # 默认选择第一行
+        if self.treeWidget.topLevelItemCount():
+            self.treeWidget.setItemSelected(self.treeWidget.topLevelItem(0), True)
 
+    
 class SubWindows(QObject):
     sig = Signal(object)
     def __init__(self, parent):

+ 6 - 9
ui/Form.ui

@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>396</width>
-    <height>388</height>
+    <width>376</width>
+    <height>374</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -20,12 +20,9 @@
   <widget class="QWidget" name="centralwidget">
    <layout class="QGridLayout" name="gridLayout">
     <item row="0" column="0">
-     <layout class="QVBoxLayout" name="verticalLayout" stretch="12,1">
+     <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
       <item>
-       <widget class="QTableView" name="tableView">
-        <property name="contextMenuPolicy">
-         <enum>Qt::CustomContextMenu</enum>
-        </property>
+       <widget class="QTableView" name="tableWidget">
         <property name="editTriggers">
          <set>QAbstractItemView::NoEditTriggers</set>
         </property>
@@ -41,7 +38,7 @@
        </widget>
       </item>
       <item>
-       <layout class="QHBoxLayout" name="horizontalLayout" stretch="1,3,1">
+       <layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0,1">
         <item>
          <spacer name="horizontalSpacer">
           <property name="orientation">
@@ -92,7 +89,7 @@
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>396</width>
+     <width>376</width>
      <height>23</height>
     </rect>
    </property>

+ 6 - 0
ui/SideBar.ui

@@ -56,6 +56,12 @@
           <property name="selectionBehavior">
            <enum>QAbstractItemView::SelectRows</enum>
           </property>
+          <attribute name="horizontalHeaderVisible">
+           <bool>false</bool>
+          </attribute>
+          <attribute name="verticalHeaderVisible">
+           <bool>false</bool>
+          </attribute>
          </widget>
         </item>
        </layout>

+ 3 - 2
ui/lineNumberWidget.py

@@ -1,5 +1,5 @@
 from PySide2.QtGui import *
-from PySide2.QtWidgets import QTextBrowser
+from PySide2.QtWidgets import QTextBrowser,QTextEdit
 from PySide2.QtCore import Qt
 
 
@@ -12,7 +12,8 @@ class LineNumberWidget(QTextBrowser):
         self.__lineCount = widget.document().lineCount()
         self.__size = int(widget.font().pointSizeF())
         self.__styleInit()
-
+        # 尝试解决行号换行问题
+        self.setLineWrapMode(QTextEdit.LineWrapMode.NoWrap)
         self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
         self.setTextInteractionFlags(Qt.NoTextInteraction)
 

+ 9 - 13
ui/ui_Form.py

@@ -21,7 +21,7 @@ class Ui_Form(object):
     def setupUi(self, Form):
         if not Form.objectName():
             Form.setObjectName(u"Form")
-        Form.resize(396, 388)
+        Form.resize(376, 374)
         icon = QIcon()
         icon.addFile(u":/icon/resource/todo-line.png", QSize(), QIcon.Normal, QIcon.Off)
         Form.setWindowIcon(icon)
@@ -31,15 +31,14 @@ class Ui_Form(object):
         self.gridLayout.setObjectName(u"gridLayout")
         self.verticalLayout = QVBoxLayout()
         self.verticalLayout.setObjectName(u"verticalLayout")
-        self.tableView = QTableView(self.centralwidget)
-        self.tableView.setObjectName(u"tableView")
-        self.tableView.setContextMenuPolicy(Qt.CustomContextMenu)
-        self.tableView.setEditTriggers(QAbstractItemView.NoEditTriggers)
-        self.tableView.setSelectionMode(QAbstractItemView.SingleSelection)
-        self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows)
-        self.tableView.verticalHeader().setVisible(False)
+        self.tableWidget = QTableView(self.centralwidget)
+        self.tableWidget.setObjectName(u"tableWidget")
+        self.tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
+        self.tableWidget.setSelectionMode(QAbstractItemView.SingleSelection)
+        self.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)
+        self.tableWidget.verticalHeader().setVisible(False)
 
-        self.verticalLayout.addWidget(self.tableView)
+        self.verticalLayout.addWidget(self.tableWidget)
 
         self.horizontalLayout = QHBoxLayout()
         self.horizontalLayout.setObjectName(u"horizontalLayout")
@@ -62,20 +61,17 @@ class Ui_Form(object):
         self.horizontalLayout.addItem(self.horizontalSpacer_2)
 
         self.horizontalLayout.setStretch(0, 1)
-        self.horizontalLayout.setStretch(1, 3)
         self.horizontalLayout.setStretch(2, 1)
 
         self.verticalLayout.addLayout(self.horizontalLayout)
 
-        self.verticalLayout.setStretch(0, 12)
-        self.verticalLayout.setStretch(1, 1)
 
         self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1)
 
         Form.setCentralWidget(self.centralwidget)
         self.menubar = QMenuBar(Form)
         self.menubar.setObjectName(u"menubar")
-        self.menubar.setGeometry(QRect(0, 0, 396, 23))
+        self.menubar.setGeometry(QRect(0, 0, 376, 23))
         Form.setMenuBar(self.menubar)
 
         self.retranslateUi(Form)

+ 2 - 0
ui/ui_SideBar.py

@@ -54,6 +54,8 @@ class Ui_SideBar(object):
         self.tableView.setTabKeyNavigation(True)
         self.tableView.setSelectionMode(QAbstractItemView.SingleSelection)
         self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows)
+        self.tableView.horizontalHeader().setVisible(False)
+        self.tableView.verticalHeader().setVisible(False)
 
         self.verticalLayout.addWidget(self.tableView)