>
> You can put all these function definitions in a node or nodes and install
> them by running the node with CTRL-b.  Or if there are so many that you
> want to put them in a module, you can import them from the module, but it
> doesn't have to be a plugin.  You could put it into, for example,
> ~/.leo/functions.  You can add that location to the Python system path,
> then import your function definition module from there.
>
> So there are many possibilities for adding your own functions and command
> that can be stored right in subtrees in myLeoSettings.leo, or in a module,
> without even needing a plugin.  Or a plugin could use the same techniques
> to install your functions. If you want to write them as Leo minibuffer
> commands, you can create menu items for them, so that you can access them
> from Leo's menubar (you do that in myLeoSettings.leo, or in particular
> outlines).
>

Hi, Thomas, Thanks again for your detailed advice!

For now, there is nothing special for my personal_common_functions. Just
some wraps like

def get_clipboard():
return g.app.gui.getTextFromClipboard()

Or some stupid hard codes(like, I used hard code when ask API
key...Ocp-Apim-Subscription-Key):

def translate_text(text, to_lang='zh-Hans', from_lang='en'):
# Declare httpx client
client = httpx.Client(proxies=os.getenv("https_proxy"))
# Define the Translator Text API endpoint
endpoint = "https://api.cognitive.microsofttranslator.com";

# Add required headers to API request
headers = {
'Ocp-Apim-Subscription-Key': 'simple hard code',
'Ocp-Apim-Subscription-Region': 'eastasia',
'Content-type': 'application/json',
'X-ClientTraceId': str(uuid.uuid4())
}

# Add required parameters to API request
params = {
'api-version': '3.0',
'from': from_lang,
'to': to_lang
}

# Package the text to be translated into a JSON object
body = [{'text' : text}]

# Make the API request
response = client.post(f"{endpoint}/translate", headers=headers, params=params,
json=body)

# Check the status of the request
if response.status_code == 200:
# On success, return the translated text
return response.json()[0]['translations'][0]['text']
else:
# On failure, return a message indicating the error
return f"Translation request failed with status code {response.status_code}"

Yes, I know I can put them in myLeoSettings.leo or ~/.leo/functions, but I
plan to refine them or add tests in future. So I think plugin is the right
place?(correct me if I'm wrong)

If my plugins and some leo node scripts rely on these
personal_common_functions, I believe putting them all to the plugin system
is a reasonable choice? Maybe I'm wrong.



> class Hiliter:
>     def __init__(self, cc):
>         self.c = cc
>         w = cc.frame.body.wrapper
>         self.editor = w.widget
>     # .....
>
> # Install the highlighter in all commanders
> for cc in g.app.commanders():
>     cc.hiliter = Hiliter(cc)
>
> cc.hiliter.editor.cursorPositionChanged.connect(cc.hiliter.highlightCurrentLine)
>
an interesting function!


-- 
--
Sincerely,

HaveF

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/CA%2BUQrQwmrrsuJZqWu8hx7tR33iyLu0yEkM%2BJfk8Spc2%3D1nf6bg%40mail.gmail.com.

Reply via email to