Colours

Mike Bray (Quote Loader Author)'s Avatar

Mike Bray (Quote Loader Author)

21 Feb, 2022 03:17 PM

What is the best way to get hold of the current colour theme and colours? I want to use the same colours.

  1. 1 Posted by Stuart Beesley ... on 21 Feb, 2022 05:08 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    MD_REF needs to be set to the moneydance context

    currentTheme = MD_REF.getUI().getCurrentTheme()
    id = currentTheme.getThemeID()
    if currentTheme.isSystemDark() then xxx

    examples:
    RED:
    MD_REF.getUI().getColors().errorMessageForeground

    BLUE:
    MD_REF.getUI().getColors().defaultTextForeground

    Dark Green:
    MD_REF.getUI().getColors().budgetHealthyColor

    Refer:
    com.moneydance.apps.md.view.gui.MDColors

    Hope this helps? If not shout, with what else you need?

  2. 2 Posted by Mike Bray (Quot... on 23 Feb, 2022 08:24 AM

    Mike Bray (Quote Loader Author)'s Avatar

    Thanks Stuart, I have always had problems with getting the context. Once you have it you can navigate the data. How do you get the context?

  3. 3 Posted by Mike Bray (Quot... on 23 Feb, 2022 08:48 AM

    Mike Bray (Quote Loader Author)'s Avatar

    Found it, the FeatureContext passed is an Main object which contains the ui but this is null until you invoke the extension. Once invoked you can get hold of the UI and then get hold of the colors.

  4. Support Staff 4 Posted by Sean Reilly on 23 Feb, 2022 09:09 AM

    Sean Reilly's Avatar

    There's a singleton for the MDColors class which you're welcome to use:
    'colors = com.moneydance.apps.md.view.gui.MDColors.getSingleton()'

    The colors object has all of the different colors in use as public members. If the color theme changes then those members are updated with the new values.

    Cheers,
    Sean

    --
    Sean Reilly
    Developer, The Infinite Kind
    https://infinitekind.com

  5. 5 Posted by Mike Bray (Quot... on 23 Feb, 2022 11:22 AM

    Mike Bray (Quote Loader Author)'s Avatar

    You can get to the colors by casting the context and ui to the appropriate class.

    The code is:

         com.moneydance.apps.md.controller.Main mdContext = (com.moneydance.apps.md.controller.Main) context;
            MoneydanceGUI ui = (MoneydanceGUI)mdContext.getUI();
            MDColors defaults = ui.getColors();
    
    This must be done after the extension is 'invoked'. The ui us null when the extension is intialized.
  6. 6 Posted by Mike Bray (Quot... on 23 Feb, 2022 11:24 AM

    Mike Bray (Quote Loader Author)'s Avatar

    Thanks Sean for the pointer.

  7. Support Staff 7 Posted by Sean Reilly on 23 Feb, 2022 11:26 AM

    Sean Reilly's Avatar

    If you use the MDColors.getSingleton() call you don't need the UI or even the extension context. In general you should access the colors when you are showing the UI, not during extension initialisation. The MDColors object will always be the same object, but the color properties will change as the app is running. So it's a good idea to get the colors at the point where you are creating the UI, not in the extension initialisation.

    Cheers,
    Sean

    --
    Sean Reilly
    Developer, The Infinite Kind
    https://infinitekind.com

  8. 8 Posted by Mike Bray (Quot... on 23 Feb, 2022 11:48 AM

    Mike Bray (Quote Loader Author)'s Avatar

    Is there a listener for changing the theme/preferences so I know when the colours have changed?

    Sent from Mail for Windows

  9. 9 Posted by Stuart Beesley ... on 23 Feb, 2022 12:07 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    from com.moneydance.apps.md.controller import PreferencesListener

    Method preferencesUpdated()

  10. 10 Posted by Stuart Beesley ... on 23 Feb, 2022 12:38 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    Within .preferencesUpdated() you can then do this...

    newThemeID = prefs.getSetting("gui.current_theme", ThemeInfo.DEFAULT_THEME_ID)
    if self.themeID and self.themeID != newThemeID:
       do something
    
  11. System closed this discussion on 25 May, 2022 12:40 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac