这是我的 main.py 我有一个名为 loadShot 的函数,我想从另一个函数调用它
class MainWindow(QMainWindow):
# Main Window UI
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
loadUi(os.path.join(SCRIPT_DIRECTORY, 'mainwindow.ui'), self)
self.connectInterface()
# Connect signals
def connectInterface(self):
self.scene_Line.textChanged.connect(self.shotName)
self.activeProjcet_Line.textChanged.connect(self.shotName)
self.character_Line.textChanged.connect(self.shotName)
self.take_Line.valueChanged.connect(self.shotName)
self.load_Button.setShortcut(QKeySequence("Alt+B"))
####################################################
# Shot Loader Functions
####################################################
def browse(self, dir):
root = Tkinter.Tk()
root.withdraw() #use to hide tkinter window
tempdir = tkFileDialog.askdirectory(parent=root, initialdir=dir, title='Please select a directory')
if tempdir.startswith('D:/Capture data/'):
self.activeProjcet_Line.setText(tempdir)
elif tempdir.startswith('R:/Project Files/'):
self.uploadProjcet_Line.setText(tempdir)
self.uploadFolder()
else:
pass
def uploadFolder(self):
project = self.activeProjcet_Line.text()
uploadDir = self.uploadProjcet_Line.text()
f = open('C:/_Mocap/output/folderName.txt', 'w')
f.write(' \n' + project.replace('D:/Capture data/', '') + '\n' + uploadDir.replace('R:/Project Files/', ''))
f.close()
def loadShot(self):
shot = self.shotName_Line.text()
f = open('C:/_Mocap/output/ShotLoader.txt', 'w')
f.write('\n' + '[name]\n' + '\n' + 'take Name=' + shot)
f.close()
self.uploadFolder()
if self.incrementTake.isChecked():
self.takeIncrement()
else:
pass
这是我的另一个 python 文件,它是一个关键的侦听器,我想要 loadShot 函数。问题是我一直将 MainWindow 作为实例加载。这是我做不到的。我只需要能够在我的 MainWindow 类中调用该函数而无需加载另一个实例。
def handle_Ctrl_L ():
m = MainWindow()
m.loadShot()
hk = HotKeys()
w = WindowMgr()
pid = w.GetProcessID('Blade')
w.focusWindow(pid)
time.sleep(.2)
hk.F8()