コード例 #1
0
 def on_phrase_post(self, j):
     phrase = self.parse_phrase(j.get('phrase', []))
     cmd = j['cmd']
     if cmd == 'p.end' and phrase:
         self.history.append(phrase)
         self.history = self.history[-hist_len:]
         webview.render(template, phrases=self.history)
コード例 #2
0
 def on_phrase_post(self, j):
     phrase = self.parse_phrase(j.get('phrase', []))
     if phrase in ('history show', 'history hide'):
         return
     cmd = j['cmd']
     if cmd == 'p.end' and phrase:
         self.history.append((phrase, ''))
         self.history = self.history[-hist_len:]
         webview.render(template, phrases=self.history)
コード例 #3
0
 def on_phrase_post(self, j):
     phrase = self.parse_phrase(j.get("phrase", []))
     if phrase in ("history show", "history hide"):
         return
     cmd = j["cmd"]
     if cmd == "p.end" and phrase:
         self.history.append((phrase, ""))
         self.history = self.history[-hist_len:]
         webview.render(template, phrases=self.history)
コード例 #4
0
 def on_phrase_post(self, j):
     phrase = self.parse_phrase(j.get("phrase", []))
     cmd = j["cmd"]
     if cmd == "p.end" and phrase:
         self.history.append(phrase)
         self.history = self.history[-hist_len:]
         if WEBVIEW:
             webview.render(template, phrases=self.history)
             self.refresh()
         if NOTIFY:
             app.notify(body="\r\n".join(self.history))
コード例 #5
0
 def render(self):
     global show_agains
     agains = get_agains()
     agains = (format_keys(agains[0]), format_keys(agains[1]), agains[2])
     show_macro = is_recording() or display_macro()
     webview.render(template,
                    phrases=self.history,
                    agains=agains,
                    show_again=show_agains,
                    show_macro=show_macro,
                    recording=is_recording(),
                    recorded="␣".join(self.macro_history))
コード例 #6
0
ファイル: phrase_frequency.py プロジェクト: ym-han/talon-user
 def on_phrase_post(self, j):
     phrase = self.parse_phrase(j.get("phrase", []))
     if phrase in ("toggle frequency", "pa"):
         return
     cmd = j["cmd"]
     if cmd == "p.end" and phrase:
         self.history[phrase] += 1
     by_count = sorted(self.history.items(),
                       reverse=True,
                       key=lambda v: v[1])[:50]
     # print(by_count)
     webview.render(template, phrases=by_count)
コード例 #7
0
 def on_phrase_post(self, j):
     phrase = self.parse_phrase(j.get("phrase", []))
     if phrase in ("toggle history"):
         return
     cmd = j["cmd"]
     if cmd == "p.end" and phrase:
         if phrase != "clear history":
             self.history.append((phrase, ""))
         self.history = self.history[-hist_len:]
         webview.render(template, phrases=self.history)
         with open("last_phrase.txt", "w") as fh:
             fh.write(phrase)
コード例 #8
0
def on_phrase(j):
    phrase = parse_phrase(j.get("phrase", []))
    cmd = j["cmd"]
    if cmd == "p.end":

        if phrase:
            with atomic_write(path, overwrite=True) as f:
                f.write(phrase)

            if WEBVIEW:
                last_items.appendleft(phrase)
                webview.render(last_template, last_items=last_items)

            if NOTIFY:
                app.notify(body=phrase)
コード例 #9
0
def on_phrase(j):
    phrase = parse_phrase(j.get("phrase", []))
    cmd = j["cmd"]
    if cmd == "p.end" and phrase:
        with atomic_write(path, overwrite=True) as f:
            f.write(phrase)

    if WEBVIEW and cmd in ("p.end", "p.hypothesis") and phrase:
        body = phrase.replace(" ", " ")
        if cmd == "p.hypothesis":
            webview.render("<i>{{ phrase }}</i>", phrase=body)
        else:
            webview.render("{{ phrase }}", phrase=body)

    if NOTIFY and cmd == "p.end" and phrase:
        app.notify(body=phrase)
コード例 #10
0
def on_phrase(j):
    phrase = parse_phrase(j.get('phrase', []))
    cmd = j['cmd']

    if WEBVIEW and cmd in ('p.end', 'p.hypothesis') and phrase:
        body = phrase.replace(' ', '&nbsp;')
        if cmd == 'p.hypothesis':
            webview.render("<i>{{ phrase }}</i>", phrase=body)
        else:
            webview.render("{{ phrase }}", phrase=body)

    if NOTIFY and cmd == 'p.end' and phrase:
        app.notify(body=phrase)


#engine.register('phrase', on_phrase)
コード例 #11
0
def on_phrase(j):
    phrase = parse_phrase(j.get('phrase', []))
    cmd = j['cmd']
    if cmd == 'p.end' and phrase:
        with atomic_write(path, overwrite=True) as f:
            f.write(phrase)

    if WEBVIEW and cmd in ('p.end', 'p.hypothesis') and phrase:
        body = phrase.replace(' ', '&nbsp;')
        if cmd == 'p.hypothesis':
            webview.render("<i>{{ phrase }}</i>", phrase=body)
        else:
            webview.render("{{ phrase }}", phrase=body)

    if NOTIFY and cmd == 'p.end' and phrase:
        app.notify(body=phrase)
コード例 #12
0
def on_phrase(j):
    phrase = parse_phrase(j.get('phrase', []))
    cmd = j['cmd']
    if cmd == 'p.end' and phrase:
        with atomic_write(path, overwrite=True) as f:
            f.write(phrase)
        if LOG and not all([
                x in '0123456789' for x in phrase.split(' ')
        ]):  # don't record phrases with only numbers (security)
            with open(phrase_log_path, 'a') as f:
                f.write(str(datetime.datetime.now()) + '\t' + phrase + '\n')

    if WEBVIEW and cmd in ('p.end', 'p.hypothesis') and phrase:
        body = phrase.replace(' ', '&nbsp;')
        if cmd == 'p.hypothesis':
            webview.render("<i>{{ phrase }}</i>", phrase=body)
        else:
            webview.render("{{ phrase }}", phrase=body)

    if NOTIFY and cmd == 'p.end' and phrase:
        app.notify(body=phrase)
コード例 #13
0
ファイル: history.py プロジェクト: itsthejoker/talonconfigs
def on_phrase(j):
    global LAST_COUNT
    phrase = parse_phrase(j.get("phrase", []))
    cmd = j["cmd"]
    if cmd == "p.end":

        if phrase:
            with atomic_write(path, overwrite=True) as f:
                f.write(phrase)

            if WEBVIEW:
                last_items.appendleft(phrase)
                phrase_words = phrase.split()

                if "history show" in phrase and phrase_words[-1].isdigit():
                    LAST_COUNT = int(phrase_words[-1])

                webview.render(last_template, last_items=list(itertools.islice(last_items, 0, LAST_COUNT)))

            if NOTIFY:
                app.notify(body=phrase)
コード例 #14
0
ファイル: last_phrase.py プロジェクト: slin63/talon_community
def on_phrase(j):
    # context_name = j.get("parsed") or ""
    # if context_name:
    #     context_name = cleanup_context_name(context_name[0]._name)
    # print(
    #     "@6e6 ~/.talon/user/talon_community/misc/last_phrase.py:42\n>",
    #     f"j['parsed']: {cleanup_context_name(x[0]._name)}",
    # )
    phrase = parse_phrase(j.get("phrase", []))
    cmd = j["cmd"]
    if cmd == "p.end" and phrase:
        with atomic_write(path, overwrite=True) as f:
            f.write(phrase)

    if WEBVIEW and cmd in ("p.end", "p.hypothesis") and phrase:
        body = phrase.replace(" ", "&nbsp;")
        if cmd == "p.hypothesis":
            webview.render("<i>{{ phrase }}</i>", phrase=body)
        else:
            webview.render("{{ phrase }}", phrase=body)

    if NOTIFY and cmd == "p.end" and phrase and phrase not in IGNORE_PHRASES:
        app.notify(title=BIRDS[0], body=phrase)
コード例 #15
0
    webview_locations = config.load_config_json("webview_locations.json")

    def webview_blur(*args, **kwargs):
        global webview_locations
        key = screen_key()
        r = webview.rect
        new_location = {"x": r.x, "y": r.y}
        webview_location = webview_locations[key]
        if (webview_location["x"] != new_location["x"]
                or webview_location["y"] != new_location["y"]):
            webview_locations[key] = new_location
            config.save_config_json("webview_locations.json",
                                    webview_locations)

    webview = webview.Webview()
    webview.render(template, phrases=["command"])
    webview.show()

    key = screen_key()
    if key not in webview_locations:
        webview_locations[key] = {"x": 1, "y": ui.main_screen().height}
    print("moving webview_locations", webview_locations[key])
    webview.move(webview_locations[key]["x"], webview_locations[key]["y"])

    webview.register("blur", webview_blur)


class History:
    def __init__(self):
        self.visible = True
        self.history = []
コード例 #16
0
ファイル: history.py プロジェクト: kolemannix/talon_community
    padding-right: 5px; /* this is broken */
    min-width: 100px;
}
</style>

<h3 id="title">History</h3>
<table>
{% for phrase in phrases %}
<tr><td class="phrase">{{ phrase }}</td></tr>
{% endfor %}
<tr><td><i>{{ hypothesis }}</i></td></tr>
</ul>
'''

webview = webview.Webview()
webview.render(template, phrases=['command'])
webview.show()
webview.move(1, ui.main_screen().height)

class History:
    def __init__(self):
        self.history = []
        engine.register('post:phrase', self.on_phrase_post)

    def parse_phrase(self, phrase):
        return ' '.join(word.split('\\')[0] for word in phrase)

    def on_phrase_post(self, j):
        phrase = self.parse_phrase(j.get('phrase', []))
        cmd = j['cmd']
        if cmd == 'p.end' and phrase:
コード例 #17
0
        <td><span class="number">0</span>{{ agains[0] }}</td>
        <td {% if agains[1] == None %}colspan="2" {%endif%} style="text-align: {% if agains[1] != None %}center{%else%}right{%endif%};"><span style='white-space: nowrap; overflow: hidden; text-overflow: ellipsis;'>({{ agains[2] }})</span></td>
        {% if agains[1] != None %}<td style="text-align: right;">{{ agains[1] }}<span class="number">0</span></td>{% endif %}
    </tr>
{% endif %}
{% if show_macro %}
    <tr id="macro">
        <td colspan="3">{% if recording %}<span class="number recording"></span>{%endif%}{% if not recording %}<span class="number">0</span><strong>macro:</strong>{%endif%} {{recorded}}{% if recorded == '' %}&lt;recording>{% endif %}</td>
    </tr>
{% endif %}
</table>
'''

webview = webview.Webview()
webview.render(template,
               phrases=[('--start--', '', 1)],
               agains=(None, None, None),
               show_again=show_agains)
webview.move(ui.main_screen().width - 400, ui.main_screen().height)


class History:
    def __init__(self):
        self.history = []
        self.macro_history = []
        self.timer = cron.after('15s', self.auto_hide)
        self.auto_hidden = False
        engine.register('post:phrase', self.on_phrase_post)
        # engine.register('pre:phrase', self.on_phrase_pre)

    def parse_phrase(self, phrase):
        return ' '.join(word.split('\\')[0] for word in phrase)
コード例 #18
0
ファイル: phrase_frequency.py プロジェクト: ym-han/talon-user
    padding-right: 5px; /* this is broken */
    min-width: 100px;
}
</style>

<h3 id="title">Counts</h3>
<table>
{% for phrase, text in phrases %}
<tr><td class="phrase">{{ phrase }}</td><td class="text">{{ text }}</td></tr>
{% endfor %}
<tr><td><i>{{ hypothesis }}</i></td></tr>
</ul>
"""

webview = webview.Webview()
webview.render(template, phrases=[("command", "")])
webview.move(0, ui.main_screen().height)

webview_shown = False


def toggle_webview(m):
    global webview_shown
    if webview_shown:
        webview.hide()
    else:
        webview.show()
    webview_shown = not webview_shown


class History:
コード例 #19
0
    padding-right: 5px; /* this is broken */
    min-width: 100px;
}
</style>

<h3 id="title">History</h3>
<table>
{% for phrase, text in phrases %}
<tr><td class="phrase">{{ phrase }}</td><td class="text">{{ text }}</td></tr>
{% endfor %}
<tr><td><i>{{ hypothesis }}</i></td></tr>
</ul>
"""

webview = webview.Webview()
webview.render(template, phrases=[(" ", "")])
webview.move(0, ui.main_screen().height)

webview_shown = False


def toggle_webview(m):
    global webview_shown
    if webview_shown:
        webview.hide()
    else:
        webview.show()
    webview_shown = not webview_shown


class History:
コード例 #20
0
    padding-right: 5px; /* this is broken */
    min-width: 100px;
}
</style>

<table>
{% for phrase in phrases %}
<tr><td class="phrase">{{ phrase }}</td></tr>
{% endfor %}
<tr><td><i>{{ hypothesis }}</i></td></tr>
</ul>
'''

if SHOW:
    webview = webview.Webview()
    webview.render(template, phrases=['waiting...'])
    webview.show()
    webview.move(ui.main_screen().width - 100, ui.main_screen().height)

    class History:
        def __init__(self):
            self.history = []
            engine.register('post:phrase', self.on_phrase_post)

        def parse_phrase(self, phrase):
            return ' '.join(word.split('\\')[0] for word in phrase)

        def on_phrase_post(self, j):
            phrase = self.parse_phrase(j.get('phrase', []))
            cmd = j['cmd']
            if cmd == 'p.end' and phrase:
コード例 #21
0
    padding-right: 5px; /* this is broken */
    min-width: 100px;
}
</style>

<h3 id="title">History</h3>
<table>
{% for phrase, text in phrases %}
<tr><td class="phrase">{{ phrase }}</td><td class="text">{{ text }}</td></tr>
{% endfor %}
<tr><td><i>{{ hypothesis }}</i></td></tr>
</ul>
'''

webview = webview.Webview()
webview.render(template, phrases=[('command', '')])
webview.move(0, ui.main_screen().height)


class History:
    def __init__(self):
        self.history = []
        engine.register('post:phrase', self.on_phrase_post)

    def parse_phrase(self, phrase):
        return ' '.join(word.split('\\')[0] for word in phrase)

    def on_phrase_post(self, j):
        phrase = self.parse_phrase(j.get('phrase', []))
        if phrase in ('history show', 'history hide'):
            return