Continuous toolbox

501 views
Skip to first unread message

fu6...@gmail.com

unread,
Sep 28, 2022, 2:43:10 PM9/28/22
to Blockly
Hi, group

I want to use ContinuousToolbox plugin in my project. When I dragged the block to left side as shown in the video, the block was deleted and the flyout showed. Any help would be much appreciated.


  var blocklyWorkspace = document.getElementsByClassName("blocklyFlyout");
      for (var f=0;f<blocklyWorkspace.length;f++) {
            blocklyWorkspace[f].addEventListener('dblclick', function(){
                 Blockly.hideChaff();
                 continuousFlyout.setVisible(false);
       });
  }

  function onWorkspaceChanged(event) {
        if (event.type=="create"&&continuousFlyout.isVisible_==true)
              continuousFlyout.setVisible(false);
        else if (event.type=="toolbox_item_select"&&continuousFlyout.isVisible_==false)
              continuousFlyout.setVisible(true);
  }
  workspace.addChangeListener(onWorkspaceChanged);


fu6...
ContinuousToolbox.mp4

Beka Westberg

unread,
Sep 28, 2022, 4:27:15 PM9/28/22
to blo...@googlegroups.com
Hello!

Before I jump in and try to answer this, I just want to clarify: You're trying to use the continuous toolbox, but you want it to close when the user drags a block out (like a normal flyout)?

Best wishes, and thank you for your question!
--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/51ead1e2-03f0-4c05-adc0-2ad857d6a6ban%40googlegroups.com.

fu6...@gmail.com

unread,
Sep 28, 2022, 6:33:11 PM9/28/22
to Blockly
Hi, Beka

Yes. I tried to modify the continuous toolbox like a normal flyout. Is there a solution to do it?
Thank you.

fu6...

bwes...@google.com 在 2022年9月29日 星期四凌晨4:27:15 [UTC+8] 的信中寫道:
Message has been deleted
Message has been deleted

fu6...@gmail.com

unread,
Sep 29, 2022, 12:59:17 AM9/29/22
to Blockly
I do it. But I am not sure if there are bugs. Please help me try it.

Page
https://fustyles.github.io/webduino/LinkIt7697/test_myContinuousToolbox/index.html

Source
https://github.com/fustyles/webduino/tree/master/LinkIt7697/test_myContinuousToolbox

fu6...

fu6...@gmail.com 在 2022年9月29日 星期四上午9:22:58 [UTC+8] 的信中寫道:
Please update the code. 

    function onWorkspaceChanged(event) {
        if ((event.type=="create"||event.type=="click")&&continuousFlyout.isVisible_==true)

            continuousFlyout.setVisible(false);
        else if (event.type=="toolbox_item_select"&&continuousFlyout.isVisible_==false)
            continuousFlyout.setVisible(true);
    }
    workspace.addChangeListener(onWorkspaceChanged);

fu6...@gmail.com 在 2022年9月29日 星期四上午8:41:00 [UTC+8] 的信中寫道:
I set aglobal variable to control the flyout.


var continuousFlyout;
class ContinuousFlyout extends Blockly.VerticalFlyout {

  constructor(workspaceOptions) {
    super(workspaceOptions);
    continuousFlyout = this;
   //etc...
  }
   //etc...
   
}




function start() {

    var media = 'media/';
    workspace = Blockly.inject('blocklyDiv',
        {
            media: media,
            toolbox: document.getElementById('toolbox-categories'),
            zoom:{
                controls: true,
                wheel: false,
                startScale: 1.0,
                maxScale: 3,
                minScale: 0.3,
                scaleSpeed: 1.2
            },
            move: {
                scrollbars: {
                horizontal: true,
                vertical: true
            },
            drag: true,
            wheel: true
            },
            trashcan: true,
            plugins: {
                'flyoutsVerticalToolbox': ContinuousFlyout,
                'toolbox': ContinuousToolbox,    
                'metricsManager': ContinuousMetrics,          
            }

        }
    );

    continuousFlyout.setVisible(false);

    var  flyout   = document.getElementsByClassName("blocklyFlyout");
    for (var f=0;f< flyout.length;f++) {
         flyout[f].addEventListener('dblclick', function(){

              Blockly.hideChaff();
              continuousFlyout.setVisible(false);
        });
    }

    function onWorkspaceChanged(event) {
        if (event.type=="create"&&continuousFlyout.isVisible_==true)
            continuousFlyout.setVisible(false);
        else if (event.type=="toolbox_item_select"&&continuousFlyout.isVisible_==false)
            continuousFlyout.setVisible(true);

    }
    workspace.addChangeListener(onWorkspaceChanged);
   
}



fu6...

fu6...@gmail.com 在 2022年9月29日 星期四清晨6:33:11 [UTC+8] 的信中寫道:
myContinuousToolbox.mp4

fu6...@gmail.com

unread,
Sep 29, 2022, 3:07:35 AM9/29/22
to Blockly
Hi, beka

Something wrong after throwing the block to left side as shown in the video. Any help would be appreciated.

