コード例 #1
0
ファイル: run.py プロジェクト: mattharrison/typetrainer
def run():
    from optparse import OptionParser
    from typetrainer import VERSION
    from typetrainer.i18n import _
    from typetrainer.config import Config

    parser = OptionParser(usage=_("%prog [options] [file_with_words]"),
        version="%prog " + VERSION)
    parser.add_option("-t", "--tutor", dest="tutor",
        help=_("Tutor maker to use (en.basic, en.advanced, ru.basic). Default is en.basic"),
        metavar="tutor")

    options, args = parser.parse_args()
    config = Config()
    config.load('config')

    if options.tutor:
        config['TUTOR'] = options.tutor

    if args:
        config['FILE'] = args[0]

    if 'FILE' in config:
        from typetrainer.tutors import get_filler
        try:
            filler = get_filler(config['TUTOR'], config['FILE'])
            config._add_recent_file(config['FILE'])
        except ImportError:
            parser.error(_("Can't find [%s] tutor") % config['TUTOR'])
        except IOError:
            parser.error(_("Can't read [%s]") % config['FILE'])
    else:
        import tutors.help
        filler = tutors.help.get_filler()

    import gtk
    import os.path

    from typetrainer.ui import idle
    from typetrainer.ui.main import Main
    from typetrainer.ui import kbd
    from typetrainer.stat import FileStatistic
    from typetrainer.util import make_missing_dirs, join_to_data_dir

    fake_stat = join_to_data_dir('fake_stat')
    make_missing_dirs(fake_stat)
    stat = FileStatistic(os.path.dirname(fake_stat))

    kbd_layout = getattr(kbd, config['KEYBOARD'] + '_keyboard')
    print "KEYBOARD", kbd_layout
    app = Main(config, filler, stat, kbd.KeyboardDrawer(kbd_layout))
    app.window.show()
    idle(app.fill)

    try:
        gtk.main()
    except KeyboardInterrupt:
        pass
コード例 #2
0
ファイル: main.py プロジェクト: rodrigoieh/typetrainer
    def update_filler(self, tutor, filename):
        self.totype_entry.set_text(_('Opening...'))
        refresh_gui()

        self.filler = get_filler(tutor, filename)
        self.fill()
        self.fill_tutors()
        self.config._add_recent_file(filename)
        self.update_title()

        self.config['TUTOR'] = tutor
        self.config['FILE'] = filename
コード例 #3
0
ファイル: main.py プロジェクト: Velesey/typetrainer
    def update_filler(self, tutor, filename):
        self.totype_entry.set_text(_('Opening...'))
        refresh_gui()

        self.filler = get_filler(tutor, filename)
        self.fill()
        self.fill_tutors()
        self.config._add_recent_file(filename)
        self.update_title()

        self.config['TUTOR'] = tutor
        self.config['FILE'] = filename
コード例 #4
0
ファイル: main.py プロジェクト: Velesey/typetrainer
    def on_open_bt_clicked(self, *args):
        dialog = gtk.FileChooserDialog(_("Open file..."),
            None,
            gtk.FILE_CHOOSER_ACTION_OPEN,
            (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
            gtk.STOCK_OPEN, gtk.RESPONSE_OK))

        dialog.set_default_response(gtk.RESPONSE_OK)

        response = dialog.run()
        if response == gtk.RESPONSE_OK:
            idle(self.update_filler, self.get_tutor_for_file(dialog.get_filename()),
                dialog.get_filename())

        dialog.destroy()
コード例 #5
0
ファイル: main.py プロジェクト: rodrigoieh/typetrainer
    def on_open_bt_clicked(self, *args):
        dialog = gtk.FileChooserDialog(_("Open file..."), None,
                                       gtk.FILE_CHOOSER_ACTION_OPEN,
                                       (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                        gtk.STOCK_OPEN, gtk.RESPONSE_OK))

        dialog.set_default_response(gtk.RESPONSE_OK)

        response = dialog.run()
        if response == gtk.RESPONSE_OK:
            idle(self.update_filler,
                 self.get_tutor_for_file(dialog.get_filename()),
                 dialog.get_filename())

        dialog.destroy()
