Skip to content

Commit

Permalink
fixed using input method on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
eliranwong committed Nov 19, 2024
1 parent 65312f4 commit 2e1321d
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 121 deletions.
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This single project has two major interfaces:

Qt-based Multi-Window Desktop Application:

<b>Tested in:</b> <a href="https://github.com/eliranwong/UniqueBible/wiki/Install-on-Windows">Windows 10</a>, <a href="https://github.com/eliranwong/wsl2/blob/master/bible_apps/desktop.md">Windows WSL2</a>, <a href="https://github.com/eliranwong/UniqueBible/wiki/Install-on-macOS">macOS [Sierra+]</a> and <a href="https://github.com/eliranwong/UniqueBible/wiki/Install-on-Linux">Linux</a> (Arch, Debian, Ubuntu & Mint), <a href="https://github.com/eliranwong/UniqueBible/wiki/Install-on-Chrome-OS">Chrome OS</a> (Debian 10), <a href="https://github.com/eliranwong/UniqueBible/wiki/Webtop-Version---RECOMMENDED!">Webtops</a>, <a href="https://github.com/eliranwong/UniqueBible/wiki/Android-iOS-Version">Android / iOS</a>
<b>Tested in:</b> <a href="https://github.com/eliranwong/UniqueBible/wiki/Install-on-Windows">Windows 10</a>, <a href="https://github.com/eliranwong/wsl2/blob/master/bible_apps/desktop.md">Windows WSL2</a>, <a href="https://github.com/eliranwong/UniqueBible/wiki/Install-on-macOS">macOS [Sierra+]</a> and <a href="https://github.com/eliranwong/UniqueBible/wiki/Install-on-Linux">Linux</a> (Arch, Debian, Ubuntu & Mint), <a href="https://github.com/eliranwong/UniqueBible/wiki/Install-on-Chrome-OS">Chrome OS</a> (Debian 10), <a href="https://github.com/eliranwong/UniqueBible/wiki/Android-iOS-Version">Android / iOS</a>

Unique Bible App can <a href="https://github.com/eliranwong/UniqueBible/wiki/UBA-Run-Modes">runs in different modes</a>, both online and offline, for examples:

