def _buildProjectJar(element, document): component = element.getRootElement().getComponent() larchJarURL = app_in_jar.getLarchJarURL() chosenJarURL = None if larchJarURL is None: openDialog = JFileChooser() openDialog.setFileFilter( FileNameExtensionFilter('Larch executable JAR (*.jar)', ['jar'])) response = openDialog.showDialog(component, 'Choose Larch JAR') if response == JFileChooser.APPROVE_OPTION: sf = openDialog.getSelectedFile() if sf is not None: chosenJarURL = sf.toURI().toURL() else: return jarFile = None bFinished = False while not bFinished: saveDialog = JFileChooser() saveDialog.setFileFilter( FileNameExtensionFilter('JAR file (*.jar)', ['jar'])) response = saveDialog.showSaveDialog(component) if response == JFileChooser.APPROVE_OPTION: sf = saveDialog.getSelectedFile() if sf is not None: if sf.exists(): response = JOptionPane.showOptionDialog( component, 'File already exists. Overwrite?', 'File already exists', JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, None, ['Overwrite', 'Cancel'], 'Cancel') if response == JFileChooser.APPROVE_OPTION: jarFile = sf bFinished = True else: bFinished = False else: jarFile = sf bFinished = True else: bFinished = True else: bFinished = True if jarFile is not None: outStream = FileOutputStream(jarFile) documentBytes = document.writeAsBytes() nameBytesPairs = [('app.larch', documentBytes)] app_in_jar.buildLarchJar(outStream, nameBytesPairs, larchJarURL=chosenJarURL) outStream.close()
def get_image_file(self) : file_dialog = JFileChooser() #image files image_filter = FileNameExtensionFilter("Image Files", ["jpg","bmp","png","gif"]) print image_filter.getExtensions() file_dialog.setFileFilter(image_filter) x = file_dialog.showOpenDialog(None) if x == JFileChooser.APPROVE_OPTION : return file_dialog.getSelectedFile() else : return None
def showFC(self, event): fc = JFileChooser(RestrictedFileSystemView(File(r'C:\IBM\WebSphere'))) fc.addChoosableFileFilter(FileNameExtensionFilter( 'XML files', ['xml'])) fc.addChoosableFileFilter( FileNameExtensionFilter('Image files', 'bmp,jpg,jpeg,gif,png'.split(','))) fc.addChoosableFileFilter( FileNameExtensionFilter('Text files', ['txt'])) result = fc.showOpenDialog(None) if result == JFileChooser.APPROVE_OPTION: message = 'result = "%s"' % fc.getSelectedFile() else: message = 'Request canceled by user' self.label.setText(message)
def openFile(self, event=None): ''' 1. Check if current file in text area has unsaved changes 1.1 Prompt user for file saving 1.1.1 Save file 2. Display browser for user to choose file 3. Load file in text area 4. Display file name in title bar ''' if self.handleUnsaved(): if self.currentFilename: default_path = os.path.dirname(self.currentFilename) else: default_path = os.getcwd() fileChooser = JFileChooser(default_path) file_filter = FileNameExtensionFilter("ATF files", ["atf"]) fileChooser.setFileFilter(file_filter) status = fileChooser.showDialog(self.view, "Choose file") if status == JFileChooser.APPROVE_OPTION: atfFile = fileChooser.getSelectedFile() filename = atfFile.getCanonicalPath() basename = atfFile.getName() atfText = self.readTextFile(filename) self.currentFilename = atfFile.getCanonicalPath() # Clear ATF area before adding next text to clean up tooltips # and such self.atfAreaController.clearAtfArea() self.atfAreaController.setAtfAreaText(atfText) self.logger.debug("File %s successfully opened.", filename) self.view.setTitle(basename)
def openFile(self, fileext, filedesc, fileparm): myFilePath = '' chooseFile = JFileChooser() myFilter = FileNameExtensionFilter(filedesc, [fileext]) chooseFile.setFileFilter(myFilter) ret = chooseFile.showOpenDialog(self.tab) if ret == JFileChooser.APPROVE_OPTION: file = chooseFile.getSelectedFile() myFilePath = str(file.getCanonicalPath()).lower() if not myFilePath.endswith(fileext): myFilePath += '.' + fileext okWrite = JOptionPane.YES_OPTION if os.path.isfile(myFilePath): okWrite = JOptionPane.showConfirmDialog( self.tab, 'File already exists. Ok to over-write?', '', JOptionPane.YES_NO_OPTION) if okWrite == JOptionPane.NO_OPTION: return j = True while j: try: f = open(myFilePath, mode=fileparm) j = False except IOError: okWrite = JOptionPane.showConfirmDialog( self.tab, 'File cannot be opened. Correct and retry?', '', JOptionPane.YES_NO_OPTION) if okWrite == JOptionPane.NO_OPTION: return None, False return f, True
def actionPerformed(self,actionEvent): self.scl_long_tuneup_controller.getMessageTextField().setText("") fc = JFileChooser(constants_lib.const_path_dict["LINAC_WIZARD_FILES_DIR_PATH"]) fc.setDialogTitle("Read BPM Offsets from ASCII file") fc.setApproveButtonText("Read") fl_filter = FileNameExtensionFilter("ASCII *.dat File",["dat",]) fc.setFileFilter(fl_filter) returnVal = fc.showOpenDialog(self.scl_long_tuneup_controller.linac_wizard_document.linac_wizard_window.frame) if(returnVal == JFileChooser.APPROVE_OPTION): scl_long_tuneup_energy_meter_controller = self.scl_long_tuneup_controller.scl_long_tuneup_energy_meter_controller bpm_wrappers_holder = scl_long_tuneup_energy_meter_controller.bpm_wrappers_holder bpm_wrappers_holder.clean() fl_in = fc.getSelectedFile() fl_ph_in = open(fl_in.getPath(),"r") lns = fl_ph_in.readlines() fl_ph_in.close() for ln in lns: res_arr = ln.split() if(len(res_arr) == 5): bpm_name = res_arr[1] bpm_wrapper = self.scl_long_tuneup_controller.getBPM_WrapperForBPM_Id(bpm_name) if(bpm_wrapper != null): bpm_wrappers_holder.em_bpm_wrpprs.append(bpm_wrapper) bpm_wrappers_holder.use_bpms.append(true) bpm_wrappers_holder.bpm_phase_offsets.append(float(res_arr[3])) bpm_wrappers_holder.bpm_amp_phase_data_dict[bpm_wrapper] = ([],[]) bpm_wrappers_holder.bpm_phase_diff_arr.append([]) #----- update table table_and_plots_panel = scl_long_tuneup_energy_meter_controller.table_and_plots_panel table_and_plots_panel.bpm_table.getModel().fireTableDataChanged()
def actionPerformed(self,actionEvent): self.scl_long_tuneup_controller.getMessageTextField().setText("") fc = JFileChooser(constants_lib.const_path_dict["LINAC_WIZARD_FILES_DIR_PATH"]) fc.setDialogTitle("Read BPM Final Phase Offsets from ASCII file") fc.setApproveButtonText("Read") fl_filter = FileNameExtensionFilter("ASCII *.dat File",["dat",]) fc.setFileFilter(fl_filter) returnVal = fc.showOpenDialog(self.scl_long_tuneup_controller.linac_wizard_document.linac_wizard_window.frame) if(returnVal == JFileChooser.APPROVE_OPTION): fl_in = fc.getSelectedFile() fl_ph_in = open(fl_in.getPath(),"r") lns = fl_ph_in.readlines() fl_ph_in.close() #----- set all as "not ready" for bpm_wrapper in self.scl_long_tuneup_controller.bpm_wrappers: bpm_wrapper.final_phase_offset.isReady = false bpm_wrapper.final_phase_offset.phaseOffset_avg = 0. bpm_wrapper.final_phase_offset.phaseOffset_err = 0. #----- set existing in file as "ready" for ln in lns: res_arr = ln.split() if(len(res_arr) == 5): bpm_name = res_arr[1] bpm_wrapper = self.scl_long_tuneup_controller.getBPM_WrapperForBPM_Id(bpm_name) if(bpm_wrapper != null): bpm_wrapper.final_phase_offset.isReady = true bpm_wrapper.final_phase_offset.phaseOffset_avg = float(res_arr[3]) bpm_wrapper.final_phase_offset.phaseOffset_err = float(res_arr[4]) #----- update table scl_long_tuneup_bpm_offsets_controller = self.scl_long_tuneup_controller.scl_long_tuneup_bpm_offsets_controller scl_long_tuneup_bpm_offsets_controller.bpm_offsets_table.getModel().fireTableDataChanged()
def actionPerformed(self,actionEvent): self.scl_long_tuneup_controller.getMessageTextField().setText("") fc = JFileChooser(constants_lib.const_path_dict["LINAC_WIZARD_FILES_DIR_PATH"]) fc.setDialogTitle("Save BPM Final Phase Offsets Table into ASCII file") fc.setApproveButtonText("Save") fl_filter = FileNameExtensionFilter("ASCII *.dat File",["dat",]) fc.setFileFilter(fl_filter) returnVal = fc.showOpenDialog(self.scl_long_tuneup_controller.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 = fl_path+".dat" fl_ph_out = open(fl_path,"w") txt = "# BPM pos[m] offset[deg] offset_err[deg]" fl_ph_out.write(txt+"\n") bpm_wrappers = self.scl_long_tuneup_controller.bpm_wrappers count = 0 for bpm_ind in range(len(bpm_wrappers)): bpm_wrapper = bpm_wrappers[bpm_ind] if(bpm_wrapper.isGood and bpm_wrapper.final_phase_offset.isReady): count += 1 txt = str(count)+" "+bpm_wrapper.bpm.getId()+ " %9.3f "%bpm_wrapper.pos txt += " %7.2f"% bpm_wrapper.final_phase_offset.phaseOffset_avg txt += " %7.2f"% bpm_wrapper.final_phase_offset.phaseOffset_err fl_ph_out.write(txt+"\n") #---- end of writing fl_ph_out.flush() fl_ph_out.close()
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()
def actionPerformed(self, actionEvent): oldFileName = self.config_controller.filePathJText.getText() fc = JFileChooser() if (len(oldFileName) != 0): try: fc.setSelectedFile(File(oldFileName)) except: fc.setCurrentDirectory(File(oldFileName)) self.config_controller.filePathJText.setText("") fc.setDialogTitle("Read Configuration from the file ...") fc.setApproveButtonText("Open") fl_filter = FileNameExtensionFilter("Event Monitor Conf.", [ "evnt", ]) fc.setFileFilter(fl_filter) returnVal = fc.showOpenDialog( self.config_controller.event_monitor_document.frame) if (returnVal == JFileChooser.APPROVE_OPTION): fl_in = fc.getSelectedFile() if (fl_in.isFile() and fl_in.canRead()): self.config_controller.readData(fl_in.toURI().toURL()) self.config_controller.filePathJText.setText(fl_in.getPath()) messTxt = self.config_controller.event_monitor_document.event_monitor_window.getMessageTextField( ) messTxt.setText("") else: messTxt = self.config_controller.event_monitor_document.event_monitor_window.getMessageTextField( ) messTxt.setText("Could not find file:" + fl_in.getPath())
def promptSaveDocumentAs(world, component, handleSaveDocumentAsFn, existingFilename=None): filename = None bFinished = False while not bFinished: saveDialog = JFileChooser() saveDialog.setFileFilter( FileNameExtensionFilter( 'Larch project (*.larch)', [ 'larch' ] ) ) response = saveDialog.showSaveDialog( component ) if response == JFileChooser.APPROVE_OPTION: sf = saveDialog.getSelectedFile() if sf is not None: if sf.exists(): response = JOptionPane.showOptionDialog( component, 'File already exists. Overwrite?', 'File already exists', JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, None, [ 'Overwrite', 'Cancel' ], 'Cancel' ) if response == JFileChooser.APPROVE_OPTION: filename = sf.getPath() bFinished = True else: bFinished = False else: filename = sf.getPath() bFinished = True else: bFinished = True else: bFinished = True if filename is not None: handleSaveDocumentAsFn( filename ) return True else: return False
def actionPerformed(self, event): """Delete the last row""" # Generate a save dialog dialog = JFileChooser(Prefs.get("roiGroup.importDir", "")) dialog.setSelectedFile(File("roiGroups.txt")) dialog.setFileFilter(FileNameExtensionFilter("Text file", ["txt"])) output = dialog.showOpenDialog( self.groupTable) # could be None argument too if output in [JFileChooser.CANCEL_OPTION, JFileChooser.ERROR_OPTION]: return selectedFile = dialog.getSelectedFile() directory = selectedFile.getParent() Prefs.set("roiGroup.importDir", directory) if not selectedFile.isFile(): return filePath = selectedFile.getPath() # Read comma-separated group from file with open(filePath, "r") as textFile: stringGroup = textFile.readline().rstrip() # Update table with content of file tableModel = self.groupTable.tableModel tableModel.setGroupColumn(stringGroup)
def actionPerformed(self,actionEvent): index = self.transverse_twiss_analysis_Controller.dict_panel.dict_table.getSelectedRow() if(index < 0): return accState = self.transverse_twiss_analysis_Controller.accStatesKeeper.getAccStatesArr()[index] quad_cav_dict = accState.getQuadCavDict() [quad_dict,cav_amp_phase_dict] = quad_cav_dict linac_wizard_document = self.transverse_twiss_analysis_Controller.linac_wizard_document quads = linac_wizard_document.ws_lw_controller.quads cavs = linac_wizard_document.ws_lw_controller.cavs #----------set the output file fc = JFileChooser(constants_lib.const_path_dict["LINAC_WIZARD_FILES_DIR_PATH"]) fc.setDialogTitle("Save Cavities Amps.&Phases to ASCII file") fc.setApproveButtonText("Save") fl_filter = FileNameExtensionFilter("ASCII *.dat File",["dat",]) fc.setFileFilter(fl_filter) 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 = fl_out.getPath()+".dat" fl_out = open(fl_path,"w") #----- start dump for cav in cavs: if(cav_amp_phase_dict.has_key(cav)): txt = cav.getId()+" %8.6f %7.3f "%(cav_amp_phase_dict[cav][0],cav_amp_phase_dict[cav][1]) fl_out.write(txt+"\n") fl_out.close()
def openFile(self, event=None): ''' 1. Check if current file in text area has unsaved changes 1.1 Prompt user for file saving 1.1.1 Save file 2. Display browser for user to choose file 3. Load file in text area 4. Display file name in title bar ''' if self.handleUnsaved(): fileChooser = JFileChooser(self.get_working_dir()) file_filter = FileNameExtensionFilter("ATF files", ["atf"]) fileChooser.setFileFilter(file_filter) status = fileChooser.showDialog(self.view, "Choose file") if status == JFileChooser.APPROVE_OPTION: atfFile = fileChooser.getSelectedFile() filename = atfFile.getCanonicalPath() basename = atfFile.getName() atfText = self.readTextFile(filename) self.currentFilename = atfFile.getCanonicalPath() # Clear ATF area before adding next text to clean up tooltips # and such self.atfAreaController.clearAtfArea() self.atfAreaController.setAtfAreaText(atfText) self.logger.debug("File %s successfully opened.", filename) self.view.setTitle(basename) # TODO: Else, prompt user to choose again before closing # Update settings with current file's path self.update_config_element(self.get_working_dir(), 'default', 'working_dir')
def open(self, e): filechooser = JFileChooser() filter = FileNameExtensionFilter("c files", ["c"]) filechooser.addChoosableFileFilter(filter) ret = filechooser.showDialog(self.panel, "Elegir fichero") if ret == JFileChooser.APPROVE_OPTION: file = filechooser.getSelectedFile() text = self.readFile(file) self.area.setText(text)
def createDialogBoxForImportExport(self, dialogTitle, extensionFilter, buttonText): # create frame frameImportExportDialogBox = JFrame() # try to load the last used directory try: # load the directory for future imports/exports fileChooserDirectory = self._callbacks.loadExtensionSetting("fileChooserDirectory") # there is not a last used directory except: # set the last used directory to blank fileChooserDirectory = "" # create file chooser fileChooserImportExportDialogBox = JFileChooser(fileChooserDirectory) # set dialog title fileChooserImportExportDialogBox.setDialogTitle(dialogTitle) # create extension filter filterImportExportDialogBox = FileNameExtensionFilter(extensionFilter[0], extensionFilter[1]) # set extension filter fileChooserImportExportDialogBox.setFileFilter(filterImportExportDialogBox) # show dialog box and get value valueFileChooserImportExportDialogBox = fileChooserImportExportDialogBox.showDialog(frameImportExportDialogBox, buttonText) # check if a file was not selected if valueFileChooserImportExportDialogBox != JFileChooser.APPROVE_OPTION: # return no path/file selected return False, "No Path/File" # get the directory fileChooserDirectory = fileChooserImportExportDialogBox.getCurrentDirectory() # store the directory for future imports/exports self._callbacks.saveExtensionSetting("fileChooserDirectory", str(fileChooserDirectory)) # get absolute path of file fileChosenImportExportDialogBox = fileChooserImportExportDialogBox.getSelectedFile().getAbsolutePath() # split name and extension fileNameImportExportDialogBox, fileExtensionImportExportDialogBox = os.path.splitext(fileChosenImportExportDialogBox) # check if file does not have an extention if fileExtensionImportExportDialogBox == "": # add extension to file fileChosenImportExportDialogBox = fileChosenImportExportDialogBox + extensionFilter[2] # return dialog box value and path/file return True, fileChosenImportExportDialogBox
def actionPerformed(self, event): command = event.getActionCommand() if self.itemType == "dialog": #False positives dialog if command == self.strings.getString("False_positives..."): self.app.falsePositiveDlg.show() #Preferences dialog elif command == self.strings.getString("Preferences..."): self.app.open_preferences("from menu") #About dialog elif command == self.strings.getString("About..."): try: self.app.aboutDlg except AttributeError: #build about dialog self.app.aboutDlg = AboutDialog( Main.parent, self.strings.getString("about_title"), True, self.app) self.app.aboutDlg.show() #Web link of the tool elif self.itemType == "link": OpenBrowser.displayUrl(self.tool.uri) elif self.itemType in ("check", "local file"): #Open local GPX file with errors if self.itemType == "local file": fileNameExtensionFilter = FileNameExtensionFilter( "files GPX (*.gpx)", ["gpx"]) chooser = DiskAccessAction.createAndOpenFileChooser( True, False, self.strings.getString("Open_a_GPX_file"), fileNameExtensionFilter, JFileChooser.FILES_ONLY, None) if chooser is None: return filePath = chooser.getSelectedFile() #remove former loaded local file for i, tool in enumerate(self.app.tools): if filePath.getName() == tool.name: self.app.dlg.toolsCombo.removeItemAt(i) del self.app.tools[i] #create a new local file tool self.tool = LocalFileTool(self.app, filePath) self.view = self.tool.views[0] self.check = self.view.checks[0] self.app.tools.append(self.tool) #add tool to toggle dialog self.app.dlg.add_data_to_models(self.tool) selection = (self.tool, self.view, self.check) self.app.on_selection_changed("menu", selection)
def onClick(self, e): chooseFile = JFileChooser() filter = FileNameExtensionFilter("SQLite", ["sqlite"]) chooseFile.addChoosableFileFilter(filter) ret = chooseFile.showDialog(self.panel, "Select SQLite") if ret == JFileChooser.APPROVE_OPTION: file = chooseFile.getSelectedFile() text = self.readPath(file) self.area.setText(text)
def promptOpenDocument(world, component, handleOpenedDocumentFn): openDialog = JFileChooser() openDialog.setFileFilter( FileNameExtensionFilter( 'Larch project (*.larch)', [ 'larch' ] ) ) response = openDialog.showDialog( component, 'Open' ) if response == JFileChooser.APPROVE_OPTION: sf = openDialog.getSelectedFile() if sf is not None: filename = sf.getPath() if filename is not None: document = Document.readFile( world, filename ) if document is not None: handleOpenedDocumentFn( filename, document )
def openFile(self, event=None): ''' 1. Check if current file in text area has unsaved changes 1.1 Prompt user for file saving 1.1.1 Save file 2. Display browser for user to choose file 3. Load file in text area 4. Display file name in title bar ''' if self.handleUnsaved(): fileChooser = JFileChooser(self.get_working_dir()) file_filter = FileNameExtensionFilter("ATF files", ["atf"]) fileChooser.setFileFilter(file_filter) status = fileChooser.showDialog(self.view, "Choose file") if status == JFileChooser.APPROVE_OPTION: atfFile = fileChooser.getSelectedFile() filename = atfFile.getCanonicalPath() basename = atfFile.getName() atfText = self.readTextFile(filename) self.currentFilename = atfFile.getCanonicalPath() # Clear ATF area before adding next text to clean up tooltips # and such self.atfAreaController.clearAtfArea() # Turn off caret movement and highligting for file load self.atfAreaController.caret.setUpdatePolicy( DefaultCaret.NEVER_UPDATE) syntax_highlight = self.atfAreaController.syntax_highlighter syntax_highlight.syntax_highlight_on = False self.atfAreaController.setAtfAreaText(atfText) self.consoleController.clearConsole() self.logger.info("File %s successfully opened.", filename) self.view.setTitle(basename) # Re-enable caret updating and syntax highlighting after load self.atfAreaController.caret.setUpdatePolicy( DefaultCaret.ALWAYS_UPDATE) syntax_highlight.syntax_highlight_on = True # Now dispatch syntax highlighting in a new thread so # we dont highlight before the full file is loaded runSwingLater(self.initHighlighting) # TODO: Else, prompt user to choose again before closing # Update settings with current file's path self.update_config_element(self.get_working_dir(), 'default', 'working_dir') # Finally, refresh the edit area to propagate custom font settings self.atfAreaController.refreshEditArea()
def fileButtonClick(self, e): fileTypeList = ["war", "ear", "zip"] warFilter = FileNameExtensionFilter("war", fileTypeList) fileChooser = JFileChooser() fileChooser.addChoosableFileFilter(warFilter) result = fileChooser.showOpenDialog(self._splitpane) if result == JFileChooser.APPROVE_OPTION: f = fileChooser.getSelectedFile() fileName = f.getPath() self.populateJTable(f)
def actionPerformed(self,actionEvent): fc = JFileChooser() fc.setCurrentDirectory(File("/ade/xal/docs/EventMonitor/Configs/")) fc.setDialogTitle("Save Configuration to the file ...") fc.setApproveButtonText("Save") fl_filter = FileNameExtensionFilter("Event Monitor Conf.",["evnt",]) fc.setFileFilter(fl_filter) returnVal = fc.showOpenDialog(self.config_controller.event_monitor_document.frame) if(returnVal == JFileChooser.APPROVE_OPTION): fl_in = fc.getSelectedFile() if(fl_in.getPath().rfind(".evnt") < 0): fl_in = File(fl_in.getPath()+".evnt") self.config_controller.writeData(fl_in.toURI().toURL())
def actionPerformed(self,actionEvent): fc = JFileChooser(constants_lib.const_path_dict["LINAC_WIZARD_FILES_DIR_PATH"]) fc.setDialogTitle("Read data from the file ...") fc.setApproveButtonText("Open") fl_filter = FileNameExtensionFilter("SCL Wizard",["sclw",]) fc.setFileFilter(fl_filter) returnVal = fc.showOpenDialog(self.linac_wizard_document.linac_wizard_window.frame) if(returnVal == JFileChooser.APPROVE_OPTION): fl_in = fc.getSelectedFile() io_controller = self.linac_wizard_document.getIO_Controller() io_controller.readData(fl_in.toURI().toURL()) io_controller.old_fl_out_name = fl_in.getName() self.linac_wizard_document.linac_wizard_window.setTitle(io_controller.old_fl_out_name)
def Find_Plaso_File(self, e): chooseFile = JFileChooser() filter = FileNameExtensionFilter("All", ["*.*"]) chooseFile.addChoosableFileFilter(filter) ret = chooseFile.showDialog(self.panel0, "Find Plaso Storage File") if ret == JFileChooser.APPROVE_OPTION: file = chooseFile.getSelectedFile() Canonical_file = file.getCanonicalPath() #text = self.readPath(file) self.local_settings.setPlaso_Storage_File(Canonical_file) self.Plaso_Storage_File_TF.setText(Canonical_file)
def onClick(self, e): chooseFile = JFileChooser() filter = FileNameExtensionFilter("SQLite", ["sqlite"]) chooseFile.addChoosableFileFilter(filter) ret = chooseFile.showDialog(self.panel0, "Select SQLite") if ret == JFileChooser.APPROVE_OPTION: file = chooseFile.getSelectedFile() Canonical_file = file.getCanonicalPath() #text = self.readPath(file) self.local_settings.setSetting('ExecFile', Canonical_file) self.Program_Executable_TF.setText(Canonical_file)
def actionPerformed(self,actionEvent): self.scl_long_tuneup_controller.getMessageTextField().setText("") rightNow = Calendar.getInstance() date_format = SimpleDateFormat("MM.dd.yyyy") time_str = date_format.format(rightNow.getTime()) fc = JFileChooser(constants_lib.const_path_dict["XAL_XML_ACC_FILES_DIRS_PATH"]) fc.setDialogTitle("Save SCL data into the SCL_new.xdxf file") fc.setApproveButtonText("Save") fl_filter = FileNameExtensionFilter("SCL Acc File",["xdxf",]) fc.setFileFilter(fl_filter) fc.setSelectedFile(File("SCL_"+time_str+".xdxf")) returnVal = fc.showOpenDialog(self.scl_long_tuneup_controller.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(".xdxf") != (len(fl_path) - 5)): fl_out = File(fl_out.getPath()+".xdxf") #---------prepare the XmlDataAdaptor root_DA = XmlDataAdaptor.newEmptyDocumentAdaptor() scl_DA = root_DA.createChild("xdxf") scl_DA.setValue("date",time_str) scl_DA.setValue("system","sns") scl_DA.setValue("version","2.0") #---- SCLMed seq_name_arr = ["SCLMed","SCLHigh","HEBT1"] for seq_name in seq_name_arr: accl = self.scl_long_tuneup_controller.linac_wizard_document.accl seq = accl.findSequence(seq_name) cavs = seq.getAllNodesWithQualifier(AndTypeQualifier().and((OrTypeQualifier()).or(SCLCavity.s_strType))) quads = seq.getAllNodesWithQualifier(AndTypeQualifier().and((OrTypeQualifier()).or(Quadrupole.s_strType))) scl_seq_DA = scl_DA.createChild("sequence") scl_seq_DA.setValue("id",seq.getId()) for quad in quads: node_DA = scl_seq_DA.createChild("node") node_DA.setValue("id",quad.getId()) attr_DA = node_DA.createChild("attributes") field_DA = attr_DA.createChild("magnet") scl_quad_fields_dict_holder = self.scl_long_tuneup_controller.scl_long_tuneup_init_controller.scl_quad_fields_dict_holder field_DA.setValue("dfltMagFld",str(scl_quad_fields_dict_holder.quad_field_dict[quad])) for cav in cavs: node_DA = scl_seq_DA.createChild("sequence") node_DA.setValue("id",cav.getId()) attr_DA = node_DA.createChild("attributes") rf_cav_DA = attr_DA.createChild("rfcavity") cav_wrappper = self.scl_long_tuneup_controller.getCav_WrapperForCavId(cav.getId()) (amp,phase) = (cav_wrappper.designAmp,cav_wrappper.designPhase) rf_cav_DA.setValue("amp",float("%8.5f"%amp)) rf_cav_DA.setValue("phase",float("%8.3f"%phase)) root_DA.writeTo(fl_out)
def FindFTKTxtFile(self, e): chooseFile = JFileChooser() filter = FileNameExtensionFilter("ALL", ["*.*"]) chooseFile.addChoosableFileFilter(filter) ret = chooseFile.showDialog(self.panel0, "Find FTK Log File") if ret == JFileChooser.APPROVE_OPTION: file = chooseFile.getSelectedFile() Canonical_file = file.getCanonicalPath() #text = self.readPath(file) self.local_settings.setSetting('FTKLogFile', Canonical_file) setSetting('FTKLogFile', Canonical_file) self.FTKLogFile_TF.setText(Canonical_file)
def Find_Dir(self, e): chooseFile = JFileChooser() filter = FileNameExtensionFilter("All", ["*.*"]) chooseFile.addChoosableFileFilter(filter) #chooseFile.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY) ret = chooseFile.showDialog(self.panel0, "Find Volatility Directory") if ret == JFileChooser.APPROVE_OPTION: file = chooseFile.getSelectedFile() Canonical_file = file.getCanonicalPath() #text = self.readPath(file) self.local_settings.setVolatility_Directory(Canonical_file) self.Program_Executable_TF.setText(Canonical_file)
def initUI(self): self.panel = JPanel() self.panel.setLayout(BorderLayout()) chooseFile = JFileChooser() chooseFile.setDialogTitle("Select Access Database") fnfilter = FileNameExtensionFilter("Access Databases", ["mdb", "accdb"]) chooseFile.setFileFilter(fnfilter) ret = chooseFile.showSaveDialog(self.panel) if ret == JFileChooser.APPROVE_OPTION: self.file_name = str(chooseFile.getSelectedFile())
def actionPerformed(self,actionEvent): fc = JFileChooser(constants_lib.const_path_dict["LINAC_WIZARD_FILES_DIR_PATH"]) fc.setDialogTitle("Save data into the file ...") fc.setApproveButtonText("Save") fl_filter = FileNameExtensionFilter("SCL Wizard",["sclw",]) fc.setFileFilter(fl_filter) returnVal = fc.showOpenDialog(self.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(".sclw") != (len(fl_path) - 5)): fl_out = File(fl_out.getPath()+".sclw") io_controller = self.linac_wizard_document.getIO_Controller() io_controller.writeData(fl_out.toURI().toURL()) io_controller.old_fl_out_name = fl_out.getName() self.linac_wizard_document.linac_wizard_window.setTitle(io_controller.old_fl_out_name)
def _select_sql_file(self, e): """ Shows a JFileChooser dialog to select the SQL file to use for creating the model. """ try: chooseFile = JFileChooser() filter_ = FileNameExtensionFilter("txt files", ["txt"]) chooseFile.addChoosableFileFilter(filter_) ret = chooseFile.showDialog(self._panel, "Choose file") if ret == JFileChooser.APPROVE_OPTION: self._sql_file = chooseFile.getSelectedFile().getPath() else: self._sql_file = None self._text_field_sql_file.setText("" + self._sql_file) except Exception as e: print(e)