You have to cast the ui.Image
into a scene.Texture
. Something like that:
return scene.Texture(ctx.get_image())
Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
You have to cast the ui.Image
into a scene.Texture
. Something like that:
return scene.Texture(ctx.get_image())
You could also just use os.path.dirname(__file__)
- assuming your interpreted file lies in your Book Notes folder. This would have the advantage of not having to hard code any folder name.
Works fine for me. Your exception suggests that in your enviroment the functiondelete_calendar()
in the namespace reminders
has been overwritten with a string of the same name. You should investigate that with the inspector when your exception is raised.
Or more likely ... you have missed a parenthesis while copying the snippet which often completely confuses the interpreter.
It is a bit unclear to me what you are trying to do.
ui.NavigationView
is just a (weirdly named) StackPanelmain_view
you cannot add it to the nav_view
and present it again.edit: You can present an instance of a view multiple times as a popover (popovers behave it a bit weirdly). Also nothing should crash if you try to present a view twice. You should just get an exception informing you that the view is already being presented. So if your code is crashing for you, you should probably provide a more extensive code example.
Your code should look something like this:
import ui
some_view = ui.View()
nav_view = ui.NavigationView(some_view)
nav_view.present('popover')
Ploting and calculus can be done with numpy
and matplotlib
. Both are available in pythonista by default.
import numpy
from matplotlib import pyplot
#100 linear samples between -10 and 10
x = numpy.linspace(-10, 10, 100)
#draw a red line through f(x) = x
pyplot.plot(x, x, 'r-')
#draw a blue dotted line through f(x) = sin(x)
pyplot.plot(x, numpy.sin(x), 'b--')
#show the plot
pyplot.show()
In order to save space in device (iPhone), can I delete freely from Pythonista some pure python external libraries that I never use [...]
Hm, pythonista is taking about 450 MB with some installed extra libraries for me. Sympy 1.0 is is about 4 MB big. I do not want to be rude, but I somehow fail to see how this going to make any impact on a device that measures its storage space in GB.
Okay, thanks. I gave the thread a more meaningful title. I cannot provide a full example as my code relies on other stuff, but here is a snippet how I did solve the problem now (a bit clunky). Maybe it will help someone in the future. I wrote two comments so that the code does make some sense.
def draw_line(self):
'''
'''
if self.line is not None:
self.line.remove_from_parent()
minx, miny = None, None
path = ui.Path()
path.line_width = 2
# self is a pythonista node. self.anchors are some phythonista node
# objects that are children of self. We want to draw a line through all
# these anchors within the coord system of self.
for i, anchor in enumerate(self.anchors):
p = anchor.position
# get/update the lower left corner minimum
minx, miny = (p.x if minx is None else min(minx, p.x),
p.y if miny is None else min(miny, p.y))
if i == 0: path.move_to(p.x, -p.y)
else: path.line_to(p.x, -p.y)
# the offset(position) of our node has to be the lower left corner
# point plus the center vector of our path
self.line = ShapeNode(path,
stroke_color='green',
fill_color='transparent',
position = (minx + path.bounds.w * .5,
miny + path.bounds.h * .5),
parent=self)