def __init__(self, m, d, i): GUIModule.__init__(self, m, d, i) # some constants self.msLongPress = 400 self.centeringDisableThreshold = 2048 self.firstTimeSignal = signal.Signal() size = (800, 480) # initial window size # register exit handler pyotherside.atexit(self._shutdown) # window state self._fullscreen = False # get screen resolution # TODO: implement this #screenWH = self.getScreenWH() #print(" @ screen size: %dx%d" % screenWH) #if self.highDPI: # print(" @ high DPI") #else: # print(" @ normal DPI") # NOTE: what about multi-display devices ? :) ## add image providers self._imageProviders = { "icon" : IconImageProvider(self), "tile" : TileImageProvider(self), } with open("data/tile_not_found.png", "rb") as f: self._tileNotFoundImage = f.read() ## register the actual callback, that ## will call the appropriate provider base on ## image id prefix pyotherside.set_image_provider(self._selectImageProviderCB) # initialize theming self._theme = Theme(self) ## make constants accessible #self.constants = self.getConstants() #rc.setContextProperty("C", self.constants) ## connect to the close event #self.window.closeEvent = self._qtWindowClosed ##self.window.show() self._notificationQueue = [] # provides easy access to modRana modules from QML self.modules = Modules(self) # search functionality for the QML context self.search = Search(self)
def __init__(self, *args, **kwargs): GUIModule.__init__(self, *args, **kwargs) # some constants self.msLongPress = 400 self.centeringDisableThreshold = 2048 self.firstTimeSignal = signal.Signal() size = (800, 480) # initial window size self._screen_size = None # positioning related self._pythonPositioning = False # we handle notifications by forwarding them to the QML context self.modrana.notificationTriggered.connect( self._dispatchNotificationCB) # register exit handler #pyotherside.atexit(self._shutdown) # FIXME: for some reason the exit handler is never # called on Sailfish OS, so we use a onDestruction # handler on the QML side to trigger shutdown # window state self._fullscreen = False # get screen resolution # TODO: implement this #screenWH = self.getScreenWH() #self.log.debug(" @ screen size: %dx%d" % screenWH) #if self.highDPI: # self.log.debug(" @ high DPI") #else: # self.log.debug(" @ normal DPI") # NOTE: what about multi-display devices ? :) ## add image providers self._imageProviders = { "icon": IconImageProvider(self), "tile": TileImageProvider(self), } # log what version of PyOtherSide we are using # - we log this without prefix as this shows up early # during startup, so it looks nicer that way :-) no_prefix_log.info("using PyOtherSide %s", pyotherside.version) ## register the actual callback, that ## will call the appropriate provider base on ## image id prefix pyotherside.set_image_provider(self._selectImageProviderCB) # initialize theming self._theme = Theme(self) ## make constants accessible #self.constants = self.getConstants() #rc.setContextProperty("C", self.constants) ## connect to the close event #self.window.closeEvent = self._qtWindowClosed ##self.window.show() self._notificationQueue = [] # provides easy access to modRana modules from QML self.modules = Modules(self) # search functionality for the QML context self.search = Search(self) # POI handling for the QML context self.POI = POI(self) # make the log manager easily accessible self.log_manager = modrana_log.log_manager # log for log messages from the QML context self.qml_log = qml_log # queue a notification to QML context that # a Python loggers is available pyotherside.send("loggerAvailable") # tracklogs self.tracklogs = Tracklogs(self) #routing self.routing = Routing(self) # turn by turn navigation self.navigation = Navigation(self)
a = b = 0 for i in range(steps): a, b = a**2 - b**2 + x, 2*a*b + y if a**2 + b**2 >= 4: break return i def render_mandelbrot(image_id, requested_size): # when the url is: "image://python/xmin/xmax/ymin/ymax" # the image_id is: "xmin/xmax/ymin/ymax" parts = [float(x) for x in image_id.split('/')] x_range = parts[0:2] y_range = parts[2:4] # width and height will be -1 if not set in QML if requested_size == (-1, -1): requested_size = (200, 200) width, height = requested_size pixels = [] for y in range(height): yy = y_range[0] + (y_range[1] - y_range[0]) * y / height for x in range(width): xx = x_range[0] + (x_range[1] - x_range[0]) * x / width pixels.extend(reversed(COLORS[mandelbrot(xx, yy, len(COLORS))])) return bytearray(pixels), (width, height), pyotherside.format_argb32 pyotherside.set_image_provider(render_mandelbrot)
#!/usr/bin/env python # -*- coding: utf-8 -*- import pyotherside import urllib.request import os import random def image_provider(image_id, requested_size): if requested_size == (-1, -1): requested_size = (300, 300) url = image_id response = urllib.request.urlopen(url) data = response.read() return bytearray(data), requested_size, pyotherside.format_data pyotherside.set_image_provider(image_provider)
def render(image_id, requested_size): print('image_id: "{image_id}", size: {requested_size}'.format(**locals())) # width and height will be -1 if not set in QML if requested_size == (-1, -1): requested_size = (300, 300) width, height = requested_size # center for circle cx, cy = width / 2, 10 pixels = [] for y in range(height): for x in range(width): pixels.extend( reversed([ 255, # alpha int(10 + 10 * ((x - y * 0.5) % 20)), # red 20 + 10 * (y % 20), # green int(255 * abs( math.sin(0.3 * math.sqrt((cx - x)**2 + (cy - y)**2)))) # blue ])) return bytearray(pixels), (width, height), pyotherside.format_argb32 pyotherside.set_image_provider(render)
a, b = a**2 - b**2 + x, 2 * a * b + y if a**2 + b**2 >= 4: break return i def render_mandelbrot(image_id, requested_size): # when the url is: "image://python/xmin/xmax/ymin/ymax" # the image_id is: "xmin/xmax/ymin/ymax" parts = [float(x) for x in image_id.split('/')] x_range = parts[0:2] y_range = parts[2:4] # width and height will be -1 if not set in QML if requested_size == (-1, -1): requested_size = (200, 200) width, height = requested_size pixels = [] for y in range(height): yy = y_range[0] + (y_range[1] - y_range[0]) * y / height for x in range(width): xx = x_range[0] + (x_range[1] - x_range[0]) * x / width pixels.extend(reversed(COLORS[mandelbrot(xx, yy, len(COLORS))])) return bytearray(pixels), (width, height), pyotherside.format_argb32 pyotherside.set_image_provider(render_mandelbrot)
g7ZDf7JQhbBkkbV9ob/X3uOdutFDhbs4gr44fLU3ea83dqtkjrI4f7o3c6VCc6VJiLtEicDN3+73 9/+CrdFwlrWbv9329fU8cp6Cr9Q2bZybvdo3apRakb/v7+//7WD/5ln44W5/qMr/617/41T51ls4 hcP/20z12oL7zkewx9n/1UTx5cNyoMVQfKH16Mb/4FL/0ED12Y1Sjb341Wj4zVd/nrjx7Nr/zDv7 yED71U/8xTmAo8DG1OD/2En/xTJDeafc4ef145j64mL7wDf15qb/vCn5wkSApsb3zXTz8vJCfa76 vkCQr8n/tSH22Jf5wEmhus9Jf6z/zVf/4Jf/1nv/9+X/03b9vi7/+/L/1oP33pL/z2r/7cj/5Kz/ uC330oT4x2L236D/tTH31Hvr6urm5uaTuO3WAAAAAWJLR0QAiAUdSAAAAAlwSFlzAAAASAAAAEgA RslrPgAAAnBJREFUaN7tlltz0kAYQBcVRcsmbdDWKooppDZNRFRAUWhtoViKFjXWe73f/f/v7iVZ toG8ZD9mdNzz2plzyJdvt0FIo9FoNBrNv0bm2PET2ZOEU7nTZ+D1c3mMsWEYpmnOExbA/RhblmXQ AtEXCoWzwIFzeHHp/DJ7ANMsUC7ABvL4IkLFcEAscAk2gPFlhJYM4S+VStABvHwlKwZUAg+wF3zE Dx0QGxr5gQOCXBSwgYSZFXrCcHxAtm2XKxXHcVYV/VcxTvDb5bU1x3XddSX/nOd59Ahb0gkQAYf6 ff+aSmCR+6UrQvjtssv8flXBf91LHBALEL1fq91IH7jpefIdKhaIcqveaFB9rXk7feAOThyQnWn5 3N+8mz6QTx7QvXbo73Q20gcsa/KK4PPJtDepn+g7nfvpA/Lv39ouj6m3ut0u9/d6PaUnMHhhp/9g t8Kh68/XJ/QrBLJiQP1VoXca0fqE/kH6wErk39qb4m9y//Bh+sCj6AT0d8fjccX69Jh/uJ8+sB2e gPmRE/NH4yH+YTt9AD0ON3SU4Cf64RMFP3rKP7N4YHJ9qD94phJAOX5FjKauD/MfKPkRev5ih4DI P5fQX61WNxgDhsIbPoIYfwtIGMedWB+F4zU9EH+9wAE6/uj27L189Zq8XtiAL6/PG4TeBoewgU12 O4fXwzuE3gfAI/og3z4fP33+EnyFDaB16fYJCN+A/Qh9r0anl+h/qN0PCdR/HgwO6e22r/AlpPlr KY4mmIU8/OoCjRSLsloGpiHrf42REwC/X+h/c0QCojDjJ5j9O2CJ4pQlJdA/qOulSgwwt0aj0Wg0 Gs1/wR/yOd+mI4x7LgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxMy0xMC0wNFQwMzo1OTozNCswMDow MLgfTfgAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTMtMTAtMDRUMDM6NTk6MzQrMDA6MDDJQvVEAAAA AElFTkSuQmCC """ def load_data(image_id, requested_size): # If you return data in the format "pyotherside.format_data", the size is # ignored; the data is interpreted as image file data (e.g. PNG, jpeg, ..) return bytearray(base64.b64decode(IMAGE_DATA)), (-1, -1), pyotherside.format_data pyotherside.set_image_provider(load_data)
""" Utils.send('error', str) @staticmethod def tips(str): """ Send tips message """ Utils.send("tips", str) @staticmethod def loading(str): """ Send if progress is doing """ Utils.send("loading", str) @staticmethod def send(event, msg=None): """ Send data to QML """ pyotherside.send(event, msg) utils = Utils() imghaldler = ImgHandler() pyotherside.set_image_provider(imghaldler.image_provider)
# # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND # FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. # import matplotlib.pyplot as plt import numpy as np import io import pyotherside def plot_provider(image_id, requested_size): plt.figure() x = np.arange(0.0, 5.0, 0.1) plt.plot(np.sin(x)) for dataset in image_id.split(';'): plt.plot([float(x) for x in dataset.split(',') if x]) plt.title("Dataset from QML") buf = io.BytesIO() plt.savefig(buf, format='png') plt.close() buf.seek(0) return bytearray(buf.read()), requested_size, pyotherside.format_data pyotherside.set_image_provider(plot_provider)
# purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND # FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. # import pyotherside import os def load_data(image_id, requested_size): # If you return data in the format "pyotherside.format_svg_data" requested_size # is is used as the target size when rendering the SVG image # We use the image id to get name of the SVG file to render with open(image_id, 'rb') as f: svg_image_data = f.read() return bytearray( svg_image_data), requested_size, pyotherside.format_svg_data pyotherside.set_image_provider(load_data)
def __init__(self, *args, **kwargs): GUIModule.__init__(self, *args, **kwargs) # some constants self.msLongPress = 400 self.centeringDisableThreshold = 2048 self.firstTimeSignal = signal.Signal() size = (800, 480) # initial window size # positioning related self._pythonPositioning = False # we handle notifications by forwarding them to the QML context self.modrana.notificationTriggered.connect(self._dispatchNotificationCB) # register exit handler #pyotherside.atexit(self._shutdown) # FIXME: for some reason the exit handler is never # called on Sailfish OS, so we use a onDestruction # handler on the QML side to trigger shutdown # window state self._fullscreen = False # get screen resolution # TODO: implement this #screenWH = self.getScreenWH() #self.log.debug(" @ screen size: %dx%d" % screenWH) #if self.highDPI: # self.log.debug(" @ high DPI") #else: # self.log.debug(" @ normal DPI") # NOTE: what about multi-display devices ? :) ## add image providers self._imageProviders = { "icon" : IconImageProvider(self), "tile" : TileImageProvider(self), } ## register the actual callback, that ## will call the appropriate provider base on ## image id prefix pyotherside.set_image_provider(self._selectImageProviderCB) # initialize theming self._theme = Theme(self) ## make constants accessible #self.constants = self.getConstants() #rc.setContextProperty("C", self.constants) ## connect to the close event #self.window.closeEvent = self._qtWindowClosed ##self.window.show() self._notificationQueue = [] # provides easy access to modRana modules from QML self.modules = Modules(self) # search functionality for the QML context self.search = Search(self) # make the log manager easily accessible self.log_manager = modrana_log.log_manager # log for log messages from the QML context self.qml_log = qml_log # queue a notification to QML context that # a Python loggers is available pyotherside.send("loggerAvailable") # tracklogs self.tracklogs = Tracklogs(self) #routing self.routing = Routing(self)