Skip to content

Commit

Permalink
Merge pull request #3 from arossato/main
Browse files Browse the repository at this point in the history
making diacritics keys configurable
  • Loading branch information
jeremymarch authored Oct 10, 2022
2 parents 8605657 + 6ea3714 commit 9b5f37b
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 70 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The extension is contained in the file hoplitekb.oxt. Download this file from t
To build the extension from source code, clone this repository. Run the build.sh script to build the extension. Install hoplitekb.oxt in LibreOffice as above.

## Use:
Use your usual Greek keyboard to type base letters. Use this extension to add diacritics. After typing a vowel, while holding Control (Command on Mac), press a key 1-9 to toggle on/off diacritics. The 1-9 keys are bound to:
Toggle on the extension by pressing the icon installed in the toolbar. The letters a-z and A-Z will be automatically transliterated into Greek characters. To add diacritics, after typing a vowel, press a key 1-9 to toggle on/off diacritics. The 1-9 keys, by default, are bound to:
1. rough breathing
2. smooth breathing
3. acute
Expand All @@ -36,7 +36,7 @@ Use your usual Greek keyboard to type base letters. Use this extension to add d
8. iota subscript
9. diaeresis

The key bindings can be changed in the file Accelerators.xcu. Then rebuild the extension and reinstall.
The default key bindings can be changed in the extension preferences.

## Options:
The options menu can be accessed on Mac from LibreOffice -> Preferences -> LibreOffice Writer -> Hoplite Keyboard. On Linux and Windows it can be accessed from Tools -> Options -> LibreOffice Writer -> Hoplite Keyboard. On all platforms it can also be accessed from Tools -> Extension Manager; then select the extension and click the Options button.
Expand All @@ -48,6 +48,8 @@ From the options menu you can select the Unicode mode.

There is a detailed discussion of these differences [here](https://apagreekkeys.org/technicalDetails.html).

From the options menu you can also define different key bindings for adding diacritics.

## Why a LibreOffice extension? Why not offer this functionality system-wide?
The Linux, Mac, and Windows operating systems do not provide the keyboard with the information necessary to toggle on/off diacritics. The Hoplite Keyboard started on [iOS](https://github.com/jeremymarch/HopliteKB-iOS) and [Android](https://github.com/jeremymarch/HopliteKB-Android) where this information *is* provided to the keyboard. So for Linux, Mac, and Windows the only way to implement this is inside applications.

Expand Down
73 changes: 73 additions & 0 deletions src/config.xcs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,34 @@
<prop
oor:name="UnicodeMode"
oor:type="xs:string" />

<prop
oor:name="roughKey"
oor:type="xs:string" />
<prop
oor:name="smoothKey"
oor:type="xs:string" />
<prop
oor:name="acuteKey"
oor:type="xs:string" />
<prop
oor:name="graveKey"
oor:type="xs:string" />
<prop
oor:name="circumflexKey"
oor:type="xs:string" />
<prop
oor:name="macronKey"
oor:type="xs:string" />
<prop
oor:name="breveKey"
oor:type="xs:string" />
<prop
oor:name="iotaKey"
oor:type="xs:string" />
<prop
oor:name="diaeresisKey"
oor:type="xs:string" />
<group oor:name="Defaults">
<prop
oor:name="Width"
Expand All @@ -36,6 +64,51 @@
oor:type="xs:string">
<value>Precomposed</value>
</prop>
<prop
oor:name="roughKey"
oor:type="xs:string">
<value>1</value>
</prop>
<prop
oor:name="smoothKey"
oor:type="xs:string">
<value>2</value>
</prop>
<prop
oor:name="acuteKey"
oor:type="xs:string">
<value>3</value>
</prop>
<prop
oor:name="graveKey"
oor:type="xs:string">
<value>4</value>
</prop>
<prop
oor:name="circumflexKey"
oor:type="xs:string">
<value>5</value>
</prop>
<prop
oor:name="macronKey"
oor:type="xs:string">
<value>6</value>
</prop>
<prop
oor:name="breveKey"
oor:type="xs:string">
<value>7</value>
</prop>
<prop
oor:name="iotaKey"
oor:type="xs:string">
<value>8</value>
</prop>
<prop
oor:name="diaeresisKey"
oor:type="xs:string">
<value>9</value>
</prop>
</group>
</group>
</templates>
Expand Down
80 changes: 35 additions & 45 deletions src/dialogs/optionsdialog.xdl
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,40 @@
dlg:withtitlebar="false">
<dlg:styles>
<dlg:style dlg:style-id="0" dlg:font-weight="150"/>
</dlg:styles>
<dlg:bulletinboard>
<!--
<dlg:combobox dlg:id="UnicodeMode" dlg:left="8" dlg:top="63" dlg:width="158" dlg:height="51" dlg:help-text="Unicode Help">
<dlg:menupopup>
<dlg:menuitem dlg:value="Precomposed"/>
<dlg:menuitem dlg:value="Precomposed with PUA"/>
<dlg:menuitem dlg:value="Combining-Only"/>
</dlg:menupopup>
</dlg:combobox>
-->

<dlg:text dlg:id="HKBTitle" dlg:style-id="0" dlg:left="3" dlg:top="3" dlg:width="155" dlg:height="8" dlg:value="Hoplite Polytonic Greek Keyboard Settings"/>

<dlg:titledbox dlg:id="options" dlg:left="3" dlg:top="18" dlg:width="90" dlg:height="50">
<dlg:title dlg:value="Unicode Mode"/>
</dlg:titledbox>

<dlg:radiogroup>
<dlg:radio dlg:id="PrecomposedOption" dlg:tab-index="1" dlg:left="8" dlg:top="23" dlg:width="232" dlg:height="21" dlg:value="Precomposed" dlg:multiline="true" dlg:valign="center" dlg:help-text="Use precomposed unicode characters where possible.">
</dlg:radio>
<dlg:radio dlg:id="PrecomposedPUAOption" dlg:tab-index="2" dlg:left="8" dlg:top="35" dlg:width="232" dlg:height="21" dlg:value="Precomposed with PUA" dlg:multiline="true" dlg:valign="center" dlg:help-text="Use precomposed unicode characters including private use area characters where possible.">
</dlg:radio>
<dlg:radio dlg:id="CombiningOption" dlg:tab-index="3" dlg:left="8" dlg:top="47" dlg:width="232" dlg:height="21" dlg:value="Combining-Only" dlg:multiline="true" dlg:valign="center" dlg:help-text="Use combining characters for diacritics.">
</dlg:radio>
</dlg:radiogroup>


<dlg:titledbox dlg:id="InstructionsBox" dlg:left="3" dlg:top="80" dlg:width="90" dlg:height="122">
<dlg:title dlg:value="Diacritic Keys"/>
</dlg:titledbox>

<dlg:text dlg:id="rough" dlg:left="8" dlg:top="92" dlg:width="232" dlg:height="8" dlg:value="1 - Rough breathing"/>
<dlg:text dlg:id="smooth" dlg:left="8" dlg:top="104" dlg:width="232" dlg:height="8" dlg:value="2 - Smooth breathing"/>
<dlg:text dlg:id="acute" dlg:left="8" dlg:top="116" dlg:width="232" dlg:height="8" dlg:value="3 - Acute"/>
<dlg:text dlg:id="grave" dlg:left="8" dlg:top="128" dlg:width="232" dlg:height="8" dlg:value="4 - Grave"/>
<dlg:text dlg:id="circumflex" dlg:left="8" dlg:top="140" dlg:width="232" dlg:height="8" dlg:value="5 - Circumflex"/>
<dlg:text dlg:id="macron" dlg:left="8" dlg:top="152" dlg:width="232" dlg:height="8" dlg:value="6 - Macron"/>
<dlg:text dlg:id="breve" dlg:left="8" dlg:top="164" dlg:width="232" dlg:height="8" dlg:value="7 - Breve"/>
<dlg:text dlg:id="iota" dlg:left="8" dlg:top="176" dlg:width="232" dlg:height="8" dlg:value="8 - Iota subscript"/>
<dlg:text dlg:id="diaeresis" dlg:left="8" dlg:top="188" dlg:width="232" dlg:height="8" dlg:value="9 - Diaeresis"/>
<!--<dlg:text dlg:id="underdot" dlg:left="8" dlg:top="104" dlg:width="232" dlg:height="8" dlg:value="0"/>-->



</dlg:styles>
<dlg:bulletinboard>
<dlg:text dlg:style-id="0" dlg:id="HKBTitle" dlg:tab-index="0" dlg:left="3" dlg:top="3" dlg:width="155" dlg:height="8" dlg:value="Hoplite Polytonic Greek Keyboard Settings"/>
<dlg:titledbox dlg:id="options" dlg:tab-index="1" dlg:left="3" dlg:top="18" dlg:width="90" dlg:height="50">
<dlg:title dlg:value="Unicode Mode"/>
</dlg:titledbox>
<dlg:radiogroup>
<dlg:radio dlg:id="PrecomposedOption" dlg:tab-index="12" dlg:left="8" dlg:top="23" dlg:width="232" dlg:height="21" dlg:help-text="Use precomposed unicode characters where possible." dlg:value="Precomposed" dlg:valign="center" dlg:multiline="true"/>
<dlg:radio dlg:id="PrecomposedPUAOption" dlg:tab-index="13" dlg:left="8" dlg:top="35" dlg:width="232" dlg:height="21" dlg:help-text="Use precomposed unicode characters including private use area characters where possible." dlg:value="Precomposed with PUA" dlg:valign="center" dlg:multiline="true"/>
<dlg:radio dlg:id="CombiningOption" dlg:tab-index="14" dlg:left="8" dlg:top="47" dlg:width="232" dlg:height="21" dlg:help-text="Use combining characters for diacritics." dlg:value="Combining-Only" dlg:valign="center" dlg:multiline="true"/>
</dlg:radiogroup>
<dlg:titledbox dlg:id="InstructionsBox" dlg:tab-index="2" dlg:left="3" dlg:top="80" dlg:width="90" dlg:height="122">
<dlg:title dlg:value="Diacritic Keys"/>
</dlg:titledbox>
<dlg:text dlg:id="rough" dlg:tab-index="3" dlg:left="16" dlg:top="92" dlg:width="224" dlg:height="8" dlg:value="- Rough breathing"/>
<dlg:text dlg:id="smooth" dlg:tab-index="4" dlg:left="16" dlg:top="104" dlg:width="224" dlg:height="8" dlg:value="- Smooth breathing"/>
<dlg:text dlg:id="acute" dlg:tab-index="5" dlg:left="16" dlg:top="116" dlg:width="224" dlg:height="8" dlg:value="- Acute"/>
<dlg:text dlg:id="grave" dlg:tab-index="6" dlg:left="16" dlg:top="128" dlg:width="226" dlg:height="8" dlg:value="- Grave"/>
<dlg:text dlg:id="circumflex" dlg:tab-index="7" dlg:left="16" dlg:top="140" dlg:width="232" dlg:height="8" dlg:value="- Circumflex"/>
<dlg:text dlg:id="macron" dlg:tab-index="8" dlg:left="16" dlg:top="152" dlg:width="232" dlg:height="8" dlg:value="- Macron"/>
<dlg:text dlg:id="breve" dlg:tab-index="9" dlg:left="16" dlg:top="164" dlg:width="232" dlg:height="8" dlg:value="- Breve"/>
<dlg:text dlg:id="iota" dlg:tab-index="10" dlg:left="16" dlg:top="176" dlg:width="232" dlg:height="8" dlg:value="- Iota subscript"/>
<dlg:text dlg:id="diaeresis" dlg:tab-index="11" dlg:left="16" dlg:top="188" dlg:width="232" dlg:height="8" dlg:value="- Diaeresis"/>
<!--<dlg:text dlg:id="underdot" dlg:left="8" dlg:top="104" dlg:width="232" dlg:height="8" dlg:value="0"/>-->

<dlg:textfield dlg:id="roughKey" dlg:tab-index="15" dlg:left="8" dlg:top="92" dlg:width="7" dlg:height="8" dlg:maxlength="1" dlg:value="1"/>
<dlg:textfield dlg:id="smoothKey" dlg:tab-index="16" dlg:left="8" dlg:top="104" dlg:width="7" dlg:height="8" dlg:maxlength="1" dlg:value="2"/>
<dlg:textfield dlg:id="acuteKey" dlg:tab-index="17" dlg:left="8" dlg:top="116" dlg:width="7" dlg:height="8" dlg:maxlength="1" dlg:value="3"/>
<dlg:textfield dlg:id="graveKey" dlg:tab-index="18" dlg:left="8" dlg:top="128" dlg:width="7" dlg:height="8" dlg:maxlength="1" dlg:value="4"/>
<dlg:textfield dlg:id="circumflexKey" dlg:tab-index="19" dlg:left="8" dlg:top="140" dlg:width="7" dlg:height="8" dlg:maxlength="1" dlg:value="5"/>
<dlg:textfield dlg:id="macronKey" dlg:tab-index="20" dlg:left="8" dlg:top="152" dlg:width="7" dlg:height="8" dlg:maxlength="1" dlg:value="6"/>
<dlg:textfield dlg:id="breveKey" dlg:tab-index="21" dlg:left="8" dlg:top="164" dlg:width="7" dlg:height="8" dlg:maxlength="1" dlg:value="7"/>
<dlg:textfield dlg:id="iotaKey" dlg:tab-index="22" dlg:left="8" dlg:top="176" dlg:width="7" dlg:height="8" dlg:maxlength="1" dlg:value="8"/>
<dlg:textfield dlg:id="diaeresisKey" dlg:tab-index="23" dlg:left="8" dlg:top="188" dlg:width="7" dlg:height="8" dlg:maxlength="1" dlg:value="9"/>
<!--<dlg:textfield dlg:id="debug" dlg:tab-index="24" dlg:left="8" dlg:top="200" dlg:width="230" dlg:height="8" dlg:maxlength="0" dlg:value=""/>-->
</dlg:bulletinboard>
</dlg:window>
53 changes: 39 additions & 14 deletions src/py/hoplitekb.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def insertString(ctx, string):

#set default
vUnicodeMode = hopliteaccent.PRECOMPOSED_MODE
diacriticsKeys = []
def setDiacriticsKeys(val):
global diacriticsKeys
diacriticsKeys = val

def setUnicodeMode(mode):
global vUnicodeMode
Expand Down Expand Up @@ -139,7 +143,9 @@ def setUnicodeMode(mode):
"F": "Φ",
"X": "Χ",
"C": "Ψ",
"V": "Ω"
"V": "Ω",
"?": ";",
";": "·"
}

def transliterate(s):
Expand Down Expand Up @@ -190,7 +196,7 @@ def keyPressed(self, oEvent):
if oEvent.Modifiers != 0 and oEvent.Modifiers != 1:
return False
letter = oEvent.KeyChar.value
if letter.isnumeric():
if letter in diacriticsKeys:
self.parent.toggleDiacritic(letter)
return True
a = transliterate(letter)
Expand All @@ -213,7 +219,6 @@ def __init__(self, ctx):
self.key_handler = KeyHandler(self, self.ctx)

def toggleDiacritic(self, args):

try:
if args is None or len(args) < 1:
return
Expand All @@ -224,23 +229,23 @@ def toggleDiacritic(self, args):
text = doc.Text
cursor = text.createTextCursor()

if args == "3":#"acute":
if args == diacriticsKeys[2]: #"3":#"acute":
diacriticToAdd = hopliteaccent.kACUTE
elif args == "5":#"circumflex":
elif args == diacriticsKeys[4]: #"5":#"circumflex":
diacriticToAdd = hopliteaccent.kCIRCUMFLEX
elif args == "4":#"grave":
elif args == diacriticsKeys[3]: #"4":#"grave":
diacriticToAdd = hopliteaccent.kGRAVE
elif args == "6":#"macron":
elif args == diacriticsKeys[5]: #"6":#"macron":
diacriticToAdd = hopliteaccent.kMACRON
elif args == "1":#"rough":
elif args == diacriticsKeys[0]: #"1":#"rough":
diacriticToAdd = hopliteaccent.kROUGH_BREATHING
elif args == "2":#"smooth":
elif args == diacriticsKeys[1]: #"2":#"smooth":
diacriticToAdd = hopliteaccent.kSMOOTH_BREATHING
elif args == "8":#"iotasub":
elif args == diacriticsKeys[7]: #"8":#"iotasub":
diacriticToAdd = hopliteaccent.kIOTA_SUBSCRIPT
elif args == "9":#"diaeresis":
elif args == diacriticsKeys[8]: #"9":#"diaeresis":
diacriticToAdd = hopliteaccent.kDIAERESIS
elif args == "7":#"breve":
elif args == diacriticsKeys[6]: #"7":#"breve":
diacriticToAdd = hopliteaccent.kBREVE
else:
return
Expand Down Expand Up @@ -343,7 +348,7 @@ def stopkb(self):
ImplementationName,
(ServiceName,),)


