popsicle
Popsicle is a project that aims to give JUCE (https://juce.com/) a broader audience by allowing it to be used from python. Thanks to cppyy (http://cppyy.readthedocs.io/en/latest/) it exposes the JUCE framework api in a pythonic way, and the way it enables to write apps in python is very much similar to the way of writing them in C++ but without the overweight of managing project build, configurations and IDE solutions.
Features
- Easy and quick to iterate over a JUCE application, no need to setup a build environment.
- The way it allows to write JUCE code is very similar to how you would write it in C++.
- It allows to mix Python and C++, and even compile C++ code at runtime when needed.
- It is fast, and when the speed of C++ is required, it is possible to write those parts in C++ directly.
Example usage
A single 80 lines script is better than thousand of words:
from popsicle import juce_gui_basics
from popsicle import juce, juce_multi, START_JUCE_APPLICATION
class MainContentComponent(juce_multi(juce.Component, juce.Timer)):
def __init__(self):
super().__init__((), ())
self.setSize(600, 400)
self.startTimerHz(60)
def __del__(self):
self.stopTimer()
def paint(self, g):
g.fillAll(juce.Colours.black)
random = juce.Random.getSystemRandom()
rect = juce.Rectangle[int](0, 0, 20, 20)
for _ in range(100):
g.setColour(juce.Colour(
random.nextInt(256),
random.nextInt(256),
random.nextInt(256)))
rect.setCentre(random.nextInt(self.getWidth()), random.nextInt(self.getHeight()))
g.drawRect(rect)
def timerCallback(self):
if self.isVisible():
self.repaint()
class MainWindow(juce.DocumentWindow):
component = None
def __init__(self):
super().__init__(
juce.JUCEApplication.getInstance().getApplicationName(),
juce.Desktop.getInstance().getDefaultLookAndFeel()
.findColour(juce.ResizableWindow.backgroundColourId),
juce.DocumentWindow.allButtons,
True)
self.component = MainContentComponent()
self.setResizable(True, True)
self.setContentNonOwned(self.component, True)
self.centreWithSize(800, 600)
self.setVisible(True)
def __del__(self):
if hasattr(self, "component"):
self.component.__del__()
self.component = None
def closeButtonPressed(self):
juce.JUCEApplication.getInstance().systemRequestedQuit()
class Application(juce.JUCEApplication):
window = None
def getApplicationName(self):
return "JUCE-o-matic"
def getApplicationVersion(self):
return "1.0"
def initialise(self, commandLine):
self.window = MainWindow()
def shutdown(self):
if hasattr(self, "window"):
self.window.__del__()
self.window = None
if __name__ == "__main__":
START_JUCE_APPLICATION(Application)
As easy as that ! You will find more example on JUCE usage in the examples folder.
Example Applications
Some images of JUCE tutorials and other small apps ported to popsicle.
Animated Component (https://docs.juce.com/master/tutorial_animation.html)
Audio Player with waveforms (https://docs.juce.com/master/tutorial_audio_thumbnail.html)
Slider decibels (https://docs.juce.com/master/tutorial_synth_db_level_control.html)
Slider values example (https://docs.juce.com/master/tutorial_slider_values.html)
Wavetable oscillator (https://docs.juce.com/master/tutorial_wavetable_synth.html)
Responsive GUI layouts using FlexBox and Grid (https://docs.juce.com/master/tutorial_flex_box_grid.html)
Advanced GUI layout techniques (https://docs.juce.com/master/tutorial_rectangle_advanced.html)
Table listbox (https://docs.juce.com/master/tutorial_table_list_box.html)
Super Simple Animated Graphics
Installation
Installing popsicle is as easy as pulling from pypi (osx only for now):
pip3 install popsicle
Make sure you have a recent pip if you are on BigSur intel.
Build From Source
Clone the repository recursively as JUCE is a submodule
git clone --recursive [email protected]:kunitoki/popsicle.git
Install python dependencies.
pip3 install "cppyy>=2.3.1"
Then it's possible to package a wheel and install it (currently this is only tested on macOS and Linux):
# Cleanup the temporary folders
python3 setup.py clean --all
# Build the binary distribution
python3 setup.py bdist_wheel
# Install the local wheel
pip3 install dist/popsicle-*.whl
Eventually uploading to PyPI:
python3 -m twine upload --repository popsicle dist/popsicle-*.whl