Dynamically Change Workspace Theme

305 views
Skip to first unread message

PIERRE LABROCHE

unread,
Aug 18, 2022, 4:44:40 AM8/18/22
to Blockly
Hi I wanted to allow users to dynamically change the color of their work space between two themes. However, while it works the first time changing the workspace to one of the themes, it not work a second. Does anyone have any clue what I am doing wrong?

Best,

Pierre Labroche

Code is attached here:
Screen Shot 2022-08-18 at 4.42.32 AM.png
Screen Shot 2022-08-18 at 4.42.44 AM.png

pigeonmaléfique

unread,
Aug 18, 2022, 6:18:28 AM8/18/22
to Blockly
Hi,

Have you any console errors ? Maybe it's the if(theme == theme_2)

I tryed that and I haved and all worked fine : 

Blockly.Themes.whitebg = Blockly.Theme.defineTheme('whitebg', {
  'base': Blockly.Themes.Classic,
   'componentStyles': {
     'workspaceBackgroundColour': '#fff',
     'toolboxBackgroundColour': '#222f3e',
    'flyoutBackgroundColour': '#264653',
    'scrollbarOpacity': 0.3,
   }

});

Blockly.Themes.blackbg = Blockly.Theme.defineTheme('blackbg', {
  'base': Blockly.Themes.Classic,
   'componentStyles': {
     'workspaceBackgroundColour': '#000',
     'toolboxBackgroundColour': '#222f3e',
    'flyoutBackgroundColour': '#264653',
    'scrollbarOpacity': 0.3,
   }

});

var theme = Blockly.Themes.whitebg;
function toogle_wk(){
    if(theme == Blockly.Themes.whitebg){
        console.log("Set black");
        theme = Blockly.Themes.blackbg;
        worklol.setTheme(Blockly.Themes.blackbg);
    } else {
           console.log("Set white");
        theme = Blockly.Themes.whitebg;
                worklol.setTheme(Blockly.Themes.whitebg);

    }
}

var worklol = Blockly.inject('blocklyDiv', {
      toolbox: document.getElementById('toolbox-categories'),
          renderer: 'zelos',
              theme: Blockly.Themes.whitebg,
          });

PIERRE LABROCHE

unread,
Aug 18, 2022, 6:52:09 AM8/18/22
to Blockly
Nope, no errors; I console logged the theme == theme_2 and saw that it was alternating between true and false correctly. So, the function just is not switching between themes for some odd reason. I tried to alter my code to much how you did it even and still the same result
Screen Shot 2022-08-18 at 6.51.32 AM.png

pigeonmaléfique

unread,
Aug 18, 2022, 7:18:35 AM8/18/22
to Blockly

PIERRE LABROCHE

unread,
Aug 18, 2022, 7:26:41 AM8/18/22
to Blockly
Didn't work either :( I really don't get why it's not working

Beka Westberg

unread,
Aug 18, 2022, 11:38:51 AM8/18/22
to blo...@googlegroups.com
Hmm, it looks to me like you're doing everything correctly as well. I would recommend enabling sourcemaps and adding a breakpoint here so you can step through the code and see what it's doing.

Hopefully once we have a bit more information we can get this issue sorted =)
--Beka

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/807cd223-042d-40f9-a5ba-ed0180d8dd85n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages