summaryrefslogtreecommitdiff
path: root/Pb_Api
diff options
context:
space:
mode:
Diffstat (limited to 'Pb_Api')
-rw-r--r--Pb_Api/ImBreak/Params.py58
-rw-r--r--Pb_Api/ImBreak/__init__.py13
-rw-r--r--Pb_Api/ImGradient/Params.py45
-rw-r--r--Pb_Api/ImGradient/__init__.py35
-rw-r--r--Pb_Api/ImGradient/options.py83
-rw-r--r--Pb_Api/ImGrid/Params.py132
-rw-r--r--Pb_Api/ImGrid/__init__.py10
-rwxr-xr-xPb_Api/ImGrid/options.py64
-rw-r--r--Pb_Api/ImPattern/Params.py2
-rwxr-xr-xPb_Api/ImPattern/__init__.py10
-rw-r--r--Pb_Api/Param/Color.py19
-rw-r--r--Pb_Api/Param/MultiSelect.py19
-rw-r--r--Pb_Api/Param/NumberRange.py14
-rw-r--r--Pb_Api/Param/Options.py12
-rw-r--r--Pb_Api/Params.py5
-rw-r--r--Pb_Api/__init__.py2
16 files changed, 402 insertions, 121 deletions
diff --git a/Pb_Api/ImBreak/Params.py b/Pb_Api/ImBreak/Params.py
new file mode 100644
index 0000000..7d15476
--- /dev/null
+++ b/Pb_Api/ImBreak/Params.py
@@ -0,0 +1,58 @@
+import re, random
+from Pb_Api.Params import Pb_Api_Params
+from Pb_Api.Param import Pb_Api_Param
+from Pb_Api.Param.Option import Pb_Api_Param_Option
+from Pb_Api.Param.Options import Pb_Api_Param_Options
+from Pb_Api.Param.Username import Pb_Api_Param_Username
+from Pb_Api.Param.Image_Url import Pb_Api_Param_Image_Url
+from Pb_Api.Param.MultiSelect import Pb_Api_Param_MultiSelect
+from Pb_Api.Param.NumberRange import Pb_Api_Param_NumberRange
+from Pb_Api.Param.Color import Pb_Api_Param_Color
+from config import PATTERN_BASE_URL
+
+
+breaktype_options = Pb_Api_Param_Options.from_dict(
+ {"value":"CLASSIC", "weight": 1},
+ {"value":"REDUX", "weight": 1},
+ {"value":"BLURRY_BREAK", "weight": 1},
+ {"value":"BLURRY_BREAK_2", "weight": 1},
+ {"value":"SWIPE", "weight": 1},
+ {"value":"RGB_WASH", "weight": 1},
+ {"value":"RGB_WASH_2", "weight": 1},
+ {"value":"NOISY_BREAK", "weight": 1},
+ {"value":"BROKEN_VIGNETTE", "weight": 1},
+ {"value":"FAX_MACHINE", "weight": 1},
+ {"value":"STRIPES", "weight": 1},
+ {"value":"PHOTOCOPY", "weight": 1},
+)
+breakmode_options = Pb_Api_Param_Options.from_dict(
+ {"value":"extreme", "weight": 1},
+ {"value":"subtle", "weight": 1},
+)
+finalformat_options = Pb_Api_Param_Options.from_dict(
+ {"value":"png", "weight": 5},
+ {"value":"jpg", "weight": 2},
+ {"value":"gif", "weight": 2},
+)
+breakangle_options = Pb_Api_Param_Options.from_dict(
+ {"value":0, "weight": 9},
+ {"value":90, "weight": 2},
+ {"value":-180, "weight": 2},
+ {"value":180, "weight": 2},
+)
+expanded_options = Pb_Api_Param_Options.from_dict(
+ {"value": "" , "weight": 11 },
+ {"value": 1, "weight": 2}
+)
+
+class ImBreak_Params(Pb_Api_Params):
+ def __init__(self):
+ self.params = [
+ Pb_Api_Param_Username(name="username", required=0),
+ Pb_Api_Param_Image_Url(name="url", required=1),
+ Pb_Api_Param_MultiSelect(name="finalformat", required=0, options=finalformat_options),
+ Pb_Api_Param_MultiSelect(name="breaktype", required=1, options=breaktype_options),
+ Pb_Api_Param_NumberRange(name="breakangle", required=0, options=breakangle_options, min=-180, max=180),
+ Pb_Api_Param_MultiSelect(name="breakmode", required=1, options=breakmode_options),
+ Pb_Api_Param_MultiSelect(name="expanded", required=0, options=expanded_options),
+ ]
diff --git a/Pb_Api/ImBreak/__init__.py b/Pb_Api/ImBreak/__init__.py
new file mode 100644
index 0000000..7836f2e
--- /dev/null
+++ b/Pb_Api/ImBreak/__init__.py
@@ -0,0 +1,13 @@
+#!/usr/bin/python2.7
+from Pb_Api import Pb_Api
+from Pb_Api.ImBreak.Params import ImBreak_Params
+from config import IMBREAK_URL
+
+class Pb_Api_ImBreak(Pb_Api):
+ def __init__(self):
+ self.url = IMBREAK_URL
+ def params_init(self):
+ new_params = ImBreak_Params()
+ #new_params = self.get_from_server()
+ new_params.api = self
+ return new_params
diff --git a/Pb_Api/ImGradient/Params.py b/Pb_Api/ImGradient/Params.py
index e69de29..10d98d5 100644
--- a/Pb_Api/ImGradient/Params.py
+++ b/Pb_Api/ImGradient/Params.py
@@ -0,0 +1,45 @@
+import re, random
+from Pb_Api.Params import Pb_Api_Params
+from Pb_Api.Param import Pb_Api_Param
+from Pb_Api.Param.Option import Pb_Api_Param_Option
+from Pb_Api.Param.Options import Pb_Api_Param_Options
+from Pb_Api.Param.Username import Pb_Api_Param_Username
+from Pb_Api.Param.Image_Url import Pb_Api_Param_Image_Url
+from Pb_Api.Param.MultiSelect import Pb_Api_Param_MultiSelect
+from Pb_Api.Param.NumberRange import Pb_Api_Param_NumberRange
+from Pb_Api.Param.Color import Pb_Api_Param_Color
+
+from Pb_Api.ImGradient.options import *
+
+
+
+class ImGradient_Params(Pb_Api_Params):
+ def __init__(self):
+ self.params = [
+ Pb_Api_Param_Username(name="username", required=0),
+ Pb_Api_Param_NumberRange(name="width", required=1, options=width_options, min=100, max=800),
+ Pb_Api_Param_NumberRange(name="height", required=1, options=height_options, min=100, max=800),
+ Pb_Api_Param_Color(name="color1", required=1, options=color1_options),
+ Pb_Api_Param_Color(name="color2", required=1, options=color2_options),
+ Pb_Api_Param_MultiSelect(name="filetype", required=0, options=filetype_options),
+ Pb_Api_Param_MultiSelect(name="gradienttype", required=1, options=gradienttype_options),
+ Pb_Api_Param_MultiSelect(name="halftone", required=0, options=halftone_options),
+ Pb_Api_Param_MultiSelect(name="bevel", required=0, options=bevel_options),
+
+ Pb_Api_Param_NumberRange(name="stripenumber", required=0, options=stripenumber_options, min=0, max=400),
+ Pb_Api_Param_NumberRange(name="stripeintensity", required=0, options=stripeintensity_options, min=0, max=5000),
+
+ Pb_Api_Param_NumberRange(name="blurriness", required=0, options=blurriness_options, min=0, max=200),
+# Pb_Api_Param_NumberRange(name="contrast", required=0, options=contrast_options, min=0, max=200),
+ Pb_Api_Param_NumberRange(name="brightness", required=0, options=brightness_options, min=0, max=200),
+ Pb_Api_Param_NumberRange(name="saturation", required=0, options=saturation_options, min=0, max=200),
+ Pb_Api_Param_NumberRange(name="hue", required=0, options=hue_options, min=0, max=200),
+
+ Pb_Api_Param_NumberRange(name="percentbeveled", required=0, options=percentbeveled_options, min=0, max=100),
+ Pb_Api_Param_NumberRange(name="rotate", required=0, options=rotate_options, min=0, max=360),
+ Pb_Api_Param_NumberRange(name="tilt", required=0, options=tilt_options, min=0, max=360),
+
+
+ Pb_Api_Param_MultiSelect(name="flop", required=0, options=flop_options),
+ Pb_Api_Param_MultiSelect(name="flip", required=0, options=flip_options),
+ ]
diff --git a/Pb_Api/ImGradient/__init__.py b/Pb_Api/ImGradient/__init__.py
index 18c27c0..1f90bbe 100644
--- a/Pb_Api/ImGradient/__init__.py
+++ b/Pb_Api/ImGradient/__init__.py
@@ -1,30 +1,13 @@
#!/usr/bin/python2.7
-import urllib
-import urllib2
-import simplejson as json
-import random
-import sys
-from lib.utils import post_request, Pb_Api
+from Pb_Api import Pb_Api
+from Pb_Api.ImGradient.Params import ImGradient_Params
+from config import IMGRADIENT_URL
-
-IMGRADIENT_URL = "http://asdf.us/im/api/imgradient"
-#from Api.ImGradient.Api import *
-
-class ImGradientApi(Pb_Api):
+class Pb_Api_ImGradient(Pb_Api):
def __init__(self):
self.url = IMGRADIENT_URL
- self._required_keys = [
- "width", "height",
- "color1", "color2",
- "stripes",
- "stripenumber", "stripeintensity",
- "blurriness",
- "contrast",
- "brightness", "saturation", "hue",
- "halftone",
- "bevel", "percentbeveled",
- "rotate", "flip", "flop", "tilt",
- "filetype",
- "gradienttype",
- "username",
- ]
+ def params_init(self):
+ new_params = ImGradient_Params()
+ #new_params = self.get_from_server()
+ new_params.api = self
+ return new_params
diff --git a/Pb_Api/ImGradient/options.py b/Pb_Api/ImGradient/options.py
new file mode 100644
index 0000000..a6ad88c
--- /dev/null
+++ b/Pb_Api/ImGradient/options.py
@@ -0,0 +1,83 @@
+from Pb_Api.Param.Options import Pb_Api_Param_Options
+width_options = Pb_Api_Param_Options.from_dict(
+ { "value" : 400, "weight" : 1 },
+ { "value" : 600, "weight" : 1 },
+)
+height_options = Pb_Api_Param_Options.from_dict(
+ { "value" : 400, "weight" : 1 },
+ { "value" : 600, "weight" : 1 },
+)
+color1_options = Pb_Api_Param_Options.from_dict(
+ { "value" : "black", "weight" : 1 },
+ { "value" : "white", "weight" : 2 },
+)
+color2_options = Pb_Api_Param_Options.from_dict(
+ { "value" : "black", "weight" : 2 },
+ { "value" : "white", "weight" : 1 },
+)
+stripes_options = Pb_Api_Param_Options.from_dict(
+ {"value":"true", "weight": 1},
+ {"value":"false", "weight": 1},
+)
+stripenumber_options = Pb_Api_Param_Options.from_dict(
+ {"value":1, "weight": 50},
+ {"value":2, "weight": 50},
+)
+# contrast_options = \
+stripeintensity_options = \
+ brightness_options = \
+ saturation_options = \
+ hue_options = \
+ Pb_Api_Param_Options.from_dict(
+ {"value": "", "weight": 300},
+)
+halftone_options = Pb_Api_Param_Options.from_dict(
+ { "value" : "checkeredfade", "weight": 1 },
+ { "value" : "etchedtransition", "weight": 1 },
+ { "value" : "bendaydots", "weight": 1 },
+ { "value" : "smallerdots1", "weight": 1 },
+ { "value" : "smallerdots2", "weight": 1 },
+ { "value" : "flatstripes", "weight": 1 },
+)
+bevel_options = Pb_Api_Param_Options.from_dict(
+ { "value" : "", "weight" : 4 },
+ { "value" : "flatout", "weight" : 1 },
+ { "value" : "flatinner", "weight" : 1 },
+ { "value" : "evenlyframed", "weight" : 1 },
+ { "value" : "biginner", "weight" : 1 },
+ { "value" : "bigouter", "weight" : 1 },
+ { "value" : "dramaticflatout", "weight" : 1 },
+ { "value" : "dramaticflatinner", "weight" : 1 },
+)
+
+blurriness_options = \
+ percentbeveled_options = Pb_Api_Param_Options.from_dict(
+ { "value" : "", "weight": 4 },
+)
+rotate_options = \
+ tilt_options = Pb_Api_Param_Options.from_dict(
+ {"value":"", "weight": 9},
+ {"value":90, "weight": 2},
+ {"value":180, "weight": 2},
+ {"value":270, "weight": 2},
+)
+flop_options = flip_options = Pb_Api_Param_Options.from_dict(
+ {"value":"", "weight": 1},
+ {"value":"true", "weight": 1},
+)
+
+filetype_options = Pb_Api_Param_Options.from_dict(
+ {"value":"png", "weight": 5},
+ {"value":"jpg", "weight": 2},
+ {"value":"gif", "weight": 2},
+)
+gradienttype_options = Pb_Api_Param_Options.from_dict(
+ { "value" : "canvas", "weight" : 1 },
+ { "value" : "gradient", "weight" : 3 },
+ { "value" : "radial", "weight" : 1 },
+ { "value" : "colorspace", "weight" : 1 },
+ { "value" : "plasmawash", "weight" : 1 },
+ { "value" : "gradientwash", "weight" : 1 },
+ { "value" : "mirrored", "weight" : 1 },
+ { "value" : "noise", "weight" : 1 },
+)
diff --git a/Pb_Api/ImGrid/Params.py b/Pb_Api/ImGrid/Params.py
index ef07251..c469b6a 100644
--- a/Pb_Api/ImGrid/Params.py
+++ b/Pb_Api/ImGrid/Params.py
@@ -1,4 +1,4 @@
-import re
+import re, random
from Pb_Api.Params import Pb_Api_Params
from Pb_Api.Param import Pb_Api_Param
from Pb_Api.Param.Option import Pb_Api_Param_Option
@@ -9,23 +9,16 @@ from Pb_Api.Param.MultiSelect import Pb_Api_Param_MultiSelect
from Pb_Api.Param.NumberRange import Pb_Api_Param_NumberRange
from Pb_Api.Param.Color import Pb_Api_Param_Color
-#ok so is there anything else a bit weird here?
-class Pattern_Url_Option(Pb_Api_Param_Option):
- def __init__(self, **kwargs):
- super(Pb_Api_Param_Option, self).__init__(**kwargs)
- @classmethod
- def from_name(cls, **kwargs):
- formatted = "{}/{}.png".format(PATTERN_BASE_URL, kwargs["value"])
- return cls(weight=kwargs["weight"], value=formatted )
-#I made options optional
+from Pb_Api.ImGrid.options import *
class Param_Zoom(Pb_Api_Param_NumberRange):
def __init__(self, **kwargs):
- super(Pb_Api_Param_Option, self).__init__(**kwargs)
+ super(Param_Zoom, self).__init__(**kwargs)
self.exclusion_range = kwargs['exclusion_range']
+ def test_value(self):
+ return not ((self.value > self.exclusion_range[0]) and (self.value < self.exclusion_range[1]))
def randomize(self):
- weights_total = sum(map(lambda x: x["weight"], self.options()) +
- (self.range_max - self.range_min) - (self.exclusion_range[1] - self.exclusion_range[0])
+ weights_total = sum(map(lambda x: x["weight"], self.options())) + 10
choice = random.randint(0, weights_total)
position = 0
for elem in self.options():
@@ -35,19 +28,36 @@ class Param_Zoom(Pb_Api_Param_NumberRange):
return
max_tries = 10000
while(max_tries):
- self.value = random.randint(self.range_max, self.range_min),
- if not (self.value > self.exclusion_range[0] or self.value < self.exclusion_range[1]):
- return
+ self.value = round(random.uniform(self.range_max, self.range_min), 2)
+ if self.test_value: return
max_tries -= 1;
raise ValueError
-#does this make any sense? yeah but can be improved a lot, so if you see you have a lot of ways to check if value is valid or not, and
-#those checks appear here and there, so it's time to just move that code into separate method like is_valid, so you could quickly check
-#if newly generate value is valid. moreover, this loop with max_tries already used in several classes (and i suspect you plan to use that later too). instead, you can defined randomize() method to have this max_tries loop, and call something like randomize_do() in child class, so all classes will have ability to regenrate value if it's not valid. I get it, and I can do that.
-#thing is that so far this is only needed once, for one param. and the randomize thing below was applying to the params class,
-#sort of a different check, to see if all the randomized params work with one another, so I think maybe I should wait to move it into
-#the parent? alright, ideally max_tries loop will be in Params class only, and Params class will have is_valid too, so basically if one param is not valid (as seen from Params) you will start over again. ahh, if one param isn't valid, it can just call randomize again on that param (individually) not on all the others, right? yep yeah that's much better ok I'll change that tomorrow.
+
+ @property
+ def value(self):
+ return super(Pb_Api_Param_MultiSelect, self).get_value()
+ @value.setter
+ def value(self, value):
+ self._value = value
+ if not self._value is None:
+ self.is_ready = 1
+ self.set_by_user = 1
+
+class Param_Opacity(Pb_Api_Param_NumberRange):
+ def __init__(self, **kwargs):
+ super(Param_Opacity, self).__init__(**kwargs)
+ def randomize(self):
+ weights_total = sum(map(lambda x: x["weight"], self.options()) + self.range_max - self.range_min)
+ choice = random.randint(0, weights_total)
+ position = 0
+ for elem in self.options():
+ position += elem["weight"]
+ if position >= choice:
+ self.value = elem["value"]
+ return
+ self.value = round(random.uniform(self.range_min,range_max), 2),
-class ImPattern_Params(Pb_Api_Params):
+class ImGrid_Params(Pb_Api_Params):
def __init__(self):
self.params = [
Pb_Api_Param_Username(name="username", required=0),
@@ -56,48 +66,46 @@ class ImPattern_Params(Pb_Api_Params):
Pb_Api_Param_Image_Url(name="planebgimage", required=0),
Pb_Api_Param_MultiSelect(name="format", required=0, options=format_options),
Pb_Api_Param_MultiSelect(name="transition", required=1, options=transition_options),
- Pb_Api_Param_Color(name="skycolor", required=0, preferred_colors=skycolor_colors),
- Pb_Api_Param_Color(name="planebgcolor", required=0, preferred_colors=planebgcolor_colors),
- Pb_Api_Param_Color(name="bgcolor", required=0, preferred_colors=bgcolor_colors),
- Pb_Api_Param_Color(name="linecolor", required=0, preferred_colors=linecolor_colors),
- Pb_Api_Param_NumberRange(name="swing", required=0, options=swing_options),
- Pb_Api_Param_NumberRange(name="tilt", required=0, options=tilt_options),
- Pb_Api_Param_NumberRange(name="roll", required=0, options=roll_options),
- Pb_Api_Param_NumberRange(name="width", required=0, options=width_options),
- Pb_Api_Param_NumberRange(name="height", required=0, options=height_options),
- Pb_Api_Param_NumberRange(name="linethickness", required=0, options=height_options),
- Pb_Api_Param_NumberRange(name="opacity", required=0, options=height_options),
- Pb_Api_Param_NumberRange(name="spacing", required=0, options=height_options),
- Pb_Api_Param_MultiSelect(name="vlines", required=0, options=vlines_options),# not defined yet? oh the thing is the options have a
-#predefined weight...that's what you're supposed to set here, anyway hm, that complicated thing if different bool values have different weigths, so it's better to keep them as is then, o rs change to multiselect
+ Pb_Api_Param_Color(name="skycolor", required=0, options=skycolor_colors),
+ Pb_Api_Param_Color(name="planebgcolor", required=0, options=planebgcolor_colors),
+ Pb_Api_Param_Color(name="bgcolor", required=0, options=bgcolor_colors),
+ Pb_Api_Param_Color(name="linecolor", required=0, options=linecolor_colors),
+ Pb_Api_Param_NumberRange(name="swing", required=0, options=swing_options, min=-170, max=170),
+ Pb_Api_Param_NumberRange(name="tilt", required=0, options=tilt_options, min=-170, max=170),
+ Pb_Api_Param_NumberRange(name="roll", required=0, options=roll_options, min=-170, max=170),
+ Pb_Api_Param_NumberRange(name="width", required=0, options=width_options, min=100, max=800),
+ Pb_Api_Param_NumberRange(name="height", required=0, options=height_options, min=100, max=800),
+ Pb_Api_Param_NumberRange(name="linethickness", required=0, options=linethickness_options, min=1, max=30),
+ Pb_Api_Param_NumberRange(name="opacity", required=0, options=opacity_options, min=0, max=1),
+ Pb_Api_Param_NumberRange(name="spacing", required=0, options=spacing_options, min=2, max=100),
+ Pb_Api_Param_MultiSelect(name="vlines", required=0, options=vlines_options),
Pb_Api_Param_MultiSelect(name="hlines", required=0, options=hlines_options),
Pb_Api_Param_MultiSelect(name="trim", required=0, options=trim_options),
Pb_Api_Param_MultiSelect(name="shadow", required=0, options=shadow_options),
- Param_Zoom(name="zoom", required=0, options=zoom_options),
+ Param_Zoom(name="zoom", required=0, options=zoom_options, min=-12, max=12, exclusion_range=[-1.1, 1.1]),
]
+ def test_values(self):
+ p = self.params
+ return not any([
+ (self.param('spacing').value > self.param('width').value),
+ (self.param('spacing').value > self.param('height').value),
+ (self.param('linethickness').value > self.param('width').value),
+ (self.param('linethickness').value > self.param('height').value),
+ ])
def randomize(self):
- max_tries = 10000
- while(max_tries):
- super(ImPattern_Params, self).randomize()
- p = self.params()
- if not any([
- p['spacing'].value > p['width'].value,
- p['spacing'].value > p['height'].value,
- p['linethickness'] > p['width'].value,
- p['linethickness'] > p['height'].value ]):
- return
- max_tries -= 1
- raise ValueError
-##ok I think I get it, last thing is this Param_Zoom
-
-skycolor_colors = Pb_Api_Param_Options(
- Pb_Api_Param_Option( value='black', weight=50 ),
- Pb_Api_Param_Option( value='silver', weight=20 ),
-)
-
-pattern_url_options = Pb_Api_Param_Options([
- Pattern_Url_Option.from_name(weight=0, value=i) for i in range(1,100) ] + [
- Pattern_Url_Option.from_name(weight=0, value="a{}".format(i)) for i in range(0, 42)
-])
+ p = self.params
+ for el in p:
+ if el in ['spacing', 'linethickness']:
+ continue
+ if el.set_by_user:
+ continue
+ el.randomize()
+ for name in ['spacing', 'linethickness']:
+ max_tries = 10000
+ while(max_tries):
+ self.param(name).randomize()
+ if self.test_values():
+ return
+ max_tries -= 1
+ raise ValueError
-pattern_url_options.search("a10").weight = 20;
diff --git a/Pb_Api/ImGrid/__init__.py b/Pb_Api/ImGrid/__init__.py
index 0c238b9..553c04c 100644
--- a/Pb_Api/ImGrid/__init__.py
+++ b/Pb_Api/ImGrid/__init__.py
@@ -1,13 +1,13 @@
#!/usr/bin/python2.7
from Pb_Api import Pb_Api
from Pb_Api.ImGrid.Params import ImGrid_Params
-from config import IMPATTERN_URL
+from config import IMGRID_URL
-class Pb_Api_ImPattern(Pb_Api):
+class Pb_Api_ImGrid(Pb_Api):
def __init__(self):
- self.url = IMPATTERN_URL
- def request_new(self):
- new_params = ImPattern_Params()
+ self.url = IMGRID_URL
+ def params_init(self):
+ new_params = ImGrid_Params()
#new_params = self.get_from_server()
new_params.api = self
return new_params
diff --git a/Pb_Api/ImGrid/options.py b/Pb_Api/ImGrid/options.py
new file mode 100755
index 0000000..387a489
--- /dev/null
+++ b/Pb_Api/ImGrid/options.py
@@ -0,0 +1,64 @@
+from Pb_Api.Param.Options import Pb_Api_Param_Options
+format_options = Pb_Api_Param_Options.from_dict(
+ { 'weight': 20, 'value': 'png' },
+ { 'weight': 0, 'value': 'gif' },
+ { 'weight': 0, 'value': 'jpg' },
+)
+transition_options = Pb_Api_Param_Options.from_dict(
+ { "value" : "background", "weight": 1 },
+ { "value" : "dither", "weight": 1 },
+ { "value" : "random", "weight": 1 },
+ { "value" : "tile", "weight": 1 },
+ { "value" : "edge", "weight": 1 },
+)
+skycolor_colors = \
+ bgcolor_colors = planebgcolor_colors = Pb_Api_Param_Options.from_dict(
+ { "value" : "white", "weight" : 1 },
+ { "value" : "silver", "weight" : 1 },
+ { "value" : None, "weight" : 10 },
+)
+
+linecolor_colors = Pb_Api_Param_Options.from_dict(
+ { "value" : "black", "weight" : 1 },
+ { "value" : "white", "weight" : 1 },
+ { "value" : "silver", "weight" : 1 },
+)
+swing_options = tilt_options = roll_options = Pb_Api_Param_Options.from_dict(
+ {"value": "", "weight": 2},
+ {"value": 30, "weight": 1},
+ {"value": -30, "weight": 1},
+)
+width_options = height_options = Pb_Api_Param_Options.from_dict(
+ { "value" : 400, "weight" : 1 },
+ { "value" : 600, "weight" : 1 },
+)
+linethickness_options = Pb_Api_Param_Options.from_dict(
+ {"value":1, "weight": 2},
+ {"value":2, "weight": 1},
+)
+opacity_options = Pb_Api_Param_Options.from_dict(
+ {"value":1, "weight": 2},
+ {"value":0.5, "weight": 1},
+)
+spacing_options = Pb_Api_Param_Options.from_dict(
+ {"value":10, "weight": 1},
+ {"value":15, "weight": 1},
+)
+vlines_options = hlines_options = Pb_Api_Param_Options.from_dict(
+ {"value":"", "weight": 2},
+ {"value":"true", "weight": 1},
+)
+shadow_options = Pb_Api_Param_Options.from_dict(
+ {"value":"", "weight": 1},
+ {"value":"true", "weight": 1},
+)
+zoom_options = Pb_Api_Param_Options.from_dict(
+ {"value": 0, "weight": 3},
+ {"value": 1.2, "weight": 1},
+ {"value": -1.2, "weight": 1},
+)
+trim_options = Pb_Api_Param_Options.from_dict(
+ {"value":"", "weight": 1},
+ {"value":"true", "weight": 1},
+)
+
diff --git a/Pb_Api/ImPattern/Params.py b/Pb_Api/ImPattern/Params.py
index 1e1214a..5c12083 100644
--- a/Pb_Api/ImPattern/Params.py
+++ b/Pb_Api/ImPattern/Params.py
@@ -26,7 +26,7 @@ class ImPattern_Params(Pb_Api_Params):
Pb_Api_Param_MultiSelect(name="pattern_url", required=1, options=pattern_url_options)
]
-pattern_url_options = Pb_Api_Param_Options([
+pattern_url_options = Pb_Api_Param_Options(*[
Pattern_Url_Option.from_name(weight=0, value=i) for i in range(1,100) ] + [
Pattern_Url_Option.from_name(weight=0, value="a{}".format(i)) for i in range(0, 42)
])
diff --git a/Pb_Api/ImPattern/__init__.py b/Pb_Api/ImPattern/__init__.py
index ed2cc69..b81af58 100755
--- a/Pb_Api/ImPattern/__init__.py
+++ b/Pb_Api/ImPattern/__init__.py
@@ -1,13 +1,13 @@
#!/usr/bin/python2.7
from Pb_Api import Pb_Api
-from Pb_Api.ImPattern.Params import ImGrid_params
-from config import IMGRID_URL
+from Pb_Api.ImPattern.Params import ImPattern_Params
+from config import IMPATTERN_URL
class Pb_Api_ImPattern(Pb_Api):
def __init__(self):
- self.url = IMGRID_URL
- def request_new(self):
- new_params = ImGrid_Params()
+ self.url = IMPATTERN_URL
+ def params_init(self):
+ new_params = ImPattern_Params()
#new_params = self.get_from_server()
new_params.api = self
return new_params
diff --git a/Pb_Api/Param/Color.py b/Pb_Api/Param/Color.py
index 1c14c8d..678a087 100644
--- a/Pb_Api/Param/Color.py
+++ b/Pb_Api/Param/Color.py
@@ -7,10 +7,19 @@ class Pb_Api_Param_Color(Pb_Api_Param_MultiSelect):
@classmethod
def from_rgb(cls, r,g,b):
return cls(value="rgb({},{},{})".format(r,g,b))
-
+
+ @property
+ def value(self):
+ return super(Pb_Api_Param_MultiSelect, self).get_value()
+ @value.setter
+ def value(self, value):
+ self._value = value
+ if not self._value is None:
+ self.is_ready = 1
+ self.set_by_user = 1
def randomize(self):
- weights_total = sum(map(lambda x: x["weight"], self.options()) + (255 * 255 * 255)
+ weights_total = sum(map(lambda x: x["weight"], self.options())) + (255 * 255 * 255)
choice = random.randint(0, weights_total)
position = 0
for elem in self.options():
@@ -18,8 +27,4 @@ class Pb_Api_Param_Color(Pb_Api_Param_MultiSelect):
if position >= choice:
self.value = elem["value"]
return
- self.value = "rgb({},{},{})".format(
- random.randint(0,255),
- random.randint(0,255),
- random.randint(0,255),
- )
+ self.value = "rgb({},{},{})".format( random.randint(0,255), random.randint(0,255), random.randint(0,255))
diff --git a/Pb_Api/Param/MultiSelect.py b/Pb_Api/Param/MultiSelect.py
index b84d75b..3761302 100644
--- a/Pb_Api/Param/MultiSelect.py
+++ b/Pb_Api/Param/MultiSelect.py
@@ -2,9 +2,10 @@ import random
from Pb_Api.Param import Pb_Api_Param
class Pb_Api_Param_MultiSelect(Pb_Api_Param):
- def __init__(self, *args, **kwargs):
- self._options = kwargs['options'] if options in kwargs else []
- super(Pb_Api_Param_MultiSelect, self).__init__(*args, **kwargs)
+ def __init__(self, **kwargs):
+ self._options = []
+ if 'options' in kwargs: self._options = kwargs['options'] or []
+ super(Pb_Api_Param_MultiSelect, self).__init__(**kwargs)
if len(self._options):
self._validate_options()
self.default(self._choose_heaviest())
@@ -19,14 +20,14 @@ class Pb_Api_Param_MultiSelect(Pb_Api_Param):
except Exception as e:
raise ValueError
- @property
- def value(self):
+ def get_value(self):
return super(Pb_Api_Param_MultiSelect, self).get_value()
- @value.setter
- def value(self, value):
- if not any([ value == i['value'] for i in self.options() ]) and value != None:
+ def set_value(self, value):
+ if not any([ value == i['value'] for i in self._options ]) and value != None:
raise ValueError
super(Pb_Api_Param_MultiSelect, self).set_value(value)
+ value = property(get_value, set_value)
+
def randomize(self):
weights_total = sum(map(lambda x: x["weight"], self.options()))
@@ -48,7 +49,7 @@ class Pb_Api_Param_MultiSelect(Pb_Api_Param):
heaviest_weight = elem["weight"]
heaviest_idx = idx;
idx += 1
- self.value = self.options()[heaviest_idx]["value"]
+ return self.options()[heaviest_idx]["value"]
else:
self.randomize()
def heaviest(self):
diff --git a/Pb_Api/Param/NumberRange.py b/Pb_Api/Param/NumberRange.py
index fa11a29..fe1ece6 100644
--- a/Pb_Api/Param/NumberRange.py
+++ b/Pb_Api/Param/NumberRange.py
@@ -1,3 +1,4 @@
+import sys
from Pb_Api.Param.MultiSelect import Pb_Api_Param_MultiSelect
import random
class Pb_Api_Param_NumberRange(Pb_Api_Param_MultiSelect):
@@ -6,7 +7,7 @@ class Pb_Api_Param_NumberRange(Pb_Api_Param_MultiSelect):
self.range_min = kwargs['min']
self.range_max = kwargs['max']
def randomize(self):
- weights_total = sum(map(lambda x: x["weight"], self.options()) + self.range_max - self.range_min
+ weights_total = sum(map(lambda x: x["weight"], self.options())) + self.range_max - self.range_min
choice = random.randint(0, weights_total)
position = 0
for elem in self.options():
@@ -14,4 +15,13 @@ class Pb_Api_Param_NumberRange(Pb_Api_Param_MultiSelect):
if position >= choice:
self.value = elem["value"]
return
- self.value = random.randint(ANGLE_MIN,ANGLE_MAX),
+ self.value = random.randint(self.range_min,self.range_max)
+ @property
+ def value(self):
+ return super(Pb_Api_Param_MultiSelect, self).get_value()
+ @value.setter
+ def value(self, value):
+ self._value = value
+ if not self._value is None:
+ self.is_ready = 1
+ self.set_by_user = 1
diff --git a/Pb_Api/Param/Options.py b/Pb_Api/Param/Options.py
index d19f42a..ebc6fc9 100644
--- a/Pb_Api/Param/Options.py
+++ b/Pb_Api/Param/Options.py
@@ -1,8 +1,12 @@
+from Pb_Api.Param.Option import Pb_Api_Param_Option
+import sys
class Pb_Api_Param_Options:
- def __init__(self, arr):
- self._values = arr
+ def __init__(self, *args):
+ self._values = args
def __iter__(self):
return iter(self._values)
+ def __len__(self):
+ return len(self._values)
def __str__(self):
return str(self._values)
def __getitem__(self, i):
@@ -11,3 +15,7 @@ class Pb_Api_Param_Options:
for i in self:
if str(s) in i.value:
return i
+ @classmethod
+ def from_dict(cls, *args):
+ options = map(lambda x: Pb_Api_Param_Option(**x), args);
+ return cls(*options);
diff --git a/Pb_Api/Params.py b/Pb_Api/Params.py
index 29bb423..4fcc113 100644
--- a/Pb_Api/Params.py
+++ b/Pb_Api/Params.py
@@ -1,3 +1,4 @@
+import sys
import pprint
class Pb_Api_Params(object):
def __init__(self):
@@ -24,13 +25,13 @@ class Pb_Api_Params(object):
def api(self, cls):
self._api = cls
- #does this really have to be here in Pb_Api_Params? seems confusing though yeah it has to be here because ImPattern inherits from it? impatter params
def execute(self):
return self.api.call(self)
def is_ready(self):
for p in self.params:
- if not p.is_ready():
+ if not p.is_ready and not p.default:
+ sys.stderr.write("param not ready: {}".format(p))
return 0
return 1
def as_hash(self):
diff --git a/Pb_Api/__init__.py b/Pb_Api/__init__.py
index 25f78dd..6961496 100644
--- a/Pb_Api/__init__.py
+++ b/Pb_Api/__init__.py
@@ -32,4 +32,6 @@ class Pb_Api:
sys.stderr.write(str(e))
raise
def call(self, params):
+ if not(params.is_ready()):
+ raise Exception( "Api Params Not Ready")
return json.loads(self.post_request(self.url, params.as_hash()))