Skip to content

Instantly share code, notes, and snippets.

@tararoys
Last active April 9, 2021 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tararoys/d138b36731262fb8ae452814c13b9d4f to your computer and use it in GitHub Desktop.
Save tararoys/d138b36731262fb8ae452814c13b9d4f to your computer and use it in GitHub Desktop.

This is a collection of files that pop up reminders. Ever needed to take a quick note? Remember a couple of things? add a complicated url to your article?

Adapting the homophones functionality from the knausj repositiory, this lets you summon a reminder for a keyword. You can also choose something off the reminders list and have it type that item into a text field.

Highly adaptable for having a custom vocabulary for a specific article, your grocery list, or to keep notes on poker odds.

It workds like this:

Open your .csv file. To create a new reminder list, write the keyword you want to use to summon at particular list in the first. Then addd everything you want on that list, separated by commas.

For example,

fractal,julia,mandelbrot,glynnsim,chaotica

is a list of words I associate with fractals. I can summon this list with the command

reminder fractal

and a list of all those words will appear in sorted alphabetical order.

image

you can simply refer to this list, or, if you say, Choose 2, it will type out the word 'fractal'

We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 4 columns, instead of 5. in line 1.
today,buy coffee, work on talon, eat lunch
vocabulary,Talon,talonvoice.com,talon.wiki,youtube.com/tararoys
from talon import Context, Module, app, clip, cron, imgui, actions, ui, fs
import os
########################################################################
# global settings
########################################################################
# a list of reminders where each line is a comma separated list
# e.g. where,wear,ware
# a suitable one can be found here:
# https://github.com/pimentel/reminders
cwd = os.path.dirname(os.path.realpath(__file__))
reminders_file = os.path.join(cwd, "reminders.csv")
# if quick_replace, then when a word is selected and only one reminder exists,
# replace it without bringing up the options
quick_replace = True
show_help = False
########################################################################
ctx = Context()
mod = Module()
mod.mode("reminders")
mod.list("reminders_canonicals", desc="list of words ")
main_screen = ui.main_screen()
def update_reminders(name, flags):
if name != reminders_file:
return
phones = {} #create a dictionary called phones
canonical_list = [] #create an empty array
with open(reminders_file, "r") as f: #open the file
for line in f: #get a line of the csv
words = line.rstrip().split(",") #create an array of the values on the line of the csv
canonical_list.append(words[0]) #take the first value and put it in the list of link words
for word in words: # going through the words one by one
word = word.lower() #make the word lowercase
old_words = phones.get(word, []) #look for that word in the phones dictionary
phones[word] = sorted(set(old_words + words)) #in the phones dictionary, for the key word,
global all_reminders
print(phones)
all_reminders = phones
ctx.lists["self.reminders_canonicals"] = canonical_list
print(canonical_list)
update_reminders(reminders_file, None)
fs.watch(cwd, update_reminders)
active_word_list = None
is_selection = False
def close_reminders():
gui.hide()
actions.mode.disable("user.reminders")
def raise_reminders(word, forced=False, selection=False):
global quick_replace
global active_word_list
global show_help
global force_raise
global is_selection
force_raise = forced
is_selection = selection
if is_selection:
word = word.strip()
is_capitalized = word == word.capitalize()
is_upper = word.isupper()
word = word.lower()
if word not in all_reminders:
app.notify("reminders.py", '"%s" not in reminders list' % word)
return
active_word_list = all_reminders[word]
if (
is_selection
and len(active_word_list) == 2
and quick_replace
and not force_raise
):
if word == active_word_list[0].lower():
new = active_word_list[1]
else:
new = active_word_list[0]
if is_capitalized:
new = new.capitalize()
elif is_upper:
new = new.upper()
clip.set(new)
actions.edit.paste()
return
actions.mode.enable("user.reminders")
show_help = False
gui.show()
@imgui.open(x=main_screen.x + main_screen.width / 2.6, y=main_screen.y)
def gui(gui: imgui.GUI):
global active_word_list
if show_help:
gui.text("Homephone help - todo")
else:
gui.text("Select a reminder")
gui.line()
index = 1
for word in active_word_list:
gui.text("Choose {}: {} ".format(index, word))
index = index + 1
def show_help_gui():
global show_help
show_help = True
gui.show()
@mod.capture(rule="{self.reminders_canonicals}")
def reminders_canonical(m) -> str:
"Returns a single string"
return m.reminders_canonicals
@mod.action_class
class Actions:
def reminders_hide():
"""Hides the reminders display"""
close_reminders()
def reminders_show(m: str):
"""Sentence formatter"""
print(m)
raise_reminders(m, False, False)
def reminders_show_selection():
"""Sentence formatter"""
raise_reminders(actions.edit.selected_text(), False, True)
def reminders_force_show(m: str):
"""Sentence formatter"""
raise_reminders(m, True, False)
def reminders_force_show_selection():
"""Sentence formatter"""
raise_reminders(actions.edit.selected_text(), True, True)
def reminders_select(number: int) -> str:
"""selects the reminder by number"""
if number <= len(active_word_list) and number > 0:
return active_word_list[number - 1]
error = "reminders.py index {} is out of range (1-{})".format(
number, len(active_word_list)
)
app.notify(error)
raise error
reminders <user.reminders_canonical>: user.reminders_show(reminders_canonical)
reminders that: user.reminders_show_selection()
reminders force <user.reminders_canonical>: user.reminders_force_show(reminders_canonical)
reminders force: user.reminders_force_show_selection()
reminders hide: user.reminders_hide()
mode: user.reminders
-
choose <number_small>:
result = user.reminders_select(number_small)
insert(result)
user.homophones_hide()
choose <user.formatters> <number_small>:
result = user.reminders_select(number_small)
insert(user.formatted_text(result, formatters))
user.reminders_hide()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment