Python wx.FD_OVERWRITE_PROMPT Examples

The following are 26 code examples of wx.FD_OVERWRITE_PROMPT(). 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 vote down vote up
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: score_frame.py    From dials with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def OnSave(self, event):
        dialog = wx.FileDialog(
            self,
            defaultDir="",
            message="Save scores",
            style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT,
            wildcard="Text files (*.txt)|*.txt",
        )
        if dialog.ShowModal() == wx.ID_OK:
            path = dialog.GetPath()
            if path != "":
                stream = open(path, "w")
                for (key, score) in _scores.items():
                    if score is None:
                        print("%s None" % (key), file=stream)
                    else:
                        print("%s %d" % (key, score), file=stream)
                stream.close()
                print("Dumped scores to", path) 
Example #3
Source File: main.py    From wxGlade with MIT License 6 votes vote down vote up
def save_app_as(self):
        "saves a wxGlade project onto an xml file chosen by the user"
        # both flags occurs several times
        fn = wx.FileSelector( _("Save project as..."),
                              wildcard="wxGlade files (*.wxg)|*.wxg|wxGlade Template files (*.wgt) |*.wgt|"
                              "XML files (*.xml)|*.xml|All files|*",
                              flags=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT,
                              default_filename=common.root.filename or (self.cur_dir+os.sep+"wxglade.wxg"))
        if not fn: return

        # check for file extension and add default extension if missing
        ext = os.path.splitext(fn)[1].lower()
        if not ext:
            fn = "%s.wxg" % fn

        common.root.filename = fn
        #remove the template flag so we can save the file.
        common.root.properties["is_template"].set(False)

        self.save_app()
        self.cur_dir = os.path.dirname(fn)
        self.file_history.AddFileToHistory(fn) 
Example #4
Source File: control.py    From atbswp with GNU General Public License v3.0 6 votes vote down vote up
def compile(event):
        """Return a compiled version of the capture currently loaded.

        For now it only returns a bytecode file.
        #TODO: Return a proper executable for the platform currently
        used **Without breaking the current workflow** which works both
        in development mode and in production
        """
        try:
            bytecode_path = py_compile.compile(TMP_PATH)
        except:
            wx.LogError("No capture loaded")
            return
        default_file = "capture.pyc"
        with wx.FileDialog(parent=event.GetEventObject().Parent, message="Save capture executable",
                           defaultDir=os.path.expanduser("~"), defaultFile=default_file, wildcard="*",
                           style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) as fileDialog:

            if fileDialog.ShowModal() == wx.ID_CANCEL:
                return     # the user changed their mind
            pathname = fileDialog.GetPath()
            try:
                shutil.copy(bytecode_path, pathname)
            except IOError:
                wx.LogError(f"Cannot save current data in file {pathname}.") 
Example #5
Source File: backend_wx.py    From Mastering-Elasticsearch-7.0 with MIT License 5 votes vote down vote up
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.canvas.GetParent(),
                            "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.
                _log.warning('extension %s did not match the selected '
                             'image type %s; going with %s',
                             ext, format, ext)
                format = ext
            try:
                self.canvas.figure.savefig(
                    os.path.join(dirname, filename), format=format)
            except Exception as e:
                error_msg_wx(str(e)) 
Example #6
Source File: backend_wx.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
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=0)
            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 #7
Source File: backend_wx.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
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=0)
                format = ext
            try:
                self.canvas.figure.savefig(
                    os.path.join(dirname, filename), format=format)
            except Exception as e:
                error_msg_wx(str(e)) 
