Esempio n. 1
0
    import tkinter as tk
from taklowGUI import Kwitya, Radiobar, Entrybar, CheckButtonBar
import mutatya
import textwrap

if __name__ == '__main__':
    root = tk.Tk()
    root.title('Mutatya')
    mhead = tk.Label(root, text="Studh Treylyans")
    mhead.config(font=('Open Sans', 16, 'bold'))
    mhead.pack(side=tk.TOP, anchor=tk.NW)
    # various mutation states
    mstate = Radiobar(root, [
        '1 (heb treylyans)', '2 (medhel)', '3 (hwythys)', '4 (kales)',
        '5 (kemmyskys)', '6 (kemmyskys wosa \'th)', '7 (kildreylyans)'
    ],
                      side=tk.TOP,
                      anchor=tk.NW,
                      default='1 (heb treylyans)')
    mstate.pack(side=tk.LEFT, fill=tk.Y)
    mstate.config(relief=tk.RIDGE, bd=2)

    tradgraph = CheckButtonBar(mstate, ['Lytherennans\nhengovek (SWF/T)'],
                               side=tk.TOP,
                               justify=tk.LEFT,
                               anchor=tk.NW)
    tradgraph.pack(side=tk.LEFT, fill=tk.Y)

    def allstates():
        print(mstate.state(), tradgraph.state(), intmstate(), ent.fetch())
Esempio n. 2
0
    args = parser.parse_args()
    if args.netbook:
        heightadjust = -4
        fontsizeadj = -1
    else:
        heightadjust = 0
        fontsizeadj = 0

    root = tk.Tk()
    root.title('Syllabenn Ranna Kernewek')
    mhead = tk.Label(root, text="Dewisyow")
    mhead.config(font=('Open Sans', 16 + fontsizeadj, 'bold'))
    mhead.pack(side=tk.TOP, anchor=tk.NW)

    options = Radiobar(root, ['Mode Hir', 'Mode Berr', 'Mode Linenn'],
                       side=tk.TOP,
                       anchor=tk.NW,
                       default='Mode Berr')
    options.pack(side=tk.LEFT, fill=tk.Y)
    options.config(relief=tk.RIDGE, bd=2, padx=10, pady=10)

    options2 = Radiobar(options, ['Rannans war-rag', 'Rannans war-dhelergh'],
                        side=tk.TOP,
                        anchor=tk.NW,
                        default='Rannans war-dhelergh')
    options2.pack(side=tk.LEFT, fill=tk.Y)
    options2.config(pady=10)

    kkfss = Radiobar(options2, ['Kernewek Kemmyn', 'Kernewek FSS'],
                     side=tk.TOP,
                     anchor=tk.NW,
                     default='Kernewek Kemmyn')
Esempio n. 3
0
    """ copy the contents of the output window to the clipboard """
    root.clipboard_clear()
    root.clipboard_append(msg2.cget("text"))


if __name__ == '__main__':
    root = tk.Tk()
    root.title('Treiglo')
    mhead = tk.Label(root, text="Ystad Treiglo")
    mhead.config(font=('Open Sans', 16, 'bold'))
    mhead.pack(side=tk.TOP, anchor=tk.NW)
    # various mutation states
    mstate = Radiobar(root, [
        'Heb treiglo', 'Treiglad meddal', 'Treiglad llais', 'Treiglad trwynol',
        'Cymysgu wedi "ni"', 'Gwrthdroi treiglad'
    ], [1, 2, 3, 7, 8, 9],
                      side=tk.TOP,
                      anchor=tk.NW,
                      default=1)
    mstate.pack(side=tk.LEFT, fill=tk.Y)
    mstate.config(relief=tk.RIDGE, bd=2)

    msg = tk.Label(root, text="Rhowch gair Cymraeg islaw os gwelwch yn dda")
    msg.config(font=('Open Sans', 16, 'bold'))
    msg.pack()

    # text entry bar
    ent = Entrybar(root)
    ent.pack()

    msg2 = tk.Label(root)
    def make_widgets(self):
        """ display GUI widgets """
        self.mhead = tk.Label(
            self,
            text=CorpusStats.labelTexts['mhead'][self.mscript][self.ifacelang])
        self.mhead.config(font=('Noto Sans', 16 + self.fontsizeadj, 'bold'))
        self.mhead.pack(side=tk.TOP, anchor=tk.NW)
        c = self.checkNLTK()
        print("NLTK available = {c}".format(c=c))
        if c == 0:
            self.names = [
                "Bewnans Meryasek", "Charter Fragment", "Gwreans an Bys",
                "Passhyon Agan Arloedh", "Origo Mundi", "Passio Christ",
                "Resurrectio Domini", "Skeul an Yeth 1", "Solemptnyta",
                "LoTR chapters", "Tregear Homilies"
            ]
        else:
            # import cornish_corpus
            # unecessary as done already
            self.kk_texts, self.names = cornish_corpus.corpusKW(
                args.manuscript, outlang=self.ifacelang)
            self.kk_text_dict = {
                k: v
                for (k, v) in zip(self.names, self.kk_texts)
            }
        if self.mscript:
            textmenu = CorpusStats.labelTexts['textchoicems'][self.ifacelang]
            # make all texts option still 10 even though there are fewer texts in manuscript spelling
            optionnums = list(range(len(textmenu) - 1))
            optionnums.append(10)
        else:
            textmenu = CorpusStats.labelTexts['textchoice'][self.ifacelang]
            optionnums = list(range(len(textmenu)))

        self.textchoice = Radiobar(self,
                                   textmenu,
                                   vals=optionnums,
                                   side=tk.TOP,
                                   anchor=tk.NW,
                                   default=2,
                                   justify=tk.LEFT,
                                   font=('Noto Sans', 13 + self.fontsizeadj,
                                         'normal'))
        self.textchoice.pack(side=tk.LEFT, fill=tk.Y)
        self.textchoice.config(relief=tk.RIDGE, bd=2)
        self.switchlang = tk.Button(
            self.textchoice,
            text=CorpusStats.labelTexts['switchlang'][self.ifacelang],
            font=('Noto Sans', 14 + self.fontsizeadj),
            command=self.changeifacelang)
        self.switchlang.pack(anchor=tk.SW, side=tk.LEFT, padx=10, pady=10)
        self.switchms = tk.Button(self.textchoice,
                                  text=CorpusStats.labelTexts['switchms'][
                                      self.mscript][self.ifacelang],
                                  font=('Noto Sans', 14 + self.fontsizeadj),
                                  command=self.switchms)
        self.switchms.pack(anchor=tk.SW, side=tk.LEFT, padx=10, pady=10)

        self.mhead2 = tk.Label(
            self, text=CorpusStats.labelTexts['mhead2'][self.ifacelang])
        self.mhead2.config(font=('Noto Sans', 16 + self.fontsizeadj * 2,
                                 'bold'))
        self.mhead2.pack(side=tk.TOP, anchor=tk.NW)
        mchoicetext = CorpusStats.labelTexts['modechoice'][self.ifacelang]
        mchoicevals = range(len(mchoicetext))
        self.modechoice = Radiobar(self,
                                   mchoicetext,
                                   vals=mchoicevals,
                                   side=tk.TOP,
                                   anchor=tk.NW,
                                   justify=tk.LEFT,
                                   default=0,
                                   font=('Noto Sans', 13 + self.fontsizeadj,
                                         'normal'))
        self.msg1 = tk.Label(
            self.modechoice,
            text=CorpusStats.labelTexts['msg'][self.ifacelang],
            anchor=tk.W,
            justify=tk.LEFT,
            pady=10 + self.padadj)
        self.msg1.config(font=('Noto Sans', 12 + self.fontsizeadj))
        self.msg1.pack(anchor=tk.W)
        self.ent = Entrybar(self.modechoice, anchor=tk.NW)
        self.ent.pack(anchor=tk.W, padx=5)
        self.msg2 = tk.Label(
            self.modechoice,
            text=CorpusStats.labelTexts['msg2'][self.ifacelang],
            anchor=tk.W,
            justify=tk.LEFT,
            pady=10 + self.padadj)
        self.msg2.config(font=('Noto Sans', 12 + self.fontsizeadj))
        self.msg2.pack(anchor=tk.W)
        self.ent2 = Entrybar(self.modechoice, anchor=tk.NW)
        self.ent2.pack(anchor=tk.W, padx=5)
        self.msg3 = tk.Label(
            self.modechoice,
            text=CorpusStats.labelTexts['msg3'][self.ifacelang],
            anchor=tk.W,
            justify=tk.LEFT,
            pady=10 + self.padadj)
        self.msg3.config(font=('Noto Sans', 12 + self.fontsizeadj))
        self.msg3.pack(anchor=tk.W, padx=5)
        self.ent3 = Entrybar(self.modechoice, anchor=tk.NW)
        self.ent3.pack(anchor=tk.W, padx=5)
        self.keworra = tk.Button(
            self.modechoice,
            text=CorpusStats.labelTexts['keworra'][self.ifacelang],
            font=('Noto Sans', 14 + self.fontsizeadj),
            command=self.addtocomparelist)
        self.klerhe = tk.Button(
            self.modechoice,
            text=CorpusStats.labelTexts['klerhe'][self.ifacelang],
            font=('Noto Sans', 14 + self.fontsizeadj),
            command=self.clearcomparelist)
        self.keworra.pack(anchor=tk.NW, side=tk.LEFT, pady=10)
        self.klerhe.pack(anchor=tk.NW, side=tk.LEFT, pady=10)
        self.modechoice.pack(side=tk.LEFT, fill=tk.Y)
        self.modechoice.config(relief=tk.RIDGE, bd=2)
        self.outbox = ScrolledText(self)
        self.outbox.text.config(bg='light yellow',
                                fg='dark red',
                                width=60,
                                height=20 + self.heightadjust,
                                font=('Courier', 14 + self.fontsizeadj,
                                      'bold'))
        self.outbox.pack()
        # buttons
        self.Kwitya = Kwitya2(self)
        self.Kwitya.pack(side=tk.RIGHT)
        self.dalleth = tk.Button(
            self,
            text=CorpusStats.labelTexts['dalleth'][self.ifacelang],
            font=('Noto Sans', 14),
            command=self.printoutput)
        self.klerhefigs = tk.Button(
            self,
            text=CorpusStats.labelTexts['klerhefigs'][self.ifacelang],
            font=('Noto Sans', 14 + self.fontsizeadj),
            command=self.clearfigures)
        self.klyppbordh = tk.Button(
            self,
            text=CorpusStats.labelTexts['klyppbordh'][self.ifacelang],
            font=('Noto Sans', 14 + self.fontsizeadj),
            command=self.copyclipbd)

        if c == 0:
            self.dalleth['state'] = tk.DISABLED
            self.outbox.settext(
                CorpusStats.labelTexts['NLTKerr'][self.ifacelang])
        self.klerhefigs.pack(side=tk.RIGHT)
        self.dalleth.pack(side=tk.RIGHT)
        self.klyppbordh.pack(side=tk.LEFT)
