#######################################
#モデルを開くウィンドウ
#######################################

import sys, configparser

from PyQt5.QtWidgets import (QVBoxLayout, QLineEdit,QGridLayout,
 QApplication, QLabel, QMenu, QWidget, QHBoxLayout,QDialog,
 QAction, QTextEdit,QPushButton, qApp, QMessageBox, QInputDialog,
 QMainWindow, QFrame, QFileDialog, QCheckBox, QProgressBar,
 QListWidget, QCompleter, QComboBox)
from PyQt5.QtGui import (QIcon, QFont, QColor, QPixmap, QDrag, QPainter,
 QBrush, QPen,QStandardItem,QStandardItemModel)
from PyQt5.QtCore import (QCoreApplication, Qt, QObject, pyqtSignal,
 QMimeData, )

class open_project_SubWindow(QWidget):

    def __init__(self, projects):
        super().__init__()
        self.aa=""
        self.projects=projects

        self.open_project()

    def open_project(self):
        self.w=QDialog()
        label = QLabel()
        label.setText('プロジェクトの選択')

        items=QListWidget()
        #item.addItem(projects)
        for n in self.projects:
            items.addItem(n)
        items.currentItemChanged.connect(self.get_project_name)

        select=QPushButton("選択")
        select.clicked.connect(lambda: self.select_Clicked(self.aa))


        cancel=QPushButton("キャンセル")
        cancel.clicked.connect(self.w.close)

        hbox=QHBoxLayout()
        hbox.addStretch(1)
        hbox.addWidget(select)
        hbox.addWidget(cancel)

        layout = QVBoxLayout()
        layout.addWidget(label)
        layout.addWidget(items)
        layout.addLayout(hbox)

        self.w.setWindowTitle('プロジェクトを開く')
        self.w.setLayout(layout)

    def get_project_name(self, item):
        self.project_name=item.text()

        self.aa=self.project_name

    def select_Clicked(self,aa):

        g = open("select_project_temp.txt","w")
        g.write(self.aa)
        g.close()

        self.w.close()


    def show(self):
        self.w.exec_()

if __name__=="__main__":
    app=QApplication(sys.argv)
    pro=["aa","bb","cc"]
    ex=open_project_SubWindow(pro).open_project()
    open_project_SubWindow(pro).show()
    sys.exit(app.exec_())
