How to set openfiledialog extension filter to PropertyFileIncluded property?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

How to set openfiledialog extension filter to PropertyFileIncluded property?

Post by Evgeniy »

How to set an extension filter for the open file dialog that is invoked when the PropertyFileIncluded property is changed?
wmayer
Founder
Posts: 20242
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to set openfiledialog extension filter to PropertyFileIncluded property?

Post by wmayer »

First of all the C++ class PropertyFileIncluded must be extended by a further class member like PropertyFile. This means that the private member

Code: Select all

std::string m_filter
must added and the suitable getter and setter methods

Code: Select all

    void setFilter(const std::string& filter);
    std::string getFilter() const;
Now it's possible to change the filter in C++ but still not in Python. Therefore an option is to "overload" PropertyFileIncluded::setPyObject(). So, this method can be extended by also checking if the passed argument is a dict. If yes, it should check for the key "filter" and if available and the corresponding value is a string assign it to m_filter.

In Python it will be possible to change the filter with:

Code: Select all

feature.FileIncluded = {"filter" : "Svg files (*.svg *.SVG);;All files (*.*)"}
wmayer
Founder
Posts: 20242
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to set openfiledialog extension filter to PropertyFileIncluded property?

Post by wmayer »

git commit 302d3f5b95

As a test to see how it works create a TechDraw page. The created object is called Template and you can change the file filters with:

Code: Select all

App.ActiveDocument.Template.Template={"filter" : "Svg files (*.svg);;All files (*.*)"}
App.ActiveDocument.Template.PageResult={"filter" : "Svg files (*.svg);;All files (*.*)"}
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: How to set openfiledialog extension filter to PropertyFileIncluded property?

Post by Evgeniy »

wmayer wrote: Wed Dec 07, 2022 10:15 am Now it's possible to change the filter in C++ but still not in Python.
I thought there was such a possibility in pure Python after all... As for C++, it is clear that there is such a possibility.
And when will this Feature be available in Python?

I know, It seems to be possible to output a message if the user has selected the wrong file, I saw something like this in the Arch workbench code, but this is not fine...
Last edited by Evgeniy on Wed Dec 07, 2022 1:53 pm, edited 2 times in total.
wmayer
Founder
Posts: 20242
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to set openfiledialog extension filter to PropertyFileIncluded property?

Post by wmayer »

And when will this Feature be available in Python?
git commit 302d3f5b95
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: How to set openfiledialog extension filter to PropertyFileIncluded property?

Post by Evgeniy »

wmayer wrote: Wed Dec 07, 2022 12:00 pm git commit 302d3f5b95
Thanks. Sorry I didn't pay attention to that.
Post Reply