RP Blockly Python is a sophisticated web-based visual programming environment that allows users to create Python code using Google's Blockly library. This project combines Blockly's intuitive drag-and-drop interface with Python code generation, execution, and real-time log viewing, offering a unique development experience for both beginners and experienced programmers.
- Visual programming interface using Google Blockly
- Python code generation from Blockly blocks
- Real-time code execution on a separate Python server
- Live log viewer for Python output
- Custom block support for enhanced functionality
- Ability to add custom Python libraries locally
- Responsive design for various screen sizes
- Node.js (v14 or later recommended)
- Python 3.x
- A modern web browser
- Clone the repository:
git clone https://github.com/timjtchang/rp_blockly_python.git
cd rp_blockly_python
- Install Node.js dependencies:
npm install
- Set up a Python virtual environment (recommended):
python3 -m venv myenv
source myenv/bin/activate # On Windows, use `myenv\Scripts\activate`
- Install Python dependencies:
pip3 install -r requirements.txt
There are two ways to run the application:
Run the following command:
npm run user
This command executes user_start.py
, which automatically:
- Opens the logViewer.html in your default browser
- Starts the Node.js server for Blockly interface
- Launches the Python execution server
- Start the development server:
npm start
- In a separate terminal, start the Python execution server:
node src/logViewer/saveCode.js
- Open
src/logViewer/logViewer.html
in a web browser to view the Python execution logs.
- Open the Blockly interface in your web browser (typically at
http://localhost:8080
when running locally). - Use the drag-and-drop interface to create your Python program using Blockly blocks.
- The generated Python code will be displayed in real-time in the code pane on the right side of the interface.
- Located on the Blockly interface.
- When clicked, it will:
- Download the generated Python code from the Blockly GUI.
- Send the code to the Python execution server.
- Trigger the compilation and execution of the code.
- Display the output in the log viewer.
- Located on the Blockly interface.
- When clicked, it will:
- Send a stop signal to the Python execution server.
- Immediately halt the execution of the current Python program.
Open the log viewer by navigating to src/logViewer/logViewer.html
in your web browser.
- Located on the log viewer interface.
- When clicked, it will:
- Retrieve the most recently saved Python code.
- Send the code to the Python execution server.
- Trigger the compilation and execution of the code.
- Display the output in real-time in the log viewer.
- Located on the log viewer interface.
- When clicked, it will:
- Send a stop signal to the Python execution server.
- Immediately halt the execution of the current Python program.
- Display a "-- STOP --" message in the log viewer.
- Add custom blocks in
src/blocks/
- Modify the toolbox in
src/toolbox.js
- Adjust Python code generation in
src/generators/python.js
- Add custom Python libraries to the local environment for extended functionality
src/
: Source files for the Blockly interfaceblocks/
: Custom block definitionsgenerators/
: Python code generators for blockslogViewer/
: Log viewer componentsgeneratedCode
: Contains the dynamically constructed Python source code generated by the applicationwebpack.config.js
: Webpack configurationpackage.json
: Node.js dependencies and scriptsrequirements.txt
: Python dependenciesuser_start.py
: Script to launch all components of the application
npm start
: Start the development servernpm run build
: Build the project for productionnpm run user
: Run the user start script (executesuser_start.py
)
This project is licensed under the Apache 2.0 License.
This project uses Google's Blockly library.