def Open(self, e):
openFileDialog = wx.FileDialog(
self,
"Open Log file",
"",
"",
"log files (*.mi2log) |*.mi2log| All files |*.*",
wx.FD_OPEN | wx.FD_FILE_MUST_EXIST | wx.FD_MULTIPLE)
if (openFileDialog.ShowModal() == wx.ID_OK):
# print 'Selected %s' %openFileDialog.GetPath()
print 'Selected %s' % openFileDialog.Paths
try:
self.grid.ClearGrid()
# thread.start_new_thread(openFile,(openFileDialog.GetPath(),))
# t = Thread(target = self.openFile, args=(openFileDialog.GetPath(),self.selectedTypes))
t = Thread(
target=self.openFile,
args=(
openFileDialog.Paths,
self.selectedTypes))
self.progressDialog = ProgressDialog(self)
t.start()
self.progressDialog.ShowModal()
if len(openFileDialog.Paths) == 1:
self.SetTitle(openFileDialog.GetPath())
else:
self.SetTitle(
"Multiple files in " +
openFileDialog.Directory)
except e:
print "Error while opening file.", e
# if (random() > 0.5):
# self.SetupGrid(self.data1)
# else:
# self.SetupGrid(self.data2)
python类FD_FILE_MUST_EXIST的实例源码
def on_open(self, event):
"""
Recursively loads a KiCad schematic and all subsheets
"""
#self.save_component_type_changes()
open_dialog = wx.FileDialog(self, "Open KiCad Schematic", "", "",
"Kicad Schematics (*.sch)|*.sch",
wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
if open_dialog.ShowModal() == wx.ID_CANCEL:
return
# Load Chosen Schematic
print("opening File:", open_dialog.GetPath())
# Store the path to the file history
self.filehistory.AddFileToHistory(open_dialog.GetPath())
self.filehistory.Save(self.config)
self.config.Flush()
self.load(open_dialog.GetPath())
def on_open(*args, **kwargs):
wildcard = "Arquivo de projeto do GRIPy (*.pgg)|*.pgg"
try:
fdlg = wx.FileDialog(wx.App.Get().GetTopWindow(),
'Escolha o arquivo PGG',
wildcard=wildcard,
style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST
)
if fdlg.ShowModal() == wx.ID_OK:
file_name = fdlg.GetFilename()
dir_name = fdlg.GetDirectory()
fdlg.Destroy()
else:
fdlg.Destroy()
return
fullfilename = os.path.join(dir_name, file_name)
gripy_app = wx.App.Get()
gripy_app.load_project_data(fullfilename)
except Exception:
raise
def OnOpen(self, event):
openFileDialog = wx.FileDialog(self, "Open i3 Config file", os.path.expanduser("~/.i3/"), "","i3 Config file |*", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
if openFileDialog.ShowModal() == wx.ID_CANCEL:
return
cfg = Config(self.messager,openFileDialog.GetPath())
self.LoadConfig(cfg)
def audio_btn_click(self, e):
openFileDialog = wx.FileDialog(self, "Select caps folder", "", "", "MP3 files (*.mp3)|*.mp3", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
openFileDialog.SetMessage("Select an audio file from to use")
if openFileDialog.ShowModal() == wx.ID_CANCEL:
return 'none'
audio_track = openFileDialog.GetPath()
self.audio_box.SetValue(str(audio_track))
def select_caps_folder(self):
openFileDialog = wx.FileDialog(self, "Select caps folder", "", "", "JPG files (*.jpg)|*.jpg", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
openFileDialog.SetMessage("Select an image from the caps folder you want to import")
if openFileDialog.ShowModal() == wx.ID_CANCEL:
return 'none'
new_cap_path = openFileDialog.GetPath()
capsdir = os.path.split(new_cap_path)
capset = capsdir[1].split(".")[0][0:-10] # Used to select set if more than one are present
cap_type = capsdir[1].split('.')[1]
capsdir = capsdir[0] + '/'
print(" Selected " + capsdir + " with capset; " + capset + " filetype; " + cap_type)
return capsdir, capset, cap_type
def browse(self, event):
wildcard = "Audio and Video files ({wildcards})|{wildcards}".format(wildcards=';'.join(FILE_EXTS))
file_dialog = wx.FileDialog(self, message="Select files",
style=wx.FD_OPEN | wx.FD_MULTIPLE | wx.FD_FILE_MUST_EXIST, wildcard=wildcard)
file_dialog.SetDirectory(self.in_dir) if self.in_dir else None
if file_dialog.ShowModal() != wx.ID_OK:
file_dialog.Destroy()
return
self.in_files = file_dialog.GetPaths()
self.in_picker.GetTextCtrl().SetValue(str(file_dialog.GetFilenames()).strip('[]'))
file_dialog.Destroy()
def file_open_dialog():
dialog_style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST
dialog = wx.FileDialog(
None, message='Open',
defaultDir=os.getcwd(),
defaultFile='', style=dialog_style)
return dialog
def set_cemu_exe(self):
dialog = wx.FileDialog(None, "Open", desktop, "", "Cemu (*.exe)|*.exe", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) # self.app.frame,
dialog.ShowModal()
cemu_exe = dialog.GetPath()
if cemu_exe:
core.CONFIG['cemu_exe'] = cemu_exe
self.browser.ExecuteJavascript('$("input#cemu_exe").val({})'.format(json.dumps(cemu_exe)))
dialog.Destroy()
def set_bg_image(self):
dialog = wx.FileDialog(None, "Open", desktop, "", "Images (*.jpg; *.png; *.bmp)|*.jpg; *.png; *.bmp", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
dialog.ShowModal()
bg_image = dialog.GetPath()
print bg_image
if bg_image:
core.CONFIG['background_image'] = bg_image
self.browser.ExecuteJavascript('$("input#background_image").val({})'.format(json.dumps(bg_image)))
self.browser.ExecuteFunction('update_bg_image', json.dumps(bg_image))
dialog.Destroy()
def OpenfileButton(self, event):
openFileDialog = wx.FileDialog(self, "Open", "", "", "Newick files (*.nwk)|*.nwk", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
openFileDialog.ShowModal()
self.path = openFileDialog.GetPath()
if self.path != "":
st = self.path.rfind("/") + 1
self.m_staticText161.SetForegroundColour((0, 100, 0))
self.m_staticText161.SetLabel(self.path[st :])
self.m_staticText16.SetLabel(u"???????")
def on_import_segy_seis(event):
style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST
wildcard="Arquivos SEG-Y (*.sgy)|*.sgy"
file_dlg = wx.FileDialog(wx.App.Get().GetTopWindow(),
'Escolha o arquivo SEG-Y',
wildcard=wildcard, style=style
)
result = file_dlg.ShowModal()
if result == wx.ID_OK:
file_name = file_dlg.GetFilename()
dir_name = file_dlg.GetDirectory()
file_dlg.Destroy()
if result == wx.ID_CANCEL:
return
name = file_name.split('.')[0]
app_utils.load_segy(event, os.path.join(dir_name, file_name),
new_obj_name=name, comparators_list=None,
iline_byte=9, xline_byte=21, offset_byte=37
)
def on_import_segy_vel(event):
style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST
wildcard="SEG-Y files (*.sgy)|*.sgy"
fdlg = wx.FileDialog(wx.App.Get().GetTopWindow(), 'Choose SEG-Y file',
wildcard=wildcard, style=style)
if fdlg.ShowModal() == wx.ID_OK:
file_name = fdlg.GetFilename()
dir_name = fdlg.GetDirectory()
fdlg.Destroy()
else:
fdlg.Destroy()
return
segy_file = FileIO.SEGY.SEGYFile(os.path.join(dir_name, file_name))
segy_file.read()
name = segy_file.filename.rsplit('\\')[-1]
name = name.split('.')[0]
OM = ObjectManager(event.GetEventObject())
velocity = OM.new('velocity', segy_file.data, name=name,
unit='ms', domain='time',
sample_rate=segy_file.sample_rate*1000, datum=0,
samples=segy_file.number_of_samples,
#stacked=stacked,
traces=int(segy_file.data.shape[0])
)
OM.add(velocity)
def onLoadFile(self, evt):
style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST
wildcard = "Arquivo de console GRIPy (*.gripy_console)|*.gripy_console"
fdlg = wx.FileDialog(self, 'Escolha o arquivo gripy_console',
defaultDir=self.dir_name,
wildcard=wildcard,
style=style
)
if fdlg.ShowModal() == wx.ID_OK:
self.file_name = fdlg.GetFilename()
self.dir_name = fdlg.GetDirectory()
self._load_file()
fdlg.Destroy()
def read_superputty_xml(self):
style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST
dialog = wx.FileDialog(self, message='Open Sessions.XML', wildcard='(*.XML)|*.XML', style=style)
if dialog.ShowModal() == wx.ID_OK:
file = dialog.GetPath()
else:
return False
dialog.Destroy()
try:
tree = ET.parse(file)
for item in tree.iter():
if item.tag == "SessionData":
sessionPath = item.attrib.get('SessionId')
list = sessionPath.encode('utf-8').split('/')
tmp = self.root
res = Resolver('name')
counter = 1
for i in list:
pathB64 = base64.b64encode(i)
try:
if res.get(tmp, pathB64):
tmp = res.get(tmp, pathB64)
if counter >= len(list):
print pathB64
self.saveSessionData(
node=tmp,
name=str(item.attrib.get('SessionName').encode('utf-8')),
username=str(item.attrib.get('Username').encode('utf-8')),
privateKey='',
hostname=str(item.attrib.get('Host').encode('utf-8')),
port=str(item.attrib.get('Port').encode('utf-8'))
)
print pathB64
except ChildResolverError as e:
if counter < len(list):
tmp = Node(pathB64, parent=tmp, type="Container")
if counter >= len(list):
self.saveSessionData(
node=tmp,
name=str(item.attrib.get('SessionName').encode('utf-8')),
username=str(item.attrib.get('Username').encode('utf-8')),
privateKey='',
hostname=str(item.attrib.get('Host').encode('utf-8')),
port=str(item.attrib.get('Port').encode('utf-8'))
)
counter = counter + 1
return True
except Exception as e:
return False
def read_mobaxterm_ini(self):
style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST
dialog = wx.FileDialog(self, message='Open MobaXterm.ini', wildcard='(*.ini)|*.ini', style=style)
if dialog.ShowModal() == wx.ID_OK:
file = dialog.GetPath()
else:
return False
dialog.Destroy()
try:
config = configparser.RawConfigParser()
config.optionxform = str
config.read(file)
res = Resolver('name')
for s in config.sections():
if s.startswith('Bookmarks'):
if config[s]['SubRep'] == 'PuTTY sessions':
continue
tmp = self.root
for (key,val) in config.items(s):
if key == 'ImgNum':
continue
if key == 'SubRep' and val:
sessionPath = config[s]['SubRep']
list = sessionPath.encode('utf-8').split('\\')
counter = 1
for i in list:
pathB64 = base64.b64encode(i)
try:
if res.get(tmp, pathB64):
tmp = res.get(tmp, pathB64)
except ChildResolverError as e:
node = Node(pathB64, parent=tmp, type='Container')
tmp = node
counter = counter + 1
break
for (key,val) in config.items(s):
if key == 'ImgNum' or key == 'SubRep':
continue
sessionData = val.encode('utf-8').split('%')
if sessionData[0] == '#109#0':
self.saveSessionData(tmp, key, sessionData[3], '', sessionData[1], sessionData[2])
return True
except Exception as e:
return False