コード例 #6
0
def get_filler(tutor, filename):
    fullname = tutor
    tutor, sep, level = tutor.partition('.')

    package_name = 'typetrainer.tutors.' + tutor
    __import__(package_name)
    pkg = sys.modules[package_name]

    if filename:
        text = open(filename).read().decode('utf-8')
    else:
        text = _(u'Choose file with words.')

    filler = pkg.get_filler(text, level)
    filler.filename = filename
    filler.name = tutor
    filler.level = level
    filler.tutor = pkg
    filler.fullname = fullname

    return filler
コード例 #7
0
ファイル: __init__.py プロジェクト: Velesey/typetrainer
def get_filler(tutor, filename):
    fullname = tutor
    tutor, sep, level = tutor.partition('.')

    package_name = 'typetrainer.tutors.' + tutor
    __import__(package_name)
    pkg = sys.modules[package_name]

    if filename:
        text = open(filename).read().decode('utf-8')
    else:
        text = _(u'Choose file with words.')

    filler = pkg.get_filler(text, level)
    filler.filename = filename
    filler.name = tutor
    filler.level = level
    filler.tutor = pkg
    filler.fullname = fullname

    return filler
コード例 #8
0
ファイル: en.py プロジェクト: Velesey/typetrainer
import re
from .common import Filler

from typetrainer.i18n import _

name = 'en'
label = _('English')

levels = (
    ('basic', _('Basic')),
    ('advanced', _('Advanced')),
#    ('superb', _('Superb')),
)

def make_lengths_seq(words):
    for t, w in words:
        if t == 'w':
            wlen = len(w)
            yield 'w', wlen if wlen <= 3 else wlen + 3
        else:
            yield t, w

def split_to_words(text, level):
    filter_non_word = re.compile('(?i)[^a-z\']+')

    charsets = {
        'basic': '(?i)[a-z\',]+',
        'advanced': '(?i)[a-z\',.:;"]+'
    }

    if level == 'basic':
コード例 #9
0
ファイル: ru.py プロジェクト: rodrigoieh/typetrainer
# -*- coding: utf-8 -*-
import re
from .common import Filler

from typetrainer.i18n import _

name = 'ru'
label = _('Russian')

levels = (
    ('basic', _('Basic')),
    ('advanced', _('Advanced')),
    #    ('superb', _('Superb')),
)


def make_lengths_seq(words):
    for t, w in words:
        if t == 'w':
            wlen = len(w)
            yield 'w', wlen
        else:
            yield t, w


def split_to_words(text, level):
    filter_non_word = re.compile(u'(?iu)[^а-я]+')

    charsets = {'basic': u'(?iu)[а-я]+', 'advanced': u'(?iu)[а-я,.:;"!]+'}

    if level == 'basic':
コード例 #10
0
import re
from .common import Filler

from typetrainer.i18n import _

name = 'en'
label = _('English')

levels = (
    ('basic', _('Basic')),
    ('advanced', _('Advanced')),
    #    ('superb', _('Superb')),
)


def make_lengths_seq(words):
    for t, w in words:
        if t == 'w':
            wlen = len(w)
            yield 'w', wlen if wlen <= 3 else wlen + 3
        else:
            yield t, w


def split_to_words(text, level):
    filter_non_word = re.compile('(?i)[^a-z\']+')

    charsets = {'basic': '(?i)[a-z\',]+', 'advanced': '(?i)[a-z\',.:;"]+'}

    if level == 'basic':
        text = text.lower()
コード例 #11
0
# -*- coding: utf-8 -*-
import re
from .common import Filler

from typetrainer.i18n import _

name = 'uk'
label = _('Ukraine')

