Skip to content

Commit 16c6e8f

Browse files
committed
tutro cb selectors done
1 parent 89d3d81 commit 16c6e8f

File tree

11 files changed

+166
-133
lines changed

11 files changed

+166
-133
lines changed

typetrainer/tutors/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
from typetrainer.i18n import _
44

5-
available_tutors = {
6-
'en.basic': _('Basic English'),
7-
'en.advanced': _('Advanced English'),
8-
'ru.basic': _('Basic Russian'),
9-
}
5+
from . import en, ru
6+
7+
available_tutors = (en, ru)
108

119
def get_filler(tutor, filename):
10+
fullname = tutor
11+
tutor, sep, level = tutor.partition('.')
12+
1213
package_name = 'typetrainer.tutors.' + tutor
1314
__import__(package_name)
1415
pkg = sys.modules[package_name]
@@ -18,8 +19,11 @@ def get_filler(tutor, filename):
1819
else:
1920
text = _(u'Choose file with words.')
2021

21-
filler = pkg.get_filler(text, None)
22+
filler = pkg.get_filler(text, level)
2223
filler.filename = filename
2324
filler.name = tutor
25+
filler.level = level
26+
filler.tutor = pkg
27+
filler.fullname = fullname
2428

2529
return filler
Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
import re
2-
from ..common import Filler
2+
from .common import Filler
3+
4+
from typetrainer.i18n import _
5+
6+
name = 'en'
7+
label = _('English')
8+
9+
levels = (
10+
('basic', _('Basic')),
11+
('advanced', _('Advanced')),
12+
# ('superb', _('Superb')),
13+
)
314

415
def make_lengths_seq(words):
516
for t, w in words:
@@ -9,9 +20,18 @@ def make_lengths_seq(words):
920
else:
1021
yield t, w
1122

12-
def split_to_words(text):
23+
def split_to_words(text, level):
1324
filter_non_word = re.compile('(?i)[^a-z\']+')
14-
for word in re.findall('(?i)[a-z\',.:;"]+', text):
25+
26+
charsets = {
27+
'basic': '(?i)[a-z\',]+',
28+
'advanced': '(?i)[a-z\',.:;"]+'
29+
}
30+
31+
if level == 'basic':
32+
text = text.lower()
33+
34+
for word in re.findall(charsets[level], text):
1535
non_word_cars = ',.:;"'
1636
esym = None
1737
for c in non_word_cars:
@@ -21,7 +41,7 @@ def split_to_words(text):
2141

2242
ssym = '"' if word.startswith('"') else None
2343

24-
word = filter_non_word.sub('', word)
44+
word = filter_non_word.sub('', word).strip("'")
2545
if word:
2646
if ssym:
2747
yield 's', ssym
@@ -31,8 +51,10 @@ def split_to_words(text):
3151

3252
yield 's', ' '
3353

34-
def get_filler(text, options):
35-
words = list(split_to_words(text))
54+
def get_filler(text, level):
55+
words = list(split_to_words(text, level))
3656
if not words:
37-
words = list(split_to_words(u'Tutor is empty. Select another or choose appropriate file.'))
57+
words = list(split_to_words(
58+
u'Tutor is empty. Select another or choose appropriate file.',
59+
level))
3860
return Filler(words, make_lengths_seq)

typetrainer/tutors/en/__init__.py

Whitespace-only changes.

typetrainer/tutors/en/basic.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

typetrainer/tutors/help.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def __init__(self, words):
3030
self.chain = make_word_chain(words, self.dist)
3131
self.name = 'help'
3232
self.filename = None
33+
self.tutor = None
34+
self.fullname = None
35+
self.level = None
3336

3437
def get_next_word(self, prev=None):
3538
try:

typetrainer/tutors/ru/basic.py renamed to typetrainer/tutors/ru.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# -*- coding: utf-8 -*-
22
import re
3-
from ..common import Filler
3+
from .common import Filler
4+
5+
from typetrainer.i18n import _
6+
7+
name = 'ru'
8+
label = _('Russian')
9+
10+
levels = (
11+
('basic', _('Basic')),
12+
# ('advanced', _('Advanced')),
13+
# ('superb', _('Superb')),
14+
)
415

516
def make_lengths_seq(words):
617
for t, w in words:
@@ -25,7 +36,7 @@ def split_to_words(text):
2536

2637
yield 's', ' '
2738

