From 3b1aa3c4d6b4aaa75ed51faf338deb6061afe370 Mon Sep 17 00:00:00 2001 From: Denis Fomin Date: Fri, 17 Sep 2010 17:59:26 +0400 Subject: [PATCH] 'wrong layout' plugin added --- wrong_layout/__init__.py | 1 + .../locale/ru/LC_MESSAGES/WrongLayout.mo | Bin 0 -> 863 bytes wrong_layout/plugin.py | 138 ++++++++++++++++++ wrong_layout/po/Makefile | 34 +++++ wrong_layout/po/WrongLayout.po | 23 +++ wrong_layout/po/WrongLayout.pot | 22 +++ 6 files changed, 218 insertions(+) create mode 100644 wrong_layout/__init__.py create mode 100644 wrong_layout/locale/ru/LC_MESSAGES/WrongLayout.mo create mode 100644 wrong_layout/plugin.py create mode 100644 wrong_layout/po/Makefile create mode 100644 wrong_layout/po/WrongLayout.po create mode 100644 wrong_layout/po/WrongLayout.pot diff --git a/wrong_layout/__init__.py b/wrong_layout/__init__.py new file mode 100644 index 0000000..c257f6f --- /dev/null +++ b/wrong_layout/__init__.py @@ -0,0 +1 @@ +from plugin import WrongLayoutPlugin diff --git a/wrong_layout/locale/ru/LC_MESSAGES/WrongLayout.mo b/wrong_layout/locale/ru/LC_MESSAGES/WrongLayout.mo new file mode 100644 index 0000000000000000000000000000000000000000..c89a7998c12a854ed1efc1b93a14a291c2550e50 GIT binary patch literal 863 zcmZuuO>fgc5H$!cIdbMOM^LiCX)9FRP(j-uRcb_tBH+5j8)KC0M)s!A3u?-tNPP6f znZJ;x2~AS!{)P1)K>QTmI#i(&n~Zj6=FOWo<6pOKd~8;1XtV>z5!B;uHOTjwLvikeF9ibzxQHIHJ_dtKpEDCupaWI%1cr+S*| zy|}zykpXJe8`0Ek+h@;36o*QB^ui){GGMMQx+>DF8V8}zHhMwK8p@+w?P-H;MuKY; zur02IM@w$WW$pv!u2AW|x8&yC71srj)x~aTiT{sV&b!ON?eJK$M#N>@=2}G_Jy9Kq z-V!p5sob)TFCKMx*e*uBb--oN0cFJ-L6&^W0i_-Zc|AuBsyU$9%=DT z-|Mz{DA(rO68d3Jx7g|eXBD+X#456>{7?oSt-cC%?j@@!;fI=X$qdO{m;~`L-uNYEWCnzy zv6-cPTU@Y-G2Wl&EsoL6GM=ZO%=8~5-9g_oD`bew2m~O##DN49SvnImLnGU4N+|jX z9CV_^(OoNNj1J?!S|;a`c literal 0 HcmV?d00001 diff --git a/wrong_layout/plugin.py b/wrong_layout/plugin.py new file mode 100644 index 0000000..8706604 --- /dev/null +++ b/wrong_layout/plugin.py @@ -0,0 +1,138 @@ +# -*- coding: utf-8 -*- + +import gtk +import os +import gettext +from common import helpers +from common import gajim + +from plugins import GajimPlugin +from plugins.helpers import log_calls, log + + +locale_path = os.path.dirname(__file__) + '/locale' +try: + gett = gettext.Catalog('WrongLayout', locale_path) + _ = gett.gettext +except: pass + + +class WrongLayoutPlugin(GajimPlugin): + name = u'Wrong Layout' + short_name = u'Wrong Layout' + version = u'0.1' + description = _(u'''Press alt+r to convert chars typed in wrong layout Rus<>Eng''') + authors = [u'Denis Fomin '] + homepage = u'http://bitbucket.org/dicson12/plugins/src/tip/wrong_layout/' + + @log_calls('WrongLayoutPlugin') + def init(self): + self.config_dialog = None + self.gui_extension_points = { + 'chat_control_base' : (self.connect_with_chat_control, + self.disconnect_from_chat_control) + } + self.chat_control = None + self.controls = [] + self.dict_eng = {'`': 'ё', 'q': 'й', 'w': 'ц', 'e': 'у', 'r': 'к', 't': 'е', + 'y': 'н', 'u': 'г', 'i': 'ш', 'o': 'щ', 'p': 'з', '[': 'х', + ']': 'ъ', 'a': 'ф', 's': 'ы', 'd': 'в', 'f': 'а', 'g': 'п', + 'h': 'р', 'j': 'о', 'k': 'л', 'l': 'д', ';': 'ж', '\'': 'э', + 'z': 'я', 'x': 'ч', 'c': 'с', 'v': 'м', 'b': 'и', 'n': 'т', + 'm': 'ь', ',': 'б', '.': 'ю', '/': '.', + '\\': '\\', '~': 'Ё', '@': '"', '$': ';', '^': ':', '&': '?', + 'Q': 'Й', 'W': 'Ц', 'E': 'У', 'R': 'К', 'T': 'Е', 'Y': 'Н', + 'U': 'Г', 'I': 'Ш', 'O': 'Щ', 'P': 'З', '{': 'Х', '}': 'Ъ', + '|': '/', 'A': 'Ф', 'S': 'Ы', 'D': 'В', 'F': 'А', 'G': 'П', + 'H': 'Р', 'J': 'О', 'K': 'Л', 'L': 'Д', '"': 'Э', 'Z': 'Я', + 'X': 'Ч', 'C': 'С', 'V': 'М', 'B': 'И', 'N': 'Т', 'M': 'Ь', + '<': 'Б', '>': 'Ю', '?': ',', ':': 'Ж'} + self.dict_ru = {} + for key in self.dict_eng.keys(): + self.dict_ru[self.dict_eng[key]] = key + + @log_calls('WrongLayoutPlugin') + def activate(self): + pass + + @log_calls('WrongLayoutPlugin') + def deactivate(self): + pass + + @log_calls('WrongLayoutPlugin') + def connect_with_chat_control(self, chat_control): + self.chat_control = chat_control + control = Base(self, self.chat_control) + self.controls.append(control) + + @log_calls('WrongLayoutPlugin') + def disconnect_from_chat_control(self, chat_control): + for control in self.controls: + control.disconnect_from_chat_control() + self.controls = [] + +class Base(object): + def __init__(self, plugin, chat_control): + self.plugin = plugin + self.chat_control = chat_control + self.textview = self.chat_control.conv_textview + + self.id_ = self.chat_control.msg_textview.connect('key_press_event', + self.mykeypress_event) + self.chat_control.handlers[self.id_] = self.chat_control.msg_textview + + def disconnect_from_chat_control(self): + self.chat_control.handlers[self.id_].disconnect(self.id_) + + def mykeypress_event(self, widget, event): + if event.keyval == gtk.keysyms.r or event.keyval == 1739: + if event.state & gtk.gdk.MOD1_MASK: # alt+r + start, end, iter_ = self.get_start_end() + count_eng = count_rus = 0 + c = iter_.get_char().decode('utf-8') + while ((c != 0) & iter_.in_range(start, end)): + if ((ord(c) > 65) & (ord(c) < 122)) | \ + (c == '@') | (c == '#') | (c == '$') | (c == '^') | \ + (c == '&') | (c == '|') | (c == '~') | \ + (c == '{') | (c == '}') | (c == '[') | (c == ']') | \ + (c == '<') | (c == '>'): + count_eng += 1 + if ((ord(c) > 1040) & (ord(c) < 1103)) | (c == 'ё') | \ + (c == 'Ё') | (c == '№'): + count_rus += 1 + iter_.forward_char() + c = iter_.get_char().decode('utf-8') + is_russian = (count_rus >= count_eng) + start, end, iter_ = self.get_start_end() + c = iter_.get_char().decode('utf-8') + text = '' + while ((c != 0) & iter_.in_range(start, end)): + if not is_russian: + conv = self.plugin.dict_eng.get(c, c) + else: + conv = self.plugin.dict_ru.get(c.encode('utf-8'), c) + text = text + conv + iter_.forward_char() + c = iter_.get_char().decode('utf-8') + start, end, iter_ = self.get_start_end() + message_buffer = self.chat_control.msg_textview.get_buffer() + message_buffer.delete(start, end) + message_buffer.insert_at_cursor(text) + self.chat_control.msg_textview.grab_focus() + return True + + def get_start_end(self): + message_buffer = self.chat_control.msg_textview.get_buffer() + sel = message_buffer.get_selection_bounds() + if sel != (): + start, end = sel + else: + start = message_buffer.get_start_iter() + end = message_buffer.get_end_iter() + stext = gajim.config.get('gc_refer_to_nick_char') + res = start.forward_search(stext, gtk.TEXT_SEARCH_TEXT_ONLY) + if res: + first, start = res + start.order(end) + iter_ = start + return start, end, iter_ diff --git a/wrong_layout/po/Makefile b/wrong_layout/po/Makefile new file mode 100644 index 0000000..975e32a --- /dev/null +++ b/wrong_layout/po/Makefile @@ -0,0 +1,34 @@ +PYFILES = $(shell find ../ -type f -name "*.py") +GLADEFILES = $(wildcard ../*.ui) +POFILES = $(wildcard *.po) + +GLADEHFILES := $(GLADEFILES:.ui=.ui.h) + +help: + @echo "USAGE:" + @echo "make update - updates messages.pot and .po files" + @echo "make sr.po - updates sr.po file OR creates new one" + @echo " (replace 'sr' with your language code)" + +%.h: % + intltool-extract --type="gettext/glade" $* + + +messages.pot: $(GLADEHFILES) $(PYFILES) + xgettext -k_ -kN_ -o WrongLayout.pot $(PYFILES) $(GLADEHFILES) --from-code=utf-8 + +%.po: messages.pot + @if test -f $@; then \ + echo -n "Updating '$*' language ";\ + msgmerge -U $@ WrongLayout.pot;\ + else \ + msginit -l $*.UTF8 -o $@; \ + fi + $(RM) $(GLADEHFILES) + +update: $(POFILES) + +clean: + $(RM) $(GLADEHFILES) + +.PHONY: update diff --git a/wrong_layout/po/WrongLayout.po b/wrong_layout/po/WrongLayout.po new file mode 100644 index 0000000..66262fc --- /dev/null +++ b/wrong_layout/po/WrongLayout.po @@ -0,0 +1,23 @@ +# Language WrongLayout translations for PACKAGE package. +# Copyright (C) 2010 THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# test , 2010. +# +msgid "" +msgstr "" +"Project-Id-Version: WrongLayout\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2010-09-04 16:20+0400\n" +"PO-Revision-Date: 2010-09-04 16:23+0300\n" +"Last-Translator: Fomin Denis \n" +"Language-Team: \n" +"Language: WrongLayout\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Poedit-Language: Russian\n" + +#: ../plugin.py:28 +msgid "Press alt+r to convert chars typed in wrong layout Rus<>Eng" +msgstr "При нажатии сочетания клавиш Alt+R в поле ввода текста, весь набранный текст (или выделенный, если таковой имеется) переводится из английской раскладки в русскую или наоборот, в зависимости от того, что написано." + diff --git a/wrong_layout/po/WrongLayout.pot b/wrong_layout/po/WrongLayout.pot new file mode 100644 index 0000000..682da07 --- /dev/null +++ b/wrong_layout/po/WrongLayout.pot @@ -0,0 +1,22 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2010-09-04 16:20+0400\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: ../plugin.py:28 +msgid "Press alt+r to convert chars typed in wrong layout Rus<>Eng" +msgstr ""