Commit dda2bd83 by Anwar_N

One-Hand-Mode enabled

parent beb8d517
......@@ -31,6 +31,10 @@ from gi.repository import Pango
#Liblouis
import louis
# For 3 dot system
from threading import Timer
keysyms = IBus
......@@ -89,13 +93,15 @@ class EngineSharadaBraille(IBus.Engine):
self.keycode_map = {}
for key,value in {"dot-1":"1","dot-2":"2","dot-3":"3","dot-4":"4","dot-5":"5",
"dot-6":"6","dot-7":"7","dot-8":"8","punctuation_key":"0","capitol_switch_key":"c",
"letter_deletion_key":"9","abbreviation_key":"a"}.items():
"letter_deletion_key":"9","abbreviation_key":"a","one_hand_skip_key":"o"}.items():
self.keycode_map[int(Config.get('cfg',key))] = value
self.key_to_switch_between_languages = int(Config.get('cfg',"switch_between_languages"))
self.list_switch_key = int(Config.get('cfg',"list_switch_key"))
self.language_iter = int(Config.get('cfg',"default-language"))
self.conventional_braille = int(Config.get('cfg',"conventional-braille"))
self.liblouis_mode = int(Config.get('cfg',"liblouis-mode"))
self.one_hand_mode = int(Config.get('cfg',"one-hand-mode"))
self.one_hand_conversion_delay = int(Config.get('cfg',"one-hand-conversion-delay"))*1/1000;
self.liblouis_table_list = Config.get('cfg',"liblouis-table-list").split(",")
except:
self.checked_languages = ["english-en","hindi-hi"]
......@@ -105,6 +111,8 @@ class EngineSharadaBraille(IBus.Engine):
self.list_switch_key = 56
self.language_iter = 0
self.conventional_braille = False;
self.one_hand_mode = False
self.one_hand_conversion_delay = 0.5
self.liblouis_mode = False;
self.liblouis_table_list = ['unicode.dis','en-us-g2.ctb'];
......@@ -113,6 +121,9 @@ class EngineSharadaBraille(IBus.Engine):
self.conventional_braille_dot_4_pass = False;
self.conventional_braille_dot_3 = False;
#Three dot braille
self.three_dot_pos = 1;
#Braille Iter's
self.braille_letter_map_pos = 0;
......@@ -154,7 +165,6 @@ class EngineSharadaBraille(IBus.Engine):
#Key Release
if not is_press:
ordered_pressed_keys = self.order_pressed_keys(self.pressed_keys);
self.pressed_keys = "";
if (ordered_pressed_keys == "3" and self.conventional_braille):
self.conventional_braille_dot_3 = True;
......@@ -248,6 +258,15 @@ class EngineSharadaBraille(IBus.Engine):
#self.louis_current_typing_word = self.louis_current_typing_word + chr(pressed_dots)
self.__commit_string(chr(pressed_dots))
else:
if (self.one_hand_mode):
if (self.three_dot_pos == 1 and self.pressed_keys != ""):
if (self.pressed_keys == "o"):
self.pressed_keys = "";
self.three_dot_pos = 2;
t = Timer(self.one_hand_conversion_delay, self.three_dot_do_commit)
t.start()
return False
value = self.map[ordered_pressed_keys][self.braille_letter_map_pos]
if (self.capital_switch == 1 or self.capital == 1):
value = value.upper()
......@@ -260,6 +279,7 @@ class EngineSharadaBraille(IBus.Engine):
self.__commit_string(self.map["4"][self.braille_letter_map_pos]);
self.conventional_braille_dot_4_pass = True;
self.braille_letter_map_pos = 1;
self.pressed_keys = "";
return False
......@@ -268,7 +288,13 @@ class EngineSharadaBraille(IBus.Engine):
self.get_surrounding_text()
if keycode in self.keycode_map.keys():
#Store the letters
self.pressed_keys += self.keycode_map[keycode];
if (self.one_hand_mode):
if (self.three_dot_pos == 1):
self.pressed_keys += self.keycode_map[keycode];
else:
self.pressed_keys += str(int(self.keycode_map[keycode])+3);
else:
self.pressed_keys += self.keycode_map[keycode];
return True
else:
if (keyval == keysyms.space):
......@@ -370,7 +396,7 @@ class EngineSharadaBraille(IBus.Engine):
def order_pressed_keys(self,pressed_keys):
ordered = ""
#["g","f","d","s","h","j","k","l","a",";"]
for key in ["1","2","3","4","5","6","7","8","a","c","9","0"]:
for key in ["1","2","3","4","5","6","7","8","a","c","9","0","o"]:
if key in pressed_keys:
ordered += key;
return ordered;
......@@ -379,4 +405,14 @@ class EngineSharadaBraille(IBus.Engine):
self.commit_text(IBus.Text.new_from_string(text))
if (len(text) > 1):
speak(text)
def three_dot_do_commit(self):
print("Commiting and Reverting")
self.three_dot_pos = 1;
ordered_pressed_keys = self.order_pressed_keys(self.pressed_keys);
self.pressed_keys = ""
try:
value = self.map[ordered_pressed_keys][self.braille_letter_map_pos]
self.__commit_string(value);
except:
pass
......@@ -49,19 +49,21 @@ class ibus_sharada_braille_preferences():
self.config = configparser.ConfigParser()
self.default_key_dict = { "dot-1":33,"dot-2":32,"dot-3":31,"dot-4":36,"dot-5":37,"dot-6":38,
"dot-7":44,"dot-8":52,"punctuation_key":39,"capitol_switch_key":34,"letter_deletion_key":35,
"switch_between_languages":119,"list_switch_key":56,"abbreviation_key":30 }
"switch_between_languages":119,"list_switch_key":56,"abbreviation_key":30,"one_hand_skip_key":20 }
try:
self.config.read("{}/isb.cfg".format(home_dir))
self.checked_languages = self.config.get('cfg',"checked_languages").split(",")
self.key_dict = {}
default_language = int(self.config.get('cfg',"default-language"))
one_hand_conversion_delay = int(self.config.get('cfg',"one-hand-conversion-delay"))
liblouis_table_list = self.config.get('cfg',"liblouis-table-list")
print(liblouis_table_list)
for key in self.default_key_dict.keys():
self.key_dict[key] = int(self.config.get('cfg',key))
# The following are for a try only
self.config.get('cfg',"conventional-braille")
self.config.get('cfg',"one-hand-mode")
self.config.get('cfg',"simple-mode")
self.config.get('cfg',"liblouis-mode")
......@@ -76,6 +78,8 @@ class ibus_sharada_braille_preferences():
self.reset_keys_and_shorcuts(None,None)
self.config.set('cfg',"simple-mode",str(0))
self.config.set('cfg',"conventional-braille",str(0))
self.config.set('cfg',"one-hand-mode",str(0))
self.config.set('cfg',"one-hand-conversion-delay",str(500))
self.config.set('cfg',"liblouis-mode",str(0))
self.config.set('cfg',"default-language",str(0))
default_language = 0;
......@@ -133,6 +137,13 @@ class ibus_sharada_braille_preferences():
#set liblouis_table_list entry
self.entry_liblouis_table_list.set_text(liblouis_table_list)
#Set one-hand-mode checkbox
checkbutton_one_hand_mode = self.guibuilder.get_object("checkbutton_one_hand_mode")
checkbutton_one_hand_mode.set_active(int(self.config.get('cfg',"one-hand-mode")))
#Set one-hand-mode conversion delay
scale_one_hand_conversion_delay = self.guibuilder.get_object("scale_one_hand_conversion_delay")
scale_one_hand_conversion_delay.set_value(int(self.config.get('cfg',"one-hand-conversion-delay")))
self.guibuilder.connect_signals(self)
self.window.show()
......@@ -146,6 +157,12 @@ class ibus_sharada_braille_preferences():
def conventional_braille_toggled(self,widget,data=None):
self.config.set('cfg',"conventional-braille",str(int(widget.get_active())))
def one_hand_mode_toggled(self,widget,data=None):
self.config.set('cfg',"one-hand-mode",str(int(widget.get_active())))
def one_hand_conversion_delay_changed(self,widget):
self.config.set('cfg',"one-hand-conversion-delay",str(int(widget.get_value())))
def table_type_changed(self,widget,data=None):
value = int(widget.get_active())
self.config.set('cfg',"liblouis-mode",str(value))
......
......@@ -22,6 +22,13 @@ along with . If not, see <http://www.gnu.org/licenses/>.
<interface>
<requires lib="gtk+" version="3.8"/>
<!-- interface-license-type gplv3 -->
<object class="GtkAdjustment" id="adjustment_one_hand_conversion_delay">
<property name="upper">1000</property>
<property name="value">500</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
<signal name="value-changed" handler="one_hand_conversion_delay_changed" swapped="no"/>
</object>
<object class="GtkListStore" id="liststore1">
<columns>
<!-- column-name Text -->
......@@ -144,6 +151,61 @@ along with . If not, see <http://www.gnu.org/licenses/>.
</packing>
</child>
<child>
<object class="GtkCheckButton" id="checkbutton_one_hand_mode">
<property name="label" translatable="yes">One-Hand-Mode</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="one_hand_mode_toggled" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label22">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">One Hand Conversion Delay </property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">scale_one_hand_conversion_delay</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScale" id="scale_one_hand_conversion_delay">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">adjustment_one_hand_conversion_delay</property>
<property name="round_digits">1</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box4">
<property name="visible">True</property>
<property name="can_focus">False</property>
......@@ -177,7 +239,7 @@ along with . If not, see <http://www.gnu.org/licenses/>.
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="position">4</property>
</packing>
</child>
</object>
......@@ -651,6 +713,31 @@ along with . If not, see <http://www.gnu.org/licenses/>.
<property name="top_attach">7</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="one_hand_skip_key">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">False</property>
<signal name="key-press-event" handler="key_press" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">12</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label21">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">One-Hand-Skip</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">one_hand_skip_key</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">12</property>
</packing>
</child>
</object>
</child>
</object>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment