def page(content, pagecallback=None): """ Output `content`, call `pagecallback` after every page with page number as a parameter. `pagecallback` may return False to terminate pagination. Default callback shows prompt, waits for keypress and aborts on 'q', ESC or Ctrl-C. """ width = pager.getwidth() height = pager.getheight() pagenum = 1 print content.next() try: try: line = content.next().rstrip("\r\n") except AttributeError: # Python 3 compatibility line = content.__next__().rstrip("\r\n") except StopIteration: pagecallback(pagenum, height-1) return while True: # page cycle linesleft = height-1 # leave the last line for the prompt callback while linesleft: linelist = [line[i:i+width] for i in range(0, len(line), width)] if not linelist: linelist = [''] lines2print = min(len(linelist), linesleft) for i in range(lines2print): print(linelist[i]) linesleft -= lines2print linelist = linelist[lines2print:] if linelist: # prepare symbols left on the line for the next iteration line = ''.join(linelist) continue else: try: try: line = content.next().rstrip("\r\n") except AttributeError: # Python 3 compatibility line = content.__next__().rstrip("\r\n") except StopIteration: pagecallback(pagenum, linesleft) return if pagecallback(pagenum, linesleft) == False: return pagenum += 1
def get_map(self): width, height = pager.getwidth() * self.scaling, pager.getheight( ) * self.scaling minx, miny, maxx, maxy = ( self.center[0] - (width / float(2) + self.gutter) * self.res, self.center[1] - (height / float(2) + self.gutter) * self.res, self.center[0] + (width / float(2) + self.gutter) * self.res, self.center[1] + (height / float(2) + self.gutter) * self.res) bbox = (miny, minx, maxy, maxx) if self.invert_axis else (minx, miny, maxx, maxy) params = { "width": int(width + self.gutter * 2), "height": int(height + self.gutter * 2), "bbox": ",".join(str(x) for x in bbox), "layers": self.layer, "format": self.format, "request": "GetMap", "version": ".".join(str(x) for x in self.version), "service": "WMS" } if self.version >= (1, 3, 0): params["crs"] = self.srs else: params["srs"] = self.srs if self.style: params["style"] = self.style r = self.session.get(self.url, params=params) self.last_error = None if r.status_code != 200 or not r.headers.get( "Content-Type").startswith("image/"): self.last_error = r.text return None try: img = Image.open(io.BytesIO(r.content)) img = process_image(img, self.gutter, self.scaling) return img except IOError as e: self.last_error = str(e) return None
import argparse import pydoc import pager from texttable import Texttable from .ntripbrowser import NtripBrowser from .ntripbrowser import ExceededTimeoutError, UnableToConnect, NoDataReceivedFromCaster from .ntripbrowser import CAS_HEADERS, STR_HEADERS, NET_HEADERS SCREEN_WIDTH = pager.getwidth() def argparser(): parser = argparse.ArgumentParser(description='Parse NTRIP sourcetable') parser.add_argument('url', help='NTRIP sourcetable address') parser.add_argument('-p', '--port', type=int, help='Set url port. Standard port is 2101', default=2101) parser.add_argument('-t', '--timeout', type=int, help='add timeout', default=4) parser.add_argument('-c', '--coordinates', help='Add NTRIP station distance to this coordinate', nargs=2) parser.add_argument(
def pan_right(self): self.center = self.center[0] + int(self.res * pager.getwidth() * self.pan_factor * self.scaling), \ self.center[1]
def print_progress(msg, width=None): if not width: width = getwidth() sys.stderr.write(colored('\r' + ' '*width + '\r' + msg[0 : width -1], 'green')) sys.stderr.flush()