Web2py Rating Widget (5 of them and in the same line) - database

I have a new problem.
I already done my widget but now i want 5 rating widget's for 5 categories in my database.
I have this column in my database (named places.categ):
places.categ
a
b
c
d
a
e
....
I have 21 markers in my Google Maps and each one of them as a category. (a,b,c,d or e).
How can i associate 5 rating widgets to those 21 markers by category? All i could do was this:
db.define_table('product',
Field('A', 'integer',requires=IS_IN_SET(range(1,6))),
Field('B', 'integer',requires=IS_IN_SET(range(1,6))),
Field('C', 'integer',requires=IS_IN_SET(range(1,6))),
Field('D', 'integer',requires=IS_IN_SET(range(1,6))),
Field('E', 'integer',requires=IS_IN_SET(range(1,6))))
I have this code in my models/db.py and this one in my controllers/default.py:
from plugin_rating_widget import RatingWidget
# Inject the widgets
db.product.A.widget = RatingWidget()
db.product.B.widget = RatingWidget()
db.product.C.widget = RatingWidget()
db.product.D.widget = RatingWidget()
db.product.E.widget = RatingWidget()
# form2 = SQLFORM.factory(
# Field('Rating','integer',widget=SQLFORM.widgets.RatingWidget))
# if form2.process().accepted:
# print form2.vars.search
form2 = SQLFORM(db.product)
if form2.accepts(request.vars, session):
session.flash = 'submitted %s' % form2.vars
redirect(URL('index'))
I have 5 rating widget but they are not associated to my database and they are vertical (in 5 lines) and not in 1 line, like i wanted too.
TIA.
P.S.: I have the plugin rating widget uploaded.

