Need Help on populating user colors with Stylesheet change.

A forum for research and development of the user interface of FreeCAD
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
turn211
Posts: 162
Joined: Mon Feb 01, 2021 11:37 pm

Need Help on populating user colors with Stylesheet change.

Post by turn211 »

The #1 tech support complaint i get with my ProDark theme is User color clashes that a FreeCAD designer has no control of. Proposing a Designer with a Stylesheet accessible Mod or script that would populate User colors. Any ideas or contributions?
User avatar
chennes
Veteran
Posts: 3914
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Need Help on populating user colors with Stylesheet change.

Post by chennes »

It seems like we need a functionality that is a layer above the stylesheets: something that can operate on a bundled package of QSS stylesheet, user colors preferences, Start page CSS stylesheet, and whatever else constitutes the look-and-feel of the program. So a style author provides this whole package of data, and the user just hits "Apply" and it all gets pushed to where it needs to go. It could be done with a Macro, or baked into the core.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
turn211
Posts: 162
Joined: Mon Feb 01, 2021 11:37 pm

Re: Need Help on populating user colors with Stylesheet change.

Post by turn211 »

chennes wrote: Wed Mar 31, 2021 8:26 pm It seems like we need a functionality that is a layer above the stylesheets: something that can operate on a bundled package of QSS stylesheet, user colors preferences, Start page CSS stylesheet, and whatever else constitutes the look-and-feel of the program. So a style author provides this whole package of data, and the user just hits "Apply" and it all gets pushed to where it needs to go. It could be done with a Macro, or baked into the core.
Exactly! If it is a Macro it shouldn't be hard or burried deeply in menus for the User to access. I was trying to prepopulate User.cfg and System.cfg but doesn't work properly.
User avatar
chennes
Veteran
Posts: 3914
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Need Help on populating user colors with Stylesheet change.

Post by chennes »

Well, rather than a macro, I'd love to see this as a first-class feature in FreeCAD - maybe called something like "Themes", that encompass the QSS, CSS, and user preference colors and fonts in an extensible way.

My thinking is that we use a file format for the themes that is analogous to the main FreeCAD FCStd file format ("*.FCTheme"?): just a zipped directory that contains each of the required components. The QSS and CSS are simple. We'd have to decide on a format for the rest, but probably make it match the user preferences files, maybe with a separate file per mod so it's easy to add new ones as a theme author's time allows. If there is an unrecognized mod in there it's just ignored, and any mod that doesn't have an entry is just left alone. Maybe also have an XML file with some descriptive information about the theme itself (Author, url, contact info, short description, screenshot(s)?) . This gives us some extensibility to add a Theme Manager analogous to the AddOn manager at some point in the future.

Within FreeCAD we could implement this as a "Set Theme..." button in the User Preferences or something along those lines.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Need Help on populating user colors with Stylesheet change.

Post by Kunda1 »

mpetrikas is working on a prototype for altering user.cfg file:
https://github.com/StudioPetrikas/FC_Ve ... eeCAD4K.py
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
chennes
Veteran
Posts: 3914
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Need Help on populating user colors with Stylesheet change.

Post by chennes »

Interesting -- if we are running from within FreeCAD, though, we'd just handle the user preferences using the normal FreeCAD.ParamGet() and FreeCAD.ParamSet() functions, right?
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Need Help on populating user colors with Stylesheet change.

Post by Kunda1 »

chennes wrote: Wed Mar 31, 2021 9:57 pm Interesting -- if we are running from within FreeCAD, though, we'd just handle the user preferences using the normal FreeCAD.ParamGet() and FreeCAD.ParamSet() functions, right?
I reckon he didn't know that but would have used that. If our API was a little bit more reader friendly, 😅

Edit: but it could also be that he didn't intend for it to run only with in FC
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
turn211
Posts: 162
Joined: Mon Feb 01, 2021 11:37 pm

Re: Need Help on populating user colors with Stylesheet change.

Post by turn211 »

chennes wrote: Wed Mar 31, 2021 9:40 pm Well, rather than a macro, I'd love to see this as a first-class feature in FreeCAD - maybe called something like "Themes", that encompass the QSS, CSS, and user preference colors and fonts in an extensible way.

My thinking is that we use a file format for the themes that is analogous to the main FreeCAD FCStd file format ("*.FCTheme"?): just a zipped directory that contains each of the required components. The QSS and CSS are simple. We'd have to decide on a format for the rest, but probably make it match the user preferences files, maybe with a separate file per mod so it's easy to add new ones as a theme author's time allows. If there is an unrecognized mod in there it's just ignored, and any mod that doesn't have an entry is just left alone. Maybe also have an XML file with some descriptive information about the theme itself (Author, url, contact info, short description, screenshot(s)?) . This gives us some extensibility to add a Theme Manager analogous to the AddOn manager at some point in the future.

Within FreeCAD we could implement this as a "Set Theme..." button in the User Preferences or something along those lines.
Good ideas. The .FCTheme zipped folder makes alot of sense. The "Set Theme button" would populate from whatever .FCThemes are currently avaailable. Does FreeCAD.ParamGet() and FreeCAD.ParamSet() allow for changing icons? Cause i know somebody will want to change these.
User avatar
chennes
Veteran
Posts: 3914
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Need Help on populating user colors with Stylesheet change.

Post by chennes »

turn211 wrote: Wed Mar 31, 2021 11:37 pm Does FreeCAD.ParamGet() and FreeCAD.ParamSet() allow for changing icons?
No, those functions are just the programmatic way of accessing user preferences via Python. If changing icons is on the radar we'll need a different way of doing it, and as far as I am aware right now it's not straightforward. I suggest we keep that in mind as a future expansion, but for now focus only on the things that can be changed by users already. I'd at least like to see a way for a theme to declare itself as "light" or "dark" and have the icons adjust as necessary to accommodate, but again I think that's for v2. Or v0.02. Or whatever.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
chennes
Veteran
Posts: 3914
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Need Help on populating user colors with Stylesheet change.

Post by chennes »

Purely technical coding question for the devs reading this: I think it would be a good idea for the package to have some kind of descriptive file in it. I'm thinking it should contain information about the author, the theme's name, etc. Is there a general preference between using XML or JSON for that sort of thing? Obviously XML is pretty heavy-weight for such a simple thing, but FreeCAD already supports XML for its own main file type, so there's no extra library requirement, etc.

I'm thinking of something like:

Code: Select all

<theme themefileversion="1.0">
  <name>Pro Dark</name>
  <author>turn211</author>
  <url>https://github.com/turn211/prodark</url>
  <updated>2021-03-31</updated>
  <description>The greatest theme in the history of FreeCAD themes.</description>
  <type>dark</type>
  <screenshots>
    <image>screenshot1.png</image>
    <image>screenshot2.png</image>
  </screenshots>
  <stylesheet>prodark.qss</stylesheet>
  <components>
    <module name="Part">
      <user_preferences>part_colors.xml</user_preferences>
    </module>
    <module name="Start">
      <user_preferences>start_preferences.xml</user_preferences>
    </module>
  </components>
<theme>
Each one of the user_preference files contains what is in essence a list of preferences entries, typically colors and fonts. The Start CSS stylesheet can also be specified in there, since it's just another user preference. If someday we support things besides setting user preferences, that's supported within the same file format. The reader can be coded to ignore entries it doesn't recognize so we have forwards and backwards compatibility.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
Post Reply