0

I'm trying to update my UI via a variable in another python file. Both are in there own class. Both saved in a folder called: System. As I don't want to re-execute UI, I can't simply import the file. My question: how does one change a variable from another class in another file, without re-executing?

toolsUI.py

class toolsUI:
    def __init__(self):
        # Store UI elements in a dictionary
        self.UIElements = {}

        if cmds.window("UI", exists=True):
            cmds.deleteUI("UI")

        self.UIElements["window"]=cmds.window("UI", width=200, height=600, title="UI")
        self.createColumn() # Create Column

        # Display window
        cmds.showWindow(self.UIElements ["window"])

    def createColumn(self):
        self.UIElements["column"] = cmds.columnLayout(adj=True, rs=3)
        self.UIElements["frameLayout"] = cmds.frameLayout(height=columnHeight, collapsable=False, borderVisible=True, label="To Change Label")

maintenance.py

class maintenance:
    def __init__(self):
        changeLabel = "Label is Changed"

        self.changeLabelColumn(changeLabel) # Change Label Column

    def changeLabelColumn(self, changeLabel):
        import System.toolsUI as toolsUI """<--- probably not a good idea"""
        cmds.frameLayout(toolsUI.UIElements["frameLayout"], edit=True, label=changeLabel)
Ryan Haining
  • 35,360
  • 15
  • 114
  • 174
Tommy
  • 11
  • 1
    this is pretty weird, what exactly are you trying to achieve as an end result here? – Ryan Haining May 25 '15 at 22:46
  • Well, this is not the actual code. I have made this example to simplify what I'm trying to achieve, instead of posting +1000 lines of code. As I'm basically just looking for the right syntax here. I must say. I'm very new to Python, and have probably used the wrong search terms to find my answer. To explain things a bit more. I have two UI's in my scene. Both created with there own scripts. I'm trying to get pass some variables from one to the other. I am scripting for Maya. – Tommy May 25 '15 at 23:10
  • `toolsUI` is a class, `toolsUI.UIElements` is looking for a class level variable which doesn't exist – Ryan Haining May 25 '15 at 23:16
  • are you very new to python specifically or programming in general? – Ryan Haining May 25 '15 at 23:16
  • I see. Then my idea would be to create a variable in toolsUI. Guess I am going to try that. Hope it gets me somewhere. Thanks. I new to programming in general. I'm a third year visual art student. Specializing in rigging, and now extending my skills by learning python. Slowly getting there.. – Tommy May 25 '15 at 23:36

1 Answers1

0

The right way to do this afaict would be to create an object of the toolsUI type, and then operate on that instead.

import System

class maintenance:
    def __init__(self):
        changeLabel = "Label is Changed"
        self.ui = System.toolsUI() # create a new object
        self.changeLabelColumn(changeLabel)

    def changeLabelColumn(self, changeLabel):
        cmds.frameLayout(
            self.ui.UIElements["frameLayout"],  # use the object instead
            edit=True, 
            label=changeLabel)

this way you can have multiple toolsUI objects that don't interfere with each other.

Ryan Haining
  • 35,360
  • 15
  • 114
  • 174