Python wx.FileDialog() Examples
The following are 30
code examples of wx.FileDialog().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
wx
, or try the search function
.
Example #1
Source File: gui.py From RF-Monitor with GNU General Public License v2.0 | 7 votes |
def __save(self, prompt): if prompt or self._filename is None: defDir, defFile = '', '' if self._filename is not None: defDir, defFile = os.path.split(self._filename) dlg = wx.FileDialog(self, 'Save File', defDir, defFile, 'rfmon files (*.rfmon)|*.rfmon', wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) if dlg.ShowModal() == wx.ID_CANCEL: return self._filename = dlg.GetPath() self.__update_settings() save_recordings(self._filename, self._settings.get_freq(), self._settings.get_gain(), self._settings.get_cal(), self._settings.get_dynamic_percentile(), self._monitors) self.__set_title() self._isSaved = True self.__set_title()
Example #2
Source File: trelby.py From trelby with GNU General Public License v2.0 | 6 votes |
def OnLoadScriptSettings(self, event = None): dlg = wx.FileDialog(self, "File to open", defaultDir = gd.scriptSettingsPath, wildcard = "Script setting files (*.sconf)|*.sconf|All files|*", style = wx.OPEN) if dlg.ShowModal() == wx.ID_OK: s = util.loadFile(dlg.GetPath(), self) if s: cfg = config.Config() cfg.load(s) self.panel.ctrl.applyCfg(cfg) gd.scriptSettingsPath = os.path.dirname(dlg.GetPath()) dlg.Destroy()
Example #3
Source File: trelby.py From trelby with GNU General Public License v2.0 | 6 votes |
def OnSaveScriptAs(self): if self.fileName: dDir = os.path.dirname(self.fileName) dFile = os.path.basename(self.fileName) else: dDir = misc.scriptDir dFile = u"" dlg = wx.FileDialog(mainFrame, "Filename to save as", defaultDir = dDir, defaultFile = dFile, wildcard = "Trelby files (*.trelby)|*.trelby|All files|*", style = wx.SAVE | wx.OVERWRITE_PROMPT) if dlg.ShowModal() == wx.ID_OK: self.saveFile(dlg.GetPath()) dlg.Destroy()
Example #4
Source File: cfgdlg.py From trelby with GNU General Public License v2.0 | 6 votes |
def OnBrowse(self, event): if self.pf.filename: dDir = os.path.dirname(self.pf.filename) dFile = os.path.basename(self.pf.filename) else: dDir = self.lastDir dFile = u"" dlg = wx.FileDialog(cfgFrame, "Choose font file", defaultDir = dDir, defaultFile = dFile, wildcard = "TrueType fonts (*.ttf;*.TTF)|*.ttf;*.TTF|All files|*", style = wx.OPEN) if dlg.ShowModal() == wx.ID_OK: self.fileEntry.SetValue(dlg.GetPath()) self.fileEntry.SetInsertionPointEnd() fname = dlg.GetPath() self.nameEntry.SetValue(self.getFontPostscriptName(fname)) self.lastDir = os.path.dirname(fname) dlg.Destroy()
Example #5
Source File: bomsaway.py From Boms-Away with GNU General Public License v3.0 | 6 votes |
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())
Example #6
Source File: bomsaway.py From Boms-Away with GNU General Public License v3.0 | 6 votes |
def on_export(self, event): """ Gets a file path via popup, then exports content """ exporters = plugin_loader.load_export_plugins() wildcards = '|'.join([x.wildcard for x in exporters]) export_dialog = wx.FileDialog(self, "Export BOM", "", "", wildcards, wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) if export_dialog.ShowModal() == wx.ID_CANCEL: return base, ext = os.path.splitext(export_dialog.GetPath()) filt_idx = export_dialog.GetFilterIndex() exporters[filt_idx]().export(base, self.component_type_map)
Example #7
Source File: trelby.py From trelby with GNU General Public License v2.0 | 6 votes |
def OnImportScript(self, event = None): dlg = wx.FileDialog(self, "File to import", misc.scriptDir, wildcard = "Importable files (*.txt;*.fdx;*.celtx;*.astx;*.fountain;*.fadein)|" + "*.fdx;*.txt;*.celtx;*.astx;*.fountain;*.fadein|" + "Formatted text files (*.txt)|*.txt|" + "Final Draft XML(*.fdx)|*.fdx|" + "Celtx files (*.celtx)|*.celtx|" + "Adobe Story XML files (*.astx)|*.astx|" + "Fountain files (*.fountain)|*.fountain|" + "Fadein files (*.fadein)|*.fadein|" + "All files|*", style = wx.OPEN) if dlg.ShowModal() == wx.ID_OK: misc.scriptDir = dlg.GetDirectory() if not self.tabCtrl.getPage(self.findPage(self.panel))\ .ctrl.isUntouched(): self.panel = self.createNewPanel() self.panel.ctrl.importFile(dlg.GetPath()) self.panel.ctrl.updateScreen() dlg.Destroy()
Example #8
Source File: gui.py From RF-Monitor with GNU General Public License v2.0 | 6 votes |
def __on_open(self, _event): if not self.__save_warning(): return defDir, defFile = '', '' if self._filename is not None: defDir, defFile = os.path.split(self._filename) dlg = wx.FileDialog(self, 'Open File', defDir, defFile, 'rfmon files (*.rfmon)|*.rfmon', wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) if dlg.ShowModal() == wx.ID_CANCEL: return self.open(dlg.GetPath()) self._isSaved = True self.__set_title()
Example #9
Source File: trelby.py From trelby with GNU General Public License v2.0 | 6 votes |
def OnLoadSettings(self, event = None): dlg = wx.FileDialog(self, "File to open", defaultDir = os.path.dirname(gd.confFilename), defaultFile = os.path.basename(gd.confFilename), wildcard = "Setting files (*.conf)|*.conf|All files|*", style = wx.OPEN) if dlg.ShowModal() == wx.ID_OK: s = util.loadFile(dlg.GetPath(), self) if s: c = config.ConfigGlobal() c.load(s) gd.confFilename = dlg.GetPath() self.panel.ctrl.applyGlobalCfg(c, False) dlg.Destroy()
Example #10
Source File: MainUI.py From Model-Playgrounds with MIT License | 6 votes |
def launchFileDialog(self, evt): # defining wildcard for suppported picture formats wildcard = "JPEG (*.jpg)|*.jpg|" \ "PNG (*.png)|*.png|" \ "GIF (*.gif)|*.gif" # defining the dialog object dialog = wx.FileDialog(self, message="Select Picture", defaultDir=os.getcwd(), defaultFile="", wildcard=wildcard, style=wx.FD_OPEN | wx.FD_MULTIPLE | wx.FD_CHANGE_DIR | wx.FD_FILE_MUST_EXIST | wx.FD_PREVIEW) # Function to retrieve file dialog response and return the full path of the first image (it is a multi-file selection dialog) if dialog.ShowModal() == wx.ID_OK: self.magic_collection[1].SetValue( "You have selected a Picture. It will now be processed!, Please wait! \nLoading.....") paths = dialog.GetPaths() # This adds the selected picture to the Right region. Right region object is retrieved from UI object array modification_bitmap1 = wx.Bitmap(paths[0]) modification_image1 = modification_bitmap1.ConvertToImage() modification_image1 = modification_image1.Scale(650, 490, wx.IMAGE_QUALITY_HIGH) modification_bitmap2 = modification_image1.ConvertToBitmap() report_bitmap = wx.StaticBitmap(self.magic_collection[0], -1, modification_bitmap2, (0, 20)) self.processPicture(paths[0], "PROGRAM_INSTALL_FULLPATH\\inception_v3_weights_tf_dim_ordering_tf_kernels.h5", "PROGRAM_INSTALL_FULLPATH\\imagenet_class_index.json")
Example #11
Source File: LapGUI.py From laplacian-meshes with GNU General Public License v3.0 | 6 votes |
def OnLoadMesh(self, evt): dlg = wx.FileDialog(self, "Choose a file", ".", "", "OFF files (*.off)|*.off|TOFF files (*.toff)|*.toff|OBJ files (*.obj)|*.obj", wx.FD_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.clearAllSelections() self.glcanvas.Refresh() dlg.Destroy() return
Example #12
Source File: elecsus_gui.py From ElecSus with Apache License 2.0 | 6 votes |
def OnSaveFig(self,event): """ Basically the same as saving the figure by the toolbar button. """ #widcards for file type selection wilds = "PDF (*.pdf)|*.pdf|" \ "PNG (*.png)|*.png|" \ "EPS (*.eps)|*.eps|" \ "All files (*.*)|*.*" exts = ['.pdf','.png','.eps','.pdf'] # default to pdf SaveFileDialog = wx.FileDialog(self,message="Save Figure", defaultDir="./", defaultFile="figure", wildcard=wilds, style=wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) SaveFileDialog.SetFilterIndex(0) if SaveFileDialog.ShowModal() == wx.ID_OK: output_filename = SaveFileDialog.GetPath() if output_filename[-4:] == exts[SaveFileDialog.GetFilterIndex()]: output_filename = output_filename[:-4] #save all current figures for fig, id in zip(self.figs, self.fig_IDs): fig.savefig(output_filename+'_'+str(id)+exts[SaveFileDialog.GetFilterIndex()]) SaveFileDialog.Destroy()
Example #13
Source File: gui.py From report-ng with GNU General Public License v2.0 | 6 votes |
def Save_Template_As(self, e): openFileDialog = wx.FileDialog(self, 'Save Template As', self.save_into_directory, '', 'Content files (*.yaml; *.json)|*.yaml;*.json|All files (*.*)|*.*', wx.FD_SAVE | wx.wx.FD_OVERWRITE_PROMPT) if openFileDialog.ShowModal() == wx.ID_CANCEL: return json_ext = '.json' filename = openFileDialog.GetPath() self.status('Saving Template content...') h = open(filename, 'w') if filename[-len(json_ext):] == json_ext: h.write(self.report.template_dump_json().encode('utf-8')) else: h.write(self.report.template_dump_yaml().encode('utf-8')) h.close() self.status('Template content saved')
Example #14
Source File: MainUI.py From Model-Playgrounds with MIT License | 6 votes |
def launchFileDialog(self, evt): # defining wildcard for suppported picture formats wildcard = "JPEG (*.jpg)|*.jpg|" \ "PNG (*.png)|*.png|" \ "GIF (*.gif)|*.gif" # defining the dialog object dialog = wx.FileDialog(self, message="Select Picture", defaultDir=os.getcwd(), defaultFile="", wildcard=wildcard, style=wx.FD_OPEN | wx.FD_MULTIPLE | wx.FD_CHANGE_DIR | wx.FD_FILE_MUST_EXIST | wx.FD_PREVIEW) # Function to retrieve file dialog response and return the full path of the first image (it is a multi-file selection dialog) if dialog.ShowModal() == wx.ID_OK: self.magic_collection[1].SetValue( "You have selected a Picture. It will now be processed!, Please wait! \nLoading.....") paths = dialog.GetPaths() # This adds the selected picture to the Right region. Right region object is retrieved from UI object array modification_bitmap1 = wx.Bitmap(paths[0]) modification_image1 = modification_bitmap1.ConvertToImage() modification_image1 = modification_image1.Scale(650, 490, wx.IMAGE_QUALITY_HIGH) modification_bitmap2 = modification_image1.ConvertToBitmap() report_bitmap = wx.StaticBitmap(self.magic_collection[0], -1, modification_bitmap2, (0, 20)) self.processPicture(paths[0], "PROGRAM_INSTALL_FULLPATH\\DenseNet-BC-121-32.h5", "PROGRAM_INSTALL_FULLPATH\\imagenet_class_index.json")
Example #15
Source File: MainUI.py From Model-Playgrounds with MIT License | 6 votes |
def launchFileDialog(self, evt): # defining wildcard for suppported picture formats wildcard = "JPEG (*.jpg)|*.jpg|" \ "PNG (*.png)|*.png|" \ "GIF (*.gif)|*.gif" # defining the dialog object dialog = wx.FileDialog(self, message="Select Picture", defaultDir=os.getcwd(), defaultFile="", wildcard=wildcard, style=wx.FD_OPEN | wx.FD_MULTIPLE | wx.FD_CHANGE_DIR | wx.FD_FILE_MUST_EXIST | wx.FD_PREVIEW) # Function to retrieve file dialog response and return the full path of the first image (it is a multi-file selection dialog) if dialog.ShowModal() == wx.ID_OK: self.magic_collection[1].SetValue( "You have selected a Picture. It will now be processed!, Please wait! \nLoading.....") paths = dialog.GetPaths() # This adds the selected picture to the Right region. Right region object is retrieved from UI object array modification_bitmap1 = wx.Bitmap(paths[0]) modification_image1 = modification_bitmap1.ConvertToImage() modification_image1 = modification_image1.Scale(650, 490, wx.IMAGE_QUALITY_HIGH) modification_bitmap2 = modification_image1.ConvertToBitmap() report_bitmap = wx.StaticBitmap(self.magic_collection[0], -1, modification_bitmap2, (0, 20)) self.processPicture(paths[0], "PROGRAM_INSTALL_FULLPATH\\squeezenet_weights_tf_dim_ordering_tf_kernels.h5", "PROGRAM_INSTALL_FULLPATH\\imagenet_class_index.json")
Example #16
Source File: MainUI.py From Model-Playgrounds with MIT License | 6 votes |
def launchFileDialog(self, evt): # defining wildcard for suppported picture formats wildcard = "JPEG (*.jpg)|*.jpg|" \ "PNG (*.png)|*.png|" \ "GIF (*.gif)|*.gif" # defining the dialog object dialog = wx.FileDialog(self, message="Select Picture", defaultDir=os.getcwd(), defaultFile="", wildcard=wildcard, style=wx.FD_OPEN | wx.FD_MULTIPLE | wx.FD_CHANGE_DIR | wx.FD_FILE_MUST_EXIST | wx.FD_PREVIEW) # Function to retrieve file dialog response and return the full path of the first image (it is a multi-file selection dialog) if dialog.ShowModal() == wx.ID_OK: self.magic_collection[1].SetValue( "You have selected a Picture. It will now be processed!, Please wait! \nLoading.....") paths = dialog.GetPaths() # This adds the selected picture to the Right region. Right region object is retrieved from UI object array modification_bitmap1 = wx.Bitmap(paths[0]) modification_image1 = modification_bitmap1.ConvertToImage() modification_image1 = modification_image1.Scale(650, 490, wx.IMAGE_QUALITY_HIGH) modification_bitmap2 = modification_image1.ConvertToBitmap() report_bitmap = wx.StaticBitmap(self.magic_collection[0], -1, modification_bitmap2, (0, 20)) self.processPicture(paths[0], "PROGRAM_INSTALL_FULLPATH\\resnet50_weights_tf_dim_ordering_tf_kernels.h5", "PROGRAM_INSTALL_FULLPATH\\imagenet_class_index.json")
Example #17
Source File: pyResManDialog.py From pyResMan with GNU General Public License v2.0 | 6 votes |
def _buttonLoadCardDataOnButtonClick(self, event): # Open file dialog; saveFileDialog = wx.FileDialog(self, "Load data from file ...", "", "", "All files (*.*)|*.*", wx.FD_OPEN) if saveFileDialog.ShowModal() == wx.ID_CANCEL: return file_path_name = saveFileDialog.GetPath() # Read card data from file; with open(file_path_name, 'rb') as f: card_data = f.read() if len(card_data) != 1024: self._Log('Invalid card data.', wx.LOG_Error) return # Set card data to Grid; for row_index in range(self._gridCardData.GetNumberRows()): for col_index in range(self._gridCardData.GetNumberCols()): self._gridCardData.SetCellValue(row_index, col_index, '%02X' % (ord(card_data[row_index * 0x10 + col_index]))) self._Log('Card data has been loaded from file: %s.' % (file_path_name), wx.LOG_Info) return
Example #18
Source File: preview.py From IkaLog with Apache License 2.0 | 6 votes |
def on_button_click(self, event): file_path = self.text_ctrl.GetValue() if self.should_open_file(file_path): evt = InputFileAddedEvent(input_file=file_path) wx.PostEvent(self, evt) self.prev_file_path = file_path self.update_button_label() return # file_path is invalid. Open a file dialog. file_dialog = wx.FileDialog(self, _('Select a video file')) if file_dialog.ShowModal() != wx.ID_OK: return file_path = file_dialog.GetPath() self.text_ctrl.SetValue(file_path) # Callback from wx.FileDropTarget.OnDropFiles
Example #19
Source File: guiminer.py From poclbm with GNU General Public License v3.0 | 6 votes |
def new_external_profile(self, event): """Prompt for an external miner path, then create a miner. On Windows we validate against legal miners; on Linux they can pick whatever they want. """ wildcard = _('External miner (*.exe)|*.exe|(*.py)|*.py') if sys.platform == 'win32' else '*.*' dialog = wx.FileDialog(self, _("Select external miner:"), defaultDir=os.path.join(get_module_path(), 'miners'), defaultFile="", wildcard=wildcard, style=wx.OPEN) if dialog.ShowModal() != wx.ID_OK: return if sys.platform == 'win32' and dialog.GetFilename() not in SUPPORTED_BACKENDS: self.message( _("Unsupported external miner %(filename)s. Supported are: %(supported)s") % \ dict(filename=dialog.GetFilename(), supported='\n'.join(SUPPORTED_BACKENDS)), _("Miner not supported"), wx.OK | wx.ICON_ERROR) return path = os.path.join(dialog.GetDirectory(), dialog.GetFilename()) dialog.Destroy() self.name_new_profile(extra_profile_data=dict(external_path="CGMINER"))
Example #20
Source File: configuration_dialogs.py From superpaper with MIT License | 6 votes |
def onChooseTestImage(self, event): """Open a file dialog to choose a test image.""" with wx.FileDialog(self, "Choose a test image", wildcard=("Image files (*.jpg;*.jpeg;*.png;*.bmp;*.gif;*.tiff;*.webp)" "|*.jpg;*.jpeg;*.png;*.bmp;*.gif;*.tiff;*.webp"), defaultDir=self.frame.defdir, style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as file_dialog: if file_dialog.ShowModal() == wx.ID_CANCEL: return # the user changed their mind # Proceed loading the file chosen by the user self.test_image = file_dialog.GetPath() self.tc_testimage.SetValue( os.path.basename(self.test_image) ) return
Example #21
Source File: BackgroundProcess.py From p2ptv-pi with MIT License | 6 votes |
def gui_webui_save_download(self, d2save, path): try: if sys.platform == 'win32': from win32com.shell import shell pidl = shell.SHGetSpecialFolderLocation(0, 5) defaultpath = shell.SHGetPathFromIDList(pidl) else: defaultpath = os.path.expandvars('$HOME') except: defaultpath = '' filename = 'test.mkv' if globalConfig.get_mode() == 'client_wx': import wx dlg = wx.FileDialog(None, message='Save file', defaultDir=defaultpath, defaultFile=filename, wildcard='All files (*.*)|*.*', style=wx.SAVE) dlg.Raise() result = dlg.ShowModal() dlg.Destroy() if result == wx.ID_OK: path = dlg.GetPath() d2save.save_content(path)
Example #22
Source File: gui.py From report-ng with GNU General Public License v2.0 | 6 votes |
def Save_Report_As(self, e): openFileDialog = wx.FileDialog(self, 'Save Report As', self.save_into_directory, '', 'XML files (*.xml)|*.xml|All files (*.*)|*.*', wx.FD_SAVE | wx.wx.FD_OVERWRITE_PROMPT) if openFileDialog.ShowModal() == wx.ID_CANCEL: return filename = openFileDialog.GetPath() if filename == self.report._template_filename: wx.MessageBox('For safety reasons, template overwriting with generated report is not allowed!', 'Error', wx.OK | wx.ICON_ERROR) return self.status('Generating and saving the report...') self.report.scan = self.scan self._clean_template() #self.report.xml_apply_meta() self.report.xml_apply_meta(vulnparam_highlighting=self.menu_view_v.IsChecked(), truncation=self.menu_view_i.IsChecked(), pPr_annotation=self.menu_view_p.IsChecked()) self.report.save_report_xml(filename) #self._clean_template() # merge kb before generate self.ctrl_tc_k.SetValue('') self.menu_tools_merge_kb_into_content.Enable(False) self.status('Report saved')
Example #23
Source File: meshView.py From laplacian-meshes with GNU General Public License v3.0 | 6 votes |
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
Example #24
Source File: chooser.py From Gooey with MIT License | 5 votes |
def getDialog(self): options = self.Parent._options return wx.FileDialog( self, style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT, defaultFile=options.get('default_file', _("enter_filename")), defaultDir=options.get('default_dir', _('')), message=options.get('message', _('choose_file')), wildcard=options.get('wildcard', wx.FileSelectorDefaultWildcardStr) )
Example #25
Source File: backend_wx.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def save_figure(self, *args): # Fetch the required filename and file type. filetypes, exts, filter_index = self.canvas._get_imagesave_wildcards() default_file = self.canvas.get_default_filename() dlg = wx.FileDialog(self._parent, "Save to file", "", default_file, filetypes, wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) dlg.SetFilterIndex(filter_index) if dlg.ShowModal() == wx.ID_OK: dirname = dlg.GetDirectory() filename = dlg.GetFilename() DEBUG_MSG( 'Save file dir:%s name:%s' % (dirname, filename), 3, self) format = exts[dlg.GetFilterIndex()] basename, ext = os.path.splitext(filename) if ext.startswith('.'): ext = ext[1:] if ext in ('svg', 'pdf', 'ps', 'eps', 'png') and format != ext: # looks like they forgot to set the image type drop # down, going with the extension. warnings.warn( 'extension %s did not match the selected ' 'image type %s; going with %s' % (ext, format, ext), stacklevel=2) format = ext try: self.canvas.figure.savefig( os.path.join(dirname, filename), format=format) except Exception as e: error_msg_wx(str(e))
Example #26
Source File: backend_wx.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def trigger(self, *args): # Fetch the required filename and file type. filetypes, exts, filter_index = self.canvas._get_imagesave_wildcards() default_dir = os.path.expanduser( matplotlib.rcParams['savefig.directory']) default_file = self.canvas.get_default_filename() dlg = wx.FileDialog(self.canvas.GetTopLevelParent(), "Save to file", default_dir, default_file, filetypes, wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) dlg.SetFilterIndex(filter_index) if dlg.ShowModal() != wx.ID_OK: return dirname = dlg.GetDirectory() filename = dlg.GetFilename() DEBUG_MSG('Save file dir:%s name:%s' % (dirname, filename), 3, self) format = exts[dlg.GetFilterIndex()] basename, ext = os.path.splitext(filename) if ext.startswith('.'): ext = ext[1:] if ext in ('svg', 'pdf', 'ps', 'eps', 'png') and format != ext: # looks like they forgot to set the image type drop # down, going with the extension. warnings.warn( 'extension %s did not match the selected ' 'image type %s; going with %s' % (ext, format, ext), stacklevel=2) format = ext if default_dir != "": matplotlib.rcParams['savefig.directory'] = dirname try: self.canvas.figure.savefig( os.path.join(dirname, filename), format=format) except Exception as e: error_msg_wx(str(e))
Example #27
Source File: backend_wx.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def save_figure(self, *args): # Fetch the required filename and file type. filetypes, exts, filter_index = self.canvas._get_imagesave_wildcards() default_file = self.canvas.get_default_filename() dlg = wx.FileDialog(self._parent, "Save to file", "", default_file, filetypes, wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) dlg.SetFilterIndex(filter_index) if dlg.ShowModal() == wx.ID_OK: dirname = dlg.GetDirectory() filename = dlg.GetFilename() DEBUG_MSG( 'Save file dir:%s name:%s' % (dirname, filename), 3, self) format = exts[dlg.GetFilterIndex()] basename, ext = os.path.splitext(filename) if ext.startswith('.'): ext = ext[1:] if ext in ('svg', 'pdf', 'ps', 'eps', 'png') and format != ext: # looks like they forgot to set the image type drop # down, going with the extension. warnings.warn( 'extension %s did not match the selected ' 'image type %s; going with %s' % (ext, format, ext), stacklevel=2) format = ext try: self.canvas.figure.savefig( os.path.join(dirname, filename), format=format) except Exception as e: error_msg_wx(str(e))
Example #28
Source File: GoSyncModel.py From gosync with GNU General Public License v2.0 | 5 votes |
def getCredentialFile(self): # ask for the Credential file and save it in Config directory then return True defDir, defFile = '', '' dlg = wx.FileDialog(None, 'Load Credential File', '~', 'Credentials.json', 'json files (*.json)|*.json', wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) if dlg.ShowModal() == wx.ID_CANCEL: return False try: shutil.copy(dlg.GetPath(), self.credential_file) return True except: return False
Example #29
Source File: ugrid_wx.py From gridded with The Unlicense | 5 votes |
def OnSaveImage(self, event): dlg = wx.FileDialog(self, 'Save a PNG file', ".", '', '*.png', wx.SAVE) if dlg.ShowModal() == wx.ID_OK: filename = dlg.GetPath() self.save_image(filename) dlg.Destroy()
Example #30
Source File: app.py From thotkeeper with BSD 2-Clause "Simplified" License | 5 votes |
def _GetFileDialog(self, title, flags, basename=''): directory = '.' if 'HOME' in os.environ: directory = os.environ['HOME'] if self.conf.data_file is not None: directory = os.path.dirname(self.conf.data_file) return wx.FileDialog(self.frame, title, directory, basename, 'ThotKeeper journal files (*.tkj)|*.tkj', flags)