Created
October 21, 2015 16:07
-
-
Save mattcox/1ffe6ab52babe2813fdd to your computer and use it in GitHub Desktop.
A pointless command that demonstrates how to use a notifier without arguments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import lx | |
import lxu.command | |
import modo | |
class Command (lxu.command.BasicCommand): | |
def __init__ (self): | |
lxu.command.BasicCommand.__init__ (self) | |
self.not_svc = lx.service.NotifySys () | |
self.notifier = lx.object.Notifier () | |
def basic_Enable (self, msg): | |
selected = modo.current ().selectedByType (lx.symbol.sITYPE_MESH) | |
return len (selected) > 0 | |
def cmd_Flags (self): | |
return 0 | |
def basic_Execute (self, msg, flags): | |
selected = modo.current ().selectedByType (lx.symbol.sITYPE_MESH) | |
for item in selected: | |
lx.out (item.name) | |
def cmd_NotifyAddClient (self, argument, object): | |
self.notifier = self.not_svc.Spawn ("select.event", "item +d") | |
self.notifier.AddClient (object) | |
def cmd_NotifyRemoveClient (self, object): | |
self.notifier.RemoveClient (object) | |
lx.bless (Command, "mesh.printName") |
Also worth noting is the argument index. This will be -1 for the entire command, and may be called again will the index of a particular argument (usually the one queried in the form).
This can be used together with the notifiers in UIValueHints, which only operate on specific arguments.
On a different note: there is a shortcut for common item types, so
selected = modo.current ().selectedByType (lx.symbol.sITYPE_MESH)
can be substituted with
selected = modo.Scene().meshes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think it should go like this instead:
First, initialize the notifier to None instead of lx.object.Notifier(), just so we can tell that it isn't set to anything.
self.notifier = None
cmd_NotifyAddClient() should then only Spawn() the notifier if it is not None:
This ensures that multiple clients can be added to a given notifier and will get properly removed later, and we don't allocate extra notifier instances that we don't need.