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)
python类DirDialog()的实例源码
def button_browse_path_click(self, event):
print "Event handler 'button_browse_path_click' not implemented!"
dlg = wx.DirDialog(
self,
"Choose a directory:",
style=wx.DD_DEFAULT_STYLE
)
if dlg.ShowModal() == wx.ID_OK:
self.text_ctrl_outpath.Clear()
self.text_ctrl_outpath.SetValue(dlg.GetPath())
print('You selected: %s\n' % dlg.GetPath())
dlg.Destroy()
event.Skip()
# end of class ExtractionDialog
def fdir_dialogue(self, event):
fdir = "" # Use folder as a flag
currentdir = self.dirchooser.textctrl.GetValue()
dlg = wx.DirDialog(self, defaultPath = currentdir)
if dlg.ShowModal() == wx.ID_OK:
fdir = dlg.GetPath() + "/"
dlg.SetPath(fdir)
dlg.Destroy() # best to do this sooner than later
if fdir:
self.dirchooser.textctrl.SetValue(fdir)
event = wx.PyCommandEvent(wx.EVT_TEXT_ENTER.typeId,
self.dirchooser.textctrl.GetId())
self.GetEventHandler().ProcessEvent(event)
self.fdir = fdir
def open(self, event):
dialog = wx.DirDialog(self, 'Select a Turrican II CDTV directory', '', wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST)
if dialog.ShowModal() != wx.ID_OK:
return
directory = dialog.GetPath()
test_files = ['L1-1', 'L2-1', 'L3-1', 'L4-1', 'L5-1', 'LOADER', 'MAIN']
for filename in test_files:
if not os.path.exists(os.path.join(directory, filename)):
wx.MessageBox('Not a valid Turrican II CDTV directory.', 'Invalid directory', wx.OK | wx.ICON_EXCLAMATION)
return
self._game_dir = directory
self._graphics = Graphics(self._game_dir)
self.load_worlds()
self.Entities.set_graphics(self._graphics)
self.Entities.set_font(self._font)
self.LevelSelect.SetSelection(0)
self.select_level(0, 0)
self.update_menu_state()
self.update_title()
def SaveProjectAs(self):
# Ask user to choose a path with write permissions
if wx.Platform == '__WXMSW__':
path = os.getenv("USERPROFILE")
else:
path = os.getenv("HOME")
dirdialog = wx.DirDialog(self.AppFrame, _("Choose a directory to save project"), path, wx.DD_NEW_DIR_BUTTON)
answer = dirdialog.ShowModal()
dirdialog.Destroy()
if answer == wx.ID_OK:
newprojectpath = dirdialog.GetPath()
if os.path.isdir(newprojectpath):
if self.CheckNewProjectPath(self.ProjectPath, newprojectpath):
self.ProjectPath, old_project_path = newprojectpath, self.ProjectPath
self.SaveProject(old_project_path)
self._setBuildPath(self.BuildPath)
return True
return False
def directory_chooser(parent = None, title = None):
try:
dialog = wx.DirDialog()
except wx._core.PyNoAppError:
app = mzApp()
app.launch()
dialog = wx.DirDialog()
if dialog.ShowModal() == wx.ID_OK:
return dialog.GetPath()
else:
return None
#if __name__ == "__main__":
#print "TEST MODE"
#foo = open_filearray(None, [('Foo', ["*.xlsx", '*.features']), ('Bar', ['*.features', '*.raw'])])
#print "DONE"
def chooseDirectory(self, text):
response = ""
dialog = wx.DirDialog(None, text,style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
if dialog.ShowModal() == wx.ID_OK:
response = dialog.GetPath()
dialog.Destroy()
return response
def Ingest(self):
openMsg='Choose a image directory'
wcd = 'All files (*)|*|Image Directory (*)|*'
dirname = os.path.join(os.path.expanduser('~'),self.myprefs['dir'])
od = wx.DirDialog(self, message=openMsg,
style=wx.FD_OPEN|wx.FD_CHANGE_DIR)
if od.ShowModal() == wx.ID_OK:
projpath= os.path.join( od.GetPath() )
print(projpath)
dbfile = os.path.join ( os.path.dirname(projpath), os.path.basename( od.GetPath())) + '_import_' + str(time.time()).split('.')[0]
self.imgdir = projpath
#with open(os.path.join(projpath,dbfile), 'a'):
# os.utime(path, None)
open( dbfile, 'a' ).close()
self.con = sq.connect(dbfile, isolation_level=None )
self.cur = self.con.cursor()
self.cur.execute("CREATE TABLE IF NOT EXISTS Project(Id INTEGER PRIMARY KEY, Path TEXT, Name TEXT, [timestamp] timestamp)")
self.cur.execute("CREATE TABLE IF NOT EXISTS Timeline(Id INTEGER PRIMARY KEY, Image TEXT, Blackspot INT)")
self.cur.execute("INSERT INTO Project(Path, Name, timestamp) VALUES (?,?,?)", ("images", "StopGo Project", datetime.now() ))
for counter, item in enumerate( sorted(os.listdir(self.imgdir)) ):
self.cur.execute("INSERT INTO Project(Path, Name, timestamp) VALUES (?,?,?)", ("images", "Default Project", datetime.now() ))
self.cur.execute("INSERT INTO Project(Path, Name, timestamp) VALUES (?,?,?)", ("images", "Default Project", datetime.now() ))
self.cur.execute('INSERT INTO Timeline VALUES(?,?,?)', (counter,item,0))
self.BuildTimeline(dbfile)
def _directory_chooser(self, event):
"""Open a directory chooser to select a directory other than default."""
logging.info("Going to open a folder chooser")
dir_dialog = wx.DirDialog(self, style=wx.DD_DIR_MUST_EXIST)
response = dir_dialog.ShowModal()
if response == wx.ID_OK:
logging.info("User selected directory [{}]".format(dir_dialog.GetPath()))
send_message(UploaderAppFrame.directory_selected_topic, directory=dir_dialog.GetPath())
def on_browser_button(self, evt):
cur_entry = self.current_textctrl_GetValue()
if len(cur_entry) == 0:
cur_entry = self.default_entry
cur_entry = os.path.abspath(os.path.expanduser(cur_entry))
cur_entry_parts = [a for a in ['/'] + cur_entry.split('/') if len(a) > 0]
while (len(cur_entry_parts) >= 1 and
not (os.path.isdir(os.path.join(*cur_entry_parts)) or
os.path.isfile(os.path.join(*cur_entry_parts)))):
cur_entry_parts = cur_entry_parts[:-1]
if len(cur_entry_parts) > 1:
cur_entry = os.path.join(*cur_entry_parts)
else:
cur_entry = os.path.expanduser('~')
if os.path.isdir(cur_entry):
cur_basename = ''
cur_dirname = cur_entry
else:
cur_basename = os.path.basename(cur_entry)
cur_dirname = os.path.dirname(cur_entry)
if self.is_files_not_dirs:
dlg = wx.FileDialog(self, "Choose a file:", style=wx.DD_DEFAULT_STYLE,
defaultDir=cur_dirname, defaultFile=cur_basename, wildcard=self.allowed_extensions)
# TODO: defaultFile is not being set to cur_basename in the dialog box
else:
dlg = wx.DirDialog(self, "Choose a directory:", style=wx.DD_DEFAULT_STYLE, defaultPath=cur_dirname)
if dlg.ShowModal() == wx.ID_OK:
self._on_load(dlg.GetPath())
dlg.Destroy()
def on_browser_button(self, evt):
cur_entry = self.current_textctrl_GetValue()
if len(cur_entry) == 0:
cur_entry = self.default_entry
cur_entry = os.path.abspath(os.path.expanduser(cur_entry))
cur_entry_parts = [a for a in ['/'] + cur_entry.split('/') if len(a) > 0]
while (len(cur_entry_parts) >= 1 and
not (os.path.isdir(os.path.join(*cur_entry_parts)) or
os.path.isfile(os.path.join(*cur_entry_parts)))):
cur_entry_parts = cur_entry_parts[:-1]
if len(cur_entry_parts) > 1:
cur_entry = os.path.join(*cur_entry_parts)
else:
cur_entry = os.path.expanduser('~')
if os.path.isdir(cur_entry):
cur_basename = ''
cur_dirname = cur_entry
else:
cur_basename = os.path.basename(cur_entry)
cur_dirname = os.path.dirname(cur_entry)
if self.is_files_not_dirs:
dlg = wx.FileDialog(self, "Choose a file:", style=wx.DD_DEFAULT_STYLE,
defaultDir=cur_dirname, defaultFile=cur_basename, wildcard=self.allowed_extensions)
# TODO: defaultFile is not being set to cur_basename in the dialog box
else:
dlg = wx.DirDialog(self, "Choose a directory:", style=wx.DD_DEFAULT_STYLE, defaultPath=cur_dirname)
if dlg.ShowModal() == wx.ID_OK:
self._on_load(dlg.GetPath())
dlg.Destroy()
def OnCWD(self,e):
panelphase = self.GetChildren()[1].GetPage(0)
if panelphase.pipeline_started == False:
cwd = self.CurrentWD()
dlg = wx.DirDialog(self, 'Set Working Directory', cwd, style=wx.DD_DEFAULT_STYLE, name="Change Current Working Directory")
if dlg.ShowModal() == wx.ID_OK:
os.chdir(dlg.GetPath())
dlg.Destroy()
def OnTaskBarChangeWorkingDir(self, evt):
dlg = wx.DirDialog(None, _("Choose a working directory "), self.pyroserver.workdir, wx.DD_NEW_DIR_BUTTON)
if dlg.ShowModal() == wx.ID_OK:
self.pyroserver.workdir = dlg.GetPath()
self.pyroserver.Stop()
def getdir(title, filt, para=None):
dpath = manager.ConfigManager.get('defaultpath')
if dpath ==None:
dpath = root_dir
dialog = wx.DirDialog(curapp, title, dpath )
rst = dialog.ShowModal()
path = None
if rst == wx.ID_OK:
path = dialog.GetPath()
if para!=None:para['path'] = path
dialog.Destroy()
return rst if para!=None else path
def onDir1(self, event):
"""
Show the DirDialog and print the user's choice to stdout
"""
dlg = wx.DirDialog(self, "Choose a directory:",
style=wx.DD_DEFAULT_STYLE
#| wx.DD_DIR_MUST_EXIST
#| wx.DD_CHANGE_DIR
)
if dlg.ShowModal() == wx.ID_OK:
global src
src=dlg.GetPath()
print('Source folder:', src)
dlg.Destroy()
def onDir2(self, event):
"""
Show the DirDialog and print the user's choice to stdout
"""
dlg2 = wx.DirDialog(self, "Choose a directory:",
style=wx.DD_DEFAULT_STYLE
#| wx.DD_DIR_MUST_EXIST
#| wx.DD_CHANGE_DIR
)
if dlg2.ShowModal() == wx.ID_OK:
global dst
dst=dlg2.GetPath()
print('Destination folder:', dst)
dlg2.Destroy()
def onDir1(self, event):
"""
Show the DirDialog and print the user's choice to stdout
"""
dlg = wx.DirDialog(self, "Choose a directory:",
style=wx.DD_DEFAULT_STYLE
#| wx.DD_DIR_MUST_EXIST
#| wx.DD_CHANGE_DIR
)
if dlg.ShowModal() == wx.ID_OK:
global src
src=dlg.GetPath()
print 'Source folder:', src
dlg.Destroy()
def onDir2(self, event):
"""
Show the DirDialog and print the user's choice to stdout
"""
dlg2 = wx.DirDialog(self, "Choose a directory:",
style=wx.DD_DEFAULT_STYLE
#| wx.DD_DIR_MUST_EXIST
#| wx.DD_CHANGE_DIR
)
if dlg2.ShowModal() == wx.ID_OK:
global dst
dst=dlg2.GetPath()
print 'Destination folder:', dst
dlg2.Destroy()
def onDir1(self, event):
"""
Show the DirDialog and print the user's choice to stdout
"""
dlg = wx.DirDialog(self, "Choose a directory:",
style=wx.DD_DEFAULT_STYLE
#| wx.DD_DIR_MUST_EXIST
#| wx.DD_CHANGE_DIR
)
if dlg.ShowModal() == wx.ID_OK:
global src
src=dlg.GetPath()
print 'Source folder:', src
dlg.Destroy()
def on_promotion(self, event): # wxGlade: admin_dash.<event_handler>
dir = "/home"
dlg=promo_window(self,-1,'')
dlg.ShowModal()
divs= dlg.get_div()
dlg.Destroy()
self.label_promo.SetForegroundColour(self.label_fg_color)
if divs!=[]:
dir_dlg=wx.DirDialog(self, message='Choose Folder...', defaultPath=dir, style=wx.DD_DEFAULT_STYLE)#wx.OVERWRITE_PROMPT
if dir_dlg.ShowModal() == wx.ID_OK:
path = dir_dlg.GetPath()
for each in divs:
year=each[0]
class_=each[1]
div=each[2]
deo=self.DB.Get_School_DEO()
school=self.DB.Get_School_Name()
w_d=self.DB.Get_Working_Days(year,'3')
each_path=path+"/"+class_+div+".pdf"
self.P=Promotion_List(year,school,class_,div,deo,w_d,path=each_path)
self.P.run(open=False)
#self.P=None
os.system("nautilus "+path)
event.Skip()
def set_library_dir(self):
dialog = wx.DirDialog(None, "Choose library directory", desktop, wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST)
dialog.ShowModal()
library_directory = dialog.GetPath()
if library_directory:
core.CONFIG['library_directory'] = library_directory
self.browser.ExecuteJavascript('$("input#library_directory").val({})'.format(json.dumps(library_directory)))
dialog.Destroy()
def onOpenDirectory(self, event):
"""
Opens a DirDialog to allow the user to open a folder with pictures
"""
dlg = wx.DirDialog(self, "Choose a directory",
style=wx.DD_DEFAULT_STYLE)
if dlg.ShowModal() == wx.ID_OK:
self.folderPath = dlg.GetPath()
print self.folderPath
picPaths = glob.glob(self.folderPath + "\\*.jpg")
print picPaths
Publisher().sendMessage("update images", picPaths)
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()