def __init__(self, config, filler, stat, kbd_drawer): BuilderAware.__init__(self, join_to_file_dir(__file__, 'main.glade')) self.config = config self.filler = filler self.stat = stat self.kbd_drawer = kbd_drawer self.typed_chars = deque([], CHARS_HISTORY_LENGTH) self.errors = defaultdict(float) self.vbox.pack_start(self.kbd_drawer, True, True) self.vbox.reorder_child(self.kbd_drawer, 3) self.kbd_drawer.set_size_request(-1, 280) self.kbd_drawer.show() self.tutor_ls = gtk.ListStore(object, str) self.tutor_cb.set_model(self.tutor_ls) self.level_ls = gtk.ListStore(str, str) self.level_cb.set_model(self.level_ls) self.layout_ls = gtk.ListStore(object, str) self.layout_cb.set_model(self.layout_ls) self.update_title() self.activator = ShortcutActivator(self.window) self.activator.bind('<ctrl>q', self.quit) self.activator.bind('<ctrl>s', self.on_stat_bt_clicked) self.activator.bind('<ctrl>r', self.on_recent_bt_clicked) self.activator.bind('<ctrl>o', self.on_open_bt_clicked) idle(self.fill_tutors) idle(self.fill_layouts)
def on_level_cb_changed(self, sender): level = self.get_selected_item(sender) if level: tutor = self.get_selected_item(self.tutor_cb) tutor = '%s.%s' % (tutor.name, level) self.config._set_tutor_for_file(self.filler.filename, tutor) idle(self.update_filler, tutor, self.filler.filename)
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
def on_tutor_cb_changed(self, sender): tutor = self.get_selected_item(sender) if tutor: self.fill_levels() level = self.get_selected_item(self.level_cb) if not level: level = tutor.levels[0][0] tutor = '%s.%s' % (tutor.name, level) self.config._set_tutor_for_file(self.filler.filename, tutor) idle(self.update_filler, tutor, self.filler.filename)
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()
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
def on_layout_cb_changed(self, sender): kbd = self.get_selected_item(sender) if kbd: self.config['KEYBOARD'] = kbd['name'] idle(self.kbd_drawer.set_keyboard, kbd) self.type_entry.grab_focus()
def on_filename_activate(self, item, filename): idle(self.update_filler, self.get_tutor_for_file(filename), filename)