start OSX color chooser from python plugin

Posted on
Wed Mar 12, 2014 11:08 pm
kw123 offline
User avatar
Posts: 8392
Joined: May 12, 2013
Location: Dallas, TX

start OSX color chooser from python plugin

The attached code will launch OSX color chooser ( color spectrum slider etc ) and will return the chosen color as 3*1byte hex eg ffaa45

can be used in plugin config to choose the color of an object.
Code: Select all
   def startColorWheel(self):
      rgbINT = ["" for i in range(3)]
      try:
         p= os.popen("osascript -e 'tell application \"finder\" to activate  return choose color' ")  # start color chooser / wheel / spectrum
         rgbINT = p.read().strip("\n").split(",")  # returns eg '65145,32007,13\n' --> {65145,32007,13}
         p.close()
         # convert form 0-65xxx to 0-255 ie 16 bit to 8 bit then drop the x0 infront of ff  --> ffaa82 and concatenate
         rgbHEX = str(hex(int(int(rgbINT[0])/256)))[2:] +str(hex(int(int(rgbINT[1])/256)))[2:]+str(hex(int(int(rgbINT[2])/256)))[2:]
      except:
         return""
      return rgbHEX

Posted on
Thu Mar 13, 2014 8:30 am
RogueProeliator offline
User avatar
Posts: 2506
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: start OSX color chooser from python plugin

Nicely done, Karl... don't have an immediate need for this but will definitely file this away in the event the occasion comes to use it. Interesting way to get additional functionality... Might have to look into that for possibility of a date chooser too, if that color picker is easy to use in practice.

Adam

Posted on
Thu Mar 13, 2014 8:36 am
matt (support) offline
Site Admin
User avatar
Posts: 21429
Joined: Jan 27, 2003
Location: Texas

Re: start OSX color chooser from python plugin

Neat! We really need to add UI field types for color picker, date/time picker, etc.

FYI, a couple of caveats on the approach above: 1) it will launch the color picker on your Indigo Server Mac, which in theory can be a different Mac than what is running the Indigo Client, 2) if the user takes too long to pick a color than the plugin's UI callback might timeout.

Image

Posted on
Thu Mar 13, 2014 9:04 am
kw123 offline
User avatar
Posts: 8392
Joined: May 12, 2013
Location: Dallas, TX

Re: start OSX color chooser from python plugin

time-outs, when not clicking ok/cancel in in the color chooser:
after ~ 1 minute the color wheel appears in indigo , but no harm
after ~ 2 minutes error messages in log file, no harm

after that
clicking OK in the color chooser goes back to indigo and everything works

Posted on
Thu Mar 13, 2014 9:14 am
kw123 offline
User avatar
Posts: 8392
Joined: May 12, 2013
Location: Dallas, TX

Re: start OSX color chooser from python plugin

and here the code in the plugin to use it:

1. the config Button definition:
Code: Select all
<Field id="idBbuttonGetColor1" type="button" tooltip="This launches mac color chooser ">
   <Label>Color Wheel</Label><Title>Select</Title>
   <CallbackMethod>buttonGetColor1</CallbackMethod>
</Field>


2. the corresponding code in the plugin
Code: Select all
   
   def buttonGetColor1(self, valuesDict=None, typeId="", targetId=0):
      self.RGBreturned[1]= self.startColorWheel()  # store the response for later use


It is actually very simple and to use just make sure the "buttonGetColor1" is the same in the config and the py code.

and the screen shot for the button:
colorw.tiff
colorw.tiff (7.2 KiB) Viewed 2918 times


and the color chooser
colorw2.tiff
colorw2.tiff (52.43 KiB) Viewed 2917 times

Posted on
Thu Mar 13, 2014 9:37 am
RogueProeliator offline
User avatar
Posts: 2506
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: start OSX color chooser from python plugin

Matt:

I thought about the client not being on the Indigo Server computer... can you think of an easy to check that situation? I am a bit vague on what executes where (client computer versus server) in regards to a plugin, but I imagine there could be some what to compare computer names/IPs/whatever?

Adam

Posted on
Thu Mar 13, 2014 9:48 am
matt (support) offline
Site Admin
User avatar
Posts: 21429
Joined: Jan 27, 2003
Location: Texas

Re: start OSX color chooser from python plugin

There isn't currently a way to tell what Mac (IP address/etc) initiated the plugin callback. By the time the plugin is called that information is stripped. The commands actually pass from the Indigo Client (GUI, config dialog button press in this case) to the Indigo Server, which then relays them to the correct plugin. So from the plugin's perspective they are coming from the server.

FYI, all plugins and scripts (embedded or linked, AppleScript or python) are executed on the Indigo Server Mac. The remote Mac can just run the GUI app that drives the server, but all the heavy lifting occurs on the Indigo Server Mac. There is the possibility that in the future plugins can run on secondary Macs as well -- that can actually work right now, but we have some plugin management layer work to be done first to handle starting/stopping remote plugins. Additionally, I'm not sure if there is a strong enough use-case yet to justify the work needed on remote plugins (but I think it is cool that the plugin framework supports it).

Image

Posted on
Thu Mar 13, 2014 10:49 am
RogueProeliator offline
User avatar
Posts: 2506
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: start OSX color chooser from python plugin

Thanks for the clarification, Matt... I'll probably avoid using functions that are specific to the Indigo Server Mac in general then (unless I create a backup of being able to just type them in). Sounds like it isn't worth the trouble.

Yeah, I agree that running the plugins on a remote Mac is interesting and may have some uses, but not likely to have the benefit/impact that other priorities and features would have.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests