Hi,
What would be the Action parameter to configure a CustomButton to run a sepecific script?
T&R
Action in Button to run script
- admin
- Site Admin
- Posts: 13339
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: Action in Button to run script
Hi,
you can just pass the function that you want the button to invoke that parameter – see this post for a simple example
viewtopic.php?t=169#p712
Cheers, Robin
you can just pass the function that you want the button to invoke that parameter – see this post for a simple example
viewtopic.php?t=169#p712
Cheers, Robin
Re: Action in Button to run script
Thank you Robin, I had already tested that and works perfectly ... but I want to run a py script and I dont find the action to invoke this.
T&R
T&R
- admin
- Site Admin
- Posts: 13339
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: Action in Button to run script
Hi,
I'm afraid I'm not understanding quite what you're trying to achieve then. Do you have a separate .py file that you want to run code from? If you have a file called x.py in c:\src, then I think you can do
(note the syntax for the above may be incorrect, but hopefully the idea is correct).
Cheers, Robin
I'm afraid I'm not understanding quite what you're trying to achieve then. Do you have a separate .py file that you want to run code from? If you have a file called x.py in c:\src, then I think you can do
Code: Select all
sys.path.append('c:\src')
import x
# now you can call functions from x.py
Cheers, Robin
Re: Action in Button to run script
Thank you again for your support (and patiente)
I have re-read my request and it was not clear at all. I have already solved my issue but I will explain it here just in case someone else needs it.
I had a couple of scripts that run as forms; I use them very often so I wanted to have a button instead of searching in menus and folders to run them (lazyness)
The way they normally ran was:
Now, in order to have a button for them I have substituted this by:
I have re-read my request and it was not clear at all. I have already solved my issue but I will explain it here just in case someone else needs it.
I had a couple of scripts that run as forms; I use them very often so I wanted to have a button instead of searching in menus and folders to run them (lazyness)
The way they normally ran was:
Code: Select all
form = MoveToAltAz()
Application.Run(form)
Code: Select all
form = MoveToAltAz()
def show_script():
form.ShowDialog()
SharpCap.AddCustomButton("GOTO AltAz", None, None, show_script)
Re: Action in Button to run script
Just to make it a bit more elegant ... how can I associate an image to the icon?
A file address does not work
T&R
A file address does not work
Code: Select all
SharpCap.AddCustomButton("GOTO AltAz", '..\image.png', None, show_script)
- admin
- Site Admin
- Posts: 13339
- Joined: Sat Feb 11, 2017 3:52 pm
- Location: Vale of the White Horse, UK
- Contact:
Re: Action in Button to run script
Hi,
you need to pass a .NET System.Drawing.Bitmap object, which does have a constructor that takes a file path to an image file.
Hope this helps, Robin
you need to pass a .NET System.Drawing.Bitmap object, which does have a constructor that takes a file path to an image file.
Code: Select all
clr.AddReference("System.Drawing")
from System.Drawing import Bitmap
image = Bitmap("..\\image.png")