28-
def get_filler(text, options):
39+
def get_filler(text, level):
2940
words = list(split_to_words(text))
3041
if not words:
3142
words = list(split_to_words(u'Пустое упражнение. Выберите другое или загрузите '

typetrainer/tutors/ru/__init__.py

Whitespace-only changes.

typetrainer/ui/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import gtk, gobject
2+
import contextlib
23

34
def idle_callback(callable, args):
45
args, kwargs = args
@@ -16,6 +17,14 @@ def refresh_gui():
1617
while gtk.events_pending():
1718
gtk.main_iteration_do(block=False)
1819

20+
@contextlib.contextmanager
21+
def block_handler(obj, handler):
22+
obj.handler_block_by_func(handler)
23+
try:
24+
yield
25+
finally:
26+
obj.handler_unblock_by_func(handler)
27+
1928
class BuilderAware(object):
2029
def __init__(self, glade_file):
2130
self.gtk_builder = gtk.Builder()

typetrainer/ui/kbd.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
n130_gap = 0.12
1919
n130_keyboard = {
20+
'name': 'n130',
2021
'keys': [
2122
[49, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, backspace],
2223
[tab, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 51],
@@ -52,6 +53,7 @@
5253
}
5354

5455
n130_sdfv_keyboard = n130_keyboard.copy()
56+
n130_sdfv_keyboard['name'] = 'n130_sdfv'
5557
n130_sdfv_keyboard['zones'] = [
5658
([3, 4, 7, 9, 10, 13], [3, 1, 4, 5, 1, 3, 0]),
5759
([1, 3, 4, 6, 8, 9], [0, 3, 1, 4, 5, 1, 3]),
@@ -64,6 +66,7 @@
6466
]
6567

6668
n130_dvp_keyboard = n130_keyboard.copy()
69+
n130_dvp_keyboard['name'] = 'n130_dvp'
6770
n130_dvp_keyboard['zones'] = [
6871
([3, 4, 5, 7, 9, 10, 11, 13], [1, 2, 3, 4, 5, 1, 2, 3, 0]),
6972
([1, 2, 3, 4, 6, 8, 9, 10], [0, 1, 2, 3, 4, 5, 1, 2, 3]),

typetrainer/ui/main.glade

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<property name="window_position">center</property>
1111
<property name="default_width">800</property>
1212
<property name="type_hint">dialog</property>
13-
<signal name="button_press_event" handler="on_window_button_press_event"/>
1413
<signal name="key_release_event" handler="on_key_event"/>
1514
<signal name="key_press_event" handler="on_key_event"/>
1615
<signal name="delete_event" handler="on_window_delete_event"/>
@@ -96,7 +95,9 @@
9695
<object class="GtkLabel" id="label2">
9796
<property name="visible">True</property>
9897
<property name="xalign">0</property>
99-
<property name="label" translatable="yes">Tutor</property>
98+
<property name="label" translatable="yes">_Tutor</property>
99+
<property name="use_underline">True</property>
100+
<property name="mnemonic_widget">tutor_cb</property>
100101
<attributes>
101102
<attribute name="weight" value="bold"/>
102103
</attributes>
@@ -109,7 +110,7 @@
109110
<child>
110111
<object class="GtkComboBox" id="tutor_cb">
111112
<property name="visible">True</property>
112-
<property name="model">tutor_ls</property>
113+
<signal name="changed" handler="on_tutor_cb_changed"/>
113114
<child>
114115
<object class="GtkCellRendererText" id="cellrenderertext1"/>
115116
<attributes>
@@ -136,7 +137,9 @@
136137
<object class="GtkLabel" id="label3">
137138
<property name="visible">True</property>
138139
<property name="xalign">0</property>
139-
<property name="label" translatable="yes">Level</property>
140+
<property name="label" translatable="yes">_Level</property>
141+
<property name="use_underline">True</property>
142+
<property name="mnemonic_widget">level_cb</property>
140143
<attributes>
141144
<attribute name="weight" value="bold"/>
142145
</attributes>
@@ -149,7 +152,7 @@
149152
<child>
150153
<object class="GtkComboBox" id="level_cb">
151154
<property name="visible">True</property>
152-
<property name="model">level_ls</property>
155+
<signal name="changed" handler="on_level_cb_changed"/>
153156
<child>
154157
<object class="GtkCellRendererText" id="cellrenderertext2"/>
155158
<attributes>
@@ -176,7 +179,9 @@
176179
<object class="GtkLabel" id="label4">
177180
<property name="visible">True</property>
178181
<property name="xalign">0</property>
179-
<property name="label" translatable="yes">Layout</property>
182+
<property name="label" translatable="yes">L_ayout</property>
183+
<property name="use_underline">True</property>
184+
<property name="mnemonic_widget">layout_cb</property>
180185
<attributes>
181186
<attribute name="weight" value="bold"/>
182187
</attributes>
@@ -189,7 +194,7 @@
189194
<child>
190195
<object class="GtkComboBox" id="layout_cb">
191196
<property name="visible">True</property>
192-
<property name="model">layout_ls</property>
197+
<signal name="changed" handler="on_layout_cb_changed"/>
193198
<child>
194199
<object class="GtkCellRendererText" id="cellrenderertext3"/>
195200
<attributes>
@@ -220,6 +225,7 @@
220225
<property name="visible">True</property>
221226
<property name="can_focus">True</property>
222227
<property name="receives_default">True</property>
228+
<signal name="clicked" handler="on_open_bt_clicked"/>
223229
<child>
224230
<object class="GtkLabel" id="label6">
225231
<property name="visible">True</property>
@@ -302,7 +308,8 @@
302308
<child type="label">
303309
<object class="GtkLabel" id="label1">
304310
<property name="visible">True</property>
305-
<property name="label" translatable="yes">Misc</property>
311+
<property name="label" translatable="yes">_Misc</property>
312+
<property name="use_underline">True</property>
306313
</object>
307314
</child>
308315
</object>
@@ -314,28 +321,4 @@
314321
</object>
315322
</child>
316323
</object>
317-
<object class="GtkListStore" id="tutor_ls">
318-
<columns>
319-
<!-- column-name id -->
320-
<column type="gchararray"/>
321-
<!-- column-name name -->
322-
<column type="gchararray"/>
323-
</columns>
324-
</object>
325-
<object class="GtkListStore" id="level_ls">
326-
<columns>
327-
<!-- column-name id -->
328-
<column type="gchararray"/>
329-
<!-- column-name name -->
330-
<column type="gchararray"/>
331-
</columns>
332-
</object>
333-
<object class="GtkListStore" id="layout_ls">
334-
<columns>
335-
<!-- column-name id -->
336-
<column type="gchararray"/>
337-
<!-- column-name name -->
338-
<column type="gchararray"/>
339-
</columns>
340-
</object>
341324
</interface>

0 commit comments

Comments
 (0)