Skip to content

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
redwan-hossain committed Oct 21, 2022
0 parents commit cee844f
Show file tree
Hide file tree
Showing 11 changed files with 22,172 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{py}]
charset = utf-8

# 4 space indentation
[*.py]
indent_style = space
indent_size = 4

1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.7z filter=lfs diff=lfs merge=lfs -text
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.mypy_cache
english_words.xml
copy.xml
scrap.py
test.py
__pycache__
download
build
dist
ydm.spec
tempCodeRunnerFile.py
.vscode
ortho.db
trial.py
bangla_words.xml
word_db_english.json
ortho_ui.py
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Ortho is an English to Bangla Dictionary based on Bangla Academy's E2B Database.

<br>

## Note:

- The codebase is in alpha stage.


107 changes: 107 additions & 0 deletions ortho.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import sqlite3
import json
from PyQt6 import uic
import sys
import os
import py7zr
import typing as type
from PyQt6 import QtGui
from PyQt6.QtWidgets import (
QMainWindow,
QPushButton,
QLabel,
QApplication,
QTextEdit,
QScrollArea,
)


BASE_DIR = os.path.dirname(os.path.abspath(__file__))


class Main_Ui(QMainWindow):
UI_FILE = os.path.join(BASE_DIR, "ortho.ui")
DB_PATH = os.path.join(BASE_DIR, "ortho.db")

if not os.path.exists(DB_PATH):
print("Extracting DataBase")
with py7zr.SevenZipFile("./ortho_db.7z", mode="r") as file:
file.extractall()
print("DataBase successfully extracted ")

DB_CONNECTION: type.Any = ""
JSON_BN_DB: dict = {}

def init_db_connection(self):
self.DB_CONNECTION = sqlite3.connect(self.DB_PATH)

def init_json_bn_db(self):
with open("word_db_bangla.json") as json_file:
self.JSON_BN_DB = json.load(json_file)

def __init__(self):
super(Main_Ui, self).__init__()
# load the Main_Ui
uic.loadUi(self.UI_FILE, self)
self.setFixedSize(self.size())

# load the db
self.init_db_connection()

# load the json map for db query
self.init_json_bn_db()

# defining widgets
self.word_search_bar = self.findChild(QTextEdit, "word_search_box")
self.word_search_btn = self.findChild(QPushButton, "word_search_button")
self.scrollable = self.findChild(QScrollArea, "scroll_able_area_bn_word")
self.picture_display_box = self.findChild(QLabel, "bn_word_meaning_box")

# button click handler
self.word_search_btn.clicked.connect(self.word_search_button_click_handler)

# Initially hide the result area
self.scrollable.hide()
self.picture_display_box.hide()

def query_json_bn_db(self, word_search) -> type.Any:
word_index = self.JSON_BN_DB.get(f"{word_search}")
return word_index

def query_db(self, key) -> None:
cursor: type.Any = self.DB_CONNECTION.cursor()
cursor.execute(
f"""SELECT bangla_definition FROM bangla_dictionary WHERE _id = {key};"""
)
result = cursor.fetchone()
image = result[0]
pixmap = QtGui.QPixmap()
pixmap.loadFromData(image, "gif")
pic_width = pixmap.width()
pic_height = pixmap.height()
self.picture_display_box.setMinimumSize(pic_width, pic_height)
self.picture_display_box.setPixmap(pixmap)

def word_search_button_click_handler(self) -> None:
word_from_user = str(self.word_search_bar.toPlainText())
if word_from_user != "":
word_key = self.query_json_bn_db(word_from_user)
if word_key:
self.scrollable.show()
self.picture_display_box.show()
self.statusBar().clearMessage()
self.picture_display_box.clear()
self.query_db(word_key)
else:
self.scrollable.hide()
self.picture_display_box.hide()
self.statusBar().showMessage("Word not found.")
self.statusBar().repaint()


if __name__ == "__main__":
app = QApplication(sys.argv)
app.setWindowIcon(QtGui.QIcon(os.path.join(BASE_DIR, "ortho.svg")))
window = Main_Ui()
window.show()
sys.exit(app.exec())
11 changes: 11 additions & 0 deletions ortho.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
206 changes: 206 additions & 0 deletions ortho.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>595</width>
<height>800</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>595</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>595</width>
<height>800</height>
</size>
</property>
<property name="contextMenuPolicy">
<enum>Qt::DefaultContextMenu</enum>
</property>
<property name="windowTitle">
<string>Ortho Dictionary</string>
</property>
<property name="tabShape">
<enum>QTabWidget::Triangular</enum>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QTextEdit" name="word_search_box">
<property name="geometry">
<rect>
<x>80</x>
<y>60</y>
<width>471</width>
<height>31</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="acceptRichText">
<bool>false</bool>
</property>
<property name="placeholderText">
<string>Enter your word here...</string>
</property>
</widget>
<widget class="QPushButton" name="word_search_button">
<property name="geometry">
<rect>
<x>200</x>
<y>110</y>
<width>221</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Search</string>
</property>
</widget>
<widget class="Line" name="line">
<property name="geometry">
<rect>
<x>0</x>
<y>190</y>
<width>631</width>
<height>20</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QScrollArea" name="scroll_able_area_bn_word">
<property name="geometry">
<rect>
<x>10</x>
<y>240</y>
<width>571</width>
<height>501</height>
</rect>
</property>
<property name="contextMenuPolicy">
<enum>Qt::DefaultContextMenu</enum>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>567</width>
<height>497</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="bn_word_meaning_box">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>20</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>530</width>
<height>100</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>530</width>
<height>5000</height>
</size>
</property>
<property name="mouseTracking">
<bool>true</bool>
</property>
<property name="focusPolicy">
<enum>Qt::WheelFocus</enum>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="midLineWidth">
<number>0</number>
</property>
<property name="text">
<string/>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<tabstops>
<tabstop>word_search_box</tabstop>
<tabstop>word_search_button</tabstop>
<tabstop>scroll_able_area_bn_word</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>
3 changes: 3 additions & 0 deletions ortho_db.7z
Git LFS file not shown
13 changes: 13 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Brotli==1.0.9
inflate64==0.3.0
multivolumefile==0.2.3
psutil==5.9.3
py7zr==0.20.0
pybcj==1.0.1
pycryptodomex==3.15.0
pyppmd==0.18.3
PyQt6==6.4.0
PyQt6-Qt6==6.4.0
PyQt6-sip==13.4.0
pyzstd==0.15.3
texttable==1.6.4
Loading

0 comments on commit cee844f

Please sign in to comment.