2015-01-07 45 views
-1

最後一個應用程序我與Pyside新來的傢伙,我試圖創造3DSMAX 2015插件現在我有取消按鈕合上Pyside

我有一個「主表」

麻煩

enter image description here

當我點擊「添加新對象」,我會顯示新的窗體。我們可以把它叫做是「子表」

enter image description here

當我點擊按鈕「取消」,所有的應用程序退出,3Dsmax2 015也。 我只想退出「子表格」。

這是我的代碼:

from PySide import QtGui,QtCore 
import MaxPlus 
import sys 

class _GCProtector(object): 
    widgets = [] 

app = QtGui.QApplication.instance() 
if not app: 
    app = QtGui.QApplication([]) 

def main():  
    MaxPlus.FileManager.Reset(True) 
    w = QtGui.QWidget() 

    w.setFixedSize(300,360) 
    w.setWindowTitle('Library') 
    _GCProtector.widgets.append(w) 
    w.show() 

    main_layout = QtGui.QGridLayout() 
    main_layout.addWidget(First(),0,0,2,0) 
    w.setLayout(main_layout) 

def First(): 
    # FIRST FRAME 
    FirstFrame = QtGui.QFrame() 
    FirstFrame.setMaximumWidth(230) 
    FirstFrame.setMaximumHeight(700) 
    # LABEL RENDERER 
    renderer_lb = QtGui.QLabel("Renderer :") 

    # COMBOBOX RENDERER 
    renderer_cbx = QtGui.QComboBox() 
    renderer_cbx.addItem("Vray") 
    renderer_cbx.addItem("Octane") 

    # LABEL FOLDER 
    folders_lb = QtGui.QLabel("Folder :") 

    # LIST VIEW FOLDER 
    folders_lv = QtGui.QListView() 

    # BUTTON ADD NEW OBJECTS 
    addnewobject_btn = QtGui.QPushButton("Add New Objects") 

    # BUTTON NEW SET 
    newset_btn = QtGui.QPushButton("New Set") 

    # DEFINE THE FUNCTION FOR FIRST FRAME 
    Firstbox = QtGui.QGridLayout() 
    Firstbox.addWidget(renderer_lb,0,0) 
    Firstbox.addWidget(renderer_cbx,0,1,1,3) 
    Firstbox.addWidget(folders_lb,2,0,1,4) 
    Firstbox.addWidget(folders_lv,3,0,1,4) 
    Firstbox.addWidget(addnewobject_btn,4,0,1,2) 
    Firstbox.addWidget(newset_btn,4,3) 
    Firstbox.setColumnStretch(1, 1) 
    FirstFrame.setLayout(Firstbox) 

    #++++++++++++++++++++ COMMAND ++++++++++++++++++++ 
    addnewobject_btn.clicked.connect(addnewobject) 
    newset_btn.clicked.connect(newset) 
    return FirstFrame 
    #--------------------------------------------------------------------- 
def addnewobject(): 
    w = QtGui.QWidget() 
    w.setFixedSize(450,90) 
    w.setWindowTitle('Select folder of new objects') 
    _GCProtector.widgets.append(w) 
    w.show() 

    # LABEL FOLDER 
    folder_lb = QtGui.QLabel("Folder : ") 

    # TEXT EDIT OF LINK FOLDER 
    linkfolder_txt = QtGui.QLineEdit() 

    # BUTTON BROWSE 
    browse_btn=QtGui.QPushButton("Browse...") 

    # LABEL EXAMPLE 
    ex_lb = QtGui.QLabel("(ex : SCH, faucet, K7)") 

    # BUTTON CANCEL 
    cancel_btn = QtGui.QPushButton("Cancel") 

    # BUTTON OK 
    ok_btn = QtGui.QPushButton("OK") 

    # DEFINE THE FUNCTION FOR ADD NEW OBJECT WIDEGET 
    browser = QtGui.QGridLayout() 
    browser.addWidget(folder_lb,0,0) 
    browser.addWidget(linkfolder_txt,0,1,1,4) 
    browser.addWidget(browse_btn,0,5) 
    browser.addWidget(ex_lb,1,0,1,5) 
    browser.addWidget(cancel_btn,2,4) 
    browser.addWidget(ok_btn,2,5) 
    browser.setColumnStretch(1, 1) 
    w.setLayout(browser) 

    #++++++++++++++++++++ COMMAND ++++++++++++++++++++ 
    cancel_btn.clicked.connect(quitApp) 
    #--------------------------------------------------------------------- 

def quitApp(): 
     quit() 

if __name__ == '__main__': 
    main() 

並請給我指教如何爲不可用的「主表」時,「子表」被打開,當「子表」被打開,我還是事業可以推「添加新對象」在「主窗體」上打開許多「子窗體」。

非常感謝。

+1

你爲什麼用'quitApp'作爲它的事件? – Kasramvd

+0

我認爲這只是一個名字,我只是一個新人,所以我不明白,我遵循教程。 –

回答

1

你只需要按鈕連接到widget的close slot

def addnewobject(): 
     w = QtGui.QWidget() 
     ... 
     cancel_btn.clicked.connect(w.close) 
+0

非常感謝你,我現在的代碼可以運行你的評論。 –