Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Windows/Qt, FileEditor selecting Desktop inserts extra user name #461

Open
timdiller opened this issue Jun 11, 2018 · 3 comments
Open

Comments

@timdiller
Copy link
Contributor

from os.path import expanduser
from traits.api import HasTraits, File, Unicode
from traitsui.api import FileEditor, Item, View

class Foo(HasTraits):
    f = Unicode()
    def _f_default(self):
        return expanduser("~")

view = View(Item('f', editor=FileEditor(), show_label=False),resizable=True)
foo = Foo()
foo.edit_traits(view=view)

Note the default style.
Use the folder icon to open the native directory browser.
capture2
Navigate to the Desktop and choose "Open".
The resulting path has an extra <username> appended after Desktop.
capture3

In [11]: traitsui.__version__
Out[11]: '6.0.0'
In [13]: pyface.__version__
Out[13]: '6.0.0'

PyQt version 4.12-1

@rkern
Copy link
Member

rkern commented Jun 11, 2018

You want the DirectoryEditor instead, I think.

@rkern
Copy link
Member

rkern commented Jun 11, 2018

I think this is sort-of expected/desirable behavior for FileEditor. It is expecting you to specify a filename that may not currently exist (the default is dialog_style='open'; you probably want dialog_style='save' for this use case). It populates the "File name:" field (which is the basename of the eventual complete filename that it returns) with the basename of the old value being edited. Pressing "Open" combines the currently-viewed directory with the basename to construct the new edited value.

Using DirectoryEditor, the edited value is the directory whose contents are being displayed. I think that's the behavior that you wanted in this use case.

@corranwebster
Copy link
Contributor

The extra 'eric' after closing is definitely the correct behaviour based on the appearance of the dialog before closing. Assuming that it displayed C:\Users with directory eric selected when you first open the dialog, then everything is as it should be with the dialog, and the behaviour of remembering eric as you change directories is baked in Windows dialog behaviour that we don't control.

It would be useful to know what it is that you are trying to do (select a directory? open a file? save a file?) as you may want different options and/or editors.

Finally, is there a reason you are using a Unicode instead of a File or Directory trait?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants