def gps_updt_rate(self, gps_update_rate): hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("GPS update rate in seconds: ")) self.e_gps_updt_rate = SpinBtn(gps_update_rate, 0.1, 100, 0.1, 5, False) self.e_gps_updt_rate.set_digits(1) hbox.pack_start(self.e_gps_updt_rate) return hbox
def _size(width, height): hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("Width:"), False) self.s_width = SpinBtn(width, 450, 1024, 100, 4) hbox.pack_start(self.s_width) hbox.pack_start(lbl("Height:"), False) self.s_height = SpinBtn(height, 400, 768, 100, 4) hbox.pack_start(self.s_height) return myFrame(" Size ", hbox)
def gps_track_settings(self, gps_track, track_width, track_interval): self.cb_gps_track = gtk.CheckButton('Log GPS track') self.cb_gps_track.set_active(gps_track) self.sb_gps_track_width = SpinBtn(track_width, 1, 20, 1, 2) self.sb_gps_track_interval = SpinBtn(track_interval, 1, 1000, 10, 4) vbox = gtk.VBox(False, 10) hbox = gtk.HBox(False, 10) hbox.pack_start(self.cb_gps_track) hbox.pack_start(lbl("Track width: ")) hbox.pack_start(self.sb_gps_track_width) hbox.pack_start(lbl("Point interval (in meters): ")) hbox.pack_start(self.sb_gps_track_interval) vbox.pack_start(hbox) return myFrame(" GPS track ", vbox)
def _center(center): hbox = gtk.HBox(False, 0) hbox.pack_start(lbl(" (( "), False) self.s_center00 = SpinBtn(center[0][0], 0, 999999, 1, 6) hbox.pack_start(self.s_center00, False) hbox.pack_start(lbl(" , "), False) self.s_center01 = SpinBtn(center[0][1], 0, 999999, 1, 6) hbox.pack_start(self.s_center01, False) hbox.pack_start(lbl(" ), ( "), False) self.s_center10 = SpinBtn(center[1][0], 0, 256, 32, 3) hbox.pack_start(self.s_center10, False) hbox.pack_start(lbl(" , "), False) self.s_center11 = SpinBtn(center[1][1], 0, 256, 32, 3) hbox.pack_start(self.s_center11, False) hbox.pack_start(lbl(" )) "), False) return myFrame(" Center ", hbox)
def gps_max_zoom(self, max_gps_zoom): hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("Maximum zoom for GPS: ")) self.s_gps_max_zoom = SpinBtn(max_gps_zoom, MAP_MIN_ZOOM_LEVEL, MAP_MAX_ZOOM_LEVEL - 1) hbox.pack_start(self.s_gps_max_zoom) return hbox
def gps_max_zoom(self, max_gps_zoom): hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("Here you can set the maximum zoom for the GPS: ")) self.s_gps_max_zoom = SpinBtn(max_gps_zoom, MAP_MIN_ZOOM_LEVEL, MAP_MAX_ZOOM_LEVEL - 1) hbox.pack_start(self.s_gps_max_zoom) return myFrame(" GPS Max Zoom ", hbox)
def _center(center): hbox = gtk.HBox(False, 0) hbox.pack_start(lbl(" (( "), False) self.s_center00 = SpinBtn(center[0][0], 0, 999999, 1, 6) hbox.pack_start(self.s_center00, False) hbox.pack_start(lbl(" , "), False) self.s_center01 = SpinBtn(center[0][1], 0, 999999, 1, 6) hbox.pack_start(self.s_center01, False) hbox.pack_start(lbl(" ), ( "), False) self.s_center10 = SpinBtn(center[1][0], 0, 256, 32, 3) hbox.pack_start(self.s_center10, False) hbox.pack_start(lbl(" , "), False) self.s_center11 = SpinBtn(center[1][1], 0, 256, 32, 3) hbox.pack_start(self.s_center11, False) hbox.pack_start(lbl(" )) "), False) button = gtk.Button("Use Current") button.connect('clicked', btn_use_current, parent) hbox.pack_start(button) return myFrame(" Center ", hbox)
def _zoom(zoom0, zoom1): out_hbox = gtk.HBox(False, 50) out_hbox.set_border_width(10) in_hbox = gtk.HBox(False, 20) in_hbox.pack_start(lbl("min:"), False) self.s_zoom0 = SpinBtn(zoom0) self.s_zoom0.set_digits(0) in_hbox.pack_start(self.s_zoom0) out_hbox.pack_start(in_hbox) in_hbox = gtk.HBox(False, 20) in_hbox.pack_start(lbl("max:"), False) self.s_zoom1 = SpinBtn(zoom1) self.s_zoom1.set_digits(0) in_hbox.pack_start(self.s_zoom1) out_hbox.pack_start(in_hbox) hbox = gtk.HBox() hbox.set_border_width(10) hbox.pack_start(myFrame(" Zoom ", out_hbox, 0)) return hbox
class MyGPS(gtk.VPaned): ## All the buttons at the bottom def btn_save_clicked(self, button, conf): conf.gps_update_rate = self.e_gps_updt_rate.get_value() conf.max_gps_zoom = self.s_gps_max_zoom.get_value_as_int() conf.gps_mode = self.cmb_gps_mode.get_active() conf.gps_type = self.cmb_gps_type.get_active() conf.gps_track = int(self.cb_gps_track.get_active()) conf.gps_track_width = self.sb_gps_track_width.get_value_as_int() conf.gps_track_interval = self.sb_gps_track_interval.get_value_as_int() if serialAvailable: conf.gps_serial_port = self.cmb_gps_serial_port.get_active_text() conf.gps_serial_baudrate = int(self.cmb_gps_baudrate.get_active_text()) conf.save() def __action_buttons(self, conf): def btn_revert_clicked(button, conf): self.e_gps_updt_rate.set_text(str(conf.gps_update_rate)) self.s_gps_max_zoom.set_value(conf.max_gps_zoom) self.cmb_gps_mode.set_active(conf.gps_mode) bbox = gtk.HButtonBox() bbox.set_layout(gtk.BUTTONBOX_END) bbox.set_border_width(10) bbox.set_spacing(60) button = gtk.Button(stock=gtk.STOCK_REVERT_TO_SAVED) button.connect('clicked', btn_revert_clicked, conf) bbox.add(button) button = gtk.Button(stock=gtk.STOCK_SAVE) button.connect('clicked', self.btn_save_clicked, conf) bbox.add(button) return bbox ## Option to change the GPS update rate def gps_updt_rate(self, gps_update_rate): hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("GPS update rate in seconds: ")) self.e_gps_updt_rate = SpinBtn(gps_update_rate, 0.1, 100, 0.1, 5, False) self.e_gps_updt_rate.set_digits(1) hbox.pack_start(self.e_gps_updt_rate) return hbox ## Option to change the GPS max zoom def gps_max_zoom(self, max_gps_zoom): hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("Maximum zoom for GPS: ")) self.s_gps_max_zoom = SpinBtn(max_gps_zoom, MAP_MIN_ZOOM_LEVEL, MAP_MAX_ZOOM_LEVEL - 1) hbox.pack_start(self.s_gps_max_zoom) return hbox ## ComboBox to change the GPS mode def gps_mode_combo(self, gps_mode): hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("Initial GPS mode: ")) self.cmb_gps_mode = gtk.combo_box_new_text() for strMode in GPS_NAMES: self.cmb_gps_mode.append_text(strMode) self.cmb_gps_mode.set_active(gps_mode) hbox.pack_start(self.cmb_gps_mode) return hbox ## Changes to the gps type combo box def cmb_gps_changed(self, w): sensitive = (w.get_active() > GPS_DISABLED) self.boxes[1].set_sensitive(sensitive) self.boxes[2].set_sensitive(sensitive) self.boxes[3].set_sensitive(sensitive) ## ComboBox to change the GPS type def gps_type_combo(self): hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("GPS type: ")) self.cmb_gps_type = gtk.combo_box_new_text() for strType in GPS_TYPES: self.cmb_gps_type.append_text(strType) self.cmb_gps_type.connect('changed', self.cmb_gps_changed) hbox.pack_start(self.cmb_gps_type) return hbox ## Settings for GPS track: def gps_track_settings(self, gps_track, track_width, track_interval): self.cb_gps_track = gtk.CheckButton('Draw GPS track') self.cb_gps_track.set_active(gps_track) self.sb_gps_track_width = SpinBtn(track_width, 1, 20, 1, 2) self.sb_gps_track_interval = SpinBtn(track_interval, 1, 1000, 10, 4) vbox = gtk.VBox(False, 10) hbox = gtk.HBox(False, 10) hbox.pack_start(self.cb_gps_track) hbox.pack_start(lbl("Track width: ")) hbox.pack_start(self.sb_gps_track_width) hbox.pack_start(lbl("Point interval (in meters): ")) hbox.pack_start(self.sb_gps_track_interval) vbox.pack_start(hbox) return myFrame(" GPS track ", vbox) ## ComboBox to select serial port def gps_serial_port_combo(self, serial_port): hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("Serial port: ")) self.cmb_gps_serial_port = gtk.combo_box_new_text() i = 0 ports = serialPortScan() # Adding current port from config to the list, # in case the GPS just isn't currently connected, we don't want to lose it... if serial_port not in ports: ports.insert(0, serial_port) for strPort in ports: self.cmb_gps_serial_port.append_text(strPort) if strPort == serial_port: self.cmb_gps_serial_port.set_active(i) i += 1 hbox.pack_start(self.cmb_gps_serial_port) return hbox ## ComboBox to change the GPS serial baudrate def gps_baudrate_combo(self, baudrate): hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("Serial port baudrate: ")) self.cmb_gps_baudrate = gtk.combo_box_new_text() i = 0 for baud in BAUDRATES: self.cmb_gps_baudrate.append_text(str(baud)) if baud == baudrate: self.cmb_gps_baudrate.set_active(i) i += 1 hbox.pack_start(self.cmb_gps_baudrate) return hbox def key_press(self, widget, event, conf): if (event.state & gtk.gdk.CONTROL_MASK) != 0 and event.keyval in [83, 115]: # S = 83, 115 self.btn_save_clicked(0, conf) ## Put all the GPS Widgets together def show(self, conf): def general_gps_box(): self.boxes = [self.gps_type_combo(), self.gps_updt_rate(conf.gps_update_rate), self.gps_max_zoom(conf.max_gps_zoom), self.gps_mode_combo(conf.gps_mode)] vbox = gtk.VBox(False, 5) for box in self.boxes: hbox = gtk.HBox(False, 10) hbox.pack_start(box) vbox.pack_start(hbox) return myFrame(" GPS ", vbox) def gps_serial_box(): vbox = gtk.VBox(False, 5) if serialAvailable: boxes = [self.gps_serial_port_combo(conf.gps_serial_port), self.gps_baudrate_combo(conf.gps_serial_baudrate)] for box in boxes: hbox = gtk.HBox(False, 10) hbox.pack_start(box) vbox.pack_start(hbox) else: vbox.pack_start(lbl('Install python-serial to use serial GPS.')) return myFrame(" Serial ", vbox) vbox = gtk.VBox(False, 10) vbox.set_border_width(10) vbox.pack_start(general_gps_box(), False) vbox.pack_start(self.gps_track_settings(conf.gps_track, conf.gps_track_width, conf.gps_track_interval)) vbox.pack_start(gps_serial_box(), False) self.pack1(vbox, True, True) buttons = self.__action_buttons(conf) self.pack2(buttons, False, False) self.connect('key-press-event', self.key_press, conf) self.cmb_gps_type.set_active(conf.gps_type) return self
def _zoom(zoom): hbox = gtk.HBox(False, 10) self.s_zoom = SpinBtn(zoom) hbox.pack_start(self.s_zoom, False) return myFrame(" Zoom ", hbox)
class EXWindow(gtk.Window): configpath = "None" repostype_id = REPOS_TYPE_FILES repository_temp_file = "repository_write_test.tmp" def __init__(self, mapServ, coord, kmx, kmy, layer, conf): def _zoom(zoom0, zoom1): out_hbox = gtk.HBox(False, 50) out_hbox.set_border_width(10) in_hbox = gtk.HBox(False, 20) in_hbox.pack_start(lbl("min:"), False) self.s_zoom0 = SpinBtn(zoom0) self.s_zoom0.set_digits(0) in_hbox.pack_start(self.s_zoom0) out_hbox.pack_start(in_hbox) in_hbox = gtk.HBox(False, 20) in_hbox.pack_start(lbl("max:"), False) self.s_zoom1 = SpinBtn(zoom1) self.s_zoom1.set_digits(0) in_hbox.pack_start(self.s_zoom1) out_hbox.pack_start(in_hbox) hbox = gtk.HBox() hbox.set_border_width(10) hbox.pack_start(myFrame(" Zoom ", out_hbox, 0)) return hbox def _custom_path(): def repository_type_combo(repos_type_id): self.cmb_repos_type = gtk.combo_box_new_text() for strMode in REPOS_TYPE: self.cmb_repos_type.append_text(strMode) self.cmb_repos_type.set_active(repos_type_id) return self.cmb_repos_type def get_folder(button): #if os.path.isdir(self.entry_custom_path.get_text()): # dir = self.entry_custom_path #else: # dir = None folderName = FolderChooser() if folderName: self.entry_custom_path.set_text(folderName) vbox = gtk.VBox(False, 5) 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) hbox.pack_start(self.cmb_repos_type, False) hbox.pack_start(self.entry_custom_path) button = gtk.Button(" ... ") button.connect('clicked', get_folder) hbox.pack_start(button, False) vbox.pack_start(hbox) hbox = gtk.HBox(False, 10) self.cb_overwrite_destination = gtk.CheckButton("Overwrite existing tiles in destination repository") hbox.pack_start(self.cb_overwrite_destination) vbox.pack_start(hbox) return myFrame(" Destination repository for export ", vbox) def _center(lat0, lon0): vbox = gtk.VBox(False, 5) hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("latitude:")) self.e_lat0 = myEntry("%.6f" % lat0, 15, False) hbox.pack_start(self.e_lat0, False) vbox.pack_start(hbox) hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("longitude:")) self.e_lon0 = myEntry("%.6f" % lon0, 15, False) hbox.pack_start(self.e_lon0, False) vbox.pack_start(hbox) return myFrame(" Center ", vbox) def _area(kmx, kmy): vbox = gtk.VBox(False, 5) hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("width:")) self.e_kmx = myEntry("%.6g" % kmx, 10, False) hbox.pack_start(self.e_kmx, False) vbox.pack_start(hbox) hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("height:")) self.e_kmy = myEntry("%.6g" % kmy, 10, False) hbox.pack_start(self.e_kmy, False) vbox.pack_start(hbox) return myFrame(" Area (km) ", vbox) def _buttons(): hbbox = gtk.HButtonBox() hbbox.set_border_width(10) hbbox.set_layout(gtk.BUTTONBOX_SPREAD) self.b_export = gtk.Button("Export") self.b_export.connect('clicked', self.on_b_export_clicked, self) hbbox.pack_start(self.b_export) self.b_stop = gtk.Button(stock='gtk-media-stop') self.b_stop.connect('clicked', self.on_b_stop_clicked) self.b_stop.set_sensitive(False) hbbox.pack_start(self.b_stop) return hbbox self.mapServ = mapServ 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) vbox = gtk.VBox(False) hbox = gtk.HBox(False, 10) hbox.pack_start(_center(lat0, lon0)) hbox.pack_start(_area(kmx, kmy)) vbox.pack_start(hbox) vbox.pack_start(_zoom(zoom0, zoom1)) vbox.pack_start(_custom_path()) vbox.pack_start(_buttons()) self.pbar = gtk.ProgressBar() self.pbar.set_text("...") vbox.pack_start(self.pbar) self.add(vbox) self.set_title("GMapCatcher export") self.set_border_width(10) ico = mapPixbuf.ico() if ico: self.set_icon(ico) 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() self.transfer_thread = None # check some basic file operations def check_write_access_dir(self, directory): tmp_filename = os.path.join(directory, EXWindow.repository_temp_file) ret = True try: file = open(tmp_filename, 'w') file.write(EXWindow.repository_temp_file) file.close() os.unlink(tmp_filename) except: ret = False return ret ## Start the download def on_b_export_clicked(self, b_export, window): # Creating our own gmap drepos_path = window.entry_custom_path.get_text() # 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.run() gmsg.destroy() return self.b_stop.set_sensitive(True) self.b_export.set_sensitive(False) self.drepos = trFactory.get_tile_repository(self.mapServ, self.conf) lat = float(self.e_lat0.get_text()) lng = float(self.e_lon0.get_text()) width = float(self.e_kmx.get_text()) height = float(self.e_kmy.get_text()) 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.start() def update_pbar(self, text, percent=None): self.pbar.set_text(text) if percent is not None: self.pbar.set_fraction(percent / 100.0) def finished(self, text): self.pbar.set_text(text) 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 if self.transfer_thread.isAlive(): self.transfer_thread.set_stop(True) self.transfer_thread.join() self.transfer_thread = None self.drepos.finish() self.drepos = None 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): EXWindow.configpath = self.entry_custom_path.get_text() EXWindow.repostype_id = self.cmb_repos_type.get_active() self.do_stop() return False
class MySettings(): ## Put all the settings Widgets together def show(self, parent): def _size(width, height): hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("Width:"), False) self.s_width = SpinBtn(width, 450, 1024, 100, 4) hbox.pack_start(self.s_width) hbox.pack_start(lbl("Height:"), False) self.s_height = SpinBtn(height, 400, 768, 100, 4) hbox.pack_start(self.s_height) return myFrame(" Size ", hbox) def _zoom(zoom): hbox = gtk.HBox(False, 10) self.s_zoom = SpinBtn(zoom) hbox.pack_start(self.s_zoom, False) return myFrame(" Zoom ", hbox) def _center(center): hbox = gtk.HBox(False, 0) hbox.pack_start(lbl(" (( "), False) self.s_center00 = SpinBtn(center[0][0], 0, 999999, 1, 6) hbox.pack_start(self.s_center00, False) hbox.pack_start(lbl(" , "), False) self.s_center01 = SpinBtn(center[0][1], 0, 999999, 1, 6) hbox.pack_start(self.s_center01, False) hbox.pack_start(lbl(" ), ( "), False) self.s_center10 = SpinBtn(center[1][0], 0, 256, 32, 3) hbox.pack_start(self.s_center10, False) hbox.pack_start(lbl(" , "), False) self.s_center11 = SpinBtn(center[1][1], 0, 256, 32, 3) hbox.pack_start(self.s_center11, False) hbox.pack_start(lbl(" )) "), False) return myFrame(" Center ", hbox) def _status_save(conf): def statuscombo(active_type_id): hbox = gtk.HBox(False, 10) hbox.pack_start( \ lbl(" Select status bar type ")) self.cmb_status_type = gtk.combo_box_new_text() for strType in STATUS_TYPE: self.cmb_status_type.append_text(strType) self.cmb_status_type.set_active(active_type_id) hbox.pack_start(self.cmb_status_type) return hbox def save_checkbox(active_bool): self.save_at_close_button = \ gtk.CheckButton(" Save View Params ") self.save_at_close_button.set_active(active_bool) return self.save_at_close_button status = myFrame(" Location Status ", statuscombo(conf.status_location)) save = myFrame(" Close Settings ", save_checkbox(conf.save_at_close)) hbox = gtk.HBox(False, 10) hbox.pack_start(save) hbox.pack_start(status) return hbox def custom_path(conf): def repository_type_combo(repos_type_id): self.cmb_repos_type = gtk.combo_box_new_text() for strMode in REPOS_TYPE: self.cmb_repos_type.append_text(strMode) self.cmb_repos_type.set_active(repos_type_id) return self.cmb_repos_type def get_folder(button): folderName = FolderChooser() if folderName: self.entry_custom_path.set_text(folderName) def set_folder(button): self.cmb_repos_type.set_active(REPOS_TYPE_FILES) self.entry_custom_path.set_text( os.path.join(os.path.expanduser(USER_PATH), TILES_PATH)) vbox = gtk.VBox(False, 5) vbox.set_border_width(5) hbox = gtk.HBox(False, 10) hbox.pack_start( \ lbl(" This is the directory with all the images. ")) button = gtk.Button("Reset to default") button.connect('clicked', set_folder) hbox.pack_start(button) vbox.pack_start(hbox) hbox = gtk.HBox(False, 10) myEntry = gtk.Entry() if conf.init_path: myEntry.set_text(conf.init_path) else: myEntry.set_text("None") cmbbox = repository_type_combo(conf.repository_type) hbox.pack_start(cmbbox, False) hbox.pack_start(myEntry) self.entry_custom_path = myEntry button = gtk.Button(" ... ") button.connect('clicked', get_folder) hbox.pack_start(button, False) vbox.pack_start(hbox) return myFrame(" Custom Maps Directory ", vbox) def _language(old_lang="en"): vbox = gtk.VBox(False, 5) combo = gtk.combo_box_new_text() nr = -1 df = 0 for lang in LANGUAGES: nr = nr + 1 combo.append_text(lang) if (lang == old_lang): df = nr combo.set_active(df) vbox.pack_start(combo) self.s_language = combo return myFrame(" Language ", vbox) def btn_save_clicked(button): conf.init_center = ((self.s_center00.get_value_as_int()), (self.s_center01.get_value_as_int())), \ ((self.s_center10.get_value_as_int()), (self.s_center11.get_value_as_int())) conf.init_zoom = self.s_zoom.get_value_as_int() conf.init_width = self.s_width.get_value_as_int() conf.init_height = self.s_height.get_value_as_int() conf.language = self.s_language.get_active_text() conf.status_location = self.cmb_status_type.get_active() conf.save_at_close = self.save_at_close_button.get_active() if( os.pathsep == ';' ): # we have windows OS, filesystem is case insensitive newPath = (self.entry_custom_path.get_text().lower()).strip() oldPath = conf.init_path.lower().strip() else: newPath = (self.entry_custom_path.get_text()).strip() oldPath = conf.init_path.strip() if (newPath != "" and newPath.lower() != "none") or (self.cmb_repos_type.get_active() != conf.repository_type): #if strTemp != (conf.init_path.lower()).strip(): if (newPath != oldPath) or (self.cmb_repos_type.get_active() != conf.repository_type): conf.init_path = self.entry_custom_path.get_text() conf.repository_type = self.cmb_repos_type.get_active() parent.ctx_map.initLocations(conf.init_path, conf.repository_type) parent.drawing_area.repaint() else: conf.init_path = None conf.repository_type = self.cmb_repos_type.get_active() conf.save() parent.refresh() def _action_buttons(conf, parent): def btn_revert_clicked(button): self.s_center00.set_value(conf.init_center[0][0]) self.s_center01.set_value(conf.init_center[0][1]) self.s_center10.set_value(conf.init_center[1][0]) self.s_center11.set_value(conf.init_center[1][1]) self.s_zoom.set_value(conf.init_zoom) self.s_width.set_value(conf.init_width) self.s_height.set_value(conf.init_height) if conf.init_path: self.entry_custom_path.set_text(conf.init_path) else: self.entry_custom_path.set_text("None") bbox = gtk.HButtonBox() bbox.set_layout(gtk.BUTTONBOX_END) bbox.set_border_width(10) bbox.set_spacing(60) button = gtk.Button(stock=gtk.STOCK_REVERT_TO_SAVED) button.connect('clicked', btn_revert_clicked) bbox.add(button) button = gtk.Button(stock=gtk.STOCK_SAVE) button.connect('clicked', btn_save_clicked) bbox.add(button) return bbox def btn_use_current(button, parent): self.s_center00.set_value(parent.drawing_area.center[0][0]) self.s_center01.set_value(parent.drawing_area.center[0][1]) self.s_center10.set_value(parent.drawing_area.center[1][0]) self.s_center11.set_value(parent.drawing_area.center[1][1]) self.s_zoom.set_value(parent.get_zoom()) dsize = parent.window.get_size() self.s_width.set_value(dsize[0]) self.s_height.set_value(dsize[1]) def key_press(widget, event): if (event.state & gtk.gdk.CONTROL_MASK) != 0 and \ event.keyval in [83, 115]: # S = 83, 115 btn_save_clicked(0) hpaned = gtk.VPaned() vbox = gtk.VBox() vbox.set_border_width(10) hbox = gtk.HBox(False, 10) conf = parent.conf hbox.pack_start(_size(conf.init_width, conf.init_height)) hbox.pack_start(_zoom(conf.init_zoom), False) hbox.pack_start(_language(conf.language)) vbox.pack_start(hbox, False) hbox = gtk.HBox(False, 10) hbox.pack_start(_center(conf.init_center)) bbox = gtk.HButtonBox() button = gtk.Button("Use Current") button.connect('clicked', btn_use_current, parent) bbox.add(button) hbox.pack_start(bbox) vbox.pack_start(hbox, False) vbox1 = gtk.VBox(False, 10) vbox1.set_border_width(5) vbox1.pack_start(_status_save(conf)) vbox1.pack_start(custom_path(conf)) vbox.pack_start(vbox1, False) hpaned.pack1(vbox, True, True) hpaned.pack2(_action_buttons(conf, parent), False, False) hpaned.connect('key-press-event', key_press) return hpaned
class DLWindow(gtk.Window): def __init__(self, coord, kmx, kmy, layer, conf, force_update): self.layers = [] def _zoom(zoom0, zoom1): out_hbox = gtk.HBox(False, 50) out_hbox.set_border_width(10) in_hbox = gtk.HBox(False, 20) in_hbox.pack_start(lbl("min:"), False) self.s_zoom0 = SpinBtn(zoom0) self.s_zoom0.set_digits(0) in_hbox.pack_start(self.s_zoom0) out_hbox.pack_start(in_hbox) in_hbox = gtk.HBox(False, 20) in_hbox.pack_start(lbl("max:"), False) self.s_zoom1 = SpinBtn(zoom1) self.s_zoom1.set_digits(0) in_hbox.pack_start(self.s_zoom1) out_hbox.pack_start(in_hbox) hbox = gtk.HBox() hbox.set_border_width(10) hbox.pack_start(myFrame(" Zoom ", out_hbox, 0)) return hbox def _center(lat0, lon0): vbox = gtk.VBox(False, 5) hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("latitude:")) self.e_lat0 = myEntry("%.6f" % lat0, 15, False) hbox.pack_start(self.e_lat0, False) vbox.pack_start(hbox) hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("longitude:")) self.e_lon0 = myEntry("%.6f" % lon0, 15, False) hbox.pack_start(self.e_lon0, False) vbox.pack_start(hbox) return myFrame(" Center ", vbox) def _area(kmx, kmy): vbox = gtk.VBox(False, 5) hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("width:")) self.e_kmx = myEntry("%.6g" % kmx, 10, False) hbox.pack_start(self.e_kmx, False) vbox.pack_start(hbox) hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("height:")) self.e_kmy = myEntry("%.6g" % kmy, 10, False) hbox.pack_start(self.e_kmy, False) vbox.pack_start(hbox) return myFrame(" Area (km) ", vbox) def download_rclick(self, event, menu): if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3: menu.popup(None, None, None, event.button, event.time) def rclick_menu(active_layer, map_serv): menu = gtk.Menu() for layer in range(len(LAYER_NAMES)): self.layers.append(gtk.CheckMenuItem(LAYER_NAMES[layer])) if layer == active_layer: self.layers[-1].set_active(True) else: self.layers[-1].set_sensitive( layer in MAP_SERVICES[map_serv]['layers']) menu.append(self.layers[-1]) menu.show_all() return menu def _buttons(strFolder, layer, conf): hbbox = gtk.HButtonBox() hbbox.set_border_width(10) hbbox.set_layout(gtk.BUTTONBOX_SPREAD) menu = rclick_menu(layer, MAP_SERVERS.index(conf.map_service)) gtk.stock_add([(gtk.STOCK_HARDDISK, "_Download", 0, 0, "")]) self.b_download = gtk.Button(stock=gtk.STOCK_HARDDISK) self.b_download.connect('clicked', self.start_download, strFolder) self.b_download.connect('event', download_rclick, menu) hbbox.pack_start(self.b_download) hbox = gtk.HBox() gtk.stock_add([(gtk.STOCK_UNDELETE, "", 0, 0, "")]) self.b_open = gtk.Button(stock=gtk.STOCK_UNDELETE) self.b_open.connect('clicked', self.do_open, strFolder) hbox.pack_start(self.b_open, padding=25) if isdir(fldDown): hbbox.pack_start(hbox) self.b_pause = gtk.Button(stock='gtk-media-pause') self.b_pause.connect('clicked', self.do_pause) self.b_pause.set_sensitive(False) hbbox.pack_start(self.b_pause) return hbbox fldDown = join(conf.init_path, 'download') print "DLWindow(", coord, kmx, kmy, layer, ')' self.conf = conf self.force_update = force_update kmx = mapUtils.nice_round(kmx) kmy = mapUtils.nice_round(kmy) 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) vbox = gtk.VBox(False) hbox = gtk.HBox(False, 10) hbox.pack_start(_center(lat0, lon0)) hbox.pack_start(_area(kmx, kmy)) vbox.pack_start(hbox) vbox.pack_start(_zoom(zoom0, zoom1)) vbox.pack_start(_buttons(fldDown, layer, conf)) self.pbar = gtk.ProgressBar() self.pbar.set_text(" ") vbox.pack_start(self.pbar) self.add(vbox) self.set_title("GMapCatcher download") self.set_border_width(10) ico = mapPixbuf.ico() if ico: self.set_icon(ico) 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() ## Start the download def start_download(self, w, strFolder): # Creating our own gmap self.gmap = mapServices.MapServ(self.conf) self.complete = [] self.downloader = MapDownloader(self.gmap, self.conf.maxthreads) if self.conf.map_service in NO_BULK_DOWN: if not legal_warning(self, self.conf.map_service, "bulk downloading"): self.all_done("Canceled") return args = MapArgs() if self.processing: return try: args.lat = float(self.e_lat0.get_text()) args.lng = float(self.e_lon0.get_text()) args.width = float(self.e_kmx.get_text()) args.height = float(self.e_kmy.get_text()) args.min_zl = self.s_zoom0.get_value_as_int() args.max_zl = self.s_zoom1.get_value_as_int() except ValueError: d = gtk.MessageDialog(self, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, "Some field contain non-numbers") d.run() d.destroy() return self.b_pause.set_sensitive(True) self.b_download.set_sensitive(False) self.b_open.set_sensitive(False) # Save the map info self.save_info(check_dir(strFolder), str(args)) for layer in range(len(self.layers)): self.pbar.set_text(" ") self.processing = True if self.layers[layer].get_active(): self.downloader.bulk_download( (args.lat, args.lng, 15), (args.min_zl, args.max_zl), args.width, args.height, layer, gui_callback(self.tile_received), self.download_complete, self.force_update, self.conf) self.processing = False # Open a previously saved file and auto-populate the fields def do_open(self, w, strPath): fileName = FileChooser(strPath) if fileName: file = open(fileName, "r") for line in file: args = MapArgs(line.split(" ")) self.e_lat0.set_text(str(args.lat)) self.e_lon0.set_text(str(args.lng)) self.e_kmx.set_text(str(args.width)) self.e_kmy.set_text(str(args.height)) self.s_zoom0.set_text(str(args.min_zl)) self.s_zoom1.set_text(str(args.max_zl)) return ## Save the data to a text file def save_info(self, strPath, strInfo): 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): self.download_complete() return self.update_pbar("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 self.pbar.set_fraction(percentfloat) if percentfloat > 0: percent = " [%.1f%%]" % (percentfloat * 100) self.pbar.set_text(text + percent) def download_complete(self): if self.pbar.get_text() != "Paused": self.all_done("Complete") def do_pause(self, w): self.all_done("Paused") def all_done(self, strMessage): if self.downloader: self.downloader.stop_all() self.downloader = None self.processing = False self.b_pause.set_sensitive(False) self.b_download.set_sensitive(True) self.b_open.set_sensitive(True) self.update_pbar(strMessage, 0, 1) 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): if self.downloader: self.downloader.stop_all() return False
class MySettings(): ## Put all the settings Widgets together def show(self, parent): def _size(width, height): hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("Width:"), False) self.s_width = SpinBtn(width, 450, 1024, 100, 4) hbox.pack_start(self.s_width) hbox.pack_start(lbl("Height:"), False) self.s_height = SpinBtn(height, 400, 768, 100, 4) hbox.pack_start(self.s_height) return myFrame(" Size ", hbox) def _zoom(zoom): hbox = gtk.HBox(False, 10) self.s_zoom = SpinBtn(zoom) hbox.pack_start(self.s_zoom, False) return myFrame(" Zoom ", hbox) def _center(center): hbox = gtk.HBox(False, 0) hbox.pack_start(lbl(" (( "), False) self.s_center00 = SpinBtn(center[0][0], 0, 999999, 1, 6) hbox.pack_start(self.s_center00, False) hbox.pack_start(lbl(" , "), False) self.s_center01 = SpinBtn(center[0][1], 0, 999999, 1, 6) hbox.pack_start(self.s_center01, False) hbox.pack_start(lbl(" ), ( "), False) self.s_center10 = SpinBtn(center[1][0], 0, 256, 32, 3) hbox.pack_start(self.s_center10, False) hbox.pack_start(lbl(" , "), False) self.s_center11 = SpinBtn(center[1][1], 0, 256, 32, 3) hbox.pack_start(self.s_center11, False) hbox.pack_start(lbl(" )) "), False) button = gtk.Button("Use Current") button.connect('clicked', btn_use_current, parent) hbox.pack_start(button) return myFrame(" Center ", hbox) def _units(active): hbox = gtk.HBox(False, 10) self.cmb_unit_type = gtk.combo_box_new_text() for i in range(len(DISTANCE_UNITS)): self.cmb_unit_type.append_text('%s / %s' % (DISTANCE_UNITS[i], SPEED_UNITS[i])) self.cmb_unit_type.set_active(active) hbox.pack_start(self.cmb_unit_type) return myFrame(" Select units ", hbox) def _offline(active): hbox = gtk.HBox(False, 10) self.cmb_start_offline = gtk.combo_box_new_text() self.cmb_start_offline.append_text('no') self.cmb_start_offline.append_text('yes') self.cmb_start_offline.set_active(active) hbox.pack_start(self.cmb_start_offline) return myFrame(" Start offline ", hbox) def _status_save(conf): def status_combo(active_type_id): hbox = gtk.HBox(False, 10) hbox.pack_start(lbl(" Select status bar type ")) self.cmb_status_type = gtk.combo_box_new_text() for strType in STATUS_TYPE: self.cmb_status_type.append_text(strType) self.cmb_status_type.set_active(active_type_id) hbox.pack_start(self.cmb_status_type) return hbox def save_checkbox(active_bool): self.save_at_close_button = \ gtk.CheckButton(" Save View Params ") self.save_at_close_button.set_active(active_bool) return self.save_at_close_button status = myFrame(" Location Status ", status_combo(conf.statusbar_type)) save = myFrame(" Close Settings ", save_checkbox(conf.save_at_close)) hbox = gtk.HBox(False, 10) hbox.pack_start(save) hbox.pack_start(status) return hbox def custom_path(conf): def repository_type_combo(repos_type_id): self.cmb_repos_type = gtk.combo_box_new_text() for strMode in REPOS_TYPE: self.cmb_repos_type.append_text(strMode) self.cmb_repos_type.set_active(repos_type_id) return self.cmb_repos_type def get_folder(button): folderName = FolderChooser() if folderName: self.entry_custom_path.set_text(folderName) def set_folder(button): self.cmb_repos_type.set_active(REPOS_TYPE_FILES) self.entry_custom_path.set_text(DEFAULT_PATH) vbox = gtk.VBox(False, 5) vbox.set_border_width(5) hbox = gtk.HBox(False, 10) hbox.pack_start(lbl(" This is the directory with all the images. ")) button = gtk.Button("Reset to default") button.connect('clicked', set_folder) hbox.pack_start(button) vbox.pack_start(hbox) hbox = gtk.HBox(False, 10) myEntry = gtk.Entry() if conf.init_path: myEntry.set_text(conf.init_path) else: myEntry.set_text("None") cmbbox = repository_type_combo(conf.repository_type) hbox.pack_start(cmbbox, False) hbox.pack_start(myEntry) self.entry_custom_path = myEntry button = gtk.Button(" ... ") button.connect('clicked', get_folder) hbox.pack_start(button, False) vbox.pack_start(hbox) return myFrame(" Custom Maps Directory ", vbox) def btn_save_clicked(button): conf.init_center = ((self.s_center00.get_value_as_int()), (self.s_center01.get_value_as_int())), \ ((self.s_center10.get_value_as_int()), (self.s_center11.get_value_as_int())) conf.init_zoom = self.s_zoom.get_value_as_int() conf.init_width = self.s_width.get_value_as_int() conf.init_height = self.s_height.get_value_as_int() conf.statusbar_type = self.cmb_status_type.get_active() conf.save_at_close = self.save_at_close_button.get_active() conf.units = self.cmb_unit_type.get_active() conf.start_offline = self.cmb_start_offline.get_active() if os.pathsep == ';': # we have windows OS, filesystem is case insensitive newPath = (self.entry_custom_path.get_text().lower()).strip() oldPath = conf.init_path.lower().strip() else: newPath = (self.entry_custom_path.get_text()).strip() oldPath = conf.init_path.strip() if (newPath != "" and newPath.lower() != "none") or (self.cmb_repos_type.get_active() != conf.repository_type): #if strTemp != (conf.init_path.lower()).strip(): if (newPath != oldPath) or (self.cmb_repos_type.get_active() != conf.repository_type): conf.init_path = self.entry_custom_path.get_text() conf.repository_type = self.cmb_repos_type.get_active() parent.ctx_map.initLocations(conf) parent.drawing_area.repaint() else: conf.init_path = None conf.repository_type = self.cmb_repos_type.get_active() conf.save() parent.refresh() def _action_buttons(conf, parent): def btn_revert_clicked(button): self.s_center00.set_value(conf.init_center[0][0]) self.s_center01.set_value(conf.init_center[0][1]) self.s_center10.set_value(conf.init_center[1][0]) self.s_center11.set_value(conf.init_center[1][1]) self.s_zoom.set_value(conf.init_zoom) self.s_width.set_value(conf.init_width) self.s_height.set_value(conf.init_height) if conf.init_path: self.entry_custom_path.set_text(conf.init_path) else: self.entry_custom_path.set_text("None") bbox = gtk.HButtonBox() bbox.set_layout(gtk.BUTTONBOX_END) bbox.set_border_width(10) bbox.set_spacing(60) button = gtk.Button(stock=gtk.STOCK_REVERT_TO_SAVED) button.connect('clicked', btn_revert_clicked) bbox.add(button) button = gtk.Button(stock=gtk.STOCK_SAVE) button.connect('clicked', btn_save_clicked) bbox.add(button) return bbox def btn_use_current(button, parent): self.s_center00.set_value(parent.drawing_area.center[0][0]) self.s_center01.set_value(parent.drawing_area.center[0][1]) self.s_center10.set_value(parent.drawing_area.center[1][0]) self.s_center11.set_value(parent.drawing_area.center[1][1]) self.s_zoom.set_value(parent.get_zoom()) dsize = parent.window.get_size() self.s_width.set_value(dsize[0]) self.s_height.set_value(dsize[1]) def key_press(widget, event): if (event.state & gtk.gdk.CONTROL_MASK) != 0 and \ event.keyval in [83, 115]: # S = 83, 115 btn_save_clicked(0) hpaned = gtk.VPaned() vbox = gtk.VBox() vbox.set_border_width(10) hbox = gtk.HBox(False, 10) conf = parent.conf hbox.pack_start(_size(conf.init_width, conf.init_height)) hbox.pack_start(_zoom(conf.init_zoom), False) hbox.pack_start(_units(conf.units)) vbox.pack_start(hbox, False) hbox = gtk.HBox(False, 10) hbox.pack_start(_center(conf.init_center)) hbox.pack_start(_offline(conf.start_offline)) vbox.pack_start(hbox, False) vbox1 = gtk.VBox(False, 10) vbox1.set_border_width(5) vbox1.pack_start(_status_save(conf)) vbox1.pack_start(custom_path(conf)) vbox.pack_start(vbox1, False) hpaned.pack1(vbox, True, True) hpaned.pack2(_action_buttons(conf, parent), False, False) hpaned.connect('key-press-event', key_press) return hpaned
class DLWindow(gtk.Window): def __init__(self, coord, kmx, kmy, layer, conf): self.layers = [] def _zoom(zoom0, zoom1): out_hbox = gtk.HBox(False, 50) out_hbox.set_border_width(10) in_hbox = gtk.HBox(False, 20) in_hbox.pack_start(lbl("min:"), False) self.s_zoom0 = SpinBtn(zoom0) self.s_zoom0.set_digits(0) in_hbox.pack_start(self.s_zoom0) out_hbox.pack_start(in_hbox) in_hbox = gtk.HBox(False, 20) in_hbox.pack_start(lbl("max:"), False) self.s_zoom1 = SpinBtn(zoom1) self.s_zoom1.set_digits(0) in_hbox.pack_start(self.s_zoom1) out_hbox.pack_start(in_hbox) hbox = gtk.HBox() hbox.set_border_width(10) hbox.pack_start(myFrame(" Zoom ", out_hbox, 0)) return hbox def _center(lat0, lon0): vbox = gtk.VBox(False, 5) hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("latitude:")) self.e_lat0 = myEntry("%.6f" % lat0, 15, False) hbox.pack_start(self.e_lat0, False) vbox.pack_start(hbox) hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("longitude:")) self.e_lon0 = myEntry("%.6f" % lon0, 15, False) hbox.pack_start(self.e_lon0, False) vbox.pack_start(hbox) return myFrame(" Center ", vbox) def _area(kmx, kmy): vbox = gtk.VBox(False, 5) hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("width:")) self.e_kmx = myEntry("%.6g" % kmx, 10, False) hbox.pack_start(self.e_kmx, False) vbox.pack_start(hbox) hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("height:")) self.e_kmy = myEntry("%.6g" % kmy, 10, False) hbox.pack_start(self.e_kmy, False) vbox.pack_start(hbox) return myFrame(" Area (km) ", vbox) def download_rclick(self, event, menu): if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3: menu.popup(None, None, None, event.button, event.time) def rclick_menu(active_layer, map_serv): menu = gtk.Menu() for layer in range(len(LAYER_NAMES)): self.layers.append(gtk.CheckMenuItem(LAYER_NAMES[layer])) if layer == active_layer: self.layers[-1].set_active(True) else: self.layers[-1].set_sensitive(layer in MAP_SERVICES[map_serv]['layers']) menu.append(self.layers[-1]) menu.show_all() return menu def _buttons(strFolder, layer, conf): hbbox = gtk.HButtonBox() hbbox.set_border_width(10) hbbox.set_layout(gtk.BUTTONBOX_SPREAD) menu = rclick_menu(layer, MAP_SERVERS.index(conf.map_service)) gtk.stock_add([(gtk.STOCK_HARDDISK, "_Download", 0, 0, "")]) self.b_download = gtk.Button(stock=gtk.STOCK_HARDDISK) self.b_download.connect('clicked', self.start_download, strFolder) self.b_download.connect('event', download_rclick, menu) hbbox.pack_start(self.b_download) hbox = gtk.HBox() gtk.stock_add([(gtk.STOCK_UNDELETE, "", 0, 0, "")]) self.b_open = gtk.Button(stock=gtk.STOCK_UNDELETE) self.b_open.connect('clicked', self.do_open, strFolder) hbox.pack_start(self.b_open, padding=25) if isdir(fldDown): hbbox.pack_start(hbox) self.b_pause = gtk.Button(stock='gtk-media-pause') self.b_pause.connect('clicked', self.do_pause) self.b_pause.set_sensitive(False) hbbox.pack_start(self.b_pause) return hbbox fldDown = join(conf.init_path, 'download') print "DLWindow(", coord, kmx, kmy, layer, ')' self.conf = conf kmx = mapUtils.nice_round(kmx) kmy = mapUtils.nice_round(kmy) 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) vbox = gtk.VBox(False) hbox = gtk.HBox(False, 10) hbox.pack_start(_center(lat0, lon0)) hbox.pack_start(_area(kmx, kmy)) vbox.pack_start(hbox) vbox.pack_start(_zoom(zoom0, zoom1)) vbox.pack_start(_buttons(fldDown, layer, conf)) self.pbar = gtk.ProgressBar() self.pbar.set_text(" ") vbox.pack_start(self.pbar) self.add(vbox) self.set_title("GMapCatcher download") self.set_border_width(10) ico = mapPixbuf.ico() if ico: self.set_icon(ico) 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() ## Start the download def start_download(self, w, strFolder): # Creating our own gmap self.gmap = mapServices.MapServ(self.conf) self.complete = [] self.downloader = MapDownloader(self.gmap, self.conf.maxthreads) if self.conf.map_service in NO_BULK_DOWN: if not legal_warning(self, self.conf.map_service, "bulk downloading"): self.all_done("Canceled") return args = MapArgs() if self.processing: return try: args.lat = float(self.e_lat0.get_text()) args.lng = float(self.e_lon0.get_text()) args.width = float(self.e_kmx.get_text()) args.height = float(self.e_kmy.get_text()) args.min_zl = self.s_zoom0.get_value_as_int() args.max_zl = self.s_zoom1.get_value_as_int() except ValueError: d = gtk.MessageDialog(self, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, "Some field contain non-numbers") d.run() d.destroy() return self.b_pause.set_sensitive(True) self.b_download.set_sensitive(False) self.b_open.set_sensitive(False) # Save the map info self.save_info(check_dir(strFolder), str(args)) for layer in range(len(self.layers)): self.pbar.set_text(" ") self.processing = True if self.layers[layer].get_active(): self.downloader.bulk_download((args.lat, args.lng, 15), (args.min_zl, args.max_zl), args.width, args.height, layer, gui_callback(self.tile_received), self.download_complete, False, self.conf) self.processing = False # Open a previously saved file and auto-populate the fields def do_open(self, w, strPath): fileName = FileChooser(strPath) if fileName: file = open(fileName, "r") for line in file: args = MapArgs(line.split(" ")) self.e_lat0.set_text(str(args.lat)) self.e_lon0.set_text(str(args.lng)) self.e_kmx.set_text(str(args.width)) self.e_kmy.set_text(str(args.height)) self.s_zoom0.set_text(str(args.min_zl)) self.s_zoom1.set_text(str(args.max_zl)) return ## Save the data to a text file def save_info(self, strPath, strInfo): 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): self.download_complete() return self.update_pbar( "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 self.pbar.set_fraction(percentfloat) if percentfloat > 0: percent = " [%.1f%%]" % (percentfloat * 100) self.pbar.set_text(text + percent) def download_complete(self): if self.pbar.get_text() != "Paused": self.all_done("Complete") def do_pause(self, w): self.all_done("Paused") def all_done(self, strMessage): if self.downloader: self.downloader.stop_all() self.downloader = None self.processing = False self.b_pause.set_sensitive(False) self.b_download.set_sensitive(True) self.b_open.set_sensitive(True) self.update_pbar(strMessage, 0, 1) 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): if self.downloader: self.downloader.stop_all() return False
class MyGPS(gtk.VPaned): ## All the buttons at the bottom def btn_save_clicked(self, button, conf): conf.gps_update_rate = self.e_gps_updt_rate.get_value() conf.max_gps_zoom = self.s_gps_max_zoom.get_value_as_int() conf.gps_mode = self.cmb_gps_mode.get_active() conf.gps_type = self.cmb_gps_type.get_active() conf.gps_track = int(self.cb_gps_track.get_active()) conf.gps_track_width = self.sb_gps_track_width.get_value_as_int() conf.gps_track_interval = self.sb_gps_track_interval.get_value_as_int() if serialAvailable: conf.gps_serial_port = self.cmb_gps_serial_port.get_active_text() conf.gps_serial_baudrate = int( self.cmb_gps_baudrate.get_active_text()) conf.save() def __action_buttons(self, conf): def btn_revert_clicked(button, conf): self.e_gps_updt_rate.set_text(str(conf.gps_update_rate)) self.s_gps_max_zoom.set_value(conf.max_gps_zoom) self.cmb_gps_mode.set_active(conf.gps_mode) bbox = gtk.HButtonBox() bbox.set_layout(gtk.BUTTONBOX_END) bbox.set_border_width(10) bbox.set_spacing(60) button = gtk.Button(stock=gtk.STOCK_REVERT_TO_SAVED) button.connect('clicked', btn_revert_clicked, conf) bbox.add(button) button = gtk.Button(stock=gtk.STOCK_SAVE) button.connect('clicked', self.btn_save_clicked, conf) bbox.add(button) return bbox ## Option to change the GPS update rate def gps_updt_rate(self, gps_update_rate): hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("GPS update rate in seconds: ")) self.e_gps_updt_rate = SpinBtn(gps_update_rate, 0.1, 100, 0.1, 5, False) self.e_gps_updt_rate.set_digits(1) hbox.pack_start(self.e_gps_updt_rate) return hbox ## Option to change the GPS max zoom def gps_max_zoom(self, max_gps_zoom): hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("Maximum zoom for GPS: ")) self.s_gps_max_zoom = SpinBtn(max_gps_zoom, MAP_MIN_ZOOM_LEVEL, MAP_MAX_ZOOM_LEVEL - 1) hbox.pack_start(self.s_gps_max_zoom) return hbox ## ComboBox to change the GPS mode def gps_mode_combo(self, gps_mode): hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("Initial GPS mode: ")) self.cmb_gps_mode = gtk.combo_box_new_text() for strMode in GPS_NAMES: self.cmb_gps_mode.append_text(strMode) self.cmb_gps_mode.set_active(gps_mode) hbox.pack_start(self.cmb_gps_mode) return hbox ## Changes to the gps type combo box def cmb_gps_changed(self, w): sensitive = (w.get_active() > GPS_DISABLED) self.boxes[1].set_sensitive(sensitive) self.boxes[2].set_sensitive(sensitive) self.boxes[3].set_sensitive(sensitive) ## ComboBox to change the GPS type def gps_type_combo(self): hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("GPS type: ")) self.cmb_gps_type = gtk.combo_box_new_text() for strType in GPS_TYPES: self.cmb_gps_type.append_text(strType) self.cmb_gps_type.connect('changed', self.cmb_gps_changed) hbox.pack_start(self.cmb_gps_type) return hbox ## Settings for GPS track: def gps_track_settings(self, gps_track, track_width, track_interval): self.cb_gps_track = gtk.CheckButton('Log GPS track') self.cb_gps_track.set_active(gps_track) self.sb_gps_track_width = SpinBtn(track_width, 1, 20, 1, 2) self.sb_gps_track_interval = SpinBtn(track_interval, 1, 1000, 10, 4) vbox = gtk.VBox(False, 10) hbox = gtk.HBox(False, 10) hbox.pack_start(self.cb_gps_track) hbox.pack_start(lbl("Track width: ")) hbox.pack_start(self.sb_gps_track_width) hbox.pack_start(lbl("Point interval (in meters): ")) hbox.pack_start(self.sb_gps_track_interval) vbox.pack_start(hbox) return myFrame(" GPS track ", vbox) ## ComboBox to select serial port def gps_serial_port_combo(self, serial_port): hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("Serial port: ")) self.cmb_gps_serial_port = gtk.combo_box_new_text() i = 0 ports = serialPortScan() # Adding current port from config to the list, # in case the GPS just isn't currently connected, we don't want to lose it... if serial_port not in ports: ports.insert(0, serial_port) for strPort in ports: self.cmb_gps_serial_port.append_text(strPort) if strPort == serial_port: self.cmb_gps_serial_port.set_active(i) i += 1 hbox.pack_start(self.cmb_gps_serial_port) return hbox ## ComboBox to change the GPS serial baudrate def gps_baudrate_combo(self, baudrate): hbox = gtk.HBox(False, 10) hbox.pack_start(lbl("Serial port baudrate: ")) self.cmb_gps_baudrate = gtk.combo_box_new_text() i = 0 for baud in BAUDRATES: self.cmb_gps_baudrate.append_text(str(baud)) if baud == baudrate: self.cmb_gps_baudrate.set_active(i) i += 1 hbox.pack_start(self.cmb_gps_baudrate) return hbox def key_press(self, widget, event, conf): if (event.state & gtk.gdk.CONTROL_MASK) != 0 and event.keyval in [ 83, 115 ]: # S = 83, 115 self.btn_save_clicked(0, conf) ## Put all the GPS Widgets together def show(self, conf): def general_gps_box(): self.boxes = [ self.gps_type_combo(), self.gps_updt_rate(conf.gps_update_rate), self.gps_max_zoom(conf.max_gps_zoom), self.gps_mode_combo(conf.gps_mode) ] vbox = gtk.VBox(False, 5) for box in self.boxes: hbox = gtk.HBox(False, 10) hbox.pack_start(box) vbox.pack_start(hbox) return myFrame(" GPS ", vbox) def gps_serial_box(): vbox = gtk.VBox(False, 5) if serialAvailable: boxes = [ self.gps_serial_port_combo(conf.gps_serial_port), self.gps_baudrate_combo(conf.gps_serial_baudrate) ] for box in boxes: hbox = gtk.HBox(False, 10) hbox.pack_start(box) vbox.pack_start(hbox) else: vbox.pack_start( lbl('Install python-serial to use serial GPS.')) return myFrame(" Serial ", vbox) vbox = gtk.VBox(False, 10) vbox.set_border_width(10) vbox.pack_start(general_gps_box(), False) vbox.pack_start( self.gps_track_settings(conf.gps_track, conf.gps_track_width, conf.gps_track_interval)) vbox.pack_start(gps_serial_box(), False) self.pack1(vbox, True, True) buttons = self.__action_buttons(conf) self.pack2(buttons, False, False) self.connect('key-press-event', self.key_press, conf) self.cmb_gps_type.set_active(conf.gps_type) return self