Skip to content

Commit

Permalink
adding support for more than just colors
Browse files Browse the repository at this point in the history
  • Loading branch information
sbaer committed May 18, 2011
1 parent 29a779f commit 8887fb8
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions cloudsettings.py
Expand Up @@ -4,8 +4,7 @@
"""
import sys, json, urllib, urllib2, hashlib
import rhinoscriptsyntax as rs
import System
import Rhino
import System, Rhino

couchdb_url = "https://stevebaer.cloudant.com/rhinotest"

Expand All @@ -15,22 +14,24 @@ def cloudrestore(id):
Parameters:
id: name of the document store in the database
"""
url = couchdb_url + "/" + id
f = urllib.urlopen(url)
f = urllib.urlopen(couchdb_url + "/" + id)
data = json.load(f)
f.close()
if data.has_key("error") or not data.has_key("AppearanceSettings"):
return data
def restorecolor(name, color):
def restoresetting(name, setting):
try:
s = "Rhino.ApplicationSettings.AppearanceSettings." + name
s += "=System.Drawing.ColorTranslator.FromHtml(\"" + color + "\")"
if name.endswith("Color"):
s += "=System.Drawing.ColorTranslator.FromHtml(\"" + setting + "\")"
else:
if type(setting) is str: s += "='" + setting + "'"
else: s+= "=" + str(setting)
exec(s)
except:
print sys.exc_info()
subdict = data["AppearanceSettings"]
for k, v in subdict.items():
restorecolor(k,v)
for k, v in data["AppearanceSettings"].items():
restoresetting(k,v)
rs.Redraw()


Expand Down Expand Up @@ -69,10 +70,7 @@ def cloudsave(id, password=None):
if hashed_password:
data["password_hash"] = hashed_password
subdict = {}
if data.has_key("AppearanceSettings"):
subdict = data["AppearanceSettings"]
else:
data["AppearanceSettings"] = subdict
data["AppearanceSettings"] = subdict

def addcolor(dict, name):
s = "Rhino.ApplicationSettings.AppearanceSettings." + name
Expand All @@ -82,6 +80,8 @@ def addcolor(dict, name):
addcolor(subdict, "CommandPromptHypertextColor")
addcolor(subdict, "CommandPromptTextColor")
addcolor(subdict, "CrosshairColor")
addcolor(subdict, "CurrentLayerBackgroundColor")
addcolor(subdict, "DefaultObjectColor")
addcolor(subdict, "FeedbackColor")
addcolor(subdict, "FrameBackgroundColor")
addcolor(subdict, "LockedObjectColor")
Expand All @@ -92,23 +92,25 @@ def addcolor(dict, name):
addcolor(subdict, "WorldCoordIconXAxisColor")
addcolor(subdict, "WorldCoordIconYAxisColor")
addcolor(subdict, "WorldCoordIconZAxisColor")
subdict["DefaultFontFaceName"] = Rhino.ApplicationSettings.AppearanceSettings.DefaultFontFaceName
subdict["ShowCrosshairs"] = Rhino.ApplicationSettings.AppearanceSettings.ShowCrosshairs
subdict["ShowFullPathInTitleBar"] = Rhino.ApplicationSettings.AppearanceSettings.ShowFullPathInTitleBar

j = json.dumps(data)
req = urllib2.Request(couchdb_url, j, {"content-type":"application/json"})
stream = urllib2.urlopen(req)
response = stream.read()
stream.close()
return response


def getinput():
gs = Rhino.Input.Custom.GetString()
gs.SetCommandPrompt("Name for settings")
direction = Rhino.Input.Custom.OptionToggle(True, "SaveSettingsToCloud", "GetSettingsFromCloud")
gs.AddOptionToggle("direction", direction)
while( True ):
if gs.Get()==Rhino.Input.GetResult.Option:
continue
if gs.Get()==Rhino.Input.GetResult.Option: continue
break
if gs.CommandResult()!=Rhino.Commands.Result.Success:
return
Expand Down

0 comments on commit 8887fb8

Please sign in to comment.