-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGM Example HUD.py
More file actions
35 lines (28 loc) · 1.33 KB
/
GM Example HUD.py
File metadata and controls
35 lines (28 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import sys
from functools import partial
import maya.OpenMayaUI as OpenMayaUI
from shiboken6 import wrapInstance
from PySide6 import QtWidgets
def create_hud():
# Create an instance of the M3dView class and get the 3D view from the modelPanel4 in Maya
view = OpenMayaUI.M3dView()
OpenMayaUI.M3dView.getM3dViewFromModelPanel("modelPanel4", view)
# Get the model view as a QtWidget for python2 and python3
if sys.version_info.major < 3:
model_view_widget = wrapInstance(long(view.widget()), QtWidgets.QWidget)
else:
model_view_widget = wrapInstance(int(view.widget()), QtWidgets.QWidget)
# Create ui buttons
green_button = QtWidgets.QPushButton("Green button", model_view_widget)
# Get the center position of the model view and place the ui buttons based on that position
window = model_view_widget.geometry()
green_button.setGeometry(window.x() + 10, window.y() + 10, 150, 50)
green_button.setStyleSheet("background-color: green")
# Connect button to a command and display it
green_button.clicked.connect(partial(button_command, string="Green button pressed!", button_widget=green_button))
green_button.show()
def button_command(string, button_widget):
print(string)
button_widget.close()
button_widget.deleteLater()
create_hud()