summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaiki Ueno <ueno@unixuser.org>2012-10-30 18:01:13 +0900
committerDaiki Ueno <ueno@unixuser.org>2012-10-31 09:57:45 +0900
commit6c46656de7183f2d5700806e4728dee1b0eb937a (patch)
tree362d1b079c96963c04fce600bc557d78014d001b
parentd4c2802768ef1a6bd4943091ff713bce782f016d (diff)
downloadcaribou-6c46656de7183f2d5700806e4728dee1b0eb937a.tar.gz
Port label string construction code to libcaribou
Move the key label construction code from Antler to libcaribou and also handle the "text" attribute of key. https://bugzilla.gnome.org/show_bug.cgi?id=656175
-rw-r--r--caribou/antler/keyboard_view.py32
-rw-r--r--libcaribou/key-model.vala43
2 files changed, 45 insertions, 30 deletions
diff --git a/caribou/antler/keyboard_view.py b/caribou/antler/keyboard_view.py
index 7b1ab2b..4862ab7 100644
--- a/caribou/antler/keyboard_view.py
+++ b/caribou/antler/keyboard_view.py
@@ -9,25 +9,6 @@ from gi.repository import Caribou
import os
from math import ceil
-PRETTY_LABELS = {
- "BackSpace" : u'\u232b',
- "space" : u' ',
- "Return" : u'\u23ce',
- "Return" : u'\u23ce',
- "Control_L" : u'Ctrl',
- "Control_R" : u'Ctrl',
- "Alt_L" : u'Alt',
- "Alt_R" : u'Alt',
- 'Caribou_Prefs' : u'\u2328',
- 'Caribou_ShiftUp' : u'\u2b06',
- 'Caribou_ShiftDown' : u'\u2b07',
- 'Caribou_Emoticons' : u'\u263a',
- 'Caribou_Symbols' : u'123',
- 'Caribou_Symbols_More' : u'{#*',
- 'Caribou_Alpha' : u'Abc',
- 'Caribou_Repeat' : u'\u267b'
-}
-
class AntlerKey(Gtk.Button):
def __init__(self, key, spacing=0):
GObject.GObject.__init__(self)
@@ -61,17 +42,8 @@ class AntlerKey(Gtk.Button):
self.unset_state_flags(Gtk.StateFlags.INCONSISTENT)
def _get_key_label(self):
- label = self.caribou_key().props.name
- if PRETTY_LABELS.has_key(self.caribou_key().props.name):
- label = PRETTY_LABELS[self.caribou_key().props.name]
- elif self.caribou_key().props.name.startswith('Caribou_'):
- label = self.caribou_key().name.replace('Caribou_', '')
- else:
- unichar = unichr(Gdk.keyval_to_unicode(self.caribou_key().props.keyval))
- if not unichar.isspace() and unichar != u'\x00':
- label = unichar
-
- return "<b>%s</b>" % GLib.markup_escape_text(label.encode('utf-8'))
+ label = self.caribou_key().props.label
+ return "<b>%s</b>" % GLib.markup_escape_text(label)
def _caribou_key_pressed (self, key, _key):
self.set_state_flags(Gtk.StateFlags.ACTIVE, False)
diff --git a/libcaribou/key-model.vala b/libcaribou/key-model.vala
index 4330490..af7b623 100644
--- a/libcaribou/key-model.vala
+++ b/libcaribou/key-model.vala
@@ -22,6 +22,7 @@ namespace Caribou {
public uint keyval { get; private set; }
public string? text { get; private construct set; default = null; }
private uint[] _keyvals = {};
+ public string label { get; private set; default = ""; }
public bool scan_stepping { get; internal set; }
private bool _scan_selected;
@@ -50,6 +51,25 @@ namespace Caribou {
{ null, 0 }
};
+ private const LabelMapEntry label_map[] = {
+ { "BackSpace", "\xe2\x8c\xab" },
+ { "space", " " },
+ { "Return", "\xe2\x8f\x8e" },
+ { "Return", "\xe2\x8f\x8e" },
+ { "Control_L", "Ctrl" },
+ { "Control_R", "Ctrl" },
+ { "Alt_L", "Alt" },
+ { "Alt_R", "Alt" },
+ { "Caribou_Prefs", "\xe2\x8c\xa8" },
+ { "Caribou_ShiftUp", "\xe2\xac\x86" },
+ { "Caribou_ShiftDown", "\xe2\xac\x87" },
+ { "Caribou_Emoticons", "\xe2\x98\xba" },
+ { "Caribou_Symbols", "123" },
+ { "Caribou_Symbols_More", "{#*" },
+ { "Caribou_Alpha", "Abc" },
+ { "Caribou_Repeat", "\xe2\x99\xbb" }
+ };
+
public KeyModel (string name, string? text = null) {
this.name = name;
this.text = text;
@@ -80,6 +100,24 @@ namespace Caribou {
}
}
+ for (i = 0; i < label_map.length; i++) {
+ if (label_map[i].name == name) {
+ label = label_map[i].label;
+ break;
+ }
+ }
+ if (i == label_map.length) {
+ if (text != null)
+ label = text;
+ else if (name.has_prefix ("Caribou_"))
+ label = name["Caribou_".length:name.length];
+ else if (_keyvals.length > 0) {
+ unichar uc = Gdk.keyval_to_unicode (_keyvals[0]);
+ if (!uc.isspace () && uc != 0)
+ label = uc.to_string ();
+ }
+ }
+
xadapter = XAdapter.get_default();
extended_keys = new Gee.ArrayList<KeyModel> ();
}
@@ -175,4 +213,9 @@ namespace Caribou {
string name;
Gdk.ModifierType mask;
}
+
+ private struct LabelMapEntry {
+ string name;
+ string label;
+ }
}