Ox.load(), and adding moved files

This commit is contained in:
rolux 2011-04-25 11:12:02 +02:00
commit 6cfb6b7647
594 changed files with 1381 additions and 19555 deletions

View file

@ -3,16 +3,28 @@
import json
import os
import re
import shutil
def append_file(file):
split = file.split('/')[1].split('.')
module = '.'.join([split[0], split[1]])
if not module in files:
files[module] = []
files[module].append(file)
def copy_file(source, target):
print 'copying', source, 'to', target
write_file(target, read_file(source))
def read_file(file):
#print 'reading', file
print 'reading', file
f = open(file)
data = f.read()
f.close()
return data
def write_file(file, data):
#print 'writing', file
print 'writing', file
write_path(file)
f = open(file, 'w')
f.write(data)
@ -20,6 +32,8 @@ def write_file(file, data):
return len(data)
def write_link(source, target):
print 'linking', source, 'to', target
write_path(target)
if os.path.exists(target):
os.unlink(target)
os.symlink(source, target)
@ -29,49 +43,73 @@ def write_path(file):
if path and not os.path.exists(path):
os.makedirs(path)
os.chdir(os.path.dirname(__file__))
# doesn't work here
# os.chdir(os.path.dirname(__file__))
source_path = '../../source/'
build_path = '../../build/'
files = {}
# SVG
# css
for path, dirnames, filenames in os.walk(source_path + 'css/'):
for filename in filenames:
source = os.path.join(path, filename)
target = source.replace(source_path, build_path)
copy_file(source, target)
append_file(target.replace(build_path, ''))
path = '../../source/svg/symbols/'
for dirname, dirnames, filenames in os.walk(path):
# js
filename = 'js/Ox.js'
write_link(source_path + filename, build_path + filename)
root = source_path + 'js/'
for path, dirnames, filenames in os.walk(root):
for dirname in dirnames:
if dirname[0] != '_':
if path == root and dirname != 'jquery':
source = os.path.join(path, dirname)
target = source.replace(source_path, build_path)
write_link(source, target)
for filename in filenames:
if filename[0] != '.' and filename[0] != '_':
svg = read_file(path + filename)
new_filename = 'symbol' + filename[0].upper() + filename[1:]
write_file(build_path + 'svg/ox.ui.classic/' + new_filename, svg)
write_file(build_path + 'svg/ox.ui.modern/' + new_filename, svg.replace('#404040', '#FFFFFF').replace('#000000', '#FFFFFF'))
if 'jquery' in path:
is_jquery = re.compile('jquery-[\d\.]+\.js').findall(filename)
is_jquery_min = re.compile('jquery-[\d\.]+\.min\.js').findall(filename)
source = os.path.join(path, filename)
if is_jquery:
target = os.path.join(path.replace(source_path, build_path), 'jquery.js')
elif is_jquery_min:
target = os.path.join(path.replace(source_path, build_path), 'jquery.min.js')
else:
target = source.replace(source_path, build_path)
copy_file(source, target)
if not is_jquery and not is_jquery_min:
files['Ox.UI'].append(target.replace(build_path, ''))
elif path != root and not '_' in path:
append_file(os.path.join(path, filename).replace(source_path, ''))
# JSON
files = []
for dirname, dirnames, filenames in os.walk(source_path + 'js/'):
# png
for path, dirnames, filenames in os.walk(source_path + 'png/'):
for filename in filenames:
if filename[:1] != '.':
jquery = re.compile('jquery-[\d\.]+\.js').findall(filename)
if jquery or filename in ['Ox.js', 'OxUI.js']:
target = 'jquery.js' if jquery else filename
write_link(os.path.join(dirname, filename), build_path + 'js/' + target)
elif not '_' in dirname and not filename.endswith('.min.js'):
files.append(os.path.join(dirname.replace(source_path , '../source/'), filename))
source = os.path.join(path, filename)
target = source.replace(source_path, build_path)
copy_file(source, target)
append_file(target.replace(build_path, ''))
for dirname, dirnames, filenames in os.walk(source_path + 'css'):
# svg
for path, dirnames, filenames in os.walk(source_path + 'svg/'):
for filename in filenames:
if filename[:1] != '.':
write_link(os.path.join(dirname, filename), build_path + 'css/' + filename)
if filename[0] != '.' and filename[0] != '_':
source = os.path.join(path, filename)
target = source.replace(source_path, build_path)
copy_file(source, target)
append_file(target.replace(build_path, ''))
if 'Ox.UI.classic' in source:
svg = read_file(source).replace('#404040', '#FFFFFF').replace('#000000', '#FFFFFF')
target = target.replace('Ox.UI.classic', 'Ox.UI.modern')
write_file(target, svg)
append_file(target.replace(build_path, ''))
for dirname, dirnames, filenames in os.walk(build_path + 'png'):
for filename in filenames:
if filename[:1] != '.':
files.append(os.path.join(dirname.replace(build_path, ''), filename))
for dirname, dirnames, filenames in os.walk(build_path + 'svg'):
for filename in filenames:
if filename[:1] != '.':
files.append(os.path.join(dirname.replace(build_path, ''), filename))
write_file(build_path + 'json/OxUI.json', json.dumps(files, indent=4, sort_keys=True))
for module in files:
file = build_path + 'json/' + module + '.json'
write_file(file, json.dumps(sorted(files[module]), indent=4, sort_keys=True))

View file

@ -1,6 +0,0 @@
{
ENG: "England",
NIR: "Northern Ireland",
SCT: "Scotland",
WLS: "Wales"
}

File diff suppressed because it is too large Load diff

View file

@ -1,408 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
body {
margin: 0;
overflow: hidden;
}
#map {
width: 100%;
height: 100%;
}
#data0 {
position: absolute;
left: 0;
bottom: 0;
width: 50%;
height: 100px;
padding: 0;
border: 0;
background: rgba(0, 0, 0, 0.5);
font-family: Consolas;
font-size: 8px;
color: rgb(255, 255, 255);
overflow: auto;
z-index: 1000;
}
#data:focus {
outline: none;
}
#data1 {
position: absolute;
right: 0;
bottom: 0;
width: 50%;
height: 100px;
padding: 0;
border: 0;
background: rgba(0, 0, 0, 0.5);
font-family: Consolas;
font-size: 8px;
color: rgb(255, 255, 255);
overflow: auto;
z-index: 1000;
}
.flag {
position: absolute;
width: 8px;
height: 8px;
margin-left: -4px;
margin-top: -4px;
-moz-border-radius: 1px;
-webkit-border-radius: 1px;
-moz-box-shadow: 1px 1px 2px rgba(0, 0, 0, 128);
-webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, 128);
}
.flag:hover {
width: 16px;
height: 16px;
margin-left: -8px;
margin-top: -8px;
opacity: 0.5;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
-moz-box-shadow: 2px 2px 4px rgba(0, 0, 0, 128);
-webkit-box-shadow: 2px 2px 4px rgba(0, 0, 0, 128);
}
.rect {
position: absolute;
border: 1px solid rgb(255, 255, 255);
z-index: 1;
-moz-box-shadow: 2px 2px 4px rgba(0, 0, 0, 128);
-webkit-box-shadow: 2px 2px 4px rgba(0, 0, 0, 128);
}
</style>
<script src="../../build/js/jquery-1.3.2.js"></script>
<script src="../../build/js/ox.js"></script>
<script src="../../build/js/ox.data.js"></script>
<script src="../../build/js/ox.geo.js"></script>
<script src="../../build/js/ox.map.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script>
$(function() {
var $body = $("body"),
$map = $("<img/>")
.attr({
id: "map",
src: "map.png"
})
.appendTo($body),
$data0 = $("<textarea/>")
.attr({
id: "data0"
})
.appendTo($body),
$data1 = $("<textarea/>")
.attr({
id: "data1"
})
.appendTo($body),
aliases = {
'Byelorussian Soviet Socialist Republic': 'Belarus',
'Dahomey': 'Benin',
'European Union': 'Europe',
'Georgia': 'Georgia, Europe',
'Johnston Island': 'Johnston Atoll',
'Metropolitan France': 'France',
'Neutral Zone': 'Neutral Zone, Saudi Arabia',
'Sahrawi': 'Western Sahara',
'Siam': 'Thailand',
'United States Minor Outlying Islands': 'Wake Island',
'Upper Volta': 'Burkina Faso'
// "Palestine": ["West Bank", "Gaza Strip"],
},
unions = {
/*
'Bonaire, Saint Eustatius and Saba': [
'Bonaire', 'Saba', 'Saint Eustatius'
],
*/
'Czechoslovakia': [
'Czech Republic', 'Slovakia'
],
'Korea': [
'North Korea', 'South Korea'
],
'Pacific Islands': [
'Marshall Islands', 'Micronesia', 'Northern Mariana Islands', 'Palau'
],
'Serbia and Montenegro': [
'Montenegro', 'Serbia'
],
'Soviet Union': [
'Armenia', 'Azerbaijan', 'Belarus', 'Estonia', 'Georgia',
'Latvia', 'Lithuania', 'Kazakhstan', 'Kyrgyzstan', 'Moldova',
'Russia', 'Tajikistan', 'Turkmenistan', 'Ukraine', 'Uzbekistan'
],
'United Kingdom': [
'England', 'Northern Ireland', 'Scotland', 'Wales'
],
/*
'West Germany': [
'Schleswig Holstein', 'Northrhine Westphalia', 'Bavaria'
],
*/
'Yugoslavia': [
'Bosnia and Herzegovina', 'Croatia', 'Serbia', 'Slovenia', 'Macedonia',
'Montenegro'
]
}
json = {};
///*
$.getJSON("geo.json", function(data) {
json = data;
getPlacemarks(Ox.COUNTRIES);
setTimeout(parse, 2000);
});
//*/
/*
getPlacemarks(Ox.COUNTRIES);
*/
function getPlacemarks(countries) {
var country = countries.shift();
if (!(country.code in json) || !(country.name in unions)) {
console.log(country);
Ox.getPlacemarks(aliases[country.name] || country.name, function(geodata) {
if (!geodata.results.length) {
console.log(country.name, geodata.status);
} else {
geodata = geodata.results[0];
Ox.print('geodata', geodata)
data = {
address: aliases[country.name] || country.name,
geocode: {
address_components: geodata.address_components,
formatted_address: geodata.formatted_address,
geometry: {
location: {},
location_type: geodata.geometry.location_type
},
types: geodata.types
},
name: country.name,
time: +new Date()
};
$.each(["lat", "lng"], function(i, crd) {
data.geocode.geometry.location[crd] = parseFloat(
geodata.geometry.location[crd]().toFixed(8)
);
});
$.each(["bounds", "viewport"], function(i, obj) {
if (obj in geodata.geometry) {
data.geocode.geometry[obj] = {};
$.each(["center", "southWest", "northEast"], function(i, pnt) {
data.geocode.geometry[obj][pnt] = {};
$.each(["lat", "lng"], function(i, crd) {
data.geocode.geometry[obj][pnt][crd] = parseFloat(
geodata.geometry[obj][
"get" + pnt[0].toUpperCase() + pnt.substr(1)
]()[crd]().toFixed(8)
);
});
});
}
});
json[country.code] = data;
addFlag(country, json[country.code]);
addData(json)
if (country.name != geodata.formatted_address) {
console.log(country.name, geodata.formatted_address, geodata);
}
}
if (countries.length) {
setTimeout(function() {
getPlacemarks(countries);
}, 1000);
}
});
} else {
addFlag(country, json[country.code]);
addData(json);
if (countries.length) {
setTimeout(function() {
getPlacemarks(countries);
}, 100);
}
}
}
function addData(json) {
//var scroll = $data[0].scrollTop == $data[0].scrollHeight;
$data0.html(
JSON.stringify(json, null, 4)
);
/*
if (scroll) {
$data[0].scrollTop = $data[0].scrollHeight;
}
*/
}
function addFlag(country, data) {
var location = Ox.getXY(data.geocode.geometry.location.lat, data.geocode.geometry.location.lng),
bounds = "bounds" in data.geocode.geometry ? data.geocode.geometry.bounds : data.geocode.geometry.viewport,
southWest = Ox.getXY(bounds.southWest.lat, bounds.southWest.lng),
northEast = Ox.getXY(bounds.northEast.lat, bounds.northEast.lng),
crossesDateline = southWest.x > northEast.x,
$div = [];
if (crossesDateline) {
$div = [
$("<div/>")
.addClass("rect")
.css({
left: "-16px",
top: ($map.height() * northEast.y) + "px",
right: ($map.width() - $map.width() * northEast.x) + "px",
bottom: ($map.height() - $map.height() * southWest.y) + "px",
})
.hide()
.appendTo($body),
$("<div/>")
.addClass("rect")
.css({
left: ($map.width() * southWest.x) + "px",
top: ($map.height() * northEast.y) + "px",
right: "-16px",
bottom: ($map.height() - $map.height() * southWest.y) + "px",
})
.hide()
.appendTo($body),
];
} else {
$div = [
$("<div/>")
.addClass("rect")
.css({
left: ($map.width() * southWest.x) + "px",
top: ($map.height() * northEast.y) + "px",
right: ($map.width() - $map.width() * northEast.x) + "px",
bottom: ($map.height() - $map.height() * southWest.y) + "px",
})
.hide()
.appendTo($body)
];
}
$("<img/>")
.attr({
src: '../../build/svg/' + country.code + '.' +
(country.flag == 'png' ? 'png' : 'svg'),
title: country.name + " ((" + bounds.southWest.lat + ", " + bounds.southWest.lng + "), (" + bounds.northEast.lat + ", " + bounds.northEast.lng + "))"
})
.addClass("flag")
.css({
left: (location.x * 100) + "%",
top: (location.y * 100) + "%"
})
.mouseenter(function() {
$(this).css({
zIndex: Ox.uid()
});
$.each($div, function() {
$(this).show();
});
})
.mouseleave(function() {
$.each($div, function() {
$(this).hide();
});
})
.appendTo($body);
window.status = Ox.length(json) + " " + data.address;
}
function parse() {
var bounds, center,
data = JSON.parse($data0.html()),
data_ = [],
union;
alert(Ox.COUNTRIES.length + ' ' + Ox.COUNTRIES[0].code)
Ox.COUNTRIES.forEach(function(country) {
if (country.code == 'AF') {
alert('AF')
}
Ox.print('CC', country.code)
if (country.code in data) {
bounds = data[country.code].geocode.geometry.bounds ||
data[country.code].geocode.geometry.viewport;
}
if (country.name in unions) {
unions[country.name].forEach(function(countryName, i) {
var countryCode = getCountryCode(countryName);
Ox.print('countryCode', countryCode)
bounds = data[countryCode].geocode.geometry.bounds ||
data[countryCode].geocode.geometry.viewport;
bounds = new google.maps.LatLngBounds(
new google.maps.LatLng(
bounds.southWest.lat,
bounds.southWest.lng
),
new google.maps.LatLng(
bounds.northEast.lat,
bounds.northEast.lng
)
);
union = i == 0 ? bounds : union.union(bounds);
});
bounds = {
southWest: {
lat: union.getSouthWest().lat(),
lng: union.getSouthWest().lng()
},
northEast: {
lat: union.getNorthEast().lat(),
lng: union.getNorthEast().lng()
}
};
}
if (country.name == 'Antarctica') {
bounds.southWest.lat = Ox.MIN_LATITUDE;
bounds.southWest.lng = -179.99999999;
bounds.northEast.lng = 179.99999999;
} else if (country.name == 'United Kingdom') {
}
var center = new google.maps.LatLngBounds(
new google.maps.LatLng(
bounds.southWest.lat, bounds.southWest.lng
),
new google.maps.LatLng(
bounds.northEast.lat, bounds.northEast.lng
)
).getCenter();
data_.push({
code: country.code,
name: country.name,
country: country.country,
region: country.region,
continent: country.continent,
type: country.type,
lat: center.lat(),
lng: center.lng(),
south: bounds.southWest.lat,
west: bounds.southWest.lng,
north: bounds.northEast.lat,
east: bounds.northEast.lng,
size: Ox.getArea(
bounds.southWest, bounds.northEast
)
});
});
$data1.html(JSON.stringify(data_.sort(function(a, b) {
return a.name < b.name ? -1 : (a.name > b.name ? 1 : 0);
}), null, 4));
function getCountryCode(countryName) {
var ret;
Ox.COUNTRIES.forEach(function(country) {
if (country.name == countryName) {
ret = country.code;
return false;
}
});
return ret;
}
}
});
</script>
</head>
<body></body>
</html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB