def on_open(self, e): r"""Handler for the Open menu item Open a Python file Parameters ---------- e : wx.CommandEvent """ dlg = wx.DirDialog(self, message="Choose a project folder", defaultPath="", style=wx.DD_CHANGE_DIR) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() self.model.set_root_folder(path) self.model.set_selected(path) dlg.Destroy()
def _onSeriesBrowse(self, event): joined = False rootfolder = appcfg.options[appcfg.CFG_SERIES_PATH] seriesfolder = self._seriesFolder.GetValue() if not os.path.isabs(seriesfolder) and rootfolder != '': seriesfolder = os.path.join(rootfolder, seriesfolder) joined = True dlg = wx.DirDialog(self, "Select the series path", seriesfolder) if dlg.ShowModal() == wx.ID_OK: if not joined: self._seriesFolder.SetValue(dlg.GetPath()) else: cmnstr = os.path.commonprefix([rootfolder, dlg.GetPath()]) if len(cmnstr) > 0: self._seriesFolder.SetValue( dlg.GetPath()[len(cmnstr):].strip('/\\')) else: self._seriesFolder.SetValue(dlg.GetPath())
def onfindruns(self, event): # wxGlade: MainSaint.<event_handler> runs = [] # wx.FileDialog( self, "Choose a file", self.dirnameall, wildcard = filters, style = wx.FD_OPEN | wx.MULTIPLE ) dialog = wx.DirDialog(self, "Choose sfrm directory:", self.dirnameall, style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON) if dialog.ShowModal() == wx.ID_OK: self.list_box_1.Clear() selected = dialog.GetPath() self.dirname = selected for files in os.listdir(selected): if files.endswith("0001.sfrm"): runs.append(files) sorrun = sorted(runs, key=self.sortkey) # # print sorrun for i in sorrun: self.list_box_1.Append(i) self.list_box_1.SetChecked(range(len(runs)))
def onShowDialog(self, event): currentLogDir = self.txtDir.GetValue() directory = os.getcwd() if not currentLogDir or not os.path.isdir( currentLogDir) else currentLogDir #self.fbb = MDD.MultiDirDialog(self.parent, title="Pick a directory for your logs...", defaultPath="", agwStyle=wx.DD_NEW_DIR_BUTTON) self.fbb = wx.DirDialog(self.parent, "Pick a directory for your logs...", defaultPath=directory, style=wx.DD_DEFAULT_STYLE) #self.fbb = wx.DirDialog(self.parent, "Pick a directory for your logs...", style=wx.DD_NEW_DIR_BUTTON) if self.fbb.ShowModal() != wx.ID_OK: self.fbb.Destroy() return self.txtDir.SetValue(self.fbb.GetPath()) self.fbb.Destroy() self.parent.parent.parentNotebook.notebookControlChanged()
def OnChangeAtt(self, e): fileOpenDialog = wx.DirDialog(self, self.GetParent().uploadAttachDir, style=wx.FD_SAVE | wx.FD_CHANGE_DIR) if fileOpenDialog.ShowModal() == wx.ID_CANCEL: fileOpenDialog.Destroy() return self.dir = fileOpenDialog.GetPath() #self.GetParent().attname = fileOpenDialog.GetFilename() #self.GetParent().uploadAttachDir = self.dir + "\\" + self.GetParent().attname self.GetParent().uploadAttachDir = self.dir #self.attCtrl.SetValue(self.dir + "\\" + self.GetParent().attname) self.attCtrl.SetValue(self.dir) self.layoutSizer.Layout() self.Update() self.Refresh()
def readdir(parent=None, message='Select directory to read', wildcard='*', defaultfile=''): open_dlg = wx.DirDialog( parent, message=message, ) if defaultfile != '': open_dlg.SetFilename(os.path.basename(defaultfile)) if os.path.dirname(defaultfile) != '': open_dlg.SetDirectory(os.path.dirname(defaultfile)) path = '' if open_dlg.ShowModal() == wx.ID_OK: path = open_dlg.GetPath() open_dlg.Destroy() open_dlg.Destroy() return path
def choose_images_folder(self, event): dialog = wx.DirDialog(self, 'Choose images folder', '', style=wx.DD_DEFAULT_STYLE) try: if dialog.ShowModal() == wx.ID_CANCEL: return path = dialog.GetPath() except Exception: wx.LogError('Failed to open directory!') raise finally: dialog.Destroy() if len(path) > 0: self.input_folder_path = Path(path) text_objext = self.buttons['extract_data']['images']['text'] text_objext.SetLabel('...{}'.format(str(path)[-20:])) self.update_layout()
def OnPathbtn(self, event): dirdialog = wx.DirDialog(self, message="Choose a directory", defaultPath="", style=wx.DD_DEFAULT_STYLE, pos=wx.DefaultPosition, size=wx.DefaultSize, name="wxDirCtrl") if dirdialog.ShowModal() == wx.ID_OK: chosenpath = dirdialog.GetPath() if chosenpath: #self.workspace=process_dir(chosenpath) self.workspacepath.Clear() self.workspacepath.AppendText(process_dir(chosenpath)) #self.configparser.write_item('WORKSPACE', self.workspace) else: self.workspacepath.Clear() self.workspacepath.AppendText(self.workspace) dirdialog.Destroy()
def mediaBrowse(self, event): dialog = wx.DirDialog(self, 'Choose media directory', '', style=wx.DD_DEFAULT_STYLE) try: if dialog.ShowModal() == wx.ID_CANCEL: return path = dialog.GetPath() except Exception: wx.LogError('Failed to open directory!') raise finally: dialog.Destroy() if len(path) > 0: self.mediaPathTextCtrl.SetValue(path) self.pg.mplayer.setCWD(path)
def on_Check(self, e): dialog = wx.DirDialog(self, 'Choose media directory', '', style=wx.DD_DEFAULT_STYLE) try: if dialog.ShowModal() == wx.ID_CANCEL: return elif dialog.ShowModal() == wx.ID_OK: path = dialog.GetPath() self.txt_lgy.Clear() self.txt_lgy.SetValue(path) except Exception: wx.LogError('Failed to open directory!') raise finally: dialog.Destroy()
def on_html_report(self, event): # wxGlade: mainNetAnalysis.<event_handler> global filename directoryfiledialog = wx.DirDialog( None, "Choose directory", "", wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST) if directoryfiledialog.ShowModal() == wx.ID_OK: creaderpath = directoryfiledialog.GetPath( ) #get path of selected directory directoryname = os.path.basename(creaderpath) #get directory name crd = ['chaosreader', filename, '--dir', directoryname] #run the chaosreader cmd process = Popen(crd, stdout=PIPE, stderr=PIPE) stdout, stderr = process.communicate() print( "Report successfully made in " + creaderpath ) #print out full path so that user knows exactly where the directory is
def SetPath(self, event): # print "SetPath()" file_wildcard = "Paint files(*.paint)|*.paint|All files(*.*)|*.*" # 选择文件夹 dlg = wx.DirDialog( None, message="请选择Vdisk的目录", defaultPath="/home/whatever/Dropbox/code/VDISK/test", style=wx.DD_DEFAULT_STYLE, # pos=DefaultPosition, size=DefaultSize, name=DirDialogNameStr ) if dlg.ShowModal() == wx.ID_OK: self.dirpath = dlg.GetPath() dirpath = self.dirpath print dirpath self.pathText.AppendText(self.dirpath) self.secondstep.SetBackgroundColour('GREEN') print self.dirpath dlg.Destroy()
def get_dir_path(parent, path='~', msg=''): ret = '' if not msg: msg = _('Select directory') if wal.IS_MAC: msg = '' if path == '~': path = os.path.expanduser(path) dlg = wx.DirDialog(parent, message=msg, defaultPath=path, style=wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST) dlg.CenterOnParent() if dlg.ShowModal() == wx.ID_OK: ret = path_system(dlg.GetPath()) dlg.Destroy() return ret
def BROWSE_FITS(self, event): if self.BT_OBSMODE.BackgroundColour == self.SysColor: dialog = wx.DirDialog(self, 'Set Raw FITS Location', \ defaultPath = os.environ['HOME'], \ style = wx.DD_DEFAULT_STYLE) if dialog.ShowModal() == wx.ID_OK: dialog.Destroy() self.fits_path = dialog.GetPath() self.TC_FITS.SetValue(self.fits_path) self.LB_SCANS.SetItems([]) ssu = Static_Scan_Update(self) ssu.setDaemon(True) ssu.start() event.Skip()
def OnSaveFile(self,event): with wx.DirDialog(None) as fileDialog: if fileDialog.ShowModal() == wx.ID_CANCEL: return # the user changed their mind # Proceed loading the file chosen by the user self.pathname_folder = fileDialog.GetPath() # try: # with open(pathname, 'r') as file: # self.doLoadDataOrWhatever(file) # except IOError: # wx.LogError("Cannot open file '%s'." % newfile) # global GoogleDriveApi # GoogleDriveApi.AddCourse(self.name.GetValue(),self.course_id.GetValue()) # self.Close(True) print(self.pathname_folder) self.static_text_choose_folder.SetLabelText(self.pathname_folder)
def OnSelectPath(self, event): dialog = wx.DirDialog(parent=wx.GetApp().GetTopWindow(), message=u'选择路径', defaultPath=".") dialog.CenterOnParent() ret = dialog.ShowModal() if ret == wx.ID_OK: self.ctrl_path.getControl("combobox").SetValue(dialog.GetPath()) self.LoadData(dialog.GetPath()) tarPanel = wx.GetApp().GetTopWindow().FindWindowByName("tarPanel") tarPanel.EnableAll(True) projects = self.ReadShe("projects") while len(projects) >= 5: projects.pop() while dialog.GetPath() in projects: projects.remove(dialog.GetPath()) projects.insert(0, dialog.GetPath()) self.WriteShe("projects", projects) dialog.Destroy()
def OnBtnSelectFolderButton(self, event): self.OneFolderList = [] dlg = wx.DirDialog(self) try: if dlg.ShowModal() == wx.ID_OK: dirPath = dlg.GetPath() self.OneFolderSelected = True #self.OneFolderPath = dir for root, dirs, files in os.walk(dirPath): for adir in dirs: self.OneFolderList.append(os.path.join(root, adir)) """ for dir in self.OneFolderList: print dir """ finally: dlg.Destroy() event.Skip()
def OnBrowseDBFolder(self, event): dlg = wx.DirDialog( self.panel, message='Select NEW Dropbox Folder location (move first!)', style=wx.DD_DIR_MUST_EXIST) if dlg.ShowModal() != wx.ID_OK: return self.newdbfolder = dlg.GetPath() dlg.Destroy() if os.path.isdir(self.newdbfolder): self.NewFolderText.SetLabel(self.newdbfolder) self.StatusBar.SetStatusText( 'New folder selected. Press the save button to change dropbox.' ) self.SaveBtn.Enable() else: self.SaveBtn.Disable() if not self.IsMaximized(): self.SetClientSize(self.panel.GetBestSize())
def OnOpenImageFiles(self, event): dlg = wx.DirDialog(self, "Choose directory", name="Directory") # </ if dlg.ShowModal() == wx.ID_OK: # </ path = dlg.GetPath() # </ images = os.listdir(path) # </ print path print os.path.abspath(images[1]) # </ for img in images: # </ self.filelistbox.Append(img) # wxPython ListBox method # </ if path.find("/") == 0: # </ self.filelist.append(path + '/' + img) # </ elif path.find("\\") == 0: # </ self.filelist.append(path + '\\'+img) # </ self.metadatalist.append([]) # </ dlg.Destroy() # </
def add_existing_wiki(self): dlg = wx.DirDialog(self, defaultPath=get_last_opendir(), style=wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST) if dlg.ShowModal() != wx.ID_OK: return wikiroot = dlg.GetPath() set_last_opendir(wikiroot) wiki = WikklyWiki(wikiroot) if not wiki.initted(): wm.error(self, 'No wiki found in "%s"' % wikiroot) return paths = get_wiki_list() paths.append(wikiroot) set_wiki_list(paths) self.panel.add_wiki(wikiroot)
def BackupDatabase(self): with wx.DirDialog(self._gui, 'Select backup location.') as dlg: if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() text = 'Are you sure "' + path + '" is the correct directory?' text += os.linesep * 2 text += 'Everything already in that directory will be deleted before the backup starts.' text += os.linesep * 2 text += 'The database will be locked while the backup occurs, which may lock up your gui as well.' with ClientGUIDialogs.DialogYesNo(self._gui, text) as dlg_yn: if dlg_yn.ShowModal() == wx.ID_YES: self.Write('backup', path)
def SelectMojoFolder(self, event, UserInfo): dpath = os.getenv("HOMEDRIVE") + os.getenv("HOMEPATH") # dpath = "C:\\Users\\urakubo\\Desktop\\Mojo\\ac3x75\\mojo" selectFileDialog = wx.DirDialog(self, "Select Mojo folder", dpath, wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST) selectFileDialog.ShowModal() dir = selectFileDialog.GetPath() selectFileDialog.Destroy() tmp_info = copy.deepcopy(UserInfo) tmp_info.SetMojoPath(dir) # Check file existence if os.path.exists(tmp_info.mojo_files_path) and \ os.path.exists(tmp_info.mojo_ids_path) and \ os.path.exists(tmp_info.mojo_tile_ids_path) and \ os.path.isfile(tmp_info.mojo_tile_ids_volume_file) and \ os.path.isfile(tmp_info.mojo_color_map_file) and \ os.path.isfile(tmp_info.mojo_segment_info_db_file) and \ os.path.exists(tmp_info.mojo_images_path) and \ os.path.exists(tmp_info.mojo_tile_images_path) and \ os.path.isfile(tmp_info.mojo_tile_images_volume_file) : print 'All Mojo files are found. Applying ...' UserInfo.mojo_files_found = True UserInfo.SetMojoPath(dir) else: print 'Some Mojo files are missing.' return # Change statusbar MojoControlPanel_statusbar_fields = ["Target Mojo Folder: " + UserInfo.mojo_files_path] for i in range(len(MojoControlPanel_statusbar_fields)): self.MojoControlPanel_statusbar.SetStatusText(MojoControlPanel_statusbar_fields[i], i) print UserInfo.mojo_files_path print UserInfo.mojo_ids_path print UserInfo.mojo_tile_ids_path print UserInfo.mojo_tile_ids_volume_file print UserInfo.mojo_color_map_file print UserInfo.mojo_segment_info_db_file print UserInfo.mojo_images_path print UserInfo.mojo_tile_images_path print UserInfo.mojo_tile_images_volume_file
def Browse(self, *_): # wxGlade: dir_picker.<event_handler> if self.files_mode: default_path: PathLike if self.get_value() == '': default_path = str(pathlib.Path(self.initial_value).parent) else: default_path = pathlib.Path(self.get_value()) if default_path.is_file(): default_path = default_path.parent default_path = str(default_path) pathname = file_dialog( self, extension=self.file_extension, style=self.style, defaultDir=default_path, filetypestring=self.filetypestring, title=self.dialog_title, ) if pathname: self.dir_value.SetValue(pathname) self.dir_value.SetFocus() else: if self.get_value() == '': default_path = self.initial_value else: default_path = self.get_value() dlg = wx.DirDialog(None, "Choose a directory:", style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON, defaultPath=default_path) if dlg.ShowModal() == wx.ID_OK: self.dir_value.SetValue(dlg.GetPath()) dlg.Destroy() self.dir_value.SetFocus()
def on_add_directory(self, event): dlg = wx.DirDialog(self, "Choose a directory:", style=wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST) # If the user selects OK, then we process the dialog's data. # This is done by getting the path data from the dialog - BEFORE # we destroy it. if dlg.ShowModal() == wx.ID_OK: matches = [] k = 0 filter_pattern = self.collectionNode.pref_manager.get_value( 'filter_pattern') for root, dirnames, filenames in os.walk(dlg.GetPath(), topdown=True): dirnames.sort() self.logger.info('Scanning directory: %s.', root) for cur_pattern in filter_pattern: for filename in fnmatch.filter(filenames, cur_pattern): self.logger.info('Adding file %s', os.path.join(root, filename)) fsize = os.path.getsize(os.path.join(root, filename)) fsize = old_div(fsize, (1024.0 * 1024.0)) bulletin_format = self.collectionNode.pref_manager.get_value( 'bulletin_format') matches.append( bulletin_format, (os.path.join(root, filename), '%.2f' % fsize)) k += 1 matches = [ x for x in matches if x not in self.file_grid.GetTable().data ] self.file_grid.GetTable().data.extend(matches) self.file_grid.GetTable().ResetView() #self.file_grid.do_resize() # Only destroy a dialog after you're done with it. dlg.Destroy()
def OnChooseFolder(self, evt): """Choose Folder.""" dlg = wx.DirDialog(self) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() del self.face_paths[:] self.faces.clear() for root, dirs, files in os.walk(path): if files: self.face_paths.extend( [os.path.join(root, filename) for filename in files]) self.btn.Disable() self.log.log(( 'Request: Preparing faces for grouping, detecting faces in ' 'chosen folder.')) self.grid.set_paths(self.face_paths) for path in self.face_paths: try: res = util.CF.face.detect(path) except util.CF.CognitiveFaceException: continue for entry in res: face = model.Face(entry, path) self.faces[face.id] = face self.grid.set_faces(self.faces.values()) self.log.log('Response: Success. Total {0} faces are detected.'. format(len(self.faces))) self.log.log( 'Request: Grouping {0} faces.'.format(len(self.faces))) res = util.CF.face.group(self.faces.keys()) self.result.set_data(self.faces, res) len_groups = len(res['groups']) if res.get('messyGroup'): len_groups += 1 self.log.log( 'Response: Success. {0} faces grouped into {1} groups'.format( len(self.faces), len_groups)) self.btn.Enable()
def onButtonSetProjectDirectory(self, event): dir0 = None dialog = wx.DirDialog(self.parent, 'Select a directory...', self.dir0, style=wx.DD_DEFAULT_STYLE) if dialog.ShowModal() == wx.ID_OK: dir0 = dialog.GetPath() dialog.Destroy() ### load metadata: if dir0!=None: self.dir0 = dir0 self.settings.set_dir_project(dir0) self.parent.statusbar.SetStatusText(dir0, 1) for button in self.buttons[1:-1]: button.Enable(True) db = DB.PressureDatabaseInitializer(dir0) db.check_initiated() db.check_for_other_files() if db.isinitiated: self.metadata = DB.load_metadata(dir0) self.metadata.dir0 = dir0 self.metadata.save() else: db.assemble_xml_filenames() db.check_xml_filenames() metadataXML = db.parse_xml_filenames() result = wx.MessageBox('This project has not yet been initialized.\nInitialize now?\n\nNote: All XML files will be imported. This could take several minutes to complete.', 'Database initialization', wx.CANCEL | wx.OK) if result==wx.OK: importer = DB.XMLImporter(metadataXML, False) dialog = wx.ProgressDialog("", "Importing XML files...", maximum=importer.nFiles, style = wx.PD_CAN_ABORT | wx.PD_ELAPSED_TIME) keepGoing = True count = 0 while keepGoing and (count < importer.nFiles): keepGoing = dialog.Update(count)[0] importer.filenum = count importer.import_next() count += 1 dialog.Destroy() ### save metadata: metadataH5 = importer.finish() metadataH5.save() metadataH5.savexls() metadataH5.savexls_subjmetadata() metadataH5.save_template_choices()
def Browse(self, event): """ The user find and import FFmpeg executables folder with ffmpeg, ffprobe, ffplay inside on Posix or ffmpeg.exe, ffprobe.exe, ffplay.exe inside on Windows NT. """ if self.OS == 'Windows': listFF = {'ffmpeg.exe': "", 'ffprobe.exe': "", 'ffplay.exe': ""} else: listFF = {'ffmpeg': "", 'ffprobe': "", 'ffplay': ""} dirdialog = wx.DirDialog(self, _("Videomass: locate the ffmpeg folder"), "", wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST) if dirdialog.ShowModal() == wx.ID_OK: path = "%s" % dirdialog.GetPath() dirdialog.Destroy() filelist = [] for ff in os.listdir(path): if ff in listFF.keys(): listFF[ff] = os.path.join("%s" % path, "%s" % ff) error = False for key, val in listFF.items(): if not val: error = True break if error: wx.MessageBox( _("File not found: '{0}'\n" "'{1}' does not exist!\n\n" "Need {2}\n\n" "Please, choose a valid path.").format( os.path.join("%s" % path, "%s" % key), key, [k for k in listFF.keys()]), "Videomass: warning!", wx.ICON_WARNING, self) return self.completion([v for v in listFF.values()])
def browse(self, evt=None): file = Path(self.GetValue()) # Sub in a / for blank paths to force the better folder navigator if file == Path(): file = Path("/") # Open file or dir dlg if self.dlgtype == "dir": dlg = wx.DirDialog(self, message=_translate("Specify folder..."), defaultPath=str(file)) else: dlg = wx.FileDialog(self, message=_translate("Specify file..."), defaultDir=str(file)) if dlg.ShowModal() != wx.ID_OK: return # Get data from dlg file = Path(dlg.GetPath()) # Set data self.SetValue(str(file))
def select_directory_dialog(windowTitle, defaultPath=os.getcwd(), style=None): """ Opens a directory selection dialog Style - specifies style of dialog (read wx documentation for information) """ app = wx.App(None) if style == None: style = wx.DD_DIR_MUST_EXIST dialog = wx.DirDialog(None, windowTitle, defaultPath=defaultPath, style=style) if dialog.ShowModal() == wx.ID_OK: path = dialog.GetPath() else: path = None dialog.Destroy() return path
def addPrefPath(self): currentPath = CeciliaLib.getVar("prefferedPath") path = '' dlg = wx.DirDialog(self, message="Choose a folder...", defaultPath=CeciliaLib.ensureNFD( os.path.expanduser('~'))) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() dlg.Destroy() if path and currentPath != '': path = currentPath + ';' + path elif not path: return CeciliaLib.setVar("prefferedPath", path) self.textPrefPath.SetValue(path)