error.PNG

Thank you.
fu6...

fu6...@gmail.com 在 2022年9月29日 星期四中午12:59:17 [UTC+8] 的信中寫道:
error.mp4

Beka Westberg

unread,
Sep 29, 2022, 12:02:05 PM9/29/22
to blo...@googlegroups.com
Hmmm that is weird! Could you post the full stack trace of the error so we can figure out where it's coming from?

Hopefully with a bit more info we can figure out what's happening!

Best wishes,
--Beka

fu6...@gmail.com

unread,
Sep 29, 2022, 11:39:05 PM9/29/22
to Blockly
Hi Beka,

I found it always raised an error when dragging a block from toolbox after deleting a block.
I modified the function below to avoid interruption, but this is not a good solution. 

module$exports$Blockly$WorkspaceSvg.WorkspaceSvg.prototype.getGesture=function(a){var b="mousedown"===a.type||"touchstart"===a.type||"pointerdown"===a.type,c=this.currentGesture_;return c?b&&c.hasStarted()?
(console.warn("Tried to start the same gesture twice."),null,null):c:b?
this.currentGesture_=new module$exports$Blockly$TouchGesture.TouchGesture(a,this):null};module$exports$Blockly$WorkspaceSvg.WorkspaceSvg.prototype.clearGesture=function(){this.currentGesture_=null};

error.PNG




Thank you! You are a kind angel.
fu6...
error.mp4

Beka Westberg

unread,
Sep 30, 2022, 12:34:57 PM9/30/22
to Blockly
Hello again!

I'm sorry but I really don't know what's going on here :/ I tried it out on your demo site, and I tried to dig into it. But without sourcemaps enabled it's difficult to debug a live demo site.

