Skip to content

Commit

Permalink
window: add basic voice recognition popup
Browse files Browse the repository at this point in the history
  • Loading branch information
knuxify committed Jul 12, 2022
1 parent 84d51e0 commit 90a72db
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/lapel.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<file>ui/assistant.ui</file>
<file>ui/messageview.ui</file>
<file>ui/pair.ui</file>
<file>ui/popup.ui</file>
<file>ui/preferences.ui</file>
<file>ui/skills.ui</file>
<file>ui/skillview.ui</file>
Expand Down
6 changes: 6 additions & 0 deletions data/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,9 @@
font-weight: bold;
padding: 12px 2em;
}

.assistant-popup {
background: transparent;
border: none;
box-shadow: none;
}
34 changes: 34 additions & 0 deletions data/ui/popup.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="adw" version="1.0"/>
<requires lib="gtk" version="4.0"/>
<template class="AssistantPopup" parent="AdwWindow">
<property name="title" translatable="yes">Speak to the Assistant</property>
<property name="decorated">false</property>

<style>
<class name="assistant-popup"/>
</style>

<child>
<object class="AdwFlap" id="flap">
<property name="vexpand">true</property>
<property name="orientation">vertical</property>
<property name="fold-policy">always</property>
<property name="flap-position">end</property>
<property name="reveal-flap">false</property>

<child>
<object class="GtkBox">
<property name="hexpand">true</property>
<property name="vexpand">true</property>
</object>
</child>

<child type="flap">
<object class="SpeechView"/>
</child>
</object>
</child>
</template>
</interface>
8 changes: 8 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .daemon import start_daemon, get_daemon

from .views.preferences import LapelPreferences
from .views.popup import AssistantPopup
from .window import LapelWindow, AboutDialog

class Application(Adw.Application):
Expand All @@ -28,6 +29,13 @@ def do_activate(self):
start_daemon()
self.daemon = get_daemon()

self.assistant_popup = AssistantPopup(self)

# HACK: without this, showing the window results in:
# gdk_gl_context_make_current() failed
self.assistant_popup.present()
self.assistant_popup.hide()

# Keep running in the background
self.hold()

Expand Down
1 change: 1 addition & 0 deletions src/views/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ lapel_view_sources = [
'__init__.py',
'assistant.py',
'pair.py',
'popup.py',
'preferences.py',
'skills.py',
]
Expand Down
44 changes: 44 additions & 0 deletions src/views/popup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# coding: utf-8
"""
Code for the assistant popup.
"""
from gi.repository import Adw, Gtk
from ..daemon import get_daemon

@Gtk.Template(resource_path='/org/dithernet/lapel/ui/popup.ui')
class AssistantPopup(Adw.Window):
"""Popup window that appears when Mycroft hears its wakeword."""
__gtype_name__ = 'AssistantPopup'

flap = Gtk.Template.Child()

def __init__(self, app):
super().__init__()
self.app = app
self.flap.connect('notify::reveal-progress', self.handle_reveal_progress)
self.daemon = get_daemon()
self.daemon.on('mycroft.mic.listen', self._show)
self.daemon.on('recognizer_loop:record_end', self._hide)

def _show(self, *args):
active_window = self.app.get_active_window()
if active_window and active_window.get_visible():
return

self.set_visible(True)
self.present()
self.fullscreen()
self.flap.set_reveal_flap(True)

def _hide(self, *args):
self.flap.set_reveal_flap(False)

def handle_reveal_progress(self, flap, *args):
progress = flap.get_reveal_progress()
if progress == 0:
self.set_visible(False)
self.daemon.stop_record()

def close(self, *args):
# stub
pass

0 comments on commit 90a72db

Please sign in to comment.