Skip to content

Instantly share code, notes, and snippets.

@lwu
Created August 27, 2008 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lwu/7382 to your computer and use it in GitHub Desktop.
Save lwu/7382 to your computer and use it in GitHub Desktop.
My first Shoes app! Shoes is a "Tiny Toolkit" for informal graphics and windowing:
http://code.whytheluckystiff.net/shoes/
I wanted to be able to easily edit Mapnik stylesheets, hit render, and see the result
right away. While this isn't a great solution -- the prototype shells out to a C++ binary to
re-render the map -- it works for the time being.
A screenshot of the resulting application can be seen here:
http://farm4.static.flickr.com/3095/2801694916_1a051349b4_b.jpg
(http://flickr.com/photos/wu_135/2801694916/sizes/l/)
This code doesn't come with the C++ binary nor does it come with the original dataset, but please do
provide your own!
## This is a prototype Shoes app to make Mapnik stylesheet editing a little bit easier.
## More of a proof of concept -- manysuchthings are hardcoded (image sizes, file names)
#
class DebugShoes < Shoes # Shoes got you down? DebugShoes won't fail silently on ya...
def self.app(*args, &blk)
super(*args) do
begin
self.instance_eval(&blk)
rescue => e
error(e) # log the error and inform the user!
@err_bar = flow :width => 1.0, :height => 32, :top => self.height-32, :left => 0 do
background lightgrey
stack :width => self.width-100
stack :width => 20, :margin => 4 do image "#{DIR}/static/icon-error.png" end;
stack :width => 80 do para(link("#{Shoes.log.length} Errors!", :stroke => red) { Shoes.show_log }) end;
end
end
end
end
end
class Image
def reload
self.path = "./" + path # reload hack, cache begone!
self.hide.show
end
end
DebugShoes.app :width => 1360, :height => 720, :title => 'MappinPrototype' do
STYLE_XML = 'style.xml'
IMAGE_PNG = 'cali.png'
MAP_APP = './cali ~/src/mapnik'
animate(2) do
if @render then
@render = false
`#{MAP_APP}` # shell out to run Map app
@bg.reload
end
end
background black
flow do
stack :width=>820, :margin=>15 do
@bg = image IMAGE_PNG, :width=>800, :height=>680
end
stack :width => 530, :margin=>15 do
background lightgrey, :curve => 12
para "Layers"
@e = edit_box "Would that I...", :width => 500, :height => 620
@e.text = IO.read(STYLE_XML)
button "Render!", :margin=>5 do
warn "Rendering..."
open(STYLE_XML, 'w') { |f| f.puts @e.text }
@bg.blur 10
@bg.hide.show # reload
@render = true # defer rendering so that blur effect becomes visible
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment