Exemplo n.º 1
0
	def actionPerformed(self,actionEvent):
		ws_data_analysis_controller = self.ws_lw_acquisition_controller.ws_data_analysis_controller
		linac_wizard_document = self.ws_lw_acquisition_controller.linac_wizard_document
		records_table = ws_data_analysis_controller.records_table
		index = records_table.getSelectedRow()
		#print "debug ws record for writing index=",index
		if(index < 0): return
		ws_records_table_model = ws_data_analysis_controller.ws_records_table_model
		ws_scan_and_fit_record = ws_records_table_model.ws_rec_table_element_arr[index]
		fl_name = ws_scan_and_fit_record.ws_node.getId()
		if(ws_scan_and_fit_record.ws_direction == WS_DIRECTION_HOR): fl_name += "_hor.dat" 
		if(ws_scan_and_fit_record.ws_direction == WS_DIRECTION_VER): fl_name += "_ver.dat"
		fl_name = fl_name.replace(":","_")
		#print "debug file=",fl_name
		x_arr = []
		y_arr = []
		y_fit_arr = []
		x_min = ws_scan_and_fit_record.X_MIN.getValue()
		x_max = ws_scan_and_fit_record.X_MAX.getValue()
		x_center = ws_scan_and_fit_record.X_CENTER.getValue()
		for ind in range(ws_scan_and_fit_record.gd_wf.getNumbOfPoints()):
			x = ws_scan_and_fit_record.gd_wf.getX(ind)
			y = ws_scan_and_fit_record.gd_wf.getY(ind)
			if(x >= x_min and x <= x_max):
				x_arr.append(x-x_center)
				y_arr.append(y)
				y_fit = ws_scan_and_fit_record.gd_fit_wf.getValueY(x)
				y_fit_arr.append(y_fit)
		#----normalization
		if(len(x_arr) > 1):
			x_step = (x_arr[len(x_arr)-1] - x_arr[0])/(len(x_arr)-1)
			sum_val = 0.
			for ind in range(len(x_arr)):
				sum_val += math.fabs(y_arr[ind])*x_step
			if(sum_val > 0.):
				for ind in range(len(x_arr)):
					y_arr[ind] /= sum_val
					y_fit_arr[ind] /= sum_val
		#----dump into the ASCII file---------------------
		fl_out_path = constants_lib.const_path_dict["LINAC_WIZARD_FILES_DIR_PATH"]
		fl_name = fl_out_path+"/"+fl_name
		fl_out = File(fl_name)
		fc = JFileChooser(fl_name)
		fc.setDialogTitle("Write WS/LW data into the ASCII file ...")
		fc.setApproveButtonText("Write")
		fl_filter = FileNameExtensionFilter("WS/LW Data",["dat",])
		fc.setFileFilter(fl_filter)
		fc.setSelectedFile(fl_out)
		returnVal = fc.showOpenDialog(linac_wizard_document.linac_wizard_window.frame)
		if(returnVal == JFileChooser.APPROVE_OPTION):
			fl_out = fc.getSelectedFile()
			fl_path = fl_out.getPath()
			if(fl_path.rfind(".dat") != (len(fl_path) - 4)):
				fl_path = open(fl_out.getPath()+".dat")
			fl_out = open(fl_path,"w")
			fl_out. write(" ind   x[mm]  y[mm]  y_fit[mm] \n")
			for ind in range(len(x_arr)):
				s = " %2d   %12.5g   %12.5g   %12.5g "%(ind,x_arr[ind],y_arr[ind],y_fit_arr[ind])
				fl_out. write(s + "\n")
			fl_out.close()
