Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

backend_tools.OpenFileBase(ToolBase)? #20134

Open
@sphh

Description

@sphh

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:

  1. 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.)
  2. 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.)
  3. Place amatplotlib.widgets.Button, which gets the datafile with an external file selection dialog. (See above.)
  4. Place a button on to the toolbar, which calls an external file selection dialog. (See above.)
  5. 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...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp