Permalink
Browse files

tutro cb selectors done

  • Loading branch information...
1 parent 89d3d81 commit 16c6e8f97526731c1d8439d2012d45955fb10cb7 @baverman committed Feb 14, 2011
@@ -2,13 +2,14 @@
from typetrainer.i18n import _
-available_tutors = {
- 'en.basic': _('Basic English'),
- 'en.advanced': _('Advanced English'),
- 'ru.basic': _('Basic Russian'),
-}
+from . import en, ru
+
+available_tutors = (en, ru)
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]
@@ -18,8 +19,11 @@ def get_filler(tutor, filename):
else:
text = _(u'Choose file with words.')
- filler = pkg.get_filler(text, None)
+ filler = pkg.get_filler(text, level)
filler.filename = filename
filler.name = tutor
+ filler.level = level
+ filler.tutor = pkg
+ filler.fullname = fullname
return filler
@@ -0,0 +1,60 @@
+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()
+
+ for word in re.findall(charsets[level], text):
+ non_word_cars = ',.:;"'
+ esym = None
+ for c in non_word_cars:
+ if word.endswith(c):
+ esym = c
+ break
+
+ ssym = '"' if word.startswith('"') else None
+
+ word = filter_non_word.sub('', word).strip("'")
+ if word:
+ if ssym:
+ yield 's', ssym
+ yield 'w', word
+ if esym:
+ yield 's', esym
+
+ yield 's', ' '
+
+def get_filler(text, level):
+ words = list(split_to_words(text, level))
+ if not words:
+ words = list(split_to_words(
+ u'Tutor is empty. Select another or choose appropriate file.',
+ level))
+ return Filler(words, make_lengths_seq)
No changes.
@@ -1,38 +0,0 @@
-import re
-from ..common import Filler
-
-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):
- filter_non_word = re.compile('(?i)[^a-z\']+')
- for word in re.findall('(?i)[a-z\',.:;"]+', text):
- non_word_cars = ',.:;"'
- esym = None
- for c in non_word_cars:
- if word.endswith(c):
- esym = c
- break
-
- ssym = '"' if word.startswith('"') else None
-
- word = filter_non_word.sub('', word)
- if word:
- if ssym:
- yield 's', ssym
- yield 'w', word
- if esym:
- yield 's', esym
-
- yield 's', ' '
-
-def get_filler(text, options):
- words = list(split_to_words(text))
- if not words:
- words = list(split_to_words(u'Tutor is empty. Select another or choose appropriate file.'))
- return Filler(words, make_lengths_seq)
@@ -1,31 +0,0 @@
-import re
-from ..common import Filler
-
-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):
- for word in re.findall('(?i)[a-z\',]+', text.lower()):
- syms = []
- if word.endswith(','):
- syms.append(',')
-
- word = word.replace(',', '').strip("'")
- if word:
- yield 'w', word
- if syms:
- for s in syms:
- yield 's', s
-
- yield 's', ' '
-
-def get_filler(text, options):
- words = list(split_to_words(text))
- if not words:
- words = list(split_to_words(u'Tutor is empty. Select another or choose appropriate file.'))
- return Filler(words, make_lengths_seq)
@@ -30,6 +30,9 @@ def __init__(self, words):
self.chain = make_word_chain(words, self.dist)
self.name = 'help'
self.filename = None
+ self.tutor = None
+ self.fullname = None
+ self.level = None
def get_next_word(self, prev=None):
try:
@@ -1,6 +1,17 @@
# -*- coding: utf-8 -*-
import re
-from ..common import Filler
+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:
@@ -25,7 +36,7 @@ def split_to_words(text):
yield 's', ' '
-def get_filler(text, options):
+def get_filler(text, level):
words = list(split_to_words(text))
if not words:
words = list(split_to_words(u'Пустое упражнение. Выберите другое или загрузите '
No changes.
@@ -1,4 +1,5 @@
import gtk, gobject
+import contextlib
def idle_callback(callable, args):
args, kwargs = args
@@ -16,6 +17,14 @@ def refresh_gui():
while gtk.events_pending():
gtk.main_iteration_do(block=False)
+@contextlib.contextmanager
+def block_handler(obj, handler):
+ obj.handler_block_by_func(handler)
+ try:
+ yield
+ finally:
+ obj.handler_unblock_by_func(handler)
+
class BuilderAware(object):
def __init__(self, glade_file):
self.gtk_builder = gtk.Builder()
@@ -17,6 +17,7 @@
n130_gap = 0.12
n130_keyboard = {
+ 'name': 'n130',
'keys': [
[49, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, backspace],
[tab, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 51],
@@ -52,6 +53,7 @@
}
n130_sdfv_keyboard = n130_keyboard.copy()
+n130_sdfv_keyboard['name'] = 'n130_sdfv'
n130_sdfv_keyboard['zones'] = [
([3, 4, 7, 9, 10, 13], [3, 1, 4, 5, 1, 3, 0]),
([1, 3, 4, 6, 8, 9], [0, 3, 1, 4, 5, 1, 3]),
@@ -64,6 +66,7 @@
]
n130_dvp_keyboard = n130_keyboard.copy()
+n130_dvp_keyboard['name'] = 'n130_dvp'
n130_dvp_keyboard['zones'] = [
([3, 4, 5, 7, 9, 10, 11, 13], [1, 2, 3, 4, 5, 1, 2, 3, 0]),
([1, 2, 3, 4, 6, 8, 9, 10], [0, 1, 2, 3, 4, 5, 1, 2, 3]),
@@ -10,7 +10,6 @@
<property name="window_position">center</property>
<property name="default_width">800</property>
<property name="type_hint">dialog</property>
- <signal name="button_press_event" handler="on_window_button_press_event"/>
<signal name="key_release_event" handler="on_key_event"/>
<signal name="key_press_event" handler="on_key_event"/>
<signal name="delete_event" handler="on_window_delete_event"/>
@@ -96,7 +95,9 @@
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="xalign">0</property>
- <property name="label" translatable="yes">Tutor</property>
+ <property name="label" translatable="yes">_Tutor</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">tutor_cb</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
@@ -109,7 +110,7 @@
<child>
<object class="GtkComboBox" id="tutor_cb">
<property name="visible">True</property>
- <property name="model">tutor_ls</property>
+ <signal name="changed" handler="on_tutor_cb_changed"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<attributes>
@@ -136,7 +137,9 @@
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="xalign">0</property>
- <property name="label" translatable="yes">Level</property>
+ <property name="label" translatable="yes">_Level</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">level_cb</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
@@ -149,7 +152,7 @@
<child>
<object class="GtkComboBox" id="level_cb">
<property name="visible">True</property>
- <property name="model">level_ls</property>
+ <signal name="changed" handler="on_level_cb_changed"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext2"/>
<attributes>
@@ -176,7 +179,9 @@
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="xalign">0</property>
- <property name="label" translatable="yes">Layout</property>
+ <property name="label" translatable="yes">L_ayout</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">layout_cb</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
@@ -189,7 +194,7 @@
<child>
<object class="GtkComboBox" id="layout_cb">
<property name="visible">True</property>
- <property name="model">layout_ls</property>
+ <signal name="changed" handler="on_layout_cb_changed"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext3"/>
<attributes>
@@ -220,6 +225,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
+ <signal name="clicked" handler="on_open_bt_clicked"/>
<child>
<object class="GtkLabel" id="label6">
<property name="visible">True</property>
@@ -302,7 +308,8 @@
<child type="label">
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
- <property name="label" translatable="yes">Misc</property>
+ <property name="label" translatable="yes">_Misc</property>
+ <property name="use_underline">True</property>
</object>
</child>
</object>
@@ -314,28 +321,4 @@
</object>
</child>
</object>
- <object class="GtkListStore" id="tutor_ls">
- <columns>
- <!-- column-name id -->
- <column type="gchararray"/>
- <!-- column-name name -->
- <column type="gchararray"/>
- </columns>
- </object>
- <object class="GtkListStore" id="level_ls">
- <columns>
- <!-- column-name id -->
- <column type="gchararray"/>
- <!-- column-name name -->
- <column type="gchararray"/>
- </columns>
- </object>
- <object class="GtkListStore" id="layout_ls">
- <columns>
- <!-- column-name id -->
- <column type="gchararray"/>
- <!-- column-name name -->
- <column type="gchararray"/>
- </columns>
- </object>
</interface>
Oops, something went wrong.

0 comments on commit 16c6e8f

Please sign in to comment.