Exemplo n.º 2
0
    def on_saveBtn_clicked(self, event):
        """Read preferences from gui and save them to config.properties
           file
        """
        #print "\n- saving preferences to config file"
        onOff = {True: "on", False: "off"}

        #1 Tab
        #check for update
        self.app.properties.setProperty("check_for_update",
                                        onOff[self.updateCBtn.isSelected()])
        #tools status
        for toolIndex, tool in enumerate(self.app.realTools):
            prop = "tool.%s" % tool.name
            toolCBtn = self.toolsCBtns[toolIndex]
            self.app.properties.setProperty(prop, onOff[toolCBtn.isSelected()])

        #layers preferences
        for mode, button in self.layersRBtns.iteritems():
            if button.isSelected():
                self.app.properties.setProperty("layers_mode", mode)
                break

        #max errors number
        try:
            num = Integer.parseInt(self.maxErrorsNumberTextField.getText())
        except NumberFormatException:
            num = ""
        self.app.properties.setProperty("max_errors_number", str(num))

        #2 Tab
        #Favourite zones
        changes = {
            "new": [z for z in self.app.tempZones if not z in self.app.zones],
            "deleted":
            [z for z in self.app.zones if not z in self.app.tempZones]
        }
        #delete files of removed favourite zones
        for zone in changes["deleted"]:
            f = File(
                File.separator.join([
                    self.app.SCRIPTDIR, "configuration", "favourite_zones",
                    "%s.txt" % zone.name
                ]))
            f.delete()
        #create files for new favourite zones
        for zone in changes["new"]:
            print "\nsave new zone", zone.name
            fileName = File.separator.join([
                self.app.SCRIPTDIR, "configuration", "favourite_zones",
                "%s.txt" % zone.name
            ])
            f = open(fileName, "w")
            zoneData = zone.geomString
            if zone.country != "":
                zoneData += "|" + zone.country
            f.write(zoneData.encode("utf-8"))
            f.close()

        self.app.zones = self.app.tempZones
        if len(self.app.zones) == 0:
            self.app.favZone = None
            self.app.properties.setProperty("favourite_area.name", "")
            self.favZoneStatusCBtn.setSelected(False)
        else:
            if len(self.zonesTable.getSelectedRows()) == 0:
                self.app.favZone = self.app.zones[0]
            else:
                self.app.favZone = self.app.zones[
                    self.zonesTable.getSelectedRows()[0]]
            self.app.properties.setProperty("favourite_area.name",
                                            self.app.favZone.name)
        favZoneStatus = self.favZoneStatusCBtn.isSelected()
        self.app.properties.setProperty("favourite_area.status",
                                        onOff[favZoneStatus])
        self.app.favouriteZoneStatus = favZoneStatus

        #stats panel
        self.app.dlg.update_favourite_zone_indicator()
        self.app.dlg.update_statsPanel_status()

        #3 Tab
        #tools preferences
        for tool in self.app.allTools:
            if hasattr(tool, 'prefs') and tool.prefsGui is not None:
                for pref, value in tool.prefsGui.read_gui().iteritems():
                    prefKey = "tool.%s.%s" % (tool.name, pref)
                    self.app.properties.setProperty(prefKey, value)

        self.app.save_config()
        self.dispose()
Exemplo n.º 3
0
    def on_saveBtn_clicked(self, event):
        """Read preferences from gui and save them to config.properties
           file
        """
        #print "\n- saving preferences to config file"
        onOff = {True: "on", False: "off"}

        #1 Tab
        #check for update
        self.app.properties.setProperty("check_for_update",
                                        onOff[self.updateCBtn.isSelected()])
        #tools status
        for toolIndex, tool in enumerate(self.app.realTools):
            prop = "tool.%s" % tool.name
            toolCBtn = self.toolsCBtns[toolIndex]
            self.app.properties.setProperty(prop,
                                            onOff[toolCBtn.isSelected()])

        #layers preferences
        for mode, button in self.layersRBtns.iteritems():
            if button.isSelected():
                self.app.properties.setProperty("layers_mode", mode)
                break

        #max errors number
        try:
            num = Integer.parseInt(self.maxErrorsNumberTextField.getText())
        except NumberFormatException:
            num = ""
        self.app.properties.setProperty("max_errors_number", str(num))

        #2 Tab
        #Favourite zones
        changes = {"new": [z for z in self.app.tempZones if not z in self.app.zones],
                   "deleted": [z for z in self.app.zones if not z in self.app.tempZones]}
        #delete files of removed favourite zones
        for zone in changes["deleted"]:
            f = File(File.separator.join([self.app.SCRIPTDIR,
                                          "configuration",
                                          "favourite_zones",
                                          "%s.txt" % zone.name]))
            f.delete()
        #create files for new favourite zones
        for zone in changes["new"]:
            print "\nsave new zone", zone.name
            fileName = File.separator.join([self.app.SCRIPTDIR,
                                            "configuration",
                                            "favourite_zones",
                                            "%s.txt" % zone.name])
            f = open(fileName, "w")
            zoneData = zone.geomString
            if zone.country != "":
                zoneData += "|" + zone.country
            f.write(zoneData.encode("utf-8"))
            f.close()

        self.app.zones = self.app.tempZones
        if len(self.app.zones) == 0:
            self.app.favZone = None
            self.app.properties.setProperty("favourite_area.name",
                                            "")
            self.favZoneStatusCBtn.setSelected(False)
        else:
            if len(self.zonesTable.getSelectedRows()) == 0:
                self.app.favZone = self.app.zones[0]
            else:
                self.app.favZone = self.app.zones[self.zonesTable.getSelectedRows()[0]]
            self.app.properties.setProperty("favourite_area.name",
                                            self.app.favZone.name)
        favZoneStatus = self.favZoneStatusCBtn.isSelected()
        self.app.properties.setProperty("favourite_area.status", onOff[favZoneStatus])
        self.app.favouriteZoneStatus = favZoneStatus

        #stats panel
        self.app.dlg.update_favourite_zone_indicator()
        self.app.dlg.update_statsPanel_status()

        #3 Tab
        #tools preferences
        for tool in self.app.allTools:
            if hasattr(tool, 'prefs') and tool.prefsGui is not None:
                for pref, value in tool.prefsGui.read_gui().iteritems():
                    prefKey = "tool.%s.%s" % (tool.name, pref)
                    self.app.properties.setProperty(prefKey, value)

        self.app.save_config()
        self.dispose()