由PyQt Designer创建的菜单栏

时间:2018-12-29 15:33:23

标签: python pyqt pyqt5 qt-designer qmenubar

我在PyQt-Designer中设计了一个表面并将其转换为.py 不,我正在尝试将功能链接到菜单栏(按钮)。像打开,保存,关闭...。 我已经尝试了很多,但未成功,希望您能帮助我将一个简单的功能连接到菜单栏中的打开按钮。

例如链接到菜单栏的功能 菜单栏->打开->功能(打开路径):

install:
  ; Remember the location of the original stack
  mov origStack, sp
  mov origStack+2, ss
  ; First we copy the original address of the "int 8" interrupt
  ; to the variable "origAddress"
  mov ax, 0
  mov es, ax
  mov ax, [es:20h]
  mov origAddress, ax
  mov ax, [es:22h]
  mov origAddress+2, ax
  ; We disable hardware interrupt generation
  ; This ensures that "int 8" cannot be generated between the
  ; next two instructions when [0:20h] already contains the
  ; new value but [0:22h] still contains the old one (so the
  ; combination of [0:20h] and [0:22h] is invalid)
  cli
  ; We write the address of our handler to 0:0x20
  mov word ptr [es:20h], offset hookHandler
  mov [es:22h], cs
  ; Now we can enable interrupt generation again
  sti

  ; Actually perform the program
  ...

  ; Uninstall the interrupt hook
  cli
  call uninstallHook
  ; The program finishes normally
  ...

; If the program took longer than 120s, we get here!
timeoutCode:
  cli
  ; Ensure DS contains the correct value
  push cs
  pop ds
  ; Restore the original stack
  lss sp, origStack
  ; Uninstall the hook
  call uninstallHook
  ; The program finishes due to a timeout
  ...

uninstallHook:
  ; Uninstall the hook; note: "cli" has already been called!
  mov ax, 0
  mov es, ax
  mov ax, origAddress
  mov [es:20h], ax
  mov ax, origAddress+2
  mov [es:22h], ax
  sti
  ret

; The actual handler is called 182 times in 10 seconds
; Note that a handler must not modify any registers but
; it must "push" all registers that it modifies and
; restore the original values using "pop"
hookHandler:
  ; Decrement the variable "timeout"
  dec word ptr [cs:timeout]
  ; Is it zero?
  jnz notZero
  ; It is zero; replace the address of the instruction
  ; that is executed after the interrupt by "timeoutCode"
  push bp
  mov bp,sp
  mov word ptr [ss:bp+2], timeoutCode
  mov word ptr [ss:bp+4], cs ; (segment of timeoutCode)
  pop bp
notZero:
  ; Jump to the original handler of the BIOS which will
  ; do the rest (e.g. handle the interrupt controller)
  jmp dword ptr [cs:origAddress]

origAddress DW 0,0
origStack   DW 0,0
timeout     DW 2184

谢谢您的帮助!

以下是代码:

def open_path():
                root= Tk()
                Pfad=askdirectory()
                root.destroy

1 个答案:

答案 0 :(得分:0)

首先,我建议您阅读the docs,建议您不要修改Qt Designer生成的类,但是您必须创建另一个继承自小部件的类并将Qt Designer提供的类用作接口

另一方面,不必使用tkinter,Qt提供了小部件来获取目录路径,例如QFileDialog。

最后,您必须使用self.actionOpen的触发信号。

考虑上述解决方案是:

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        # ...

    def retranslateUi(self, MainWindow):
        # ...

class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.actionOpen.triggered.connect(self.open_file)

    @QtCore.pyqtSlot()
    def open_file(self):
        fdirectory = QtWidgets.QFileDialog.getExistingDirectory(self, "Open Directory")
        if fdirectory:
            print(fdirectory)


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())