2016-09-26 5 views
1

メインウィンドウには、ユーザーが入力ファイルとホームディレクトリを更新できるオプションタブがあります。この関数は、ユーザーがプロジェクトに対して持つ可能性がある、それぞれのプロファイルのテキストファイルを更新します。これらの機能はすべてうまくいきます..変更が行われたときにメインウィンドウのラインエディットに変更を反映するという点を除いて、lineEditsは__init__で最初に実行されたときに正しいディレクトリを表示します。メインフレームでlineEditを更新できません

class MAIN_GUI(QtGui.QMainWIndow): 
    def __init__(self): 
     super(MAIN_GUI,self).__init__() 
     self.uiM=Ui_MainWindow() 
     self.uiM.setupUi(self) 
     self.update_dir_lines() 
     self.connect(self.uiM.Options_ChangeButton,QtCore.SIGNAL("clicked()"),self.choose_DIR) 

    def choose_DIR(self): 
     choose_DIR = Choose_DIR(current_profile,'main') 
     choose_DIR.show() 
     choose_DIR.exec_() 

    def update_dir_lines(self): 
     #pull the saved file directory from the profile.txt 
     self.InputFileDir = str(profile.get_dir('InputFileDir')) 
     self.uiM.Options_InputDIR_lineEdit.setText(self.InputFileDir) 
     #just to see that it's been changed print into console 
     print self.uiM.Options_inputDIR_lineEdit.text() #this actually comes back with the changed directory 
     #same spiel for the home directory so no need to repeat 

class Choose_DIR(QtGui.QDialog): 
    def __init__(self): 
     super(Choose_DIR,self).__init__() 
     self.ui3=Ui_Directories() 
     self.ui3.setupUi(self) 
     self.connect(self.ui3.Options_InputFileDir_BrowseButton,QtCore.SIGNAL("clicked()"),self.get_InputFileDir) 
     #doing the same for the home dir so no need to repeat 

    def get_InputFileDir(self): 
     QString_dir = QFileDialog.getExistingDirectory(parent=None,caption=("Choose InputFile Directory"),directory(''),optins=QFileDialog.ShowDirsOnly) 
     self.ui3.Options_InputFileDir_lineEdit.setText(QString_dir) #this works perfectly reflecting the chosen input File Dir 
     self.connect(self.ui3.select_DIR_ExecuteButton,QtCore.SIGNAL("clicked()"),self.change_DIR) 
    def change_DIR(self): 
     InputFileDir = self.ui3.Options_InputFileDir_lineEdit.text() 
     #profile is being edited and saved 
     profile.change_dir('InputFileDir',InputFileDir) 
     self.go2main() 

    def go2main(self): 
     self.close() 
     main = MAIN_GUI() 
     QtCore.QTimer.singleShot(1000,main.update_dir_lines) 

私が代わりにメインウィンドウに行こうと、最後の関数を考えて、メインウィンドウの別のインスタンスを作成するが、私はmain.show()でそれを語っていないが、私は送信する方法がわからないcuzを表示されていませんLineEditsをリフレッシュするためにメインのGUIに右の信号を...私はテキストがコンソールがラインエディットが変更された正しいディレクトリを印刷しているが、lineEdits自身が反映されていないことを設定しています。私はQApplication.instance().processEvents()を使ってみましたが、うまくいきません。私はupdate_dir_lines関数でそれを使用し、メインGUIを終了させただけです。誰か助けてくれますか?

答えて

1

exec_()でダイアログを開くと、ユーザーが閉じるまでブロックされます。あなたがちょうどことができますので、go2main()方法はもはや必要とされ

class MAIN_GUI(QtGui.QMainWIndow): 
    ... 

    def choose_DIR(self): 
     choose_DIR = Choose_DIR(current_profile,'main') 
     if choose_DIR.exec_() == QtGui.QDialog.Accepted: 
      self.update_dir_lines() 

:だから、解決策は非常に簡単です

class Choose_DIR(QtGui.QDialog): 
    ... 

    def change_DIR(self): 
     InputFileDir = self.ui3.Options_InputFileDir_lineEdit.text() 
     #profile is being edited and saved 
     profile.change_dir('InputFileDir',InputFileDir) 
     self.accept() 
関連する問題