Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible method of making Compound Controls #84

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions mGui/core/compound.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@

import weakref

from .controls import IntField, IconTextButton, Button, Text
from ..forms import HorizontalStretchForm, VerticalStretchForm
from ..events import MayaEvent


class CompoundControl(type):
# Some magic will happen here?
pass


class IntSpinner:
__metaclass__ = CompoundControl

_CONTROLS = {
'root': HorizontalStretchForm,
'field': IntField,
'label': Text,
'decrement': Button,
'increment': Button,
'form': VerticalStretchForm,
}
_HIERARCHY = {
'root': (
'label',
'field', {
'form': (
'increment',
'decrement'
)
}
)
}


class IntSpinner(object):

def __init__(self, key=None, **kwargs):
self._step = kwargs.pop('step', 1)
value = kwargs.pop('value', 0)

height = kwargs.pop('height', kwargs.pop('h', 32))
width = kwargs.pop('width', kwargs.pop('w', 256))
with HorizontalStretchForm(key='IntSpinner#', **kwargs) as self.root:
self.field = IntField(height=height, width=width - height, value=value)
with VerticalStretchForm() as self.form:
self.increment = Button(height=height / 2, width=height, label='^')
self.decrement = Button(height=height / 2, width=height, label='v')

self.increment.command += self._inc
self.decrement.command += self._dec

@property
def step(self):
return self._step

@step.setter
def step(self, value):
self._step = value

def _inc(self, *args, **kwargs):
self.field.value += self._step

def _dec(self, *args, **kwargs):
self.field.value -= self._step

def __getattr__(self, attr):
if hasattr(self, 'root') and hasattr(self.root, attr):
return getattr(self.root, attr)
return super(IntSpinner, self).__getattribute__(attr)

def __setattr__(self, attr, value):
if hasattr(self, 'root') and hasattr(self.root, attr):
setattr(self.root, attr, value)
else:
self.__dict__[attr] = value