Expand All @@ -38,23 +38,19 @@ Oliver Tseng (https://github.com/otseng)

# Quick Start

('git' and 'python 3.7+' are required)
Python 3.8+ required!

To download and set up Unique Bible app, run:
To install:

> git clone https://github.com/eliranwong/UniqueBible.git
> pip install uniquebible
> cd UniqueBible
To run GUI mode:

> python3 uba.py
> uniquebible
# Setup or Installation
More about installation at https://github.com/eliranwong/UniqueBible/wiki/Installation

Read our recommendations first at: https://github.com/eliranwong/UniqueBible/wiki/Recommendations-for-Different-Platforms

You can simply download & run UBA if you have python in place, read our examples at:

https://github.com/eliranwong/UniqueBible/wiki/Installation
More about running modes at https://github.com/eliranwong/UniqueBible/wiki/UBA-Run-Modes

# Features, instructions and how-tos

Expand Down
2 changes: 1 addition & 1 deletion docker_setup/uniquebible/Dockerfile_ubhttp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RUN \
python3 -m venv uba && \
. uba/bin/activate && \
pip install --upgrade pip && \
pip install --upgrade --no-cache-dir uniquebible==0.1.96
pip install --upgrade --no-cache-dir uniquebible==0.1.98
# Run stream mode once to set up UniqueBible App for non-gui modes
RUN \
. uba/bin/activate && \
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
# https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/
setup(
name=package,
version="0.1.96",
version="0.1.98",
python_requires=">=3.8, <3.13",
description=f"UniqueBible App is a cross-platform & offline bible application, integrated with high-quality resources and unique features. Developers: Eliran Wong and Oliver Tseng",
long_description=long_description,
Expand Down
20 changes: 8 additions & 12 deletions uniquebible/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This single project has two major interfaces:

Qt-based Multi-Window Desktop Application:

<b>Tested in:</b> <a href="https://github.com/eliranwong/UniqueBible/wiki/Install-on-Windows">Windows 10</a>, <a href="https://github.com/eliranwong/wsl2/blob/master/bible_apps/desktop.md">Windows WSL2</a>, <a href="https://github.com/eliranwong/UniqueBible/wiki/Install-on-macOS">macOS [Sierra+]</a> and <a href="https://github.com/eliranwong/UniqueBible/wiki/Install-on-Linux">Linux</a> (Arch, Debian, Ubuntu & Mint), <a href="https://github.com/eliranwong/UniqueBible/wiki/Install-on-Chrome-OS">Chrome OS</a> (Debian 10), <a href="https://github.com/eliranwong/UniqueBible/wiki/Webtop-Version---RECOMMENDED!">Webtops</a>, <a href="https://github.com/eliranwong/UniqueBible/wiki/Android-iOS-Version">Android / iOS</a>
<b>Tested in:</b> <a href="https://github.com/eliranwong/UniqueBible/wiki/Install-on-Windows">Windows 10</a>, <a href="https://github.com/eliranwong/wsl2/blob/master/bible_apps/desktop.md">Windows WSL2</a>, <a href="https://github.com/eliranwong/UniqueBible/wiki/Install-on-macOS">macOS [Sierra+]</a> and <a href="https://github.com/eliranwong/UniqueBible/wiki/Install-on-Linux">Linux</a> (Arch, Debian, Ubuntu & Mint), <a href="https://github.com/eliranwong/UniqueBible/wiki/Install-on-Chrome-OS">Chrome OS</a> (Debian 10), <a href="https://github.com/eliranwong/UniqueBible/wiki/Android-iOS-Version">Android / iOS</a>

Unique Bible App can <a href="https://github.com/eliranwong/UniqueBible/wiki/UBA-Run-Modes">runs in different modes</a>, both online and offline, for examples:

Expand All @@ -38,23 +38,19 @@ Oliver Tseng (https://github.com/otseng)

# Quick Start

('git' and 'python 3.7+' are required)
Python 3.8+ required!

To download and set up Unique Bible app, run:
To install:

> git clone https://github.com/eliranwong/UniqueBible.git
> pip install uniquebible
> cd UniqueBible
To run GUI mode:

> python3 uba.py
> uniquebible
# Setup or Installation
More about installation at https://github.com/eliranwong/UniqueBible/wiki/Installation

Read our recommendations first at: https://github.com/eliranwong/UniqueBible/wiki/Recommendations-for-Different-Platforms

You can simply download & run UBA if you have python in place, read our examples at:

https://github.com/eliranwong/UniqueBible/wiki/Installation
More about running modes at https://github.com/eliranwong/UniqueBible/wiki/UBA-Run-Modes

# Features, instructions and how-tos

Expand Down
2 changes: 2 additions & 0 deletions uniquebible/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
for i in ("chatGPT", "config", "context", "event", "language", "layout", "menu", "shutdown", "startup", "terminal", "text_editor"):
Path(os.path.join(ubahome, "plugins", i)).mkdir(parents=True, exist_ok=True)

def getSitePackagesLocation():
return os.path.dirname(config.packageDir)

def getPackageInstalledVersion(package):
try:
Expand Down
8 changes: 7 additions & 1 deletion uniquebible/latest_changes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
PIP package:

0.1.90-0.1.93
0.1.97-0.1.98

* fixed Linux qt input plugin

* updated README

0.1.90-0.1.96

* fixed to support python 3.12

Expand Down
16 changes: 1 addition & 15 deletions uniquebible/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,8 @@
# Check for dependencies and other essential elements
from uniquebible.util.checkup import *

# make sure nltk data are installed
if "Nltk" in config.enabled:
# copy nltk data to virtual environment directory
nltk_data1 = os.path.join("nltk_data", "corpora", "omw-1.4.zip")
nltk_data1_destination_folder = os.path.join(config.venvDir, nltk_data1[:-4])
nltk_data2 = os.path.join("nltk_data", "corpora", "wordnet.zip")
nltk_data2_destination_folder = os.path.join(config.venvDir, nltk_data2[:-4])
corpora_folder = os.path.join(config.venvDir, "nltk_data", "corpora")
os.makedirs(corpora_folder, exist_ok=True)
if os.path.isfile(nltk_data1) and not os.path.isdir(nltk_data1_destination_folder):
shutil.unpack_archive(nltk_data1, corpora_folder)
if os.path.isfile(nltk_data2) and not os.path.isdir(nltk_data2_destination_folder):
shutil.unpack_archive(nltk_data2, corpora_folder)

# exit application if it is run for setup only
if config.runMode == "setup-only":
if config.runMode == "setup-only": # work with gui mode only; to set up for non-gui mode run `ub John 3:16`
print("UniqueBibleApp installed!")
exit()

Expand Down
51 changes: 3 additions & 48 deletions uniquebible/uba.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,15 @@ def main():
# Do NOT use sys.executable directly
python = os.path.basename(sys.executable)
mainFile = os.path.join(wd, "main.py")
major, minor, micro, *_ = sys.version_info
#major, minor, micro, *_ = sys.version_info
cpu = ""
if thisOS == "Darwin":
thisOS = "macOS"
*_, cpu = platform.mac_ver()
cpu = f"_{cpu}"
venvDir = "venv_{0}{4}_{1}.{2}.{3}".format(thisOS, major, minor, micro, cpu)
#venvDir = "venv_{0}{4}_{1}.{2}.{3}".format(thisOS, major, minor, micro, cpu)
binDir = "Scripts" if thisOS == "Windows" else "bin"

# Check if virtual environment is being used
"""if sys.prefix == sys.base_prefix:
# Check if virtual environment is available
venvPython = os.path.join(wd, venvDir, binDir, python)
if not os.path.exists(venvPython):
# Installing virtual environment
# https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
try:
import venv
except:
installmodule("virtualenv", False)
#subprocess.Popen([python, "-m", "venv", venvDir])
print("Setting up environment ...")
# optional: add file "use_system_site_packages" in UBA direcyory to use packages installed on system
try:
if not "venv" in sys.modules:
import venv
venv.create(env_dir=venvDir, with_pip=True, system_site_packages=True) if runMode == "docker" or os.path.isfile("use_system_site_packages") else venv.create(env_dir=venvDir, with_pip=True)
except:
pass"""

# create shortcut files
# On Windows
if thisOS == "Windows":
Expand Down Expand Up @@ -115,14 +94,6 @@ def main():
f.write("#!/bin/bash\n")
f.write(f"cd {wd}\n")
f.write(f"{python} {appFile} gui\n")
""" # This method does not work with *.command file
# icon needs to be manually added by dragging an icon to file info
icon_path = os.path.abspath(os.path.join("icons", f"{appName}.icns"))
def set_icon(file_path, icon_path):
import subprocess
subprocess.call(['sips', '-i', icon_path, '--out', f'{file_path}/Icon\r'])
subprocess.call(['/usr/bin/SetFile', '-a', 'C', file_path])
set_icon(shortcut_file, icon_path)"""
os.chmod(shortcut_file, 0o755)
# desktop shortcuts on Linux
elif thisOS == "Linux":
Expand Down Expand Up @@ -167,29 +138,13 @@ def desktopFileContent():
if thisOS == "Windows":
if python.endswith(".exe"):
python = python[:-4]
# Activate virtual environment
activator = os.path.join(wd, venvDir, binDir, "activate")
# Run main.py
mainPy = "main.py {0}".format(initialCommand) if initialCommand else "main.py"
if enableCli:
#if os.path.exists(activator):
# os.system("{0} & {1} {2}".format(activator, python, mainPy))
#else:
# os.system("{0} {1}".format(python, mainPy))
exec("from uniquebible.main import *", globals())
else:
if os.path.exists(activator):
subprocess.Popen("{0} & {1} {2}".format(activator, python, mainPy), shell=True)
else:
subprocess.Popen("{0} {1}".format(python, mainPy), shell=True)
subprocess.Popen("{0} {1}".format(python, mainPy), shell=True)
else:
"""# Activate virtual environment
activator = os.path.join(wd, venvDir, binDir, "activate_this.py")
if not os.path.exists(activator):
copyfile("activate_this.py", activator)
with open(activator) as f:
code = compile(f.read(), activator, 'exec')
exec(code, dict(__file__=activator))"""
# Run main.py
if enableCli:
#os.system("{0} {1}{2}".format(python, mainFile, f" {initialCommand}" if initialCommand else ""))
Expand Down
13 changes: 2 additions & 11 deletions uniquebible/util/ConfigUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ def updateModules(module, isInstalled):
if module in config.enabled:
config.enabled.remove(module)

def getCurrentVenvDir():
'''def getCurrentVenvDir():
major, minor, micro, *_ = sys.version_info
cpu = ""
if config.thisOS == "Darwin":
*_, cpu = platform.mac_ver()
cpu = f"_{cpu}"
return "venv_{0}{4}_{1}.{2}.{3}".format("macOS" if config.thisOS == "Darwin" else config.thisOS, major, minor, micro, cpu)
return "venv_{0}{4}_{1}.{2}.{3}".format("macOS" if config.thisOS == "Darwin" else config.thisOS, major, minor, micro, cpu)'''

config.updateModules = updateModules
setConfig("enabled", """
Expand All @@ -134,15 +134,6 @@ def getCurrentVenvDir():
setConfig("disabled", """
# Disabled modules""",
['Pygithub', 'Textract', 'Pydnsbl', 'Pocketsphinx'] if os.path.isdir("/data/data/com.termux/files/home") else [])
venvDir = getCurrentVenvDir()
setConfig("venvDir", """
# virtual environment directory""",
venvDir)
# in case python version is updated or device is changed
if not config.venvDir == venvDir:
config.enabled = []
config.disabled = []
config.venvDir = venvDir
setConfig("desktopUBAIcon", """
# Desktop version UBA icon filename. UniqueBible.app provides official icons in different colours. We ask our users to use one of our official icons to acknowledge our development.""",
os.path.join("htmlResources", "UniqueBibleApp.png"))
Expand Down
2 changes: 1 addition & 1 deletion uniquebible/util/LocalCliHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ def getDotCommands(self):
".watsontranslatecopiedtext": ("run IBM Watson Translator on copied text", self.watsonTranslate),
".wt": ("an alias to '.watsontranslate'", lambda: self.watsonTranslate(False)),
".wtc": ("an alias to '.watsontranslatecopiedtext'", self.watsonTranslate),
".portablepython": ("build portable python", self.buildPortablePython),
#".portablepython": ("build portable python", self.buildPortablePython),
".system": ("system command prompt", SystemCommandPrompt().run),
".sys": ("an alias to '.system'", SystemCommandPrompt().run),
".clear": ("clear screen", self.clear_screen),
Expand Down
13 changes: 5 additions & 8 deletions uniquebible/util/checkup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from uniquebible import config
from uniquebible import config, getSitePackagesLocation
import subprocess, os, zipfile, platform, sys, re, shutil
from shutil import copyfile
from uniquebible.util.WebtopUtil import WebtopUtil
Expand Down Expand Up @@ -46,11 +46,10 @@ def downloadFileIfNotFound(databaseInfo):
def fixFcitxOnLinux(module):
# Fixed fcitx for Linux users
if platform.system() == "Linux" and not (config.runMode == "docker"):
major, minor, micro, *_ = sys.version_info
venvDir = "venv_Linux_{0}.{1}.{2}".format(major, minor, micro)
#major, minor, micro, *_ = sys.version_info
#if (config.runMode == "docker"):
# fcitxPlugin = "/usr/lib/qt/plugins/platforminputcontexts/libfcitx5platforminputcontextplugin.so"
ubaInputPluginDir = os.path.join(os.getcwd(), venvDir, "lib/python{0}.{1}/site-packages/{2}/Qt/plugins/platforminputcontexts".format(major, minor, module))
ubaInputPluginDir = os.path.join(getSitePackagesLocation(), module, "Qt/plugins/platforminputcontexts")
# plugin file 1
fcitxPlugin = "/usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so"
ubaFcitxPlugin = os.path.join(ubaInputPluginDir, "libfcitxplatforminputcontextplugin.so")
Expand Down Expand Up @@ -765,7 +764,7 @@ def runTerminalMode():
("pyperclip", "Cross-platform clipboard utilities", isPyperclipInstalled),
("numpy", "Array Computing", isNumpyInstalled),
("matplotlib", "Plotting Package", isMatplotlibInstalled),
("pickley", "Automate installation of standalone python CLIs", isPickleyInstalled),
#("pickley", "Automate installation of standalone python CLIs", isPickleyInstalled),
("Pygments", "Syntax highlighting package", isPygmentsInstalled),
("asyncssh", "Asynchronous SSHv2 client and server library", isAsyncsshInstalled),
("bcrypt", "Modern password hashing for your software and your servers", isBcryptInstalled),
Expand Down Expand Up @@ -821,7 +820,7 @@ def runTerminalMode():
("pyperclip", "Cross-platform clipboard utilities", isPyperclipInstalled),
("numpy", "Array Computing", isNumpyInstalled),
("matplotlib", "Plotting Package", isMatplotlibInstalled),
("pickley", "Automate installation of standalone python CLIs", isPickleyInstalled),
#("pickley", "Automate installation of standalone python CLIs", isPickleyInstalled),
("Pygments", "Syntax highlighting package", isPygmentsInstalled),
("asyncssh", "Asynchronous SSHv2 client and server library", isAsyncsshInstalled),
("bcrypt", "Modern password hashing for your software and your servers", isBcryptInstalled),
Expand All @@ -842,8 +841,6 @@ def runTerminalMode():
if platform.system() == "Darwin":
optional.append(("AudioConverter", "Convert Audio Files to MP3", isAudioConverterInstalled))
for module, feature, isInstalled in optional:
if config.runMode in ("stream", "http-server") and module in ("pickley"):
continue
checkModule = re.sub("-|_", "", module)
checkModule = re.sub("^(-U |--upgrade )", "", checkModule).capitalize()
if not checkModule in config.enabled and not checkModule in config.disabled:
Expand Down
14 changes: 3 additions & 11 deletions uniquebible/util/text_editor_checkup.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,15 @@ def updateModules(module, isInstalled):
print("Required feature '{0}' is not enabled.\nRun 'pip3 install {1}' to install it first!".format(feature, module))
exit(1)

major, minor, micro, *_ = sys.version_info
'''major, minor, micro, *_ = sys.version_info
thisOS = platform.system()
cpu = ""
if thisOS == "Darwin":
thisOS = "macOS"
*_, cpu = platform.mac_ver()
cpu = f"_{cpu}"
venvDir = "venv_{0}{4}_{1}.{2}.{3}".format(thisOS, major, minor, micro, cpu)
venvDir = "venv_{0}{4}_{1}.{2}.{3}".format(thisOS, major, minor, micro, cpu)'''

disabledModules = []
disabledModulesFilePath = os.path.join(venvDir, "disabled_modules.txt")
if os.path.exists(disabledModulesFilePath):
with open(disabledModulesFilePath) as disabledModulesFile:
disabledModules = [line.strip() for line in disabledModulesFile.readlines()]
# Check if optional modules are installed
optional = [
("html-text", "Read html text", isHtmlTextInstalled),
Expand All @@ -245,10 +240,7 @@ def updateModules(module, isInstalled):
checkModule = re.sub("-|_", "", module)
checkModule = re.sub("^(-U |--upgrade )", "", checkModule).capitalize()
if not checkModule in config.enabled and not checkModule in config.disabled:
if module in disabledModules:
print(f"{module} has been manually disabled")
available = False
elif not isInstalled() or config.updateDependenciesOnStartup:
if not isInstalled() or config.updateDependenciesOnStartup:
if config.updateDependenciesOnStartup and not (module.startswith("-U ") or module.startswith("--upgrade ")):
module = "--upgrade {0}".format(module)
pip3InstallModule(module)
Expand Down

0 comments on commit 2e1321d

Please sign in to comment.