Example #1
0
    def _create_history_menu(self, creator, itemname, max_itemlen):
        creator.submenu_begin(itemname)

        historylen = len(self._histories)
        break_count = 0
        max_break_count = config.inst.get_history_max_break_count()
        break_per = config.inst.get_history_break_per()
        for i in range(historylen):
            real_index = self._determine_real_index(i)
            real_itemname = unicodesupport.slice(self._histories[i], 0, max_itemlen)
            if unicodesupport.length(self._histories[i]) > max_itemlen:
                real_itemname += '...'

            if self._is_break_insertion_timing(i, break_count, max_break_count, break_per):
                creator.break_next()
                break_count += 1

            creator.append(
                HistoryMenuItemCreator.create_and_get(real_itemname, i, self._accelstr),
                command_data.CommandData('history', self._histories[i], real_index)
            )

        creator.submenu_end()
Example #2
0
    def test_slice(self):
        e = self.assertEqual
        ne = self.assertNotEqual

        # from utf8 rawstring
        # -------------------
        testee = 'aiuえお♥'
        e('aiu', unicodesupport.slice(testee, 0, 3))
        e('えお', unicodesupport.slice(testee, 3, 5))
        e(testee, unicodesupport.slice(testee))
        e('uえお♥', unicodesupport.slice(testee, 2))
        e('aiuえ', unicodesupport.slice(testee, None, 4))
        e('iuえお', unicodesupport.slice(testee, 1, -1))

        # from sjis rawstring
        # -------------------
        testee = unicodesupport._a_to_b('aiuえおか', 'utf8', 'sjis')
        e('aiu', unicodesupport.slice(testee, 0, 3))
        e('えお', unicodesupport.slice(testee, 3, 5))
        ne(testee, unicodesupport.slice(testee))
        e('aiuえおか', unicodesupport.slice(testee))
        e('uえおか', unicodesupport.slice(testee, 2))
        e('aiuえ', unicodesupport.slice(testee, None, 4))
        e('iuえお', unicodesupport.slice(testee, 1, -1))
Example #3
0
    def _interpret(self, line):
        """
        <line> := <bl><name><bl>,<bl><command><bl>,<bl><prm1><bl>,…
        <bl> := tab|space

        手順:
        1. name, command, prm1, prm2, ... に分離
        2. 各々を整形(両端の<bl>除去とマクロ展開)
        3. 整形後の name を用いてコマンド or 定型文として解釈

        @exception exception メニュー作成に失敗

        """
        name = ""
        command = ""
        prm = ""
        prm2 = ""
        prm3 = ""

        splitted_line = line.split(",")

        name = self._strip(splitted_line[0])
        # 空行は無視する.
        if name=="":
            return

        try:
            command = self._strip(splitted_line[1])
        except IndexError:
            pass
        try:
            prm = self._strip(splitted_line[2])
        except IndexError:
            pass
        try:
            prm2 = self._strip(splitted_line[3])
        except IndexError:
            pass
        try:
            prm3 = self._strip(splitted_line[4])
        except IndexError:
            pass

        firstchar = name[0]

        # name自身を表すユーザマクロを追加
        self._macroer.add("itemname", self._macroer.deploy(name))

        # 定型文以外の項目を判定&処理
        # ----------------------------------------

        # コメントは無視する
        if firstchar==";":
            return

        if firstchar=="@":
            optionname = ""
            try:
                optionname = name[1:]
            except IndexError:
                return
            # 設定値はマクロ展開しない.
            # 必要が出てきたらその時やる.
            self._set_to_config_wrapper(optionname, command)
            return

        if firstchar=="$":
            macroname = ""
            try:
                macroname = name[1:]
            except IndexError:
                pass
            if macroname!="":
                self._macroer.add(macroname, self._macroer.deploy(command))
            return

        if firstchar=="[":
            submenuname = ""
            try:
                submenuname = name[1:]
            except IndexError:
                pass
            self._creator.submenu_begin(submenuname)
            return

        if firstchar=="]":
            self._creator.submenu_end()
            return

        if firstchar=="-":
            self._creator.append_separator()
            return

        if firstchar=="=":
            self._creator.break_next()
            return

        if name=="!print":
            # 前行の内容をメニュー項目に表示する.
            # 目的は表示だけなので選択できないようグレーアウト.
            #
            # なお項目の長さは制限しない.
            # %cb% みたいに爆発的なサイズが入ることは
            # (利用者が INI ファイルに直接書かない限りは)ありえないから.
            self._creator.grayout_next()
            self._creator.append(
                self._prev_line,
                command_data.CommandData('invalid-command')
            )
            return

        # 項目のグレーアウト
        if firstchar==":":
            try:
                name = name[1:]
            except IndexError:
                return
            self._creator.grayout_next()

            # Fall Through '定型文項目を解釈' #

        # 定型文項目を解釈
        # ----------------------------------------

        # メニューに追加する前の前処理
        # - マクロを展開
        # - 項目名が最大長を越えないようにする.
        name = self._macroer.deploy(name)
        itemname = name
        if unicodesupport.length(itemname)>self._maxlen_item:
            itemname = unicodesupport.slice(name, 0, self._maxlen_item) + "..."

        if command=="":
            self._creator.append(
                itemname, \
                command_data.CommandData(name)
            )
        elif command=="history":
            # 履歴機能を使わない時は解釈を無視.
            if not(config.inst.get_use_history()):
                return
            # 各prmの意味は依存先クラスのコメントを見よ
            cmddata_for_hm = command_data.CommandData(
                "DUMMY", prm, prm2, prm3
            )
            historymenu.HistoryMenuCreator(
                cmddata_for_hm, self._creator, name, self._maxlen_item
            )
        elif command=="hisearch":
            # 履歴機能を使わない時は解釈を無視.
            if not(config.inst.get_use_history()):
                return
            cmddata = command_data.CommandData(
                "DUMMY", prm, prm2
            )
            historymenu.HistorySearchMenuCreator(
                cmddata, self._creator, name, self._maxlen_item
            )
        else:
            self._creator.append(
                itemname, \
                command_data.CommandData(
                    self._macroer.deploy(command),
                    self._macroer.deploy(prm),
                    self._macroer.deploy(prm2)
                )
            )

        # name のサイズが大きい(%cb%ででかいクリップボードデータ見た時とか)と
        # ここで時間を食うので, 出力サイズを削っておく.
        # デバッグ用なので unicodesupport.slice 未使用(見易さより処理速度優先).
        log.debug("appended. name[:128]=" + name[:128] + "/command=" + command)