levels = (
    ('basic', _('Basic')),
    ('advanced', _('Advanced')),
#    ('superb', _('Superb')),
)

def make_lengths_seq(words):
    for t, w in words:
        if t == 'w':
            wlen = len(w)
            yield 'w', wlen
        else:
            yield t, w

def split_to_words(text, level):
    filter_non_word = re.compile(u'(?iu)[^а-я\'ієїґ]+')

    charsets = {
        'basic': u'(?iu)[а-я\'ієїґ]+',
        'advanced': u'(?iu)[а-я\'ієїґ,.:;"!]+'
    }
コード例 #12
0
ファイル: help.py プロジェクト: Velesey/typetrainer
# -*- coding: utf-8 -*-
import random
import re

from typetrainer.generator import make_word_chain
from typetrainer.i18n import _

help_text = _(u'Expand misc panel and open file with words. Press Ctrl+O and choose file with words.')

def split_to_words(text):
    filter_non_word = re.compile(u'(?ui)[^a-zа-я\'+]+')
    for word in re.findall(u'(?iu)[a-zа-я\',.+"]+', text):
        non_word_cars = ',.'
        esym = None
        for c in non_word_cars:
            if word.endswith(c):
                esym = c
                break

        word = filter_non_word.sub('', word)
        if word:
            yield 'w', word
            if esym:
                yield 's', esym

class Filler(object):
    def __init__(self, words):
        self.dist = {}
        self.chain = make_word_chain(words, self.dist)
        self.name = 'help'
        self.filename = None
コード例 #13
0
ファイル: main.py プロジェクト: rodrigoieh/typetrainer
import time
from collections import defaultdict, deque

import gtk, glib
import pango

from typetrainer.i18n import _
from typetrainer.ui import idle, refresh_gui, BuilderAware, block_handler, ShortcutActivator
from typetrainer.util import join_to_file_dir
from typetrainer.tutors import available_tutors, get_filler
from typetrainer.ui.kbd import n130_dvp_keyboard, n130_keyboard, n130_sdfv_keyboard, anti_rsi_keyboard

available_keyboards = (
    (n130_keyboard, _('ASDF zones')),
    (n130_sdfv_keyboard, _('SDFV zones')),
    (n130_dvp_keyboard, _('Programmer Dvorak zones')),
    (anti_rsi_keyboard, _('Anti-RSI zones')),
)

RHYTHM_ERROR_THRESHOLD = 1.7  # Miss value from average time gap between chars
TYPO_ERROR_WEIGHT = 1.0
RHYTHM_ERROR_WEIGHT = 0.7
CORRECT_WEIGHT = 1.0
CHARS_HISTORY_LENGTH = 500
RETYPE_THRESHOLD = 0.3  # error/correct relation


class Main(BuilderAware):
    """glade-file: main.glade"""
    def __init__(self, config, filler, stat, kbd_drawer):
        BuilderAware.__init__(self, join_to_file_dir(__file__, 'main.glade'))
コード例 #14
0
# -*- coding: utf-8 -*-
import random
import re

from typetrainer.generator import make_word_chain
from typetrainer.i18n import _

help_text = _(
    u'Expand misc panel and open file with words. Press Ctrl+O and choose file with words.'
)


def split_to_words(text):
    filter_non_word = re.compile(u'(?ui)[^a-zа-я\'+]+')
    for word in re.findall(u'(?iu)[a-zа-я\',.+"]+', text):
        non_word_cars = ',.'
        esym = None
        for c in non_word_cars:
            if word.endswith(c):
                esym = c
                break

        word = filter_non_word.sub('', word)
        if word:
            yield 'w', word
            if esym:
                yield 's', esym


class Filler(object):
    def __init__(self, words):
コード例 #15
0
ファイル: ru.py プロジェクト: gth158a/typetrainer
# -*- coding: utf-8 -*-
import re
from .common import Filler

from typetrainer.i18n import _

name = "ru"
label = _("Russian")

