Skip to content

Commit

Permalink
IF YOU FIND BUGS, LOOK HERE FIRSTsvn diff!
Browse files Browse the repository at this point in the history
pep8 -fixes etc, improved general readability
  • Loading branch information
kipe committed Sep 18, 2012
1 parent ecc02be commit 63ee133
Show file tree
Hide file tree
Showing 54 changed files with 860 additions and 813 deletions.
17 changes: 10 additions & 7 deletions download.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@
ctx_map = MapServ(mConf.init_path, mConf.repository_type)
downloader = None


def dl_callback(*args, **kwargs):
if not args[0]:
sys.stdout.write('\b=*')


def download(lat, lng, lat_range, lng_range, max_zl, min_zl, layer):
for zl in range(max_zl, min_zl - 1, -1):
sys.stdout.write("\nDownloading zl %d \t" % zl)
downloader.query_region_around_location(
lat, lng,
lat_range*2, lng_range*2, zl,
lat_range * 2, lng_range * 2, zl,
layer, dl_callback,
conf=mConf
)
downloader.wait_all()


def download_coordpath(gpxfile, max_zl, min_zl, layer, arround=2):
coords = load_gpx_coords(gpxfile)
for zl in range(max_zl, min_zl - 1, -1):
Expand All @@ -44,7 +47,8 @@ def download_coordpath(gpxfile, max_zl, min_zl, layer, arround=2):

if (args.location is None) and (args.gpx is None) and ((args.lat is None) or (args.lng is None)):
args.print_help()
import signal ; os.kill(os.getpid(), signal.SIGTERM)
import signal
os.kill(os.getpid(), signal.SIGTERM)
sys.exit(0)

print "location = %s" % args.location
Expand All @@ -64,7 +68,7 @@ def download_coordpath(gpxfile, max_zl, min_zl, layer, arround=2):
# GPX path mode
args.width = int(args.width)
if args.width < 0:
args.width = 2 # The default for GPX
args.width = 2 # The default for GPX
else:
if args.width > 0:
args.lng_range = km_to_lon(args.width, args.lat)
Expand All @@ -86,14 +90,13 @@ def download_coordpath(gpxfile, max_zl, min_zl, layer, arround=2):

downloader = MapDownloader(ctx_map, args.nr_threads)
try:
if args.gpx != None:
if args.gpx is not None:
download_coordpath(args.gpx, args.max_zl, args.min_zl, args.layer, arround=args.width)
else:
download(args.lat, args.lng, args.lat_range, args.lng_range,
args.max_zl, args.min_zl, args.layer)
finally:
print "\nDownload Complete!"
downloader.stop_all()
import signal ; os.kill(os.getpid(), signal.SIGTERM)


import signal
os.kill(os.getpid(), signal.SIGTERM)
29 changes: 15 additions & 14 deletions gmapcatcher/DLWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from gtkThread import *
from os.path import join, isdir


class DLWindow(gtk.Window):

def __init__(self, coord, kmx, kmy, layer, conf):
Expand Down Expand Up @@ -107,8 +108,8 @@ def _buttons(strFolder):
gtk.Window.__init__(self)
lat0 = coord[0]
lon0 = coord[1]
zoom0 = max(MAP_MIN_ZOOM_LEVEL, coord[2]-3)
zoom1 = min(MAP_MAX_ZOOM_LEVEL, coord[2]+1)
zoom0 = max(MAP_MIN_ZOOM_LEVEL, coord[2] - 3)
zoom1 = min(MAP_MAX_ZOOM_LEVEL, coord[2] + 1)

vbox = gtk.VBox(False)
hbox = gtk.HBox(False, 10)
Expand All @@ -129,10 +130,10 @@ def _buttons(strFolder):
if ico:
self.set_icon(ico)

self.complete=[]
self.processing=False
self.gmap=None
self.downloader=None
self.complete = []
self.processing = False
self.gmap = None
self.downloader = None
self.connect('delete-event', self.on_delete)
self.connect('key-press-event', self.key_press)
self.show_all()
Expand All @@ -148,7 +149,8 @@ def run(self, w, init_path, repostype, strFolder):
self.all_done("Canceled")
return
args = MapArgs()
if self.processing: return
if self.processing:
return
try:
args.lat = float(self.e_lat0.get_text())
args.lng = float(self.e_lon0.get_text())
Expand Down Expand Up @@ -196,25 +198,25 @@ def do_open(self, w, strPath):