class CorpusStats(tk.Frame):
    labelTexts = {
        'modechoice': {
            'en': [
                'General Report', 'Word Frequencies List',
                'Letter Frequencies List',
                'Letter Frequencies List\n(without digraphs)',
                'Length of words\n(cumulative frequency graph)',
                'Word Frequency Bar Chart', 'Lexical Dispersion Plot',
                'Concordance', 'Regex findall'
            ],
            'kw': [
                'Derivas Ollgemmyn', 'Rol Menowghderow Ger',
                'Rol Menowghderow Lytherenn',
                'Rol Menowghderow Lytherenn\n(heb dilytherennow)',
                'Hirder Geryow\n(tresenn menowghder kumulativ)',
                'Menowghder Ger (tresenn barr)', 'Tresenn Keskar Ger',
                'Konkordans', 'findall Regex'
            ]
        },
        'textchoice': {
            'en': [
                'Life of Meryasek', 'Charter Fragment',
                'Creation of the World', 'Passion of our Lord', 'Origo Mundi',
                'Passio Christ', 'Resurrectio Domini',
                'Skeul an Yeth 1 examples', 'Solemptnyta', 'LoTR chapters',
                'Tregear Homilies', 'All Texts'
            ],
            'kw': [
                'Bewnans Meryasek', 'Darn Chartour', 'Gwreans an Bys',
                'Passhyon Agan Arloedh', 'Origo Mundi', 'Passio Christ',
                'Resurrectio Domini', 'Ensamplow Skeul an Yeth 1',
                'Solemptnyta', 'Chapters Arloedh an Bysowyer',
                'Pregothow Tregear', 'Oll an Tekstow'
            ]
        },
        'textchoicems': {
            'en': [
                'Life of Ke', 'Charter Fragment', 'Creation of the World',
                'Passion of our Lord', 'Origo Mundi', 'Passio Christ',
                'Resurrectio Domini', 'Tregear Homilies', 'All Texts'
            ],
            'kw': [
                'Bewnans Ke', 'Darn Chartour', 'Gwreans an Bys',
                'Passhyon Agan Arloedh', 'Origo Mundi', 'Passio Christ',
                'Resurrectio Domini', 'Pregothow Tregear', 'Oll an Tekstow'
            ]
        },
        'mhead': {
            False: {
                'en': 'Text (Kemmyn)',
                'kw': 'Tekst (Kemmyn)'
            },
            True: {
                'en': 'Text (Manuscript)',
                'kw': 'Tekst (Mammskrif)'
            }
        },
        'mhead2': {
            'en': 'Options',
            'kw': 'Dewis Gwrythyans'
        },
        'msg': {
            'en': ('Enter the minimum number of letters\n'
                   'for word frequency list below:'),
            'kw': ('Keworrowgh isella niver a lytherennow\n'
                   'rag rolyow menoghder ger a-woeles:')
        },
        'msg2': {
            'en': ('Enter the number of words to report\n'
                   'frequency of below:\ndefault = 20'),
            'kw': ('Keworrowgh niver a eryow dhe dherivas\n'
                   'an menowghder a-woeles:\ndefowt = 20')
        },
        'msg3': {
            'en': ('Enter a word to compare frequencies of\n'
                   'across the texts:'),
            'kw': ('Keworrowgh ger dhe geheveli\n'
                   'menowghderow dres an tekstow:')
        },
        'keworra': {
            'en': 'Add word to the list',
            'kw': "Keworra ger dhe'n rol"
        },
        'klerhe': {
            'en': 'Clear the list',
            'kw': 'Klerhe an rol'
        },
        'dalleth': {
            'en': 'Start',
            'kw': 'Dalleth'
        },
        'klerhefigs': {
            'en': 'Clear Figures',
            'kw': 'Klerhe Tresennow'
        },
        'klyppbordh': {
            'en': 'Copy to Clipboard',
            'kw': "Kopi dhe'm Klyppbordh"
        },
        'switchlang': {
            'en': 'Kernewek',
            'kw': 'English'
        },
        'switchms': {
            False: {
                'en': 'Switch to manuscript',
                'kw': 'Skwychya dhe Vammskrif'
            },
            True: {
                'en': 'Switch to Kemmyn',
                'kw': 'Skwychya dhe Gemmyn'
            }
        },
        'windowtitle': {
            'en': 'Cornish Corpus Statistics',
            'kw': 'Korpus Kernewek'
        },
        'NLTKerr': {
            'en': ('Python Natural Language Processing Toolkit (NLTK)'
                   'not available.\nDownload from www.nltk.org'
                   ' if not on the system.'),
            'kw': ('Nyns yw Python Natural Language Processing Toolkit'
                   '(NLTK) kavadow.\nIskargewgh diworth www.nltk.org'
                   'mar nyns yw war agas jynn-amontya.')
        }
    }

    def __init__(self,
                 parent=None,
                 netbook=False,
                 english=False,
                 mscript=False):
        tk.Frame.__init__(self, parent)
        if english:
            self.ifacelang = 'en'
        else:
            self.ifacelang = 'kw'
        self.mscript = mscript
        self.netbook = netbook
        if self.netbook:
            self.heightadjust = -8
            self.fontsizeadj = -4
            self.padadj = -5
            self.wline = 50
        else:
            self.heightadjust = 0
            self.fontsizeadj = 0
            self.padadj = 0
            self.wline = 60
        self.comparelist = []
        self.defaultsamples = [
            'dhe', 'gans', 'war', 'dhymm', 'dhymmo', 'genev', 'warnav', 'rag',
            'mes'
        ]
        self.master.title(
            CorpusStats.labelTexts['windowtitle'][self.ifacelang])
        self.pack()
        self.make_widgets()

    def make_widgets(self):
        """ display GUI widgets """
        self.mhead = tk.Label(
            self,
            text=CorpusStats.labelTexts['mhead'][self.mscript][self.ifacelang])
        self.mhead.config(font=('Noto Sans', 16 + self.fontsizeadj, 'bold'))
        self.mhead.pack(side=tk.TOP, anchor=tk.NW)
        c = self.checkNLTK()
        print("NLTK available = {c}".format(c=c))
        if c == 0:
            self.names = [
                "Bewnans Meryasek", "Charter Fragment", "Gwreans an Bys",
                "Passhyon Agan Arloedh", "Origo Mundi", "Passio Christ",
                "Resurrectio Domini", "Skeul an Yeth 1", "Solemptnyta",
                "LoTR chapters", "Tregear Homilies"
            ]
        else:
            # import cornish_corpus
            # unecessary as done already
            self.kk_texts, self.names = cornish_corpus.corpusKW(
                args.manuscript, outlang=self.ifacelang)
            self.kk_text_dict = {
                k: v
                for (k, v) in zip(self.names, self.kk_texts)
            }
        if self.mscript:
            textmenu = CorpusStats.labelTexts['textchoicems'][self.ifacelang]
            # make all texts option still 10 even though there are fewer texts in manuscript spelling
            optionnums = list(range(len(textmenu) - 1))
            optionnums.append(10)
        else:
            textmenu = CorpusStats.labelTexts['textchoice'][self.ifacelang]
            optionnums = list(range(len(textmenu)))

        self.textchoice = Radiobar(self,
                                   textmenu,
                                   vals=optionnums,
                                   side=tk.TOP,
                                   anchor=tk.NW,
                                   default=2,
                                   justify=tk.LEFT,
                                   font=('Noto Sans', 13 + self.fontsizeadj,
                                         'normal'))
        self.textchoice.pack(side=tk.LEFT, fill=tk.Y)
        self.textchoice.config(relief=tk.RIDGE, bd=2)
        self.switchlang = tk.Button(
            self.textchoice,
            text=CorpusStats.labelTexts['switchlang'][self.ifacelang],
            font=('Noto Sans', 14 + self.fontsizeadj),
            command=self.changeifacelang)
        self.switchlang.pack(anchor=tk.SW, side=tk.LEFT, padx=10, pady=10)
        self.switchms = tk.Button(self.textchoice,
                                  text=CorpusStats.labelTexts['switchms'][
                                      self.mscript][self.ifacelang],
                                  font=('Noto Sans', 14 + self.fontsizeadj),
                                  command=self.switchms)
        self.switchms.pack(anchor=tk.SW, side=tk.LEFT, padx=10, pady=10)

        self.mhead2 = tk.Label(
            self, text=CorpusStats.labelTexts['mhead2'][self.ifacelang])
        self.mhead2.config(font=('Noto Sans', 16 + self.fontsizeadj * 2,
                                 'bold'))
        self.mhead2.pack(side=tk.TOP, anchor=tk.NW)
        mchoicetext = CorpusStats.labelTexts['modechoice'][self.ifacelang]
        mchoicevals = range(len(mchoicetext))
        self.modechoice = Radiobar(self,
                                   mchoicetext,
                                   vals=mchoicevals,
                                   side=tk.TOP,
                                   anchor=tk.NW,
                                   justify=tk.LEFT,
                                   default=0,
                                   font=('Noto Sans', 13 + self.fontsizeadj,
                                         'normal'))
        self.msg1 = tk.Label(
            self.modechoice,
            text=CorpusStats.labelTexts['msg'][self.ifacelang],
            anchor=tk.W,
            justify=tk.LEFT,
            pady=10 + self.padadj)
        self.msg1.config(font=('Noto Sans', 12 + self.fontsizeadj))
        self.msg1.pack(anchor=tk.W)
        self.ent = Entrybar(self.modechoice, anchor=tk.NW)
        self.ent.pack(anchor=tk.W, padx=5)
        self.msg2 = tk.Label(
            self.modechoice,
            text=CorpusStats.labelTexts['msg2'][self.ifacelang],
            anchor=tk.W,
            justify=tk.LEFT,
            pady=10 + self.padadj)
        self.msg2.config(font=('Noto Sans', 12 + self.fontsizeadj))
        self.msg2.pack(anchor=tk.W)
        self.ent2 = Entrybar(self.modechoice, anchor=tk.NW)
        self.ent2.pack(anchor=tk.W, padx=5)
        self.msg3 = tk.Label(
            self.modechoice,
            text=CorpusStats.labelTexts['msg3'][self.ifacelang],
            anchor=tk.W,
            justify=tk.LEFT,
            pady=10 + self.padadj)
        self.msg3.config(font=('Noto Sans', 12 + self.fontsizeadj))
        self.msg3.pack(anchor=tk.W, padx=5)
        self.ent3 = Entrybar(self.modechoice, anchor=tk.NW)
        self.ent3.pack(anchor=tk.W, padx=5)
        self.keworra = tk.Button(
            self.modechoice,
            text=CorpusStats.labelTexts['keworra'][self.ifacelang],
            font=('Noto Sans', 14 + self.fontsizeadj),
            command=self.addtocomparelist)
        self.klerhe = tk.Button(
            self.modechoice,
            text=CorpusStats.labelTexts['klerhe'][self.ifacelang],
            font=('Noto Sans', 14 + self.fontsizeadj),
            command=self.clearcomparelist)
        self.keworra.pack(anchor=tk.NW, side=tk.LEFT, pady=10)
        self.klerhe.pack(anchor=tk.NW, side=tk.LEFT, pady=10)
        self.modechoice.pack(side=tk.LEFT, fill=tk.Y)
        self.modechoice.config(relief=tk.RIDGE, bd=2)
        self.outbox = ScrolledText(self)
        self.outbox.text.config(bg='light yellow',
                                fg='dark red',
                                width=60,
                                height=20 + self.heightadjust,
                                font=('Courier', 14 + self.fontsizeadj,
                                      'bold'))
        self.outbox.pack()
        # buttons
        self.Kwitya = Kwitya2(self)
        self.Kwitya.pack(side=tk.RIGHT)
        self.dalleth = tk.Button(
            self,
            text=CorpusStats.labelTexts['dalleth'][self.ifacelang],
            font=('Noto Sans', 14),
            command=self.printoutput)
        self.klerhefigs = tk.Button(
            self,
            text=CorpusStats.labelTexts['klerhefigs'][self.ifacelang],
            font=('Noto Sans', 14 + self.fontsizeadj),
            command=self.clearfigures)
        self.klyppbordh = tk.Button(
            self,
            text=CorpusStats.labelTexts['klyppbordh'][self.ifacelang],
            font=('Noto Sans', 14 + self.fontsizeadj),
            command=self.copyclipbd)

        if c == 0:
            self.dalleth['state'] = tk.DISABLED
            self.outbox.settext(
                CorpusStats.labelTexts['NLTKerr'][self.ifacelang])
        self.klerhefigs.pack(side=tk.RIGHT)
        self.dalleth.pack(side=tk.RIGHT)
        self.klyppbordh.pack(side=tk.LEFT)

    def checkNLTK(self):
        try:
            import nltk
        except ImportError:
            return 0
        return 1

    def addtocomparelist(self):
        newword = self.ent3.fetch()
        if "," in newword:
            newwordlist = newword.split(",")
            newwordlist = [w.strip() for w in newwordlist]
            newwordlist = [w.lower() for w in newwordlist if w.isalpha()]
            self.comparelist.extend(newwordlist)
        else:
            newword = newword.strip()
            newword = newword.lower()
            self.comparelist.append(newword)
        self.outbox.settext(self.comparelist)
        self.ent3.clear()

    def clearcomparelist(self):
        del self.comparelist[:]
        self.outbox.settext("")

    def getcomparelist(self):
        return self.comparelist

    def clearfigures(self):
        plt.close("all")
        self.focus_force()

    def allstates(self):
        print(self.textchoice.state(), self.modechoice.state(),
              self.ent.fetch(), self.ent2.fetch(), self.ent3.fetch())

    def getIntMinL(self, eboxtext, defaultval=1):
        """ get integer for minimum word length, """
        """ or for number of frequencies to return. """
        try:
            minL = int(eboxtext)
        except ValueError:
            print(("warning, input cannot be converted to integer."
                   " using value of {d}").format(d=defaultval))
            minL = defaultval
        return minL

    def changeifacelang(self):
        if self.ifacelang == 'kw':
            self.ifacelang = 'en'
        else:
            self.ifacelang = 'kw'
        self.switchlang.config(
            text=self.labelTexts['switchlang'][self.ifacelang])
        self.switchms.config(
            text=self.labelTexts['switchms'][self.mscript][self.ifacelang])
        self.master.title(self.labelTexts['windowtitle'][self.ifacelang])
        self.mhead.config(
            text=self.labelTexts['mhead'][self.mscript][self.ifacelang])
        if self.mscript:
            newpicks = self.labelTexts['textchoicems'][self.ifacelang]
        else:
            newpicks = self.labelTexts['textchoice'][self.ifacelang]
        for p, r in zip(newpicks, self.textchoice.rads):
            r.config(text=p)

        self.mhead2.config(text=self.labelTexts['mhead2'][self.ifacelang])
        newpicks = self.labelTexts['modechoice'][self.ifacelang]
        for p, r in zip(newpicks, self.modechoice.rads):
            r.config(text=p)
        self.msg1.config(text=self.labelTexts['msg'][self.ifacelang])
        self.msg2.config(text=self.labelTexts['msg2'][self.ifacelang])
        self.msg3.config(text=self.labelTexts['msg3'][self.ifacelang])
        self.keworra.config(text=self.labelTexts['keworra'][self.ifacelang])
        self.klerhe.config(text=self.labelTexts['klerhe'][self.ifacelang])
        self.dalleth.config(text=self.labelTexts['dalleth'][self.ifacelang])
        self.klerhefigs.config(
            text=self.labelTexts['klerhefigs'][self.ifacelang])
        self.klyppbordh.config(
            text=self.labelTexts['klyppbordh'][self.ifacelang])
        # reload texts to get new names
        self.kk_texts, self.names = cornish_corpus.corpusKW(
            self.mscript, outlang=self.ifacelang)
        self.kk_text_dict = {k: v for (k, v) in zip(self.names, self.kk_texts)}
        # rerun self.printoutput to show results in new interface language
        self.printoutput()

    def switchms(self):
        self.mscript = not (self.mscript)
        self.mhead.config(
            text=self.labelTexts['mhead'][self.mscript][self.ifacelang])
        currstate = self.textchoice.state()
        self.textchoice.destroyrads()
        self.switchlang.pack_forget()
        self.switchms.pack_forget()
        #self.textchoice.pack_forget()
        # reload texts to get new names
        self.kk_texts, self.names = cornish_corpus.corpusKW(
            self.mscript, outlang=self.ifacelang)
        self.kk_text_dict = {k: v for (k, v) in zip(self.names, self.kk_texts)}
        if self.mscript:
            textmenu = CorpusStats.labelTexts['textchoicems'][self.ifacelang]
        else:
            textmenu = CorpusStats.labelTexts['textchoice'][self.ifacelang]

        # make all texts option still 11 even though
        # there are fewer texts in manuscript spelling
        optionnums = list(range(len(textmenu) - 1))
        optionnums.append(11)
        if currstate not in optionnums:
            currstate = 2
        self.textchoice.newrads(picks=textmenu,
                                vals=optionnums,
                                default=currstate)
        self.switchms.config(
            text=self.labelTexts['switchms'][self.mscript][self.ifacelang])
        self.switchlang.pack(anchor=tk.SW, side=tk.LEFT, padx=10, pady=10)
        self.switchms.pack(anchor=tk.SW, side=tk.LEFT, padx=10, pady=10)
        # rerun self.printoutput to show results in manuscript / Kemmyn
        self.printoutput()

    def printoutput(self):
        """ show the output """
        if self.modechoice.state() == 0:
            topN = self.getIntMinL(self.ent2.fetch(), 20)
            minL = self.getIntMinL(self.ent.fetch(), 4)
            if self.textchoice.state() == 11:
                outputtext = cornish_corpus.basicReportAll(
                    self.kk_texts,
                    self.names,
                    topN,
                    minL,
                    pause=False,
                    outlang=self.ifacelang)
            else:
                outputtext = cornish_corpus.basicReport(
                    self.kk_text_dict[self.names[self.textchoice.state()]],
                    self.names[self.textchoice.state()],
                    topN,
                    minL,
                    outlang=self.ifacelang)
            outputtext = wraplines(outputtext, self.wline)

            self.outbox.settext(outputtext)
        if self.modechoice.state() == 1:
            # rol menowghder ger
            topN = self.getIntMinL(self.ent2.fetch(), 20)
            minL = self.getIntMinL(self.ent.fetch())
            if self.textchoice.state() == 11:
                self.outbox.settext(
                    cornish_corpus.MostFrequentWords(self.kk_texts,
                                                     self.names,
                                                     topN,
                                                     minL,
                                                     outlang=self.ifacelang))
            else:
                self.outbox.settext(
                    cornish_corpus.MostFreqWords1Text(
                        self.kk_text_dict[self.names[self.textchoice.state()]],
                        self.names[self.textchoice.state()],
                        topN,
                        minL,
                        outlang=self.ifacelang))
        if self.modechoice.state() == 2:
            if self.textchoice.state() == 11:
                self.outbox.settext(
                    cornish_corpus.MostFreqLetters(self.kk_texts,
                                                   self.names,
                                                   outlang=self.ifacelang))
            else:
                self.outbox.settext(
                    cornish_corpus.MostFreqLetters1Text(
                        self.kk_text_dict[self.names[self.textchoice.state()]],
                        self.names[self.textchoice.state()],
                        outlang=self.ifacelang))
        if self.modechoice.state() == 3:
            if self.textchoice.state() == 11:
                self.outbox.settext(
                    cornish_corpus.MostFreqLetters(self.kk_texts,
                                                   self.names,
                                                   False,
                                                   False,
                                                   outlang=self.ifacelang))
            else:
                self.outbox.settext(
                    cornish_corpus.MostFreqLetters1Text(
                        self.kk_text_dict[self.names[self.textchoice.state()]],
                        self.names[self.textchoice.state()],
                        False,
                        False,
                        outlang=self.ifacelang))

        if self.modechoice.state() == 4:
            plt.figure()
            if self.textchoice.state() == 11:
                self.outbox.settext(
                    cornish_corpus.nLettersFDist(self.kk_texts,
                                                 self.names,
                                                 outlang=self.ifacelang))
            else:
                self.outbox.settext(
                    cornish_corpus.nLettersFDist([
                        self.kk_text_dict[self.names[self.textchoice.state()]]
                    ], [self.names[self.textchoice.state()]],
                                                 outlang=self.ifacelang))
            plt.show()
        if self.modechoice.state() == 5:
            plt.figure()
            comparelist = self.getcomparelist()
            if len(comparelist) == 0:
                comparelist = self.defaultsamples
            self.outbox.text.config(bg='light yellow',
                                    fg='dark red',
                                    font=('Courier', 12 + self.fontsizeadj,
                                          'normal'))
            if self.textchoice.state() == 11:
                outputtext = str(comparelist)+'\n\n'+ \
                    cornish_corpus.compareSamples(self.kk_texts, self.names,                              comparelist,
                                                  outlang=self.ifacelang)
            else:
                outputtext = str(comparelist)+'\n\n'+ \
                    cornish_corpus.compareSamples([
                        self.kk_text_dict[self.names[self.textchoice.state()]]],
                        [self.names[self.textchoice.state()]],
                        comparelist, outlang=self.ifacelang)
            outputtext = wraplines(outputtext, self.wline)
            self.outbox.settext(outputtext)
            plt.show()
        if self.modechoice.state() == 6:
            comparelist = self.getcomparelist()
            if len(comparelist) == 0:
                comparelist = self.defaultsamples
            self.outbox.text.config(bg='light yellow',
                                    fg='dark red',
                                    font=('Courier', 12 + self.fontsizeadj,
                                          'normal'))
            if self.textchoice.state() == 11:
                outputtext = str(comparelist)+'\n\n'+ \
                    cornish_corpus.compareSamplesLinear(
                        self.kk_texts, self.names, comparelist,
                        outlang=self.ifacelang)
            else:
                outputtext = str(comparelist)+'\n\n'+ \
                    cornish_corpus.compareSamplesLinear(
                    [self.kk_text_dict[self.names[self.textchoice.state()]]],
                    [self.names[self.textchoice.state()]],
                    comparelist, outlang=self.ifacelang)
            outputtext = wraplines(outputtext, self.wline)
            self.outbox.settext(outputtext)
            plt.show()
        if self.modechoice.state() == 7:
            comparelist = self.getcomparelist()
            if len(comparelist) == 0:
                comparelist = ['dhe', 'gans']
            self.outbox.text.config(bg='light yellow',
                                    fg='dark red',
                                    font=('Courier', 10 + self.fontsizeadj,
                                          'normal'))
            if self.textchoice.state() == 11:
                outputtext = str(comparelist)+'\n\n'+ \
                    cornish_corpus.concordances(
                        self.kk_texts, self.names, comparelist, 59, 25,
                        outlang=self.ifacelang)
            else:
                outputtext = str(comparelist)+'\n\n'+ \
                    cornish_corpus.concordances(
                    [self.kk_text_dict[self.names[self.textchoice.state()]]],
                    [self.names[self.textchoice.state()]],
                    comparelist, 59,25, outlang=self.ifacelang)
            outputtext = wraplines(outputtext, self.wline)
            self.outbox.settext(outputtext)
        if self.modechoice.state() == 8:
            comparelist = self.getcomparelist()
            regexlist = [
                "<.*><.*><.*><.*><a><vynn><.*><.*><.*>",
                "<.*><.*><.*><.*><a><wra><.*><.*><.*>",
                "<.*><.*><.*><y><fynn.*><.*><.*><.*>",
                "<.*><.*><.*><y><hwr.*><.*><.*><.*>"
            ]
            # find any comparelist items which begin and end in angle brackets
            comparelist = [
                c for c in comparelist if (c[0] == "<" and c[-1] == ">")
            ]
            if len(comparelist) > 0:
                regexlist = comparelist
            self.outbox.text.config(bg='light yellow',
                                    fg='dark red',
                                    font=('Courier', 10 + self.fontsizeadj,
                                          'normal'))
            if self.textchoice.state() == 11:
                outputtext = str(
                    regexlist) + '\n\n' + cornish_corpus.findallRegex(
                        self.kk_texts,
                        self.names,
                        regexlist,
                        outlang=self.ifacelang)
            else:
                outputtext = str(
                    regexlist
                ) + '\n\n' + cornish_corpus.findallRegex(
                    [self.kk_text_dict[self.names[self.textchoice.state()]]],
                    [self.names[self.textchoice.state()]],
                    regexlist,
                    outlang=self.ifacelang)
            outputtext = outputtext.replace("; ", "\n\n")
            outputtext = wraplines(outputtext, self.wline)
            self.outbox.settext(outputtext)

    def copyclipbd(self):
        self.clipboard_clear()
        self.clipboard_append(self.outbox.gettext())
Esempio n. 6
0
                        help="Netbook mode - for smaller screens.")
    args = parser.parse_args()
    if args.netbook:
        heightadjust = -4
        fontsizeadj = -1
    else:
        heightadjust = 0
        fontsizeadj = -1

    root = tk.Tk()
    root.title('Syllabenn Rhannu Cymraeg')
    mhead = tk.Label(root, text = "Dewisiadau")
    mhead.config(font=('Open Sans', 16+fontsizeadj, 'bold'))
    mhead.pack(side=tk.TOP, anchor=tk.NW)

    options = Radiobar(root, ['Mode Hir', 'Mode Byr', 'Mode Llinell'],
                       side=tk.TOP, anchor=tk.NW,default='Mode Byr')
    options.pack(side=tk.LEFT, fill=tk.Y)
    options.config(relief=tk.RIDGE, bd=2, padx=10, pady=10)

    options2 = Radiobar(options, ['Rhannu ymlaen', 'Rhannu yn ôl'],
                        side=tk.TOP, anchor=tk.NW, default='Rhannu yn ôl')
    options2.pack(side=tk.LEFT, fill=tk.Y)
    options2.config(pady=10)

    
    rhybudd = CheckButtonBar(options2, ['Rhybuddio os nac ydy\'r gair wedi defnyddio yn cyfan'], side=tk.TOP, anchor=tk.NW)
    rhybudd.pack(side=tk.LEFT, fill=tk.Y)        
    
    msg = tk.Label(root, text="Rhowch testun Cymraeg ar lawr os gwelwch yn dda:")
    msg.config(font=('Open Sans', 16+fontsizeadj, 'bold'))
    msg.pack()
