i have this $shelfButtons = shelfLayout -q -ca $currentTab;
to get the name of the button there , shelfButton153
but how to click that button with mel? i cant click it with mouse because i need activate it inside some script... if try get the command from button i get pymel.internal.factories.callback...... because comes from some <function callback at 0x000001C578D25F98> any way to can run the button in the shelf? everytime that function will be different , so i need get that function information and execute it to can open a window coming from that function....
Related
I'm sorry if this question has already been answered, but I couldn't find anything on here (except this one which hasn't been answered: link and one that doesn't quite answer the question i'm asking link
I'm creating a button with ipywidgets, but the script doesn't wait for the button to be clicked. Here's a sample of the code/what I'm trying to achieve:
button = widgets.Button(description = "Click")
output = widgets.Output()
display(button, output)
def on_button_clicked(b):
with output:
print("button clicked")
button.on_click(on_button_clicked)
print("Python is ignoring you")
If I run this, I'll just get "Python is ignoring you" before I click the button. I want it to display the button, wait for the person to click it, and only then execute the rest ("Python is ignoring you").
Does anyone have an idea of how I can make python wait for the button to be clicked?
Would appreciate any help! Thanks
I never used the ipywidgets, but the problem is on the last line
you're telling python to print "Python is ignoring you" and python is doing it.
It will not wait for the user to click the button,
because the print statement is out the function "on_button_clicked".(or any)
So just Put it in the function. (That print Statement)
I was wondering if it is possible to launch a different script in Maya when right clicking on a custom shelf button verses a left click. So a traditional left click of the button would launch one version of the script, but a right click ( or some other action ) would execute a different version of the script.
Yes it is possible. What you can do is add a shelf button with cmds.shelfButton, then attach a pop-up menu with cmds.popupMenu where you can put as many commands as you want. cmds.popupMenu has a parameter button where you can specify what mouse button triggers the pop-up to show up.
import maya.cmds as cmds
# Put in what shelf tab to add the new button to.
shelf = "Rigging"
# Throw an error if it can't find the shelf tab.
if not cmds.shelfLayout(shelf_name, q=True, exists=True):
raise RuntimeError("Not able to find a shelf named '{}'".format(shelf_name))
# Create a new shelf button and add it to the shelf tab.
# Include `noDefaultPopup` to support a custom menu for right-click.
new_shelf_button = cmds.shelfButton(label="My shelf button", parent=shelf, noDefaultPopup=True)
# Create a new pop-up menu and attach it to the new shelf button.
# Use `button` to specify which mouse button triggers the pop-up, in this case right-click.
popup_menu = cmds.popupMenu(parent=new_shelf_button, button=3)
# Create commands and attach it to the pop-up menu.
menu_command_1 = cmds.menuItem(label="Select meshes", sourceType="python", parent=popup_menu, command='cmds.select(cmds.ls(type="mesh"))')
menu_command_2 = cmds.menuItem(label="Select joints", sourceType="python", parent=popup_menu, command='cmds.select(cmds.ls(type="joint"))')
menu_command_3 = cmds.menuItem(label="Select all", sourceType="python", parent=popup_menu, command='cmds.select("*")')
I am new using Tkinter to create GUIs. I would like to create a GUI which has a button that when pressed it executes some command lines.
This is the code for creating the button:
ros_start_button = Button(bottom_frame, text="Start ROS", command=self.start_ROS)
ros_start_button.pack(side=LEFT)
the code fro self.start_ROS is
def start_ROS(self):
os.system("bash start_ROS.sh")
where start_ROS.sh is an sh file which code is:
echo "Starting ROS";
cd;
source /home/m/PycharmProjects/ROSAutonomousFlight/catkin_ws/devel/setup.bash;
roslaunch ardrone_numeric_method_controller ardrone.launch;
When I press the button it is like the GUI is frozen until I stop the process that is executed by roslaunch .... I would like to know what can I do in order to just press the button, but not get the GUI frozen because I have other buttons that have to be pressed after this button.
Thank you in advance!
I am making a box that is similar to the tkMessageBox. There are two simple behaviors that I want to the box to have. First I want the button to be selected automatically when the window opens, and second I want to be able to press enter to push the button. Sounds simple and I realize that I could use the tkinterMessageBox to do this same thing, but this is a stepping stone, and I would like to know how to do this in the future for other things.
The current behavior of the window below is that it opens, and if I press tab it will select the button, but then i can only press the button with the mouse. Again the desired functionality is to have the button selected right away and be able to press the button with the enter key.
import Tkinter, tkMessageBox
from Tkinter import *
def closewindow():
Messagebox.destroy()
Messagebox=Tk()
l3=Label( Messagebox, text="This is your preview! Align camera then press ESC")
b3=Button(Messagebox, text="Okay", command=closewindow)
l3.grid(row=1,column=1)
b3.grid(row=2,column=1)
Messagebox.mainloop()
You can actually do this with just two lines of code:
b3.bind('<Return>', lambda _: closewindow())
b3.focus_set()
The first binds the button to the Enter key and the second sets the application's focus on the button.
Note that I had to use a lambda with the binding to handle the event object that will be sent to the callback. You could however change the definition of closewindow to handle this:
def closewindow(event=None):
Messagebox.destroy()
Now you can just do:
b3.bind('<Return>', closewindow)
For more information on bindings in Tkinter, see Events and Bindings over on Effbot.
I have a Dialog Window with a TreeView and two Buttons (Gtk.ResponseType.CANCEL and Gtk.ResponseType.ACCEPT). I can't find how to activates the ResponseType.ACCEPT button when I press Enter inside the Gtk.TreeView. I set cant_datault on desired button and set_default on GtkDialog but Gtk.TreeView doesn't have an activates default method.
Is there any way I can do this?
The quickest way I could find would be to use the "row-activated" signal within the TreeView. This is activated whenever you press Enter, double-click an item or press the Spacebar.
So for example:
treeview.connect("row-activated", lambda a, b, c: dialog.response(Gtk.ResponseType.ACCEPT))
I've used lambda to create the anonymous function, but if you have anything else that needs to run at the same time, you can swap it for a proper function.
Just be aware that if you also change your default response in the future, you'll need to update this function as well.