Part 3 was about making DotMorph's wheel feel alive: GPU-drawn sectors, a particle burst when a conversion succeeds, a shake when it fails. It was all silent. And it only spoke English and Arabic.
This last part about DotMorph 2.2 is about giving it a voice: seven short sounds made from nothing but sine waves and noise, and seven new languages. It ends with a bug I only found because I needed a screenshot for this article.
Sounds without samples
I didn't want to download sound packs and track their licences, so every sound is synthesized by a 140-line script in the repo, using only the standard library. Three building blocks are enough:
def env(t: float, attack: float, decay: float) -> float: """Fast attack, exponential decay.""" return (t / attack if t < attack else 1.0) * math.exp(-max(0.0, t - attack) / decay) def tone(seconds, freq, decay, partials=((1, 1.0),), attack=0.004): out = samples(seconds) for i in range(len(out)): t = i / RATE out[i] = env(t, attack, decay) * sum(a * math.sin(2 * math.pi * freq * k * t) for k, a in partials) return out def swoosh(seconds, f0, f1, rising=True): """Band of noise whose brightness sweeps f0 -> f1, with a soft bell-shaped envelope.""" out, lp, hp = samples(seconds), 0.0, 0.0 for i in range(len(out)): x = i / len(out) cutoff = f0 + (f1 - f0) * (x if rising else 1 - x) a = 1 - math.exp(-2 * math.pi * cutoff / RATE) lp += a * (rng.uniform(-1, 1) - lp) # one-pole low-pass: how "bright" the noise is hp += 0.02 * (lp - hp) # remove the rumble out[i] = (lp - hp) * math.sin(math.pi * x) ** 2 return out A tone is a sine with an envelope; extra partials at non-integer ratios (2.76, 5.4) make it ring like a small bell instead of beeping. A swoosh is white noise through a low-pass filter whose cutoff slides up or down: rising sounds like something opening, falling like something folding away.
The rest is composition. The done chime is two bell tones a fifth apart (C6, then G6 90 ms later) plus a few tiny high "sparkles" for the particle burst. The failed thud is a low sine whose pitch drops from 150 to 80 Hz in a quarter of a second. The dock snap is a fast downward zip into a 95 Hz bump, like a magnet.
The script writes WAV with the wave module, and ffmpeg encodes them to Ogg Vorbis. All seven together are 48 KB, and the longest is 0.7 seconds. python packaging/sounds.py regenerates them byte for byte, because the noise generator is seeded.
Playing a sound without Qt Multimedia
The obvious way to play a sound from a Qt app is Qt Multimedia. But it isn't in PySide6-Essentials, which DotMorph depends on. It's in PySide6-Addons, which is hundreds of megabytes and brings its own FFmpeg. That's a lot for seven sounds under a second long.
Every Linux desktop already has a library for exactly this: libcanberra, the event-sound library GNOME uses for its own clicks and alerts. DotMorph already loads librsvg over ctypes (see part 2), so this is the same trick:
def play(self, path: Path, volume_db: float, event: str) -> bool: code = self.lib.ca_context_play( self.ctx, ctypes.c_uint32(1), b"media.filename", os.fsencode(path), b"event.id", f"dotmorph-{event}".encode(), b"media.role", b"event", b"canberra.volume", f"{volume_db:.1f}".encode(), b"canberra.cache-control", b"volatile", None) # the property list ends with NULL return code == 0 ca_context_play() is variadic: key, value, key, value, ending with NULL. Forget the None at the end and libcanberra reads whatever comes next on the stack. The test fake checks for it.
media.role = event matters more than it looks: it tells PipeWire or PulseAudio that this is an alert sound, so your desktop's alert volume applies, not the music volume. The volume slider in DotMorph's settings is a percentage converted to decibels (20 × log10(volume / 100); 50% is −6 dB).
If libcanberra isn't there, DotMorph falls back to pw-play, then paplay, run in the background. If none of them exist, nothing plays. A sound must never break the wheel, so the whole play() is wrapped to return None on any error.
Sounds you can turn off
UI sounds are easy to get wrong, so most of the code is about not playing:
- Settings → Sounds: on/off, volume and a Play test button.
- Hover ticks are off by default. A tick on every sector you pass over is fun for a minute and tiring after that. When you turn them on, they're rate-limited to one every 60 ms.
-
--mutesilences one run of the wheel;DOTMORPH_SOUND=0silences all of them. - GNOME's "event sounds" switch is respected. Plain libcanberra doesn't read it (only its GTK module does), so DotMorph asks
gsettingsitself, and re-checks every 30 seconds so the background daemon notices when you change it. - The half wheel that slides out of the edge dock opens silently. It opens whenever the pointer brushes the screen edge, and a swoosh every time would get old fast.
In QML, every state change calls one function, which does nothing where there's no sound object (in the settings window, or in tests):
function sfx(name) { if (typeof sound !== "undefined" && sound) sound.play(name) } A QML test loads the real wheel with a recording sound object, picks WebP for a PNG, waits for the real conversion and asserts it heard exactly ["click", "chime"], then thud on failure and cancel on cancel. Nothing plays on the test machine.
Nine languages, one JSON file each
DotMorph 2.0 spoke English and Arabic, with the Arabic strings in a Python dict. 2.2 adds German, Spanish, French, Italian, Brazilian Portuguese, Russian and Turkish, so the strings moved to one JSON file per language in src/dotmorph/locales/, with the English text as the key. Anyone can now fix a translation without touching Python.
Text with a number in it has plural forms instead of one string. I wrote about CLDR plural rules in DotScramble, so here's just the Arabic entry for "%1 files", which uses all six forms:
"%1 files": {"zero": "لا ملفات", "one": "ملف واحد", "two": "ملفان", "few": "%1 ملفات", "many": "%1 ملفًا", "other": "%1 ملف"} That's "no files", "one file", "two files" (a dual form, without the number), "3–10 files", "11–99 files" and "100 files". Russian needs one / few / many, French counts 0 as singular. Python picks the form with trn("%1 files", n); QML asks Python for the form through a slot, i18n.plural(n), so the rules live in one place.
The launcher and the software-store listing are translated from the same files: the .desktop entry gets a Comment[de]=, Comment[ru]=… line per language, and the AppStream metainfo a <summary xml:lang="…"> per language, both generated at build time and checked with desktop-file-validate and appstreamcli validate.
Long words in a round menu
A settings window can wrap text. A ring sector can't: a label that's too wide runs into the next sector. German "Komprimieren" is twice as long as "Compress", and Russian is longer still. So each sector computes how much room a horizontal label has at its position, and shrinks the font if the text is wider. A test opened the real wheel in all nine languages and compared every label's width with that room. Green.
Then I rendered the wheel in nine languages for this article:
That's the fixed version. In the first render, three of the nine were wrong: the Spanish category name read "erramientas", Portuguese "erramentas", Russian "нструменты". The first letter was cut off.
Three things the room formula didn't know caused it:
- The label isn't in the middle of the sector. A category sector stacks an icon, the name and "9 options", so the name sits off-centre, where the ring is narrower.
- Hover moves and grows it. The hovered sector slides 7 px outward, and its label grew 14%.
- The open fan sits just outside the inner ring and is drawn on top. So any part of a name that crossed the ring's edge disappeared under the fan.
And the test passed because it checked the label against the same formula. It could never disagree with it.
So the test changed first. It now measures real geometry: for every label in every language, it maps both ends of the text into the wheel's coordinates, with the hover applied, and checks that they're inside the sector's own ring and between its edges:
for x, y in ((0, h / 2), (w, h / 2)): # left and right ends of the text p = text.mapToItem(wheel, QPointF(x, y)) dx, dy = p.x() - cx, p.y() - cy r = math.hypot(dx, dy) if not lo <= r <= hi: problem = f"leaves the ring (r={r:.0f}, ring {r0:.0f}-{r1:.0f})" angle = math.degrees(math.atan2(dx, -dy)) % 360 ... # and inside the sector's angles Run against the 2.2.0 wheel, it fails in six of the nine languages: German, Spanish, French, Italian, Portuguese and Russian, every one with a word long enough. English, Arabic and Turkish pass.
The first version of this test had a bug of its own, and CI found it. The rings lean a few pixels toward the mouse pointer (a small parallax effect from part 3), and the labels lean with them, so a user never sees a difference. But the test took the ring's centre from the sector without that lean, while it measured the labels with it. Under a test runner the pointer sits at (0, 0), so every label looked about 4 px off toward the top-left corner. The fix was to map the centre through the same transforms as the labels:
c = sector.parentItem().mapToItem( wheel, QPointF(sector.property("cx"), sector.property("cy"))) Then the fix for the wheel: instead of a formula, each line of text gets its room by binary search on its real position, at rest and hovered:
function roomAt(dy) { var lo = 0, hi = 600 for (var i = 0; i < 18; i++) { var w = (lo + hi) / 2, ok = true for (var lift = 0; lift <= 1 && ok; lift++) { var rr = s.rMid + 7 * lift, grow = 1 + s.popGrow * lift ok = s.lineFits(rr * Math.cos(s.midRad), rr * Math.sin(s.midRad) + dy * grow, w * grow / 2) } if (ok) lo = w; else hi = w } return lo - 1 } lineFits() checks five points along the line against both ring edges and both sector edges. The inner ring's names also stopped growing on hover: the colour and the lift already show which category is open, and the growth was what pushed them under the fan.
That left a few labels shrinking to 8 px, too small to read. For those, the honest fix was the translation, not the code: Russian "Инструменты" (tools) became "Утилиты", the shorter word Russian software commonly uses, and "Объединить PDF" became "Склеить PDF". Real localizers do this all the time; a translation that doesn't fit isn't a good translation.
The fix is in DotMorph 2.2.1. The lesson I'm keeping: a test that checks code against its own formula only proves the formula agrees with itself. Check the thing the user sees.
Thanks
DotMorph 2.2 started from one GitHub issue asking for transcription, and grew into sounds, nine languages, OCR and size targets. If you use DotMorph in a language it doesn't speak yet, adding one is a JSON file and a pull request: CONTRIBUTING explains the plural forms, and the tests will tell you if a word doesn't fit the wheel.
DotMorph is free and open source: github.com/kareem2099/DotMorph. It's on PyPI (pipx install 'dotmorph[gui]'), as an AppImage, a .deb, and on Arch.