Esempio n. 7
0
        fontsizeadj = 0

    root = tk.Tk()
    root.title('Inflektya Verbow Kernewek')
    mhead = tk.Label(root, text="Dewisyow")
    mhead.config(font=('Open Sans', 16, 'bold'))
    mhead.pack(side=tk.TOP, anchor=tk.NW)

    rhead = tk.Label(root, text="Amser")
    rhead.config(font=('Open Sans', 12, 'bold'))
    rhead.pack(side=tk.TOP, anchor=tk.NW)
    options = Radiobar(root, [
        'A-lemmyn', 'Tremenys', 'Anperfydh', 'Gorperfydh',
        'Islavarek A-lemmyn', 'Islavarek Anperfydh', 'Gorhemmyn', 'ppl',
        'Devedhek', 'Anperfydh Usadow', 'A-lemmyn Hir Indef', 'Anperfydh Hir',
        'A-lemmyn Hir Def', 'A-lemmyn Hir Aff', 'Perfydh'
    ],
                       font=('Open Sans', 13 + fontsizeadj, 'normal'),
                       side=tk.TOP,
                       anchor=tk.NW,
                       default='A-lemmyn')
    options.pack(side=tk.LEFT, fill=tk.Y)
    options.config(relief=tk.RIDGE, bd=2)

    rhead2 = tk.Label(root, text="Person")
    rhead2.config(font=('Open Sans', 12, 'bold'))
    rhead2.pack(side=tk.TOP, anchor=tk.NW)
    options2 = Radiobar(
        root,
        ['My', 'Ty', 'Ev', 'Hi', 'Ni', 'Hwi', 'I', 'Anpersonek', 'Pub Person'],
        font=('Open Sans', 13 + fontsizeadj, 'normal'),
        side=tk.TOP,
    def make_widgets(self):
        """ display the GUI widgets """
        self.mhead = tk.Label(self, text = "Dewisyow")
        self.mhead.config(font=('Open Sans', 16, 'bold'), padx=5, pady=5)
        self.mhead.pack(side=tk.TOP, anchor=tk.NW)
        # choose difficulty level        
        self.options2 = Radiobar(self, ['Es', 'Kres', 'Kales', 'Pur Gales'],
                                vals = [1, 2, 3, 4],
                                side=tk.TOP,
                                justify=tk.LEFT, anchor=tk.NW,
                                default=1)
        self.options2.pack(side=tk.LEFT, fill=tk.Y)
        self.options2.config(relief=tk.RIDGE, bd=2, padx=5)


        # choose whether to have addition, subtraction or either at random
        self.options = Radiobar(self.options2,
                                ['Keworra po marnas', 'Keworra', 'Marnas'],
                                side=tk.TOP,
                                justify=tk.LEFT, anchor=tk.NW,
                                default='Keworra po marnas')
        self.options.pack(side=tk.LEFT, fill=tk.Y)
        #self.options.config(relief=tk.RIDGE, bd=2, padx=0)
        self.options.config(padx=0, pady=10)

        self.kalettermsg = tk.Label(self.options,
                                    text="Gwask 'Dalleth'\nwosa chanjya\n"
                                    "an nivel kaletter\nrag dastalleth\n"
                                    "an apposyans.")
        self.kalettermsg.config(font=('Open Sans', 11), padx=5, pady=5)
        self.kalettermsg.pack(side=tk.TOP, fill=tk.Y)
        
        
        self.msg = tk.Label(self, text="Govynn:")
        self.msg.config(font=('Open Sans', 16, 'bold'), padx=10, pady=10)
        self.msg.pack(anchor=tk.W)
    
        # question
        self.govynn = tk.Label(self)
        self.govynn.pack(anchor=tk.W)
        self.govynn.config(fg = 'black', bg='light yellow',
                           font=('Open Sans', 18, 'bold'), text='',
                           padx=10, pady=10)
        self.govynn.pack(expand=tk.YES,fill=tk.BOTH, anchor=tk.CENTER)
    
        self.msg2 = tk.Label(self, text="Gorrewgh gorthyp yn bysies "
                             "a-woles mar pleg:")
        self.msg2.config(font=('Open Sans', 16, 'bold'),
                         padx=10, pady=10)
        self.msg2.pack(anchor=tk.W)
        # text entry bar for answer
        self.gorthyp = Entrybar(self)
        self.gorthyp.config(padx=10, pady=5)
        self.gorthyp.pack(anchor=tk.W)
        self.gorthyp.focus()
        # bind both Enter and the numeric keypad Enter
        self.master.bind('<Return>', lambda event: self.rigorthyp())
        self.master.bind('<KP_Enter>', lambda event: self.rigorthyp())

        # output
        self.msg3 = tk.Label(self)
        self.msg3.config(fg = 'dark red', bg='light yellow',
                         font=('Open Sans', 18, 'bold'),
                         text='', padx=10, pady=10)
        self.msg3.pack(expand=tk.YES,fill=tk.BOTH, anchor=tk.CENTER)

        # buttons
        Kwitya(self).pack(side=tk.RIGHT)
        tk.Button(self, text = 'Profya Gorthyp', font=('Open Sans',14),
                  command = self.rigorthyp).pack(side=tk.RIGHT)
        tk.Button(self, text = 'Dalleth', font=('Open Sans', 14),
                  command = self.dalleth).pack(side=tk.LEFT)
class AppAwgrym(tk.Frame):
    def __init__(self, parent=None):
        tk.Frame.__init__(self, parent)
        self.master.title("Apposyans Awgrym")
        self.pack()
        # initialise parameters
        self.niverewn = 0
        self.nivergwrys = 0
        self.poyntys = 0
        self.Ngovynn = 20
        self.gorthypkewar = 0
        self.make_widgets()
        self.dalleth()

    def make_widgets(self):
        """ display the GUI widgets """
        self.mhead = tk.Label(self, text = "Dewisyow")
        self.mhead.config(font=('Open Sans', 16, 'bold'), padx=5, pady=5)
        self.mhead.pack(side=tk.TOP, anchor=tk.NW)
        # choose difficulty level        
        self.options2 = Radiobar(self, ['Es', 'Kres', 'Kales', 'Pur Gales'],
                                vals = [1, 2, 3, 4],
                                side=tk.TOP,
                                justify=tk.LEFT, anchor=tk.NW,
                                default=1)
        self.options2.pack(side=tk.LEFT, fill=tk.Y)
        self.options2.config(relief=tk.RIDGE, bd=2, padx=5)


        # choose whether to have addition, subtraction or either at random
        self.options = Radiobar(self.options2,
                                ['Keworra po marnas', 'Keworra', 'Marnas'],
                                side=tk.TOP,
                                justify=tk.LEFT, anchor=tk.NW,
                                default='Keworra po marnas')
        self.options.pack(side=tk.LEFT, fill=tk.Y)
        #self.options.config(relief=tk.RIDGE, bd=2, padx=0)
        self.options.config(padx=0, pady=10)

        self.kalettermsg = tk.Label(self.options,
                                    text="Gwask 'Dalleth'\nwosa chanjya\n"
                                    "an nivel kaletter\nrag dastalleth\n"
                                    "an apposyans.")
        self.kalettermsg.config(font=('Open Sans', 11), padx=5, pady=5)
        self.kalettermsg.pack(side=tk.TOP, fill=tk.Y)
        
        
        self.msg = tk.Label(self, text="Govynn:")
        self.msg.config(font=('Open Sans', 16, 'bold'), padx=10, pady=10)
        self.msg.pack(anchor=tk.W)
    
        # question
        self.govynn = tk.Label(self)
        self.govynn.pack(anchor=tk.W)
        self.govynn.config(fg = 'black', bg='light yellow',
                           font=('Open Sans', 18, 'bold'), text='',
                           padx=10, pady=10)
        self.govynn.pack(expand=tk.YES,fill=tk.BOTH, anchor=tk.CENTER)
    
        self.msg2 = tk.Label(self, text="Gorrewgh gorthyp yn bysies "
                             "a-woles mar pleg:")
        self.msg2.config(font=('Open Sans', 16, 'bold'),
                         padx=10, pady=10)
        self.msg2.pack(anchor=tk.W)
        # text entry bar for answer
        self.gorthyp = Entrybar(self)
        self.gorthyp.config(padx=10, pady=5)
        self.gorthyp.pack(anchor=tk.W)
        self.gorthyp.focus()
        # bind both Enter and the numeric keypad Enter
        self.master.bind('<Return>', lambda event: self.rigorthyp())
        self.master.bind('<KP_Enter>', lambda event: self.rigorthyp())

        # output
        self.msg3 = tk.Label(self)
        self.msg3.config(fg = 'dark red', bg='light yellow',
                         font=('Open Sans', 18, 'bold'),
                         text='', padx=10, pady=10)
        self.msg3.pack(expand=tk.YES,fill=tk.BOTH, anchor=tk.CENTER)

        # buttons
        Kwitya(self).pack(side=tk.RIGHT)
        tk.Button(self, text = 'Profya Gorthyp', font=('Open Sans',14),
                  command = self.rigorthyp).pack(side=tk.RIGHT)
        tk.Button(self, text = 'Dalleth', font=('Open Sans', 14),
                  command = self.dalleth).pack(side=tk.LEFT)
        
    def chooseMaxN(self):
        """ based on difficulty choose maximum size of numbers """
        # easy allowed only numbers up to 10
        # and supresses negative answers to subtractions
        # medium up to 20, and hard up to 40
        maxNdict = {1: 10, 2: 20, 3:40, 4:100}
        return maxNdict[self.options2.state()]
        
    def choosemode(self):        
        """ set question mode depending on radio button
        either addition, subtraction or either randomly """
        if self.options.state() == "Keworra po marnas":
            self.qumode = "keworramarnas"
        else:
            self.qumode = self.options.state().lower()
        
    def allstates(self): print(self.options.state(), self.gorthyp.fetch())
    
    def diskwedhgovynn(self, tekst):
        """ display the question """
        self.govynn.config(fg = 'black', bg = 'light yellow',
                      font=('Open Sans', 18, 'bold'), text=tekst)
    
    def chekkGorthyp(self, g, kewar):
        """ check answer against the correct one,
            returning a bool and a message """
        try:
            g = int(g)
            if g == kewar:
                return True, "Ty a ros {}\nEwn os".format(g)
            else:
                return False, "Ty a ros {}\nKamm os".format(g)
        except:
            return False, "Nag yw {} niver".format(g)

    def keworra(self):
        """ ask an addition question """
        n = self.chooseMaxN()
        # random numbers in question
        x1 = math.ceil(random.random() * n)
        x2 = math.ceil(random.random() * n)
        # calculate answer
        keworrans = x1 + x2
        # store sum and answer as text and figures
        self.gorthyptekst = "{a} + {b} = {c}".format(a=niverow.numberkw(x1),
                                              b=niverow.numberkw(x2),
                                              c=niverow.numberkw(keworrans))
        self.gorthypbys = "{a} + {b} = {c}".format(a=x1, b=x2, c=keworrans)
        if self.options2.state() < 4:
            gov = "Pyth yw {a} ha {b}?".format(a=niverow.numberkw(x1),
                                               b=niverow.numberkw(x2))
        else:
            gov = "Pyth yw {a} + {b}?".format(a=niverow.numberkw(x1),
                                               b=niverow.numberkw(x2))
            
        gov = gov.replace("ha u","hag u")
        gov = gov.replace("ha e","hag e")
        gov = gov.replace("ha o","hag o")
        # display the question        
        self.diskwedhgovynn(gov)
        return keworrans


    
    def marnas(self):
        """ ask a subtraction question """
        n = self.chooseMaxN()
        # random numbers in question
        x1 = math.ceil(random.random() * n)
        x2 = math.ceil(random.random() * n)
        while self.options2.state() == 1 and x2 > x1:
            # choose again if difficulty is easy
            # and result is negative
            x1 = math.ceil(random.random() * n)
            x2 = math.ceil(random.random() * n)
        # calculate answer
        marnasyans = x1 - x2
        # store sum and answer as text and figures
        self.gorthyptekst = "{a} - {b} = {c}".format(a=niverow.numberkw(x1),
                                        b=niverow.numberkw(x2),
                                        c=niverow.numberkw_float(marnasyans))
        self.gorthypbys = "{a} - {b} = {c}".format(a=x1, b=x2, c=marnasyans)
        # display the question
        if self.options2.state() < 4:
            gov = "Pyth yw {a} marnas {b}?".format(a=niverow.numberkw(x1),
                                                   b=niverow.numberkw(x2))
        else:
            gov = "Pyth yw {a} - {b}?".format(a=niverow.numberkw(x1),
                                                   b=niverow.numberkw(x2))
        
        self.diskwedhgovynn(gov)
        return marnasyans
    
    def govynn1(self):
        """ ask a question, choosing addition or subtraction """
        self.starttime = time.time()
        self.choosemode()
        if self.qumode=="keworramarnas":
            g = random.choice([self.keworra, self.marnas])
        elif self.qumode == "marnas":
            g = self.marnas
        else:
            g = self.keworra
        return g()
        
    def rigorthyp(self):
        """ submit answer """
        self.allstates()
        if self.nivergwrys >= self.Ngovynn:
            return None
        try:
            niver = float(self.gorthyp.fetch())
            print(niver)
            self.nivergwrys += 1
            self.govynn.config(text='', padx=10, pady=10)
        except ValueError:            
            output = "Res yw gorra niver y'n kyst\n avel bysies,"
            " rag ensample '42'"
            print(output)
            self.msg3.config(fg = 'orange', bg='black',
                             font=('Open Sans', 18, 'bold'), text=output)
            niver = -99
        self.gorthyp.clear()
        if niver or niver==0:
            kewarder = self.chekkGorthyp(niver, self.gorthypkewar)        
            
            if kewarder[0]:
                # if answer was correct
                t = time.time() - self.starttime
                # increment total points by at least 1 point
                # and up to an extra 1 point for speed
                self.poyntys += max([(10.0-t)/10.0, 0]) + 1
                self.niverewn += 1
                tekst = ("{gt}\n{k}\n{t:.1f}s, {e}/{g},"
                " sommenn poyntys = {p:.2f}").format(gt=self.gorthyptekst,
                                                     k=kewarder[1], t=t,
                                                     p=self.poyntys,
                                                     e=self.niverewn,
                                                     g=self.nivergwrys)
                fcolour='dark green'
            else:
                # if the answer was wrong
                tekst = ("{gt}  {b}\n{k}\n{e}/{g},"
                " sommenn poyntys = {p:.2f}").format(k=kewarder[1],
                                                     gt=self.gorthyptekst,
                                                     b=self.gorthypbys,
                                                     p=self.poyntys,
                                                     e=self.niverewn,
                                                     g=self.nivergwrys)                
                fcolour='dark red'
            if niver != -99:
                # if a numeric input was given
                # i.e. don't go to next question if
                # a non-numeric answer was given
                print(tekst)
                self.msg3.config(fg = fcolour, bg = 'light yellow',
                                 font=('Open Sans', 18, 'bold'), text=tekst)
                if self.nivergwrys < self.Ngovynn:
                    # ask next question
                    self.gorthypkewar = self.govynn1()
                else:
                    # if required number of questions have been asked                
                    self.gorfenna()
                    
    def bonuspoyntys(self, bonus=5):
        """ points bonus for getting all correct """
        self.poyntys = self.poyntys + bonus
                     
        
    def gorfenna(self):
        """ give report of user's number correct, and score """
        if self.niverewn == self.Ngovynn:
            self.bonuspoyntys()
            bonusmsg  = ("\nKeslowena!\nTy a worthybis pub govynn yn ewn.\n"
            "Bonus a bymp poynt yw genes!\n")
        elif self.niverewn == 0:
            bonusmsg = ("\nTruan!\nTy a worthybis pub govynn yn kamm!\n"
            "Martesen kath a gerdhas a-dro dha vysowek!\n")
        else:
            bonusmsg = ""
        endmsg = ("Ty a wrug {e} kewar a {N}. {b}"
        "Dha skor yw {n:.2f} a boyntys").format(e = self.niverewn,
                                                N = self.Ngovynn,
                                                b = bonusmsg,
                                                n = self.poyntys)
        self.msg3.config(fg = 'blue', bg = 'light yellow',
                         font=('Open Sans', 18, 'bold'), text=endmsg)
        
    def dalleth(self):
        """ clear answer box, and reset parameters """
        self.gorthyp.clear()
        self.msg3.config(fg = 'dark red', bg='light yellow',
                         font=('Open Sans', 18, 'bold'), text='')
        self.niverewn = 0
        self.nivergwrys = 0
        self.poyntys = 0
        self.Ngovynn = 20        
        self.gorthypkewar = self.govynn1()
Esempio n. 10
0
        heightadj = 0
        wline = 60
    else:
        outputwidth = 80
        fontsizeadj = 0
        heightadj = 0
        wline = 80
    root = tk.Tk()
    root.title('Kovtreylyans Kernewek')
    mhead = tk.Label(root, text="Dewisyow")
    mhead.config(font=('Helvetica', 16, 'bold'))
    mhead.pack(side=tk.TOP, anchor=tk.NW)

    options = Radiobar(
        root, ['All trigrams and bigrams', 'Only N grams with a non-stopword'],
        side=tk.TOP,
        anchor=tk.NW,
        default='Only N grams with a non-stopword')
    options.pack(side=tk.LEFT, fill=tk.Y)
    options.config(relief=tk.RIDGE, bd=2, padx=5, pady=5)

    msg = tk.Label(root,
                   text="Write an English sentence in the box below please:")
    msg.config(font=('Helvetica', 16 + fontsizeadj, 'bold'))
    msg.pack(pady=10)

    # text entry bar for input
    ent = ScrolledText(root)
    ent.text.config(width=outputwidth, height=7 + heightadj)
    ent.pack(expand=0)