コード例 #1
0
    def __init__(self, parent=None):
        super(ApplicationWindow, self).__init__(parent)
        
        QMainWindow.__init__(self)
        self.setAttribute(Qt.WA_DeleteOnClose)

        self.setWindowTitle("xray yield simulation")
             
        self.resize(1200, 750)
        
        self.er_low=0.1# keV
        self.er_high=20.# keV
        self.er_step=0.001# keV
        self.enes_keV=np.arange(self.er_low,self.er_high+self.er_low+self.er_step,self.er_step)
        self.qeout=np.zeros_like(self.enes_keV)# for output
        self.flout=np.zeros_like(self.enes_keV)# for output
        # IUPAC macro
        self.LINES=['KL3','KL2','KM3','KM2',
                    'L3M5','L3M4','L2M4','L3N5',
                    'L1M3','L1M2','L2N4','L3M1']
        # Siegbahn
        self.SGBLINES=['KA1','KA2','KB1','KB3',
                       'LA1','LA2','LB1','LB2',
                       'LB3','LB4','LG1','LL']

        # radionuclide list
        self.RDNLIST=list(xrl.GetRadioNuclideDataList())
        #['55Fe','57Co','109Cd','125I','137Cs',
        #'133Ba','153Gd','238Pu','241Am','244Cm']
        # half life
        self.RDNHL=[1006.70,272.11,463.26,59.49,11018.3,
                    3854.7,239.472,32031.74,157857.678,6610.52]# days

        # universal parameters
        self.rad_duration=3600.# sec
        self.beam_duration=7200.# sec
        self.detector_resolution=8.0# eV
        self.detector_solidangle=1.0
        
        self.csvd="./csv/"
        IUPACdf=pd.read_csv(self.csvd+"IUPAC_macro.csv")
        self.IUPACmac=IUPACdf['IUPAC_macro'].values
        self.allLINES=[xrl.__getattribute__(mac) for mac in self.IUPACmac] 
        
        # ---- layout ----
        # main widget
        main_widget = QWidget(self)
        self.setCentralWidget(main_widget)
        main_layout = QHBoxLayout()

          
        # target, detector, filter materials
        topleft=QWidget()
        topleftbox=QVBoxLayout()


        self.fopenButton = QPushButton("Load csv file")
        self.fopenButton.clicked.connect(self.openFileNameDialog)
        
        self.default_none          = "None (reset all)"
        self.default_tes_jparc_mlf = "TES(Bi) J-PARC MLF"
        self.default_tes_spring8   = "TES(Bi) Spring-8"
        self.default_tes_sn        = "TES(Sn)"
        self.default_cdte          = "CdTe"
        self.default_ge            = "Ge"
        self.default_si            = "Si"
        self.chkbox0 = QCheckBox(self.default_none)
        self.chkbox1 = QCheckBox(self.default_tes_jparc_mlf)
        self.chkbox2 = QCheckBox(self.default_tes_spring8)
        self.chkbox3 = QCheckBox(self.default_tes_sn)
        self.chkbox4 = QCheckBox(self.default_cdte)
        self.chkbox5 = QCheckBox(self.default_ge)
        self.chkbox6 = QCheckBox(self.default_si)
        self.chkbg = QButtonGroup()
        self.chkbg.addButton(self.chkbox0,1)
        self.chkbg.addButton(self.chkbox1,2)
        self.chkbg.addButton(self.chkbox2,3)
        self.chkbg.addButton(self.chkbox3,4)
        self.chkbg.addButton(self.chkbox4,5)
        self.chkbg.addButton(self.chkbox5,6)
        self.chkbg.addButton(self.chkbox6,7)
        self.chkbg.buttonClicked[QAbstractButton].connect(self.btngroup)
        self.chkbox0.setChecked(True)
        ltboxw=QWidget()
        ltbox=QVBoxLayout(ltboxw)
        ltbox.setContentsMargins(0, 0, 0, 0)
        ltbox.addWidget(QLabel("Default setting"))
        ltbox.addWidget(self.fopenButton)
        ltbox.addWidget(self.chkbox0)
        ltbox.addWidget(self.chkbox1)
        ltbox.addWidget(self.chkbox2)
        ltboxw_02=QWidget()
        ltbox_02=QHBoxLayout(ltboxw_02)
        ltbox_02.setContentsMargins(0, 0, 0, 0)
        ltbox_02.addWidget(self.chkbox3)
        ltbox_02.addWidget(self.chkbox4)
        ltbox_02.addWidget(self.chkbox5)
        ltbox_02.addWidget(self.chkbox6)
                
        ltboxw2=QWidget()
        ltbox2=QVBoxLayout(ltboxw2)
        qtab=QTabWidget()
        self.bem={}
        self.tgt={}
        self.det={}
        self.bet={}
        self.rad={}
        self.dets=[]
        self.bets=[]
        self.rads=[]
        self.bemtab=material.MaterialTabWidget(parent=self,name='bem')
        self.tgttab=material.MaterialTabWidget(parent=self,name='tgt')
        self.dettab=material.MaterialTabWidget(parent=self,name='det')
        self.bettab=material.MaterialTabWidget(parent=self,name='bet')
        self.radtab=material.MaterialTabWidget(parent=self,name='rad')
        qtab.addTab(self.dettab,'Detector')
        qtab.addTab(self.tgttab,'Target')
        qtab.addTab(self.bettab,'Filter')
        qtab.addTab(self.radtab,'RadioNucl')
        qtab.addTab(self.bemtab,'Beam')
        ltbox2.addWidget(qtab)
        
        topleftbox.addWidget(ltboxw)
        topleftbox.addWidget(ltboxw_02)
        topleftbox.addWidget(ltboxw2)
        topleft.setLayout(topleftbox)


        plotButton = QPushButton("Plot")
        plotButton.clicked.connect(self._plot_trans_fluor)
        saveButton = QPushButton("Save")
        saveButton.clicked.connect(self._save_trans_fluor)
        #plotButton = QPushButton("Plot transmission")
        #plotButton.clicked.connect(self._update_trans_cv)
        #fluorButton = QPushButton("Plot flurorescence")
        #fluorButton.clicked.connect(self._update_fluor_cv)
        
        # energy range
        rangebox=QHBoxLayout()
        self.ene_range_low_le = QLineEdit()
        self.ene_range_low_le.setValidator(QDoubleValidator(0.,800.,999))
        self.ene_range_low_le.returnPressed.connect(self.apply_enerangelow)
        self.ene_range_low_le.setText("0.1")
        self.ene_range_high_le = QLineEdit()
        self.ene_range_high_le.setValidator(QDoubleValidator(0.,800.,999))
        self.ene_range_high_le.returnPressed.connect(self.apply_enerangehigh)
        self.ene_range_high_le.setText("20.")
        self.ene_range_step_le = QLineEdit()
        self.ene_range_step_le.setValidator(QDoubleValidator(0.,800.,999))
        self.ene_range_step_le.returnPressed.connect(self.apply_enerangestep)
        self.ene_range_step_le.setText("0.001")
        rangebox.addWidget(QLabel("Low:"))
        rangebox.addWidget(self.ene_range_low_le)
        rangebox.addWidget(QLabel("High:"))
        rangebox.addWidget(self.ene_range_high_le)
        rangebox.addWidget(QLabel("Step:"))
        rangebox.addWidget(self.ene_range_step_le)

        # detector resolution
        self.detector_resolution_le = QLineEdit()
        self.detector_resolution_le.setValidator(QDoubleValidator(0.,1e5,999))
        self.detector_resolution_le.returnPressed.connect(self.apply_detector_resolution)
        self.detector_resolution_le.setText(str(self.detector_resolution))
        # detector solidangle
        self.detector_solidangle_le = QLineEdit()
        self.detector_solidangle_le.setValidator(QDoubleValidator(0.,1.,999))
        self.detector_solidangle_le.returnPressed.connect(self.apply_detector_solidangle)
        self.detector_solidangle_le.setText(str(self.detector_solidangle))
        
        
        # check current setup
        topmiddle=QWidget()
        tmbox=QVBoxLayout()
        self.cc_table = QTableWidget()
        self.init_cc_table()
        self.not_draw_lines=[]
        self.line_table = QTableWidget()
        self.init_line_table()

        tmbox.addWidget(QLabel("Plot"))
        tmbox.addWidget(QLabel("Energy range (keV)"))
        tmbox.addLayout(rangebox)
        tmbox.addWidget(plotButton)
        tmbox.addWidget(saveButton)
        self.chkbox_resol = QCheckBox("Detector resolution FWHM (eV)")
        self.chkbox_resol.stateChanged.connect(self.chkbox_resol_action)
        self.chkbox_resol.setChecked(True)
        #tmbox.addWidget(QLabel("Detector resolution FWHM (eV)"))
        tmbox.addWidget(self.chkbox_resol)
        tmbox.addWidget(self.detector_resolution_le)
        tmbox.addWidget(QLabel("Solidangle ratio (0.-1.)"))
        tmbox.addWidget(self.detector_solidangle_le)
        
        #tmbox.addWidget(fluorButton)
        tmbox.addWidget(QLabel("Current setting"))
        tmbox.addWidget(self.cc_table)
        tmbox.addWidget(QLabel("X-ray lines"))
        tmbox.addWidget(self.line_table)
        topmiddle.setLayout(tmbox)
       
        topright=QWidget()
        trbox=QVBoxLayout()
        mini_width=300
        self.fig_tr = Figure(figsize=(8, 6), dpi=80)
        trans_cv = FigureCanvas(self.fig_tr)
        trans_tlbar = NavigationToolbar(trans_cv, self)
        trans_tlbar.setMinimumWidth(mini_width)
        trans_tlbar.setStyleSheet("QToolBar { border: 0px }")
        self.ax = trans_cv.figure.subplots()
        self.fig_fl = Figure(figsize=(8, 6), dpi=80)
        fluor_cv = FigureCanvas(self.fig_fl)
        fluor_tlbar = NavigationToolbar(fluor_cv, self)
        fluor_tlbar.setMinimumWidth(mini_width)
        fluor_tlbar.setStyleSheet("QToolBar { border: 0px }")
        self.ax_fl = fluor_cv.figure.subplots()
        trbox.addWidget(trans_tlbar)
        trbox.addWidget(trans_cv)
        trbox.addWidget(fluor_cv)
        trbox.addWidget(fluor_tlbar)
        topright.setLayout(trbox)
        topright.layout().setSpacing(0)

        ## cosole outputs
        ## used for debug
        #resultTE = QTextEdit()
        #resultTE.setReadOnly( True )
        #resultTE.setUndoRedoEnabled( False )
        #sys.stdout = line_wrap.Logger(resultTE, sys.stdout, QColor(0, 100, 100))
        #sys.stderr = line_wrap.Logger(resultTE, sys.stderr, QColor(200, 0, 0))
        
        splitter1 = QSplitter(Qt.Horizontal)
        splitter1.addWidget(topleft)
        splitter1.addWidget(topmiddle)
        splitter3 = QSplitter(Qt.Horizontal)
        splitter3.addWidget(splitter1)
        splitter3.addWidget(topright)
        #splitter2 = QSplitter(Qt.Vertical)
        #splitter2.addWidget(splitter3)
        #splitter2.addWidget(resultTE)
        #main_layout.addWidget(splitter2)
        main_layout.addWidget(splitter3)
        main_widget.setLayout(main_layout)
        main_widget.setFocus()
        
        self.show()