Skip to content

Commit

Permalink
preferences: add preferences menu
Browse files Browse the repository at this point in the history
  • Loading branch information
knuxify committed Mar 4, 2022
1 parent 30b94cd commit 21fb7cb
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 19 deletions.
1 change: 1 addition & 0 deletions data/lapel.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<file>ui/about.ui</file>
<file>ui/assistant.ui</file>
<file>ui/messageview.ui</file>
<file>ui/preferences.ui</file>
<file>ui/skills.ui</file>
<file>ui/skillview.ui</file>
<file>ui/speechview.ui</file>
Expand Down
15 changes: 15 additions & 0 deletions data/org.dithernet.lapel.gschema.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="lapel">
<schema id="org.dithernet.lapel" path="/org/dithernet/lapel/">
<key name="websocket-address" type="s">
<default>"0.0.0.0"</default>
<summary>Websocket address</summary>
<description>
Websocket address used when connecting to Mycroft.
</description>
</key>

<key name="websocket-port" type="i">
<default>8181</default>
<summary>Websocket port</summary>
<description>
Websocket port used when connecting to Mycroft.
</description>
</key>
</schema>
</schemalist>
52 changes: 52 additions & 0 deletions data/ui/preferences.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<requires lib="libadwaita" version="1.0"/>
<template class="LapelPreferences" parent="AdwPreferencesWindow">
<child>
<object class="AdwPreferencesPage">
<property name="icon_name">preferences-window-layout-symbolic</property>
<property name="title">Assistant</property>

<child>
<object class="AdwPreferencesGroup">
<property name="title" translatable="yes">Connection</property>

<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">Websocket address</property>
<property name="subtitle" translatable="yes">Address and port to use when connecting to Mycroft's websocket. You will need to restart Assistant before the changes take effect.</property>

<child>
<object class="GtkBox">
<property name="valign">center</property>
<style>
<class name="linked"/>
</style>

<child>
<object class="GtkEntry" id="ws_address_entry">
<property name="placeholder-text">0.0.0.0</property>
<signal name="changed" handler="set_address"/>
</object>
</child>

<child>
<object class="GtkEntry" id="ws_port_entry">
<property name="input-purpose">digits</property>
<property name="max-length">5</property>
<property name="max-width-chars">5</property>
<property name="placeholder-text">8181</property>
<signal name="changed" handler="set_port"/>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
</interface>
5 changes: 3 additions & 2 deletions po/POTFILES
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
data/org.dithernet.lapel.desktop.in
data/org.dithernet.lapel.appdata.xml.in
data/org.dithernet.lapel.gschema.xml
data/ui/window.ui
data/ui/assistant.ui
data/ui/preferences.ui
data/ui/window.ui
src/window.py
src/skill.py
src/types/skill.py
48 changes: 36 additions & 12 deletions po/lapel.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: lapel\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-03-01 21:23+0100\n"
"POT-Creation-Date: 2022-03-02 21:20+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -18,41 +18,65 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"

#: data/org.dithernet.lapel.desktop.in:3 data/ui/window.ui:6
#: data/ui/window.ui:38
#: data/ui/window.ui:63
msgid "Assistant"
msgstr ""

#: data/org.dithernet.lapel.appdata.xml.in:7
msgid "Voice assistant GUI based on Mycroft"
msgstr ""

#: data/ui/window.ui:50
msgid "Skills"
#: data/org.dithernet.lapel.gschema.xml:6 data/ui/preferences.ui:17
msgid "Websocket address"
msgstr ""

#: data/ui/window.ui:67
msgid "_Preferences"
#: data/org.dithernet.lapel.gschema.xml:7
msgid "Websocket address used when connecting to Mycroft."
msgstr ""

#: data/ui/window.ui:71
msgid "_About Assistant"
#: data/org.dithernet.lapel.gschema.xml:14
msgid "Websocket port"
msgstr ""

#: data/org.dithernet.lapel.gschema.xml:15
msgid "Websocket port used when connecting to Mycroft."
msgstr ""

#: data/ui/preferences.ui:13
msgid "Connection"
msgstr ""

#: data/ui/preferences.ui:18
msgid "Address and port to use when connecting to Mycroft's websocket."
msgstr ""

#: data/ui/assistant.ui:34
#: data/ui/window.ui:47
msgid "Could Not Connect"
msgstr ""

