I want to insert a button into the main status line in Maya, it is the line where the functions like, save scene, vertex snap, open render view and stuff like this is(screenshot).
I already can add a button to the line, but it gets appended all the way to the right.
But how do I insert it between already existing buttons?
I want for example that my button is between the "Open Renderview" and "Render the current frame" button.
The code adds a button to the status line in Maya:
import maya.cmds as cmds
MainStatusLineLayoutChildren = cmds.layout('MainStatusLineLayout', query = True, childArray = True)
a = cmds.layout(MainStatusLineLayoutChildren[0], query = True, childArray = True)
cmds.nodeIconButton('testIconButton', style = 'iconOnly', image1 = 'file.png', parent = a[0])
Related
I am working on a PyGTK application with a Gtk.Toolbar. One of the items in taht toolbar is a Gtk.MenuToolButton. However, clicking on the arrow once the program runs results in an empty menu (a tiny white sliver). Here is the code that sets up the menu:
self.compileMenu = Gtk.Menu()
self.defaultCompileOption = Gtk.MenuItem(label = "Compile with defaults")
self.configCompileOption = Gtk.MenuItem(label = "Change compile options...")
self.compileWithFiles = Gtk.MenuItem(label = "Bundle files...")
self.compileMenu.append(self.defaultCompileOption)
self.compileMenu.append(self.configCompileOption)
self.compileMenu.append(self.compileWithFiles)
self.compileButton = Gtk.MenuToolButton(icon_name = "x-package-repository", label = "Compile...", menu = self.compileMenu)
There is also a call to self.toolbar.add at the bottom, to add the MenuToolButton to the toolbar.
Found the issue! Turns out that for some reason you need to call, in my case, compileMenu.show_all() to make it realize that you added things to it.
I'm using the ipyvuetfy lib that create nice dashboarding element based ont he vuetify.js lib and ipyvwidgets.
I need to place a dialog in a specific position (on top of another element) like this menu placed on top of a select folder btn.
How can I access the the current position of a widget relative to the window ?
It is possible with Javascript code, by identifying the widget with a custom class and using the jQuery offset() method, and then setting the DOM Style top and left properties of the child (here a Card) of the ipyvuetify Dialog, with the style position set as fixed. I haven't found how to execute the JS code via the Dialog activator slot, so the Dialog widget is triggered via the click.stop event:
import ipyvuetify as v
import ipywidgets as w
from IPython.display import Javascript
out = w.Output(layout={'display': 'none'})
js = '''
var x = $(".myparentwidget").offset();
var d = document.getElementsByClassName("mydialog")[0];
d.style.top = x.top+"px";
d.style.left= x.left+"px";'''
def on_click(widget, event, data):
dialog.v_model=True
with out:
display(Javascript(js, lib="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"))
btn = v.Btn(
children=["Open dialog"],
class_='myparentwidget'
)
btn.on_event("click.stop", on_click)
dialog = v.Dialog(
v_model=False,
children=[
v.Card(
class_='mydialog',
style_="position: fixed; width: 300px",
children=[
v.CardTitle(children=["Dialog window"]),
v.CardText(children=['Dialog text']),
]
)
],
)
v.Layout(children=[btn,dialog,out])
I'm creating a tkinter GUI for the purposes of opening and analyzing an EDF file named "raw" using the mne package. Currently, when I run the script, named "my_script.py", it first prompts me to open a file using the following code:
window = Tk()
window.filename = filedialog.askopenfilename(initialdir = "Users/fishbacp/Desktop",title =
"Select file",filetypes = (("EDF files","*.edf"),("all files","*.*")))
raw = mn.io.read_raw_edf(window.filename, preload=True)
# Now perform my first operation on the returned file, "raw":
data,times=raw[:,:]
# In subsequent lines I fill my gui with checkboxes, input boxes, labels etc. to perform more tasks.
This works fine, but the file dialog starts before I see the various widgets in my window.
Now I want to run the module so that instead of the file dialog starting automatically, I first see the GUI and then use a button in it to run the file dialog. Here's my attempt:
window = Tk()
def open_file():
window.filename = filedialog.askopenfilename(initialdir = "Users/fishbacp/Desktop",title
= "Select file",filetypes = (("EDF files","*.edf"),("all files","*.*")))
raw = mn.io.read_raw_edf(window.filename, preload=True)
return raw
open_file_button=Button(window, bg='lightgray',text="Select
File",command=open_file)
open_file_button.grid(row=0,column=0,padx=10, pady=10)
# Now perform my first operation on the returned file, "raw":
data,times=raw[:,:]
The error message states, "Traceback (most recent call last):
File "/Users/fishbacp/Desktop/my_script.py", line 67, in
data,times=raw[:,:]
NameError: name 'raw' is not defined
So, I'm missing something basic about how tkinter works in terms of what I should be doing to get my open_file function return the raw file as I want.
You cannot return something from the command callback. Your code processing raw content depends on the fact a button has been clicked by the user. It hence has to be located in the callback itself.
Some more clarification:
When creating a UI, you go from procedural programing (one thing after the other) to event driven programing: a User event triggers the next operation the program will do. It is because the user will click "open file" button that you can process the data. The call to windows.mainloop() tells TK to start processing user events (clicks,...). In practice you cannot do anything on the edf file as long as user has not clicked on the button so it makes sense to put all this code in the callback.
Something like: is a starting point:
window = Tk()
def open_file():
window.filename = filedialog.askopenfilename(initialdir = "Users/fishbacp/Desktop",title
= "Select file",filetypes = (("EDF files","*.edf"),("all files","*.*")))
raw = mn.io.read_raw_edf(window.filename, preload=True)
# Now perform my first operation on the returned file, "raw":
# this can be done only once the user has selected the file to open
# which is "triggered" by the user clicking on "Select File"
data,times=raw[:,:]
...
open_file_button=Button(window, bg='lightgray',text="Select
File",command=open_file)
open_file_button.grid(row=0,column=0,padx=10, pady=10)
I am making an app for ubuntu 12.04.What i want to do is add an option to the menubar which appear when we right click on some select option.
To make it more clear-
In Normally when we select some text and right click there appear some option like cut copy pasteI want to add another option how can i do it.
When clicked the option would just have to execute another application and send the selected data to that applicaion.
I would be using Glade with python for development.
you should know some basics about glade and gtk first. the following is just notes:
1-On glade you can use the menu button to create menu.
2-Right click on it an dchoose "edit ..."
3-from the window you can add items.(the right part display the name and type of the menu item , the left part display the properties of the selected item, the lower part display the signals which could connected to the menu item)
4- now connect the menu item with the function which do what you want (When clicked the option would just have to execute another application and send the selected data to that applicaion.)
5- go to your code. get the menu as usual .
self.menu = self.builder.get_object("menu")
6- to popup the menu on right click on an object, you should connect that object with the function ahich execute the menu ( assuming that its name is :on_button_press ) :
def on_button_press(self, treeview, event):
if event.button == 3:
x = int(event.x)
y = int(event.y)
time = event.time
pthinfo = treeview.get_path_at_pos(x, y)
if pthinfo is not None:
path, col, cellx, celly = pthinfo
treeview.grab_focus()
treeview.set_cursor( path, col, 0)
self.popupmenu.popup( None, None, None, event.button, time)
return True
In my ongoing effort to learn more about python, I am trying to add a right click event to my mp3 manager program. What currently works is that it shows the menu and all of the options. What is not working is the functions selected from the menu are not executing as I think they should be. Much of this code was taken from a 'how to' on another site.
Here are the right click menu options
menu_titles = ["Remove Selection from list",
"Delete Selection from system",
"Move Selection",
"Copy Selection",
"Print Selection"]
menu_title_by_id = {}
for title in menu_titles:
menu_title_by_id[ wxNewId() ] = title
The code that is run when the right click event happens
def RightClickCb( self, event ):
# record what was clicked
self.list_item_clicked = right_click_context = event.GetText()
### 2. Launcher creates wxMenu. ###
menu = wxMenu()
for (id,title) in menu_title_by_id.items():
### 3. Launcher packs menu with Append. ###
menu.Append( id, title )
### 4. Launcher registers menu handlers with EVT_MENU, on the menu. ###
EVT_MENU( menu, id, self.MenuSelectionCb )
### 5. Launcher displays menu with call to PopupMenu, invoked on the source component, passing event's GetPoint. ###
self.MainPanel.PopupMenu( menu, event.GetPoint() )
menu.Destroy() # destroy to avoid mem leak
def MenuSelectionCb( self, event ):
# do something
operation = menu_title_by_id[ event.GetId() ]
target = self.list_item_clicked
print 'Perform "%(operation)s" on "%(target)s."' % vars()
What I expect to get when I do a right-click and then select one of the options in the menu is the output
Perform "Print Selection" on "<data about the selection here>"
What I am getting is
Perform "Print Selection" on "."
How do I get the data from the item I have selected as part of my right click event?
Maybe you should use event.GetString() in place of event.GetText()
See here
Your code seems outdated tho, binding to events should be done like this:
menu.Bind(wx.EVT_MENU, self.MenuSelectionCb, id=id)
moreover if you bind all ids to the same function you can just bind once for all ids:
menu.Bind(wx.EVT_MENU, self.MenuSelectionCb)
You can find a solution under Python: Right click on objectlistview not showing item name selected where the use of objectlistview's GetSelectedObject() method is proposed instead.