On Fri, Jul 8, 2016 at 4:22 AM yann19 <[email protected]> wrote:

> Hi, do you have an example in which I can refer to, if possible?
>
> Truth be told, I am still pretty much of an amateur in scripting. And this
> script that I am editing was not my code to begin with and I am still
> trying to grasp how it works in certain parts
>

This may be an incorrect interpretation of your modules, but something like
this?

## Module fooclass Context(object):

  def __init__(self):
    self.itemName = ""
## Module meshPaintConclass PaintSurfacer(object):

  def __init__(self, context):
    self.context = context

  def fetchObject(self):
    if self.context.itemName:
      # use it
## Module uiimport fooimport meshPaintCon
class MeshPaintWin(object):

  def __init__(self):
    self._context = foo.Context()
    self._painter = meshPaintCon.PaintSurfacer(self._context)

  def uiButtonCallback(self, *args):
    self._context.itemName = mc.ls(l=True, sl=True)[0]

​

See how your UI creates a context that is then given to your business
logic? You no longer have global variables if you do this. And it means you
could have multiple instances of the window running without values
colliding.

You may not even need to use a Context, if you can just set values directly
on your painter instance:

## Module meshPaintConclass PaintSurfacer(object):

  def __init__(self):
    self.itemName = ""

  def fetchObject(self):
    if self.itemName:
      # use it
## Module uiimport meshPaintCon
class MeshPaintWin(object):

  def __init__(self):
    self._painter = meshPaintCon.PaintSurfacer()

  def uiButtonCallback(self, *args):
    self._painter.itemName = mc.ls(l=True, sl=True)[0]

​

Justin



>
>
> On Wednesday, July 6, 2016 at 8:50:27 PM UTC-7, Justin Israel wrote:
>>
>> If I am reading your examples correct, it would appear you are using your
>> foo module as a kind of global scratch pad for storing and sharing data
>> between unrelated function calls in your UI and your business logic
>> modules. You might try making your business logic capable of storing
>> everything it needs to do its work. Your UI should be creating an instance
>> of it and managing it over time. That is, setting item name should be
>> something you do on an instance of your business logic class. Not a global
>> in a module.
>>
>> Justin
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/cf47679d-44ba-49d1-a086-43d6fb422759%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/cf47679d-44ba-49d1-a086-43d6fb422759%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2bE6bPwHHK26aUBtv-NzpL_YUsQF3WSSvCpqVy%3DY55pQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to