Giter Site home page Giter Site logo

Comments (7)

dalthviz avatar dalthviz commented on August 15, 2024 1

Hi @Czaki thank you for the feedback! I think that makes sense to improve the situation here with the QFileDialog 👍

Thinking about this, not totally sure but, maybe this is already covered by the wrapper function we have for the QFileDialog at:

qtpy/qtpy/compat.py

Lines 82 to 102 in 1874fba

def _qfiledialog_wrapper(attr, parent=None, caption='', basedir='',
filters='', selectedfilter='', options=None):
if options is None:
options = QFileDialog.Option(0)
func = getattr(QFileDialog, attr)
# Calling QFileDialog static method
if sys.platform == "win32":
# On Windows platforms: redirect standard outputs
_temp1, _temp2 = sys.stdout, sys.stderr
sys.stdout, sys.stderr = None, None
result = func(parent, caption, basedir, filters, selectedfilter, options)
if sys.platform == "win32":
# On Windows platforms: restore standard outputs
sys.stdout, sys.stderr = _temp1, _temp2
output, selectedfilter = result
# Always returns the tuple (output, selectedfilter)
return output, selectedfilter

And the respective functions for the static methods like for example getSaveFileName at:

qtpy/qtpy/compat.py

Lines 129 to 138 in 1874fba

def getsavefilename(parent=None, caption='', basedir='', filters='',
selectedfilter='', options=None):
"""Wrapper around QtGui.QFileDialog.getSaveFileName static method
Returns a tuple (filename, selectedfilter) -- when dialog box is canceled,
returns a tuple of empty strings
Compatible with PyQt >=v4.4 (API #1 and #2) and PySide >=v1.0"""
return _qfiledialog_wrapper('getSaveFileName', parent=parent,
caption=caption, basedir=basedir,
filters=filters, selectedfilter=selectedfilter,
options=options)

?

Let us know if the current wrapper definition helps or if some modification needs to be done and of course happy to see a PR if that is the case!

from qtpy.

Czaki avatar Czaki commented on August 15, 2024 1

This wrapper looks to solve the problem, but I need to figure out the discoverability of this feature as many people may use only Qt/PySide documentation and do not find the compat module.

from qtpy.

ccordoba12 avatar ccordoba12 commented on August 15, 2024 1

I took a quick look to @Czaki's PR and I think it's a good idea because it'd make things consistent between PyQt and PySide.

from qtpy.

dalthviz avatar dalthviz commented on August 15, 2024

That's a good point! Just in case, for the moment we have a very basic reference to the compat module in the README any idea to improve that is appreciated!

from qtpy.

hmaarrfk avatar hmaarrfk commented on August 15, 2024

One aspect in which the provided wrappers are not feature complete is when applications wish to customize the user experience such as with the "history"

napari uses:

dlg = QFileDialog()
hist = get_save_history()
dlg.setHistory(hist)

filename, selected_filter = dlg.getSaveFileName(
    parent=self,
    caption=trans._('Save {msg} layers', msg=msg),
    directory=hist[0],  # home dir by default,
    ....
)

which requires:

  1. The use of the method setHistory
  2. a common interface for directory vs dir

Maybe I am missing one aspect of the compat module, but I didn't see a clear way of getting there from browsing the source of the compat.py module.

from qtpy.

Czaki avatar Czaki commented on August 15, 2024

I have created #433 which may be a proper solution. There are currently no tests so it is marked as a draft but I would like to hear what did you think about this.

from qtpy.

dalthviz avatar dalthviz commented on August 15, 2024

Thanks for the feedback and proposing a solution! To be honest I'm not totally sure what could be the best here 🤔, what do you think @ccordoba12 ?

from qtpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.