def OpenSource(self, event): # wxGlade: MainFrame.<event_handler>
dlg = wx.FileDialog(
self,
message="Choose Image",
wildcard="All files (*.*)|*.*",
style=wx.OPEN | wx.CHANGE_DIR
)
if dlg.ShowModal() == wx.ID_OK:
paths = dlg.GetPaths()
for path in paths:
self.EnumerateSource(path)
print(' %s\n' % path)
dlg.Destroy()
event.Skip()
python类OPEN的实例源码
def do(self):
#app = wx.PySimpleApp(0)
wcd="Excel Files(*.xls)|*.xls|"
dir = "/home"
save_dlg = wx.FileDialog(self.parent, message='Choose File to be Imported', defaultDir=dir, defaultFile= '', wildcard=wcd, style=wx.OPEN)
if save_dlg.ShowModal() == wx.ID_OK:
path = save_dlg.GetPath()
self.book = open_workbook(path)
self.current_sheet=self.book.sheet_by_index(0)
self.rown=self.current_sheet.nrows
self.DB=db_operations()
self.write_to_db()
save_dlg.Destroy()
print "extd"
def OnLoadMesh(self, evt):
dlg = wx.FileDialog(self, "Choose a file", ".", "", "OFF files (*.off)|*.off|TOFF files (*.toff)|*.toff|OBJ files (*.obj)|*.obj", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetFilename()
dirname = dlg.GetDirectory()
filepath = os.path.join(dirname, filename)
print dirname
self.glcanvas.mesh = PolyMesh()
print "Loading mesh %s..."%filename
self.glcanvas.mesh.loadFile(filepath)
self.glcanvas.meshCentroid = self.glcanvas.mesh.getCentroid()
self.glcanvas.meshPrincipalAxes = self.glcanvas.mesh.getPrincipalAxes()
print "Finished loading mesh"
print self.glcanvas.mesh
self.glcanvas.initMeshBBox()
self.glcanvas.Refresh()
dlg.Destroy()
return
def OnTBLoad(self, event):
if self.running:
rng = True
self.OnTBStart()
else:
rng = False
dlg = wx.FileDialog(None, "Open Spectrum", os.getcwd(), "", "*.*", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetPath()
# set new working directory
directory = os.path.split(filename)
if not os.path.isdir(filename):
os.chdir(directory[0])
# save file
tmpx, tmpy = np.loadtxt(filename, unpack=True)
# add to plot window
self.addLine(tmpx, tmpy)
dlg.Destroy()
if rng:
self.OnTBStart()
def onOpenFile(self, event):
""""""
wildcard = "Python source (*.py)|*.py|" \
"All files (*.*)|*.*"
kwargs = {'message':"Choose a file",
'defaultDir':os.path.dirname(os.path.abspath( __file__ )),
'defaultFile':"",
'wildcard':wildcard,
'style':wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR
}
with ContextFileDialog(self, **kwargs) as dlg:
if dlg.ShowModal() == wx.ID_OK:
paths = dlg.GetPaths()
print "You chose the following file(s):"
for path in paths:
print path
def onOpen(self, evt=None):
"""This method opens an existing file"""
dlg = wx.FileDialog(
self, message="Choose a file",
defaultDir=os.getcwd(),
defaultFile="",
wildcard="*.json",
style=wx.OPEN | wx.CHANGE_DIR
)
# Show the dialog and retrieve the user response. If it is the OK response,
# process the data.
if dlg.ShowModal() == wx.ID_OK:
# This returns a Python list of files that were selected.
path = dlg.GetPath()
print "I'd be opening file in onOpen ", path
self.add_book.load_from_file(filename=path)
else :
print "The file dialog was canceled"
dlg.Destroy()
def chooseSessionFile(self, e):
wildcard = "Save file (*.txt)|*.txt|" \
"All files (*.*)|*.*"
dlg = wx.FileDialog(self, message="Open configuration ...", defaultDir=os.getcwd(),
defaultFile="", wildcard=wildcard, style=wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.path.SetValue(dlg.GetPath())
dlg.Destroy()
self.FitInside()
# Cette fonction permet aux préférences de se mettre à jour même si on ne les a pas changées dans la fenêtre de configuration initiale.
def do_open(self, evt):
dlg = wx.FileDialog(
self, message="Choose a file",
defaultDir=os.getcwd(),
defaultFile="invoice.csv",
wildcard="CSV Files (*.csv)|*.csv",
style=wx.OPEN
)
if dlg.ShowModal() == wx.ID_OK:
# This returns a Python list of files that were selected.
self.filename = dlg.GetPaths()[0]
dlg.Destroy()
self.SetTitle(self.filename + " - " + self.title)
self.do_new()
tmp = []
for lno, linea in enumerate(open(self.filename).readlines()):
if DEBUG: print "processing line", lno, linea
args = []
for i,v in enumerate(linea.split(";")):
if not v.startswith("'"):
v = v.replace(",",".")
else:
v = v#.decode('latin1')
if v.strip()=='':
v = None
else:
v = eval(v.strip())
args.append(v)
tmp.append(args)
# sort by z-order (priority)
for args in sorted(tmp, key=lambda t: t[-1]):
if DEBUG: print args
self.create_elements(*args)
self.diagram.ShowAll( 1 ) #
return True
def __init__(self, parent, name, objectpath, textwidth, file_extension):
def assign(input):
self.objectpath.ChangeValue(input)
def OnBrowse(self):
if IsNotWX4():
dlg = wx.FileDialog(parent, 'Choose a file', os.getcwd(), '', file_extension, wx.OPEN)
else:
dlg = wx.FileDialog(parent, 'Choose a file', os.getcwd(), '', file_extension, wx.FD_OPEN)
if dlg.ShowModal() == wx.ID_OK:
assign(dlg.GetPath())
dlg.Destroy()
def OnEdit(event):
self.objectpath.ChangeValue(event.GetString())
fontpointsize=wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT).GetPointSize()
self.font = wx.Font(fontpointsize, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
dc = wx.ScreenDC()
dc.SetFont(self.font)
textw,texth = dc.GetTextExtent(name)
if textw > textwidth:
labelw = textw
else:
labelw = textwidth
wx.BoxSizer.__init__(self, wx.HORIZONTAL)
self.label = StaticTextNew(parent, -1, name, style =wx.ALIGN_RIGHT, size=(labelw,-1) )
self.label.SetFont(self.font)
self.Add( self.label, 0, wx.CENTER )
self.objectpath = TextCtrlNew(parent, -1)
self.objectpath.SetFont(self.font)
self.objectpath.SetValue(objectpath)
self.objectpath.SetToolTipNew("Browse for file or type "+os.linesep+"path and name")
self.objectpath.Bind(wx.EVT_TEXT_ENTER, OnEdit)
self.Add( self.objectpath, 1, wx.CENTER |wx.EXPAND )
self.button = ButtonNew(parent, -1, "Browse")
self.button.SetFont(self.font)
self.button.SetToolTipNew("Browse for file or type "+os.linesep+"path and name")
self.button.Bind(wx.EVT_BUTTON, OnBrowse)
self.Add( self.button, 0, wx.LEFT|wx.CENTER)
def OnOpen(self,e):
panelphase = self.GetChildren()[1].GetPage(0)
if panelphase.pipeline_started == False:
cwd = self.CurrentWD()
if IsNotWX4():
dlg = wx.FileDialog(self, "Choose a file", cwd, "", "fin files (*.fin)|*.fin|All files (*.*)|*.*", wx.OPEN)
else:
dlg = wx.FileDialog(self, "Choose a file", cwd, "", "fin files (*.fin)|*.fin|All files (*.*)|*.*", wx.FD_OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.filename = dlg.GetFilename()
self.dirname = dlg.GetDirectory()
RestoreInstance(self)
dlg.Destroy()
def OnFileOpen(self, event):
"""Opens a selected file."""
dlg = wx.FileDialog(self, 'Choose a file to add.', '', '', '*.*', wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
fullPath = dlg.GetPath()
imageFile = dlg.GetFilename()
# checkDICMHeader()
self.show_file(imageFile, fullPath)
def OnLoadMesh(self, evt):
dlg = wx.FileDialog(self, "Choose a file", ".", "", "OFF files (*.off)|*.off|TOFF files (*.toff)|*.toff|OBJ files (*.obj)|*.obj", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetFilename()
dirname = dlg.GetDirectory()
filepath = os.path.join(dirname, filename)
print dirname
self.glcanvas.mesh = PolyMesh()
print "Loading mesh %s..."%filename
self.glcanvas.mesh.loadFile(filepath)
self.glcanvas.meshCentroid = self.glcanvas.mesh.getCentroid()
self.glcanvas.meshPrincipalAxes = self.glcanvas.mesh.getPrincipalAxes()
print "Finished loading mesh"
print self.glcanvas.mesh
self.glcanvas.initMeshBBox()
self.glcanvas.Refresh()
dlg.Destroy()
return
def OnOpenProjectMenu(self, event):
if self.Controler is not None and not self.CheckSaveBeforeClosing():
return
filepath = ""
if self.Controler is not None:
filepath = self.Controler.GetFilePath()
if filepath != "":
directory = os.path.dirname(filepath)
else:
directory = os.getcwd()
result = None
dialog = wx.FileDialog(self, _("Choose a file"), directory, "", _("PLCOpen files (*.xml)|*.xml|All files|*.*"), wx.OPEN)
if dialog.ShowModal() == wx.ID_OK:
filepath = dialog.GetPath()
if os.path.isfile(filepath):
self.ResetView()
controler = PLCControler()
result = controler.OpenXMLFile(filepath)
self.Controler = controler
self.LibraryPanel.SetController(controler)
self.ProjectTree.Enable(True)
self.PouInstanceVariablesPanel.SetController(controler)
self._Refresh(PROJECTTREE, LIBRARYTREE)
self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
dialog.Destroy()
if result is not None:
(num, line) = result
self.ShowErrorMessage(_("PLC syntax error at line {a1}:\n{a2}").format(a1=num, a2=line))
def _ImportSVG(self):
dialog = wx.FileDialog(self.GetCTRoot().AppFrame, _("Choose a SVG file"), os.getcwd(), "", _("SVG files (*.svg)|*.svg|All files|*.*"), wx.OPEN)
if dialog.ShowModal() == wx.ID_OK:
svgpath = dialog.GetPath()
if os.path.isfile(svgpath):
shutil.copy(svgpath, self._getSVGpath())
else:
self.GetCTRoot().logger.write_error(_("No such SVG file: %s\n") % svgpath)
dialog.Destroy()
def on_button_attachments(self, event): # wxGlade: email_dialog.<event_handler>
wcd = 'All files (*)|*|Editor files (*.ef)|*.ef|'
#dir = os.getcwd()
open_dlg = wx.FileDialog(self, message='Choose a Attachmet file', defaultFile='',
wildcard=wcd, style=wx.OPEN|wx.CHANGE_DIR)
if open_dlg.ShowModal() == wx.ID_OK:
path = open_dlg.GetPath()
self.text_ctrl_attachment.SetValue(path)
open_dlg.Destroy()
event.Skip()
def on_photo(self, event): # wxGlade: student_profie.<event_handler>
#wcd="Image Files(*.jpeg)|*.jpeg| JPG Files(*.jpg)|*.jpg| PNG Files(*.png)|*.png"
#return 0
print "on photo"
wcd="Image Files(*.jpeg,*.jpg,*.png)|*.jpeg;*.jpg;*.png"
dir = "/home"
open_dlg = wx.FileDialog(self, message='Select Photo', defaultDir=dir, defaultFile= '', wildcard=wcd, style=wx.OPEN)
if open_dlg.ShowModal() == wx.ID_OK:
path = open_dlg.GetPath()
result=self.VALID.validate_photo(path)
if result[0]:
self.bitmap_photo = wx.BitmapButton(self.panel_1, wx.ID_ANY,wx.Bitmap(path, wx.BITMAP_TYPE_ANY))
self.__set_properties()
self.__do_layout()
self.button_save.Enable(True)
self.prof_pic_path=path
open_dlg.Destroy
self.combo_box_adno.SetValue(str(self.current_admission_no))
else:
open_dlg.Destroy
msg=result[1]
icon=wx.ICON_ERROR
dlg = wx.MessageDialog(self, msg, 'Size Error',wx.OK | wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
else:
open_dlg.Destroy()
event.Skip()
def OnFileOpen(self, event):
"""Opens a selected file."""
dlg = wx.FileDialog(self, 'Choose a file to add.', '', '', '*.*', wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
fullPath = dlg.GetPath()
imageFile = dlg.GetFilename()
# checkDICMHeader()
self.show_file(imageFile, fullPath)
def OnOpenFile(self, event):
"""Request to open a new profile file"""
dialog = wx.FileDialog(self, style=wx.OPEN|wx.FD_MULTIPLE)
if dialog.ShowModal() == wx.ID_OK:
paths = dialog.GetPaths()
if self.loader:
# we've already got a displayed data-set, open new window...
frame = MainFrame()
frame.Show(True)
frame.load(*paths)
else:
self.load(*paths)
def on_open(self, evt):
print 'xxx', os.getcwd()
dlg = wx.FileDialog(
self, message="Choose a file",
defaultDir=os.getcwd(),
defaultFile="",
#wildcard=wildcard,
style=wx.OPEN | wx.CHANGE_DIR
)
print 'yyy',os.getcwd()
if dlg.ShowModal() == wx.ID_OK:
paths = dlg.GetPaths()
if paths[0]:
print os.getcwd()
self.dirname, self.filename = os.path.split(paths[0])
self.status_bar.SetStatusText(paths[0])
print os.getcwd()
if self.dvc is None:
self.create_inside_panel()
if self.model is not None:
old_model = self.model
old_model.Clear()
else:
old_model = None
self.model = self.get_model_from_LIS(paths[0])
print os.getcwd()
self.dvc.AssociateModel(self.model)
if old_model:
del old_model
def onOpen(self, evt=None):
"""This method opens an existing file"""
dlg = wx.FileDialog(
self, message="Choose a file",
defaultDir=os.getcwd(),
defaultFile="",
wildcard="*.json",
style=wx.OPEN | wx.CHANGE_DIR
)
# Show the dialog and retrieve the user response. If it is the OK response,
# process the data.
if dlg.ShowModal() == wx.ID_OK:
# This returns a Python list of files that were selected.
path = dlg.GetPath()
print "I'd be opening file in onOpen ", path
self.add_book.load_from_file(filename=path)
else :
print "The file dialog was canceled"
dlg.Destroy()
def onOpen(self, evt=None):
"""This method opens an existing file"""
print "Open a file: "
# Create the dialog. In this case the current directory is forced as the starting
# directory for the dialog, and no default file name is forced. This can easilly
# be changed in your program. This is an 'open' dialog, and allows multitple
# file selections as well.
#
# Finally, if the directory is changed in the process of getting files, this
# dialog is set up to change the current working directory to the path chosen.
dlg = wx.FileDialog( self,
message="Choose a file",
defaultDir=os.getcwd(),
defaultFile="",
wildcard=wildcard,
style=wx.OPEN | wx.CHANGE_DIR
)
# Show the dialog and retrieve the user response. If it is the OK response,
# process the data.
if dlg.ShowModal() == wx.ID_OK:
# This returns a Python list of files that were selected.
path = dlg.GetPath()
print "I'd be opening file in onOpen ", path
self.app_logic.file_open( path )
else :
print "The file dialog was canceled before anything was selected"
# Destroy the dialog. Don't do this until you are done with it!
# BAD things can happen otherwise!
dlg.Destroy()
def onOpen(self, evt=None):
"""This method opens an existing file"""
print "Open a file: "
# Create the dialog. In this case the current directory is forced as the starting
# directory for the dialog, and no default file name is forced. This can easily
# be changed in your program. This is an 'open' dialog, and allows multiple
# file selections as well.
#
# Finally, if the directory is changed in the process of getting files, this
# dialog is set up to change the current working directory to the path chosen.
dlg = wx.FileDialog(
self, message="Choose a file",
defaultDir=os.getcwd(),
defaultFile="",
wildcard=wildcard,
style=wx.OPEN | wx.CHANGE_DIR
)
# Show the dialog and retrieve the user response. If it is the OK response,
# process the data.
if dlg.ShowModal() == wx.ID_OK:
# This returns a Python list of files that were selected.
path = dlg.GetPath()
print "I'd be opening file in onOpen ", path
self.app_logic.file_open( path )
else :
print "The file dialog was canceled before anything was selected"
# Destroy the dialog. Don't do this until you are done with it!
# BAD things can happen otherwise!
dlg.Destroy()
def onOpen(self, evt=None):
"""This method opens an existing file"""
print "Open a file: "
# Create the dialog. In this case the current directory is forced as the starting
# directory for the dialog, and no default file name is forced. This can easilly
# be changed in your program. This is an 'open' dialog, and allows multitple
# file selections as well.
#
# Finally, if the directory is changed in the process of getting files, this
# dialog is set up to change the current working directory to the path chosen.
dlg = wx.FileDialog( self,
message="Choose a file",
defaultDir=os.getcwd(),
defaultFile="",
wildcard=wildcard,
style=wx.OPEN | wx.CHANGE_DIR
)
# Show the dialog and retrieve the user response. If it is the OK response,
# process the data.
if dlg.ShowModal() == wx.ID_OK:
# This returns a Python list of files that were selected.
path = dlg.GetPath()
print "I'd be opening file in onOpen ", path
self.app_logic.file_open( path )
else :
print "The file dialog was canceled before anything was selected"
# Destroy the dialog. Don't do this until you are done with it!
# BAD things can happen otherwise!
dlg.Destroy()
def onOpen(self, evt=None):
"""This method opens an existing file"""
print "Open a file: "
# Create the dialog. In this case the current directory is forced as the starting
# directory for the dialog, and no default file name is forced. This can easilly
# be changed in your program. This is an 'open' dialog, and allows multitple
# file selections as well.
#
# Finally, if the directory is changed in the process of getting files, this
# dialog is set up to change the current working directory to the path chosen.
dlg = wx.FileDialog( self,
message="Choose a file",
defaultDir=os.getcwd(),
defaultFile="",
wildcard=wildcard,
style=wx.OPEN | wx.CHANGE_DIR
)
# Show the dialog and retrieve the user response. If it is the OK response,
# process the data.
if dlg.ShowModal() == wx.ID_OK:
# This returns a Python list of files that were selected.
path = dlg.GetPath()
print "I'd be opening file in onOpen ", path
self.app_logic.file_open( path )
else :
print "The file dialog was canceled before anything was selected"
# Destroy the dialog. Don't do this until you are done with it!
# BAD things can happen otherwise!
dlg.Destroy()
def onOpen(self, evt=None):
"""This method opens an existing file"""
print "Open a file: "
# Create the dialog. In this case the current directory is forced as the starting
# directory for the dialog, and no default file name is forced. This can easily
# be changed in your program. This is an 'open' dialog, and allows multiple
# file selections as well.
#
# Finally, if the directory is changed in the process of getting files, this
# dialog is set up to change the current working directory to the path chosen.
dlg = wx.FileDialog(
self, message="Choose a file",
defaultDir=os.getcwd(),
defaultFile="",
wildcard=wildcard,
style=wx.OPEN | wx.CHANGE_DIR
)
# Show the dialog and retrieve the user response. If it is the OK response,
# process the data.
if dlg.ShowModal() == wx.ID_OK:
# This returns a Python list of files that were selected.
path = dlg.GetPath()
print "I'd be opening file in onOpen ", path
self.app_logic.file_open( path )
else :
print "The file dialog was canceled before anything was selected"
# Destroy the dialog. Don't do this until you are done with it!
# BAD things can happen otherwise!
dlg.Destroy()
def on_import_db(self, event): # wxGlade: admin_dash.<event_handler>
'''
msg="This feature is suspended"
dlg = wx.MessageDialog(self, msg, '',wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
return 0
'''
msg="Importing may overwrite some of the existing data \n Do you want to continue?"
dlg = wx.MessageDialog(self, msg)#,wx.SAVE|wx.ICON_QUESTION)
if dlg.ShowModal() == wx.ID_OK:
dir = "/home"
wcd="Exam Files(*.xam)|*.xam|"
open_dlg = wx.FileDialog(self, message='Choose a file', defaultDir=dir, defaultFile='', wildcard=wcd, style=wx.OPEN|wx.CHANGE_DIR)
if open_dlg.ShowModal() == wx.ID_OK:
path = open_dlg.GetPath()
try:
self.DB.import_(path)
dlg = wx.MessageDialog(self, 'Successfully imported', '',wx.OK | wx.ICON_INFORMATION)
except:
dlg = wx.MessageDialog(self, 'Sorry, Could not import', '',wx.OK | wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
self.label_import_db.SetForegroundColour(self.label_fg_color)
event.Skip()