hi everyone, I am currently trying to create a class to call on various python files to use as a base for creating my different UIs.
Since I’m quite a beginner in scripting, I’m not very good at it, and would like to have the help of someone on my small problem.
here’s my ui_base_setup:This text will be hidden
from maya import cmds
import os
def _null(*args):
pass
class _ui():
def __init__(self, name="customName", title='', winWidthHeight=(0,0), s=True):
self.name = name
self.width = winWidthHeight[0]
self.color = colorUI = []
with open(os.path.join(os.path.dirname(__file__), "colors.dat"), 'r') as f:
for i in f:
x = float(i)
colorUI.append(x)
f.close()
self._deleteUI()
self.window = cmds.window(self.name, title = title, wh = winWidthHeight, s = s)
cmds.formLayout(nd=100)
cmds.showWindow(self.window)
self.build()
def _deleteUI(self):
if cmds.window(self.name, exists=True):
cmds.deleteUI(self.name)
def build(self):
pass
def addButton(self, name, label, align, height, command, buttonName):
buttonName = cmds.button(name, l = label, align = align, bgc = self.color, w = self.width, h = height, command = command)
and here’s my other file where I call the function
from maya import cmds
import os
from importlib import reload
colorUI = []
from WB_Utils.shelves import ui_base
reload(ui_base)
class load(ui_base._ui):
def build(self):
self.addButton('test', label = 'testReussis', align = 'center', height = 30, command='', buttonName = 'test')
cmds.formLayout(attachForm = [('test', 'top', 100), ('test', 'left', 5)])
but when using the cmds.formLayout it asks for the button name, but when I provide it it just tells me that in the class from the main file, this button doesn’t exist…
does someone have an idea on how to accomplish this?
My only solution is to rely on only columnLayout… but the formLayout is better since you can uspcale your windows after…