summaryrefslogtreecommitdiff
path: root/ricky/imgrid
diff options
context:
space:
mode:
Diffstat (limited to 'ricky/imgrid')
-rw-r--r--ricky/imgrid/__init__.py1
-rw-r--r--ricky/imgrid/imgrid.py12
-rwxr-xr-xricky/imgrid/options.py64
-rw-r--r--ricky/imgrid/params.py111
4 files changed, 188 insertions, 0 deletions
diff --git a/ricky/imgrid/__init__.py b/ricky/imgrid/__init__.py
new file mode 100644
index 0000000..1ff6788
--- /dev/null
+++ b/ricky/imgrid/__init__.py
@@ -0,0 +1 @@
+from imgrid import ImGrid
diff --git a/ricky/imgrid/imgrid.py b/ricky/imgrid/imgrid.py
new file mode 100644
index 0000000..6872537
--- /dev/null
+++ b/ricky/imgrid/imgrid.py
@@ -0,0 +1,12 @@
+from ricky.api import Api
+from ricky.imgrid.params import ImGridParams
+from ricky.config import IMGRID_URL
+
+class ImGrid(Api):
+ def __init__(self):
+ self.url = IMGRID_URL
+ def params_init(self):
+ new_params = ImGridParams()
+ #new_params = self.get_from_server()
+ new_params.api = self
+ return new_params
diff --git a/ricky/imgrid/options.py b/ricky/imgrid/options.py
new file mode 100755
index 0000000..8ada475
--- /dev/null
+++ b/ricky/imgrid/options.py
@@ -0,0 +1,64 @@
+from ricky.param.options import Options
+format_options = Options.from_dict(
+ { 'weight': 20, 'value': 'png' },
+ { 'weight': 0, 'value': 'gif' },
+ { 'weight': 0, 'value': 'jpg' },
+)
+transition_options = 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 = Options.from_dict(
+ { "value" : "white", "weight" : 1 },
+ { "value" : "silver", "weight" : 1 },
+ { "value" : None, "weight" : 10 },
+)
+
+linecolor_colors = Options.from_dict(
+ { "value" : "black", "weight" : 1 },
+ { "value" : "white", "weight" : 1 },
+ { "value" : "silver", "weight" : 1 },
+)
+swing_options = tilt_options = roll_options = Options.from_dict(
+ {"value": "", "weight": 2},
+ {"value": 30, "weight": 1},
+ {"value": -30, "weight": 1},
+)
+width_options = height_options = Options.from_dict(
+ { "value" : 400, "weight" : 1 },
+ { "value" : 600, "weight" : 1 },
+)
+linethickness_options = Options.from_dict(
+ {"value":1, "weight": 2},
+ {"value":2, "weight": 1},
+)
+opacity_options = Options.from_dict(
+ {"value":1, "weight": 2},
+ {"value":0.5, "weight": 1},
+)
+spacing_options = Options.from_dict(
+ {"value":10, "weight": 1},
+ {"value":15, "weight": 1},
+)
+vlines_options = hlines_options = Options.from_dict(
+ {"value":"", "weight": 2},
+ {"value":"true", "weight": 1},
+)
+shadow_options = Options.from_dict(
+ {"value":"", "weight": 1},
+ {"value":"true", "weight": 1},
+)
+zoom_options = Options.from_dict(
+ {"value": 0, "weight": 3},
+ {"value": 1.2, "weight": 1},
+ {"value": -1.2, "weight": 1},
+)
+trim_options = Options.from_dict(
+ {"value":"", "weight": 1},
+ {"value":"true", "weight": 1},
+)
+
diff --git a/ricky/imgrid/params.py b/ricky/imgrid/params.py
new file mode 100644
index 0000000..8b63759
--- /dev/null
+++ b/ricky/imgrid/params.py
@@ -0,0 +1,111 @@
+import re, random
+from ricky.params import Params
+from ricky.param import Param
+from ricky.param.option import Option
+from ricky.param.options import Options
+from ricky.param.username import Username
+from ricky.param.imageurl import ImageUrl
+from ricky.param.multiselect import MultiSelect
+from ricky.param.numberrange import NumberRange
+from ricky.param.color import Color
+
+from ricky.imgrid.options import *
+
+class Param_Zoom(NumberRange):
+ def __init__(self, **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())) + 10
+ choice = random.randint(0, weights_total)
+ position = 0
+ for elem in self.options():
+ position += elem["weight"]
+ if position >= choice:
+ self.value = elem["value"]
+ return
+ max_tries = 10000
+ while(max_tries):
+ self.value = round(random.uniform(self.range_max, self.range_min), 2)
+ if self.test_value: return
+ max_tries -= 1;
+ raise ValueError
+
+ @property
+ def value(self):
+ return super(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(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 ImGridParams(Params):
+ def __init__(self):
+ self.params = [
+ Username(name="username", required=0),
+ ImageUrl(name="bgimage", required=0),
+ ImageUrl(name="imageinstead", required=0),
+ ImageUrl(name="planebgimage", required=0),
+ MultiSelect(name="format", required=0, options=format_options),
+ MultiSelect(name="transition", required=1, options=transition_options),
+ Color(name="skycolor", required=0, options=skycolor_colors),
+ Color(name="planebgcolor", required=0, options=planebgcolor_colors),
+ Color(name="bgcolor", required=0, options=bgcolor_colors),
+ Color(name="linecolor", required=0, options=linecolor_colors),
+ NumberRange(name="swing", required=0, options=swing_options, min=-170, max=170),
+ NumberRange(name="tilt", required=0, options=tilt_options, min=-170, max=170),
+ NumberRange(name="roll", required=0, options=roll_options, min=-170, max=170),
+ NumberRange(name="width", required=0, options=width_options, min=100, max=800),
+ NumberRange(name="height", required=0, options=height_options, min=100, max=800),
+ NumberRange(name="linethickness", required=0, options=linethickness_options, min=1, max=30),
+ NumberRange(name="opacity", required=0, options=opacity_options, min=0, max=1),
+ NumberRange(name="spacing", required=0, options=spacing_options, min=2, max=100),
+ MultiSelect(name="vlines", required=0, options=vlines_options),
+ MultiSelect(name="hlines", required=0, options=hlines_options),
+ MultiSelect(name="trim", required=0, options=trim_options),
+ MultiSelect(name="shadow", required=0, options=shadow_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):
+ 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
+