weihuajiang / WPF-Blockly

A WPF based visual programming editor and execution engine, which support all the code syntax (including module and object oriented programming), and even you can define your own syntax.
https://huaruirobot.com/vp.en.html
MIT License
346 stars 100 forks source link
blockly children-programming scripting scripting-engine visual-programming

WPF-Blockly

This is a visual programming editor like google blocky and scratch, but implemented by WPF and dotnet. Compared with existing tools, the visual script is more like real code, and it has more programming feature. With this tool, you can simply enable your application with a visual code editor and run your visual code.

In the demo, we write a visual code editor, and scratch like editor. ScreenShot You can also download it from windows store

Features

Now following feature was achieved

Besides the programming feature, this tool has following feature

The version in microsoft store achieved following feature

Use Script Editor in your application

Customize the look of your own expression and statement

To write your own expression and statement, you have inherit the Expression or Statement class, re-write Descriptor or BlockDescriptor to customize the look of your class.

The Descriptor for Expression

Some statement has only one line, the display of statement is the same as expression, so you use Descriptor only for Statement. The definition of Descriptor is the same as expression, write nothing in BlockDescriptor.

For some complex statement, like if-else, while statement, these statements have several BlockStatement and several Expression, you have to customize the BlockDescriptor.

For exsample, the if-else statement contains following BlockDescriptor,

  1. if - TextItemDescriptor for if and ExpressionDescriptor for Test
  2. BlockStatementDescriptor for Consequent BlockStatement
  3. else - TextItemDescriptor for else
  4. BlockStatementDescriptor for Alternate BlockStatement

Execution of Expression and Statement

Override ExecuteImpl function, to write execution of your expression and statement. To execute other expression and statement, just call the Execute function. ExecutionEnvironment stores all the value of variable, you can register your variable in environment, before registration, you have to make sue the level of your ExecutionEnvironment, and should your use a new ExecutionEnvironment.

Level of ExecutionEnvironment

Level of ExecutionEnvironment

Completion of expression and statement

There are five completion type, Value, Exception, Break, Continue and Return. The loop statement will handle the break, continue completion, function statement will handle the return completion, try-catch statement will handle exception.

If your execution function, you must return the right completion type, return exception completion when exception happens, otherwise the execution of script will go wrong.

Screenshot

community version ScreenShot ScreenShot store version ScreenShot ScreenShot use COM use Active-X use dll