## Save the data to a text file
def save_info(self, strPath, strInfo):
file = open(join(strPath, 'gmap'+ mapUtils.timeStamp() +'.bat'), "w")
file = open(join(strPath, 'gmap' + mapUtils.timeStamp() + '.bat'), "w")
file.write(strInfo)
file.close()

def tile_received(self, coord, layer, download=False):
self.complete.append((coord, layer))
ncomplete = len(self.complete)
nqueued = self.downloader.qsize() if self.downloader else 0
if nqueued==0 and ((not self.downloader) or self.downloader.bulk_all_placed):
if nqueued == 0 and ((not self.downloader) or self.downloader.bulk_all_placed):
self.download_complete()
return
self.update_pbar(
"x=%d y=%d zoom=%d" % coord, ncomplete, ncomplete+nqueued
"x=%d y=%d zoom=%d" % coord, ncomplete, ncomplete + nqueued
)

def update_pbar(self, text, pos, maxpos):
percent = ""
if pos != maxpos:
percentfloat = float(pos)/maxpos
percentfloat = float(pos) / maxpos
self.pbar.set_fraction(percentfloat)
if percentfloat > 0:
percent = " [%.1f%%]" % (percentfloat * 100)
Expand All @@ -224,7 +226,7 @@ def download_complete(self):
if self.pbar.get_text() != "Paused":
self.all_done("Complete")

def do_pause(self,w):
def do_pause(self, w):
self.all_done("Paused")

def all_done(self, strMessage):
Expand All @@ -243,8 +245,7 @@ def key_press(self, w, event):
self.on_delete()
self.destroy()

def on_delete(self,*params):
def on_delete(self, *params):
if self.downloader:
self.downloader.stop_all()
return False

50 changes: 20 additions & 30 deletions gmapcatcher/EXWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@
pygtk.require('2.0')
import gtk

from mapArgs import MapArgs
from fileUtils import check_dir
from mapDownloader import MapDownloader
from customWidgets import *

import tilesRepo.Factory as trFactory
import mapTilesTransfer

import mapPixbuf
import mapUtils
import mapServices
from gtkThread import *
from os.path import join, isdir


class EXWindow(gtk.Window):

Expand Down Expand Up @@ -71,8 +67,8 @@ def get_folder(button):
vbox.set_border_width(5)
hbox = gtk.HBox(False, 10)
self.entry_custom_path = gtk.Entry()
self.entry_custom_path.set_text( EXWindow.configpath )
repository_type_combo( EXWindow.repostype_id )
self.entry_custom_path.set_text(EXWindow.configpath)
repository_type_combo(EXWindow.repostype_id)
hbox.pack_start(self.cmb_repos_type, False)
hbox.pack_start(self.entry_custom_path)
button = gtk.Button(" ... ")
Expand All @@ -82,7 +78,7 @@ def get_folder(button):

hbox = gtk.HBox(False, 10)
self.cb_overwrite_destination = gtk.CheckButton("Overwrite existing tiles in destination repository")
hbox.pack_start( self.cb_overwrite_destination )
hbox.pack_start(self.cb_overwrite_destination)
vbox.pack_start(hbox)

return myFrame(" Destination repository for export ", vbox)
Expand Down Expand Up @@ -134,16 +130,15 @@ def _buttons():
return hbbox

self.mapServ = mapServ
fldDown = join(conf.init_path, 'download')
self.conf = conf
kmx = mapUtils.nice_round(kmx)
kmy = mapUtils.nice_round(kmy)
self.layer = layer
gtk.Window.__init__(self)
lat0 = coord[0]
lon0 = coord[1]
zoom0 = max(MAP_MIN_ZOOM_LEVEL, coord[2]-3)
zoom1 = min(MAP_MAX_ZOOM_LEVEL, coord[2]+1)
zoom0 = max(MAP_MIN_ZOOM_LEVEL, coord[2] - 3)
zoom1 = min(MAP_MAX_ZOOM_LEVEL, coord[2] + 1)

vbox = gtk.VBox(False)
hbox = gtk.HBox(False, 10)
Expand All @@ -165,10 +160,10 @@ def _buttons():
if ico:
self.set_icon(ico)

self.complete=[]
self.processing=False
self.gmap=None
self.downloader=None
self.complete = []
self.processing = False
self.gmap = None
self.downloader = None
self.connect('delete-event', self.on_delete)
self.connect('key-press-event', self.key_press)
self.show_all()
Expand All @@ -181,7 +176,7 @@ def check_write_access_dir(self, directory):
ret = True

try:
file = open( tmp_filename, 'w' )
file = open(tmp_filename, 'w')
file.write(EXWindow.repository_temp_file)
file.close()
os.unlink(tmp_filename)
Expand All @@ -197,15 +192,15 @@ def on_b_export_clicked(self, b_export, window):
drepos_type = window.cmb_repos_type.get_active()

if not self.check_write_access_dir(drepos_path):
gmsg = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "Error while trying to modify to selected repository '" + drepos_path + "'" )
gmsg = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "Error while trying to modify to selected repository '" + drepos_path + "'")
gmsg.run()
gmsg.destroy()
return

self.b_stop.set_sensitive(True)
self.b_export.set_sensitive(False)

self.drepos = trFactory.get_tile_repository( self.mapServ, drepos_path, drepos_type )
self.drepos = trFactory.get_tile_repository(self.mapServ, drepos_path, drepos_type)

lat = float(self.e_lat0.get_text())
lng = float(self.e_lon0.get_text())
Expand All @@ -214,28 +209,26 @@ def on_b_export_clicked(self, b_export, window):
min_zl = self.s_zoom0.get_value_as_int()
max_zl = self.s_zoom1.get_value_as_int()

self.transfer_thread = mapTilesTransfer.TilesTransfer( self.mapServ.tile_repository, self.drepos, (lat, lng), (min_zl, max_zl), (width, height), self.layer, self.cb_overwrite_destination.get_active() )
self.transfer_thread.set_callback_update( self.update_pbar )
self.transfer_thread.set_callback_finish( self.finished )
self.transfer_thread = mapTilesTransfer.TilesTransfer(self.mapServ.tile_repository, self.drepos, (lat, lng), (min_zl, max_zl), (width, height), self.layer, self.cb_overwrite_destination.get_active())
self.transfer_thread.set_callback_update(self.update_pbar)
self.transfer_thread.set_callback_finish(self.finished)

self.transfer_thread.start()


def update_pbar(self, text, percent = None):
def update_pbar(self, text, percent=None):
self.pbar.set_text(text)
if percent is not None:
self.pbar.set_fraction( percent / 100.0 )
self.pbar.set_fraction(percent / 100.0)

def finished(self, text):
self.pbar.set_text(text)
self.pbar.set_fraction( 1 )
self.pbar.set_fraction(1)
self.do_stop()

def on_b_stop_clicked(self, w):
self.do_stop()
self.pbar.set_text("Export interrupted.")


def do_stop(self):
if self.transfer_thread is None:
return
Expand All @@ -252,19 +245,16 @@ def do_stop(self):
self.b_stop.set_sensitive(False)
self.b_export.set_sensitive(True)



def key_press(self, w, event):
if (event.state & gtk.gdk.CONTROL_MASK) != 0 and event.keyval in [87, 119]:
# W = 87,119
self.on_delete()
self.destroy()

def on_delete(self,*params):
def on_delete(self, *params):

EXWindow.configpath = self.entry_custom_path.get_text()
EXWindow.repostype_id = self.cmb_repos_type.get_active()

self.do_stop()
return False

5 changes: 3 additions & 2 deletions gmapcatcher/customMsgBox.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pygtk
pygtk.require('2.0')
import gtk
import atk


## Message used to display errors
Expand All @@ -16,6 +15,7 @@ def error_msg(parent, strMessage, buttons=gtk.BUTTONS_OK):
dialog.destroy()
return resp


def error_msg_non_blocking(strTitle, strMessage):
dialog = gtk.MessageDialog(
parent = None,
Expand All @@ -26,6 +26,7 @@ def error_msg_non_blocking(strTitle, strMessage):
dialog.set_title(strTitle)
return dialog


## Message used in the updated notifications
class updateMsgBox(gtk.Window):
def hyperlink(self, strUrl):
Expand All @@ -38,7 +39,7 @@ def followLink(*w):
event_box = gtk.EventBox()
label_URL = gtk.Label()
label_URL.set_text("<span foreground=\"blue\" underline=\"single\">" +
strUrl + "</span>")
strUrl + "</span>")
label_URL.set_use_markup(True)
event_box.add(label_URL)
event_box.set_events(gtk.gdk.BUTTON_PRESS_MASK)
Expand Down
Loading

0 comments on commit 63ee133

Please sign in to comment.