I solved in another way. I get colors to each category with this code:
var amarelo = new google.maps.MarkerImage(
"http://labs.google.com/ridefinder/images/mm_20_yellow.png",
new google.maps.Size(12, 20),
new google.maps.Point(0, 0),
new google.maps.Point(6, 20));
var vermelho = new google.maps.MarkerImage(
"http://labs.google.com/ridefinder/images/mm_20_red.png",
new google.maps.Size(12, 20),
new google.maps.Point(0, 0),
new google.maps.Point(6, 20));
var verde = new google.maps.MarkerImage(
"http://labs.google.com/ridefinder/images/mm_20_green.png",
new google.maps.Size(12, 20),
new google.maps.Point(0, 0),
new google.maps.Point(6, 20));
var azul = new google.maps.MarkerImage(
"http://labs.google.com/ridefinder/images/mm_20_blue.png",
new google.maps.Size(12, 20),
new google.maps.Point(0, 0),
new google.maps.Point(6, 20));
var branco = new google.maps.MarkerImage(
"http://labs.google.com/ridefinder/images/mm_20_white.png",
new google.maps.Size(12, 20),
new google.maps.Point(0, 0),
new google.maps.Point(6, 20));
var sombra = new google.maps.MarkerImage(
"http://labs.google.com/ridefinder/images/mm_20_shadow.png",
new google.maps.Size(22, 20),
new google.maps.Point(0, 0),
new google.maps.Point(6, 20));
I awarded each category in one of this colors (example):
if (placescoordjs[i][4]== 'a')
{
marker = new google.maps.Marker({
position: new google.maps.LatLng(placescoordjs[i][1],placescoordjs[i][2]),
icon: amarelo, shadow: sombra,
map: map,
title: placescoordjs[i][3]
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(placescoordjs[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
I have more 3 "else if" and the final else with the final color to my last category.
Thanks anyway. ;)

Related

Codename one - autocompletetextfield getitem selected

I have two problems:
1) First, I want to add a map in AutoCompleteTextField exactlly in DefaultListModel and after I want to add the the listmodel in my autocompletetextField
2) How can I get the text when I select an element in the AutoCompleteTextField?
Form hi = new Form("Auto Complete", new BoxLayout(BoxLayout.Y_AXIS));
AutoCompleteTextField ac = new AutoCompleteTextField("Short", "Shock", "Sholder", "Shrek0", "3asna", "niazra");
ac.setMinimumElementsShownInPopup(5);
//final DefaultListModel<Map<String,Object>> options = new DefaultListModel<>();
final DefaultListModel<String> options = new DefaultListModel<>();
AutoCompleteTextField an = new AutoCompleteTextField(options);
hi.add(an);
ac.addListListener(a -> {
List<Object> ls = new List<>();
System.out.println("i want to display the text selected");
});
hi.add(ac);
hi.show();
When you select an item in the suggestion box of an AutoCompleteTextField the text of this item is copied to the TextField part of the AutoCompleteTextfield, but this occur only after the ListEvent.
In order to have this behavior, prefer using a Selection Listener on the DefaultListModel:
Form hi = new Form("ACTF", new BoxLayout(BoxLayout.Y_AXIS));
DefaultListModel<String> defList = new DefaultListModel<>("Red", "Green", "Blue", "Orange");
AutoCompleteTextField tf1 = new AutoCompleteTextField(defList);
defList.addSelectionListener((oldid, newid)-> Log.p(defList.getItemAt(newid)));
hi.add(tf1);
hi.show();
I don't know why, it occur two times after showing the form, but it works perfectly fine after.
Edit: If you want to display the text on screen, you must use something like this :
Form hi = new Form("ACTF", new BoxLayout(BoxLayout.Y_AXIS));
Label text = new Label("Selected text");
DefaultListModel<String> defList = new DefaultListModel<>("Red", "Green", "Blue", "Orange");
AutoCompleteTextField tf1 = new AutoCompleteTextField(defList);
defList.addSelectionListener((oldid, newid)-> {
text.setText(defList.getItemAt(newid));
hi.revalidate();
});
hi.add(text);
hi.add(tf1);
hi.show();
EDIT 2: Example with a linked map:
Form hi = new Form("ACTF", new BoxLayout(BoxLayout.Y_AXIS));
Map testMap = new HashMap<String, String>();
testMap.put("Red", "Roses are red");
testMap.put("Green", "Grass is green");
testMap.put("Blue", "Sky is blue");
testMap.put("Orange", "Apricots are orange");
Label text = new Label("Selected text");
DefaultListModel<String> defList = new DefaultListModel<>(testMap.keySet());
AutoCompleteTextField tf1 = new AutoCompleteTextField(defList);
defList.addSelectionListener((oldid, newid)-> {
text.setText((String) testMap.get(defList.getItemAt(newid)));
hi.revalidate();
});
hi.add(text);
hi.add(tf1);
hi.show();

Timeout when selecting PostgisMultipolygon with Npgsql

In this example I use Npgsql in development version 3.1.0-alpha6.
I want to specify a PostgisGeometry object as a parameter in a query (NpgsqlDbType.Geometry)
and select the object again.
Queries with types like Point, MultiPoint, LineString, MultiLineString, Polygon and GeometryCollection will be returned correctly. A PostgisMultiPolygon object with only one polygon will be returned correctly too.
However, it does not work with a PostgisMultiPolygon with more than one polygon.
PostgisMultiPolygon geom1 = new PostgisMultiPolygon(new[]
{
new PostgisPolygon(new[]
{
new[]
{
new Coordinate2D(40, 40),
new Coordinate2D(20, 45),
new Coordinate2D(45, 30),
new Coordinate2D(40, 40)
}
})
}) {SRID = 4326};
PostgisMultiPolygon geom2 = new PostgisMultiPolygon(new[]
{
new PostgisPolygon(new[]
{
new[]
{
new Coordinate2D(40, 40),
new Coordinate2D(20, 45),
new Coordinate2D(45, 30),
new Coordinate2D(40, 40)
}
}),
new PostgisPolygon(new[]
{
new[]
{
new Coordinate2D(20, 35),
new Coordinate2D(10, 30),
new Coordinate2D(10, 10),
new Coordinate2D(30, 5),
new Coordinate2D(45, 20),
new Coordinate2D(20, 35)
}
})
}) {SRID = 4326};
using (NpgsqlConnection connection = CreateConnection())
{
NpgsqlCommand command = connection.CreateCommand();
command.Parameters.AddWithValue("p1", NpgsqlDbType.Geometry, geom1);
command.CommandText = "Select :p1";
command.ExecuteScalar();
}
using (NpgsqlConnection connection = CreateConnection())
{
NpgsqlCommand command = connection.CreateCommand();
command.Parameters.AddWithValue("p1", NpgsqlDbType.Geometry, geom2);
command.CommandText = "Select :p1";
command.ExecuteScalar(); //timeout occurs...
}
If increasing the CommandTimeout, the timeout occurs anyway.
Thanks in advance!
The fix for this bug has just been merged: https://github.com/npgsql/npgsql/pull/1025

Yandex Maps: how change styles placemark from api 1.0 to 2.0

I have this styles in api 1.0
var s = new YMaps.Style();
s.iconStyle = new YMaps.IconStyle();
s.iconStyle.offset = new YMaps.Point(-1, -30);
s.iconStyle.href = "http:www.example.com/images/1.png";
s.iconStyle.size = new YMaps.Point(29, 28);
s.iconStyle.shadow = new YMaps.IconShadowStyle();
s.iconStyle.shadow.offset = new YMaps.Point(2, -12);
s.iconStyle.shadow.href = "http:www.example.com/images/2.png";
s.iconStyle.shadow.size = new YMaps.Point(29, 7);
here I add this styles to placemark
var placemark = new YMaps.Placemark(new YMaps.GeoPoint(lat, long),
{hasBalloon: false,
style: s
});
placemark.setHintContent(mystring);
placemark.enableHint();
map.addOverlay(placemark);
how create this styles in api 2.0 ?
I solve like this :
placemark.options.set('iconImageHref', 'http:www.example.com/images/1.png');
placemark.options.set('iconImageOffset', [-1, -30]);
placemark.options.set('iconImageSize', [28,29]);
placemark.options.set('iconShadowImageHref', 'http:www.example.com/images/2.png');
placemark.options.set('iconShadowImageOffset', [2, -12]);
placemark.options.set('iconShadowImageSize', [29, 7]);

Actionscript 3, Flash CC: Placing Objects In An Array From The Library Onto The Stage

Hello programming gurus of stackoverflow, I am hoping that at least one of you will be able to help me with my coding problem. This is the first time I'm posting on this site, so if I miss something with the structure of my post, or anything please let me know (preferably not in a condescending matter) and I will gladly change it.
I actually had a different problem I was going to ask about, but I recently realized that some objects from my library weren't showing up on my stage. Hopefully, if this gets solved I won't have my other problem.
I am creating a learning module app using Flash CC and Actionscript 3, I like to think I am fairly proficient with Flash, but right now all my code is on the timeline because when I started I wasn't aware of the package setup. When I finish with the learning module I'll try and move everything to an AS package, so please bear with me.
This current frame of the module is a drag and drop game where the user drags the correct food, for the animal they chose in the previous frame, to the animal in the middle. The animal is dynamically placed on the stage, as well as an array of six possible food choices, all MovieClips pulled from the library. The array of food elements is actually not what I'm having problem with, they appear on my stage with no problems at all. The problem I'm having is when the user drags the correct food onto the animal, and the win condition is met, the array of balloon elements does not show up on the stage. I find it weird because I'm using near identical code for both the food and balloon array.
Here is my full code:
import flash.display.MovieClip;
import flash.events.MouseEvent;
foodPet();
function foodPet():void {
//all of my pet, food, and balloon library objects have been exported for AS
var theBird:pet_bird = new pet_bird;
var theCat:pet_cat = new pet_cat;
var theChicken:pet_chicken = new pet_chicken;
var theDog:pet_dog = new pet_dog;
var theDuck:pet_duck = new pet_duck;
var theGuinea:pet_guinea = new pet_guinea;
var theHamster:pet_hamster = new pet_hamster;
var birdSeed:food_bird_seed = new food_bird_seed;
var catFood:food_cat_food = new food_cat_food;
var chickenFeed:food_chicken_feed = new food_chicken_feed;
var chocolate:food_chocolate = new food_chocolate;
var dogFood:food_dog_food = new food_dog_food;
var duckFood:food_duck_food = new food_duck_food;
var animalList:Array = [theBird, theCat, theChicken, theDog,
theDuck, theGuinea, theHamster];
var food1Array:Array = [birdSeed, catFood, chickenFeed,
chocolate, dogFood, duckFood, 4];
var xPosFood:Array = new Array();
var yPosFood:Array = new Array();
xPosFood = [32, 71, 146, 363, 431, 512];
yPosFood = [304, 222, 123, 123, 222, 304];
var animalClip:MovieClip;
animalClip = animalList[chosenAnimal];
addChild(animalClip);
animalClip.x = 256;
animalClip.y = 287;
animalClip.name = "selectedAnimal";
for (var i:uint = 0; i < food1Array.length - 1; i++){ //Where the food gets added
var isItRight:Boolean = false;
var foodName:String = ("food" + i);
var foodClip:MovieClip;
foodClip = food1Array[i];
foodClip.x = xPosFood[i];
foodClip.y = yPosFood[i];
foodClip.name = foodName;
addChild(foodClip);
trace(foodClip.parent);
foodDragSetup(foodClip, animalClip, food1Array[food1Array.length - 1], isItRight);
}
}
function foodDragSetup(clip:MovieClip, targ:MovieClip, correctNum:uint, isItRight:Boolean) {
var beingDragged:Boolean = false;
var xPos:Number = clip.x;
var yPos:Number = clip.y;
clip.addEventListener(MouseEvent.MOUSE_DOWN, beginDrag);
function beginDrag(event:MouseEvent):void
{
clip.startDrag();
if (int(clip.name.substr(4)) == correctNum){
isItRight = true;
}
this.beingDragged = true;
setChildIndex(clip, numChildren - 1);
clip.addEventListener(MouseEvent.MOUSE_UP, endDrag);
}
function endDrag(event:MouseEvent):void
{
if (this.beingDragged) {
this.beingDragged = false;
clip.stopDrag();
if ((isItRight) && (clip.hitTestPoint(targ.x, targ.y, true))){
trace(targ.name + " has been hit.");
clip.x = targ.x;
clip.y = targ.y;
win_animal_food();
} else {
isItRight = false;
clip.x = xPos;
clip.y = yPos;
}
}
}
}
function win_animal_food():void {
const BALLOON_ROW:int = 4;
var count:uint = 0;
var altX:uint = 0;
var bBalloon:blue_balloon = new blue_balloon;
var gBalloon:green_balloon = new green_balloon;
var oBalloon:orange_balloon = new orange_balloon;
var pBalloon:purple_balloon = new purple_balloon;
var rBalloon:red_balloon = new red_balloon;
var yBalloon:yellow_balloon = new yellow_balloon;
var balloonList:Array = [bBalloon, gBalloon, oBalloon,
pBalloon, rBalloon, yBalloon, bBalloon, gBalloon,
oBalloon, pBalloon, rBalloon, yBalloon, bBalloon,
gBalloon, oBalloon, pBalloon];
var balloonY:Array = [144, -205, -265, -325];
var balloonX:Array = [0, 140, 284, 428, 68, 212, 356, 500];
for (var ballY:uint = 0; ballY < balloonY.length; ballY++){ //Where balloons
for (var ballX:uint = altX; ballX < altX + BALLOON_ROW; ballX++){ //get added
var balloonName:String = ("balloon" + count);
var balloonClip:MovieClip;
balloonClip = balloonList[count];
balloonClip.x = balloonX[ballX];
balloonClip.y = balloonY[ballY];
balloonClip.name = balloonName;
addChild(balloonClip);
trace(balloonClip.parent);
trace(balloonClip + " has been added!");
balloonClip.addEventListener(MouseEvent.CLICK, balloonPop);
count++;
}
if (altX == 0) {
altX = BALLOON_ROW;
} else {
altX = 0;
}
}
function balloonPop(event:MouseEvent):void {
event.target.play();
event.target.removeEventListener(MouseEvent.CLICK, balloonPop);
}
}
I thought there might have been a problem with my balloon MovieClips, so I subbed them in the food array:
var birdSeed:blue_balloon = new blue_balloon;
var catFood:green_balloon = new green_balloon;
var chickenFeed:orange_balloon = new orange_balloon;
var chocolate:purple_balloon = new purple_balloon;
var dogFood:red_balloon = new red_balloon;
var duckFood:yellow_balloon = new yellow_balloon;
They all showed up on the stage, so there's nothing wrong with the MovieClips.
Added: The first values of balloonXArray and balloonYArray were originally -4 and -145 respectively, but when I started having problems I wanted to make sure the balloons were showing up so I set the first values to 0 and 144 the balloon height and width are both 144 and their cross (not sure on it's name) is in the top left corner.
Added: The reason why there are multiple instances of the same balloon in the balloonList is because I need four rows of four balloons, but only have six different balloons.
I know the balloons are on the stage because the debug display shows their x and y values on the viewable stage. Using trace(foodClip.parent) and trace(balloonClip.parent) shows that the balloons and food all have the same parent, MainTimeline, so I know the balloons aren't getting added to some different space.
I have searched online, but have not come across anyone with a similar problem. Thus, I am asking on this forum if anyone can tell me why my balloons will not show up on the stage.
Please and thank you.
One thing I see straight off in the baloonList is that you have the same object instances listed multiple times. Each instance can only exist on stage exactly once. If you addChild() an instance that is already on stage, the instance is first removed, then re-added at the top of the display list.
You should change:
var bBalloon:blue_balloon = new blue_balloon;
var gBalloon:green_balloon = new green_balloon;
var oBalloon:orange_balloon = new orange_balloon;
var pBalloon:purple_balloon = new purple_balloon;
var rBalloon:red_balloon = new red_balloon;
var yBalloon:yellow_balloon = new yellow_balloon;
var balloonList:Array = [bBalloon, gBalloon, oBalloon,
pBalloon, rBalloon, yBalloon, bBalloon, gBalloon,
oBalloon, pBalloon, rBalloon, yBalloon, bBalloon,
gBalloon, oBalloon, pBalloon];
to:
var balloonList:Array = [
new blue_balloon,
new green_balloon,
new orange_balloon,
new purple_balloon,
new red_balloon,
new yellow_balloon,
new blue_balloon,
new green_balloon,
new orange_balloon,
new purple_balloon,
new red_balloon,
new yellow_balloon,
new blue_balloon,
new blue_balloon,
new green_balloon,
new orange_balloon,
new purple_balloon
];

Rotate a Geometry Path

I'm working newly with a Streamgeometry to draw a simple arrow. Now I need to turn the arrow to a specified angle. But how to rotate this geometry?
Dim pt1 As New Point(X1, Me.Y1) 'left point
Dim pt2 As New Point(_X2, Me.Y2) 'right point
Dim pt3 As New Point(_X2 + (HeadWidth * cost - HeadHeight * sint), Y2 + (HeadWidth * sint + HeadHeight * cost)) 'arrow line down
Dim pt4 As New Point(_X2 + (HeadWidth * cost + HeadHeight * sint), Y2 - (HeadHeight * cost - HeadWidth * sint)) 'arrow line up
context.BeginFigure(pt1, True, False)
context.LineTo(pt2, True, True)
context.LineTo(pt3, True, True)
context.LineTo(pt2, True, True)
context.LineTo(pt4, True, True)
If the rotation is only for presentation (i.e. you don't care that the original geometry data is still an arrow pointing in the original direction) then you can apply a transform to it.
After you've drawn on your context, just apply the transform on the original StreamGeometry object (code in C# but it applies to VB.NET too):
var geo = new StreamGeometry();
using (var ctx = geo.Open())
{
ctx.BeginFigure(new Point(0, 20), false, false);
ctx.LineTo(new Point(100, 20), true, true);
ctx.LineTo(new Point(80, 40), true, true);
ctx.LineTo(new Point(80, 0), true, true);
ctx.LineTo(new Point(100, 20), true, true);
}
geo.Transform = new RotateTransform(45);
var drawing = new GeometryDrawing(Brushes.Transparent, new Pen(Brushes.Black, 1), geo);
image1.Source = new DrawingImage(drawing);
The above code will draw an arrow pointing down/right on an Image control named image1.

Resources