Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Description
Problem
If you write a "standalone" matplotlib application, you often want to show a data file. At the moment there are four ways to open a data file for processing:
- Give the data file on the command line as parameter. (But often you want others to be able just to start the application and then select the data file, as they are used from many GUI programs.)
- Before displaying the matplotlib window, get the datafile with an external file selection dialog, e.g.
pyzenity.GetFilename()
. (This needs another package, most likely using another GUI toolkit.) - Place a
matplotlib.widgets.Button
, which gets the datafile with an external file selection dialog. (See above.) - Place a button on to the toolbar, which calls an external file selection dialog. (See above.)
- 2./3./4. + a custom made file selection dialog with one of the available toolkits. (If started on another platform, the changes are high, that the selected toolkit will not be available.)
None of these solutions are native to the matplotlib window, whereas all underlying toolkits have file selection dialogs readily available. I would like to have a toolbar button, where the user can select a file with the "native" file selection dialog.
Proposed Solution
Define aOpenFileBase
class, similar to:
classOpenFileBase(ToolBase):description='Open a data file'image='openfile'default_keymap=mpl.rcParams['keymap.open']def__init__(self,*args,filetypes=[('All files', ('*.*,))],**kwargs) ...deftrigger(self,sender,event,data=None):# Get file namefilename,filetype= ...self.openfile(filename,filetype)defopenfile(self,filename,filetype):pass
Usage:
importmatplotlibclassOpenDatafile(matplotlib.backend_tools.OpenFileBase):def__init__(self,*args,**kwargs):super().__init__(*args,filetypes=[ ('Data files', ('*.dat','*.cvs')), ('Databases', ('*.sqlite','*.db')), ('All files', (*.*,))],**kwargs)defopenfile(self,filename,filetype):iffiletype=='Data files': ...eliffiletype=='Database': ...else: ...# Load the button into the toolbar...