# Settings
def initializeOptionsOnce():
ctx = uno.getComponentContext()
Expand All @@ -361,11 +366,31 @@ def initializeOptionsOnce():
else:
setUnicodeMode(0)

def loadDiacriticsKeys():
ctx = uno.getComponentContext()
smgr = ctx.getServiceManager()
readConfig, writeConfig = optionsdialog.createConfigAccessor(ctx, smgr, "/com.philolog.hoplitekb.ExtensionData/Leaves/HKBSettingsNode")
defaults = readConfig("Defaults/Width", "Defaults/Height", "Defaults/UnicodeMode", "Defaults/roughKey", "Defaults/smoothKey", "Defaults/acuteKey", "Defaults/graveKey", "Defaults/circumflexKey", "Defaults/macronKey", "Defaults/breveKey", "Defaults/iotaKey", "Defaults/diaeresisKey")
#set current value
cfgnames = "Width", "Height", "UnicodeMode", "roughKey", "smoothKey", "acuteKey", "graveKey", "circumflexKey", "macronKey", "breveKey", "iotaKey", "diaeresisKey"
maxwidth, maxheight, umode, roughKey, smoothKey, acuteKey, graveKey, circumflexKey, macronKey, breveKey, iotaKey, diaeresisKey = readConfig(*cfgnames)
roughKey = roughKey or defaults[3]
smoothKey = smoothKey or defaults[4]
acuteKey = acuteKey or defaults[5]
graveKey = graveKey or defaults[6]
circumflexKey = circumflexKey or defaults[7]
macronKey = macronKey or defaults[8]
breveKey = breveKey or defaults[9]
iotaKey = iotaKey or defaults[10]
diaeresisKey = diaeresisKey or defaults[11]
setDiacriticsKeys([roughKey, smoothKey, acuteKey, graveKey, circumflexKey, macronKey, breveKey, iotaKey, diaeresisKey])

initializeOptionsOnce()
loadDiacriticsKeys()

IMPLE_NAME = "com.philolog.hoplitekb.OptionsDialog"
SERVICE_NAME = "com.philolog.hoplitekb.OptionsDialog"
def create(ctx, *args):
return optionsdialog.create(ctx, *args, imple_name=IMPLE_NAME, service_name=SERVICE_NAME, on_options_changed=setUnicodeMode)
return optionsdialog.create(ctx, *args, imple_name=IMPLE_NAME, service_name=SERVICE_NAME, on_options_changed=setUnicodeMode, reload_diacritics_keys = loadDiacriticsKeys)

g_ImplementationHelper.addImplementation(create, IMPLE_NAME, (SERVICE_NAME,),)
Loading

0 comments on commit 9b5f37b

Please sign in to comment.