I’ve been customizing the Override V/G tool, but can’t figure out how to change the colour of the text in the form that pops up. Here’s what I’ve got:
While the color of the text does change to white when moused over, I would like to make the text on the dark buttons white or yellow in the non-mouseover state, i.e. like this:
I assume there’s a property named ‘color’ or ‘text’ or ‘fontcolor’ or something similar that I can set to a colour of my choice, but after reading pyrevit.forms — pyRevit 4.5 documentation I can’t seem to find it.
Hi JP, thanks for your suggestion. Unfortunately, nothing happens The relevant line of code, which works (it makes the background red), is
'1 make RED': {'background': COLOUR_RED},
so I’ve tried each of these variations (one at a time of course!):
'1 make RED': {'background': COLOUR_RED, 'foreground' : COLOUR_WHITE}
'1 make RED': {'background': COLOUR_RED, 'foreground color' : COLOUR_WHITE}
'1 make RED': {'background': COLOUR_RED, 'foregroundcolor' : COLOUR_WHITE}
'1 make RED': {'background': COLOUR_RED, 'color' : COLOUR_WHITE}
'1 make RED': {'background': COLOUR_RED, 'font color' : COLOUR_WHITE}
'1 make RED': {'background': COLOUR_RED, 'fontcolor' : COLOUR_WHITE}
… and none of those has any effect (well, the background is still red, but the text doesn’t change).
I’m assuming this is a PyRevit issue – either a lack of documentation or perhaps the functionality of changing the text colour just isn’t available. If it can’t be done, it’s not a deal-breaker, but I’d just like to know!
Thank you, but I think this is where I have to stop now.
My code tweaking so far has been limited to opening up the script.py file associated with a particular PyRevit function, and editing that. After reading your suggestion I searched my computer for “pyrevit xaml” and found quite a few scripts, then googled those same terms and found a much deeper rabbit hole than I had expected. I’d figured it would be a relatively straightforward matter of looking up the syntax of the parameter I wanted to change, then implementing that.
I may eventually find time to start studying xaml, but for now I’ll have to curtail my PyRevit ambitions…
The original line was <Setter Property="Foreground" Value="{DynamicResource pyRevitDarkerDarkBrush}"/>
and that was preventing overriding the color.
I wasn’t able to figure out how to change the colors for foreground or background within the script, only by modifying the XAML directly. The only script I had that used that command switch is using some complicated dictionaries, so i probably wasn’t doing correct.
The background that you were able to override in the script looks like this <Setter Property="Background" Value="#ffffff"/>
so if you change the dynamic resource on line 17 to match, that may allow you to override as well.
Once I located the CommandSwitchWindow.xaml file, I finally understood what you were referring to And I was able to change the text colour – but only by hardcoding it within the xaml file. For some reason the script.py’s override works for the background but is ignored for the foreground.
So these lines in xaml, by themselves, will make both the text and background cyan:
But if I then try to override those from within the script.py file, with this code:
… then only the background colour actually changes to red, and the foreground stays cyan. And it doesn’t seem to be an uppercase/lowercase issue, as it happens whether I use ‘foreground’ and ‘Foreground’ in my code.
For what it’s worth, I also tried changing the values of “BorderBrush” and “BorderThickness”, which exhibited the same behaviour – i.e. I could hardcode a different value into the xaml (just like ‘Background’ is hardcoded), but trying to change them from within the script.py file wouldn’t work. It’s as if there’s code somewhere else that is enabling the background attribute to be mutable, but not the others
selected_switch = \
forms.CommandSwitchWindow.show(
options.keys(), # this just tailors visual appearance for various of the 'options' listed above;
# any items from the 'options' missing from the following list will simply appear with the default white background
config={'Halftone Selected': {'background': '0xaaaaaa'},
'1 make RED': {'background': COLOUR_RED, 'font color': COLOUR_WHITE},
'2 make YELLOW': {'background': COLOUR_YELLOW},
'3 make GREEN': {'background': COLOUR_GREEN},
'4 make BLUE': {'background': COLOUR_BLUE},
'5 make FUCSIA': {'background': COLOUR_FUCSIA},
'6 LINES red' : {'background' : COLOUR_BLUE_DARK, 'BorderBrush' : COLOUR_FUCSIA, 'BorderThickness' : '3', 'Foreground' : COLOUR_WHITE},
'7 LINES blue' : {'background' : COLOUR_BLUE_MEDIUM},
'8 make EXISTING (grey)': {'background': COLOUR_GREY},
'9 make HALFTONE': {'background': COLOUR_HALFTONE}},
message='Pick Visibility/Graphics override option:'
)
It’s that longest line that I’m experimenting with. If I comment it out, I get this:
If I uncomment it, I get this:
… where you can see that the only part of my script.py code that changed the properties defined in the xaml file is the background.
If you want the entire script.py file let me know.