I think it's clear that the gesture isn't getting cleaned up properly (currentGesture_ is still set to an old gesture when it shouldn't be). But why that's happening I don't know :/

If there's anything else I can do to help I'm happy to! But with the current information there's not much to go off of :/

Best wishes,
--Beka

Maribeth Bottorff

unread,
Oct 6, 2022, 6:26:48 PM10/6/22
to Blockly
Hi, I haven't fully dug into the issues you're discussing, but I wanted to mention the Continuous Toolbox is designed to remain open all the time. As such, the ContinuousMetrics class in the plugin recalculates the size of the workspace accordingly. So I think you'd need to change that class if the flyout would be closed again. I hope that gives you another angle to look into debugging this.

Maribeth

fu6...@gmail.com

unread,
Oct 6, 2022, 10:14:57 PM10/6/22
to Blockly
Hi, Beka and  Maribeth~~

Thank you for your kind assistance. I made it, but it needs to modify Blockly.WorkspaceSvg.getGesture function for avoiding interruption. I wiil continue to research this issue. Sorry for my bad English.


Share my code.

Step 1:  ContinuousFlyout.js

class ContinuousFlyout extends Blockly.VerticalFlyout {
    this.autoClose = true;
}

Step 2:  ContinuousMetrics.js

  getViewMetrics(getWorkspaceCoordinates = undefined) {      
      if (toolboxPosition == Blockly.TOOLBOX_AT_TOP || toolboxPosition == Blockly.TOOLBOX_AT_BOTTOM) {

      } else if (toolboxPosition == Blockly.TOOLBOX_AT_LEFT || toolboxPosition == Blockly.TOOLBOX_AT_RIGHT) {
        svgMetrics.width -= toolboxMetrics.width;
      }
  }

  getAbsoluteMetrics() {      
    if (this.workspace_.getToolbox() &&  toolboxPosition == Blockly.TOOLBOX_AT_LEFT) {
        absoluteLeft = toolboxMetrics.width;
    }
  }

Step 3: 

function start() {
    var workspace = Blockly.inject('blocklyDiv',
          {
        media: media,
        //renderer: 'zelos',
        toolbox: toolboxXmlString,

        zoom:{
            controls: true,
            wheel: false,
            startScale: 1.0,
            maxScale: 3,
            minScale: 0.3,
            scaleSpeed: 1.2
        },
        move: {
            scrollbars: {
              horizontal: true,
              vertical: true
            },
            drag: true,
            wheel: true
        },
        trashcan: true,
        plugins: {
          'toolbox': ContinuousToolbox,  
          'flyoutsVerticalToolbox': ContinuousFlyout,
          'metricsManager': ContinuousMetrics,    
     
        }
    });
     
    var continuousFlyout = Blockly.getMainWorkspace().toolbox_.flyout_;
    continuousFlyout.setVisible(false);

     
    var blocklyWorkspace = document.getElementsByClassName("blocklyFlyout");
    for (var f=0;f<blocklyWorkspace.length;f++) {
        blocklyWorkspace[f].addEventListener('dblclick', function(){
            continuousFlyout.setVisible(false);
            Blockly.hideChaff();
        });        
    }      
     
    function onWorkspaceChanged(event) {
        if ((event.type=="create"||event.type=="click"||event.type=="delete")&&continuousFlyout.isVisible_==true) {

            continuousFlyout.setVisible(false);
        }
        else if (event.type=="toolbox_item_select"&&continuousFlyout.isVisible_==false) {
            continuousFlyout.setVisible(true);
        }
        else if (event.type=="toolbox_item_select"&&(!event.newItem)&&continuousFlyout.isVisible_==true) {
            continuousFlyout.setVisible(false);
        }

    }
    workspace.addChangeListener(onWorkspaceChanged);
}

Best wishes
Fu6...
ContinuousToolbox.mp4

fu6...@gmail.com

unread,
Oct 6, 2022, 10:28:46 PM10/6/22
to Blockly
Step 4: blockly.min.js


module$exports$Blockly$WorkspaceSvg.WorkspaceSvg.prototype.getGesture=function(a){var b="mousedown"===a.type||"touchstart"===a.type||"pointerdown"===a.type,c=this.currentGesture_;return c?b&&c.hasStarted()?
(console.warn("Tried to start the same gesture twice."),null,null):c:b?
this.currentGesture_=new module$exports$Blockly$TouchGesture.TouchGesture(a,this):null};module$exports$Blockly$WorkspaceSvg.WorkspaceSvg.prototype.clearGesture=function(){this.currentGesture_=null};


Fu6...
fu6...@gmail.com 在 2022年10月7日 星期五上午10:14:57 [UTC+8] 的信中寫道:

Maribeth Bottorff

unread,
Oct 7, 2022, 4:19:19 PM10/7/22
to Blockly
Is your goal to just create a ContinuousFlyout that can autoclose and open like normal? If so then I think you'd be better off avoiding the events route and just undo the changes to the flyout that we made to keep it open forever. I haven't tested this but what I think you'd need to change:

- Don't use ContinuousMetrics; this is what changes the workspace to not be "under" the flyout, but in your case you want the default behavior. Just don't even register this class I think.
- In ContinuousFlyout, get rid of the changes to the `position` method for the same reason.
- Set `autoClose` to true in ContinuousFlyout constructor

Right now your current approach is a mix of keeping the code that keeps it open but then trying to close it automatically. I don't think you should register the double click event on each block to close the flyout, you should let Blockly handle that. But if you feel you need to keep the event, try using the conditionalBind function: https://developers.google.com/blockly/reference/js/blockly.browserevents_namespace.conditionalbind_1_function.md  instead of registering the browser event handler directly. I suspect that this would solve the "same gesture twice" problem, but I don't know for sure.

Good luck!

Message has been deleted

fu6...@gmail.com

unread,
Oct 16, 2022, 5:03:51 AM10/16/22
to Blockly
Hi, Beka and mari...

After modifying the code as the image shows,  the  gesture  problem has been solved. Where there’s a will, there’s a way. Thank you both.


Step 5: ContinuousToolbox.js
debug.png


I also modified a part of code.

    function onWorkspaceChanged(event) {
        if (
(event.type=="create"||event.type=="click")&&continuousFlyout.isVisible_==true) {

            continuousFlyout.setVisible(false);
        }
        else if (event.type=="toolbox_item_select"&&continuousFlyout.isVisible_==false) {
            continuousFlyout.setVisible(true);
        }
        else if (event.type=="toolbox_item_select"&&(!event.newItem)&&continuousFlyout.isVisible_==true) {
            workspace.toolbox_.clearSelection();
            setTimeout(function(){
                continuousFlyout.setVisible(false);
            }, 10);

        }
    }
    workspace.addChangeListener(onWorkspaceChanged);



Best wishes.
Fu6...
mari...@google.com 在 2022年10月8日 星期六凌晨4:19:19 [UTC+8] 的信中寫道:

fu6...@gmail.com

unread,
May 27, 2023, 12:23:25 AM5/27/23
to Blockly
Hi group:


Example page

ContinuousToolbox.jpg

fu6...

fu6...@gmail.com 在 2022年10月16日 星期日下午5:03:51 [UTC+8] 的信中寫道:

fu6...@gmail.com

unread,
Jun 10, 2024, 10:07:43 AMJun 10
to Blockly
Hi  all,

The Continuous toolbox examples I wrote still generates the error message "Tried to start the same gesture twice" after copying any blocks. Afterward, it may not be possible to drag any blocks from the toolbox. However, after attempting to modify the getGesture function, the issue no longer occurs.  

getGesture(a){
    const b="pointerdown"===a.type,c=this.currentGesture_;
    return c?b&&c.hasStarted()?null:c:b?this.currentGesture_=new Gesture$$module$build$src$core$gesture(a,this):null
}

Hope this helps.

fu6...

fu6...@gmail.com 在 2023年5月27日 星期六中午12:23:25 [UTC+8] 的信中寫道:

Jemal Kemal

unread,
Jun 10, 2024, 11:21:35 AMJun 10
to blo...@googlegroups.com

https://link.in/e6gwUDBv


--
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.
Reply all
Reply to author
Forward
0 new messages