Example #1
0
def main():
    from ui import Image

    USER_APPS = 0
    SYSTEM_APPS = 1

    UIImage = ObjCClass('UIImage')

    allApps = defaultWorkspace.applicationsOfType_(USER_APPS)

    for i, app in enumerate(allApps):
        #print('hidden' in str(app.appTags()))
        console.write_link(
            '{} : {}, version {}. By {}'.format(app.bundleIdentifier(),
                                                app.localizedName(),
                                                app.shortVersionString(),
                                                app.vendorName()),
            'pythonista://{}?action=run&argv={}'.format(
                __file__.rsplit('/Pythonista3/Documents/')[-1],
                app.bundleIdentifier()))
        Image.from_data(
            uiimage_to_png(
                UIImage._applicationIconImageForBundleIdentifier_format_scale_(
                    app.bundleIdentifier(), 1, 100))).show()
        print('\n')
def contentFromC(aCContent):
    if aCContent is None: return None
    elif aCContent.isKindOfClass(UIColor):
        return RGBA(aCContent.red(), aCContent.green(), aCContent.blue(),
                    aCContent.alpha())
    elif aCContent.isKindOfClass(ObjCClass('UIImage')):
        c.UIImagePNGRepresentation.argtypes = [c_void_p]
        c.UIImagePNGRepresentation.restype = c_void_p
        data = ObjCInstance(c.UIImagePNGRepresentation(aCContent.ptr))
        return Image.from_data(nsdata_to_bytes(data), 2.0)
    elif aCContent.isKindOfClass(NSArray):
        if aCContent.objectAtIndex(0).isKindOfClass(ObjCClass('UIImage')):
            imageArray = []
            c.UIImagePNGRepresentation.argtypes = [c_void_p]
            c.UIImagePNGRepresentation.restype = c_void_p
            for i in range(aCContent.count()):
                aCImg = aCContent.objectAtIndex(i)
                if aCImg.isKindOfClass(ObjCClass('UIImage')):
                    data = ObjCInstance(c.UIImagePNGRepresentation(aCImg.ptr))
                    imageArray.append(
                        Image.from_data(nsdata_to_bytes(data), 2.0))
            return imageArray
        elif aCContent.isKindOfClass(NSURL):
            return str(aCContent.absoluteString())
        else:
            pass
    return aCContent
Example #3
0
	def plot(self):
		fig = BytesIO()
		if self.plt3D:
			figure = plt.figure()
			ax = figure.add_subplot(111, projection='3d')
			xs, ys, zs = self.ys
			for n in range(len(xs)):
				ax.plot_wireframe(xs[n], ys[n], zs[n])

			plt.savefig(fig)
			return Image.from_data(fig.getvalue())
		else:
			for n in range(len(self.ys)):
				plt.step(self.ranges[self.vars[0]][n], self.ys[n])
			plt.savefig(fig)
			return Image.from_data(fig.getvalue())
Example #4
0
def makeicon(c1, c2, name):
    gradient = makegradient(c1, c2, appsize)

    # hack to support partial transparency
    uii = UIImage.named(name)
    data = io.BytesIO(uii.to_png())
    top = PILImage.open(data)

    icon = composite(top, gradient, offset)
    data.close()

    with io.BytesIO() as bIO:
        icon.save(bIO, 'PNG')
        img = UIImage.from_data(bIO.getvalue())
    return img
Example #5
0
def analyse_data(fname, load_time, rest_time, interactive=False):
    t, f = np.loadtxt(fname).T
    tmeans, durations, _, fmeans, e_fmeans = measure_mean_loads(t, f)
    print(tmeans, fmeans)
    factor = load_time / (load_time + rest_time)
    load_asymptote = np.nanmean(fmeans[-5:-1])
    e_load_asymptote = np.nanstd(fmeans[-5:-1]) / np.sum(
        np.isfinite(fmeans[-5:-1]))

    critical_load = load_asymptote * factor
    e_critical_load = critical_load * (e_load_asymptote / load_asymptote)

    used_in_each_interval = (
        fmeans - critical_load) * load_time - critical_load * rest_time
    used_alternative = (fmeans - critical_load) * durations - critical_load * (
        load_time + rest_time - durations)
    wprime = np.sum(used_in_each_interval)
    wprime_alt = np.sum(used_alternative)
    remaining = wprime_alt - np.cumsum(used_alternative)

    # force constant
    alpha = np.median((fmeans - load_asymptote) / remaining)

    msg = 'peak load = {:.2f} +/- {:.2f} kg\n'.format(fmeans[0], e_fmeans[0])
    msg += 'critical load = {:.2f} +/- {:.2f} kg\n'.format(
        critical_load, e_critical_load)
    msg += 'asymptotic load = {:.2f} +/- {:.2f} kg\n'.format(
        load_asymptote, e_load_asymptote)
    msg += "W'' = {:.0f} J\n".format(9.8 * np.sum(used_in_each_interval))
    msg += "W'' (alt) = {:.0f} J\n".format(9.8 * wprime_alt)
    msg += 'Anaerobic function score = {:.1f}'.format(wprime_alt /
                                                      critical_load)

    fmax = f.max()
    predicted_force = load_asymptote + remaining * (
        fmax - load_asymptote) / wprime_alt
    #predicted_force = load_asymptote + alpha * remaining

    plt.rcParams.update({'font.size': 12})
    fig, axis = plt.subplots()
    axis.plot(t, f, alpha=0.5)
    axis.errorbar(tmeans, fmeans, yerr=e_fmeans, fmt='o')
    axis.axhline(critical_load, label='critical load')
    axis.axhline(load_asymptote, label='asymptotic load')
    axis.plot(tmeans, predicted_force, label='predicted max force')
    axis.fill_between(tmeans,
                      load_asymptote,
                      predicted_force,
                      color='g',
                      alpha=0.3,
                      label="W''")
    axis.set_xlabel('Time since start (s)')
    axis.set_ylabel('Load (kg)')
    plt.legend()
    axis.set_ylim(bottom=10)
    if interactive:
        print(msg)
        plt.show()
        return
    b = BytesIO()
    plt.savefig(b)
    plt.close('all')
    img = Image.from_data(b.getvalue())
    return msg, img
Example #6
-1
def makeicon(c1, c2, name):
    gradient = makegradient(c1, c2, appsize)

    # hack to support partial transparency
    uii = UIImage.named(name)
    data = io.BytesIO(uii.to_png())
    top = PILImage.open(data)
    
    icon = composite(top, gradient, offset)
    data.close()
    
    with io.BytesIO() as bIO:
        icon.save(bIO, 'PNG')
        img = UIImage.from_data(bIO.getvalue())
    return img