summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--caribou/antler/keyboard_view.py41
-rw-r--r--libcaribou/Makefile.am3
-rw-r--r--libcaribou/column-model.vala12
-rw-r--r--libcaribou/group-model.vala14
-rw-r--r--libcaribou/ikeyboard-object.vala18
-rw-r--r--libcaribou/key-model.vala13
-rw-r--r--libcaribou/keyboard-model.vala12
-rw-r--r--libcaribou/level-model.vala7
-rw-r--r--libcaribou/row-model.vala6
9 files changed, 93 insertions, 33 deletions
diff --git a/caribou/antler/keyboard_view.py b/caribou/antler/keyboard_view.py
index 385a636..ff77b75 100644
--- a/caribou/antler/keyboard_view.py
+++ b/caribou/antler/keyboard_view.py
@@ -158,39 +158,46 @@ class AntlerLayout(Gtk.HBox):
return col
def _on_scan_cleared (self, level):
- for key in self._active_scan_group:
- self._keys_map[key].set_group_scan_active(False)
+ self._foreach_key(self._active_scan_group,
+ lambda x: x.set_group_scan_active (False))
self._active_scan_group = []
- for key in self._dwelling_scan_group:
- self._keys_map[key].set_dwell_scan(False)
+ self._foreach_key(self._dwelling_scan_group,
+ lambda x: x.set_dwell_scan (False))
self._dwelling_scan_group = []
def _on_active_group_changed(self, level, active_item):
- for key in self._active_scan_group:
- self._keys_map[key].set_group_scan_active(False)
+ self._foreach_key(self._active_scan_group,
+ lambda x: x.set_group_scan_active (False))
if isinstance(active_item, Caribou.KeyModel):
self._active_scan_group = [active_item]
else:
self._active_scan_group = active_item.get_keys()
- for key in self._active_scan_group:
- self._keys_map[key].set_group_scan_active(True)
+ self._foreach_key(self._active_scan_group,
+ lambda x: x.set_group_scan_active (True))
def _on_dwelling_group_changed(self, level, dwell_item):
- for key in self._dwelling_scan_group:
- self._keys_map[key].set_dwell_scan(False)
+ self._foreach_key(self._dwelling_scan_group,
+ lambda x: x.set_dwell_scan (False))
if isinstance(dwell_item, Caribou.KeyModel):
self._dwelling_scan_group = [dwell_item]
else:
self._dwelling_scan_group = dwell_item.get_keys()
- for key in self._dwelling_scan_group:
- self._keys_map[key].set_dwell_scan(True)
+ self._foreach_key(self._dwelling_scan_group,
+ lambda x: x.set_dwell_scan (True))
+
+ def _foreach_key(self, keys, cb):
+ for key in keys:
+ try:
+ cb(self._keys_map[key])
+ except KeyError:
+ continue
def add_row(self, row, row_num=0):
x = 0
@@ -214,15 +221,7 @@ class AntlerLayout(Gtk.HBox):
def load_rows(self, rows):
for row_num, row in enumerate(rows):
- self.add_row([c.get_keys() for c in row.get_columns()], row_num)
-
- def _on_scan_state_changed(self, row, prop, antler_keys):
- if prop.name == "scan-dwelling":
- for key in antler_keys:
- key.set_dwell_scan(row.props.scan_dwelling)
- elif prop.name == "scan-active":
- for key in antler_keys:
- key.set_group_scan_active(row.props.scan_active)
+ self.add_row([c.get_children() for c in row.get_columns()], row_num)
class AntlerKeyboardView(Gtk.Notebook):
def __init__(self):
diff --git a/libcaribou/Makefile.am b/libcaribou/Makefile.am
index 65a4ca5..a329030 100644
--- a/libcaribou/Makefile.am
+++ b/libcaribou/Makefile.am
@@ -43,7 +43,8 @@ libcaribou_la_SOURCES = \
json-deserializer.vala \
iscannable-item.vala \
iscannable-group.vala \
- scannable-group.vala
+ scannable-group.vala \
+ ikeyboard-object.vala
EXTRA_DIST = \
external-libs.vapi \
diff --git a/libcaribou/column-model.vala b/libcaribou/column-model.vala
index ffc5b2f..1707edc 100644
--- a/libcaribou/column-model.vala
+++ b/libcaribou/column-model.vala
@@ -1,5 +1,5 @@
namespace Caribou {
- public class ColumnModel : ScannableGroup, IScannableItem {
+ public class ColumnModel : ScannableGroup, IScannableItem, IKeyboardObject {
public bool scan_stepping { get; set; }
public bool scan_selected { get; set; }
@@ -17,10 +17,6 @@ namespace Caribou {
return keys.get (index);
}
- public KeyModel[] get_keys () {
- return (KeyModel[]) keys.to_array ();
- }
-
public KeyModel first_key () {
return keys.first();
}
@@ -28,5 +24,9 @@ namespace Caribou {
public override IScannableItem[] get_scan_children () {
return (IScannableItem[]) get_keys ();
}
- }
+
+ public IKeyboardObject[] get_children () {
+ return (IKeyboardObject[]) keys.to_array ();
+ }
+ }
}
diff --git a/libcaribou/group-model.vala b/libcaribou/group-model.vala
index 965cb96..1a111ae 100644
--- a/libcaribou/group-model.vala
+++ b/libcaribou/group-model.vala
@@ -1,7 +1,7 @@
using GLib;
namespace Caribou {
- public class GroupModel : GLib.Object {
+ public class GroupModel : Object, IKeyboardObject {
public string active_level { get; private set; }
public string group;
@@ -46,5 +46,17 @@ namespace Caribou {
else
active_level = new_level;
}
+
+ public IKeyboardObject[] get_children () {
+ IKeyboardObject[] children = new IKeyboardObject[levels.size ()];
+ uint i = 0;
+
+ foreach (LevelModel obj in levels.get_values ()) {
+ children[i++] = (IKeyboardObject) obj;
+ }
+
+ return children;
+ }
+
}
} \ No newline at end of file
diff --git a/libcaribou/ikeyboard-object.vala b/libcaribou/ikeyboard-object.vala
new file mode 100644
index 0000000..f227492
--- /dev/null
+++ b/libcaribou/ikeyboard-object.vala
@@ -0,0 +1,18 @@
+namespace Caribou {
+ public interface IKeyboardObject : Object {
+ public abstract IKeyboardObject[] get_children ();
+
+ public signal void key_activated (KeyModel key);
+
+ public virtual KeyModel[] get_keys () {
+ Gee.ArrayList<KeyModel> keys = new Gee.ArrayList<KeyModel> ();
+ foreach (IKeyboardObject obj in get_children ()) {
+ KeyModel[] obj_keys = obj.get_keys();
+ foreach (KeyModel key in obj_keys) {
+ keys.add(key);
+ }
+ }
+ return (KeyModel[]) keys.to_array ();
+ }
+ }
+} \ No newline at end of file
diff --git a/libcaribou/key-model.vala b/libcaribou/key-model.vala
index 49e88aa..e7edb8c 100644
--- a/libcaribou/key-model.vala
+++ b/libcaribou/key-model.vala
@@ -1,7 +1,7 @@
using GLib;
namespace Caribou {
- public class KeyModel : GLib.Object, IScannableItem {
+ public class KeyModel : GLib.Object, IScannableItem, IKeyboardObject {
public double margin_left { get; set; default = 0.0; }
public double width { get; set; default = 1.0; }
public string toggle { get; set; default = ""; }
@@ -84,5 +84,16 @@ namespace Caribou {
public KeyModel[] get_extended_keys () {
return (KeyModel[]) extended_keys.to_array ();
}
+
+ public KeyModel[] get_keys () {
+ Gee.ArrayList<KeyModel> all_keys = new Gee.ArrayList<KeyModel> ();
+ all_keys.add (this);
+ all_keys.add_all (extended_keys);
+ return (KeyModel[]) all_keys.to_array ();
+ }
+
+ public IKeyboardObject[] get_children () {
+ return (IKeyboardObject[]) extended_keys.to_array ();
+ }
}
} \ No newline at end of file
diff --git a/libcaribou/keyboard-model.vala b/libcaribou/keyboard-model.vala
index 3b06c9f..64813f2 100644
--- a/libcaribou/keyboard-model.vala
+++ b/libcaribou/keyboard-model.vala
@@ -1,7 +1,7 @@
using Bus;
namespace Caribou {
- public class KeyboardModel : Object {
+ public class KeyboardModel : Object, IKeyboardObject {
public string active_group { get; private set; default = ""; }
public string keyboard_type { get; construct; }
@@ -54,5 +54,15 @@ namespace Caribou {
}
}
+ public IKeyboardObject[] get_children () {
+ IKeyboardObject[] children = new IKeyboardObject[groups.size ()];
+ uint i = 0;
+
+ foreach (GroupModel obj in groups.get_values ()) {
+ children[i++] = (IKeyboardObject) obj;
+ }
+
+ return children;
+ }
}
} \ No newline at end of file
diff --git a/libcaribou/level-model.vala b/libcaribou/level-model.vala
index 65db469..127e5d9 100644
--- a/libcaribou/level-model.vala
+++ b/libcaribou/level-model.vala
@@ -1,7 +1,7 @@
using GLib;
namespace Caribou {
- public class LevelModel : ScannableGroup {
+ public class LevelModel : ScannableGroup, IKeyboardObject {
public signal void level_toggled (string new_level);
public string mode { get; private set; default = ""; }
@@ -60,5 +60,10 @@ namespace Caribou {
else
return (IScannableItem[]) rows.to_array ();
}
+
+ public IKeyboardObject[] get_children () {
+ return (IKeyboardObject[]) get_rows ();
+ }
+
}
}
diff --git a/libcaribou/row-model.vala b/libcaribou/row-model.vala
index 3774519..8387689 100644
--- a/libcaribou/row-model.vala
+++ b/libcaribou/row-model.vala
@@ -1,5 +1,5 @@
namespace Caribou {
- public class RowModel : ScannableGroup, IScannableItem {
+ public class RowModel : ScannableGroup, IScannableItem, IKeyboardObject {
public bool scan_stepping { get; set; }
public bool scan_selected { get; set; }
@@ -47,5 +47,9 @@ namespace Caribou {
else
return (IScannableItem[]) columns.to_array ();
}
+
+ public IKeyboardObject[] get_children () {
+ return (IKeyboardObject[]) get_columns ();
+ }
}
}