Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pep8 fixes #6

Merged
merged 1 commit into from
Apr 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ script:
- coverage run --include="src/*" test/test_manager.py
# Static analysis
- pyflakes .

after_script:
# Static analysis
- pep8 --statistics --count .

after_success:
Expand Down
158 changes: 80 additions & 78 deletions examples/custom_animations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,95 +8,97 @@
from osmviz.animation import SimViz, TrackingViz, Simulation
import pygame

## Our goal is to show a train lassoed to denver, running around it.
# Our goal is to show a train lassoed to Denver, running around it.

red = pygame.Color("red")


class LassoViz(SimViz):
"""
LassoViz draws a line between two (optionally moving) locations.
"""

def __init__(self, getLocAtTime1, getLocAtTime2,
linecolor=red, linewidth=3,
drawingOrder=0):
"""
getLocAtTime 1 and 2 represent the location of the 1st and 2nd
endpoint of this lasso, respectively. They should take a single
argument (time) and return the (lat,lon) of that endpoint.
LassoViz draws a line between two (optionally moving) locations.
"""
SimViz.__init__(self, drawingOrder);
self.xy1 = None
self.xy2 = None
self.linecolor = linecolor
self.linewidth = linewidth
self.getLoc1 = getLocAtTime1
self.getLoc2 = getLocAtTime2

def setState(self, simtime, getXY):
self.xy1 = getXY(*self.getLoc1(simtime))
self.xy2 = getXY(*self.getLoc2(simtime))

def drawToSurface(self, surf):
pygame.draw.line(surf, self.linecolor, self.xy1, self.xy2,
self.linewidth)

## So long as we are passing LassoViz's in as part of the scene_viz
## list to a Simulation, we don't need to implement the getLabel,
## getBoundingBox, or mouseIntersect methods.


class TiedTrain(TrackingViz):
"""
TiedTrain shows a train tied to a certain location, running around
it at a specified distance and frequency.
This is partly meant to demonstrate that it's ok to override
the TrackingViz class, too (in fact it's usually easier).
"""

def __init__(self, tiepost, lat_dist, lon_dist, frequency, time_window,
label, drawing_order=0, image="images/train.png"):
self.clat,self.clon = tiepost
self.lat_dist = lat_dist
self.lon_dist = lon_dist
self.frequency = int(frequency)

TrackingViz.__init__(self,label,image,self.getLocAtTime,time_window,
(self.clat-self.lat_dist, self.clat+self.lat_dist,
self.clon-self.lon_dist, self.clon+self.lon_dist),
drawing_order)


def getLocAtTime(self,time):
phase = float(time % self.frequency) / self.frequency
if phase < 0.25:
blat = self.clat - self.lat_dist
elat = self.clat + self.lat_dist
blon = elon = self.clon - self.lon_dist
frac = phase/0.25
elif phase < 0.5:
blat = elat = self.clat + self.lat_dist
blon = self.clon - self.lon_dist
elon = self.clon + self.lon_dist
frac = (phase-0.25)/0.25
elif phase < 0.75:
blat = self.clat + self.lat_dist
elat = self.clat - self.lat_dist
blon = elon = self.clon + self.lon_dist
frac = (phase-0.5)/0.25
else:
blat = elat = self.clat - self.lat_dist
blon = self.clon + self.lon_dist
elon = self.clon - self.lon_dist
frac = (phase-0.75)/0.25
return blat + frac*(elat-blat), blon + frac*(elon-blon)

def __init__(self, getLocAtTime1, getLocAtTime2,
linecolor=red, linewidth=3,
drawingOrder=0):
"""
getLocAtTime 1 and 2 represent the location of the 1st and 2nd
endpoint of this lasso, respectively. They should take a single
argument (time) and return the (lat,lon) of that endpoint.
"""
SimViz.__init__(self, drawingOrder)
self.xy1 = None
self.xy2 = None
self.linecolor = linecolor
self.linewidth = linewidth
self.getLoc1 = getLocAtTime1
self.getLoc2 = getLocAtTime2

def setState(self, simtime, getXY):
self.xy1 = getXY(*self.getLoc1(simtime))
self.xy2 = getXY(*self.getLoc2(simtime))

def drawToSurface(self, surf):
pygame.draw.line(surf, self.linecolor, self.xy1, self.xy2,
self.linewidth)

# So long as we are passing LassoViz's in as part of the scene_viz
# list to a Simulation, we don't need to implement the getLabel,
# getBoundingBox, or mouseIntersect methods.


class TiedTrain(TrackingViz):
"""
TiedTrain shows a train tied to a certain location, running around
it at a specified distance and frequency.
This is partly meant to demonstrate that it's ok to override
the TrackingViz class, too (in fact it's usually easier).
"""

def __init__(self, tiepost, lat_dist, lon_dist, frequency, time_window,
label, drawing_order=0, image="images/train.png"):
self.clat, self.clon = tiepost
self.lat_dist = lat_dist
self.lon_dist = lon_dist
self.frequency = int(frequency)

TrackingViz.__init__(self, label, image, self.getLocAtTime,
time_window,
(self.clat-self.lat_dist,
self.clat+self.lat_dist,
self.clon-self.lon_dist,
self.clon+self.lon_dist),
drawing_order)

def getLocAtTime(self, time):
phase = float(time % self.frequency) / self.frequency
if phase < 0.25:
blat = self.clat - self.lat_dist
elat = self.clat + self.lat_dist
blon = elon = self.clon - self.lon_dist
frac = phase/0.25
elif phase < 0.5:
blat = elat = self.clat + self.lat_dist
blon = self.clon - self.lon_dist
elon = self.clon + self.lon_dist
frac = (phase-0.25)/0.25
elif phase < 0.75:
blat = self.clat + self.lat_dist
elat = self.clat - self.lat_dist
blon = elon = self.clon + self.lon_dist
frac = (phase-0.5)/0.25
else:
blat = elat = self.clat - self.lat_dist
blon = self.clon + self.lon_dist
elon = self.clon - self.lon_dist
frac = (phase-0.75)/0.25
return blat + frac*(elat-blat), blon + frac*(elon-blon)


denver = 39.756111, -104.994167
train = TiedTrain(denver, 5.0, 5.0, 60, (0, 600), "Denver Bound")
lasso = LassoViz(train.getLocAtTime,
lambda t: denver)

sim = Simulation( [train,], [lasso,], 0)
sim.run(refresh_rate = 0.01, speed = 1, osmzoom = 7)
sim = Simulation([train, ], [lasso, ], 0)
sim.run(refresh_rate=0.01, speed=1, osmzoom=7)
51 changes: 26 additions & 25 deletions examples/multiple_trackvizs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from osmviz.animation import TrackingViz, Simulation

## The goal is to show 10 trains racing eastward across the US.
# The goal is to show 10 trains racing eastward across the US.

right_lon = -(68+39.0/60)
left_lon = -(118+15.0/60)
Expand All @@ -16,38 +16,39 @@
end_time = 60

image_f = "images/train.png"
zoom=6
zoom = 6
num_trains = 10

trackvizs = []


def makeInterpolator(begin_ll, end_ll, begin_t, end_t):
def ret(t):
if t<begin_t:
return begin_ll
elif t>end_t:
return end_ll
else:
blat,blon = begin_ll
elat,elon = end_ll
frac = float(t)/(end_t-begin_t)
return ( blat + frac*(elat-blat) , blon + frac*(elon-blon) )
return ret
def ret(t):
if t < begin_t:
return begin_ll
elif t > end_t:
return end_ll
else:
blat, blon = begin_ll
elat, elon = end_ll
frac = float(t)/(end_t-begin_t)
return (blat + frac*(elat-blat), blon + frac*(elon-blon))
return ret

for i in range(num_trains):
lat = bottom_lat + i * (top_lat-bottom_lat) / (num_trains-1)
locAtTime = makeInterpolator( (lat, left_lon),
(lat, right_lon),
begin_time, end_time )
lat = bottom_lat + i * (top_lat-bottom_lat) / (num_trains-1)

locAtTime = makeInterpolator((lat, left_lon),
(lat, right_lon),
begin_time, end_time)

tviz = TrackingViz( "Train %d" %(i+1,), image_f, locAtTime,
(begin_time,end_time),
(30,46,-119,-68.5),
1) #drawing order doesn't really matter here
tviz = TrackingViz("Train %d" % (i+1,), image_f, locAtTime,
(begin_time, end_time),
(30, 46, -119, -68.5),
1) # drawing order doesn't really matter here

trackvizs.append(tviz)
trackvizs.append(tviz)


sim = Simulation( trackvizs, [], 0 )
sim.run(speed=1,refresh_rate=0.1,osmzoom=zoom)
sim = Simulation(trackvizs, [], 0)
sim.run(speed=1, refresh_rate=0.1, osmzoom=zoom)
4 changes: 2 additions & 2 deletions examples/pil_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

imgr = PILImageManager('RGB')
osm = OSMManager(image_manager=imgr)
image,bnds = osm.createOSMImage( (30,35,-117,-112), 9 )
image, bnds = osm.createOSMImage((30, 35, -117, -112), 9)
wh_ratio = float(image.size[0]) / image.size[1]
image2 = image.resize( (int(800*wh_ratio),800), Image.ANTIALIAS )
image2 = image.resize((int(800*wh_ratio), 800), Image.ANTIALIAS)
del image
image2.show()
26 changes: 15 additions & 11 deletions html/py2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,25 @@
# - parse script encoding and allow output in any encoding by using unicode
# as intermediate

import cgi
import cStringIO
import keyword
import string
import sys
import token
import tokenize

__version__ = '0.3'
__date__ = '2005-07-04'
__license__ = 'GPL'
__author__ = 'J�rgen Hermann, Mike Brown, Christopher Arndt'


# Imports
import cgi, string, sys, cStringIO
import keyword, token, tokenize


#############################################################################
### Python Source Parser (does Hilighting)
# Python Source Parser (does highlighting)
#############################################################################

_KEYWORD = token.NT_OFFSET + 1
_TEXT = token.NT_OFFSET + 2
_TEXT = token.NT_OFFSET + 2

_css_classes = {
token.NUMBER: 'number',
Expand Down Expand Up @@ -102,6 +104,7 @@

"""


class Parser:
""" Send colored python source.
"""
Expand All @@ -122,7 +125,8 @@ def format(self):
pos = 0
while 1:
pos = string.find(self.raw, '\n', pos) + 1
if not pos: break
if not pos:
break
self.lines.append(pos)
self.lines.append(len(self.raw))

Expand All @@ -140,12 +144,12 @@ def format(self):
msg, self.raw[self.lines[line]:]))
self.out.write('\n</pre>')

def __call__(self, toktype, toktext, (srow,scol), (erow,ecol), line):
def __call__(self, toktype, toktext, (srow, scol), (erow, ecol), line):
""" Token handler.
"""
if 0:
print "type", toktype, token.tok_name[toktype], "text", toktext,
print "start", srow,scol, "end", erow,ecol, "<br>"
print "start", srow, scol, "end", erow, ecol, "<br>"

# calculate new positions
oldpos = self.pos
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
name='osmviz',
version='1.0',
long_description=open('README.md', 'r').read(),
packages= find_packages('src'),
package_dir = {'': 'src'},
packages=find_packages('src'),
package_dir={'': 'src'},
zip_safe=False,
requires = (
requires=(
'PyGame',
'PIL',
)
)
)
2 changes: 1 addition & 1 deletion src/osmviz/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### osmviz module ###
# osmviz module #
# Copyright (c) 2010 Colin Bick, Robert Damphousse

# Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
Loading