Example #1
0
    def apply(self):
        # layout
        i = self._keyboard_layouts.get_active()
        layout = self._keyboard_layouts.get_model()[i][1]
        i = self._keyboard_types.get_active()
        layout += self._keyboard_types.get_model()[i][1]
        layout = os.path.join(package.get_datadir(),
                              'layouts/' + layout + '.json')
        self._settings.set_string('layout', layout)

        # nn-as-jis-x-4063
        nn_as_x4063 = self._nn_as_x4063.get_active()
        self._settings.set_boolean('nn-as-jis-x-4063', nn_as_x4063)

        # dictionary
        i = self._kanzi_dictionaries.get_active()
        dictionary = self._kanzi_dictionaries.get_model()[i][1]
        dictionary = os.path.join(package.get_datadir(), dictionary)
        self._settings.set_string('dictionary', dictionary)

        # user-dictionary
        user = self._user_dictionary.get_text().strip()
        if user == self._default_user_dictionary:
            self._settings.reset('user-dictionary')
        else:
            self._settings.set_string('user-dictionary', user)

        if self._clear_input_history.get_active():
            # clear_input_history also reloads dictionaries
            print('clear_input_history', flush=True)
        elif self._reload_dictionaries.get_active():
            print('reload_dictionaries', flush=True)
Example #2
0
    def apply(self):
        # layout
        model = self._keyboard_layouts.get_model()
        i = self._keyboard_layouts.get_active()
        layout = model[i][1]
        if layout == 'jis':
            layout += '.109'
        else:
            model = self._keyboard_types.get_model()
            i = self._keyboard_types.get_active()
            layout += model[i][1]
        layout = os.path.join(package.get_datadir(),
                              'layouts/' + layout + '.json')
        self._settings.set_value('layout', GLib.Variant.new_string(layout))

        # nn-as-jis-x-4063
        nn_as_x4063 = self._nn_as_x4063.get_active()
        self._settings.set_value('nn-as-jis-x-4063',
                                 GLib.Variant.new_boolean(nn_as_x4063))

        # dictionary
        model = self._kanzi_dictionaries.get_model()
        i = self._kanzi_dictionaries.get_active()
        dictionary = os.path.join(package.get_datadir(), model[i][1])
        self._settings.set_value('dictionary',
                                 GLib.Variant.new_string(dictionary))
Example #3
0
 def _load_layout(self, settings):
     default_layout = os.path.join(package.get_datadir(), 'layouts')
     default_layout = os.path.join(default_layout, 'roomazi.json')
     path = settings.get_string('layout')
     logger.info(f'layout: {path}')
     layout = dict()
     try:
         with open(path) as f:
             layout = json.load(f)
     except Exception as error:
         logger.error(error)
     if not layout:
         try:
             with open(default_layout) as f:
                 layout = json.load(f)
         except Exception as error:
             logger.error(error)
     if layout.get('Type') == 'Kana':
         self._to_kana = self._handle_kana_layout
         self._dict.use_romazi(False)
     elif 'Roomazi' in layout:
         self._to_kana = self._handle_roomazi_layout
         self._dict.use_romazi(True)
     else:
         self._to_kana = self._handle_default_layout
         self._dict.use_romazi(True)
     return layout
Example #4
0
 def _load_layout(self, config):
     default_layout = os.path.join(package.get_datadir(), 'layouts')
     default_layout = os.path.join(default_layout, 'roomazi.json')
     var = config.get_value('engine/hiragana', 'layout')
     if var is None:
         path = default_layout
     elif var.get_type_string() != 's':
         config.unset('engine/hiragana', 'layout')
         path = default_layout
     else:
         path = var.get_string()
     logger.info("layout: %s", path)
     layout = dict()
     try:
         with open(path) as f:
             layout = json.load(f)
     except Exception as error:
         logger.error(error)
     if not layout:
         try:
             with open(default_layout) as f:
                 layout = json.load(f)
         except Exception as error:
             logger.error(error)
     if layout.get('Type') == 'Kana':
         self._to_kana = self._handle_kana_layout
     elif 'Roomazi' in layout:
         self._to_kana = self._handle_roomazi_layout
     else:
         self._to_kana = self._handle_default_layout
     return layout
Example #5
0
 def on_help(self, *args):
     url = "file://" + os.path.join(package.get_datadir(),
                                    "help/index.html")
     Gtk.show_uri_on_window(self.window, url, Gdk.CURRENT_TIME)
     if self.window:
         # see https://gitlab.gnome.org/GNOME/gtk/-/issues/1211
         self.window.get_window().set_cursor(self.cursor)
Example #6
0
 def do_activate(self):
     if not self.window:
         filename = os.path.join(package.get_datadir(), 'lessons/menu.txt')
         self.window = TypingWindow(application=self, filename=filename)
         self.cursor = Gdk.Cursor.new_from_name(self.window.get_display(),
                                                "default")
     self.window.present()
Example #7
0
    def __init__(self, path):
        logger.info("Dictionary(%s)", path)

        self._dict_base = {}
        self._dict = {}

        self._yomi = ''
        self._no = 0
        self._cand = []
        self._numeric = ''
        self._dirty = False

        self._orders_path = ''

        try:
            # Load Katakana dictionary first so that Katakana words come after Kanji words.
            katakana_path = os.path.join(package.get_datadir(), 'katakana.dic')
            self._load_dict(self._dict_base, katakana_path)

            # Load system dictionary
            self._load_dict(self._dict_base, path)
        except Exception as error:
            logger.error(error)

        # Load private dictionary
        self._dict = self._dict_base.copy()

        my_path = os.path.join(package.get_user_datadir(), 'my.dic')
        self._load_dict(self._dict, my_path, 'a+')

        base = os.path.basename(path)
        if base:
            self._orders_path = os.path.join(package.get_user_datadir(), base)
            self._load_dict(self._dict, self._orders_path, 'a+', version_checked=False)
Example #8
0
 def _load_dictionary(self, config):
     var = config.get_value('engine/hiragana', 'dictionary')
     if var is None or var.get_type_string() != 's':
         path = os.path.join(package.get_datadir(), 'restrained.dic')
         if var:
             config.unset('engine/hiragana', 'dictionary')
     else:
         path = var.get_string()
     return Dictionary(path)
Example #9
0
 def on_value_changed(self, settings, key):
     value = settings.get_value(key)
     if key == 'layout':
         self._set_current_keyboard(value.get_string())
     elif key == 'nn-as-jis-x-4063':
         t = value.get_boolean()
         self._nn_as_x4063.set_active(value.get_boolean())
     elif key == 'dictionary':
         current = value.get_string()
         current = current[len(package.get_datadir()) + 1:]
         print(current)
         model = self._kanzi_dictionaries.get_model()
         for i in model:
             if i[1] == current:
                 self._kanzi_dictionaries.set_active(i[2])
                 break
Example #10
0
 def on_about(self, action, param):
     dialog = Gtk.AboutDialog(transient_for=self.window, modal=True)
     dialog.set_program_name(_("Typing Practice"))
     dialog.set_copyright("Copyright 2020, 2021 Esrille Inc.")
     dialog.set_authors(["Esrille Inc."])
     dialog.set_documenters(["Esrille Inc."])
     dialog.set_website(
         "file://" + os.path.join(package.get_datadir(), "help/index.html"))
     dialog.set_website_label(_("Introduction to Typing Practice"))
     dialog.set_logo_icon_name(package.get_name())
     dialog.set_version(package.get_version())
     dialog.present()
     # To close the dialog when "close" is clicked, e.g. on Raspberry Pi OS,
     # the "response" signal needs to be connected on_about_response
     dialog.connect("response", self.on_about_response)
     dialog.show()
Example #11
0
    def __init__(self, path, user, clear_history=False):
        logger.info(f'Dictionary("{path}", "{user}")')

        self._dict_base = {}
        self._dict = {}

        self._yomi = ''
        self._no = 0
        self._cand = []
        self._order = []
        self._completed = []
        self._numeric = ''
        self._dirty = False
        self._strdcmp = self.strcmp

        self._orders_path = ''

        try:
            # Load Katakana dictionary first so that Katakana words come after Kanji words.
            katakana_path = os.path.join(package.get_datadir(), 'katakana.dic')
            self._load_dict(self._dict_base, katakana_path)
            # Load system dictionary
            self._load_dict(self._dict_base, path)
        except Exception as error:
            logger.error(error)

        # Load private dictionary
        self._dict = self._dict_base.copy()
        if user:
            my_path = os.path.join(package.get_user_datadir(), user)
            self._load_dict(self._dict, my_path, 'a+')

        base = os.path.basename(path)
        if base:
            self._orders_path = os.path.join(package.get_user_datadir(), base)
            if clear_history:
                logger.info('clear_history')
                with open(self._orders_path, 'w') as file:
                    file.write("; " + DICTIONARY_VERSION + "\n")
            self._load_dict(self._dict, self._orders_path, 'a+', version_checked=False)
Example #12
0
 def do_property_activate(self, prop_name, state):
     logger.info(f'property_activate({prop_name}, {state})')
     if prop_name == 'Setup':
         self._setup_start()
     elif prop_name == 'Help':
         url = 'file://' + os.path.join(package.get_datadir(), 'help/index.html')
         # Use yelp to open local HTML help files.
         subprocess.Popen(['yelp', url])
     elif prop_name == 'About':
         if self._about_dialog:
             self._about_dialog.present()
             return
         dialog = Gtk.AboutDialog()
         dialog.set_program_name(_("Hiragana IME"))
         dialog.set_copyright("Copyright 2017-2022 Esrille Inc.")
         dialog.set_authors(["Esrille Inc."])
         dialog.set_documenters(["Esrille Inc."])
         dialog.set_website("https://www.esrille.com/")
         dialog.set_website_label("Esrille Inc.")
         dialog.set_logo_icon_name(package.get_name())
         dialog.set_default_icon_name(package.get_name())
         dialog.set_version(package.get_version())
         # To close the dialog when "close" is clicked on Raspberry Pi OS,
         # we connect the "response" signal to _about_response_cb
         dialog.connect("response", self._about_response_cb)
         self._about_dialog = dialog
         dialog.show()
     elif prop_name.startswith('InputMode.'):
         if state == IBus.PropState.CHECKED:
             mode = {
                 'InputMode.Alphanumeric': 'A',
                 'InputMode.Hiragana': 'あ',
                 'InputMode.Katakana': 'ア',
                 'InputMode.WideAlphanumeric': 'A',
                 'InputMode.HalfWidthKatakana': 'ア',
             }.get(prop_name, 'A')
             self.set_mode(mode, True)
Example #13
0
 def do_property_activate(self, prop_name, state):
     logger.info("property_activate(%s, %d)" % (prop_name, state))
     if prop_name == "Setup":
         self._start_setup()
     if prop_name == "About":
         if self._about_dialog:
             self._about_dialog.present()
             return
         dialog = Gtk.AboutDialog()
         dialog.set_program_name(_("Hiragana IME"))
         dialog.set_copyright("Copyright 2017-2020 Esrille Inc.")
         dialog.set_authors(["Esrille Inc."])
         dialog.set_documenters(["Esrille Inc."])
         dialog.set_website(
             "file://" +
             os.path.join(package.get_datadir(), "help/index.html"))
         dialog.set_website_label(_("Introduction to Hiragana IME"))
         dialog.set_logo_icon_name(package.get_name())
         dialog.set_version(package.get_version())
         # To close the dialog when "close" is clicked, e.g. on RPi,
         # we connect the "response" signal to about_response_callback
         dialog.connect("response", self.about_response_callback)
         self._about_dialog = dialog
         dialog.show()
Example #14
0
import locale
import logging
import os
import signal
import sys

if __name__ == '__main__':
    try:
        locale.bindtextdomain(package.get_domain(), package.get_localedir())
    except Exception:
        pass
    gettext.bindtextdomain(package.get_domain(), package.get_localedir())
    logging.basicConfig(level=logging.DEBUG)

    resource = Gio.Resource.load(
        os.path.join(package.get_datadir(), 'esrille-paint.gresource'))
    resource._register()

    style_provider = Gtk.CssProvider()
    style_provider.load_from_resource(package.APP_PATH +
                                      '/css/esrille-paint.css')
    Gtk.StyleContext.add_provider_for_screen(
        Gdk.Screen.get_default(), style_provider,
        Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

    icon_theme = Gtk.IconTheme.get_default()
    icon_theme.add_resource_path(package.APP_PATH + '/icons')

    app = Application()
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    exit_status = app.run(sys.argv)
Example #15
0
 def help_callback(self, *whatever):
     url = "file://" + os.path.join(package.get_datadir(),
                                    _("help/en/index.html"))
     Gtk.show_uri_on_window(self, url, Gdk.CURRENT_TIME)