levels = (
    ("basic", _("Basic")),
    ("advanced", _("Advanced")),
    #    ('superb', _('Superb')),
)


def make_lengths_seq(words):
    for t, w in words:
        if t == "w":
            wlen = len(w)
            yield "w", wlen
        else:
            yield t, w


def split_to_words(text, level):
    filter_non_word = re.compile(u"(?iu)[^а-я]+")

    charsets = {"basic": u"(?iu)[а-я]+", "advanced": u'(?iu)[а-я,.:;"!]+'}

    if level == "basic":
コード例 #16
0
ファイル: run.py プロジェクト: rodrigoieh/typetrainer
def run():
    from optparse import OptionParser
    from typetrainer import VERSION
    from typetrainer.i18n import _
    from typetrainer.config import Config

    parser = OptionParser(usage=_("%prog [options] [file_with_words]"),
                          version="%prog " + VERSION)
    parser.add_option(
        "-t",
        "--tutor",
        dest="tutor",
        help=
        _("Tutor maker to use (en.basic, en.advanced, ru.basic). Default is en.basic"
          ),
        metavar="tutor")

    options, args = parser.parse_args()
    config = Config()
    config.load('config')

    if options.tutor:
        config['TUTOR'] = options.tutor

    if args:
        config['FILE'] = args[0]

    if 'FILE' in config:
        from typetrainer.tutors import get_filler
        try:
            filler = get_filler(config['TUTOR'], config['FILE'])
            config._add_recent_file(config['FILE'])
        except ImportError:
            parser.error(_("Can't find [%s] tutor") % config['TUTOR'])
        except IOError:
            parser.error(_("Can't read [%s]") % config['FILE'])
    else:
        import tutors.help
        filler = tutors.help.get_filler()

    import gtk
    import os.path

    from typetrainer.ui import idle
    from typetrainer.ui.main import Main
    from typetrainer.ui import kbd
    from typetrainer.stat import FileStatistic
    from typetrainer.util import make_missing_dirs, join_to_data_dir

    fake_stat = join_to_data_dir('fake_stat')
    make_missing_dirs(fake_stat)
    stat = FileStatistic(os.path.dirname(fake_stat))

    kbd_layout = getattr(kbd, config['KEYBOARD'] + '_keyboard')
    app = Main(config, filler, stat, kbd.KeyboardDrawer(kbd_layout))
    app.window.show()
    idle(app.fill)

    try:
        gtk.main()
    except KeyboardInterrupt:
        pass
コード例 #17
0
ファイル: main.py プロジェクト: Velesey/typetrainer
import time
from collections import defaultdict, deque

import gtk, glib
import pango

from typetrainer.i18n import _
from typetrainer.ui import idle, refresh_gui, BuilderAware, block_handler, ShortcutActivator
from typetrainer.util import join_to_file_dir
from typetrainer.tutors import available_tutors, get_filler
from typetrainer.ui.kbd import n130_dvp_keyboard, n130_keyboard, n130_sdfv_keyboard, anti_rsi_keyboard

available_keyboards = (
    (n130_keyboard, _('ASDF zones')),
    (n130_sdfv_keyboard, _('SDFV zones')),
    (n130_dvp_keyboard, _('Programmer Dvorak zones')),
	(anti_rsi_keyboard, _('Anti-RSI zones')),
)

RHYTHM_ERROR_THRESHOLD = 1.7   # Miss value from average time gap between chars
TYPO_ERROR_WEIGHT = 1.0
RHYTHM_ERROR_WEIGHT = 0.7
CORRECT_WEIGHT = 1.0
CHARS_HISTORY_LENGTH = 500
RETYPE_THRESHOLD = 0.3        # error/correct relation

class Main(BuilderAware):
    """glade-file: main.glade"""

    def __init__(self, config, filler, stat, kbd_drawer):
        BuilderAware.__init__(self, join_to_file_dir(__file__, 'main.glade'))