Example #8
Source File: relay_board_gui.py    From R421A08-rs485-8ch-relay-board with MIT License 5 votes vote down vote up
def OnSaveAsClick(self, event=None):
        dlg = wx.FileDialog(self, 'Save settings as...', os.getcwd(), '', '*.relay',
                            style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
        if dlg.ShowModal() == wx.ID_OK:
            self.m_settings_file = dlg.GetPath()
            if not self.m_settings_file.endswith('.relay'):
                self.m_settings_file += '.relay'
            self.save_settings(self.m_settings_file)
        dlg.Destroy() 
Example #9
Source File: PluginInstall.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def Export(self, pluginInfo):
        pluginData = self.GetPluginData(pluginInfo)
        #dialog = PluginOverviewDialog(
        #    eg.document.frame,
        #    "Plugin Information",
        #    pluginData=pluginData,
        #    basePath=pluginInfo.path,
        #    message="Do you want to save this plugin as a plugin file?"
        #)
        #result = dialog.ShowModal()
        #dialog.Destroy()
        #if result == wx.ID_CANCEL:
        #    return
        filename = os.path.basename(pluginInfo.path)
        title = eg.text.MainFrame.Menu.Export.replace("&", "").replace(".", "")
        dialog = wx.FileDialog(
            eg.document.frame,
            defaultFile=filename,
            message=title,
            wildcard="EventGhost Plugin (*.egplugin)|*.egplugin",
            style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT
        )
        try:
            result = dialog.ShowModal()
            if result == wx.ID_CANCEL:
                return
            targetPath = dialog.GetPath()
        finally:
            dialog.Destroy()
        self.CreatePluginPackage(pluginInfo.path, targetPath, pluginData) 
Example #10
Source File: backend_wx.py    From CogAlg with MIT License 5 votes vote down vote up
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.canvas.GetParent(),
                            "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.
                _log.warning('extension %s did not match the selected '
                             'image type %s; going with %s',
                             ext, format, ext)
                format = ext
            try:
                self.canvas.figure.savefig(
                    os.path.join(dirname, filename), format=format)
            except Exception as e:
                error_msg_wx(str(e)) 
Example #11
Source File: backend_wx.py    From coffeegrindsize with MIT License 5 votes vote down vote up
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 #12
Source File: backend_wx.py    From coffeegrindsize with MIT License 5 votes vote down vote up
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 #13
Source File: control.py    From atbswp with GNU General Public License v3.0 5 votes vote down vote up
def save_file(self, event):
        """Save the capture currently loaded."""
        with wx.FileDialog(self.parent, "Save capture file", wildcard="*",
                           style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) as fileDialog:

            if fileDialog.ShowModal() == wx.ID_CANCEL:
                return     # the user changed their mind

            # save the current contents in the file
            pathname = fileDialog.GetPath()
            try:
                shutil.copy(TMP_PATH, pathname)
            except IOError:
                wx.LogError(f"Cannot save current data in file {pathname}.") 
Example #14
Source File: i2cgui.py    From i2cdriver with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def check_c(self, e):
        global StopCapture
        cm = e.EventObject.GetValue()
        # self.sd.monitor(self.monitor)
        if cm:
            openFileDialog = wx.FileDialog(self, "CSV dump to file", "", "", 
                  "CSV files (*.csv)|*.csv", 
                         wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
            openFileDialog.ShowModal()
            self.log_csv = openFileDialog.GetPath()
            openFileDialog.Destroy()
            if self.log_csv == u"":
                e.EventObject.SetValue(False)
                return
            StopCapture = False
            self.sd.dumpcount = 0
            t = threading.Thread(target=capture_thr, args=(self.sd, self.log_csv))
            t.setDaemon(True)
            t.start()
        else:
            StopCapture = True
            wx.MessageBox("Capture finished. %d events written to \"%s\"" % (self.sd.dumpcount, self.log_csv), "Message", wx.OK | wx.ICON_INFORMATION)
            while StopCapture:
                pass
        [d.Enable(not cm) for d in self.dynamic]
        if cm:
            [self.hot(i, False) for i in self.heat]
        self.capture = cm 
Example #15
Source File: g.gui.tangible.py    From grass-tangible-landscape with GNU General Public License v2.0 5 votes vote down vote up
def CreateNewFile(self):
        get_lib_path('g.gui.tangible')
        dlg = wx.FileDialog(self, message="Create a new file with analyses",
                            wildcard="Python source (*.py)|*.py",
                            style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
        if dlg.ShowModal() == wx.ID_OK:
            path = dlg.GetPath()
            orig = os.path.join(get_lib_path('g.gui.tangible'), 'current_analyses.py')
            if not os.path.exists(orig):
                self.giface.WriteError("File with analyses not found: {}".format(orig))
            else:
                copyfile(orig, path)
                self.selectAnalyses.SetValue(path)
                self.settings['analyses']['file'] = path
        dlg.Destroy() 
Example #16
Source File: app.py    From thotkeeper with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def _FileArchiveMenu(self, event):
        date = self._QueryChooseDate('Archive files before which date?')
        if date is None:
            return

        path = None
        new_basename = ''
        if self.conf.data_file is not None:
            new_base, new_ext = os.path.splitext(os.path.basename(
                self.conf.data_file))
            if not new_ext:
                new_ext = '.tkj'
            new_basename = new_base + '.archive' + new_ext
        dialog = self._GetFileDialog('Archive to a new data file',
                                     wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT,
                                     new_basename)
        if dialog.ShowModal() == wx.ID_OK:
            path = dialog.GetPath()
        dialog.Destroy()
        if path is None:
            return

        if len(path) < 5 or not path.endswith('.tkj'):
            path = path + '.tkj'
        wx.Yield()
        wx.BeginBusyCursor()
        try:
            self._ArchiveEntriesBeforeDate(path,
                                           date.GetYear(),
                                           date.GetMonth() + 1,
                                           date.GetDay())
        finally:
            wx.EndBusyCursor() 
Example #17
Source File: app.py    From thotkeeper with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def _FileSaveAsMenu(self, event):
        dialog = self._GetFileDialog('Save as a new data file',
                                     wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
        if dialog.ShowModal() == wx.ID_OK:
            path = dialog.GetPath()
            if len(path) < 5 or not path.endswith('.tkj'):
                path = path + '.tkj'
            self._SaveEntriesToPath(path)
        dialog.Destroy() 
Example #18
Source File: app.py    From thotkeeper with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def _FileNewMenu(self, event):
        if self._RefuseUnsavedModifications(True):
            return False
        dialog = self._GetFileDialog("Create new data file",
                                     wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
        if dialog.ShowModal() == wx.ID_OK:
            path = dialog.GetPath()
            if len(path) < 5 or not path.endswith('.tkj'):
                path = path + '.tkj'
            self._SetDataFile(path, True)
        dialog.Destroy() 
Example #19
Source File: toolbox.py    From goreviewpartner with GNU General Public License v3.0 5 votes vote down vote up
def save_all_file(filename, parent, config, filetype):
		initialdir = grp_config.get(config[0],config[1])
		dialog = wx.FileDialog(None,_('Choose a filename'), defaultDir=initialdir,defaultFile=filename, wildcard=filetype[0]+" "+filetype[1], style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
		filename = None
		if dialog.ShowModal() == wx.ID_OK:
			filename = dialog.GetPath()
		dialog.Destroy()
		if filename:
			initialdir=os.path.dirname(filename)
			grp_config.set(config[0],config[1],initialdir)
		return filename 
Example #20
Source File: chooser.py    From Gooey with MIT License 5 votes vote down vote up
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 #21
Source File: chronolapse.py    From chronolapse with MIT License 5 votes vote down vote up
def saveFileBrowser(self, message, defaultFile=''):
        dlg = wx.FileDialog(self, message, defaultFile=defaultFile,
                        style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
        if dlg.ShowModal() == wx.ID_OK:
            path = dlg.GetPath()
        else:
            path = ''
        dlg.Destroy()
        return path 
Example #22
Source File: backend_wx.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #23
Source File: backend_wx.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #24
Source File: backend_wx.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
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 #25
Source File: backend_wx.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
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: calibration_frame.py    From dials with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def OnSaveMetrology(self, event):
        import pycbf

        dialog = wx.FileDialog(
            self,
            defaultDir=os.curdir,
            defaultFile="quadrants.def",
            message="Save metrology file",
            style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT,
            wildcard="Phil files (*.def)|*.def",
        )
        if dialog.ShowModal() == wx.ID_OK:
            path = str(dialog.GetPath())
            if path != "":
                # The detector object of the format instance is adjusted when the quadrant calibration
                # arrows are clicked.  Sync those adjustments to a new cbf handle, drop uneeded categories
                # (categories frame specific but not metrology specific) and write the file.
                frame = self.GetParent().GetParent()
                img = frame.pyslip.tiles.raw_image
                header = img.image_set.get_format_class()(img.full_path)
                header.sync_detector_to_cbf(img.get_detector())
                cbf = header._cbf_handle
                cbf.find_category("array_data")
                cbf.remove_category()
                cbf.find_category("array_structure")
                cbf.remove_category()
                cbf.find_category("array_intensities")
                cbf.remove_category()
                cbf.find_category("diffrn_radiation")
                cbf.remove_category()
                cbf.find_category("diffrn_radiation_wavelength")
                cbf.remove_category()
                cbf.find_category("diffrn_measurement")
                cbf.remove_category()
                cbf.find_category("diffrn_scan")
                cbf.remove_category()
                cbf.find_category("diffrn_scan_frame")
                cbf.remove_category()

                cbf.write_widefile(
                    path,
                    pycbf.CBF,
                    pycbf.MIME_HEADERS | pycbf.MSG_DIGEST | pycbf.PAD_4K,
                    0,
                )

                print("Saved cbf header to", path)