#: data/ui/assistant.ui:35
#: data/ui/window.ui:48
msgid ""
"Failed to connect to Mycroft websocket. Make sure that Mycroft is running."
msgstr ""

#: data/ui/window.ui:75
msgid "Skills"
msgstr ""

#: data/ui/window.ui:94
msgid "_Preferences"
msgstr ""

#: data/ui/window.ui:98
msgid "_About Assistant"
msgstr ""

#. TRANSLATORS: Shown in the skills menu when no a skill has no provided examples.
#: src/skill.py:170
#: src/types/skill.py:170
msgid "No examples found."
msgstr ""

#. TRANSLATORS: Shown in the skills menu when a skill's information could not be found.
#: src/skill.py:175
#: src/types/skill.py:175
msgid "Skill data not found."
msgstr ""
7 changes: 7 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# coding: utf-8
"""
Provides the configuration variable for setting up Assistant
"""
from gi.repository import Gio

config = Gio.Settings.new('org.dithernet.lapel')
3 changes: 2 additions & 1 deletion src/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from .types.message import LapelMessage
from .types.skill import LapelSkill
from .config import config

daemon = None

Expand All @@ -20,7 +21,7 @@ class MessageBusDaemon:

def __init__(self):
"""Sets up the MessageBus handler."""
self.client = MessageBusClient()
self.client = MessageBusClient(host=config['websocket-address'], port=config['websocket-port'])
self.client.run_in_thread()

self.messages = Gio.ListStore(item_type=LapelMessage)
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ configure_file(

lapel_sources = [
'__init__.py',
'config.py',
'daemon.py',
'window.py'
]
Expand Down
3 changes: 2 additions & 1 deletion src/views/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ moduledir = join_paths(pkgdatadir, 'lapel')
lapel_view_sources = [
'__init__.py',
'assistant.py',
'skills.py'
'preferences.py',
'skills.py',
]

install_data(lapel_view_sources, install_dir: join_paths(moduledir, 'views'))
30 changes: 30 additions & 0 deletions src/views/preferences.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# coding: utf-8
"""
Code for the preferences window.
"""
from gi.repository import Adw, Gtk

from ..config import config

@Gtk.Template(resource_path='/org/dithernet/lapel/ui/preferences.ui')
class LapelPreferences(Adw.PreferencesWindow):
"""Preference window for Assistant."""
__gtype_name__ = 'LapelPreferences'

ws_address_entry = Gtk.Template.Child()
ws_port_entry = Gtk.Template.Child()

def __init__(self):
"""Initializes the preferences."""
super().__init__()

self.ws_address_entry.set_text(config['websocket-address'])
self.ws_port_entry.set_text(str(config['websocket-port']))

@Gtk.Template.Callback()
def set_address(self, entry, *args):
config['websocket-address'] = entry.get_text()

@Gtk.Template.Callback()
def set_port(self, entry, *args):
config['websocket-port'] = int(entry.get_text())
5 changes: 4 additions & 1 deletion src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from .views.assistant import AssistantContent # noqa: F401
from .views.skills import SkillsContent # noqa: F401
from .views.preferences import LapelPreferences
from .daemon import start_daemon, get_daemon

@Gtk.Template(resource_path='/org/dithernet/lapel/ui/window.ui')
Expand Down Expand Up @@ -73,14 +74,16 @@ def do_activate(self):
if not win:
win = LapelWindow(application=self)
self.create_action('about', self.on_about_action)
self.create_action('preferences', self.on_preferences_action)
win.present()

def on_about_action(self, widget, _):
about = AboutDialog(self.props.active_window)
about.present()

def on_preferences_action(self, widget, _):
print('app.preferences action activated')
preferences = LapelPreferences()
preferences.present()

def create_action(self, name, callback):
"""Add an action and connect it to a callback."""
Expand Down
4 changes: 2 additions & 2 deletions src/wrappers/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def add_button(self, answer, label=None):

def do_suggestion(self, button, answer):
"""Sends a message from a suggestion."""
daemon.client.emit(Message('active_skill_request'))
daemon.send_message(answer, reply_to=self.message)
self.daemon.client.emit(Message('active_skill_request'))
self.daemon.send_message(answer, reply_to=self.message)
self.hide_buttons()

def hide_buttons(self, *args):
Expand Down

0 comments on commit 21fb7cb

Please sign in to comment.