def onClick(s, e): currentDirectory = Directory.GetCurrentDirectory() openFileDialog = OpenFileDialog() openFileDialog.Multiselect = False if CultureInfo.CurrentCulture.Equals(CultureInfo.GetCultureInfo("ja-JP")): openFileDialog.Filter = "XMLファイル (*.xml)|*.xml" else: openFileDialog.Filter = "XML files (*.xml)|*.xml" if openFileDialog.ShowDialog() == True: fileName = openFileDialog.FileName warningList = List[String]() errorList = List[String]() context = TaskScheduler.FromCurrentSynchronizationContext() def onValidate(): fs = None try: fs = FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read) doc = XmlDocument() doc.Load(fs) if doc.DocumentElement.Name.Equals("script"): for childNode1 in doc.DocumentElement.ChildNodes: if childNode1.Name.Equals("character"): hasName = False for xmlAttribute in childNode1.Attributes: if xmlAttribute.Name.Equals("name"): hasName = True if not hasName: if CultureInfo.CurrentCulture.Equals(CultureInfo.GetCultureInfo("ja-JP")): errorList.Add("characterタグにname属性がありません。") else: errorList.Add("Could not find name attribute in character tag.") for childNode2 in childNode1.ChildNodes: if childNode2.Name.Equals("sequence"): parseSequence(childNode2, Path.GetDirectoryName(fileName), warningList, errorList) else: if CultureInfo.CurrentCulture.Equals(CultureInfo.GetCultureInfo("ja-JP")): errorList.Add("scriptタグがありません。") else: errorList.Add("Could not find script tag.") except Exception, e: errorList.Add(e.clsException.Message) finally:
def get_sp_file(): dialog = OpenFileDialog() dialog.Title = "Select Shared Parameters file" dialog.Filter = "TXT|*.txt" if not dialog.ShowDialog(): return with codecs.open(dialog.FileName, 'r', 'utf-16') as f: data = f.read() if '# This is a Revit shared parameter file.' not in data: return return dialog.FileName
def FileOpenDialog(initialFile=None,multiselect=False): dlg = OpenFileDialog() dlg.Multiselect = multiselect dlg.DefaultExt = ".txt"; # Default file extension dlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; if initialFile: dlg.InitialDirectory = System.IO.Path.GetDirectoryName(initialFile) dlg.FileName = System.IO.Path.GetFileName(initialFile) #Directory.GetParent(initialFile) #Path.GetFileName(initialFile) if dlg.ShowDialog() == True: return dlg.FileNames
def onPostClick(source, rea): if not String.IsNullOrEmpty(comboBox.Text): fileName = None if checkBox.IsChecked: currentDirectory = Directory.GetCurrentDirectory() openFileDialog = OpenFileDialog() openFileDialog.Multiselect = False if CultureInfo.CurrentCulture.Equals(CultureInfo.GetCultureInfo("ja-JP")): openFileDialog.Filter = "画像ファイル (*.jpg;*.jpeg;*.png)|*.jpg;*.jpeg;*.png" else: openFileDialog.Filter = "Image files (*.jpg;*.jpeg;*.png)|*.jpg;*.jpeg;*.png" if openFileDialog.ShowDialog() == True: fileName = openFileDialog.FileName Directory.SetCurrentDirectory(currentDirectory) post(comboBox.Text, fileName)
def get_interference(): dialog = OpenFileDialog() dialog.Title = "Select interference report" dialog.Filter = "HTML|*.html" if not dialog.ShowDialog(): sys.exit() with codecs.open(dialog.FileName, 'r', 'utf-16') as f: data = f.read() if 'Interference Report' not in data: sys.exit() pattern = re.compile( r'<td>.+id (\d+)\s+</td>\s+<td>.+id (\d+)\s+</td>\s+') m = re.findall(pattern, data) ret = [] for key, group in itertools.groupby(m, lambda x: x[0]): li = [key] for i in group: li.append(i[1]) ret.append(li) return ret
def pickFile(config): dialog = OpenFileDialog() dialog.Title = config['title'] if 'title' in config else 'Pick file' # dialog.InitialDirectory = config['initialDirectory'] if 'initialDirectory' in config else None # TODO FIXME dialog.Multiselect = True if 'multiselect' in config and config[ 'multiselect'] else False # # TODO FIXME # if 'filter' in config: # for f in config['filter']: # dialog.Filter = '{}|({});{}|'.format(f[0], f[1], f[1]) result = dialog.ShowDialog() if result: if 'read' in config and config['read'] and 'multiselect' not in config: with open(dialog.FileName, 'r') as f: return f.read() else: if 'multiselect' in config and config['multiselect']: return list(dialog.FileNames) else: return dialog.FileName
def EzFileOpenDialog(initialFile=None, multiselect=False): dlg = OpenFileDialog() dlg.Multiselect = multiselect dlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*" if initialFile: dlg.InitialDirectory = Directory.GetParent( initialFile) #Path.GetFileName(initialFile) if dlg.ShowDialog() == True: return dlg.FileNames
def HandleimportBtn(sender, args): #Create a File open dialog dialog = OpenFileDialog() dialog.Title = "Select CSV file(s)" #Configure for single file selection dialog.Multiselect = True #Set up the file types you want to support dialog.Filter = "CSV Files|*.csv|All Files|*.*" global selectedFiles if dialog.ShowDialog(): selectedFiles = dialog.FileNames numOfTrajectories.Text = " {0} file(s)".format(len(selectedFiles))
def HandleimportBtn(sender, args): # Create a File open dialog dialog = OpenFileDialog() dialog.Title = "Select CSV file(s)" # Configure for single file selection dialog.Multiselect = True # Set up the file types you want to support dialog.Filter = "CSV Files|*.csv|All Files|*.*" # Display the dialog # If it returns anything # get the file name global selectedFiles if dialog.ShowDialog(): selectedFiles = dialog.FileNames fileNameTextBox.Text = str(len(selectedFiles))
def OpenFileButton_Click(self, sender, e): dlg = OpenFileDialog() dlg.DefaultExt = ".txt" dlg.Filter = "Text Files (*.txt)|*.txt" dlg.Multiselect = True if dlg.ShowDialog() == True: self.file_names = dlg.FileNames self.combo_clear() self.log_clear() self.log_append( f'Successfully loaded {len(self.file_names)} stages:') for file_name in self.file_names: stem = Path.GetFileNameWithoutExtension(file_name) self.log_append(stem) self.FileComboBox.Items.Add(stem) self.SaveXMLButton.IsEnabled = True self.FileComboBox.IsEnabled = True
def BtnBrowse_Click(self, sender, e): try: dlgOrg = OpenFileDialog() dlgOrg.Title = "Select orginal picture" dlgOrg.DefaultExt = ".jpg" dlgOrg.Filter = "JPG|*.jpg|PNG|*.png|TIF|*.tif" dlgMask = OpenFileDialog() dlgMask.Title = "Select mask picture" dlgMask.DefaultExt = ".tif" dlgOrg.Filter = "JPG|*.jpg|PNG|*.png|TIF|*.tif" if dlgOrg.ShowDialog(self): if dlgMask.ShowDialog(self): print(dlgOrg.FileName) print(dlgMask.FileName) self.img.Source = BitmapImage(Uri(dlgOrg.FileName)) self.imgResult.Source = BitmapImage(Uri(dlgMask.FileName)) #import Test except e: print("Error: {}", e) return 0
def Choose_Button_Click(self,sender, e): openFileDialog = OpenFileDialog() openFileDialog.Filter = "JPG|*.jpg" openFileDialog.ShowDialog() self.image1.Source = BitmapImage (Uri(openFileDialog.FileName)) self.pathBlock.Text = openFileDialog.FileName
def onClick(s, e): currentDirectory = Directory.GetCurrentDirectory() openFileDialog = OpenFileDialog() openFileDialog.Multiselect = False if CultureInfo.CurrentCulture.Equals(CultureInfo.GetCultureInfo("ja-JP")): openFileDialog.Filter = "XMLファイル (*.xml)|*.xml" else: openFileDialog.Filter = "XML files (*.xml)|*.xml" if openFileDialog.ShowDialog() == True: fileName = openFileDialog.FileName warningList = List[String]() errorList = List[String]() context = TaskScheduler.FromCurrentSynchronizationContext() def onValidate(): fs = None try: fs = FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read) doc = XmlDocument() doc.Load(fs) if doc.DocumentElement.Name.Equals("script"): for childNode1 in doc.DocumentElement.ChildNodes: if childNode1.Name.Equals("character"): hasName = False for xmlAttribute in childNode1.Attributes: if xmlAttribute.Name.Equals("name"): hasName = True if not hasName: if CultureInfo.CurrentCulture.Equals( CultureInfo.GetCultureInfo("ja-JP")): errorList.Add("characterタグにname属性がありません。") else: errorList.Add( "Could not find name attribute in character tag." ) for childNode2 in childNode1.ChildNodes: if childNode2.Name.Equals("sequence"): parseSequence( childNode2, Path.GetDirectoryName(fileName), warningList, errorList) else: if CultureInfo.CurrentCulture.Equals( CultureInfo.GetCultureInfo("ja-JP")): errorList.Add("scriptタグがありません。") else: errorList.Add("Could not find script tag.") except Exception, e: errorList.Add(e.clsException.Message) finally: