Last active
January 15, 2019 15:01
-
-
Save mz0/2bc63487359a1f628d9e3594274090e2 to your computer and use it in GitHub Desktop.
Arabic alphabet learning aid and PyQt5 primer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
""" | |
https://opensource.com/article/18/11/study-aid-python | |
2018.11.06 Greg Pittman | |
An exercise for learning Arabic letters. | |
An Arabic letter is shown, the name of which can be guessed. | |
Hover the mouse cursor over the letter to see its name in a Tool Tip. | |
Click Next to load another letter. | |
""" | |
import sys | |
from random import randint | |
try: | |
from PyQt5.QtCore import * | |
from PyQt5.QtGui import QFont | |
from PyQt5.QtWidgets import QWidget, QLabel, QApplication, QToolTip, QPushButton | |
except ModuleNotFoundError: | |
print("PyQt5 imports failed. Try:\n pip3 install --user pyqt5") | |
sys.exit(-5) | |
class Example(QWidget): | |
def __init__(self, parent = None): | |
super(Example, self).__init__(parent) | |
self.initUI() | |
def initUI(self): | |
QToolTip.setFont(QFont('DejaVuSans', 30)) | |
i = randint(0, 37) | |
self.lbl2 = QLabel(L[12], self) | |
self.lbl2.setToolTip(lname[12]+' \n ') | |
self.lbl2.setFont(QFont('FreeSerif', 40)) | |
self.lbl2.setTextFormat(1) | |
self.lbl2.setAlignment(Qt.AlignVCenter) | |
self.lbl2.setAlignment(Qt.AlignHCenter) | |
butn = QPushButton("Next", self) | |
butn.move(70, 70) | |
butn.clicked.connect(self.buttonClicked) | |
self.setGeometry(300, 300, 160, 110) | |
self.setWindowTitle('Arabic Letters') | |
self.show() | |
def buttonClicked(self): | |
i = randint(0,37) | |
self.lbl2.setFont(QFont('FreeSerif', 40)) | |
self.lbl2.setTextFormat(1) | |
self.lbl2.setText(L[i]) | |
self.lbl2.setAlignment(Qt.AlignVCenter) | |
self.lbl2.setAlignment(Qt.AlignHCenter) | |
self.lbl2.setToolTip(lname[i]+' \n ') | |
if __name__ == '__main__': | |
lname = ['alif', 'beh', 'teh', 'theh', 'jim', 'ha', 'kha', 'dal', 'dhal', 'ra', | |
'zin', 'sin', 'shin', 'Sad', 'Dad', 'Ta', 'DHa', 'ain', 'ghain', 'feh', | |
'qaf', 'kaf', 'lam', 'mim', 'nün', 'heh', 'waw', 'yeh', | |
'Sifr (0)', 'wáaHid (1)', 'ithnáyn (2)', 'thaláatha (3)', 'árba:ah (4)', | |
'khámsah (5)', 'sittah (6)', 'sáb:ah (7)', 'thamáanyah (8)', 'tís:ah (9)'] | |
L = [u"\u0627", u"\u0628", u"\u062A", u"\u062B", u"\u062C", u"\u062D", u"\u062E", u"\u062F", u"\u0630", u"\u0631", | |
u"\u0632", u"\u0633", u"\u0634", u"\u0635", u"\u0636", u"\u0637", u"\u0638", u"\u0639", u"\u063A", u"\u0641", | |
u"\u0642", u"\u0643", u"\u0644", u"\u0645", u"\u0646", u"\u0647", u"\u0648", u"\u064A", | |
u"\u0660", u"\u0661", u"\u0662", u"\u0663", u"\u0664", | |
u"\u0665", u"\u0666", u"\u0667", u"\u0668", u"\u0669"] | |
app = QApplication(sys.argv) | |
ex = Example() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment